]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.2.11-201203152127.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.2.11-201203152127.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index dfa6fc6..6af9546 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 @@ -116,9 +126,11 @@ devlist.h*
67 dnotify_test
68 docproc
69 dslm
70 +dtc-lexer.lex.c
71 elf2ecoff
72 elfconfig.h*
73 evergreen_reg_safe.h
74 +exception_policy.conf
75 fixdep
76 flask.h
77 fore200e_mkfirm
78 @@ -126,12 +138,15 @@ fore200e_pca_fw.c*
79 gconf
80 gconf.glade.h
81 gen-devlist
82 +gen-kdb_cmds.c
83 gen_crc32table
84 gen_init_cpio
85 generated
86 genheaders
87 genksyms
88 *_gray256.c
89 +hash
90 +hid-example
91 hpet_example
92 hugepage-mmap
93 hugepage-shm
94 @@ -146,7 +161,7 @@ int32.c
95 int4.c
96 int8.c
97 kallsyms
98 -kconfig
99 +kern_constants.h
100 keywords.c
101 ksym.c*
102 ksym.h*
103 @@ -154,7 +169,7 @@ kxgettext
104 lkc_defs.h
105 lex.c
106 lex.*.c
107 -linux
108 +lib1funcs.S
109 logo_*.c
110 logo_*_clut224.c
111 logo_*_mono.c
112 @@ -166,14 +181,15 @@ machtypes.h
113 map
114 map_hugetlb
115 maui_boot.h
116 -media
117 mconf
118 +mdp
119 miboot*
120 mk_elfconfig
121 mkboot
122 mkbugboot
123 mkcpustr
124 mkdep
125 +mkpiggy
126 mkprep
127 mkregtable
128 mktables
129 @@ -209,6 +225,7 @@ r300_reg_safe.h
130 r420_reg_safe.h
131 r600_reg_safe.h
132 recordmcount
133 +regdb.c
134 relocs
135 rlim_names.h
136 rn50_reg_safe.h
137 @@ -219,6 +236,7 @@ setup
138 setup.bin
139 setup.elf
140 sImage
141 +slabinfo
142 sm_tbl*
143 split-include
144 syscalltab.h
145 @@ -229,6 +247,7 @@ tftpboot.img
146 timeconst.h
147 times.h*
148 trix_boot.h
149 +user_constants.h
150 utsrelease.h*
151 vdso-syms.lds
152 vdso.lds
153 @@ -246,7 +265,9 @@ vmlinux
154 vmlinux-*
155 vmlinux.aout
156 vmlinux.bin.all
157 +vmlinux.bin.bz2
158 vmlinux.lds
159 +vmlinux.relocs
160 vmlinuz
161 voffset.h
162 vsyscall.lds
163 @@ -254,9 +275,11 @@ vsyscall_32.lds
164 wanxlfw.inc
165 uImage
166 unifdef
167 +utsrelease.h
168 wakeup.bin
169 wakeup.elf
170 wakeup.lds
171 zImage*
172 zconf.hash.c
173 +zconf.lex.c
174 zoffset.h
175 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
176 index 81c287f..d456d02 100644
177 --- a/Documentation/kernel-parameters.txt
178 +++ b/Documentation/kernel-parameters.txt
179 @@ -1935,6 +1935,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
180 the specified number of seconds. This is to be used if
181 your oopses keep scrolling off the screen.
182
183 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
184 + virtualization environments that don't cope well with the
185 + expand down segment used by UDEREF on X86-32 or the frequent
186 + page table updates on X86-64.
187 +
188 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
189 +
190 pcbit= [HW,ISDN]
191
192 pcd. [PARIDE]
193 diff --git a/Makefile b/Makefile
194 index 4b76371..53aa79c 100644
195 --- a/Makefile
196 +++ b/Makefile
197 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
198
199 HOSTCC = gcc
200 HOSTCXX = g++
201 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
202 -HOSTCXXFLAGS = -O2
203 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
204 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
205 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
206
207 # Decide whether to build built-in, modular, or both.
208 # Normally, just do built-in.
209 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
210 # Rules shared between *config targets and build targets
211
212 # Basic helpers built in scripts/
213 -PHONY += scripts_basic
214 -scripts_basic:
215 +PHONY += scripts_basic gcc-plugins
216 +scripts_basic: gcc-plugins
217 $(Q)$(MAKE) $(build)=scripts/basic
218 $(Q)rm -f .tmp_quiet_recordmcount
219
220 @@ -564,6 +565,50 @@ else
221 KBUILD_CFLAGS += -O2
222 endif
223
224 +ifndef DISABLE_PAX_PLUGINS
225 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
226 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
227 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
228 +endif
229 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
230 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
231 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
232 +endif
233 +ifdef CONFIG_KALLOCSTAT_PLUGIN
234 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
235 +endif
236 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
237 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
238 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
239 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
240 +endif
241 +ifdef CONFIG_CHECKER_PLUGIN
242 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
243 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
244 +endif
245 +endif
246 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
247 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
248 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
249 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
250 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
251 +ifeq ($(KBUILD_EXTMOD),)
252 +gcc-plugins:
253 + $(Q)$(MAKE) $(build)=tools/gcc
254 +else
255 +gcc-plugins: ;
256 +endif
257 +else
258 +gcc-plugins:
259 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
260 + $(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.))
261 +else
262 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
263 +endif
264 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
265 +endif
266 +endif
267 +
268 include $(srctree)/arch/$(SRCARCH)/Makefile
269
270 ifneq ($(CONFIG_FRAME_WARN),0)
271 @@ -708,7 +753,7 @@ export mod_strip_cmd
272
273
274 ifeq ($(KBUILD_EXTMOD),)
275 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
276 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
277
278 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
279 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
280 @@ -932,6 +977,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
281
282 # The actual objects are generated when descending,
283 # make sure no implicit rule kicks in
284 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
285 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
286 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
287
288 # Handle descending into subdirectories listed in $(vmlinux-dirs)
289 @@ -941,7 +988,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
290 # Error messages still appears in the original language
291
292 PHONY += $(vmlinux-dirs)
293 -$(vmlinux-dirs): prepare scripts
294 +$(vmlinux-dirs): gcc-plugins prepare scripts
295 $(Q)$(MAKE) $(build)=$@
296
297 # Store (new) KERNELRELASE string in include/config/kernel.release
298 @@ -985,6 +1032,7 @@ prepare0: archprepare FORCE
299 $(Q)$(MAKE) $(build)=.
300
301 # All the preparing..
302 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
303 prepare: prepare0
304
305 # Generate some files
306 @@ -1086,6 +1134,8 @@ all: modules
307 # using awk while concatenating to the final file.
308
309 PHONY += modules
310 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
311 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
312 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
313 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
314 @$(kecho) ' Building modules, stage 2.';
315 @@ -1101,7 +1151,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
316
317 # Target to prepare building external modules
318 PHONY += modules_prepare
319 -modules_prepare: prepare scripts
320 +modules_prepare: gcc-plugins prepare scripts
321
322 # Target to install modules
323 PHONY += modules_install
324 @@ -1198,6 +1248,7 @@ distclean: mrproper
325 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
326 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
327 -o -name '.*.rej' \
328 + -o -name '.*.rej' -o -name '*.so' \
329 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
330 -type f -print | xargs rm -f
331
332 @@ -1358,6 +1409,8 @@ PHONY += $(module-dirs) modules
333 $(module-dirs): crmodverdir $(objtree)/Module.symvers
334 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
335
336 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
337 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
338 modules: $(module-dirs)
339 @$(kecho) ' Building modules, stage 2.';
340 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
341 @@ -1484,17 +1537,21 @@ else
342 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
343 endif
344
345 -%.s: %.c prepare scripts FORCE
346 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
347 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
348 +%.s: %.c gcc-plugins prepare scripts FORCE
349 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
350 %.i: %.c prepare scripts FORCE
351 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
352 -%.o: %.c prepare scripts FORCE
353 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
354 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
355 +%.o: %.c gcc-plugins prepare scripts FORCE
356 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
357 %.lst: %.c prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 -%.s: %.S prepare scripts FORCE
360 +%.s: %.S gcc-plugins prepare scripts FORCE
361 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
362 -%.o: %.S prepare scripts FORCE
363 +%.o: %.S gcc-plugins prepare scripts FORCE
364 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
365 %.symtypes: %.c prepare scripts FORCE
366 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
367 @@ -1504,11 +1561,15 @@ endif
368 $(cmd_crmodverdir)
369 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
370 $(build)=$(build-dir)
371 -%/: prepare scripts FORCE
372 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
373 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
374 +%/: gcc-plugins prepare scripts FORCE
375 $(cmd_crmodverdir)
376 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
377 $(build)=$(build-dir)
378 -%.ko: prepare scripts FORCE
379 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
380 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
381 +%.ko: gcc-plugins prepare scripts FORCE
382 $(cmd_crmodverdir)
383 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
384 $(build)=$(build-dir) $(@:.ko=.o)
385 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
386 index 640f909..48b6597 100644
387 --- a/arch/alpha/include/asm/atomic.h
388 +++ b/arch/alpha/include/asm/atomic.h
389 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
390 #define atomic_dec(v) atomic_sub(1,(v))
391 #define atomic64_dec(v) atomic64_sub(1,(v))
392
393 +#define atomic64_read_unchecked(v) atomic64_read(v)
394 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
395 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
396 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
397 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
398 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
399 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
400 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
401 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
402 +
403 #define smp_mb__before_atomic_dec() smp_mb()
404 #define smp_mb__after_atomic_dec() smp_mb()
405 #define smp_mb__before_atomic_inc() smp_mb()
406 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
407 index ad368a9..fbe0f25 100644
408 --- a/arch/alpha/include/asm/cache.h
409 +++ b/arch/alpha/include/asm/cache.h
410 @@ -4,19 +4,19 @@
411 #ifndef __ARCH_ALPHA_CACHE_H
412 #define __ARCH_ALPHA_CACHE_H
413
414 +#include <linux/const.h>
415
416 /* Bytes per L1 (data) cache line. */
417 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
418 -# define L1_CACHE_BYTES 64
419 # define L1_CACHE_SHIFT 6
420 #else
421 /* Both EV4 and EV5 are write-through, read-allocate,
422 direct-mapped, physical.
423 */
424 -# define L1_CACHE_BYTES 32
425 # define L1_CACHE_SHIFT 5
426 #endif
427
428 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
429 #define SMP_CACHE_BYTES L1_CACHE_BYTES
430
431 #endif
432 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
433 index da5449e..7418343 100644
434 --- a/arch/alpha/include/asm/elf.h
435 +++ b/arch/alpha/include/asm/elf.h
436 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
437
438 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
439
440 +#ifdef CONFIG_PAX_ASLR
441 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
442 +
443 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
444 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
445 +#endif
446 +
447 /* $0 is set by ld.so to a pointer to a function which might be
448 registered using atexit. This provides a mean for the dynamic
449 linker to call DT_FINI functions for shared libraries that have
450 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
451 index de98a73..bd4f1f8 100644
452 --- a/arch/alpha/include/asm/pgtable.h
453 +++ b/arch/alpha/include/asm/pgtable.h
454 @@ -101,6 +101,17 @@ struct vm_area_struct;
455 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
456 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
457 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
458 +
459 +#ifdef CONFIG_PAX_PAGEEXEC
460 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
461 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
462 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
463 +#else
464 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
465 +# define PAGE_COPY_NOEXEC PAGE_COPY
466 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
467 +#endif
468 +
469 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
470
471 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
472 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
473 index 2fd00b7..cfd5069 100644
474 --- a/arch/alpha/kernel/module.c
475 +++ b/arch/alpha/kernel/module.c
476 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
477
478 /* The small sections were sorted to the end of the segment.
479 The following should definitely cover them. */
480 - gp = (u64)me->module_core + me->core_size - 0x8000;
481 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
482 got = sechdrs[me->arch.gotsecindex].sh_addr;
483
484 for (i = 0; i < n; i++) {
485 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
486 index 01e8715..be0e80f 100644
487 --- a/arch/alpha/kernel/osf_sys.c
488 +++ b/arch/alpha/kernel/osf_sys.c
489 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
490 /* At this point: (!vma || addr < vma->vm_end). */
491 if (limit - len < addr)
492 return -ENOMEM;
493 - if (!vma || addr + len <= vma->vm_start)
494 + if (check_heap_stack_gap(vma, addr, len))
495 return addr;
496 addr = vma->vm_end;
497 vma = vma->vm_next;
498 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
499 merely specific addresses, but regions of memory -- perhaps
500 this feature should be incorporated into all ports? */
501
502 +#ifdef CONFIG_PAX_RANDMMAP
503 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
504 +#endif
505 +
506 if (addr) {
507 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
508 if (addr != (unsigned long) -ENOMEM)
509 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
510 }
511
512 /* Next, try allocating at TASK_UNMAPPED_BASE. */
513 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
514 - len, limit);
515 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
516 +
517 if (addr != (unsigned long) -ENOMEM)
518 return addr;
519
520 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
521 index fadd5f8..904e73a 100644
522 --- a/arch/alpha/mm/fault.c
523 +++ b/arch/alpha/mm/fault.c
524 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
525 __reload_thread(pcb);
526 }
527
528 +#ifdef CONFIG_PAX_PAGEEXEC
529 +/*
530 + * PaX: decide what to do with offenders (regs->pc = fault address)
531 + *
532 + * returns 1 when task should be killed
533 + * 2 when patched PLT trampoline was detected
534 + * 3 when unpatched PLT trampoline was detected
535 + */
536 +static int pax_handle_fetch_fault(struct pt_regs *regs)
537 +{
538 +
539 +#ifdef CONFIG_PAX_EMUPLT
540 + int err;
541 +
542 + do { /* PaX: patched PLT emulation #1 */
543 + unsigned int ldah, ldq, jmp;
544 +
545 + err = get_user(ldah, (unsigned int *)regs->pc);
546 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
547 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
548 +
549 + if (err)
550 + break;
551 +
552 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
553 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
554 + jmp == 0x6BFB0000U)
555 + {
556 + unsigned long r27, addr;
557 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
558 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
559 +
560 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
561 + err = get_user(r27, (unsigned long *)addr);
562 + if (err)
563 + break;
564 +
565 + regs->r27 = r27;
566 + regs->pc = r27;
567 + return 2;
568 + }
569 + } while (0);
570 +
571 + do { /* PaX: patched PLT emulation #2 */
572 + unsigned int ldah, lda, br;
573 +
574 + err = get_user(ldah, (unsigned int *)regs->pc);
575 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
576 + err |= get_user(br, (unsigned int *)(regs->pc+8));
577 +
578 + if (err)
579 + break;
580 +
581 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
582 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
583 + (br & 0xFFE00000U) == 0xC3E00000U)
584 + {
585 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
586 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
587 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
588 +
589 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
590 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
591 + return 2;
592 + }
593 + } while (0);
594 +
595 + do { /* PaX: unpatched PLT emulation */
596 + unsigned int br;
597 +
598 + err = get_user(br, (unsigned int *)regs->pc);
599 +
600 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
601 + unsigned int br2, ldq, nop, jmp;
602 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
603 +
604 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
605 + err = get_user(br2, (unsigned int *)addr);
606 + err |= get_user(ldq, (unsigned int *)(addr+4));
607 + err |= get_user(nop, (unsigned int *)(addr+8));
608 + err |= get_user(jmp, (unsigned int *)(addr+12));
609 + err |= get_user(resolver, (unsigned long *)(addr+16));
610 +
611 + if (err)
612 + break;
613 +
614 + if (br2 == 0xC3600000U &&
615 + ldq == 0xA77B000CU &&
616 + nop == 0x47FF041FU &&
617 + jmp == 0x6B7B0000U)
618 + {
619 + regs->r28 = regs->pc+4;
620 + regs->r27 = addr+16;
621 + regs->pc = resolver;
622 + return 3;
623 + }
624 + }
625 + } while (0);
626 +#endif
627 +
628 + return 1;
629 +}
630 +
631 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
632 +{
633 + unsigned long i;
634 +
635 + printk(KERN_ERR "PAX: bytes at PC: ");
636 + for (i = 0; i < 5; i++) {
637 + unsigned int c;
638 + if (get_user(c, (unsigned int *)pc+i))
639 + printk(KERN_CONT "???????? ");
640 + else
641 + printk(KERN_CONT "%08x ", c);
642 + }
643 + printk("\n");
644 +}
645 +#endif
646
647 /*
648 * This routine handles page faults. It determines the address,
649 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
650 good_area:
651 si_code = SEGV_ACCERR;
652 if (cause < 0) {
653 - if (!(vma->vm_flags & VM_EXEC))
654 + if (!(vma->vm_flags & VM_EXEC)) {
655 +
656 +#ifdef CONFIG_PAX_PAGEEXEC
657 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
658 + goto bad_area;
659 +
660 + up_read(&mm->mmap_sem);
661 + switch (pax_handle_fetch_fault(regs)) {
662 +
663 +#ifdef CONFIG_PAX_EMUPLT
664 + case 2:
665 + case 3:
666 + return;
667 +#endif
668 +
669 + }
670 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
671 + do_group_exit(SIGKILL);
672 +#else
673 goto bad_area;
674 +#endif
675 +
676 + }
677 } else if (!cause) {
678 /* Allow reads even for write-only mappings */
679 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
680 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
681 index 86976d0..683de93 100644
682 --- a/arch/arm/include/asm/atomic.h
683 +++ b/arch/arm/include/asm/atomic.h
684 @@ -15,6 +15,10 @@
685 #include <linux/types.h>
686 #include <asm/system.h>
687
688 +#ifdef CONFIG_GENERIC_ATOMIC64
689 +#include <asm-generic/atomic64.h>
690 +#endif
691 +
692 #define ATOMIC_INIT(i) { (i) }
693
694 #ifdef __KERNEL__
695 @@ -25,7 +29,15 @@
696 * atomic_set() is the clrex or dummy strex done on every exception return.
697 */
698 #define atomic_read(v) (*(volatile int *)&(v)->counter)
699 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
700 +{
701 + return v->counter;
702 +}
703 #define atomic_set(v,i) (((v)->counter) = (i))
704 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
705 +{
706 + v->counter = i;
707 +}
708
709 #if __LINUX_ARM_ARCH__ >= 6
710
711 @@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
712 int result;
713
714 __asm__ __volatile__("@ atomic_add\n"
715 +"1: ldrex %1, [%3]\n"
716 +" adds %0, %1, %4\n"
717 +
718 +#ifdef CONFIG_PAX_REFCOUNT
719 +" bvc 3f\n"
720 +"2: bkpt 0xf103\n"
721 +"3:\n"
722 +#endif
723 +
724 +" strex %1, %0, [%3]\n"
725 +" teq %1, #0\n"
726 +" bne 1b"
727 +
728 +#ifdef CONFIG_PAX_REFCOUNT
729 +"\n4:\n"
730 + _ASM_EXTABLE(2b, 4b)
731 +#endif
732 +
733 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
734 + : "r" (&v->counter), "Ir" (i)
735 + : "cc");
736 +}
737 +
738 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
739 +{
740 + unsigned long tmp;
741 + int result;
742 +
743 + __asm__ __volatile__("@ atomic_add_unchecked\n"
744 "1: ldrex %0, [%3]\n"
745 " add %0, %0, %4\n"
746 " strex %1, %0, [%3]\n"
747 @@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
748 smp_mb();
749
750 __asm__ __volatile__("@ atomic_add_return\n"
751 +"1: ldrex %1, [%3]\n"
752 +" adds %0, %1, %4\n"
753 +
754 +#ifdef CONFIG_PAX_REFCOUNT
755 +" bvc 3f\n"
756 +" mov %0, %1\n"
757 +"2: bkpt 0xf103\n"
758 +"3:\n"
759 +#endif
760 +
761 +" strex %1, %0, [%3]\n"
762 +" teq %1, #0\n"
763 +" bne 1b"
764 +
765 +#ifdef CONFIG_PAX_REFCOUNT
766 +"\n4:\n"
767 + _ASM_EXTABLE(2b, 4b)
768 +#endif
769 +
770 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
771 + : "r" (&v->counter), "Ir" (i)
772 + : "cc");
773 +
774 + smp_mb();
775 +
776 + return result;
777 +}
778 +
779 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
780 +{
781 + unsigned long tmp;
782 + int result;
783 +
784 + smp_mb();
785 +
786 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
787 "1: ldrex %0, [%3]\n"
788 " add %0, %0, %4\n"
789 " strex %1, %0, [%3]\n"
790 @@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
791 int result;
792
793 __asm__ __volatile__("@ atomic_sub\n"
794 +"1: ldrex %1, [%3]\n"
795 +" subs %0, %1, %4\n"
796 +
797 +#ifdef CONFIG_PAX_REFCOUNT
798 +" bvc 3f\n"
799 +"2: bkpt 0xf103\n"
800 +"3:\n"
801 +#endif
802 +
803 +" strex %1, %0, [%3]\n"
804 +" teq %1, #0\n"
805 +" bne 1b"
806 +
807 +#ifdef CONFIG_PAX_REFCOUNT
808 +"\n4:\n"
809 + _ASM_EXTABLE(2b, 4b)
810 +#endif
811 +
812 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
813 + : "r" (&v->counter), "Ir" (i)
814 + : "cc");
815 +}
816 +
817 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
818 +{
819 + unsigned long tmp;
820 + int result;
821 +
822 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
823 "1: ldrex %0, [%3]\n"
824 " sub %0, %0, %4\n"
825 " strex %1, %0, [%3]\n"
826 @@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
827 smp_mb();
828
829 __asm__ __volatile__("@ atomic_sub_return\n"
830 -"1: ldrex %0, [%3]\n"
831 -" sub %0, %0, %4\n"
832 +"1: ldrex %1, [%3]\n"
833 +" sub %0, %1, %4\n"
834 +
835 +#ifdef CONFIG_PAX_REFCOUNT
836 +" bvc 3f\n"
837 +" mov %0, %1\n"
838 +"2: bkpt 0xf103\n"
839 +"3:\n"
840 +#endif
841 +
842 " strex %1, %0, [%3]\n"
843 " teq %1, #0\n"
844 " bne 1b"
845 +
846 +#ifdef CONFIG_PAX_REFCOUNT
847 +"\n4:\n"
848 + _ASM_EXTABLE(2b, 4b)
849 +#endif
850 +
851 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
852 : "r" (&v->counter), "Ir" (i)
853 : "cc");
854 @@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
855 return oldval;
856 }
857
858 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
859 +{
860 + unsigned long oldval, res;
861 +
862 + smp_mb();
863 +
864 + do {
865 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
866 + "ldrex %1, [%3]\n"
867 + "mov %0, #0\n"
868 + "teq %1, %4\n"
869 + "strexeq %0, %5, [%3]\n"
870 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
871 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
872 + : "cc");
873 + } while (res);
874 +
875 + smp_mb();
876 +
877 + return oldval;
878 +}
879 +
880 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
881 {
882 unsigned long tmp, tmp2;
883 @@ -207,6 +349,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
884 #endif /* __LINUX_ARM_ARCH__ */
885
886 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
887 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
888 +{
889 + return xchg(&v->counter, new);
890 +}
891
892 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
893 {
894 @@ -219,11 +365,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
895 }
896
897 #define atomic_inc(v) atomic_add(1, v)
898 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
899 +{
900 + atomic_add_unchecked(1, v);
901 +}
902 #define atomic_dec(v) atomic_sub(1, v)
903 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
904 +{
905 + atomic_sub_unchecked(1, v);
906 +}
907
908 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
909 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
910 +{
911 + return atomic_add_return_unchecked(1, v) == 0;
912 +}
913 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
914 #define atomic_inc_return(v) (atomic_add_return(1, v))
915 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
916 +{
917 + return atomic_add_return_unchecked(1, v);
918 +}
919 #define atomic_dec_return(v) (atomic_sub_return(1, v))
920 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
921
922 @@ -239,6 +401,14 @@ typedef struct {
923 u64 __aligned(8) counter;
924 } atomic64_t;
925
926 +#ifdef CONFIG_PAX_REFCOUNT
927 +typedef struct {
928 + u64 __aligned(8) counter;
929 +} atomic64_unchecked_t;
930 +#else
931 +typedef atomic64_t atomic64_unchecked_t;
932 +#endif
933 +
934 #define ATOMIC64_INIT(i) { (i) }
935
936 static inline u64 atomic64_read(atomic64_t *v)
937 @@ -254,6 +424,19 @@ static inline u64 atomic64_read(atomic64_t *v)
938 return result;
939 }
940
941 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
942 +{
943 + u64 result;
944 +
945 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
946 +" ldrexd %0, %H0, [%1]"
947 + : "=&r" (result)
948 + : "r" (&v->counter), "Qo" (v->counter)
949 + );
950 +
951 + return result;
952 +}
953 +
954 static inline void atomic64_set(atomic64_t *v, u64 i)
955 {
956 u64 tmp;
957 @@ -268,6 +451,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
958 : "cc");
959 }
960
961 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
962 +{
963 + u64 tmp;
964 +
965 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
966 +"1: ldrexd %0, %H0, [%2]\n"
967 +" strexd %0, %3, %H3, [%2]\n"
968 +" teq %0, #0\n"
969 +" bne 1b"
970 + : "=&r" (tmp), "=Qo" (v->counter)
971 + : "r" (&v->counter), "r" (i)
972 + : "cc");
973 +}
974 +
975 static inline void atomic64_add(u64 i, atomic64_t *v)
976 {
977 u64 result;
978 @@ -276,6 +473,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
979 __asm__ __volatile__("@ atomic64_add\n"
980 "1: ldrexd %0, %H0, [%3]\n"
981 " adds %0, %0, %4\n"
982 +" adcs %H0, %H0, %H4\n"
983 +
984 +#ifdef CONFIG_PAX_REFCOUNT
985 +" bvc 3f\n"
986 +"2: bkpt 0xf103\n"
987 +"3:\n"
988 +#endif
989 +
990 +" strexd %1, %0, %H0, [%3]\n"
991 +" teq %1, #0\n"
992 +" bne 1b"
993 +
994 +#ifdef CONFIG_PAX_REFCOUNT
995 +"\n4:\n"
996 + _ASM_EXTABLE(2b, 4b)
997 +#endif
998 +
999 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1000 + : "r" (&v->counter), "r" (i)
1001 + : "cc");
1002 +}
1003 +
1004 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1005 +{
1006 + u64 result;
1007 + unsigned long tmp;
1008 +
1009 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1010 +"1: ldrexd %0, %H0, [%3]\n"
1011 +" adds %0, %0, %4\n"
1012 " adc %H0, %H0, %H4\n"
1013 " strexd %1, %0, %H0, [%3]\n"
1014 " teq %1, #0\n"
1015 @@ -287,12 +514,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1016
1017 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1018 {
1019 - u64 result;
1020 - unsigned long tmp;
1021 + u64 result, tmp;
1022
1023 smp_mb();
1024
1025 __asm__ __volatile__("@ atomic64_add_return\n"
1026 +"1: ldrexd %1, %H1, [%3]\n"
1027 +" adds %0, %1, %4\n"
1028 +" adcs %H0, %H1, %H4\n"
1029 +
1030 +#ifdef CONFIG_PAX_REFCOUNT
1031 +" bvc 3f\n"
1032 +" mov %0, %1\n"
1033 +" mov %H0, %H1\n"
1034 +"2: bkpt 0xf103\n"
1035 +"3:\n"
1036 +#endif
1037 +
1038 +" strexd %1, %0, %H0, [%3]\n"
1039 +" teq %1, #0\n"
1040 +" bne 1b"
1041 +
1042 +#ifdef CONFIG_PAX_REFCOUNT
1043 +"\n4:\n"
1044 + _ASM_EXTABLE(2b, 4b)
1045 +#endif
1046 +
1047 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1048 + : "r" (&v->counter), "r" (i)
1049 + : "cc");
1050 +
1051 + smp_mb();
1052 +
1053 + return result;
1054 +}
1055 +
1056 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1057 +{
1058 + u64 result;
1059 + unsigned long tmp;
1060 +
1061 + smp_mb();
1062 +
1063 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1064 "1: ldrexd %0, %H0, [%3]\n"
1065 " adds %0, %0, %4\n"
1066 " adc %H0, %H0, %H4\n"
1067 @@ -316,6 +580,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1068 __asm__ __volatile__("@ atomic64_sub\n"
1069 "1: ldrexd %0, %H0, [%3]\n"
1070 " subs %0, %0, %4\n"
1071 +" sbcs %H0, %H0, %H4\n"
1072 +
1073 +#ifdef CONFIG_PAX_REFCOUNT
1074 +" bvc 3f\n"
1075 +"2: bkpt 0xf103\n"
1076 +"3:\n"
1077 +#endif
1078 +
1079 +" strexd %1, %0, %H0, [%3]\n"
1080 +" teq %1, #0\n"
1081 +" bne 1b"
1082 +
1083 +#ifdef CONFIG_PAX_REFCOUNT
1084 +"\n4:\n"
1085 + _ASM_EXTABLE(2b, 4b)
1086 +#endif
1087 +
1088 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1089 + : "r" (&v->counter), "r" (i)
1090 + : "cc");
1091 +}
1092 +
1093 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1094 +{
1095 + u64 result;
1096 + unsigned long tmp;
1097 +
1098 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1099 +"1: ldrexd %0, %H0, [%3]\n"
1100 +" subs %0, %0, %4\n"
1101 " sbc %H0, %H0, %H4\n"
1102 " strexd %1, %0, %H0, [%3]\n"
1103 " teq %1, #0\n"
1104 @@ -327,18 +621,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1105
1106 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1107 {
1108 - u64 result;
1109 - unsigned long tmp;
1110 + u64 result, tmp;
1111
1112 smp_mb();
1113
1114 __asm__ __volatile__("@ atomic64_sub_return\n"
1115 -"1: ldrexd %0, %H0, [%3]\n"
1116 -" subs %0, %0, %4\n"
1117 -" sbc %H0, %H0, %H4\n"
1118 +"1: ldrexd %1, %H1, [%3]\n"
1119 +" subs %0, %1, %4\n"
1120 +" sbc %H0, %H1, %H4\n"
1121 +
1122 +#ifdef CONFIG_PAX_REFCOUNT
1123 +" bvc 3f\n"
1124 +" mov %0, %1\n"
1125 +" mov %H0, %H1\n"
1126 +"2: bkpt 0xf103\n"
1127 +"3:\n"
1128 +#endif
1129 +
1130 " strexd %1, %0, %H0, [%3]\n"
1131 " teq %1, #0\n"
1132 " bne 1b"
1133 +
1134 +#ifdef CONFIG_PAX_REFCOUNT
1135 +"\n4:\n"
1136 + _ASM_EXTABLE(2b, 4b)
1137 +#endif
1138 +
1139 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1140 : "r" (&v->counter), "r" (i)
1141 : "cc");
1142 @@ -372,6 +680,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1143 return oldval;
1144 }
1145
1146 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1147 +{
1148 + u64 oldval;
1149 + unsigned long res;
1150 +
1151 + smp_mb();
1152 +
1153 + do {
1154 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1155 + "ldrexd %1, %H1, [%3]\n"
1156 + "mov %0, #0\n"
1157 + "teq %1, %4\n"
1158 + "teqeq %H1, %H4\n"
1159 + "strexdeq %0, %5, %H5, [%3]"
1160 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1161 + : "r" (&ptr->counter), "r" (old), "r" (new)
1162 + : "cc");
1163 + } while (res);
1164 +
1165 + smp_mb();
1166 +
1167 + return oldval;
1168 +}
1169 +
1170 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1171 {
1172 u64 result;
1173 @@ -395,21 +727,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1174
1175 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1176 {
1177 - u64 result;
1178 - unsigned long tmp;
1179 + u64 result, tmp;
1180
1181 smp_mb();
1182
1183 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1184 -"1: ldrexd %0, %H0, [%3]\n"
1185 -" subs %0, %0, #1\n"
1186 -" sbc %H0, %H0, #0\n"
1187 +"1: ldrexd %1, %H1, [%3]\n"
1188 +" subs %0, %1, #1\n"
1189 +" sbc %H0, %H1, #0\n"
1190 +
1191 +#ifdef CONFIG_PAX_REFCOUNT
1192 +" bvc 3f\n"
1193 +" mov %0, %1\n"
1194 +" mov %H0, %H1\n"
1195 +"2: bkpt 0xf103\n"
1196 +"3:\n"
1197 +#endif
1198 +
1199 " teq %H0, #0\n"
1200 -" bmi 2f\n"
1201 +" bmi 4f\n"
1202 " strexd %1, %0, %H0, [%3]\n"
1203 " teq %1, #0\n"
1204 " bne 1b\n"
1205 -"2:"
1206 +"4:\n"
1207 +
1208 +#ifdef CONFIG_PAX_REFCOUNT
1209 + _ASM_EXTABLE(2b, 4b)
1210 +#endif
1211 +
1212 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213 : "r" (&v->counter)
1214 : "cc");
1215 @@ -432,13 +777,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1216 " teq %0, %5\n"
1217 " teqeq %H0, %H5\n"
1218 " moveq %1, #0\n"
1219 -" beq 2f\n"
1220 +" beq 4f\n"
1221 " adds %0, %0, %6\n"
1222 " adc %H0, %H0, %H6\n"
1223 +
1224 +#ifdef CONFIG_PAX_REFCOUNT
1225 +" bvc 3f\n"
1226 +"2: bkpt 0xf103\n"
1227 +"3:\n"
1228 +#endif
1229 +
1230 " strexd %2, %0, %H0, [%4]\n"
1231 " teq %2, #0\n"
1232 " bne 1b\n"
1233 -"2:"
1234 +"4:\n"
1235 +
1236 +#ifdef CONFIG_PAX_REFCOUNT
1237 + _ASM_EXTABLE(2b, 4b)
1238 +#endif
1239 +
1240 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1241 : "r" (&v->counter), "r" (u), "r" (a)
1242 : "cc");
1243 @@ -451,10 +808,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1244
1245 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1246 #define atomic64_inc(v) atomic64_add(1LL, (v))
1247 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1248 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1249 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1250 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1251 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1252 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1253 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1254 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1255 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1256 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1257 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1258 index 75fe66b..2255c86 100644
1259 --- a/arch/arm/include/asm/cache.h
1260 +++ b/arch/arm/include/asm/cache.h
1261 @@ -4,8 +4,10 @@
1262 #ifndef __ASMARM_CACHE_H
1263 #define __ASMARM_CACHE_H
1264
1265 +#include <linux/const.h>
1266 +
1267 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1268 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1269 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1270
1271 /*
1272 * Memory returned by kmalloc() may be used for DMA, so we must make
1273 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1274 index d5d8d5c..ad92c96 100644
1275 --- a/arch/arm/include/asm/cacheflush.h
1276 +++ b/arch/arm/include/asm/cacheflush.h
1277 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1278 void (*dma_unmap_area)(const void *, size_t, int);
1279
1280 void (*dma_flush_range)(const void *, const void *);
1281 -};
1282 +} __no_const;
1283
1284 /*
1285 * Select the calling method
1286 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1287 index 0e9ce8d..6ef1e03 100644
1288 --- a/arch/arm/include/asm/elf.h
1289 +++ b/arch/arm/include/asm/elf.h
1290 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1291 the loader. We need to make sure that it is out of the way of the program
1292 that it will "exec", and that there is sufficient room for the brk. */
1293
1294 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1295 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1296 +
1297 +#ifdef CONFIG_PAX_ASLR
1298 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1299 +
1300 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1301 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1302 +#endif
1303
1304 /* When the program starts, a1 contains a pointer to a function to be
1305 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1306 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1307 extern void elf_set_personality(const struct elf32_hdr *);
1308 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1309
1310 -struct mm_struct;
1311 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1312 -#define arch_randomize_brk arch_randomize_brk
1313 -
1314 extern int vectors_user_mapping(void);
1315 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1316 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1317 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1318 index e51b1e8..32a3113 100644
1319 --- a/arch/arm/include/asm/kmap_types.h
1320 +++ b/arch/arm/include/asm/kmap_types.h
1321 @@ -21,6 +21,7 @@ enum km_type {
1322 KM_L1_CACHE,
1323 KM_L2_CACHE,
1324 KM_KDB,
1325 + KM_CLEARPAGE,
1326 KM_TYPE_NR
1327 };
1328
1329 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1330 index 53426c6..c7baff3 100644
1331 --- a/arch/arm/include/asm/outercache.h
1332 +++ b/arch/arm/include/asm/outercache.h
1333 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1334 #endif
1335 void (*set_debug)(unsigned long);
1336 void (*resume)(void);
1337 -};
1338 +} __no_const;
1339
1340 #ifdef CONFIG_OUTER_CACHE
1341
1342 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1343 index ca94653..6ac0d56 100644
1344 --- a/arch/arm/include/asm/page.h
1345 +++ b/arch/arm/include/asm/page.h
1346 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1347 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1348 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1349 unsigned long vaddr, struct vm_area_struct *vma);
1350 -};
1351 +} __no_const;
1352
1353 #ifdef MULTI_USER
1354 extern struct cpu_user_fns cpu_user;
1355 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1356 index 984014b..a6d914f 100644
1357 --- a/arch/arm/include/asm/system.h
1358 +++ b/arch/arm/include/asm/system.h
1359 @@ -90,6 +90,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1360
1361 #define xchg(ptr,x) \
1362 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1363 +#define xchg_unchecked(ptr,x) \
1364 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1365
1366 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1367
1368 @@ -101,7 +103,7 @@ extern int __pure cpu_architecture(void);
1369 extern void cpu_init(void);
1370
1371 void arm_machine_restart(char mode, const char *cmd);
1372 -extern void (*arm_pm_restart)(char str, const char *cmd);
1373 +extern void (*arm_pm_restart)(char str, const char *cmd) __noreturn;
1374
1375 #define UDBG_UNDEFINED (1 << 0)
1376 #define UDBG_SYSCALL (1 << 1)
1377 @@ -526,6 +528,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1378
1379 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1380
1381 +#define _ASM_EXTABLE(from, to) \
1382 +" .pushsection __ex_table,\"a\"\n"\
1383 +" .align 3\n" \
1384 +" .long " #from ", " #to"\n" \
1385 +" .popsection"
1386 +
1387 +
1388 #endif /* __ASSEMBLY__ */
1389
1390 #define arch_align_stack(x) (x)
1391 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1392 index b293616..96310e5 100644
1393 --- a/arch/arm/include/asm/uaccess.h
1394 +++ b/arch/arm/include/asm/uaccess.h
1395 @@ -22,6 +22,8 @@
1396 #define VERIFY_READ 0
1397 #define VERIFY_WRITE 1
1398
1399 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1400 +
1401 /*
1402 * The exception table consists of pairs of addresses: the first is the
1403 * address of an instruction that is allowed to fault, and the second is
1404 @@ -387,8 +389,23 @@ do { \
1405
1406
1407 #ifdef CONFIG_MMU
1408 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1409 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1410 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1411 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1412 +
1413 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1414 +{
1415 + if (!__builtin_constant_p(n))
1416 + check_object_size(to, n, false);
1417 + return ___copy_from_user(to, from, n);
1418 +}
1419 +
1420 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1421 +{
1422 + if (!__builtin_constant_p(n))
1423 + check_object_size(from, n, true);
1424 + return ___copy_to_user(to, from, n);
1425 +}
1426 +
1427 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1428 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1429 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1430 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1431
1432 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1433 {
1434 + if ((long)n < 0)
1435 + return n;
1436 +
1437 if (access_ok(VERIFY_READ, from, n))
1438 n = __copy_from_user(to, from, n);
1439 else /* security hole - plug it */
1440 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1441
1442 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1443 {
1444 + if ((long)n < 0)
1445 + return n;
1446 +
1447 if (access_ok(VERIFY_WRITE, to, n))
1448 n = __copy_to_user(to, from, n);
1449 return n;
1450 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1451 index 5b0bce6..becd81c 100644
1452 --- a/arch/arm/kernel/armksyms.c
1453 +++ b/arch/arm/kernel/armksyms.c
1454 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1455 #ifdef CONFIG_MMU
1456 EXPORT_SYMBOL(copy_page);
1457
1458 -EXPORT_SYMBOL(__copy_from_user);
1459 -EXPORT_SYMBOL(__copy_to_user);
1460 +EXPORT_SYMBOL(___copy_from_user);
1461 +EXPORT_SYMBOL(___copy_to_user);
1462 EXPORT_SYMBOL(__clear_user);
1463
1464 EXPORT_SYMBOL(__get_user_1);
1465 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1466 index 3d0c6fb..9d326fa 100644
1467 --- a/arch/arm/kernel/process.c
1468 +++ b/arch/arm/kernel/process.c
1469 @@ -28,7 +28,6 @@
1470 #include <linux/tick.h>
1471 #include <linux/utsname.h>
1472 #include <linux/uaccess.h>
1473 -#include <linux/random.h>
1474 #include <linux/hw_breakpoint.h>
1475 #include <linux/cpuidle.h>
1476
1477 @@ -92,7 +91,7 @@ static int __init hlt_setup(char *__unused)
1478 __setup("nohlt", nohlt_setup);
1479 __setup("hlt", hlt_setup);
1480
1481 -void arm_machine_restart(char mode, const char *cmd)
1482 +__noreturn void arm_machine_restart(char mode, const char *cmd)
1483 {
1484 /* Disable interrupts first */
1485 local_irq_disable();
1486 @@ -134,7 +133,7 @@ void arm_machine_restart(char mode, const char *cmd)
1487 void (*pm_power_off)(void);
1488 EXPORT_SYMBOL(pm_power_off);
1489
1490 -void (*arm_pm_restart)(char str, const char *cmd) = arm_machine_restart;
1491 +void (*arm_pm_restart)(char str, const char *cmd) __noreturn = arm_machine_restart;
1492 EXPORT_SYMBOL_GPL(arm_pm_restart);
1493
1494 static void do_nothing(void *unused)
1495 @@ -248,6 +247,7 @@ void machine_power_off(void)
1496 machine_shutdown();
1497 if (pm_power_off)
1498 pm_power_off();
1499 + BUG();
1500 }
1501
1502 void machine_restart(char *cmd)
1503 @@ -484,12 +484,6 @@ unsigned long get_wchan(struct task_struct *p)
1504 return 0;
1505 }
1506
1507 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1508 -{
1509 - unsigned long range_end = mm->brk + 0x02000000;
1510 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1511 -}
1512 -
1513 #ifdef CONFIG_MMU
1514 /*
1515 * The vectors page is always readable from user space for the
1516 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1517 index 8fc2c8f..064c150 100644
1518 --- a/arch/arm/kernel/setup.c
1519 +++ b/arch/arm/kernel/setup.c
1520 @@ -108,13 +108,13 @@ struct processor processor __read_mostly;
1521 struct cpu_tlb_fns cpu_tlb __read_mostly;
1522 #endif
1523 #ifdef MULTI_USER
1524 -struct cpu_user_fns cpu_user __read_mostly;
1525 +struct cpu_user_fns cpu_user __read_only;
1526 #endif
1527 #ifdef MULTI_CACHE
1528 -struct cpu_cache_fns cpu_cache __read_mostly;
1529 +struct cpu_cache_fns cpu_cache __read_only;
1530 #endif
1531 #ifdef CONFIG_OUTER_CACHE
1532 -struct outer_cache_fns outer_cache __read_mostly;
1533 +struct outer_cache_fns outer_cache __read_only;
1534 EXPORT_SYMBOL(outer_cache);
1535 #endif
1536
1537 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1538 index 99a5727..a3d5bb1 100644
1539 --- a/arch/arm/kernel/traps.c
1540 +++ b/arch/arm/kernel/traps.c
1541 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1542
1543 static DEFINE_RAW_SPINLOCK(die_lock);
1544
1545 +extern void gr_handle_kernel_exploit(void);
1546 +
1547 /*
1548 * This function is protected against re-entrancy.
1549 */
1550 @@ -288,6 +290,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1551 panic("Fatal exception in interrupt");
1552 if (panic_on_oops)
1553 panic("Fatal exception");
1554 +
1555 + gr_handle_kernel_exploit();
1556 +
1557 if (ret != NOTIFY_STOP)
1558 do_exit(SIGSEGV);
1559 }
1560 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1561 index 66a477a..bee61d3 100644
1562 --- a/arch/arm/lib/copy_from_user.S
1563 +++ b/arch/arm/lib/copy_from_user.S
1564 @@ -16,7 +16,7 @@
1565 /*
1566 * Prototype:
1567 *
1568 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1569 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1570 *
1571 * Purpose:
1572 *
1573 @@ -84,11 +84,11 @@
1574
1575 .text
1576
1577 -ENTRY(__copy_from_user)
1578 +ENTRY(___copy_from_user)
1579
1580 #include "copy_template.S"
1581
1582 -ENDPROC(__copy_from_user)
1583 +ENDPROC(___copy_from_user)
1584
1585 .pushsection .fixup,"ax"
1586 .align 0
1587 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1588 index 6ee2f67..d1cce76 100644
1589 --- a/arch/arm/lib/copy_page.S
1590 +++ b/arch/arm/lib/copy_page.S
1591 @@ -10,6 +10,7 @@
1592 * ASM optimised string functions
1593 */
1594 #include <linux/linkage.h>
1595 +#include <linux/const.h>
1596 #include <asm/assembler.h>
1597 #include <asm/asm-offsets.h>
1598 #include <asm/cache.h>
1599 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1600 index d066df6..df28194 100644
1601 --- a/arch/arm/lib/copy_to_user.S
1602 +++ b/arch/arm/lib/copy_to_user.S
1603 @@ -16,7 +16,7 @@
1604 /*
1605 * Prototype:
1606 *
1607 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1608 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1609 *
1610 * Purpose:
1611 *
1612 @@ -88,11 +88,11 @@
1613 .text
1614
1615 ENTRY(__copy_to_user_std)
1616 -WEAK(__copy_to_user)
1617 +WEAK(___copy_to_user)
1618
1619 #include "copy_template.S"
1620
1621 -ENDPROC(__copy_to_user)
1622 +ENDPROC(___copy_to_user)
1623 ENDPROC(__copy_to_user_std)
1624
1625 .pushsection .fixup,"ax"
1626 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1627 index d0ece2a..5ae2f39 100644
1628 --- a/arch/arm/lib/uaccess.S
1629 +++ b/arch/arm/lib/uaccess.S
1630 @@ -20,7 +20,7 @@
1631
1632 #define PAGE_SHIFT 12
1633
1634 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1635 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1636 * Purpose : copy a block to user memory from kernel memory
1637 * Params : to - user memory
1638 * : from - kernel memory
1639 @@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May fault
1640 sub r2, r2, ip
1641 b .Lc2u_dest_aligned
1642
1643 -ENTRY(__copy_to_user)
1644 +ENTRY(___copy_to_user)
1645 stmfd sp!, {r2, r4 - r7, lr}
1646 cmp r2, #4
1647 blt .Lc2u_not_enough
1648 @@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May fault
1649 ldrgtb r3, [r1], #0
1650 USER( T(strgtb) r3, [r0], #1) @ May fault
1651 b .Lc2u_finished
1652 -ENDPROC(__copy_to_user)
1653 +ENDPROC(___copy_to_user)
1654
1655 .pushsection .fixup,"ax"
1656 .align 0
1657 9001: ldmfd sp!, {r0, r4 - r7, pc}
1658 .popsection
1659
1660 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1661 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1662 * Purpose : copy a block from user memory to kernel memory
1663 * Params : to - kernel memory
1664 * : from - user memory
1665 @@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May fault
1666 sub r2, r2, ip
1667 b .Lcfu_dest_aligned
1668
1669 -ENTRY(__copy_from_user)
1670 +ENTRY(___copy_from_user)
1671 stmfd sp!, {r0, r2, r4 - r7, lr}
1672 cmp r2, #4
1673 blt .Lcfu_not_enough
1674 @@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May fault
1675 USER( T(ldrgtb) r3, [r1], #1) @ May fault
1676 strgtb r3, [r0], #1
1677 b .Lcfu_finished
1678 -ENDPROC(__copy_from_user)
1679 +ENDPROC(___copy_from_user)
1680
1681 .pushsection .fixup,"ax"
1682 .align 0
1683 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1684 index 025f742..8432b08 100644
1685 --- a/arch/arm/lib/uaccess_with_memcpy.c
1686 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1687 @@ -104,7 +104,7 @@ out:
1688 }
1689
1690 unsigned long
1691 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1692 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1693 {
1694 /*
1695 * This test is stubbed out of the main function above to keep
1696 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1697 index e9d5f4a..f099699 100644
1698 --- a/arch/arm/mach-omap2/board-n8x0.c
1699 +++ b/arch/arm/mach-omap2/board-n8x0.c
1700 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1701 }
1702 #endif
1703
1704 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1705 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1706 .late_init = n8x0_menelaus_late_init,
1707 };
1708
1709 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1710 index 2b2d51c..0127490 100644
1711 --- a/arch/arm/mach-ux500/mbox-db5500.c
1712 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1713 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1714 return sprintf(buf, "0x%X\n", mbox_value);
1715 }
1716
1717 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1718 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1719
1720 static int mbox_show(struct seq_file *s, void *data)
1721 {
1722 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1723 index aa33949..d366075 100644
1724 --- a/arch/arm/mm/fault.c
1725 +++ b/arch/arm/mm/fault.c
1726 @@ -183,6 +183,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1727 }
1728 #endif
1729
1730 +#ifdef CONFIG_PAX_PAGEEXEC
1731 + if (fsr & FSR_LNX_PF) {
1732 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1733 + do_group_exit(SIGKILL);
1734 + }
1735 +#endif
1736 +
1737 tsk->thread.address = addr;
1738 tsk->thread.error_code = fsr;
1739 tsk->thread.trap_no = 14;
1740 @@ -384,6 +391,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1741 }
1742 #endif /* CONFIG_MMU */
1743
1744 +#ifdef CONFIG_PAX_PAGEEXEC
1745 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1746 +{
1747 + long i;
1748 +
1749 + printk(KERN_ERR "PAX: bytes at PC: ");
1750 + for (i = 0; i < 20; i++) {
1751 + unsigned char c;
1752 + if (get_user(c, (__force unsigned char __user *)pc+i))
1753 + printk(KERN_CONT "?? ");
1754 + else
1755 + printk(KERN_CONT "%02x ", c);
1756 + }
1757 + printk("\n");
1758 +
1759 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1760 + for (i = -1; i < 20; i++) {
1761 + unsigned long c;
1762 + if (get_user(c, (__force unsigned long __user *)sp+i))
1763 + printk(KERN_CONT "???????? ");
1764 + else
1765 + printk(KERN_CONT "%08lx ", c);
1766 + }
1767 + printk("\n");
1768 +}
1769 +#endif
1770 +
1771 /*
1772 * First Level Translation Fault Handler
1773 *
1774 @@ -628,6 +662,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1775 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1776 struct siginfo info;
1777
1778 +#ifdef CONFIG_PAX_REFCOUNT
1779 + if (fsr_fs(ifsr) == 2) {
1780 + unsigned int bkpt;
1781 +
1782 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1783 + current->thread.error_code = ifsr;
1784 + current->thread.trap_no = 0;
1785 + pax_report_refcount_overflow(regs);
1786 + fixup_exception(regs);
1787 + return;
1788 + }
1789 + }
1790 +#endif
1791 +
1792 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1793 return;
1794
1795 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1796 index 44b628e..623ee2a 100644
1797 --- a/arch/arm/mm/mmap.c
1798 +++ b/arch/arm/mm/mmap.c
1799 @@ -54,6 +54,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1800 if (len > TASK_SIZE)
1801 return -ENOMEM;
1802
1803 +#ifdef CONFIG_PAX_RANDMMAP
1804 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1805 +#endif
1806 +
1807 if (addr) {
1808 if (do_align)
1809 addr = COLOUR_ALIGN(addr, pgoff);
1810 @@ -61,15 +65,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1811 addr = PAGE_ALIGN(addr);
1812
1813 vma = find_vma(mm, addr);
1814 - if (TASK_SIZE - len >= addr &&
1815 - (!vma || addr + len <= vma->vm_start))
1816 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1817 return addr;
1818 }
1819 if (len > mm->cached_hole_size) {
1820 - start_addr = addr = mm->free_area_cache;
1821 + start_addr = addr = mm->free_area_cache;
1822 } else {
1823 - start_addr = addr = TASK_UNMAPPED_BASE;
1824 - mm->cached_hole_size = 0;
1825 + start_addr = addr = mm->mmap_base;
1826 + mm->cached_hole_size = 0;
1827 }
1828 /* 8 bits of randomness in 20 address space bits */
1829 if ((current->flags & PF_RANDOMIZE) &&
1830 @@ -89,14 +92,14 @@ full_search:
1831 * Start a new search - just in case we missed
1832 * some holes.
1833 */
1834 - if (start_addr != TASK_UNMAPPED_BASE) {
1835 - start_addr = addr = TASK_UNMAPPED_BASE;
1836 + if (start_addr != mm->mmap_base) {
1837 + start_addr = addr = mm->mmap_base;
1838 mm->cached_hole_size = 0;
1839 goto full_search;
1840 }
1841 return -ENOMEM;
1842 }
1843 - if (!vma || addr + len <= vma->vm_start) {
1844 + if (check_heap_stack_gap(vma, addr, len)) {
1845 /*
1846 * Remember the place where we stopped the search:
1847 */
1848 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1849 index 4c1a363..df311d0 100644
1850 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1851 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1852 @@ -41,7 +41,7 @@ struct samsung_dma_ops {
1853 int (*started)(unsigned ch);
1854 int (*flush)(unsigned ch);
1855 int (*stop)(unsigned ch);
1856 -};
1857 +} __no_const;
1858
1859 extern void *samsung_dmadev_get_ops(void);
1860 extern void *s3c_dma_get_ops(void);
1861 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1862 index 5f28cae..3d23723 100644
1863 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1864 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1865 @@ -14,7 +14,7 @@
1866 struct s5p_ehci_platdata {
1867 int (*phy_init)(struct platform_device *pdev, int type);
1868 int (*phy_exit)(struct platform_device *pdev, int type);
1869 -};
1870 +} __no_const;
1871
1872 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1873
1874 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1875 index c3a58a1..78fbf54 100644
1876 --- a/arch/avr32/include/asm/cache.h
1877 +++ b/arch/avr32/include/asm/cache.h
1878 @@ -1,8 +1,10 @@
1879 #ifndef __ASM_AVR32_CACHE_H
1880 #define __ASM_AVR32_CACHE_H
1881
1882 +#include <linux/const.h>
1883 +
1884 #define L1_CACHE_SHIFT 5
1885 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1886 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1887
1888 /*
1889 * Memory returned by kmalloc() may be used for DMA, so we must make
1890 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1891 index 3b3159b..425ea94 100644
1892 --- a/arch/avr32/include/asm/elf.h
1893 +++ b/arch/avr32/include/asm/elf.h
1894 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1895 the loader. We need to make sure that it is out of the way of the program
1896 that it will "exec", and that there is sufficient room for the brk. */
1897
1898 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1899 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1900
1901 +#ifdef CONFIG_PAX_ASLR
1902 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1903 +
1904 +#define PAX_DELTA_MMAP_LEN 15
1905 +#define PAX_DELTA_STACK_LEN 15
1906 +#endif
1907
1908 /* This yields a mask that user programs can use to figure out what
1909 instruction set this CPU supports. This could be done in user space,
1910 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1911 index b7f5c68..556135c 100644
1912 --- a/arch/avr32/include/asm/kmap_types.h
1913 +++ b/arch/avr32/include/asm/kmap_types.h
1914 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1915 D(11) KM_IRQ1,
1916 D(12) KM_SOFTIRQ0,
1917 D(13) KM_SOFTIRQ1,
1918 -D(14) KM_TYPE_NR
1919 +D(14) KM_CLEARPAGE,
1920 +D(15) KM_TYPE_NR
1921 };
1922
1923 #undef D
1924 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1925 index f7040a1..db9f300 100644
1926 --- a/arch/avr32/mm/fault.c
1927 +++ b/arch/avr32/mm/fault.c
1928 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1929
1930 int exception_trace = 1;
1931
1932 +#ifdef CONFIG_PAX_PAGEEXEC
1933 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1934 +{
1935 + unsigned long i;
1936 +
1937 + printk(KERN_ERR "PAX: bytes at PC: ");
1938 + for (i = 0; i < 20; i++) {
1939 + unsigned char c;
1940 + if (get_user(c, (unsigned char *)pc+i))
1941 + printk(KERN_CONT "???????? ");
1942 + else
1943 + printk(KERN_CONT "%02x ", c);
1944 + }
1945 + printk("\n");
1946 +}
1947 +#endif
1948 +
1949 /*
1950 * This routine handles page faults. It determines the address and the
1951 * problem, and then passes it off to one of the appropriate routines.
1952 @@ -156,6 +173,16 @@ bad_area:
1953 up_read(&mm->mmap_sem);
1954
1955 if (user_mode(regs)) {
1956 +
1957 +#ifdef CONFIG_PAX_PAGEEXEC
1958 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1959 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1960 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1961 + do_group_exit(SIGKILL);
1962 + }
1963 + }
1964 +#endif
1965 +
1966 if (exception_trace && printk_ratelimit())
1967 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1968 "sp %08lx ecr %lu\n",
1969 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
1970 index 568885a..f8008df 100644
1971 --- a/arch/blackfin/include/asm/cache.h
1972 +++ b/arch/blackfin/include/asm/cache.h
1973 @@ -7,6 +7,7 @@
1974 #ifndef __ARCH_BLACKFIN_CACHE_H
1975 #define __ARCH_BLACKFIN_CACHE_H
1976
1977 +#include <linux/const.h>
1978 #include <linux/linkage.h> /* for asmlinkage */
1979
1980 /*
1981 @@ -14,7 +15,7 @@
1982 * Blackfin loads 32 bytes for cache
1983 */
1984 #define L1_CACHE_SHIFT 5
1985 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1986 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1987 #define SMP_CACHE_BYTES L1_CACHE_BYTES
1988
1989 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
1990 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
1991 index aea2718..3639a60 100644
1992 --- a/arch/cris/include/arch-v10/arch/cache.h
1993 +++ b/arch/cris/include/arch-v10/arch/cache.h
1994 @@ -1,8 +1,9 @@
1995 #ifndef _ASM_ARCH_CACHE_H
1996 #define _ASM_ARCH_CACHE_H
1997
1998 +#include <linux/const.h>
1999 /* Etrax 100LX have 32-byte cache-lines. */
2000 -#define L1_CACHE_BYTES 32
2001 #define L1_CACHE_SHIFT 5
2002 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2003
2004 #endif /* _ASM_ARCH_CACHE_H */
2005 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2006 index 1de779f..336fad3 100644
2007 --- a/arch/cris/include/arch-v32/arch/cache.h
2008 +++ b/arch/cris/include/arch-v32/arch/cache.h
2009 @@ -1,11 +1,12 @@
2010 #ifndef _ASM_CRIS_ARCH_CACHE_H
2011 #define _ASM_CRIS_ARCH_CACHE_H
2012
2013 +#include <linux/const.h>
2014 #include <arch/hwregs/dma.h>
2015
2016 /* A cache-line is 32 bytes. */
2017 -#define L1_CACHE_BYTES 32
2018 #define L1_CACHE_SHIFT 5
2019 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2020
2021 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2022
2023 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2024 index 0d8a7d6..d0c9ff5 100644
2025 --- a/arch/frv/include/asm/atomic.h
2026 +++ b/arch/frv/include/asm/atomic.h
2027 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2028 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2029 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2030
2031 +#define atomic64_read_unchecked(v) atomic64_read(v)
2032 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2033 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2034 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2035 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2036 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2037 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2038 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2039 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2040 +
2041 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2042 {
2043 int c, old;
2044 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2045 index 2797163..c2a401d 100644
2046 --- a/arch/frv/include/asm/cache.h
2047 +++ b/arch/frv/include/asm/cache.h
2048 @@ -12,10 +12,11 @@
2049 #ifndef __ASM_CACHE_H
2050 #define __ASM_CACHE_H
2051
2052 +#include <linux/const.h>
2053
2054 /* bytes per L1 cache line */
2055 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2056 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2057 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2058
2059 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2060 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2061 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2062 index f8e16b2..c73ff79 100644
2063 --- a/arch/frv/include/asm/kmap_types.h
2064 +++ b/arch/frv/include/asm/kmap_types.h
2065 @@ -23,6 +23,7 @@ enum km_type {
2066 KM_IRQ1,
2067 KM_SOFTIRQ0,
2068 KM_SOFTIRQ1,
2069 + KM_CLEARPAGE,
2070 KM_TYPE_NR
2071 };
2072
2073 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2074 index 385fd30..6c3d97e 100644
2075 --- a/arch/frv/mm/elf-fdpic.c
2076 +++ b/arch/frv/mm/elf-fdpic.c
2077 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2078 if (addr) {
2079 addr = PAGE_ALIGN(addr);
2080 vma = find_vma(current->mm, addr);
2081 - if (TASK_SIZE - len >= addr &&
2082 - (!vma || addr + len <= vma->vm_start))
2083 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2084 goto success;
2085 }
2086
2087 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2088 for (; vma; vma = vma->vm_next) {
2089 if (addr > limit)
2090 break;
2091 - if (addr + len <= vma->vm_start)
2092 + if (check_heap_stack_gap(vma, addr, len))
2093 goto success;
2094 addr = vma->vm_end;
2095 }
2096 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2097 for (; vma; vma = vma->vm_next) {
2098 if (addr > limit)
2099 break;
2100 - if (addr + len <= vma->vm_start)
2101 + if (check_heap_stack_gap(vma, addr, len))
2102 goto success;
2103 addr = vma->vm_end;
2104 }
2105 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2106 index c635028..6d9445a 100644
2107 --- a/arch/h8300/include/asm/cache.h
2108 +++ b/arch/h8300/include/asm/cache.h
2109 @@ -1,8 +1,10 @@
2110 #ifndef __ARCH_H8300_CACHE_H
2111 #define __ARCH_H8300_CACHE_H
2112
2113 +#include <linux/const.h>
2114 +
2115 /* bytes per L1 cache line */
2116 -#define L1_CACHE_BYTES 4
2117 +#define L1_CACHE_BYTES _AC(4,UL)
2118
2119 /* m68k-elf-gcc 2.95.2 doesn't like these */
2120
2121 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2122 index 0f01de2..d37d309 100644
2123 --- a/arch/hexagon/include/asm/cache.h
2124 +++ b/arch/hexagon/include/asm/cache.h
2125 @@ -21,9 +21,11 @@
2126 #ifndef __ASM_CACHE_H
2127 #define __ASM_CACHE_H
2128
2129 +#include <linux/const.h>
2130 +
2131 /* Bytes per L1 cache line */
2132 -#define L1_CACHE_SHIFT (5)
2133 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2134 +#define L1_CACHE_SHIFT 5
2135 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2136
2137 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2138 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2139 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2140 index 3fad89e..3047da5 100644
2141 --- a/arch/ia64/include/asm/atomic.h
2142 +++ b/arch/ia64/include/asm/atomic.h
2143 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2144 #define atomic64_inc(v) atomic64_add(1, (v))
2145 #define atomic64_dec(v) atomic64_sub(1, (v))
2146
2147 +#define atomic64_read_unchecked(v) atomic64_read(v)
2148 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2149 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2150 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2151 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2152 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2153 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2154 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2155 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2156 +
2157 /* Atomic operations are already serializing */
2158 #define smp_mb__before_atomic_dec() barrier()
2159 #define smp_mb__after_atomic_dec() barrier()
2160 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2161 index 988254a..e1ee885 100644
2162 --- a/arch/ia64/include/asm/cache.h
2163 +++ b/arch/ia64/include/asm/cache.h
2164 @@ -1,6 +1,7 @@
2165 #ifndef _ASM_IA64_CACHE_H
2166 #define _ASM_IA64_CACHE_H
2167
2168 +#include <linux/const.h>
2169
2170 /*
2171 * Copyright (C) 1998-2000 Hewlett-Packard Co
2172 @@ -9,7 +10,7 @@
2173
2174 /* Bytes per L1 (data) cache line. */
2175 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2176 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2177 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2178
2179 #ifdef CONFIG_SMP
2180 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2181 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2182 index b5298eb..67c6e62 100644
2183 --- a/arch/ia64/include/asm/elf.h
2184 +++ b/arch/ia64/include/asm/elf.h
2185 @@ -42,6 +42,13 @@
2186 */
2187 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2188
2189 +#ifdef CONFIG_PAX_ASLR
2190 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2191 +
2192 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2193 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2194 +#endif
2195 +
2196 #define PT_IA_64_UNWIND 0x70000001
2197
2198 /* IA-64 relocations: */
2199 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2200 index 1a97af3..7529d31 100644
2201 --- a/arch/ia64/include/asm/pgtable.h
2202 +++ b/arch/ia64/include/asm/pgtable.h
2203 @@ -12,7 +12,7 @@
2204 * David Mosberger-Tang <davidm@hpl.hp.com>
2205 */
2206
2207 -
2208 +#include <linux/const.h>
2209 #include <asm/mman.h>
2210 #include <asm/page.h>
2211 #include <asm/processor.h>
2212 @@ -143,6 +143,17 @@
2213 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2214 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2215 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2216 +
2217 +#ifdef CONFIG_PAX_PAGEEXEC
2218 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2219 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2220 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2221 +#else
2222 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2223 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2224 +# define PAGE_COPY_NOEXEC PAGE_COPY
2225 +#endif
2226 +
2227 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2228 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2229 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2230 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2231 index b77768d..e0795eb 100644
2232 --- a/arch/ia64/include/asm/spinlock.h
2233 +++ b/arch/ia64/include/asm/spinlock.h
2234 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2235 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2236
2237 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2238 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2239 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2240 }
2241
2242 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2243 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2244 index 449c8c0..432a3d2 100644
2245 --- a/arch/ia64/include/asm/uaccess.h
2246 +++ b/arch/ia64/include/asm/uaccess.h
2247 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2248 const void *__cu_from = (from); \
2249 long __cu_len = (n); \
2250 \
2251 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2252 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2253 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2254 __cu_len; \
2255 })
2256 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2257 long __cu_len = (n); \
2258 \
2259 __chk_user_ptr(__cu_from); \
2260 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2261 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2262 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2263 __cu_len; \
2264 })
2265 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2266 index 24603be..948052d 100644
2267 --- a/arch/ia64/kernel/module.c
2268 +++ b/arch/ia64/kernel/module.c
2269 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2270 void
2271 module_free (struct module *mod, void *module_region)
2272 {
2273 - if (mod && mod->arch.init_unw_table &&
2274 - module_region == mod->module_init) {
2275 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2276 unw_remove_unwind_table(mod->arch.init_unw_table);
2277 mod->arch.init_unw_table = NULL;
2278 }
2279 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2280 }
2281
2282 static inline int
2283 +in_init_rx (const struct module *mod, uint64_t addr)
2284 +{
2285 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2286 +}
2287 +
2288 +static inline int
2289 +in_init_rw (const struct module *mod, uint64_t addr)
2290 +{
2291 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2292 +}
2293 +
2294 +static inline int
2295 in_init (const struct module *mod, uint64_t addr)
2296 {
2297 - return addr - (uint64_t) mod->module_init < mod->init_size;
2298 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2299 +}
2300 +
2301 +static inline int
2302 +in_core_rx (const struct module *mod, uint64_t addr)
2303 +{
2304 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2305 +}
2306 +
2307 +static inline int
2308 +in_core_rw (const struct module *mod, uint64_t addr)
2309 +{
2310 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2311 }
2312
2313 static inline int
2314 in_core (const struct module *mod, uint64_t addr)
2315 {
2316 - return addr - (uint64_t) mod->module_core < mod->core_size;
2317 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2318 }
2319
2320 static inline int
2321 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2322 break;
2323
2324 case RV_BDREL:
2325 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2326 + if (in_init_rx(mod, val))
2327 + val -= (uint64_t) mod->module_init_rx;
2328 + else if (in_init_rw(mod, val))
2329 + val -= (uint64_t) mod->module_init_rw;
2330 + else if (in_core_rx(mod, val))
2331 + val -= (uint64_t) mod->module_core_rx;
2332 + else if (in_core_rw(mod, val))
2333 + val -= (uint64_t) mod->module_core_rw;
2334 break;
2335
2336 case RV_LTV:
2337 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2338 * addresses have been selected...
2339 */
2340 uint64_t gp;
2341 - if (mod->core_size > MAX_LTOFF)
2342 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2343 /*
2344 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2345 * at the end of the module.
2346 */
2347 - gp = mod->core_size - MAX_LTOFF / 2;
2348 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2349 else
2350 - gp = mod->core_size / 2;
2351 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2352 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2353 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2354 mod->arch.gp = gp;
2355 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2356 }
2357 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2358 index 609d500..7dde2a8 100644
2359 --- a/arch/ia64/kernel/sys_ia64.c
2360 +++ b/arch/ia64/kernel/sys_ia64.c
2361 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2362 if (REGION_NUMBER(addr) == RGN_HPAGE)
2363 addr = 0;
2364 #endif
2365 +
2366 +#ifdef CONFIG_PAX_RANDMMAP
2367 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2368 + addr = mm->free_area_cache;
2369 + else
2370 +#endif
2371 +
2372 if (!addr)
2373 addr = mm->free_area_cache;
2374
2375 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2376 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2377 /* At this point: (!vma || addr < vma->vm_end). */
2378 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2379 - if (start_addr != TASK_UNMAPPED_BASE) {
2380 + if (start_addr != mm->mmap_base) {
2381 /* Start a new search --- just in case we missed some holes. */
2382 - addr = TASK_UNMAPPED_BASE;
2383 + addr = mm->mmap_base;
2384 goto full_search;
2385 }
2386 return -ENOMEM;
2387 }
2388 - if (!vma || addr + len <= vma->vm_start) {
2389 + if (check_heap_stack_gap(vma, addr, len)) {
2390 /* Remember the address where we stopped this search: */
2391 mm->free_area_cache = addr + len;
2392 return addr;
2393 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2394 index 53c0ba0..2accdde 100644
2395 --- a/arch/ia64/kernel/vmlinux.lds.S
2396 +++ b/arch/ia64/kernel/vmlinux.lds.S
2397 @@ -199,7 +199,7 @@ SECTIONS {
2398 /* Per-cpu data: */
2399 . = ALIGN(PERCPU_PAGE_SIZE);
2400 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2401 - __phys_per_cpu_start = __per_cpu_load;
2402 + __phys_per_cpu_start = per_cpu_load;
2403 /*
2404 * ensure percpu data fits
2405 * into percpu page size
2406 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2407 index 20b3593..1ce77f0 100644
2408 --- a/arch/ia64/mm/fault.c
2409 +++ b/arch/ia64/mm/fault.c
2410 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2411 return pte_present(pte);
2412 }
2413
2414 +#ifdef CONFIG_PAX_PAGEEXEC
2415 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2416 +{
2417 + unsigned long i;
2418 +
2419 + printk(KERN_ERR "PAX: bytes at PC: ");
2420 + for (i = 0; i < 8; i++) {
2421 + unsigned int c;
2422 + if (get_user(c, (unsigned int *)pc+i))
2423 + printk(KERN_CONT "???????? ");
2424 + else
2425 + printk(KERN_CONT "%08x ", c);
2426 + }
2427 + printk("\n");
2428 +}
2429 +#endif
2430 +
2431 void __kprobes
2432 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2433 {
2434 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2435 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2436 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2437
2438 - if ((vma->vm_flags & mask) != mask)
2439 + if ((vma->vm_flags & mask) != mask) {
2440 +
2441 +#ifdef CONFIG_PAX_PAGEEXEC
2442 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2443 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2444 + goto bad_area;
2445 +
2446 + up_read(&mm->mmap_sem);
2447 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2448 + do_group_exit(SIGKILL);
2449 + }
2450 +#endif
2451 +
2452 goto bad_area;
2453
2454 + }
2455 +
2456 /*
2457 * If for any reason at all we couldn't handle the fault, make
2458 * sure we exit gracefully rather than endlessly redo the
2459 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2460 index 5ca674b..e0e1b70 100644
2461 --- a/arch/ia64/mm/hugetlbpage.c
2462 +++ b/arch/ia64/mm/hugetlbpage.c
2463 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2464 /* At this point: (!vmm || addr < vmm->vm_end). */
2465 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2466 return -ENOMEM;
2467 - if (!vmm || (addr + len) <= vmm->vm_start)
2468 + if (check_heap_stack_gap(vmm, addr, len))
2469 return addr;
2470 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2471 }
2472 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2473 index 00cb0e2..2ad8024 100644
2474 --- a/arch/ia64/mm/init.c
2475 +++ b/arch/ia64/mm/init.c
2476 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2477 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2478 vma->vm_end = vma->vm_start + PAGE_SIZE;
2479 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2480 +
2481 +#ifdef CONFIG_PAX_PAGEEXEC
2482 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2483 + vma->vm_flags &= ~VM_EXEC;
2484 +
2485 +#ifdef CONFIG_PAX_MPROTECT
2486 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2487 + vma->vm_flags &= ~VM_MAYEXEC;
2488 +#endif
2489 +
2490 + }
2491 +#endif
2492 +
2493 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2494 down_write(&current->mm->mmap_sem);
2495 if (insert_vm_struct(current->mm, vma)) {
2496 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2497 index 40b3ee9..8c2c112 100644
2498 --- a/arch/m32r/include/asm/cache.h
2499 +++ b/arch/m32r/include/asm/cache.h
2500 @@ -1,8 +1,10 @@
2501 #ifndef _ASM_M32R_CACHE_H
2502 #define _ASM_M32R_CACHE_H
2503
2504 +#include <linux/const.h>
2505 +
2506 /* L1 cache line size */
2507 #define L1_CACHE_SHIFT 4
2508 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2509 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2510
2511 #endif /* _ASM_M32R_CACHE_H */
2512 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2513 index 82abd15..d95ae5d 100644
2514 --- a/arch/m32r/lib/usercopy.c
2515 +++ b/arch/m32r/lib/usercopy.c
2516 @@ -14,6 +14,9 @@
2517 unsigned long
2518 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2519 {
2520 + if ((long)n < 0)
2521 + return n;
2522 +
2523 prefetch(from);
2524 if (access_ok(VERIFY_WRITE, to, n))
2525 __copy_user(to,from,n);
2526 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2527 unsigned long
2528 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2529 {
2530 + if ((long)n < 0)
2531 + return n;
2532 +
2533 prefetchw(to);
2534 if (access_ok(VERIFY_READ, from, n))
2535 __copy_user_zeroing(to,from,n);
2536 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2537 index 0395c51..5f26031 100644
2538 --- a/arch/m68k/include/asm/cache.h
2539 +++ b/arch/m68k/include/asm/cache.h
2540 @@ -4,9 +4,11 @@
2541 #ifndef __ARCH_M68K_CACHE_H
2542 #define __ARCH_M68K_CACHE_H
2543
2544 +#include <linux/const.h>
2545 +
2546 /* bytes per L1 cache line */
2547 #define L1_CACHE_SHIFT 4
2548 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2549 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2550
2551 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2552
2553 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2554 index 4efe96a..60e8699 100644
2555 --- a/arch/microblaze/include/asm/cache.h
2556 +++ b/arch/microblaze/include/asm/cache.h
2557 @@ -13,11 +13,12 @@
2558 #ifndef _ASM_MICROBLAZE_CACHE_H
2559 #define _ASM_MICROBLAZE_CACHE_H
2560
2561 +#include <linux/const.h>
2562 #include <asm/registers.h>
2563
2564 #define L1_CACHE_SHIFT 5
2565 /* word-granular cache in microblaze */
2566 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2567 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2568
2569 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2570
2571 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2572 index 1d93f81..67794d0 100644
2573 --- a/arch/mips/include/asm/atomic.h
2574 +++ b/arch/mips/include/asm/atomic.h
2575 @@ -21,6 +21,10 @@
2576 #include <asm/war.h>
2577 #include <asm/system.h>
2578
2579 +#ifdef CONFIG_GENERIC_ATOMIC64
2580 +#include <asm-generic/atomic64.h>
2581 +#endif
2582 +
2583 #define ATOMIC_INIT(i) { (i) }
2584
2585 /*
2586 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2587 */
2588 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2589
2590 +#define atomic64_read_unchecked(v) atomic64_read(v)
2591 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2592 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2593 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2594 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2595 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2596 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2597 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2598 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2599 +
2600 #endif /* CONFIG_64BIT */
2601
2602 /*
2603 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2604 index b4db69f..8f3b093 100644
2605 --- a/arch/mips/include/asm/cache.h
2606 +++ b/arch/mips/include/asm/cache.h
2607 @@ -9,10 +9,11 @@
2608 #ifndef _ASM_CACHE_H
2609 #define _ASM_CACHE_H
2610
2611 +#include <linux/const.h>
2612 #include <kmalloc.h>
2613
2614 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2615 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2616 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2617
2618 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2619 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2620 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2621 index 455c0ac..ad65fbe 100644
2622 --- a/arch/mips/include/asm/elf.h
2623 +++ b/arch/mips/include/asm/elf.h
2624 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2625 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2626 #endif
2627
2628 +#ifdef CONFIG_PAX_ASLR
2629 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2630 +
2631 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2632 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2633 +#endif
2634 +
2635 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2636 struct linux_binprm;
2637 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2638 int uses_interp);
2639
2640 -struct mm_struct;
2641 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2642 -#define arch_randomize_brk arch_randomize_brk
2643 -
2644 #endif /* _ASM_ELF_H */
2645 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2646 index e59cd1a..8e329d6 100644
2647 --- a/arch/mips/include/asm/page.h
2648 +++ b/arch/mips/include/asm/page.h
2649 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2650 #ifdef CONFIG_CPU_MIPS32
2651 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2652 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2653 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2654 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2655 #else
2656 typedef struct { unsigned long long pte; } pte_t;
2657 #define pte_val(x) ((x).pte)
2658 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2659 index 6018c80..7c37203 100644
2660 --- a/arch/mips/include/asm/system.h
2661 +++ b/arch/mips/include/asm/system.h
2662 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2663 */
2664 #define __ARCH_WANT_UNLOCKED_CTXSW
2665
2666 -extern unsigned long arch_align_stack(unsigned long sp);
2667 +#define arch_align_stack(x) ((x) & ~0xfUL)
2668
2669 #endif /* _ASM_SYSTEM_H */
2670 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2671 index 9fdd8bc..4bd7f1a 100644
2672 --- a/arch/mips/kernel/binfmt_elfn32.c
2673 +++ b/arch/mips/kernel/binfmt_elfn32.c
2674 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2675 #undef ELF_ET_DYN_BASE
2676 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2677
2678 +#ifdef CONFIG_PAX_ASLR
2679 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2680 +
2681 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2682 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2683 +#endif
2684 +
2685 #include <asm/processor.h>
2686 #include <linux/module.h>
2687 #include <linux/elfcore.h>
2688 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2689 index ff44823..97f8906 100644
2690 --- a/arch/mips/kernel/binfmt_elfo32.c
2691 +++ b/arch/mips/kernel/binfmt_elfo32.c
2692 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2693 #undef ELF_ET_DYN_BASE
2694 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2695
2696 +#ifdef CONFIG_PAX_ASLR
2697 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2698 +
2699 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2700 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2701 +#endif
2702 +
2703 #include <asm/processor.h>
2704
2705 /*
2706 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2707 index c47f96e..661d418 100644
2708 --- a/arch/mips/kernel/process.c
2709 +++ b/arch/mips/kernel/process.c
2710 @@ -481,15 +481,3 @@ unsigned long get_wchan(struct task_struct *task)
2711 out:
2712 return pc;
2713 }
2714 -
2715 -/*
2716 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2717 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2718 - */
2719 -unsigned long arch_align_stack(unsigned long sp)
2720 -{
2721 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2722 - sp -= get_random_int() & ~PAGE_MASK;
2723 -
2724 - return sp & ALMASK;
2725 -}
2726 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2727 index 937cf33..adb39bb 100644
2728 --- a/arch/mips/mm/fault.c
2729 +++ b/arch/mips/mm/fault.c
2730 @@ -28,6 +28,23 @@
2731 #include <asm/highmem.h> /* For VMALLOC_END */
2732 #include <linux/kdebug.h>
2733
2734 +#ifdef CONFIG_PAX_PAGEEXEC
2735 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2736 +{
2737 + unsigned long i;
2738 +
2739 + printk(KERN_ERR "PAX: bytes at PC: ");
2740 + for (i = 0; i < 5; i++) {
2741 + unsigned int c;
2742 + if (get_user(c, (unsigned int *)pc+i))
2743 + printk(KERN_CONT "???????? ");
2744 + else
2745 + printk(KERN_CONT "%08x ", c);
2746 + }
2747 + printk("\n");
2748 +}
2749 +#endif
2750 +
2751 /*
2752 * This routine handles page faults. It determines the address,
2753 * and the problem, and then passes it off to one of the appropriate
2754 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2755 index 302d779..7d35bf8 100644
2756 --- a/arch/mips/mm/mmap.c
2757 +++ b/arch/mips/mm/mmap.c
2758 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2759 do_color_align = 1;
2760
2761 /* requesting a specific address */
2762 +
2763 +#ifdef CONFIG_PAX_RANDMMAP
2764 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2765 +#endif
2766 +
2767 if (addr) {
2768 if (do_color_align)
2769 addr = COLOUR_ALIGN(addr, pgoff);
2770 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2771 addr = PAGE_ALIGN(addr);
2772
2773 vma = find_vma(mm, addr);
2774 - if (TASK_SIZE - len >= addr &&
2775 - (!vma || addr + len <= vma->vm_start))
2776 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2777 return addr;
2778 }
2779
2780 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2781 /* At this point: (!vma || addr < vma->vm_end). */
2782 if (TASK_SIZE - len < addr)
2783 return -ENOMEM;
2784 - if (!vma || addr + len <= vma->vm_start)
2785 + if (check_heap_stack_gap(vmm, addr, len))
2786 return addr;
2787 addr = vma->vm_end;
2788 if (do_color_align)
2789 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2790 /* make sure it can fit in the remaining address space */
2791 if (likely(addr > len)) {
2792 vma = find_vma(mm, addr - len);
2793 - if (!vma || addr <= vma->vm_start) {
2794 + if (check_heap_stack_gap(vmm, addr - len, len))
2795 /* cache the address as a hint for next time */
2796 return mm->free_area_cache = addr - len;
2797 }
2798 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2799 * return with success:
2800 */
2801 vma = find_vma(mm, addr);
2802 - if (likely(!vma || addr + len <= vma->vm_start)) {
2803 + if (check_heap_stack_gap(vmm, addr, len)) {
2804 /* cache the address as a hint for next time */
2805 return mm->free_area_cache = addr;
2806 }
2807 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2808 mm->unmap_area = arch_unmap_area_topdown;
2809 }
2810 }
2811 -
2812 -static inline unsigned long brk_rnd(void)
2813 -{
2814 - unsigned long rnd = get_random_int();
2815 -
2816 - rnd = rnd << PAGE_SHIFT;
2817 - /* 8MB for 32bit, 256MB for 64bit */
2818 - if (TASK_IS_32BIT_ADDR)
2819 - rnd = rnd & 0x7ffffful;
2820 - else
2821 - rnd = rnd & 0xffffffful;
2822 -
2823 - return rnd;
2824 -}
2825 -
2826 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2827 -{
2828 - unsigned long base = mm->brk;
2829 - unsigned long ret;
2830 -
2831 - ret = PAGE_ALIGN(base + brk_rnd());
2832 -
2833 - if (ret < mm->brk)
2834 - return mm->brk;
2835 -
2836 - return ret;
2837 -}
2838 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2839 index 967d144..db12197 100644
2840 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2841 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2842 @@ -11,12 +11,14 @@
2843 #ifndef _ASM_PROC_CACHE_H
2844 #define _ASM_PROC_CACHE_H
2845
2846 +#include <linux/const.h>
2847 +
2848 /* L1 cache */
2849
2850 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2851 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2852 -#define L1_CACHE_BYTES 16 /* bytes per entry */
2853 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2854 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2855 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2856
2857 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2858 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2859 index bcb5df2..84fabd2 100644
2860 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2861 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2862 @@ -16,13 +16,15 @@
2863 #ifndef _ASM_PROC_CACHE_H
2864 #define _ASM_PROC_CACHE_H
2865
2866 +#include <linux/const.h>
2867 +
2868 /*
2869 * L1 cache
2870 */
2871 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2872 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2873 -#define L1_CACHE_BYTES 32 /* bytes per entry */
2874 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2875 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2876 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
2877
2878 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2879 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
2880 index 4ce7a01..449202a 100644
2881 --- a/arch/openrisc/include/asm/cache.h
2882 +++ b/arch/openrisc/include/asm/cache.h
2883 @@ -19,11 +19,13 @@
2884 #ifndef __ASM_OPENRISC_CACHE_H
2885 #define __ASM_OPENRISC_CACHE_H
2886
2887 +#include <linux/const.h>
2888 +
2889 /* FIXME: How can we replace these with values from the CPU...
2890 * they shouldn't be hard-coded!
2891 */
2892
2893 -#define L1_CACHE_BYTES 16
2894 #define L1_CACHE_SHIFT 4
2895 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2896
2897 #endif /* __ASM_OPENRISC_CACHE_H */
2898 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
2899 index 4054b31..a10c105 100644
2900 --- a/arch/parisc/include/asm/atomic.h
2901 +++ b/arch/parisc/include/asm/atomic.h
2902 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2903
2904 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2905
2906 +#define atomic64_read_unchecked(v) atomic64_read(v)
2907 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2908 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2909 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2910 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2911 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2912 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2913 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2914 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2915 +
2916 #endif /* !CONFIG_64BIT */
2917
2918
2919 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
2920 index 47f11c7..3420df2 100644
2921 --- a/arch/parisc/include/asm/cache.h
2922 +++ b/arch/parisc/include/asm/cache.h
2923 @@ -5,6 +5,7 @@
2924 #ifndef __ARCH_PARISC_CACHE_H
2925 #define __ARCH_PARISC_CACHE_H
2926
2927 +#include <linux/const.h>
2928
2929 /*
2930 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
2931 @@ -15,13 +16,13 @@
2932 * just ruin performance.
2933 */
2934 #ifdef CONFIG_PA20
2935 -#define L1_CACHE_BYTES 64
2936 #define L1_CACHE_SHIFT 6
2937 #else
2938 -#define L1_CACHE_BYTES 32
2939 #define L1_CACHE_SHIFT 5
2940 #endif
2941
2942 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2943 +
2944 #ifndef __ASSEMBLY__
2945
2946 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2947 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2948 index 19f6cb1..6c78cf2 100644
2949 --- a/arch/parisc/include/asm/elf.h
2950 +++ b/arch/parisc/include/asm/elf.h
2951 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
2952
2953 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2954
2955 +#ifdef CONFIG_PAX_ASLR
2956 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2957 +
2958 +#define PAX_DELTA_MMAP_LEN 16
2959 +#define PAX_DELTA_STACK_LEN 16
2960 +#endif
2961 +
2962 /* This yields a mask that user programs can use to figure out what
2963 instruction set this CPU supports. This could be done in user space,
2964 but it's not easy, and we've already done it here. */
2965 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2966 index 22dadeb..f6c2be4 100644
2967 --- a/arch/parisc/include/asm/pgtable.h
2968 +++ b/arch/parisc/include/asm/pgtable.h
2969 @@ -210,6 +210,17 @@ struct vm_area_struct;
2970 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2971 #define PAGE_COPY PAGE_EXECREAD
2972 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2973 +
2974 +#ifdef CONFIG_PAX_PAGEEXEC
2975 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2976 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2977 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2978 +#else
2979 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2980 +# define PAGE_COPY_NOEXEC PAGE_COPY
2981 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2982 +#endif
2983 +
2984 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2985 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
2986 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
2987 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
2988 index 5e34ccf..672bc9c 100644
2989 --- a/arch/parisc/kernel/module.c
2990 +++ b/arch/parisc/kernel/module.c
2991 @@ -98,16 +98,38 @@
2992
2993 /* three functions to determine where in the module core
2994 * or init pieces the location is */
2995 +static inline int in_init_rx(struct module *me, void *loc)
2996 +{
2997 + return (loc >= me->module_init_rx &&
2998 + loc < (me->module_init_rx + me->init_size_rx));
2999 +}
3000 +
3001 +static inline int in_init_rw(struct module *me, void *loc)
3002 +{
3003 + return (loc >= me->module_init_rw &&
3004 + loc < (me->module_init_rw + me->init_size_rw));
3005 +}
3006 +
3007 static inline int in_init(struct module *me, void *loc)
3008 {
3009 - return (loc >= me->module_init &&
3010 - loc <= (me->module_init + me->init_size));
3011 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3012 +}
3013 +
3014 +static inline int in_core_rx(struct module *me, void *loc)
3015 +{
3016 + return (loc >= me->module_core_rx &&
3017 + loc < (me->module_core_rx + me->core_size_rx));
3018 +}
3019 +
3020 +static inline int in_core_rw(struct module *me, void *loc)
3021 +{
3022 + return (loc >= me->module_core_rw &&
3023 + loc < (me->module_core_rw + me->core_size_rw));
3024 }
3025
3026 static inline int in_core(struct module *me, void *loc)
3027 {
3028 - return (loc >= me->module_core &&
3029 - loc <= (me->module_core + me->core_size));
3030 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3031 }
3032
3033 static inline int in_local(struct module *me, void *loc)
3034 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3035 }
3036
3037 /* align things a bit */
3038 - me->core_size = ALIGN(me->core_size, 16);
3039 - me->arch.got_offset = me->core_size;
3040 - me->core_size += gots * sizeof(struct got_entry);
3041 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3042 + me->arch.got_offset = me->core_size_rw;
3043 + me->core_size_rw += gots * sizeof(struct got_entry);
3044
3045 - me->core_size = ALIGN(me->core_size, 16);
3046 - me->arch.fdesc_offset = me->core_size;
3047 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3048 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3049 + me->arch.fdesc_offset = me->core_size_rw;
3050 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3051
3052 me->arch.got_max = gots;
3053 me->arch.fdesc_max = fdescs;
3054 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3055
3056 BUG_ON(value == 0);
3057
3058 - got = me->module_core + me->arch.got_offset;
3059 + got = me->module_core_rw + me->arch.got_offset;
3060 for (i = 0; got[i].addr; i++)
3061 if (got[i].addr == value)
3062 goto out;
3063 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3064 #ifdef CONFIG_64BIT
3065 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3066 {
3067 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3068 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3069
3070 if (!value) {
3071 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3072 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3073
3074 /* Create new one */
3075 fdesc->addr = value;
3076 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3077 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3078 return (Elf_Addr)fdesc;
3079 }
3080 #endif /* CONFIG_64BIT */
3081 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3082
3083 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3084 end = table + sechdrs[me->arch.unwind_section].sh_size;
3085 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3086 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3087
3088 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3089 me->arch.unwind_section, table, end, gp);
3090 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3091 index c9b9322..02d8940 100644
3092 --- a/arch/parisc/kernel/sys_parisc.c
3093 +++ b/arch/parisc/kernel/sys_parisc.c
3094 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3095 /* At this point: (!vma || addr < vma->vm_end). */
3096 if (TASK_SIZE - len < addr)
3097 return -ENOMEM;
3098 - if (!vma || addr + len <= vma->vm_start)
3099 + if (check_heap_stack_gap(vma, addr, len))
3100 return addr;
3101 addr = vma->vm_end;
3102 }
3103 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3104 /* At this point: (!vma || addr < vma->vm_end). */
3105 if (TASK_SIZE - len < addr)
3106 return -ENOMEM;
3107 - if (!vma || addr + len <= vma->vm_start)
3108 + if (check_heap_stack_gap(vma, addr, len))
3109 return addr;
3110 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3111 if (addr < vma->vm_end) /* handle wraparound */
3112 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3113 if (flags & MAP_FIXED)
3114 return addr;
3115 if (!addr)
3116 - addr = TASK_UNMAPPED_BASE;
3117 + addr = current->mm->mmap_base;
3118
3119 if (filp) {
3120 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3121 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3122 index f19e660..414fe24 100644
3123 --- a/arch/parisc/kernel/traps.c
3124 +++ b/arch/parisc/kernel/traps.c
3125 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3126
3127 down_read(&current->mm->mmap_sem);
3128 vma = find_vma(current->mm,regs->iaoq[0]);
3129 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3130 - && (vma->vm_flags & VM_EXEC)) {
3131 -
3132 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3133 fault_address = regs->iaoq[0];
3134 fault_space = regs->iasq[0];
3135
3136 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3137 index 18162ce..94de376 100644
3138 --- a/arch/parisc/mm/fault.c
3139 +++ b/arch/parisc/mm/fault.c
3140 @@ -15,6 +15,7 @@
3141 #include <linux/sched.h>
3142 #include <linux/interrupt.h>
3143 #include <linux/module.h>
3144 +#include <linux/unistd.h>
3145
3146 #include <asm/uaccess.h>
3147 #include <asm/traps.h>
3148 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3149 static unsigned long
3150 parisc_acctyp(unsigned long code, unsigned int inst)
3151 {
3152 - if (code == 6 || code == 16)
3153 + if (code == 6 || code == 7 || code == 16)
3154 return VM_EXEC;
3155
3156 switch (inst & 0xf0000000) {
3157 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3158 }
3159 #endif
3160
3161 +#ifdef CONFIG_PAX_PAGEEXEC
3162 +/*
3163 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3164 + *
3165 + * returns 1 when task should be killed
3166 + * 2 when rt_sigreturn trampoline was detected
3167 + * 3 when unpatched PLT trampoline was detected
3168 + */
3169 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3170 +{
3171 +
3172 +#ifdef CONFIG_PAX_EMUPLT
3173 + int err;
3174 +
3175 + do { /* PaX: unpatched PLT emulation */
3176 + unsigned int bl, depwi;
3177 +
3178 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3179 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3180 +
3181 + if (err)
3182 + break;
3183 +
3184 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3185 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3186 +
3187 + err = get_user(ldw, (unsigned int *)addr);
3188 + err |= get_user(bv, (unsigned int *)(addr+4));
3189 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3190 +
3191 + if (err)
3192 + break;
3193 +
3194 + if (ldw == 0x0E801096U &&
3195 + bv == 0xEAC0C000U &&
3196 + ldw2 == 0x0E881095U)
3197 + {
3198 + unsigned int resolver, map;
3199 +
3200 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3201 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3202 + if (err)
3203 + break;
3204 +
3205 + regs->gr[20] = instruction_pointer(regs)+8;
3206 + regs->gr[21] = map;
3207 + regs->gr[22] = resolver;
3208 + regs->iaoq[0] = resolver | 3UL;
3209 + regs->iaoq[1] = regs->iaoq[0] + 4;
3210 + return 3;
3211 + }
3212 + }
3213 + } while (0);
3214 +#endif
3215 +
3216 +#ifdef CONFIG_PAX_EMUTRAMP
3217 +
3218 +#ifndef CONFIG_PAX_EMUSIGRT
3219 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3220 + return 1;
3221 +#endif
3222 +
3223 + do { /* PaX: rt_sigreturn emulation */
3224 + unsigned int ldi1, ldi2, bel, nop;
3225 +
3226 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3227 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3228 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3229 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3230 +
3231 + if (err)
3232 + break;
3233 +
3234 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3235 + ldi2 == 0x3414015AU &&
3236 + bel == 0xE4008200U &&
3237 + nop == 0x08000240U)
3238 + {
3239 + regs->gr[25] = (ldi1 & 2) >> 1;
3240 + regs->gr[20] = __NR_rt_sigreturn;
3241 + regs->gr[31] = regs->iaoq[1] + 16;
3242 + regs->sr[0] = regs->iasq[1];
3243 + regs->iaoq[0] = 0x100UL;
3244 + regs->iaoq[1] = regs->iaoq[0] + 4;
3245 + regs->iasq[0] = regs->sr[2];
3246 + regs->iasq[1] = regs->sr[2];
3247 + return 2;
3248 + }
3249 + } while (0);
3250 +#endif
3251 +
3252 + return 1;
3253 +}
3254 +
3255 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3256 +{
3257 + unsigned long i;
3258 +
3259 + printk(KERN_ERR "PAX: bytes at PC: ");
3260 + for (i = 0; i < 5; i++) {
3261 + unsigned int c;
3262 + if (get_user(c, (unsigned int *)pc+i))
3263 + printk(KERN_CONT "???????? ");
3264 + else
3265 + printk(KERN_CONT "%08x ", c);
3266 + }
3267 + printk("\n");
3268 +}
3269 +#endif
3270 +
3271 int fixup_exception(struct pt_regs *regs)
3272 {
3273 const struct exception_table_entry *fix;
3274 @@ -192,8 +303,33 @@ good_area:
3275
3276 acc_type = parisc_acctyp(code,regs->iir);
3277
3278 - if ((vma->vm_flags & acc_type) != acc_type)
3279 + if ((vma->vm_flags & acc_type) != acc_type) {
3280 +
3281 +#ifdef CONFIG_PAX_PAGEEXEC
3282 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3283 + (address & ~3UL) == instruction_pointer(regs))
3284 + {
3285 + up_read(&mm->mmap_sem);
3286 + switch (pax_handle_fetch_fault(regs)) {
3287 +
3288 +#ifdef CONFIG_PAX_EMUPLT
3289 + case 3:
3290 + return;
3291 +#endif
3292 +
3293 +#ifdef CONFIG_PAX_EMUTRAMP
3294 + case 2:
3295 + return;
3296 +#endif
3297 +
3298 + }
3299 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3300 + do_group_exit(SIGKILL);
3301 + }
3302 +#endif
3303 +
3304 goto bad_area;
3305 + }
3306
3307 /*
3308 * If for any reason at all we couldn't handle the fault, make
3309 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3310 index 02e41b5..ec6e26c 100644
3311 --- a/arch/powerpc/include/asm/atomic.h
3312 +++ b/arch/powerpc/include/asm/atomic.h
3313 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3314
3315 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3316
3317 +#define atomic64_read_unchecked(v) atomic64_read(v)
3318 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3319 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3320 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3321 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3322 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3323 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3324 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3325 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3326 +
3327 #endif /* __powerpc64__ */
3328
3329 #endif /* __KERNEL__ */
3330 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3331 index 4b50941..5605819 100644
3332 --- a/arch/powerpc/include/asm/cache.h
3333 +++ b/arch/powerpc/include/asm/cache.h
3334 @@ -3,6 +3,7 @@
3335
3336 #ifdef __KERNEL__
3337
3338 +#include <linux/const.h>
3339
3340 /* bytes per L1 cache line */
3341 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3342 @@ -22,7 +23,7 @@
3343 #define L1_CACHE_SHIFT 7
3344 #endif
3345
3346 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3347 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3348
3349 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3350
3351 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3352 index 3bf9cca..e7457d0 100644
3353 --- a/arch/powerpc/include/asm/elf.h
3354 +++ b/arch/powerpc/include/asm/elf.h
3355 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3356 the loader. We need to make sure that it is out of the way of the program
3357 that it will "exec", and that there is sufficient room for the brk. */
3358
3359 -extern unsigned long randomize_et_dyn(unsigned long base);
3360 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3361 +#define ELF_ET_DYN_BASE (0x20000000)
3362 +
3363 +#ifdef CONFIG_PAX_ASLR
3364 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3365 +
3366 +#ifdef __powerpc64__
3367 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3368 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3369 +#else
3370 +#define PAX_DELTA_MMAP_LEN 15
3371 +#define PAX_DELTA_STACK_LEN 15
3372 +#endif
3373 +#endif
3374
3375 /*
3376 * Our registers are always unsigned longs, whether we're a 32 bit
3377 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3378 (0x7ff >> (PAGE_SHIFT - 12)) : \
3379 (0x3ffff >> (PAGE_SHIFT - 12)))
3380
3381 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3382 -#define arch_randomize_brk arch_randomize_brk
3383 -
3384 #endif /* __KERNEL__ */
3385
3386 /*
3387 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3388 index bca8fdc..61e9580 100644
3389 --- a/arch/powerpc/include/asm/kmap_types.h
3390 +++ b/arch/powerpc/include/asm/kmap_types.h
3391 @@ -27,6 +27,7 @@ enum km_type {
3392 KM_PPC_SYNC_PAGE,
3393 KM_PPC_SYNC_ICACHE,
3394 KM_KDB,
3395 + KM_CLEARPAGE,
3396 KM_TYPE_NR
3397 };
3398
3399 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3400 index d4a7f64..451de1c 100644
3401 --- a/arch/powerpc/include/asm/mman.h
3402 +++ b/arch/powerpc/include/asm/mman.h
3403 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3404 }
3405 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3406
3407 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3408 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3409 {
3410 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3411 }
3412 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3413 index dd9c4fd..a2ced87 100644
3414 --- a/arch/powerpc/include/asm/page.h
3415 +++ b/arch/powerpc/include/asm/page.h
3416 @@ -141,8 +141,9 @@ extern phys_addr_t kernstart_addr;
3417 * and needs to be executable. This means the whole heap ends
3418 * up being executable.
3419 */
3420 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3421 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3422 +#define VM_DATA_DEFAULT_FLAGS32 \
3423 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3424 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3425
3426 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3427 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3428 @@ -170,6 +171,9 @@ extern phys_addr_t kernstart_addr;
3429 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3430 #endif
3431
3432 +#define ktla_ktva(addr) (addr)
3433 +#define ktva_ktla(addr) (addr)
3434 +
3435 /*
3436 * Use the top bit of the higher-level page table entries to indicate whether
3437 * the entries we point to contain hugepages. This works because we know that
3438 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3439 index fb40ede..d3ce956 100644
3440 --- a/arch/powerpc/include/asm/page_64.h
3441 +++ b/arch/powerpc/include/asm/page_64.h
3442 @@ -144,15 +144,18 @@ do { \
3443 * stack by default, so in the absence of a PT_GNU_STACK program header
3444 * we turn execute permission off.
3445 */
3446 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3447 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3448 +#define VM_STACK_DEFAULT_FLAGS32 \
3449 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3450 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3451
3452 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3453 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3454
3455 +#ifndef CONFIG_PAX_PAGEEXEC
3456 #define VM_STACK_DEFAULT_FLAGS \
3457 (is_32bit_task() ? \
3458 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3459 +#endif
3460
3461 #include <asm-generic/getorder.h>
3462
3463 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3464 index 88b0bd9..e32bc67 100644
3465 --- a/arch/powerpc/include/asm/pgtable.h
3466 +++ b/arch/powerpc/include/asm/pgtable.h
3467 @@ -2,6 +2,7 @@
3468 #define _ASM_POWERPC_PGTABLE_H
3469 #ifdef __KERNEL__
3470
3471 +#include <linux/const.h>
3472 #ifndef __ASSEMBLY__
3473 #include <asm/processor.h> /* For TASK_SIZE */
3474 #include <asm/mmu.h>
3475 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3476 index 4aad413..85d86bf 100644
3477 --- a/arch/powerpc/include/asm/pte-hash32.h
3478 +++ b/arch/powerpc/include/asm/pte-hash32.h
3479 @@ -21,6 +21,7 @@
3480 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3481 #define _PAGE_USER 0x004 /* usermode access allowed */
3482 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3483 +#define _PAGE_EXEC _PAGE_GUARDED
3484 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3485 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3486 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3487 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3488 index 559da19..7e5835c 100644
3489 --- a/arch/powerpc/include/asm/reg.h
3490 +++ b/arch/powerpc/include/asm/reg.h
3491 @@ -212,6 +212,7 @@
3492 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3493 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3494 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3495 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3496 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3497 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3498 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3499 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3500 index e30a13d..2b7d994 100644
3501 --- a/arch/powerpc/include/asm/system.h
3502 +++ b/arch/powerpc/include/asm/system.h
3503 @@ -530,7 +530,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3504 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3505 #endif
3506
3507 -extern unsigned long arch_align_stack(unsigned long sp);
3508 +#define arch_align_stack(x) ((x) & ~0xfUL)
3509
3510 /* Used in very early kernel initialization. */
3511 extern unsigned long reloc_offset(void);
3512 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3513 index bd0fb84..a42a14b 100644
3514 --- a/arch/powerpc/include/asm/uaccess.h
3515 +++ b/arch/powerpc/include/asm/uaccess.h
3516 @@ -13,6 +13,8 @@
3517 #define VERIFY_READ 0
3518 #define VERIFY_WRITE 1
3519
3520 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3521 +
3522 /*
3523 * The fs value determines whether argument validity checking should be
3524 * performed or not. If get_fs() == USER_DS, checking is performed, with
3525 @@ -327,52 +329,6 @@ do { \
3526 extern unsigned long __copy_tofrom_user(void __user *to,
3527 const void __user *from, unsigned long size);
3528
3529 -#ifndef __powerpc64__
3530 -
3531 -static inline unsigned long copy_from_user(void *to,
3532 - const void __user *from, unsigned long n)
3533 -{
3534 - unsigned long over;
3535 -
3536 - if (access_ok(VERIFY_READ, from, n))
3537 - return __copy_tofrom_user((__force void __user *)to, from, n);
3538 - if ((unsigned long)from < TASK_SIZE) {
3539 - over = (unsigned long)from + n - TASK_SIZE;
3540 - return __copy_tofrom_user((__force void __user *)to, from,
3541 - n - over) + over;
3542 - }
3543 - return n;
3544 -}
3545 -
3546 -static inline unsigned long copy_to_user(void __user *to,
3547 - const void *from, unsigned long n)
3548 -{
3549 - unsigned long over;
3550 -
3551 - if (access_ok(VERIFY_WRITE, to, n))
3552 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3553 - if ((unsigned long)to < TASK_SIZE) {
3554 - over = (unsigned long)to + n - TASK_SIZE;
3555 - return __copy_tofrom_user(to, (__force void __user *)from,
3556 - n - over) + over;
3557 - }
3558 - return n;
3559 -}
3560 -
3561 -#else /* __powerpc64__ */
3562 -
3563 -#define __copy_in_user(to, from, size) \
3564 - __copy_tofrom_user((to), (from), (size))
3565 -
3566 -extern unsigned long copy_from_user(void *to, const void __user *from,
3567 - unsigned long n);
3568 -extern unsigned long copy_to_user(void __user *to, const void *from,
3569 - unsigned long n);
3570 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3571 - unsigned long n);
3572 -
3573 -#endif /* __powerpc64__ */
3574 -
3575 static inline unsigned long __copy_from_user_inatomic(void *to,
3576 const void __user *from, unsigned long n)
3577 {
3578 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3579 if (ret == 0)
3580 return 0;
3581 }
3582 +
3583 + if (!__builtin_constant_p(n))
3584 + check_object_size(to, n, false);
3585 +
3586 return __copy_tofrom_user((__force void __user *)to, from, n);
3587 }
3588
3589 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3590 if (ret == 0)
3591 return 0;
3592 }
3593 +
3594 + if (!__builtin_constant_p(n))
3595 + check_object_size(from, n, true);
3596 +
3597 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3598 }
3599
3600 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3601 return __copy_to_user_inatomic(to, from, size);
3602 }
3603
3604 +#ifndef __powerpc64__
3605 +
3606 +static inline unsigned long __must_check copy_from_user(void *to,
3607 + const void __user *from, unsigned long n)
3608 +{
3609 + unsigned long over;
3610 +
3611 + if ((long)n < 0)
3612 + return n;
3613 +
3614 + if (access_ok(VERIFY_READ, from, n)) {
3615 + if (!__builtin_constant_p(n))
3616 + check_object_size(to, n, false);
3617 + return __copy_tofrom_user((__force void __user *)to, from, n);
3618 + }
3619 + if ((unsigned long)from < TASK_SIZE) {
3620 + over = (unsigned long)from + n - TASK_SIZE;
3621 + if (!__builtin_constant_p(n - over))
3622 + check_object_size(to, n - over, false);
3623 + return __copy_tofrom_user((__force void __user *)to, from,
3624 + n - over) + over;
3625 + }
3626 + return n;
3627 +}
3628 +
3629 +static inline unsigned long __must_check copy_to_user(void __user *to,
3630 + const void *from, unsigned long n)
3631 +{
3632 + unsigned long over;
3633 +
3634 + if ((long)n < 0)
3635 + return n;
3636 +
3637 + if (access_ok(VERIFY_WRITE, to, n)) {
3638 + if (!__builtin_constant_p(n))
3639 + check_object_size(from, n, true);
3640 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3641 + }
3642 + if ((unsigned long)to < TASK_SIZE) {
3643 + over = (unsigned long)to + n - TASK_SIZE;
3644 + if (!__builtin_constant_p(n))
3645 + check_object_size(from, n - over, true);
3646 + return __copy_tofrom_user(to, (__force void __user *)from,
3647 + n - over) + over;
3648 + }
3649 + return n;
3650 +}
3651 +
3652 +#else /* __powerpc64__ */
3653 +
3654 +#define __copy_in_user(to, from, size) \
3655 + __copy_tofrom_user((to), (from), (size))
3656 +
3657 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3658 +{
3659 + if ((long)n < 0 || n > INT_MAX)
3660 + return n;
3661 +
3662 + if (!__builtin_constant_p(n))
3663 + check_object_size(to, n, false);
3664 +
3665 + if (likely(access_ok(VERIFY_READ, from, n)))
3666 + n = __copy_from_user(to, from, n);
3667 + else
3668 + memset(to, 0, n);
3669 + return n;
3670 +}
3671 +
3672 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3673 +{
3674 + if ((long)n < 0 || n > INT_MAX)
3675 + return n;
3676 +
3677 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3678 + if (!__builtin_constant_p(n))
3679 + check_object_size(from, n, true);
3680 + n = __copy_to_user(to, from, n);
3681 + }
3682 + return n;
3683 +}
3684 +
3685 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3686 + unsigned long n);
3687 +
3688 +#endif /* __powerpc64__ */
3689 +
3690 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3691
3692 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3693 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3694 index 429983c..7af363b 100644
3695 --- a/arch/powerpc/kernel/exceptions-64e.S
3696 +++ b/arch/powerpc/kernel/exceptions-64e.S
3697 @@ -587,6 +587,7 @@ storage_fault_common:
3698 std r14,_DAR(r1)
3699 std r15,_DSISR(r1)
3700 addi r3,r1,STACK_FRAME_OVERHEAD
3701 + bl .save_nvgprs
3702 mr r4,r14
3703 mr r5,r15
3704 ld r14,PACA_EXGEN+EX_R14(r13)
3705 @@ -596,8 +597,7 @@ storage_fault_common:
3706 cmpdi r3,0
3707 bne- 1f
3708 b .ret_from_except_lite
3709 -1: bl .save_nvgprs
3710 - mr r5,r3
3711 +1: mr r5,r3
3712 addi r3,r1,STACK_FRAME_OVERHEAD
3713 ld r4,_DAR(r1)
3714 bl .bad_page_fault
3715 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3716 index cf9c69b..ebc9640 100644
3717 --- a/arch/powerpc/kernel/exceptions-64s.S
3718 +++ b/arch/powerpc/kernel/exceptions-64s.S
3719 @@ -1004,10 +1004,10 @@ handle_page_fault:
3720 11: ld r4,_DAR(r1)
3721 ld r5,_DSISR(r1)
3722 addi r3,r1,STACK_FRAME_OVERHEAD
3723 + bl .save_nvgprs
3724 bl .do_page_fault
3725 cmpdi r3,0
3726 beq+ 13f
3727 - bl .save_nvgprs
3728 mr r5,r3
3729 addi r3,r1,STACK_FRAME_OVERHEAD
3730 lwz r4,_DAR(r1)
3731 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3732 index 745c1e7..59d97a6 100644
3733 --- a/arch/powerpc/kernel/irq.c
3734 +++ b/arch/powerpc/kernel/irq.c
3735 @@ -547,9 +547,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3736 host->ops = ops;
3737 host->of_node = of_node_get(of_node);
3738
3739 - if (host->ops->match == NULL)
3740 - host->ops->match = default_irq_host_match;
3741 -
3742 raw_spin_lock_irqsave(&irq_big_lock, flags);
3743
3744 /* If it's a legacy controller, check for duplicates and
3745 @@ -622,7 +619,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3746 */
3747 raw_spin_lock_irqsave(&irq_big_lock, flags);
3748 list_for_each_entry(h, &irq_hosts, link)
3749 - if (h->ops->match(h, node)) {
3750 + if (h->ops->match) {
3751 + if (h->ops->match(h, node)) {
3752 + found = h;
3753 + break;
3754 + }
3755 + } else if (default_irq_host_match(h, node)) {
3756 found = h;
3757 break;
3758 }
3759 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3760 index 0b6d796..d760ddb 100644
3761 --- a/arch/powerpc/kernel/module_32.c
3762 +++ b/arch/powerpc/kernel/module_32.c
3763 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3764 me->arch.core_plt_section = i;
3765 }
3766 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3767 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3768 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3769 return -ENOEXEC;
3770 }
3771
3772 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3773
3774 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3775 /* Init, or core PLT? */
3776 - if (location >= mod->module_core
3777 - && location < mod->module_core + mod->core_size)
3778 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3779 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3780 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3781 - else
3782 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3783 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3784 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3785 + else {
3786 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3787 + return ~0UL;
3788 + }
3789
3790 /* Find this entry, or if that fails, the next avail. entry */
3791 while (entry->jump[0]) {
3792 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3793 index 6457574..08b28d3 100644
3794 --- a/arch/powerpc/kernel/process.c
3795 +++ b/arch/powerpc/kernel/process.c
3796 @@ -660,8 +660,8 @@ void show_regs(struct pt_regs * regs)
3797 * Lookup NIP late so we have the best change of getting the
3798 * above info out without failing
3799 */
3800 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3801 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3802 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3803 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3804 #endif
3805 show_stack(current, (unsigned long *) regs->gpr[1]);
3806 if (!user_mode(regs))
3807 @@ -1165,10 +1165,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3808 newsp = stack[0];
3809 ip = stack[STACK_FRAME_LR_SAVE];
3810 if (!firstframe || ip != lr) {
3811 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3812 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3813 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3814 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3815 - printk(" (%pS)",
3816 + printk(" (%pA)",
3817 (void *)current->ret_stack[curr_frame].ret);
3818 curr_frame--;
3819 }
3820 @@ -1188,7 +1188,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3821 struct pt_regs *regs = (struct pt_regs *)
3822 (sp + STACK_FRAME_OVERHEAD);
3823 lr = regs->link;
3824 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3825 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3826 regs->trap, (void *)regs->nip, (void *)lr);
3827 firstframe = 1;
3828 }
3829 @@ -1263,58 +1263,3 @@ void thread_info_cache_init(void)
3830 }
3831
3832 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3833 -
3834 -unsigned long arch_align_stack(unsigned long sp)
3835 -{
3836 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3837 - sp -= get_random_int() & ~PAGE_MASK;
3838 - return sp & ~0xf;
3839 -}
3840 -
3841 -static inline unsigned long brk_rnd(void)
3842 -{
3843 - unsigned long rnd = 0;
3844 -
3845 - /* 8MB for 32bit, 1GB for 64bit */
3846 - if (is_32bit_task())
3847 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3848 - else
3849 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3850 -
3851 - return rnd << PAGE_SHIFT;
3852 -}
3853 -
3854 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3855 -{
3856 - unsigned long base = mm->brk;
3857 - unsigned long ret;
3858 -
3859 -#ifdef CONFIG_PPC_STD_MMU_64
3860 - /*
3861 - * If we are using 1TB segments and we are allowed to randomise
3862 - * the heap, we can put it above 1TB so it is backed by a 1TB
3863 - * segment. Otherwise the heap will be in the bottom 1TB
3864 - * which always uses 256MB segments and this may result in a
3865 - * performance penalty.
3866 - */
3867 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3868 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3869 -#endif
3870 -
3871 - ret = PAGE_ALIGN(base + brk_rnd());
3872 -
3873 - if (ret < mm->brk)
3874 - return mm->brk;
3875 -
3876 - return ret;
3877 -}
3878 -
3879 -unsigned long randomize_et_dyn(unsigned long base)
3880 -{
3881 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3882 -
3883 - if (ret < base)
3884 - return base;
3885 -
3886 - return ret;
3887 -}
3888 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3889 index 836a5a1..27289a3 100644
3890 --- a/arch/powerpc/kernel/signal_32.c
3891 +++ b/arch/powerpc/kernel/signal_32.c
3892 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3893 /* Save user registers on the stack */
3894 frame = &rt_sf->uc.uc_mcontext;
3895 addr = frame;
3896 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3897 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3898 if (save_user_regs(regs, frame, 0, 1))
3899 goto badframe;
3900 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3901 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3902 index a50b5ec..547078a 100644
3903 --- a/arch/powerpc/kernel/signal_64.c
3904 +++ b/arch/powerpc/kernel/signal_64.c
3905 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3906 current->thread.fpscr.val = 0;
3907
3908 /* Set up to return from userspace. */
3909 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3910 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3911 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3912 } else {
3913 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3914 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3915 index 5459d14..10f8070 100644
3916 --- a/arch/powerpc/kernel/traps.c
3917 +++ b/arch/powerpc/kernel/traps.c
3918 @@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
3919 static inline void pmac_backlight_unblank(void) { }
3920 #endif
3921
3922 +extern void gr_handle_kernel_exploit(void);
3923 +
3924 int die(const char *str, struct pt_regs *regs, long err)
3925 {
3926 static struct {
3927 @@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs *regs, long err)
3928 if (panic_on_oops)
3929 panic("Fatal exception");
3930
3931 + gr_handle_kernel_exploit();
3932 +
3933 oops_exit();
3934 do_exit(err);
3935
3936 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3937 index 7d14bb6..1305601 100644
3938 --- a/arch/powerpc/kernel/vdso.c
3939 +++ b/arch/powerpc/kernel/vdso.c
3940 @@ -35,6 +35,7 @@
3941 #include <asm/firmware.h>
3942 #include <asm/vdso.h>
3943 #include <asm/vdso_datapage.h>
3944 +#include <asm/mman.h>
3945
3946 #include "setup.h"
3947
3948 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3949 vdso_base = VDSO32_MBASE;
3950 #endif
3951
3952 - current->mm->context.vdso_base = 0;
3953 + current->mm->context.vdso_base = ~0UL;
3954
3955 /* vDSO has a problem and was disabled, just don't "enable" it for the
3956 * process
3957 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3958 vdso_base = get_unmapped_area(NULL, vdso_base,
3959 (vdso_pages << PAGE_SHIFT) +
3960 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3961 - 0, 0);
3962 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3963 if (IS_ERR_VALUE(vdso_base)) {
3964 rc = vdso_base;
3965 goto fail_mmapsem;
3966 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3967 index 5eea6f3..5d10396 100644
3968 --- a/arch/powerpc/lib/usercopy_64.c
3969 +++ b/arch/powerpc/lib/usercopy_64.c
3970 @@ -9,22 +9,6 @@
3971 #include <linux/module.h>
3972 #include <asm/uaccess.h>
3973
3974 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3975 -{
3976 - if (likely(access_ok(VERIFY_READ, from, n)))
3977 - n = __copy_from_user(to, from, n);
3978 - else
3979 - memset(to, 0, n);
3980 - return n;
3981 -}
3982 -
3983 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3984 -{
3985 - if (likely(access_ok(VERIFY_WRITE, to, n)))
3986 - n = __copy_to_user(to, from, n);
3987 - return n;
3988 -}
3989 -
3990 unsigned long copy_in_user(void __user *to, const void __user *from,
3991 unsigned long n)
3992 {
3993 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
3994 return n;
3995 }
3996
3997 -EXPORT_SYMBOL(copy_from_user);
3998 -EXPORT_SYMBOL(copy_to_user);
3999 EXPORT_SYMBOL(copy_in_user);
4000
4001 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4002 index 5efe8c9..db9ceef 100644
4003 --- a/arch/powerpc/mm/fault.c
4004 +++ b/arch/powerpc/mm/fault.c
4005 @@ -32,6 +32,10 @@
4006 #include <linux/perf_event.h>
4007 #include <linux/magic.h>
4008 #include <linux/ratelimit.h>
4009 +#include <linux/slab.h>
4010 +#include <linux/pagemap.h>
4011 +#include <linux/compiler.h>
4012 +#include <linux/unistd.h>
4013
4014 #include <asm/firmware.h>
4015 #include <asm/page.h>
4016 @@ -43,6 +47,7 @@
4017 #include <asm/tlbflush.h>
4018 #include <asm/siginfo.h>
4019 #include <mm/mmu_decl.h>
4020 +#include <asm/ptrace.h>
4021
4022 #ifdef CONFIG_KPROBES
4023 static inline int notify_page_fault(struct pt_regs *regs)
4024 @@ -66,6 +71,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4025 }
4026 #endif
4027
4028 +#ifdef CONFIG_PAX_PAGEEXEC
4029 +/*
4030 + * PaX: decide what to do with offenders (regs->nip = fault address)
4031 + *
4032 + * returns 1 when task should be killed
4033 + */
4034 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4035 +{
4036 + return 1;
4037 +}
4038 +
4039 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4040 +{
4041 + unsigned long i;
4042 +
4043 + printk(KERN_ERR "PAX: bytes at PC: ");
4044 + for (i = 0; i < 5; i++) {
4045 + unsigned int c;
4046 + if (get_user(c, (unsigned int __user *)pc+i))
4047 + printk(KERN_CONT "???????? ");
4048 + else
4049 + printk(KERN_CONT "%08x ", c);
4050 + }
4051 + printk("\n");
4052 +}
4053 +#endif
4054 +
4055 /*
4056 * Check whether the instruction at regs->nip is a store using
4057 * an update addressing form which will update r1.
4058 @@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4059 * indicate errors in DSISR but can validly be set in SRR1.
4060 */
4061 if (trap == 0x400)
4062 - error_code &= 0x48200000;
4063 + error_code &= 0x58200000;
4064 else
4065 is_write = error_code & DSISR_ISSTORE;
4066 #else
4067 @@ -259,7 +291,7 @@ good_area:
4068 * "undefined". Of those that can be set, this is the only
4069 * one which seems bad.
4070 */
4071 - if (error_code & 0x10000000)
4072 + if (error_code & DSISR_GUARDED)
4073 /* Guarded storage error. */
4074 goto bad_area;
4075 #endif /* CONFIG_8xx */
4076 @@ -274,7 +306,7 @@ good_area:
4077 * processors use the same I/D cache coherency mechanism
4078 * as embedded.
4079 */
4080 - if (error_code & DSISR_PROTFAULT)
4081 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4082 goto bad_area;
4083 #endif /* CONFIG_PPC_STD_MMU */
4084
4085 @@ -343,6 +375,23 @@ bad_area:
4086 bad_area_nosemaphore:
4087 /* User mode accesses cause a SIGSEGV */
4088 if (user_mode(regs)) {
4089 +
4090 +#ifdef CONFIG_PAX_PAGEEXEC
4091 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4092 +#ifdef CONFIG_PPC_STD_MMU
4093 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4094 +#else
4095 + if (is_exec && regs->nip == address) {
4096 +#endif
4097 + switch (pax_handle_fetch_fault(regs)) {
4098 + }
4099 +
4100 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4101 + do_group_exit(SIGKILL);
4102 + }
4103 + }
4104 +#endif
4105 +
4106 _exception(SIGSEGV, regs, code, address);
4107 return 0;
4108 }
4109 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4110 index 5a783d8..c23e14b 100644
4111 --- a/arch/powerpc/mm/mmap_64.c
4112 +++ b/arch/powerpc/mm/mmap_64.c
4113 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4114 */
4115 if (mmap_is_legacy()) {
4116 mm->mmap_base = TASK_UNMAPPED_BASE;
4117 +
4118 +#ifdef CONFIG_PAX_RANDMMAP
4119 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4120 + mm->mmap_base += mm->delta_mmap;
4121 +#endif
4122 +
4123 mm->get_unmapped_area = arch_get_unmapped_area;
4124 mm->unmap_area = arch_unmap_area;
4125 } else {
4126 mm->mmap_base = mmap_base();
4127 +
4128 +#ifdef CONFIG_PAX_RANDMMAP
4129 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4130 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4131 +#endif
4132 +
4133 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4134 mm->unmap_area = arch_unmap_area_topdown;
4135 }
4136 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4137 index 73709f7..6b90313 100644
4138 --- a/arch/powerpc/mm/slice.c
4139 +++ b/arch/powerpc/mm/slice.c
4140 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4141 if ((mm->task_size - len) < addr)
4142 return 0;
4143 vma = find_vma(mm, addr);
4144 - return (!vma || (addr + len) <= vma->vm_start);
4145 + return check_heap_stack_gap(vma, addr, len);
4146 }
4147
4148 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4149 @@ -256,7 +256,7 @@ full_search:
4150 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4151 continue;
4152 }
4153 - if (!vma || addr + len <= vma->vm_start) {
4154 + if (check_heap_stack_gap(vma, addr, len)) {
4155 /*
4156 * Remember the place where we stopped the search:
4157 */
4158 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4159 }
4160 }
4161
4162 - addr = mm->mmap_base;
4163 - while (addr > len) {
4164 + if (mm->mmap_base < len)
4165 + addr = -ENOMEM;
4166 + else
4167 + addr = mm->mmap_base - len;
4168 +
4169 + while (!IS_ERR_VALUE(addr)) {
4170 /* Go down by chunk size */
4171 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4172 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4173
4174 /* Check for hit with different page size */
4175 mask = slice_range_to_mask(addr, len);
4176 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4177 * return with success:
4178 */
4179 vma = find_vma(mm, addr);
4180 - if (!vma || (addr + len) <= vma->vm_start) {
4181 + if (check_heap_stack_gap(vma, addr, len)) {
4182 /* remember the address as a hint for next time */
4183 if (use_cache)
4184 mm->free_area_cache = addr;
4185 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4186 mm->cached_hole_size = vma->vm_start - addr;
4187
4188 /* try just below the current vma->vm_start */
4189 - addr = vma->vm_start;
4190 + addr = skip_heap_stack_gap(vma, len);
4191 }
4192
4193 /*
4194 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4195 if (fixed && addr > (mm->task_size - len))
4196 return -EINVAL;
4197
4198 +#ifdef CONFIG_PAX_RANDMMAP
4199 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4200 + addr = 0;
4201 +#endif
4202 +
4203 /* If hint, make sure it matches our alignment restrictions */
4204 if (!fixed && addr) {
4205 addr = _ALIGN_UP(addr, 1ul << pshift);
4206 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4207 index 8517d2a..d2738d4 100644
4208 --- a/arch/s390/include/asm/atomic.h
4209 +++ b/arch/s390/include/asm/atomic.h
4210 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4211 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4212 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4213
4214 +#define atomic64_read_unchecked(v) atomic64_read(v)
4215 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4216 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4217 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4218 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4219 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4220 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4221 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4222 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4223 +
4224 #define smp_mb__before_atomic_dec() smp_mb()
4225 #define smp_mb__after_atomic_dec() smp_mb()
4226 #define smp_mb__before_atomic_inc() smp_mb()
4227 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4228 index 2a30d5a..5e5586f 100644
4229 --- a/arch/s390/include/asm/cache.h
4230 +++ b/arch/s390/include/asm/cache.h
4231 @@ -11,8 +11,10 @@
4232 #ifndef __ARCH_S390_CACHE_H
4233 #define __ARCH_S390_CACHE_H
4234
4235 -#define L1_CACHE_BYTES 256
4236 +#include <linux/const.h>
4237 +
4238 #define L1_CACHE_SHIFT 8
4239 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4240 #define NET_SKB_PAD 32
4241
4242 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4243 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4244 index 547f1a6..0b22b53 100644
4245 --- a/arch/s390/include/asm/elf.h
4246 +++ b/arch/s390/include/asm/elf.h
4247 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4248 the loader. We need to make sure that it is out of the way of the program
4249 that it will "exec", and that there is sufficient room for the brk. */
4250
4251 -extern unsigned long randomize_et_dyn(unsigned long base);
4252 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4253 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4254 +
4255 +#ifdef CONFIG_PAX_ASLR
4256 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4257 +
4258 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4259 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4260 +#endif
4261
4262 /* This yields a mask that user programs can use to figure out what
4263 instruction set this CPU supports. */
4264 @@ -211,7 +217,4 @@ struct linux_binprm;
4265 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4266 int arch_setup_additional_pages(struct linux_binprm *, int);
4267
4268 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4269 -#define arch_randomize_brk arch_randomize_brk
4270 -
4271 #endif
4272 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4273 index ef573c1..75a1ce6 100644
4274 --- a/arch/s390/include/asm/system.h
4275 +++ b/arch/s390/include/asm/system.h
4276 @@ -262,7 +262,7 @@ extern void (*_machine_restart)(char *command);
4277 extern void (*_machine_halt)(void);
4278 extern void (*_machine_power_off)(void);
4279
4280 -extern unsigned long arch_align_stack(unsigned long sp);
4281 +#define arch_align_stack(x) ((x) & ~0xfUL)
4282
4283 static inline int tprot(unsigned long addr)
4284 {
4285 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4286 index 2b23885..e136e31 100644
4287 --- a/arch/s390/include/asm/uaccess.h
4288 +++ b/arch/s390/include/asm/uaccess.h
4289 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4290 copy_to_user(void __user *to, const void *from, unsigned long n)
4291 {
4292 might_fault();
4293 +
4294 + if ((long)n < 0)
4295 + return n;
4296 +
4297 if (access_ok(VERIFY_WRITE, to, n))
4298 n = __copy_to_user(to, from, n);
4299 return n;
4300 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4301 static inline unsigned long __must_check
4302 __copy_from_user(void *to, const void __user *from, unsigned long n)
4303 {
4304 + if ((long)n < 0)
4305 + return n;
4306 +
4307 if (__builtin_constant_p(n) && (n <= 256))
4308 return uaccess.copy_from_user_small(n, from, to);
4309 else
4310 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4311 unsigned int sz = __compiletime_object_size(to);
4312
4313 might_fault();
4314 +
4315 + if ((long)n < 0)
4316 + return n;
4317 +
4318 if (unlikely(sz != -1 && sz < n)) {
4319 copy_from_user_overflow();
4320 return n;
4321 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4322 index dfcb343..eda788a 100644
4323 --- a/arch/s390/kernel/module.c
4324 +++ b/arch/s390/kernel/module.c
4325 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4326
4327 /* Increase core size by size of got & plt and set start
4328 offsets for got and plt. */
4329 - me->core_size = ALIGN(me->core_size, 4);
4330 - me->arch.got_offset = me->core_size;
4331 - me->core_size += me->arch.got_size;
4332 - me->arch.plt_offset = me->core_size;
4333 - me->core_size += me->arch.plt_size;
4334 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4335 + me->arch.got_offset = me->core_size_rw;
4336 + me->core_size_rw += me->arch.got_size;
4337 + me->arch.plt_offset = me->core_size_rx;
4338 + me->core_size_rx += me->arch.plt_size;
4339 return 0;
4340 }
4341
4342 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4343 if (info->got_initialized == 0) {
4344 Elf_Addr *gotent;
4345
4346 - gotent = me->module_core + me->arch.got_offset +
4347 + gotent = me->module_core_rw + me->arch.got_offset +
4348 info->got_offset;
4349 *gotent = val;
4350 info->got_initialized = 1;
4351 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4352 else if (r_type == R_390_GOTENT ||
4353 r_type == R_390_GOTPLTENT)
4354 *(unsigned int *) loc =
4355 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4356 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4357 else if (r_type == R_390_GOT64 ||
4358 r_type == R_390_GOTPLT64)
4359 *(unsigned long *) loc = val;
4360 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4361 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4362 if (info->plt_initialized == 0) {
4363 unsigned int *ip;
4364 - ip = me->module_core + me->arch.plt_offset +
4365 + ip = me->module_core_rx + me->arch.plt_offset +
4366 info->plt_offset;
4367 #ifndef CONFIG_64BIT
4368 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4369 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4370 val - loc + 0xffffUL < 0x1ffffeUL) ||
4371 (r_type == R_390_PLT32DBL &&
4372 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4373 - val = (Elf_Addr) me->module_core +
4374 + val = (Elf_Addr) me->module_core_rx +
4375 me->arch.plt_offset +
4376 info->plt_offset;
4377 val += rela->r_addend - loc;
4378 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4379 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4380 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4381 val = val + rela->r_addend -
4382 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4383 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4384 if (r_type == R_390_GOTOFF16)
4385 *(unsigned short *) loc = val;
4386 else if (r_type == R_390_GOTOFF32)
4387 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4388 break;
4389 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4390 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4391 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4392 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4393 rela->r_addend - loc;
4394 if (r_type == R_390_GOTPC)
4395 *(unsigned int *) loc = val;
4396 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4397 index 53088e2..9f44a36 100644
4398 --- a/arch/s390/kernel/process.c
4399 +++ b/arch/s390/kernel/process.c
4400 @@ -320,39 +320,3 @@ unsigned long get_wchan(struct task_struct *p)
4401 }
4402 return 0;
4403 }
4404 -
4405 -unsigned long arch_align_stack(unsigned long sp)
4406 -{
4407 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4408 - sp -= get_random_int() & ~PAGE_MASK;
4409 - return sp & ~0xf;
4410 -}
4411 -
4412 -static inline unsigned long brk_rnd(void)
4413 -{
4414 - /* 8MB for 32bit, 1GB for 64bit */
4415 - if (is_32bit_task())
4416 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4417 - else
4418 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4419 -}
4420 -
4421 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4422 -{
4423 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4424 -
4425 - if (ret < mm->brk)
4426 - return mm->brk;
4427 - return ret;
4428 -}
4429 -
4430 -unsigned long randomize_et_dyn(unsigned long base)
4431 -{
4432 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4433 -
4434 - if (!(current->flags & PF_RANDOMIZE))
4435 - return base;
4436 - if (ret < base)
4437 - return base;
4438 - return ret;
4439 -}
4440 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4441 index a0155c0..34cc491 100644
4442 --- a/arch/s390/mm/mmap.c
4443 +++ b/arch/s390/mm/mmap.c
4444 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4445 */
4446 if (mmap_is_legacy()) {
4447 mm->mmap_base = TASK_UNMAPPED_BASE;
4448 +
4449 +#ifdef CONFIG_PAX_RANDMMAP
4450 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4451 + mm->mmap_base += mm->delta_mmap;
4452 +#endif
4453 +
4454 mm->get_unmapped_area = arch_get_unmapped_area;
4455 mm->unmap_area = arch_unmap_area;
4456 } else {
4457 mm->mmap_base = mmap_base();
4458 +
4459 +#ifdef CONFIG_PAX_RANDMMAP
4460 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4461 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4462 +#endif
4463 +
4464 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4465 mm->unmap_area = arch_unmap_area_topdown;
4466 }
4467 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4468 */
4469 if (mmap_is_legacy()) {
4470 mm->mmap_base = TASK_UNMAPPED_BASE;
4471 +
4472 +#ifdef CONFIG_PAX_RANDMMAP
4473 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4474 + mm->mmap_base += mm->delta_mmap;
4475 +#endif
4476 +
4477 mm->get_unmapped_area = s390_get_unmapped_area;
4478 mm->unmap_area = arch_unmap_area;
4479 } else {
4480 mm->mmap_base = mmap_base();
4481 +
4482 +#ifdef CONFIG_PAX_RANDMMAP
4483 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4484 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4485 +#endif
4486 +
4487 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4488 mm->unmap_area = arch_unmap_area_topdown;
4489 }
4490 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4491 index ae3d59f..f65f075 100644
4492 --- a/arch/score/include/asm/cache.h
4493 +++ b/arch/score/include/asm/cache.h
4494 @@ -1,7 +1,9 @@
4495 #ifndef _ASM_SCORE_CACHE_H
4496 #define _ASM_SCORE_CACHE_H
4497
4498 +#include <linux/const.h>
4499 +
4500 #define L1_CACHE_SHIFT 4
4501 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4502 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4503
4504 #endif /* _ASM_SCORE_CACHE_H */
4505 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4506 index 589d5c7..669e274 100644
4507 --- a/arch/score/include/asm/system.h
4508 +++ b/arch/score/include/asm/system.h
4509 @@ -17,7 +17,7 @@ do { \
4510 #define finish_arch_switch(prev) do {} while (0)
4511
4512 typedef void (*vi_handler_t)(void);
4513 -extern unsigned long arch_align_stack(unsigned long sp);
4514 +#define arch_align_stack(x) (x)
4515
4516 #define mb() barrier()
4517 #define rmb() barrier()
4518 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4519 index 25d0803..d6c8e36 100644
4520 --- a/arch/score/kernel/process.c
4521 +++ b/arch/score/kernel/process.c
4522 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4523
4524 return task_pt_regs(task)->cp0_epc;
4525 }
4526 -
4527 -unsigned long arch_align_stack(unsigned long sp)
4528 -{
4529 - return sp;
4530 -}
4531 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4532 index ef9e555..331bd29 100644
4533 --- a/arch/sh/include/asm/cache.h
4534 +++ b/arch/sh/include/asm/cache.h
4535 @@ -9,10 +9,11 @@
4536 #define __ASM_SH_CACHE_H
4537 #ifdef __KERNEL__
4538
4539 +#include <linux/const.h>
4540 #include <linux/init.h>
4541 #include <cpu/cache.h>
4542
4543 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4544 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4545
4546 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4547
4548 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4549 index afeb710..d1d1289 100644
4550 --- a/arch/sh/mm/mmap.c
4551 +++ b/arch/sh/mm/mmap.c
4552 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4553 addr = PAGE_ALIGN(addr);
4554
4555 vma = find_vma(mm, addr);
4556 - if (TASK_SIZE - len >= addr &&
4557 - (!vma || addr + len <= vma->vm_start))
4558 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4559 return addr;
4560 }
4561
4562 @@ -106,7 +105,7 @@ full_search:
4563 }
4564 return -ENOMEM;
4565 }
4566 - if (likely(!vma || addr + len <= vma->vm_start)) {
4567 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4568 /*
4569 * Remember the place where we stopped the search:
4570 */
4571 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4572 addr = PAGE_ALIGN(addr);
4573
4574 vma = find_vma(mm, addr);
4575 - if (TASK_SIZE - len >= addr &&
4576 - (!vma || addr + len <= vma->vm_start))
4577 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4578 return addr;
4579 }
4580
4581 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4582 /* make sure it can fit in the remaining address space */
4583 if (likely(addr > len)) {
4584 vma = find_vma(mm, addr-len);
4585 - if (!vma || addr <= vma->vm_start) {
4586 + if (check_heap_stack_gap(vma, addr - len, len)) {
4587 /* remember the address as a hint for next time */
4588 return (mm->free_area_cache = addr-len);
4589 }
4590 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4591 if (unlikely(mm->mmap_base < len))
4592 goto bottomup;
4593
4594 - addr = mm->mmap_base-len;
4595 - if (do_colour_align)
4596 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4597 + addr = mm->mmap_base - len;
4598
4599 do {
4600 + if (do_colour_align)
4601 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4602 /*
4603 * Lookup failure means no vma is above this address,
4604 * else if new region fits below vma->vm_start,
4605 * return with success:
4606 */
4607 vma = find_vma(mm, addr);
4608 - if (likely(!vma || addr+len <= vma->vm_start)) {
4609 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4610 /* remember the address as a hint for next time */
4611 return (mm->free_area_cache = addr);
4612 }
4613 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4614 mm->cached_hole_size = vma->vm_start - addr;
4615
4616 /* try just below the current vma->vm_start */
4617 - addr = vma->vm_start-len;
4618 - if (do_colour_align)
4619 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4620 - } while (likely(len < vma->vm_start));
4621 + addr = skip_heap_stack_gap(vma, len);
4622 + } while (!IS_ERR_VALUE(addr));
4623
4624 bottomup:
4625 /*
4626 diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
4627 index f92602e..27060b2 100644
4628 --- a/arch/sparc/Kconfig
4629 +++ b/arch/sparc/Kconfig
4630 @@ -31,6 +31,7 @@ config SPARC
4631
4632 config SPARC32
4633 def_bool !64BIT
4634 + select GENERIC_ATOMIC64
4635
4636 config SPARC64
4637 def_bool 64BIT
4638 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4639 index ad1fb5d..fc5315b 100644
4640 --- a/arch/sparc/Makefile
4641 +++ b/arch/sparc/Makefile
4642 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4643 # Export what is needed by arch/sparc/boot/Makefile
4644 export VMLINUX_INIT VMLINUX_MAIN
4645 VMLINUX_INIT := $(head-y) $(init-y)
4646 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4647 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4648 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4649 VMLINUX_MAIN += $(drivers-y) $(net-y)
4650
4651 diff --git a/arch/sparc/include/asm/atomic_32.h b/arch/sparc/include/asm/atomic_32.h
4652 index 5c3c8b6..ba822fa 100644
4653 --- a/arch/sparc/include/asm/atomic_32.h
4654 +++ b/arch/sparc/include/asm/atomic_32.h
4655 @@ -13,6 +13,8 @@
4656
4657 #include <linux/types.h>
4658
4659 +#include <asm-generic/atomic64.h>
4660 +
4661 #ifdef __KERNEL__
4662
4663 #include <asm/system.h>
4664 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4665 index 9f421df..b81fc12 100644
4666 --- a/arch/sparc/include/asm/atomic_64.h
4667 +++ b/arch/sparc/include/asm/atomic_64.h
4668 @@ -14,18 +14,40 @@
4669 #define ATOMIC64_INIT(i) { (i) }
4670
4671 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4672 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4673 +{
4674 + return v->counter;
4675 +}
4676 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4677 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4678 +{
4679 + return v->counter;
4680 +}
4681
4682 #define atomic_set(v, i) (((v)->counter) = i)
4683 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4684 +{
4685 + v->counter = i;
4686 +}
4687 #define atomic64_set(v, i) (((v)->counter) = i)
4688 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4689 +{
4690 + v->counter = i;
4691 +}
4692
4693 extern void atomic_add(int, atomic_t *);
4694 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4695 extern void atomic64_add(long, atomic64_t *);
4696 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4697 extern void atomic_sub(int, atomic_t *);
4698 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4699 extern void atomic64_sub(long, atomic64_t *);
4700 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4701
4702 extern int atomic_add_ret(int, atomic_t *);
4703 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4704 extern long atomic64_add_ret(long, atomic64_t *);
4705 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4706 extern int atomic_sub_ret(int, atomic_t *);
4707 extern long atomic64_sub_ret(long, atomic64_t *);
4708
4709 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4710 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4711
4712 #define atomic_inc_return(v) atomic_add_ret(1, v)
4713 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4714 +{
4715 + return atomic_add_ret_unchecked(1, v);
4716 +}
4717 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4718 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4719 +{
4720 + return atomic64_add_ret_unchecked(1, v);
4721 +}
4722
4723 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4724 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4725
4726 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4727 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4728 +{
4729 + return atomic_add_ret_unchecked(i, v);
4730 +}
4731 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4732 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4733 +{
4734 + return atomic64_add_ret_unchecked(i, v);
4735 +}
4736
4737 /*
4738 * atomic_inc_and_test - increment and test
4739 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4740 * other cases.
4741 */
4742 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4743 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4744 +{
4745 + return atomic_inc_return_unchecked(v) == 0;
4746 +}
4747 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4748
4749 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4750 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4751 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4752
4753 #define atomic_inc(v) atomic_add(1, v)
4754 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4755 +{
4756 + atomic_add_unchecked(1, v);
4757 +}
4758 #define atomic64_inc(v) atomic64_add(1, v)
4759 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4760 +{
4761 + atomic64_add_unchecked(1, v);
4762 +}
4763
4764 #define atomic_dec(v) atomic_sub(1, v)
4765 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4766 +{
4767 + atomic_sub_unchecked(1, v);
4768 +}
4769 #define atomic64_dec(v) atomic64_sub(1, v)
4770 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4771 +{
4772 + atomic64_sub_unchecked(1, v);
4773 +}
4774
4775 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4776 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4777
4778 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4779 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4780 +{
4781 + return cmpxchg(&v->counter, old, new);
4782 +}
4783 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4784 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4785 +{
4786 + return xchg(&v->counter, new);
4787 +}
4788
4789 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4790 {
4791 - int c, old;
4792 + int c, old, new;
4793 c = atomic_read(v);
4794 for (;;) {
4795 - if (unlikely(c == (u)))
4796 + if (unlikely(c == u))
4797 break;
4798 - old = atomic_cmpxchg((v), c, c + (a));
4799 +
4800 + asm volatile("addcc %2, %0, %0\n"
4801 +
4802 +#ifdef CONFIG_PAX_REFCOUNT
4803 + "tvs %%icc, 6\n"
4804 +#endif
4805 +
4806 + : "=r" (new)
4807 + : "0" (c), "ir" (a)
4808 + : "cc");
4809 +
4810 + old = atomic_cmpxchg(v, c, new);
4811 if (likely(old == c))
4812 break;
4813 c = old;
4814 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4815 #define atomic64_cmpxchg(v, o, n) \
4816 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4817 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4818 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4819 +{
4820 + return xchg(&v->counter, new);
4821 +}
4822
4823 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4824 {
4825 - long c, old;
4826 + long c, old, new;
4827 c = atomic64_read(v);
4828 for (;;) {
4829 - if (unlikely(c == (u)))
4830 + if (unlikely(c == u))
4831 break;
4832 - old = atomic64_cmpxchg((v), c, c + (a));
4833 +
4834 + asm volatile("addcc %2, %0, %0\n"
4835 +
4836 +#ifdef CONFIG_PAX_REFCOUNT
4837 + "tvs %%xcc, 6\n"
4838 +#endif
4839 +
4840 + : "=r" (new)
4841 + : "0" (c), "ir" (a)
4842 + : "cc");
4843 +
4844 + old = atomic64_cmpxchg(v, c, new);
4845 if (likely(old == c))
4846 break;
4847 c = old;
4848 }
4849 - return c != (u);
4850 + return c != u;
4851 }
4852
4853 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4854 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4855 index 69358b5..9d0d492 100644
4856 --- a/arch/sparc/include/asm/cache.h
4857 +++ b/arch/sparc/include/asm/cache.h
4858 @@ -7,10 +7,12 @@
4859 #ifndef _SPARC_CACHE_H
4860 #define _SPARC_CACHE_H
4861
4862 +#include <linux/const.h>
4863 +
4864 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
4865
4866 #define L1_CACHE_SHIFT 5
4867 -#define L1_CACHE_BYTES 32
4868 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4869
4870 #ifdef CONFIG_SPARC32
4871 #define SMP_CACHE_BYTES_SHIFT 5
4872 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4873 index 4269ca6..e3da77f 100644
4874 --- a/arch/sparc/include/asm/elf_32.h
4875 +++ b/arch/sparc/include/asm/elf_32.h
4876 @@ -114,6 +114,13 @@ typedef struct {
4877
4878 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4879
4880 +#ifdef CONFIG_PAX_ASLR
4881 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4882 +
4883 +#define PAX_DELTA_MMAP_LEN 16
4884 +#define PAX_DELTA_STACK_LEN 16
4885 +#endif
4886 +
4887 /* This yields a mask that user programs can use to figure out what
4888 instruction set this cpu supports. This can NOT be done in userspace
4889 on Sparc. */
4890 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4891 index 7df8b7f..4946269 100644
4892 --- a/arch/sparc/include/asm/elf_64.h
4893 +++ b/arch/sparc/include/asm/elf_64.h
4894 @@ -180,6 +180,13 @@ typedef struct {
4895 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4896 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4897
4898 +#ifdef CONFIG_PAX_ASLR
4899 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4900 +
4901 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4902 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4903 +#endif
4904 +
4905 extern unsigned long sparc64_elf_hwcap;
4906 #define ELF_HWCAP sparc64_elf_hwcap
4907
4908 diff --git a/arch/sparc/include/asm/page_32.h b/arch/sparc/include/asm/page_32.h
4909 index 156707b..aefa786 100644
4910 --- a/arch/sparc/include/asm/page_32.h
4911 +++ b/arch/sparc/include/asm/page_32.h
4912 @@ -8,6 +8,8 @@
4913 #ifndef _SPARC_PAGE_H
4914 #define _SPARC_PAGE_H
4915
4916 +#include <linux/const.h>
4917 +
4918 #define PAGE_SHIFT 12
4919
4920 #ifndef __ASSEMBLY__
4921 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4922 index a790cc6..091ed94 100644
4923 --- a/arch/sparc/include/asm/pgtable_32.h
4924 +++ b/arch/sparc/include/asm/pgtable_32.h
4925 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4926 BTFIXUPDEF_INT(page_none)
4927 BTFIXUPDEF_INT(page_copy)
4928 BTFIXUPDEF_INT(page_readonly)
4929 +
4930 +#ifdef CONFIG_PAX_PAGEEXEC
4931 +BTFIXUPDEF_INT(page_shared_noexec)
4932 +BTFIXUPDEF_INT(page_copy_noexec)
4933 +BTFIXUPDEF_INT(page_readonly_noexec)
4934 +#endif
4935 +
4936 BTFIXUPDEF_INT(page_kernel)
4937
4938 #define PMD_SHIFT SUN4C_PMD_SHIFT
4939 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
4940 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4941 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4942
4943 +#ifdef CONFIG_PAX_PAGEEXEC
4944 +extern pgprot_t PAGE_SHARED_NOEXEC;
4945 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4946 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4947 +#else
4948 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4949 +# define PAGE_COPY_NOEXEC PAGE_COPY
4950 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4951 +#endif
4952 +
4953 extern unsigned long page_kernel;
4954
4955 #ifdef MODULE
4956 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4957 index f6ae2b2..b03ffc7 100644
4958 --- a/arch/sparc/include/asm/pgtsrmmu.h
4959 +++ b/arch/sparc/include/asm/pgtsrmmu.h
4960 @@ -115,6 +115,13 @@
4961 SRMMU_EXEC | SRMMU_REF)
4962 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4963 SRMMU_EXEC | SRMMU_REF)
4964 +
4965 +#ifdef CONFIG_PAX_PAGEEXEC
4966 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4967 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4968 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4969 +#endif
4970 +
4971 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4972 SRMMU_DIRTY | SRMMU_REF)
4973
4974 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4975 index 9689176..63c18ea 100644
4976 --- a/arch/sparc/include/asm/spinlock_64.h
4977 +++ b/arch/sparc/include/asm/spinlock_64.h
4978 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
4979
4980 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4981
4982 -static void inline arch_read_lock(arch_rwlock_t *lock)
4983 +static inline void arch_read_lock(arch_rwlock_t *lock)
4984 {
4985 unsigned long tmp1, tmp2;
4986
4987 __asm__ __volatile__ (
4988 "1: ldsw [%2], %0\n"
4989 " brlz,pn %0, 2f\n"
4990 -"4: add %0, 1, %1\n"
4991 +"4: addcc %0, 1, %1\n"
4992 +
4993 +#ifdef CONFIG_PAX_REFCOUNT
4994 +" tvs %%icc, 6\n"
4995 +#endif
4996 +
4997 " cas [%2], %0, %1\n"
4998 " cmp %0, %1\n"
4999 " bne,pn %%icc, 1b\n"
5000 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5001 " .previous"
5002 : "=&r" (tmp1), "=&r" (tmp2)
5003 : "r" (lock)
5004 - : "memory");
5005 + : "memory", "cc");
5006 }
5007
5008 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5009 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5010 {
5011 int tmp1, tmp2;
5012
5013 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5014 "1: ldsw [%2], %0\n"
5015 " brlz,a,pn %0, 2f\n"
5016 " mov 0, %0\n"
5017 -" add %0, 1, %1\n"
5018 +" addcc %0, 1, %1\n"
5019 +
5020 +#ifdef CONFIG_PAX_REFCOUNT
5021 +" tvs %%icc, 6\n"
5022 +#endif
5023 +
5024 " cas [%2], %0, %1\n"
5025 " cmp %0, %1\n"
5026 " bne,pn %%icc, 1b\n"
5027 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5028 return tmp1;
5029 }
5030
5031 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5032 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5033 {
5034 unsigned long tmp1, tmp2;
5035
5036 __asm__ __volatile__(
5037 "1: lduw [%2], %0\n"
5038 -" sub %0, 1, %1\n"
5039 +" subcc %0, 1, %1\n"
5040 +
5041 +#ifdef CONFIG_PAX_REFCOUNT
5042 +" tvs %%icc, 6\n"
5043 +#endif
5044 +
5045 " cas [%2], %0, %1\n"
5046 " cmp %0, %1\n"
5047 " bne,pn %%xcc, 1b\n"
5048 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5049 : "memory");
5050 }
5051
5052 -static void inline arch_write_lock(arch_rwlock_t *lock)
5053 +static inline void arch_write_lock(arch_rwlock_t *lock)
5054 {
5055 unsigned long mask, tmp1, tmp2;
5056
5057 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5058 : "memory");
5059 }
5060
5061 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5062 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5063 {
5064 __asm__ __volatile__(
5065 " stw %%g0, [%0]"
5066 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5067 : "memory");
5068 }
5069
5070 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5071 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5072 {
5073 unsigned long mask, tmp1, tmp2, result;
5074
5075 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5076 index fa57532..e1a4c53 100644
5077 --- a/arch/sparc/include/asm/thread_info_32.h
5078 +++ b/arch/sparc/include/asm/thread_info_32.h
5079 @@ -50,6 +50,8 @@ struct thread_info {
5080 unsigned long w_saved;
5081
5082 struct restart_block restart_block;
5083 +
5084 + unsigned long lowest_stack;
5085 };
5086
5087 /*
5088 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5089 index 60d86be..952dea1 100644
5090 --- a/arch/sparc/include/asm/thread_info_64.h
5091 +++ b/arch/sparc/include/asm/thread_info_64.h
5092 @@ -63,6 +63,8 @@ struct thread_info {
5093 struct pt_regs *kern_una_regs;
5094 unsigned int kern_una_insn;
5095
5096 + unsigned long lowest_stack;
5097 +
5098 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5099 };
5100
5101 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5102 index e88fbe5..96b0ce5 100644
5103 --- a/arch/sparc/include/asm/uaccess.h
5104 +++ b/arch/sparc/include/asm/uaccess.h
5105 @@ -1,5 +1,13 @@
5106 #ifndef ___ASM_SPARC_UACCESS_H
5107 #define ___ASM_SPARC_UACCESS_H
5108 +
5109 +#ifdef __KERNEL__
5110 +#ifndef __ASSEMBLY__
5111 +#include <linux/types.h>
5112 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5113 +#endif
5114 +#endif
5115 +
5116 #if defined(__sparc__) && defined(__arch64__)
5117 #include <asm/uaccess_64.h>
5118 #else
5119 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5120 index 8303ac4..07f333d 100644
5121 --- a/arch/sparc/include/asm/uaccess_32.h
5122 +++ b/arch/sparc/include/asm/uaccess_32.h
5123 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5124
5125 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5126 {
5127 - if (n && __access_ok((unsigned long) to, n))
5128 + if ((long)n < 0)
5129 + return n;
5130 +
5131 + if (n && __access_ok((unsigned long) to, n)) {
5132 + if (!__builtin_constant_p(n))
5133 + check_object_size(from, n, true);
5134 return __copy_user(to, (__force void __user *) from, n);
5135 - else
5136 + } else
5137 return n;
5138 }
5139
5140 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5141 {
5142 + if ((long)n < 0)
5143 + return n;
5144 +
5145 + if (!__builtin_constant_p(n))
5146 + check_object_size(from, n, true);
5147 +
5148 return __copy_user(to, (__force void __user *) from, n);
5149 }
5150
5151 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5152 {
5153 - if (n && __access_ok((unsigned long) from, n))
5154 + if ((long)n < 0)
5155 + return n;
5156 +
5157 + if (n && __access_ok((unsigned long) from, n)) {
5158 + if (!__builtin_constant_p(n))
5159 + check_object_size(to, n, false);
5160 return __copy_user((__force void __user *) to, from, n);
5161 - else
5162 + } else
5163 return n;
5164 }
5165
5166 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5167 {
5168 + if ((long)n < 0)
5169 + return n;
5170 +
5171 return __copy_user((__force void __user *) to, from, n);
5172 }
5173
5174 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5175 index 3e1449f..5293a0e 100644
5176 --- a/arch/sparc/include/asm/uaccess_64.h
5177 +++ b/arch/sparc/include/asm/uaccess_64.h
5178 @@ -10,6 +10,7 @@
5179 #include <linux/compiler.h>
5180 #include <linux/string.h>
5181 #include <linux/thread_info.h>
5182 +#include <linux/kernel.h>
5183 #include <asm/asi.h>
5184 #include <asm/system.h>
5185 #include <asm/spitfire.h>
5186 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5187 static inline unsigned long __must_check
5188 copy_from_user(void *to, const void __user *from, unsigned long size)
5189 {
5190 - unsigned long ret = ___copy_from_user(to, from, size);
5191 + unsigned long ret;
5192
5193 + if ((long)size < 0 || size > INT_MAX)
5194 + return size;
5195 +
5196 + if (!__builtin_constant_p(size))
5197 + check_object_size(to, size, false);
5198 +
5199 + ret = ___copy_from_user(to, from, size);
5200 if (unlikely(ret))
5201 ret = copy_from_user_fixup(to, from, size);
5202
5203 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5204 static inline unsigned long __must_check
5205 copy_to_user(void __user *to, const void *from, unsigned long size)
5206 {
5207 - unsigned long ret = ___copy_to_user(to, from, size);
5208 + unsigned long ret;
5209
5210 + if ((long)size < 0 || size > INT_MAX)
5211 + return size;
5212 +
5213 + if (!__builtin_constant_p(size))
5214 + check_object_size(from, size, true);
5215 +
5216 + ret = ___copy_to_user(to, from, size);
5217 if (unlikely(ret))
5218 ret = copy_to_user_fixup(to, from, size);
5219 return ret;
5220 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5221 index cb85458..e063f17 100644
5222 --- a/arch/sparc/kernel/Makefile
5223 +++ b/arch/sparc/kernel/Makefile
5224 @@ -3,7 +3,7 @@
5225 #
5226
5227 asflags-y := -ansi
5228 -ccflags-y := -Werror
5229 +#ccflags-y := -Werror
5230
5231 extra-y := head_$(BITS).o
5232 extra-y += init_task.o
5233 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5234 index f793742..4d880af 100644
5235 --- a/arch/sparc/kernel/process_32.c
5236 +++ b/arch/sparc/kernel/process_32.c
5237 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5238 rw->ins[4], rw->ins[5],
5239 rw->ins[6],
5240 rw->ins[7]);
5241 - printk("%pS\n", (void *) rw->ins[7]);
5242 + printk("%pA\n", (void *) rw->ins[7]);
5243 rw = (struct reg_window32 *) rw->ins[6];
5244 }
5245 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5246 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5247
5248 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5249 r->psr, r->pc, r->npc, r->y, print_tainted());
5250 - printk("PC: <%pS>\n", (void *) r->pc);
5251 + printk("PC: <%pA>\n", (void *) r->pc);
5252 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5253 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5254 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5255 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5256 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5257 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5258 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5259 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5260
5261 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5262 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5263 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5264 rw = (struct reg_window32 *) fp;
5265 pc = rw->ins[7];
5266 printk("[%08lx : ", pc);
5267 - printk("%pS ] ", (void *) pc);
5268 + printk("%pA ] ", (void *) pc);
5269 fp = rw->ins[6];
5270 } while (++count < 16);
5271 printk("\n");
5272 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5273 index 3739a06..48b2ff0 100644
5274 --- a/arch/sparc/kernel/process_64.c
5275 +++ b/arch/sparc/kernel/process_64.c
5276 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
5277 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5278 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5279 if (regs->tstate & TSTATE_PRIV)
5280 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5281 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5282 }
5283
5284 void show_regs(struct pt_regs *regs)
5285 {
5286 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5287 regs->tpc, regs->tnpc, regs->y, print_tainted());
5288 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5289 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5290 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5291 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5292 regs->u_regs[3]);
5293 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5294 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5295 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5296 regs->u_regs[15]);
5297 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5298 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5299 show_regwindow(regs);
5300 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5301 }
5302 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void)
5303 ((tp && tp->task) ? tp->task->pid : -1));
5304
5305 if (gp->tstate & TSTATE_PRIV) {
5306 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5307 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5308 (void *) gp->tpc,
5309 (void *) gp->o7,
5310 (void *) gp->i7,
5311 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5312 index 42b282f..28ce9f2 100644
5313 --- a/arch/sparc/kernel/sys_sparc_32.c
5314 +++ b/arch/sparc/kernel/sys_sparc_32.c
5315 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5316 if (ARCH_SUN4C && len > 0x20000000)
5317 return -ENOMEM;
5318 if (!addr)
5319 - addr = TASK_UNMAPPED_BASE;
5320 + addr = current->mm->mmap_base;
5321
5322 if (flags & MAP_SHARED)
5323 addr = COLOUR_ALIGN(addr);
5324 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5325 }
5326 if (TASK_SIZE - PAGE_SIZE - len < addr)
5327 return -ENOMEM;
5328 - if (!vmm || addr + len <= vmm->vm_start)
5329 + if (check_heap_stack_gap(vmm, addr, len))
5330 return addr;
5331 addr = vmm->vm_end;
5332 if (flags & MAP_SHARED)
5333 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5334 index 441521a..b767073 100644
5335 --- a/arch/sparc/kernel/sys_sparc_64.c
5336 +++ b/arch/sparc/kernel/sys_sparc_64.c
5337 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5338 /* We do not accept a shared mapping if it would violate
5339 * cache aliasing constraints.
5340 */
5341 - if ((flags & MAP_SHARED) &&
5342 + if ((filp || (flags & MAP_SHARED)) &&
5343 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5344 return -EINVAL;
5345 return addr;
5346 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5347 if (filp || (flags & MAP_SHARED))
5348 do_color_align = 1;
5349
5350 +#ifdef CONFIG_PAX_RANDMMAP
5351 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5352 +#endif
5353 +
5354 if (addr) {
5355 if (do_color_align)
5356 addr = COLOUR_ALIGN(addr, pgoff);
5357 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5358 addr = PAGE_ALIGN(addr);
5359
5360 vma = find_vma(mm, addr);
5361 - if (task_size - len >= addr &&
5362 - (!vma || addr + len <= vma->vm_start))
5363 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5364 return addr;
5365 }
5366
5367 if (len > mm->cached_hole_size) {
5368 - start_addr = addr = mm->free_area_cache;
5369 + start_addr = addr = mm->free_area_cache;
5370 } else {
5371 - start_addr = addr = TASK_UNMAPPED_BASE;
5372 + start_addr = addr = mm->mmap_base;
5373 mm->cached_hole_size = 0;
5374 }
5375
5376 @@ -174,14 +177,14 @@ full_search:
5377 vma = find_vma(mm, VA_EXCLUDE_END);
5378 }
5379 if (unlikely(task_size < addr)) {
5380 - if (start_addr != TASK_UNMAPPED_BASE) {
5381 - start_addr = addr = TASK_UNMAPPED_BASE;
5382 + if (start_addr != mm->mmap_base) {
5383 + start_addr = addr = mm->mmap_base;
5384 mm->cached_hole_size = 0;
5385 goto full_search;
5386 }
5387 return -ENOMEM;
5388 }
5389 - if (likely(!vma || addr + len <= vma->vm_start)) {
5390 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5391 /*
5392 * Remember the place where we stopped the search:
5393 */
5394 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5395 /* We do not accept a shared mapping if it would violate
5396 * cache aliasing constraints.
5397 */
5398 - if ((flags & MAP_SHARED) &&
5399 + if ((filp || (flags & MAP_SHARED)) &&
5400 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5401 return -EINVAL;
5402 return addr;
5403 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5404 addr = PAGE_ALIGN(addr);
5405
5406 vma = find_vma(mm, addr);
5407 - if (task_size - len >= addr &&
5408 - (!vma || addr + len <= vma->vm_start))
5409 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5410 return addr;
5411 }
5412
5413 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5414 /* make sure it can fit in the remaining address space */
5415 if (likely(addr > len)) {
5416 vma = find_vma(mm, addr-len);
5417 - if (!vma || addr <= vma->vm_start) {
5418 + if (check_heap_stack_gap(vma, addr - len, len)) {
5419 /* remember the address as a hint for next time */
5420 return (mm->free_area_cache = addr-len);
5421 }
5422 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5423 if (unlikely(mm->mmap_base < len))
5424 goto bottomup;
5425
5426 - addr = mm->mmap_base-len;
5427 - if (do_color_align)
5428 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5429 + addr = mm->mmap_base - len;
5430
5431 do {
5432 + if (do_color_align)
5433 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5434 /*
5435 * Lookup failure means no vma is above this address,
5436 * else if new region fits below vma->vm_start,
5437 * return with success:
5438 */
5439 vma = find_vma(mm, addr);
5440 - if (likely(!vma || addr+len <= vma->vm_start)) {
5441 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5442 /* remember the address as a hint for next time */
5443 return (mm->free_area_cache = addr);
5444 }
5445 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5446 mm->cached_hole_size = vma->vm_start - addr;
5447
5448 /* try just below the current vma->vm_start */
5449 - addr = vma->vm_start-len;
5450 - if (do_color_align)
5451 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5452 - } while (likely(len < vma->vm_start));
5453 + addr = skip_heap_stack_gap(vma, len);
5454 + } while (!IS_ERR_VALUE(addr));
5455
5456 bottomup:
5457 /*
5458 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5459 gap == RLIM_INFINITY ||
5460 sysctl_legacy_va_layout) {
5461 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5462 +
5463 +#ifdef CONFIG_PAX_RANDMMAP
5464 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5465 + mm->mmap_base += mm->delta_mmap;
5466 +#endif
5467 +
5468 mm->get_unmapped_area = arch_get_unmapped_area;
5469 mm->unmap_area = arch_unmap_area;
5470 } else {
5471 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5472 gap = (task_size / 6 * 5);
5473
5474 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5475 +
5476 +#ifdef CONFIG_PAX_RANDMMAP
5477 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5478 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5479 +#endif
5480 +
5481 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5482 mm->unmap_area = arch_unmap_area_topdown;
5483 }
5484 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5485 index 591f20c..0f1b925 100644
5486 --- a/arch/sparc/kernel/traps_32.c
5487 +++ b/arch/sparc/kernel/traps_32.c
5488 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5489 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5490 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5491
5492 +extern void gr_handle_kernel_exploit(void);
5493 +
5494 void die_if_kernel(char *str, struct pt_regs *regs)
5495 {
5496 static int die_counter;
5497 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5498 count++ < 30 &&
5499 (((unsigned long) rw) >= PAGE_OFFSET) &&
5500 !(((unsigned long) rw) & 0x7)) {
5501 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5502 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5503 (void *) rw->ins[7]);
5504 rw = (struct reg_window32 *)rw->ins[6];
5505 }
5506 }
5507 printk("Instruction DUMP:");
5508 instruction_dump ((unsigned long *) regs->pc);
5509 - if(regs->psr & PSR_PS)
5510 + if(regs->psr & PSR_PS) {
5511 + gr_handle_kernel_exploit();
5512 do_exit(SIGKILL);
5513 + }
5514 do_exit(SIGSEGV);
5515 }
5516
5517 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5518 index 0cbdaa4..438e4c9 100644
5519 --- a/arch/sparc/kernel/traps_64.c
5520 +++ b/arch/sparc/kernel/traps_64.c
5521 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5522 i + 1,
5523 p->trapstack[i].tstate, p->trapstack[i].tpc,
5524 p->trapstack[i].tnpc, p->trapstack[i].tt);
5525 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5526 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5527 }
5528 }
5529
5530 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5531
5532 lvl -= 0x100;
5533 if (regs->tstate & TSTATE_PRIV) {
5534 +
5535 +#ifdef CONFIG_PAX_REFCOUNT
5536 + if (lvl == 6)
5537 + pax_report_refcount_overflow(regs);
5538 +#endif
5539 +
5540 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5541 die_if_kernel(buffer, regs);
5542 }
5543 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5544 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5545 {
5546 char buffer[32];
5547 -
5548 +
5549 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5550 0, lvl, SIGTRAP) == NOTIFY_STOP)
5551 return;
5552
5553 +#ifdef CONFIG_PAX_REFCOUNT
5554 + if (lvl == 6)
5555 + pax_report_refcount_overflow(regs);
5556 +#endif
5557 +
5558 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5559
5560 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5561 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5562 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5563 printk("%s" "ERROR(%d): ",
5564 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5565 - printk("TPC<%pS>\n", (void *) regs->tpc);
5566 + printk("TPC<%pA>\n", (void *) regs->tpc);
5567 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5568 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5569 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5570 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5571 smp_processor_id(),
5572 (type & 0x1) ? 'I' : 'D',
5573 regs->tpc);
5574 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5575 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5576 panic("Irrecoverable Cheetah+ parity error.");
5577 }
5578
5579 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5580 smp_processor_id(),
5581 (type & 0x1) ? 'I' : 'D',
5582 regs->tpc);
5583 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5584 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5585 }
5586
5587 struct sun4v_error_entry {
5588 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5589
5590 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5591 regs->tpc, tl);
5592 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5593 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5594 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5595 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5596 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5597 (void *) regs->u_regs[UREG_I7]);
5598 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5599 "pte[%lx] error[%lx]\n",
5600 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5601
5602 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5603 regs->tpc, tl);
5604 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5605 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5606 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5607 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5608 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5609 (void *) regs->u_regs[UREG_I7]);
5610 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5611 "pte[%lx] error[%lx]\n",
5612 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5613 fp = (unsigned long)sf->fp + STACK_BIAS;
5614 }
5615
5616 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5617 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5618 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5619 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5620 int index = tsk->curr_ret_stack;
5621 if (tsk->ret_stack && index >= graph) {
5622 pc = tsk->ret_stack[index - graph].ret;
5623 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5624 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5625 graph++;
5626 }
5627 }
5628 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5629 return (struct reg_window *) (fp + STACK_BIAS);
5630 }
5631
5632 +extern void gr_handle_kernel_exploit(void);
5633 +
5634 void die_if_kernel(char *str, struct pt_regs *regs)
5635 {
5636 static int die_counter;
5637 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5638 while (rw &&
5639 count++ < 30 &&
5640 kstack_valid(tp, (unsigned long) rw)) {
5641 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5642 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5643 (void *) rw->ins[7]);
5644
5645 rw = kernel_stack_up(rw);
5646 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5647 }
5648 user_instruction_dump ((unsigned int __user *) regs->tpc);
5649 }
5650 - if (regs->tstate & TSTATE_PRIV)
5651 + if (regs->tstate & TSTATE_PRIV) {
5652 + gr_handle_kernel_exploit();
5653 do_exit(SIGKILL);
5654 + }
5655 do_exit(SIGSEGV);
5656 }
5657 EXPORT_SYMBOL(die_if_kernel);
5658 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5659 index 76e4ac1..78f8bb1 100644
5660 --- a/arch/sparc/kernel/unaligned_64.c
5661 +++ b/arch/sparc/kernel/unaligned_64.c
5662 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5663 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5664
5665 if (__ratelimit(&ratelimit)) {
5666 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5667 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5668 regs->tpc, (void *) regs->tpc);
5669 }
5670 }
5671 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5672 index a3fc437..fea9957 100644
5673 --- a/arch/sparc/lib/Makefile
5674 +++ b/arch/sparc/lib/Makefile
5675 @@ -2,7 +2,7 @@
5676 #
5677
5678 asflags-y := -ansi -DST_DIV0=0x02
5679 -ccflags-y := -Werror
5680 +#ccflags-y := -Werror
5681
5682 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5683 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5684 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5685 index 59186e0..f747d7a 100644
5686 --- a/arch/sparc/lib/atomic_64.S
5687 +++ b/arch/sparc/lib/atomic_64.S
5688 @@ -18,7 +18,12 @@
5689 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5690 BACKOFF_SETUP(%o2)
5691 1: lduw [%o1], %g1
5692 - add %g1, %o0, %g7
5693 + addcc %g1, %o0, %g7
5694 +
5695 +#ifdef CONFIG_PAX_REFCOUNT
5696 + tvs %icc, 6
5697 +#endif
5698 +
5699 cas [%o1], %g1, %g7
5700 cmp %g1, %g7
5701 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5702 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5703 2: BACKOFF_SPIN(%o2, %o3, 1b)
5704 .size atomic_add, .-atomic_add
5705
5706 + .globl atomic_add_unchecked
5707 + .type atomic_add_unchecked,#function
5708 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5709 + BACKOFF_SETUP(%o2)
5710 +1: lduw [%o1], %g1
5711 + add %g1, %o0, %g7
5712 + cas [%o1], %g1, %g7
5713 + cmp %g1, %g7
5714 + bne,pn %icc, 2f
5715 + nop
5716 + retl
5717 + nop
5718 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5719 + .size atomic_add_unchecked, .-atomic_add_unchecked
5720 +
5721 .globl atomic_sub
5722 .type atomic_sub,#function
5723 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5724 BACKOFF_SETUP(%o2)
5725 1: lduw [%o1], %g1
5726 - sub %g1, %o0, %g7
5727 + subcc %g1, %o0, %g7
5728 +
5729 +#ifdef CONFIG_PAX_REFCOUNT
5730 + tvs %icc, 6
5731 +#endif
5732 +
5733 cas [%o1], %g1, %g7
5734 cmp %g1, %g7
5735 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5736 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5737 2: BACKOFF_SPIN(%o2, %o3, 1b)
5738 .size atomic_sub, .-atomic_sub
5739
5740 + .globl atomic_sub_unchecked
5741 + .type atomic_sub_unchecked,#function
5742 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5743 + BACKOFF_SETUP(%o2)
5744 +1: lduw [%o1], %g1
5745 + sub %g1, %o0, %g7
5746 + cas [%o1], %g1, %g7
5747 + cmp %g1, %g7
5748 + bne,pn %icc, 2f
5749 + nop
5750 + retl
5751 + nop
5752 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5753 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5754 +
5755 .globl atomic_add_ret
5756 .type atomic_add_ret,#function
5757 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5758 BACKOFF_SETUP(%o2)
5759 1: lduw [%o1], %g1
5760 - add %g1, %o0, %g7
5761 + addcc %g1, %o0, %g7
5762 +
5763 +#ifdef CONFIG_PAX_REFCOUNT
5764 + tvs %icc, 6
5765 +#endif
5766 +
5767 cas [%o1], %g1, %g7
5768 cmp %g1, %g7
5769 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5770 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5771 2: BACKOFF_SPIN(%o2, %o3, 1b)
5772 .size atomic_add_ret, .-atomic_add_ret
5773
5774 + .globl atomic_add_ret_unchecked
5775 + .type atomic_add_ret_unchecked,#function
5776 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5777 + BACKOFF_SETUP(%o2)
5778 +1: lduw [%o1], %g1
5779 + addcc %g1, %o0, %g7
5780 + cas [%o1], %g1, %g7
5781 + cmp %g1, %g7
5782 + bne,pn %icc, 2f
5783 + add %g7, %o0, %g7
5784 + sra %g7, 0, %o0
5785 + retl
5786 + nop
5787 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5788 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5789 +
5790 .globl atomic_sub_ret
5791 .type atomic_sub_ret,#function
5792 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5793 BACKOFF_SETUP(%o2)
5794 1: lduw [%o1], %g1
5795 - sub %g1, %o0, %g7
5796 + subcc %g1, %o0, %g7
5797 +
5798 +#ifdef CONFIG_PAX_REFCOUNT
5799 + tvs %icc, 6
5800 +#endif
5801 +
5802 cas [%o1], %g1, %g7
5803 cmp %g1, %g7
5804 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5805 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5806 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5807 BACKOFF_SETUP(%o2)
5808 1: ldx [%o1], %g1
5809 - add %g1, %o0, %g7
5810 + addcc %g1, %o0, %g7
5811 +
5812 +#ifdef CONFIG_PAX_REFCOUNT
5813 + tvs %xcc, 6
5814 +#endif
5815 +
5816 casx [%o1], %g1, %g7
5817 cmp %g1, %g7
5818 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5819 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5820 2: BACKOFF_SPIN(%o2, %o3, 1b)
5821 .size atomic64_add, .-atomic64_add
5822
5823 + .globl atomic64_add_unchecked
5824 + .type atomic64_add_unchecked,#function
5825 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5826 + BACKOFF_SETUP(%o2)
5827 +1: ldx [%o1], %g1
5828 + addcc %g1, %o0, %g7
5829 + casx [%o1], %g1, %g7
5830 + cmp %g1, %g7
5831 + bne,pn %xcc, 2f
5832 + nop
5833 + retl
5834 + nop
5835 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5836 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5837 +
5838 .globl atomic64_sub
5839 .type atomic64_sub,#function
5840 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5841 BACKOFF_SETUP(%o2)
5842 1: ldx [%o1], %g1
5843 - sub %g1, %o0, %g7
5844 + subcc %g1, %o0, %g7
5845 +
5846 +#ifdef CONFIG_PAX_REFCOUNT
5847 + tvs %xcc, 6
5848 +#endif
5849 +
5850 casx [%o1], %g1, %g7
5851 cmp %g1, %g7
5852 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5853 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5854 2: BACKOFF_SPIN(%o2, %o3, 1b)
5855 .size atomic64_sub, .-atomic64_sub
5856
5857 + .globl atomic64_sub_unchecked
5858 + .type atomic64_sub_unchecked,#function
5859 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5860 + BACKOFF_SETUP(%o2)
5861 +1: ldx [%o1], %g1
5862 + subcc %g1, %o0, %g7
5863 + casx [%o1], %g1, %g7
5864 + cmp %g1, %g7
5865 + bne,pn %xcc, 2f
5866 + nop
5867 + retl
5868 + nop
5869 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5870 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5871 +
5872 .globl atomic64_add_ret
5873 .type atomic64_add_ret,#function
5874 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5875 BACKOFF_SETUP(%o2)
5876 1: ldx [%o1], %g1
5877 - add %g1, %o0, %g7
5878 + addcc %g1, %o0, %g7
5879 +
5880 +#ifdef CONFIG_PAX_REFCOUNT
5881 + tvs %xcc, 6
5882 +#endif
5883 +
5884 casx [%o1], %g1, %g7
5885 cmp %g1, %g7
5886 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5887 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5888 2: BACKOFF_SPIN(%o2, %o3, 1b)
5889 .size atomic64_add_ret, .-atomic64_add_ret
5890
5891 + .globl atomic64_add_ret_unchecked
5892 + .type atomic64_add_ret_unchecked,#function
5893 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5894 + BACKOFF_SETUP(%o2)
5895 +1: ldx [%o1], %g1
5896 + addcc %g1, %o0, %g7
5897 + casx [%o1], %g1, %g7
5898 + cmp %g1, %g7
5899 + bne,pn %xcc, 2f
5900 + add %g7, %o0, %g7
5901 + mov %g7, %o0
5902 + retl
5903 + nop
5904 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5905 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5906 +
5907 .globl atomic64_sub_ret
5908 .type atomic64_sub_ret,#function
5909 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5910 BACKOFF_SETUP(%o2)
5911 1: ldx [%o1], %g1
5912 - sub %g1, %o0, %g7
5913 + subcc %g1, %o0, %g7
5914 +
5915 +#ifdef CONFIG_PAX_REFCOUNT
5916 + tvs %xcc, 6
5917 +#endif
5918 +
5919 casx [%o1], %g1, %g7
5920 cmp %g1, %g7
5921 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5922 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5923 index 1b30bb3..b4a16c7 100644
5924 --- a/arch/sparc/lib/ksyms.c
5925 +++ b/arch/sparc/lib/ksyms.c
5926 @@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
5927
5928 /* Atomic counter implementation. */
5929 EXPORT_SYMBOL(atomic_add);
5930 +EXPORT_SYMBOL(atomic_add_unchecked);
5931 EXPORT_SYMBOL(atomic_add_ret);
5932 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5933 EXPORT_SYMBOL(atomic_sub);
5934 +EXPORT_SYMBOL(atomic_sub_unchecked);
5935 EXPORT_SYMBOL(atomic_sub_ret);
5936 EXPORT_SYMBOL(atomic64_add);
5937 +EXPORT_SYMBOL(atomic64_add_unchecked);
5938 EXPORT_SYMBOL(atomic64_add_ret);
5939 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5940 EXPORT_SYMBOL(atomic64_sub);
5941 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5942 EXPORT_SYMBOL(atomic64_sub_ret);
5943
5944 /* Atomic bit operations. */
5945 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5946 index 301421c..e2535d1 100644
5947 --- a/arch/sparc/mm/Makefile
5948 +++ b/arch/sparc/mm/Makefile
5949 @@ -2,7 +2,7 @@
5950 #
5951
5952 asflags-y := -ansi
5953 -ccflags-y := -Werror
5954 +#ccflags-y := -Werror
5955
5956 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
5957 obj-y += fault_$(BITS).o
5958 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5959 index 8023fd7..c8e89e9 100644
5960 --- a/arch/sparc/mm/fault_32.c
5961 +++ b/arch/sparc/mm/fault_32.c
5962 @@ -21,6 +21,9 @@
5963 #include <linux/perf_event.h>
5964 #include <linux/interrupt.h>
5965 #include <linux/kdebug.h>
5966 +#include <linux/slab.h>
5967 +#include <linux/pagemap.h>
5968 +#include <linux/compiler.h>
5969
5970 #include <asm/system.h>
5971 #include <asm/page.h>
5972 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5973 return safe_compute_effective_address(regs, insn);
5974 }
5975
5976 +#ifdef CONFIG_PAX_PAGEEXEC
5977 +#ifdef CONFIG_PAX_DLRESOLVE
5978 +static void pax_emuplt_close(struct vm_area_struct *vma)
5979 +{
5980 + vma->vm_mm->call_dl_resolve = 0UL;
5981 +}
5982 +
5983 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5984 +{
5985 + unsigned int *kaddr;
5986 +
5987 + vmf->page = alloc_page(GFP_HIGHUSER);
5988 + if (!vmf->page)
5989 + return VM_FAULT_OOM;
5990 +
5991 + kaddr = kmap(vmf->page);
5992 + memset(kaddr, 0, PAGE_SIZE);
5993 + kaddr[0] = 0x9DE3BFA8U; /* save */
5994 + flush_dcache_page(vmf->page);
5995 + kunmap(vmf->page);
5996 + return VM_FAULT_MAJOR;
5997 +}
5998 +
5999 +static const struct vm_operations_struct pax_vm_ops = {
6000 + .close = pax_emuplt_close,
6001 + .fault = pax_emuplt_fault
6002 +};
6003 +
6004 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6005 +{
6006 + int ret;
6007 +
6008 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6009 + vma->vm_mm = current->mm;
6010 + vma->vm_start = addr;
6011 + vma->vm_end = addr + PAGE_SIZE;
6012 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6013 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6014 + vma->vm_ops = &pax_vm_ops;
6015 +
6016 + ret = insert_vm_struct(current->mm, vma);
6017 + if (ret)
6018 + return ret;
6019 +
6020 + ++current->mm->total_vm;
6021 + return 0;
6022 +}
6023 +#endif
6024 +
6025 +/*
6026 + * PaX: decide what to do with offenders (regs->pc = fault address)
6027 + *
6028 + * returns 1 when task should be killed
6029 + * 2 when patched PLT trampoline was detected
6030 + * 3 when unpatched PLT trampoline was detected
6031 + */
6032 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6033 +{
6034 +
6035 +#ifdef CONFIG_PAX_EMUPLT
6036 + int err;
6037 +
6038 + do { /* PaX: patched PLT emulation #1 */
6039 + unsigned int sethi1, sethi2, jmpl;
6040 +
6041 + err = get_user(sethi1, (unsigned int *)regs->pc);
6042 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6043 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6044 +
6045 + if (err)
6046 + break;
6047 +
6048 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6049 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6050 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6051 + {
6052 + unsigned int addr;
6053 +
6054 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6055 + addr = regs->u_regs[UREG_G1];
6056 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6057 + regs->pc = addr;
6058 + regs->npc = addr+4;
6059 + return 2;
6060 + }
6061 + } while (0);
6062 +
6063 + { /* PaX: patched PLT emulation #2 */
6064 + unsigned int ba;
6065 +
6066 + err = get_user(ba, (unsigned int *)regs->pc);
6067 +
6068 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6069 + unsigned int addr;
6070 +
6071 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6072 + regs->pc = addr;
6073 + regs->npc = addr+4;
6074 + return 2;
6075 + }
6076 + }
6077 +
6078 + do { /* PaX: patched PLT emulation #3 */
6079 + unsigned int sethi, jmpl, nop;
6080 +
6081 + err = get_user(sethi, (unsigned int *)regs->pc);
6082 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6083 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6084 +
6085 + if (err)
6086 + break;
6087 +
6088 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6089 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6090 + nop == 0x01000000U)
6091 + {
6092 + unsigned int addr;
6093 +
6094 + addr = (sethi & 0x003FFFFFU) << 10;
6095 + regs->u_regs[UREG_G1] = addr;
6096 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6097 + regs->pc = addr;
6098 + regs->npc = addr+4;
6099 + return 2;
6100 + }
6101 + } while (0);
6102 +
6103 + do { /* PaX: unpatched PLT emulation step 1 */
6104 + unsigned int sethi, ba, nop;
6105 +
6106 + err = get_user(sethi, (unsigned int *)regs->pc);
6107 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6108 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6109 +
6110 + if (err)
6111 + break;
6112 +
6113 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6114 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6115 + nop == 0x01000000U)
6116 + {
6117 + unsigned int addr, save, call;
6118 +
6119 + if ((ba & 0xFFC00000U) == 0x30800000U)
6120 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6121 + else
6122 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6123 +
6124 + err = get_user(save, (unsigned int *)addr);
6125 + err |= get_user(call, (unsigned int *)(addr+4));
6126 + err |= get_user(nop, (unsigned int *)(addr+8));
6127 + if (err)
6128 + break;
6129 +
6130 +#ifdef CONFIG_PAX_DLRESOLVE
6131 + if (save == 0x9DE3BFA8U &&
6132 + (call & 0xC0000000U) == 0x40000000U &&
6133 + nop == 0x01000000U)
6134 + {
6135 + struct vm_area_struct *vma;
6136 + unsigned long call_dl_resolve;
6137 +
6138 + down_read(&current->mm->mmap_sem);
6139 + call_dl_resolve = current->mm->call_dl_resolve;
6140 + up_read(&current->mm->mmap_sem);
6141 + if (likely(call_dl_resolve))
6142 + goto emulate;
6143 +
6144 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6145 +
6146 + down_write(&current->mm->mmap_sem);
6147 + if (current->mm->call_dl_resolve) {
6148 + call_dl_resolve = current->mm->call_dl_resolve;
6149 + up_write(&current->mm->mmap_sem);
6150 + if (vma)
6151 + kmem_cache_free(vm_area_cachep, vma);
6152 + goto emulate;
6153 + }
6154 +
6155 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6156 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6157 + up_write(&current->mm->mmap_sem);
6158 + if (vma)
6159 + kmem_cache_free(vm_area_cachep, vma);
6160 + return 1;
6161 + }
6162 +
6163 + if (pax_insert_vma(vma, call_dl_resolve)) {
6164 + up_write(&current->mm->mmap_sem);
6165 + kmem_cache_free(vm_area_cachep, vma);
6166 + return 1;
6167 + }
6168 +
6169 + current->mm->call_dl_resolve = call_dl_resolve;
6170 + up_write(&current->mm->mmap_sem);
6171 +
6172 +emulate:
6173 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6174 + regs->pc = call_dl_resolve;
6175 + regs->npc = addr+4;
6176 + return 3;
6177 + }
6178 +#endif
6179 +
6180 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6181 + if ((save & 0xFFC00000U) == 0x05000000U &&
6182 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6183 + nop == 0x01000000U)
6184 + {
6185 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6186 + regs->u_regs[UREG_G2] = addr + 4;
6187 + addr = (save & 0x003FFFFFU) << 10;
6188 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6189 + regs->pc = addr;
6190 + regs->npc = addr+4;
6191 + return 3;
6192 + }
6193 + }
6194 + } while (0);
6195 +
6196 + do { /* PaX: unpatched PLT emulation step 2 */
6197 + unsigned int save, call, nop;
6198 +
6199 + err = get_user(save, (unsigned int *)(regs->pc-4));
6200 + err |= get_user(call, (unsigned int *)regs->pc);
6201 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6202 + if (err)
6203 + break;
6204 +
6205 + if (save == 0x9DE3BFA8U &&
6206 + (call & 0xC0000000U) == 0x40000000U &&
6207 + nop == 0x01000000U)
6208 + {
6209 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6210 +
6211 + regs->u_regs[UREG_RETPC] = regs->pc;
6212 + regs->pc = dl_resolve;
6213 + regs->npc = dl_resolve+4;
6214 + return 3;
6215 + }
6216 + } while (0);
6217 +#endif
6218 +
6219 + return 1;
6220 +}
6221 +
6222 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6223 +{
6224 + unsigned long i;
6225 +
6226 + printk(KERN_ERR "PAX: bytes at PC: ");
6227 + for (i = 0; i < 8; i++) {
6228 + unsigned int c;
6229 + if (get_user(c, (unsigned int *)pc+i))
6230 + printk(KERN_CONT "???????? ");
6231 + else
6232 + printk(KERN_CONT "%08x ", c);
6233 + }
6234 + printk("\n");
6235 +}
6236 +#endif
6237 +
6238 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6239 int text_fault)
6240 {
6241 @@ -280,6 +545,24 @@ good_area:
6242 if(!(vma->vm_flags & VM_WRITE))
6243 goto bad_area;
6244 } else {
6245 +
6246 +#ifdef CONFIG_PAX_PAGEEXEC
6247 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6248 + up_read(&mm->mmap_sem);
6249 + switch (pax_handle_fetch_fault(regs)) {
6250 +
6251 +#ifdef CONFIG_PAX_EMUPLT
6252 + case 2:
6253 + case 3:
6254 + return;
6255 +#endif
6256 +
6257 + }
6258 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6259 + do_group_exit(SIGKILL);
6260 + }
6261 +#endif
6262 +
6263 /* Allow reads even for write-only mappings */
6264 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6265 goto bad_area;
6266 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6267 index 504c062..6fcb9c6 100644
6268 --- a/arch/sparc/mm/fault_64.c
6269 +++ b/arch/sparc/mm/fault_64.c
6270 @@ -21,6 +21,9 @@
6271 #include <linux/kprobes.h>
6272 #include <linux/kdebug.h>
6273 #include <linux/percpu.h>
6274 +#include <linux/slab.h>
6275 +#include <linux/pagemap.h>
6276 +#include <linux/compiler.h>
6277
6278 #include <asm/page.h>
6279 #include <asm/pgtable.h>
6280 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6281 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6282 regs->tpc);
6283 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6284 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6285 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6286 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6287 dump_stack();
6288 unhandled_fault(regs->tpc, current, regs);
6289 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6290 show_regs(regs);
6291 }
6292
6293 +#ifdef CONFIG_PAX_PAGEEXEC
6294 +#ifdef CONFIG_PAX_DLRESOLVE
6295 +static void pax_emuplt_close(struct vm_area_struct *vma)
6296 +{
6297 + vma->vm_mm->call_dl_resolve = 0UL;
6298 +}
6299 +
6300 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6301 +{
6302 + unsigned int *kaddr;
6303 +
6304 + vmf->page = alloc_page(GFP_HIGHUSER);
6305 + if (!vmf->page)
6306 + return VM_FAULT_OOM;
6307 +
6308 + kaddr = kmap(vmf->page);
6309 + memset(kaddr, 0, PAGE_SIZE);
6310 + kaddr[0] = 0x9DE3BFA8U; /* save */
6311 + flush_dcache_page(vmf->page);
6312 + kunmap(vmf->page);
6313 + return VM_FAULT_MAJOR;
6314 +}
6315 +
6316 +static const struct vm_operations_struct pax_vm_ops = {
6317 + .close = pax_emuplt_close,
6318 + .fault = pax_emuplt_fault
6319 +};
6320 +
6321 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6322 +{
6323 + int ret;
6324 +
6325 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6326 + vma->vm_mm = current->mm;
6327 + vma->vm_start = addr;
6328 + vma->vm_end = addr + PAGE_SIZE;
6329 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6330 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6331 + vma->vm_ops = &pax_vm_ops;
6332 +
6333 + ret = insert_vm_struct(current->mm, vma);
6334 + if (ret)
6335 + return ret;
6336 +
6337 + ++current->mm->total_vm;
6338 + return 0;
6339 +}
6340 +#endif
6341 +
6342 +/*
6343 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6344 + *
6345 + * returns 1 when task should be killed
6346 + * 2 when patched PLT trampoline was detected
6347 + * 3 when unpatched PLT trampoline was detected
6348 + */
6349 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6350 +{
6351 +
6352 +#ifdef CONFIG_PAX_EMUPLT
6353 + int err;
6354 +
6355 + do { /* PaX: patched PLT emulation #1 */
6356 + unsigned int sethi1, sethi2, jmpl;
6357 +
6358 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6359 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6360 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6361 +
6362 + if (err)
6363 + break;
6364 +
6365 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6366 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6367 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6368 + {
6369 + unsigned long addr;
6370 +
6371 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6372 + addr = regs->u_regs[UREG_G1];
6373 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6374 +
6375 + if (test_thread_flag(TIF_32BIT))
6376 + addr &= 0xFFFFFFFFUL;
6377 +
6378 + regs->tpc = addr;
6379 + regs->tnpc = addr+4;
6380 + return 2;
6381 + }
6382 + } while (0);
6383 +
6384 + { /* PaX: patched PLT emulation #2 */
6385 + unsigned int ba;
6386 +
6387 + err = get_user(ba, (unsigned int *)regs->tpc);
6388 +
6389 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6390 + unsigned long addr;
6391 +
6392 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6393 +
6394 + if (test_thread_flag(TIF_32BIT))
6395 + addr &= 0xFFFFFFFFUL;
6396 +
6397 + regs->tpc = addr;
6398 + regs->tnpc = addr+4;
6399 + return 2;
6400 + }
6401 + }
6402 +
6403 + do { /* PaX: patched PLT emulation #3 */
6404 + unsigned int sethi, jmpl, nop;
6405 +
6406 + err = get_user(sethi, (unsigned int *)regs->tpc);
6407 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6408 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6409 +
6410 + if (err)
6411 + break;
6412 +
6413 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6414 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6415 + nop == 0x01000000U)
6416 + {
6417 + unsigned long addr;
6418 +
6419 + addr = (sethi & 0x003FFFFFU) << 10;
6420 + regs->u_regs[UREG_G1] = addr;
6421 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6422 +
6423 + if (test_thread_flag(TIF_32BIT))
6424 + addr &= 0xFFFFFFFFUL;
6425 +
6426 + regs->tpc = addr;
6427 + regs->tnpc = addr+4;
6428 + return 2;
6429 + }
6430 + } while (0);
6431 +
6432 + do { /* PaX: patched PLT emulation #4 */
6433 + unsigned int sethi, mov1, call, mov2;
6434 +
6435 + err = get_user(sethi, (unsigned int *)regs->tpc);
6436 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6437 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6438 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6439 +
6440 + if (err)
6441 + break;
6442 +
6443 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6444 + mov1 == 0x8210000FU &&
6445 + (call & 0xC0000000U) == 0x40000000U &&
6446 + mov2 == 0x9E100001U)
6447 + {
6448 + unsigned long addr;
6449 +
6450 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6451 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 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 + do { /* PaX: patched PLT emulation #5 */
6463 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6464 +
6465 + err = get_user(sethi, (unsigned int *)regs->tpc);
6466 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6467 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6468 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6469 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6470 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6471 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6472 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6473 +
6474 + if (err)
6475 + break;
6476 +
6477 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6478 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6479 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6480 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6481 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6482 + sllx == 0x83287020U &&
6483 + jmpl == 0x81C04005U &&
6484 + nop == 0x01000000U)
6485 + {
6486 + unsigned long addr;
6487 +
6488 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6489 + regs->u_regs[UREG_G1] <<= 32;
6490 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6491 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6492 + regs->tpc = addr;
6493 + regs->tnpc = addr+4;
6494 + return 2;
6495 + }
6496 + } while (0);
6497 +
6498 + do { /* PaX: patched PLT emulation #6 */
6499 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6500 +
6501 + err = get_user(sethi, (unsigned int *)regs->tpc);
6502 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6503 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6504 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6505 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6506 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6507 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6508 +
6509 + if (err)
6510 + break;
6511 +
6512 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6513 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6514 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6515 + sllx == 0x83287020U &&
6516 + (or & 0xFFFFE000U) == 0x8A116000U &&
6517 + jmpl == 0x81C04005U &&
6518 + nop == 0x01000000U)
6519 + {
6520 + unsigned long addr;
6521 +
6522 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6523 + regs->u_regs[UREG_G1] <<= 32;
6524 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6525 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6526 + regs->tpc = addr;
6527 + regs->tnpc = addr+4;
6528 + return 2;
6529 + }
6530 + } while (0);
6531 +
6532 + do { /* PaX: unpatched PLT emulation step 1 */
6533 + unsigned int sethi, ba, nop;
6534 +
6535 + err = get_user(sethi, (unsigned int *)regs->tpc);
6536 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6537 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6538 +
6539 + if (err)
6540 + break;
6541 +
6542 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6543 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6544 + nop == 0x01000000U)
6545 + {
6546 + unsigned long addr;
6547 + unsigned int save, call;
6548 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6549 +
6550 + if ((ba & 0xFFC00000U) == 0x30800000U)
6551 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6552 + else
6553 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6554 +
6555 + if (test_thread_flag(TIF_32BIT))
6556 + addr &= 0xFFFFFFFFUL;
6557 +
6558 + err = get_user(save, (unsigned int *)addr);
6559 + err |= get_user(call, (unsigned int *)(addr+4));
6560 + err |= get_user(nop, (unsigned int *)(addr+8));
6561 + if (err)
6562 + break;
6563 +
6564 +#ifdef CONFIG_PAX_DLRESOLVE
6565 + if (save == 0x9DE3BFA8U &&
6566 + (call & 0xC0000000U) == 0x40000000U &&
6567 + nop == 0x01000000U)
6568 + {
6569 + struct vm_area_struct *vma;
6570 + unsigned long call_dl_resolve;
6571 +
6572 + down_read(&current->mm->mmap_sem);
6573 + call_dl_resolve = current->mm->call_dl_resolve;
6574 + up_read(&current->mm->mmap_sem);
6575 + if (likely(call_dl_resolve))
6576 + goto emulate;
6577 +
6578 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6579 +
6580 + down_write(&current->mm->mmap_sem);
6581 + if (current->mm->call_dl_resolve) {
6582 + call_dl_resolve = current->mm->call_dl_resolve;
6583 + up_write(&current->mm->mmap_sem);
6584 + if (vma)
6585 + kmem_cache_free(vm_area_cachep, vma);
6586 + goto emulate;
6587 + }
6588 +
6589 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6590 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6591 + up_write(&current->mm->mmap_sem);
6592 + if (vma)
6593 + kmem_cache_free(vm_area_cachep, vma);
6594 + return 1;
6595 + }
6596 +
6597 + if (pax_insert_vma(vma, call_dl_resolve)) {
6598 + up_write(&current->mm->mmap_sem);
6599 + kmem_cache_free(vm_area_cachep, vma);
6600 + return 1;
6601 + }
6602 +
6603 + current->mm->call_dl_resolve = call_dl_resolve;
6604 + up_write(&current->mm->mmap_sem);
6605 +
6606 +emulate:
6607 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6608 + regs->tpc = call_dl_resolve;
6609 + regs->tnpc = addr+4;
6610 + return 3;
6611 + }
6612 +#endif
6613 +
6614 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6615 + if ((save & 0xFFC00000U) == 0x05000000U &&
6616 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6617 + nop == 0x01000000U)
6618 + {
6619 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6620 + regs->u_regs[UREG_G2] = addr + 4;
6621 + addr = (save & 0x003FFFFFU) << 10;
6622 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6623 +
6624 + if (test_thread_flag(TIF_32BIT))
6625 + addr &= 0xFFFFFFFFUL;
6626 +
6627 + regs->tpc = addr;
6628 + regs->tnpc = addr+4;
6629 + return 3;
6630 + }
6631 +
6632 + /* PaX: 64-bit PLT stub */
6633 + err = get_user(sethi1, (unsigned int *)addr);
6634 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6635 + err |= get_user(or1, (unsigned int *)(addr+8));
6636 + err |= get_user(or2, (unsigned int *)(addr+12));
6637 + err |= get_user(sllx, (unsigned int *)(addr+16));
6638 + err |= get_user(add, (unsigned int *)(addr+20));
6639 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6640 + err |= get_user(nop, (unsigned int *)(addr+28));
6641 + if (err)
6642 + break;
6643 +
6644 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6645 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6646 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6647 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6648 + sllx == 0x89293020U &&
6649 + add == 0x8A010005U &&
6650 + jmpl == 0x89C14000U &&
6651 + nop == 0x01000000U)
6652 + {
6653 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6654 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6655 + regs->u_regs[UREG_G4] <<= 32;
6656 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6657 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6658 + regs->u_regs[UREG_G4] = addr + 24;
6659 + addr = regs->u_regs[UREG_G5];
6660 + regs->tpc = addr;
6661 + regs->tnpc = addr+4;
6662 + return 3;
6663 + }
6664 + }
6665 + } while (0);
6666 +
6667 +#ifdef CONFIG_PAX_DLRESOLVE
6668 + do { /* PaX: unpatched PLT emulation step 2 */
6669 + unsigned int save, call, nop;
6670 +
6671 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6672 + err |= get_user(call, (unsigned int *)regs->tpc);
6673 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6674 + if (err)
6675 + break;
6676 +
6677 + if (save == 0x9DE3BFA8U &&
6678 + (call & 0xC0000000U) == 0x40000000U &&
6679 + nop == 0x01000000U)
6680 + {
6681 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6682 +
6683 + if (test_thread_flag(TIF_32BIT))
6684 + dl_resolve &= 0xFFFFFFFFUL;
6685 +
6686 + regs->u_regs[UREG_RETPC] = regs->tpc;
6687 + regs->tpc = dl_resolve;
6688 + regs->tnpc = dl_resolve+4;
6689 + return 3;
6690 + }
6691 + } while (0);
6692 +#endif
6693 +
6694 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6695 + unsigned int sethi, ba, nop;
6696 +
6697 + err = get_user(sethi, (unsigned int *)regs->tpc);
6698 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6699 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6700 +
6701 + if (err)
6702 + break;
6703 +
6704 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6705 + (ba & 0xFFF00000U) == 0x30600000U &&
6706 + nop == 0x01000000U)
6707 + {
6708 + unsigned long addr;
6709 +
6710 + addr = (sethi & 0x003FFFFFU) << 10;
6711 + regs->u_regs[UREG_G1] = addr;
6712 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6713 +
6714 + if (test_thread_flag(TIF_32BIT))
6715 + addr &= 0xFFFFFFFFUL;
6716 +
6717 + regs->tpc = addr;
6718 + regs->tnpc = addr+4;
6719 + return 2;
6720 + }
6721 + } while (0);
6722 +
6723 +#endif
6724 +
6725 + return 1;
6726 +}
6727 +
6728 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6729 +{
6730 + unsigned long i;
6731 +
6732 + printk(KERN_ERR "PAX: bytes at PC: ");
6733 + for (i = 0; i < 8; i++) {
6734 + unsigned int c;
6735 + if (get_user(c, (unsigned int *)pc+i))
6736 + printk(KERN_CONT "???????? ");
6737 + else
6738 + printk(KERN_CONT "%08x ", c);
6739 + }
6740 + printk("\n");
6741 +}
6742 +#endif
6743 +
6744 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6745 {
6746 struct mm_struct *mm = current->mm;
6747 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6748 if (!vma)
6749 goto bad_area;
6750
6751 +#ifdef CONFIG_PAX_PAGEEXEC
6752 + /* PaX: detect ITLB misses on non-exec pages */
6753 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6754 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6755 + {
6756 + if (address != regs->tpc)
6757 + goto good_area;
6758 +
6759 + up_read(&mm->mmap_sem);
6760 + switch (pax_handle_fetch_fault(regs)) {
6761 +
6762 +#ifdef CONFIG_PAX_EMUPLT
6763 + case 2:
6764 + case 3:
6765 + return;
6766 +#endif
6767 +
6768 + }
6769 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6770 + do_group_exit(SIGKILL);
6771 + }
6772 +#endif
6773 +
6774 /* Pure DTLB misses do not tell us whether the fault causing
6775 * load/store/atomic was a write or not, it only says that there
6776 * was no match. So in such a case we (carefully) read the
6777 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6778 index 07e1453..0a7d9e9 100644
6779 --- a/arch/sparc/mm/hugetlbpage.c
6780 +++ b/arch/sparc/mm/hugetlbpage.c
6781 @@ -67,7 +67,7 @@ full_search:
6782 }
6783 return -ENOMEM;
6784 }
6785 - if (likely(!vma || addr + len <= vma->vm_start)) {
6786 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6787 /*
6788 * Remember the place where we stopped the search:
6789 */
6790 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6791 /* make sure it can fit in the remaining address space */
6792 if (likely(addr > len)) {
6793 vma = find_vma(mm, addr-len);
6794 - if (!vma || addr <= vma->vm_start) {
6795 + if (check_heap_stack_gap(vma, addr - len, len)) {
6796 /* remember the address as a hint for next time */
6797 return (mm->free_area_cache = addr-len);
6798 }
6799 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6800 if (unlikely(mm->mmap_base < len))
6801 goto bottomup;
6802
6803 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6804 + addr = mm->mmap_base - len;
6805
6806 do {
6807 + addr &= HPAGE_MASK;
6808 /*
6809 * Lookup failure means no vma is above this address,
6810 * else if new region fits below vma->vm_start,
6811 * return with success:
6812 */
6813 vma = find_vma(mm, addr);
6814 - if (likely(!vma || addr+len <= vma->vm_start)) {
6815 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6816 /* remember the address as a hint for next time */
6817 return (mm->free_area_cache = addr);
6818 }
6819 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6820 mm->cached_hole_size = vma->vm_start - addr;
6821
6822 /* try just below the current vma->vm_start */
6823 - addr = (vma->vm_start-len) & HPAGE_MASK;
6824 - } while (likely(len < vma->vm_start));
6825 + addr = skip_heap_stack_gap(vma, len);
6826 + } while (!IS_ERR_VALUE(addr));
6827
6828 bottomup:
6829 /*
6830 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6831 if (addr) {
6832 addr = ALIGN(addr, HPAGE_SIZE);
6833 vma = find_vma(mm, addr);
6834 - if (task_size - len >= addr &&
6835 - (!vma || addr + len <= vma->vm_start))
6836 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6837 return addr;
6838 }
6839 if (mm->get_unmapped_area == arch_get_unmapped_area)
6840 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6841 index 7b00de6..78239f4 100644
6842 --- a/arch/sparc/mm/init_32.c
6843 +++ b/arch/sparc/mm/init_32.c
6844 @@ -316,6 +316,9 @@ extern void device_scan(void);
6845 pgprot_t PAGE_SHARED __read_mostly;
6846 EXPORT_SYMBOL(PAGE_SHARED);
6847
6848 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6849 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6850 +
6851 void __init paging_init(void)
6852 {
6853 switch(sparc_cpu_model) {
6854 @@ -344,17 +347,17 @@ void __init paging_init(void)
6855
6856 /* Initialize the protection map with non-constant, MMU dependent values. */
6857 protection_map[0] = PAGE_NONE;
6858 - protection_map[1] = PAGE_READONLY;
6859 - protection_map[2] = PAGE_COPY;
6860 - protection_map[3] = PAGE_COPY;
6861 + protection_map[1] = PAGE_READONLY_NOEXEC;
6862 + protection_map[2] = PAGE_COPY_NOEXEC;
6863 + protection_map[3] = PAGE_COPY_NOEXEC;
6864 protection_map[4] = PAGE_READONLY;
6865 protection_map[5] = PAGE_READONLY;
6866 protection_map[6] = PAGE_COPY;
6867 protection_map[7] = PAGE_COPY;
6868 protection_map[8] = PAGE_NONE;
6869 - protection_map[9] = PAGE_READONLY;
6870 - protection_map[10] = PAGE_SHARED;
6871 - protection_map[11] = PAGE_SHARED;
6872 + protection_map[9] = PAGE_READONLY_NOEXEC;
6873 + protection_map[10] = PAGE_SHARED_NOEXEC;
6874 + protection_map[11] = PAGE_SHARED_NOEXEC;
6875 protection_map[12] = PAGE_READONLY;
6876 protection_map[13] = PAGE_READONLY;
6877 protection_map[14] = PAGE_SHARED;
6878 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6879 index cbef74e..c38fead 100644
6880 --- a/arch/sparc/mm/srmmu.c
6881 +++ b/arch/sparc/mm/srmmu.c
6882 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6883 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6884 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6885 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6886 +
6887 +#ifdef CONFIG_PAX_PAGEEXEC
6888 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6889 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6890 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6891 +#endif
6892 +
6893 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6894 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6895
6896 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
6897 index 27fe667..36d474c 100644
6898 --- a/arch/tile/include/asm/atomic_64.h
6899 +++ b/arch/tile/include/asm/atomic_64.h
6900 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6901
6902 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6903
6904 +#define atomic64_read_unchecked(v) atomic64_read(v)
6905 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6906 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6907 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6908 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6909 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6910 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6911 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6912 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6913 +
6914 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
6915 #define smp_mb__before_atomic_dec() smp_mb()
6916 #define smp_mb__after_atomic_dec() smp_mb()
6917 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
6918 index 392e533..536b092 100644
6919 --- a/arch/tile/include/asm/cache.h
6920 +++ b/arch/tile/include/asm/cache.h
6921 @@ -15,11 +15,12 @@
6922 #ifndef _ASM_TILE_CACHE_H
6923 #define _ASM_TILE_CACHE_H
6924
6925 +#include <linux/const.h>
6926 #include <arch/chip.h>
6927
6928 /* bytes per L1 data cache line */
6929 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
6930 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6931 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6932
6933 /* bytes per L2 cache line */
6934 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
6935 diff --git a/arch/um/Makefile b/arch/um/Makefile
6936 index 7730af6..cce5b19 100644
6937 --- a/arch/um/Makefile
6938 +++ b/arch/um/Makefile
6939 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6940 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6941 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
6942
6943 +ifdef CONSTIFY_PLUGIN
6944 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6945 +endif
6946 +
6947 #This will adjust *FLAGS accordingly to the platform.
6948 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
6949
6950 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
6951 index 19e1bdd..3665b77 100644
6952 --- a/arch/um/include/asm/cache.h
6953 +++ b/arch/um/include/asm/cache.h
6954 @@ -1,6 +1,7 @@
6955 #ifndef __UM_CACHE_H
6956 #define __UM_CACHE_H
6957
6958 +#include <linux/const.h>
6959
6960 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
6961 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6962 @@ -12,6 +13,6 @@
6963 # define L1_CACHE_SHIFT 5
6964 #endif
6965
6966 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6967 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6968
6969 #endif
6970 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6971 index 6c03acd..a5e0215 100644
6972 --- a/arch/um/include/asm/kmap_types.h
6973 +++ b/arch/um/include/asm/kmap_types.h
6974 @@ -23,6 +23,7 @@ enum km_type {
6975 KM_IRQ1,
6976 KM_SOFTIRQ0,
6977 KM_SOFTIRQ1,
6978 + KM_CLEARPAGE,
6979 KM_TYPE_NR
6980 };
6981
6982 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6983 index 7cfc3ce..cbd1a58 100644
6984 --- a/arch/um/include/asm/page.h
6985 +++ b/arch/um/include/asm/page.h
6986 @@ -14,6 +14,9 @@
6987 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6988 #define PAGE_MASK (~(PAGE_SIZE-1))
6989
6990 +#define ktla_ktva(addr) (addr)
6991 +#define ktva_ktla(addr) (addr)
6992 +
6993 #ifndef __ASSEMBLY__
6994
6995 struct page;
6996 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6997 index c533835..84db18e 100644
6998 --- a/arch/um/kernel/process.c
6999 +++ b/arch/um/kernel/process.c
7000 @@ -406,22 +406,6 @@ int singlestepping(void * t)
7001 return 2;
7002 }
7003
7004 -/*
7005 - * Only x86 and x86_64 have an arch_align_stack().
7006 - * All other arches have "#define arch_align_stack(x) (x)"
7007 - * in their asm/system.h
7008 - * As this is included in UML from asm-um/system-generic.h,
7009 - * we can use it to behave as the subarch does.
7010 - */
7011 -#ifndef arch_align_stack
7012 -unsigned long arch_align_stack(unsigned long sp)
7013 -{
7014 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7015 - sp -= get_random_int() % 8192;
7016 - return sp & ~0xf;
7017 -}
7018 -#endif
7019 -
7020 unsigned long get_wchan(struct task_struct *p)
7021 {
7022 unsigned long stack_page, sp, ip;
7023 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7024 index ad8f795..2c7eec6 100644
7025 --- a/arch/unicore32/include/asm/cache.h
7026 +++ b/arch/unicore32/include/asm/cache.h
7027 @@ -12,8 +12,10 @@
7028 #ifndef __UNICORE_CACHE_H__
7029 #define __UNICORE_CACHE_H__
7030
7031 -#define L1_CACHE_SHIFT (5)
7032 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7033 +#include <linux/const.h>
7034 +
7035 +#define L1_CACHE_SHIFT 5
7036 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7037
7038 /*
7039 * Memory returned by kmalloc() may be used for DMA, so we must make
7040 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7041 index efb4294..61bc18c 100644
7042 --- a/arch/x86/Kconfig
7043 +++ b/arch/x86/Kconfig
7044 @@ -235,7 +235,7 @@ config X86_HT
7045
7046 config X86_32_LAZY_GS
7047 def_bool y
7048 - depends on X86_32 && !CC_STACKPROTECTOR
7049 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7050
7051 config ARCH_HWEIGHT_CFLAGS
7052 string
7053 @@ -1022,7 +1022,7 @@ choice
7054
7055 config NOHIGHMEM
7056 bool "off"
7057 - depends on !X86_NUMAQ
7058 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7059 ---help---
7060 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7061 However, the address space of 32-bit x86 processors is only 4
7062 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
7063
7064 config HIGHMEM4G
7065 bool "4GB"
7066 - depends on !X86_NUMAQ
7067 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7068 ---help---
7069 Select this if you have a 32-bit processor and between 1 and 4
7070 gigabytes of physical RAM.
7071 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
7072 hex
7073 default 0xB0000000 if VMSPLIT_3G_OPT
7074 default 0x80000000 if VMSPLIT_2G
7075 - default 0x78000000 if VMSPLIT_2G_OPT
7076 + default 0x70000000 if VMSPLIT_2G_OPT
7077 default 0x40000000 if VMSPLIT_1G
7078 default 0xC0000000
7079 depends on X86_32
7080 @@ -1496,6 +1496,7 @@ config SECCOMP
7081
7082 config CC_STACKPROTECTOR
7083 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7084 + depends on X86_64 || !PAX_MEMORY_UDEREF
7085 ---help---
7086 This option turns on the -fstack-protector GCC feature. This
7087 feature puts, at the beginning of functions, a canary value on
7088 @@ -1553,6 +1554,7 @@ config KEXEC_JUMP
7089 config PHYSICAL_START
7090 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7091 default "0x1000000"
7092 + range 0x400000 0x40000000
7093 ---help---
7094 This gives the physical address where the kernel is loaded.
7095
7096 @@ -1616,6 +1618,7 @@ config X86_NEED_RELOCS
7097 config PHYSICAL_ALIGN
7098 hex "Alignment value to which kernel should be aligned" if X86_32
7099 default "0x1000000"
7100 + range 0x400000 0x1000000 if PAX_KERNEXEC
7101 range 0x2000 0x1000000
7102 ---help---
7103 This value puts the alignment restrictions on physical address
7104 @@ -1647,9 +1650,10 @@ config HOTPLUG_CPU
7105 Say N if you want to disable CPU hotplug.
7106
7107 config COMPAT_VDSO
7108 - def_bool y
7109 + def_bool n
7110 prompt "Compat VDSO support"
7111 depends on X86_32 || IA32_EMULATION
7112 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7113 ---help---
7114 Map the 32-bit VDSO to the predictable old-style address too.
7115
7116 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7117 index e3ca7e0..b30b28a 100644
7118 --- a/arch/x86/Kconfig.cpu
7119 +++ b/arch/x86/Kconfig.cpu
7120 @@ -341,7 +341,7 @@ config X86_PPRO_FENCE
7121
7122 config X86_F00F_BUG
7123 def_bool y
7124 - depends on M586MMX || M586TSC || M586 || M486 || M386
7125 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7126
7127 config X86_INVD_BUG
7128 def_bool y
7129 @@ -365,7 +365,7 @@ config X86_POPAD_OK
7130
7131 config X86_ALIGNMENT_16
7132 def_bool y
7133 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7134 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7135
7136 config X86_INTEL_USERCOPY
7137 def_bool y
7138 @@ -411,7 +411,7 @@ config X86_CMPXCHG64
7139 # generates cmov.
7140 config X86_CMOV
7141 def_bool y
7142 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7143 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7144
7145 config X86_MINIMUM_CPU_FAMILY
7146 int
7147 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7148 index bf56e17..05f9891 100644
7149 --- a/arch/x86/Kconfig.debug
7150 +++ b/arch/x86/Kconfig.debug
7151 @@ -81,7 +81,7 @@ config X86_PTDUMP
7152 config DEBUG_RODATA
7153 bool "Write protect kernel read-only data structures"
7154 default y
7155 - depends on DEBUG_KERNEL
7156 + depends on DEBUG_KERNEL && BROKEN
7157 ---help---
7158 Mark the kernel read-only data as write-protected in the pagetables,
7159 in order to catch accidental (and incorrect) writes to such const
7160 @@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
7161
7162 config DEBUG_SET_MODULE_RONX
7163 bool "Set loadable kernel module data as NX and text as RO"
7164 - depends on MODULES
7165 + depends on MODULES && BROKEN
7166 ---help---
7167 This option helps catch unintended modifications to loadable
7168 kernel module's text and read-only data. It also prevents execution
7169 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7170 index b02e509..2631e48 100644
7171 --- a/arch/x86/Makefile
7172 +++ b/arch/x86/Makefile
7173 @@ -46,6 +46,7 @@ else
7174 UTS_MACHINE := x86_64
7175 CHECKFLAGS += -D__x86_64__ -m64
7176
7177 + biarch := $(call cc-option,-m64)
7178 KBUILD_AFLAGS += -m64
7179 KBUILD_CFLAGS += -m64
7180
7181 @@ -195,3 +196,12 @@ define archhelp
7182 echo ' FDARGS="..." arguments for the booted kernel'
7183 echo ' FDINITRD=file initrd for the booted kernel'
7184 endef
7185 +
7186 +define OLD_LD
7187 +
7188 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7189 +*** Please upgrade your binutils to 2.18 or newer
7190 +endef
7191 +
7192 +archprepare:
7193 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7194 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7195 index 95365a8..52f857b 100644
7196 --- a/arch/x86/boot/Makefile
7197 +++ b/arch/x86/boot/Makefile
7198 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7199 $(call cc-option, -fno-stack-protector) \
7200 $(call cc-option, -mpreferred-stack-boundary=2)
7201 KBUILD_CFLAGS += $(call cc-option, -m32)
7202 +ifdef CONSTIFY_PLUGIN
7203 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7204 +endif
7205 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7206 GCOV_PROFILE := n
7207
7208 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7209 index 878e4b9..20537ab 100644
7210 --- a/arch/x86/boot/bitops.h
7211 +++ b/arch/x86/boot/bitops.h
7212 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7213 u8 v;
7214 const u32 *p = (const u32 *)addr;
7215
7216 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7217 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7218 return v;
7219 }
7220
7221 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7222
7223 static inline void set_bit(int nr, void *addr)
7224 {
7225 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7226 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7227 }
7228
7229 #endif /* BOOT_BITOPS_H */
7230 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7231 index c7093bd..d4247ffe0 100644
7232 --- a/arch/x86/boot/boot.h
7233 +++ b/arch/x86/boot/boot.h
7234 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7235 static inline u16 ds(void)
7236 {
7237 u16 seg;
7238 - asm("movw %%ds,%0" : "=rm" (seg));
7239 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7240 return seg;
7241 }
7242
7243 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7244 static inline int memcmp(const void *s1, const void *s2, size_t len)
7245 {
7246 u8 diff;
7247 - asm("repe; cmpsb; setnz %0"
7248 + asm volatile("repe; cmpsb; setnz %0"
7249 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7250 return diff;
7251 }
7252 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7253 index 09664ef..edc5d03 100644
7254 --- a/arch/x86/boot/compressed/Makefile
7255 +++ b/arch/x86/boot/compressed/Makefile
7256 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7257 KBUILD_CFLAGS += $(cflags-y)
7258 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7259 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7260 +ifdef CONSTIFY_PLUGIN
7261 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7262 +endif
7263
7264 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7265 GCOV_PROFILE := n
7266 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7267 index 67a655a..b924059 100644
7268 --- a/arch/x86/boot/compressed/head_32.S
7269 +++ b/arch/x86/boot/compressed/head_32.S
7270 @@ -76,7 +76,7 @@ ENTRY(startup_32)
7271 notl %eax
7272 andl %eax, %ebx
7273 #else
7274 - movl $LOAD_PHYSICAL_ADDR, %ebx
7275 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7276 #endif
7277
7278 /* Target address to relocate to for decompression */
7279 @@ -162,7 +162,7 @@ relocated:
7280 * and where it was actually loaded.
7281 */
7282 movl %ebp, %ebx
7283 - subl $LOAD_PHYSICAL_ADDR, %ebx
7284 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7285 jz 2f /* Nothing to be done if loaded at compiled addr. */
7286 /*
7287 * Process relocations.
7288 @@ -170,8 +170,7 @@ relocated:
7289
7290 1: subl $4, %edi
7291 movl (%edi), %ecx
7292 - testl %ecx, %ecx
7293 - jz 2f
7294 + jecxz 2f
7295 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7296 jmp 1b
7297 2:
7298 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7299 index 35af09d..99c9676 100644
7300 --- a/arch/x86/boot/compressed/head_64.S
7301 +++ b/arch/x86/boot/compressed/head_64.S
7302 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7303 notl %eax
7304 andl %eax, %ebx
7305 #else
7306 - movl $LOAD_PHYSICAL_ADDR, %ebx
7307 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7308 #endif
7309
7310 /* Target address to relocate to for decompression */
7311 @@ -233,7 +233,7 @@ ENTRY(startup_64)
7312 notq %rax
7313 andq %rax, %rbp
7314 #else
7315 - movq $LOAD_PHYSICAL_ADDR, %rbp
7316 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7317 #endif
7318
7319 /* Target address to relocate to for decompression */
7320 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7321 index 3a19d04..7c1d55a 100644
7322 --- a/arch/x86/boot/compressed/misc.c
7323 +++ b/arch/x86/boot/compressed/misc.c
7324 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7325 case PT_LOAD:
7326 #ifdef CONFIG_RELOCATABLE
7327 dest = output;
7328 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7329 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7330 #else
7331 dest = (void *)(phdr->p_paddr);
7332 #endif
7333 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7334 error("Destination address too large");
7335 #endif
7336 #ifndef CONFIG_RELOCATABLE
7337 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7338 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7339 error("Wrong destination address");
7340 #endif
7341
7342 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7343 index 89bbf4e..869908e 100644
7344 --- a/arch/x86/boot/compressed/relocs.c
7345 +++ b/arch/x86/boot/compressed/relocs.c
7346 @@ -13,8 +13,11 @@
7347
7348 static void die(char *fmt, ...);
7349
7350 +#include "../../../../include/generated/autoconf.h"
7351 +
7352 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7353 static Elf32_Ehdr ehdr;
7354 +static Elf32_Phdr *phdr;
7355 static unsigned long reloc_count, reloc_idx;
7356 static unsigned long *relocs;
7357
7358 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7359 }
7360 }
7361
7362 +static void read_phdrs(FILE *fp)
7363 +{
7364 + unsigned int i;
7365 +
7366 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7367 + if (!phdr) {
7368 + die("Unable to allocate %d program headers\n",
7369 + ehdr.e_phnum);
7370 + }
7371 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7372 + die("Seek to %d failed: %s\n",
7373 + ehdr.e_phoff, strerror(errno));
7374 + }
7375 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7376 + die("Cannot read ELF program headers: %s\n",
7377 + strerror(errno));
7378 + }
7379 + for(i = 0; i < ehdr.e_phnum; i++) {
7380 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7381 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7382 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7383 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7384 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7385 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7386 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7387 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7388 + }
7389 +
7390 +}
7391 +
7392 static void read_shdrs(FILE *fp)
7393 {
7394 - int i;
7395 + unsigned int i;
7396 Elf32_Shdr shdr;
7397
7398 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7399 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7400
7401 static void read_strtabs(FILE *fp)
7402 {
7403 - int i;
7404 + unsigned int i;
7405 for (i = 0; i < ehdr.e_shnum; i++) {
7406 struct section *sec = &secs[i];
7407 if (sec->shdr.sh_type != SHT_STRTAB) {
7408 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7409
7410 static void read_symtabs(FILE *fp)
7411 {
7412 - int i,j;
7413 + unsigned int i,j;
7414 for (i = 0; i < ehdr.e_shnum; i++) {
7415 struct section *sec = &secs[i];
7416 if (sec->shdr.sh_type != SHT_SYMTAB) {
7417 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7418
7419 static void read_relocs(FILE *fp)
7420 {
7421 - int i,j;
7422 + unsigned int i,j;
7423 + uint32_t base;
7424 +
7425 for (i = 0; i < ehdr.e_shnum; i++) {
7426 struct section *sec = &secs[i];
7427 if (sec->shdr.sh_type != SHT_REL) {
7428 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7429 die("Cannot read symbol table: %s\n",
7430 strerror(errno));
7431 }
7432 + base = 0;
7433 + for (j = 0; j < ehdr.e_phnum; j++) {
7434 + if (phdr[j].p_type != PT_LOAD )
7435 + continue;
7436 + 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)
7437 + continue;
7438 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7439 + break;
7440 + }
7441 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7442 Elf32_Rel *rel = &sec->reltab[j];
7443 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7444 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7445 rel->r_info = elf32_to_cpu(rel->r_info);
7446 }
7447 }
7448 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7449
7450 static void print_absolute_symbols(void)
7451 {
7452 - int i;
7453 + unsigned int i;
7454 printf("Absolute symbols\n");
7455 printf(" Num: Value Size Type Bind Visibility Name\n");
7456 for (i = 0; i < ehdr.e_shnum; i++) {
7457 struct section *sec = &secs[i];
7458 char *sym_strtab;
7459 Elf32_Sym *sh_symtab;
7460 - int j;
7461 + unsigned int j;
7462
7463 if (sec->shdr.sh_type != SHT_SYMTAB) {
7464 continue;
7465 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7466
7467 static void print_absolute_relocs(void)
7468 {
7469 - int i, printed = 0;
7470 + unsigned int i, printed = 0;
7471
7472 for (i = 0; i < ehdr.e_shnum; i++) {
7473 struct section *sec = &secs[i];
7474 struct section *sec_applies, *sec_symtab;
7475 char *sym_strtab;
7476 Elf32_Sym *sh_symtab;
7477 - int j;
7478 + unsigned int j;
7479 if (sec->shdr.sh_type != SHT_REL) {
7480 continue;
7481 }
7482 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7483
7484 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7485 {
7486 - int i;
7487 + unsigned int i;
7488 /* Walk through the relocations */
7489 for (i = 0; i < ehdr.e_shnum; i++) {
7490 char *sym_strtab;
7491 Elf32_Sym *sh_symtab;
7492 struct section *sec_applies, *sec_symtab;
7493 - int j;
7494 + unsigned int j;
7495 struct section *sec = &secs[i];
7496
7497 if (sec->shdr.sh_type != SHT_REL) {
7498 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7499 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7500 continue;
7501 }
7502 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7503 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7504 + continue;
7505 +
7506 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7507 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7508 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7509 + continue;
7510 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7511 + continue;
7512 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7513 + continue;
7514 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7515 + continue;
7516 +#endif
7517 +
7518 switch (r_type) {
7519 case R_386_NONE:
7520 case R_386_PC32:
7521 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7522
7523 static void emit_relocs(int as_text)
7524 {
7525 - int i;
7526 + unsigned int i;
7527 /* Count how many relocations I have and allocate space for them. */
7528 reloc_count = 0;
7529 walk_relocs(count_reloc);
7530 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7531 fname, strerror(errno));
7532 }
7533 read_ehdr(fp);
7534 + read_phdrs(fp);
7535 read_shdrs(fp);
7536 read_strtabs(fp);
7537 read_symtabs(fp);
7538 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7539 index 4d3ff03..e4972ff 100644
7540 --- a/arch/x86/boot/cpucheck.c
7541 +++ b/arch/x86/boot/cpucheck.c
7542 @@ -74,7 +74,7 @@ static int has_fpu(void)
7543 u16 fcw = -1, fsw = -1;
7544 u32 cr0;
7545
7546 - asm("movl %%cr0,%0" : "=r" (cr0));
7547 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7548 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7549 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7550 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7551 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7552 {
7553 u32 f0, f1;
7554
7555 - asm("pushfl ; "
7556 + asm volatile("pushfl ; "
7557 "pushfl ; "
7558 "popl %0 ; "
7559 "movl %0,%1 ; "
7560 @@ -115,7 +115,7 @@ static void get_flags(void)
7561 set_bit(X86_FEATURE_FPU, cpu.flags);
7562
7563 if (has_eflag(X86_EFLAGS_ID)) {
7564 - asm("cpuid"
7565 + asm volatile("cpuid"
7566 : "=a" (max_intel_level),
7567 "=b" (cpu_vendor[0]),
7568 "=d" (cpu_vendor[1]),
7569 @@ -124,7 +124,7 @@ static void get_flags(void)
7570
7571 if (max_intel_level >= 0x00000001 &&
7572 max_intel_level <= 0x0000ffff) {
7573 - asm("cpuid"
7574 + asm volatile("cpuid"
7575 : "=a" (tfms),
7576 "=c" (cpu.flags[4]),
7577 "=d" (cpu.flags[0])
7578 @@ -136,7 +136,7 @@ static void get_flags(void)
7579 cpu.model += ((tfms >> 16) & 0xf) << 4;
7580 }
7581
7582 - asm("cpuid"
7583 + asm volatile("cpuid"
7584 : "=a" (max_amd_level)
7585 : "a" (0x80000000)
7586 : "ebx", "ecx", "edx");
7587 @@ -144,7 +144,7 @@ static void get_flags(void)
7588 if (max_amd_level >= 0x80000001 &&
7589 max_amd_level <= 0x8000ffff) {
7590 u32 eax = 0x80000001;
7591 - asm("cpuid"
7592 + asm volatile("cpuid"
7593 : "+a" (eax),
7594 "=c" (cpu.flags[6]),
7595 "=d" (cpu.flags[1])
7596 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7597 u32 ecx = MSR_K7_HWCR;
7598 u32 eax, edx;
7599
7600 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7601 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7602 eax &= ~(1 << 15);
7603 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7604 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7605
7606 get_flags(); /* Make sure it really did something */
7607 err = check_flags();
7608 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7609 u32 ecx = MSR_VIA_FCR;
7610 u32 eax, edx;
7611
7612 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7613 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7614 eax |= (1<<1)|(1<<7);
7615 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7616 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7617
7618 set_bit(X86_FEATURE_CX8, cpu.flags);
7619 err = check_flags();
7620 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7621 u32 eax, edx;
7622 u32 level = 1;
7623
7624 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7625 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7626 - asm("cpuid"
7627 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7628 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7629 + asm volatile("cpuid"
7630 : "+a" (level), "=d" (cpu.flags[0])
7631 : : "ecx", "ebx");
7632 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7633 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7634
7635 err = check_flags();
7636 }
7637 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7638 index bdb4d45..0476680 100644
7639 --- a/arch/x86/boot/header.S
7640 +++ b/arch/x86/boot/header.S
7641 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7642 # single linked list of
7643 # struct setup_data
7644
7645 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7646 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7647
7648 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7649 #define VO_INIT_SIZE (VO__end - VO__text)
7650 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7651 index db75d07..8e6d0af 100644
7652 --- a/arch/x86/boot/memory.c
7653 +++ b/arch/x86/boot/memory.c
7654 @@ -19,7 +19,7 @@
7655
7656 static int detect_memory_e820(void)
7657 {
7658 - int count = 0;
7659 + unsigned int count = 0;
7660 struct biosregs ireg, oreg;
7661 struct e820entry *desc = boot_params.e820_map;
7662 static struct e820entry buf; /* static so it is zeroed */
7663 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7664 index 11e8c6e..fdbb1ed 100644
7665 --- a/arch/x86/boot/video-vesa.c
7666 +++ b/arch/x86/boot/video-vesa.c
7667 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7668
7669 boot_params.screen_info.vesapm_seg = oreg.es;
7670 boot_params.screen_info.vesapm_off = oreg.di;
7671 + boot_params.screen_info.vesapm_size = oreg.cx;
7672 }
7673
7674 /*
7675 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7676 index 43eda28..5ab5fdb 100644
7677 --- a/arch/x86/boot/video.c
7678 +++ b/arch/x86/boot/video.c
7679 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7680 static unsigned int get_entry(void)
7681 {
7682 char entry_buf[4];
7683 - int i, len = 0;
7684 + unsigned int i, len = 0;
7685 int key;
7686 unsigned int v;
7687
7688 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7689 index 5b577d5..3c1fed4 100644
7690 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7691 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7692 @@ -8,6 +8,8 @@
7693 * including this sentence is retained in full.
7694 */
7695
7696 +#include <asm/alternative-asm.h>
7697 +
7698 .extern crypto_ft_tab
7699 .extern crypto_it_tab
7700 .extern crypto_fl_tab
7701 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7702 je B192; \
7703 leaq 32(r9),r9;
7704
7705 +#define ret pax_force_retaddr 0, 1; ret
7706 +
7707 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7708 movq r1,r2; \
7709 movq r3,r4; \
7710 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7711 index be6d9e3..21fbbca 100644
7712 --- a/arch/x86/crypto/aesni-intel_asm.S
7713 +++ b/arch/x86/crypto/aesni-intel_asm.S
7714 @@ -31,6 +31,7 @@
7715
7716 #include <linux/linkage.h>
7717 #include <asm/inst.h>
7718 +#include <asm/alternative-asm.h>
7719
7720 #ifdef __x86_64__
7721 .data
7722 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7723 pop %r14
7724 pop %r13
7725 pop %r12
7726 + pax_force_retaddr 0, 1
7727 ret
7728 +ENDPROC(aesni_gcm_dec)
7729
7730
7731 /*****************************************************************************
7732 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7733 pop %r14
7734 pop %r13
7735 pop %r12
7736 + pax_force_retaddr 0, 1
7737 ret
7738 +ENDPROC(aesni_gcm_enc)
7739
7740 #endif
7741
7742 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
7743 pxor %xmm1, %xmm0
7744 movaps %xmm0, (TKEYP)
7745 add $0x10, TKEYP
7746 + pax_force_retaddr_bts
7747 ret
7748
7749 .align 4
7750 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
7751 shufps $0b01001110, %xmm2, %xmm1
7752 movaps %xmm1, 0x10(TKEYP)
7753 add $0x20, TKEYP
7754 + pax_force_retaddr_bts
7755 ret
7756
7757 .align 4
7758 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
7759
7760 movaps %xmm0, (TKEYP)
7761 add $0x10, TKEYP
7762 + pax_force_retaddr_bts
7763 ret
7764
7765 .align 4
7766 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
7767 pxor %xmm1, %xmm2
7768 movaps %xmm2, (TKEYP)
7769 add $0x10, TKEYP
7770 + pax_force_retaddr_bts
7771 ret
7772
7773 /*
7774 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7775 #ifndef __x86_64__
7776 popl KEYP
7777 #endif
7778 + pax_force_retaddr 0, 1
7779 ret
7780 +ENDPROC(aesni_set_key)
7781
7782 /*
7783 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7784 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7785 popl KLEN
7786 popl KEYP
7787 #endif
7788 + pax_force_retaddr 0, 1
7789 ret
7790 +ENDPROC(aesni_enc)
7791
7792 /*
7793 * _aesni_enc1: internal ABI
7794 @@ -1959,6 +1972,7 @@ _aesni_enc1:
7795 AESENC KEY STATE
7796 movaps 0x70(TKEYP), KEY
7797 AESENCLAST KEY STATE
7798 + pax_force_retaddr_bts
7799 ret
7800
7801 /*
7802 @@ -2067,6 +2081,7 @@ _aesni_enc4:
7803 AESENCLAST KEY STATE2
7804 AESENCLAST KEY STATE3
7805 AESENCLAST KEY STATE4
7806 + pax_force_retaddr_bts
7807 ret
7808
7809 /*
7810 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7811 popl KLEN
7812 popl KEYP
7813 #endif
7814 + pax_force_retaddr 0, 1
7815 ret
7816 +ENDPROC(aesni_dec)
7817
7818 /*
7819 * _aesni_dec1: internal ABI
7820 @@ -2146,6 +2163,7 @@ _aesni_dec1:
7821 AESDEC KEY STATE
7822 movaps 0x70(TKEYP), KEY
7823 AESDECLAST KEY STATE
7824 + pax_force_retaddr_bts
7825 ret
7826
7827 /*
7828 @@ -2254,6 +2272,7 @@ _aesni_dec4:
7829 AESDECLAST KEY STATE2
7830 AESDECLAST KEY STATE3
7831 AESDECLAST KEY STATE4
7832 + pax_force_retaddr_bts
7833 ret
7834
7835 /*
7836 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
7837 popl KEYP
7838 popl LEN
7839 #endif
7840 + pax_force_retaddr 0, 1
7841 ret
7842 +ENDPROC(aesni_ecb_enc)
7843
7844 /*
7845 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7846 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
7847 popl KEYP
7848 popl LEN
7849 #endif
7850 + pax_force_retaddr 0, 1
7851 ret
7852 +ENDPROC(aesni_ecb_dec)
7853
7854 /*
7855 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7856 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
7857 popl LEN
7858 popl IVP
7859 #endif
7860 + pax_force_retaddr 0, 1
7861 ret
7862 +ENDPROC(aesni_cbc_enc)
7863
7864 /*
7865 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7866 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
7867 popl LEN
7868 popl IVP
7869 #endif
7870 + pax_force_retaddr 0, 1
7871 ret
7872 +ENDPROC(aesni_cbc_dec)
7873
7874 #ifdef __x86_64__
7875 .align 16
7876 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
7877 mov $1, TCTR_LOW
7878 MOVQ_R64_XMM TCTR_LOW INC
7879 MOVQ_R64_XMM CTR TCTR_LOW
7880 + pax_force_retaddr_bts
7881 ret
7882
7883 /*
7884 @@ -2552,6 +2580,7 @@ _aesni_inc:
7885 .Linc_low:
7886 movaps CTR, IV
7887 PSHUFB_XMM BSWAP_MASK IV
7888 + pax_force_retaddr_bts
7889 ret
7890
7891 /*
7892 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
7893 .Lctr_enc_ret:
7894 movups IV, (IVP)
7895 .Lctr_enc_just_ret:
7896 + pax_force_retaddr 0, 1
7897 ret
7898 +ENDPROC(aesni_ctr_enc)
7899 #endif
7900 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7901 index 391d245..67f35c2 100644
7902 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
7903 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7904 @@ -20,6 +20,8 @@
7905 *
7906 */
7907
7908 +#include <asm/alternative-asm.h>
7909 +
7910 .file "blowfish-x86_64-asm.S"
7911 .text
7912
7913 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
7914 jnz __enc_xor;
7915
7916 write_block();
7917 + pax_force_retaddr 0, 1
7918 ret;
7919 __enc_xor:
7920 xor_block();
7921 + pax_force_retaddr 0, 1
7922 ret;
7923
7924 .align 8
7925 @@ -188,6 +192,7 @@ blowfish_dec_blk:
7926
7927 movq %r11, %rbp;
7928
7929 + pax_force_retaddr 0, 1
7930 ret;
7931
7932 /**********************************************************************
7933 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
7934
7935 popq %rbx;
7936 popq %rbp;
7937 + pax_force_retaddr 0, 1
7938 ret;
7939
7940 __enc_xor4:
7941 @@ -349,6 +355,7 @@ __enc_xor4:
7942
7943 popq %rbx;
7944 popq %rbp;
7945 + pax_force_retaddr 0, 1
7946 ret;
7947
7948 .align 8
7949 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
7950 popq %rbx;
7951 popq %rbp;
7952
7953 + pax_force_retaddr 0, 1
7954 ret;
7955
7956 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7957 index 6214a9b..1f4fc9a 100644
7958 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7959 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7960 @@ -1,3 +1,5 @@
7961 +#include <asm/alternative-asm.h>
7962 +
7963 # enter ECRYPT_encrypt_bytes
7964 .text
7965 .p2align 5
7966 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7967 add %r11,%rsp
7968 mov %rdi,%rax
7969 mov %rsi,%rdx
7970 + pax_force_retaddr 0, 1
7971 ret
7972 # bytesatleast65:
7973 ._bytesatleast65:
7974 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
7975 add %r11,%rsp
7976 mov %rdi,%rax
7977 mov %rsi,%rdx
7978 + pax_force_retaddr
7979 ret
7980 # enter ECRYPT_ivsetup
7981 .text
7982 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7983 add %r11,%rsp
7984 mov %rdi,%rax
7985 mov %rsi,%rdx
7986 + pax_force_retaddr
7987 ret
7988 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
7989 index b2c2f57..8470cab 100644
7990 --- a/arch/x86/crypto/sha1_ssse3_asm.S
7991 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
7992 @@ -28,6 +28,8 @@
7993 * (at your option) any later version.
7994 */
7995
7996 +#include <asm/alternative-asm.h>
7997 +
7998 #define CTX %rdi // arg1
7999 #define BUF %rsi // arg2
8000 #define CNT %rdx // arg3
8001 @@ -104,6 +106,7 @@
8002 pop %r12
8003 pop %rbp
8004 pop %rbx
8005 + pax_force_retaddr 0, 1
8006 ret
8007
8008 .size \name, .-\name
8009 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8010 index 5b012a2..36d5364 100644
8011 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8012 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8013 @@ -20,6 +20,8 @@
8014 *
8015 */
8016
8017 +#include <asm/alternative-asm.h>
8018 +
8019 .file "twofish-x86_64-asm-3way.S"
8020 .text
8021
8022 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8023 popq %r13;
8024 popq %r14;
8025 popq %r15;
8026 + pax_force_retaddr 0, 1
8027 ret;
8028
8029 __enc_xor3:
8030 @@ -271,6 +274,7 @@ __enc_xor3:
8031 popq %r13;
8032 popq %r14;
8033 popq %r15;
8034 + pax_force_retaddr 0, 1
8035 ret;
8036
8037 .global twofish_dec_blk_3way
8038 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8039 popq %r13;
8040 popq %r14;
8041 popq %r15;
8042 + pax_force_retaddr 0, 1
8043 ret;
8044
8045 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8046 index 7bcf3fc..f53832f 100644
8047 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8048 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8049 @@ -21,6 +21,7 @@
8050 .text
8051
8052 #include <asm/asm-offsets.h>
8053 +#include <asm/alternative-asm.h>
8054
8055 #define a_offset 0
8056 #define b_offset 4
8057 @@ -268,6 +269,7 @@ twofish_enc_blk:
8058
8059 popq R1
8060 movq $1,%rax
8061 + pax_force_retaddr 0, 1
8062 ret
8063
8064 twofish_dec_blk:
8065 @@ -319,4 +321,5 @@ twofish_dec_blk:
8066
8067 popq R1
8068 movq $1,%rax
8069 + pax_force_retaddr 0, 1
8070 ret
8071 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8072 index fd84387..887aa7e 100644
8073 --- a/arch/x86/ia32/ia32_aout.c
8074 +++ b/arch/x86/ia32/ia32_aout.c
8075 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8076 unsigned long dump_start, dump_size;
8077 struct user32 dump;
8078
8079 + memset(&dump, 0, sizeof(dump));
8080 +
8081 fs = get_fs();
8082 set_fs(KERNEL_DS);
8083 has_dumped = 1;
8084 @@ -315,6 +317,13 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
8085 current->mm->free_area_cache = TASK_UNMAPPED_BASE;
8086 current->mm->cached_hole_size = 0;
8087
8088 + retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
8089 + if (retval < 0) {
8090 + /* Someone check-me: is this error path enough? */
8091 + send_sig(SIGKILL, current, 0);
8092 + return retval;
8093 + }
8094 +
8095 install_exec_creds(bprm);
8096 current->flags &= ~PF_FORKNOEXEC;
8097
8098 @@ -410,13 +419,6 @@ beyond_if:
8099
8100 set_brk(current->mm->start_brk, current->mm->brk);
8101
8102 - retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
8103 - if (retval < 0) {
8104 - /* Someone check-me: is this error path enough? */
8105 - send_sig(SIGKILL, current, 0);
8106 - return retval;
8107 - }
8108 -
8109 current->mm->start_stack =
8110 (unsigned long)create_aout_tables((char __user *)bprm->p, bprm);
8111 /* start thread */
8112 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8113 index 6557769..ef6ae89 100644
8114 --- a/arch/x86/ia32/ia32_signal.c
8115 +++ b/arch/x86/ia32/ia32_signal.c
8116 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8117 }
8118 seg = get_fs();
8119 set_fs(KERNEL_DS);
8120 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8121 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8122 set_fs(seg);
8123 if (ret >= 0 && uoss_ptr) {
8124 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8125 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8126 */
8127 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8128 size_t frame_size,
8129 - void **fpstate)
8130 + void __user **fpstate)
8131 {
8132 unsigned long sp;
8133
8134 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8135
8136 if (used_math()) {
8137 sp = sp - sig_xstate_ia32_size;
8138 - *fpstate = (struct _fpstate_ia32 *) sp;
8139 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8140 if (save_i387_xstate_ia32(*fpstate) < 0)
8141 return (void __user *) -1L;
8142 }
8143 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8144 sp -= frame_size;
8145 /* Align the stack pointer according to the i386 ABI,
8146 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8147 - sp = ((sp + 4) & -16ul) - 4;
8148 + sp = ((sp - 12) & -16ul) - 4;
8149 return (void __user *) sp;
8150 }
8151
8152 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8153 * These are actually not used anymore, but left because some
8154 * gdb versions depend on them as a marker.
8155 */
8156 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8157 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8158 } put_user_catch(err);
8159
8160 if (err)
8161 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8162 0xb8,
8163 __NR_ia32_rt_sigreturn,
8164 0x80cd,
8165 - 0,
8166 + 0
8167 };
8168
8169 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8170 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8171
8172 if (ka->sa.sa_flags & SA_RESTORER)
8173 restorer = ka->sa.sa_restorer;
8174 + else if (current->mm->context.vdso)
8175 + /* Return stub is in 32bit vsyscall page */
8176 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8177 else
8178 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8179 - rt_sigreturn);
8180 + restorer = &frame->retcode;
8181 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8182
8183 /*
8184 * Not actually used anymore, but left because some gdb
8185 * versions need it.
8186 */
8187 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8188 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8189 } put_user_catch(err);
8190
8191 if (err)
8192 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8193 index a6253ec..4ad2120 100644
8194 --- a/arch/x86/ia32/ia32entry.S
8195 +++ b/arch/x86/ia32/ia32entry.S
8196 @@ -13,7 +13,9 @@
8197 #include <asm/thread_info.h>
8198 #include <asm/segment.h>
8199 #include <asm/irqflags.h>
8200 +#include <asm/pgtable.h>
8201 #include <linux/linkage.h>
8202 +#include <asm/alternative-asm.h>
8203
8204 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8205 #include <linux/elf-em.h>
8206 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8207 ENDPROC(native_irq_enable_sysexit)
8208 #endif
8209
8210 + .macro pax_enter_kernel_user
8211 + pax_set_fptr_mask
8212 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8213 + call pax_enter_kernel_user
8214 +#endif
8215 + .endm
8216 +
8217 + .macro pax_exit_kernel_user
8218 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8219 + call pax_exit_kernel_user
8220 +#endif
8221 +#ifdef CONFIG_PAX_RANDKSTACK
8222 + pushq %rax
8223 + pushq %r11
8224 + call pax_randomize_kstack
8225 + popq %r11
8226 + popq %rax
8227 +#endif
8228 + .endm
8229 +
8230 +.macro pax_erase_kstack
8231 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8232 + call pax_erase_kstack
8233 +#endif
8234 +.endm
8235 +
8236 /*
8237 * 32bit SYSENTER instruction entry.
8238 *
8239 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8240 CFI_REGISTER rsp,rbp
8241 SWAPGS_UNSAFE_STACK
8242 movq PER_CPU_VAR(kernel_stack), %rsp
8243 - addq $(KERNEL_STACK_OFFSET),%rsp
8244 - /*
8245 - * No need to follow this irqs on/off section: the syscall
8246 - * disabled irqs, here we enable it straight after entry:
8247 - */
8248 - ENABLE_INTERRUPTS(CLBR_NONE)
8249 movl %ebp,%ebp /* zero extension */
8250 pushq_cfi $__USER32_DS
8251 /*CFI_REL_OFFSET ss,0*/
8252 @@ -134,25 +156,39 @@ ENTRY(ia32_sysenter_target)
8253 CFI_REL_OFFSET rsp,0
8254 pushfq_cfi
8255 /*CFI_REL_OFFSET rflags,0*/
8256 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
8257 - CFI_REGISTER rip,r10
8258 + orl $X86_EFLAGS_IF,(%rsp)
8259 + GET_THREAD_INFO(%r11)
8260 + movl TI_sysenter_return(%r11), %r11d
8261 + CFI_REGISTER rip,r11
8262 pushq_cfi $__USER32_CS
8263 /*CFI_REL_OFFSET cs,0*/
8264 movl %eax, %eax
8265 - pushq_cfi %r10
8266 + pushq_cfi %r11
8267 CFI_REL_OFFSET rip,0
8268 pushq_cfi %rax
8269 cld
8270 SAVE_ARGS 0,1,0
8271 + pax_enter_kernel_user
8272 + /*
8273 + * No need to follow this irqs on/off section: the syscall
8274 + * disabled irqs, here we enable it straight after entry:
8275 + */
8276 + ENABLE_INTERRUPTS(CLBR_NONE)
8277 /* no need to do an access_ok check here because rbp has been
8278 32bit zero extended */
8279 +
8280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8281 + mov $PAX_USER_SHADOW_BASE,%r11
8282 + add %r11,%rbp
8283 +#endif
8284 +
8285 1: movl (%rbp),%ebp
8286 .section __ex_table,"a"
8287 .quad 1b,ia32_badarg
8288 .previous
8289 - GET_THREAD_INFO(%r10)
8290 - orl $TS_COMPAT,TI_status(%r10)
8291 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8292 + GET_THREAD_INFO(%r11)
8293 + orl $TS_COMPAT,TI_status(%r11)
8294 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8295 CFI_REMEMBER_STATE
8296 jnz sysenter_tracesys
8297 cmpq $(IA32_NR_syscalls-1),%rax
8298 @@ -162,13 +198,15 @@ sysenter_do_call:
8299 sysenter_dispatch:
8300 call *ia32_sys_call_table(,%rax,8)
8301 movq %rax,RAX-ARGOFFSET(%rsp)
8302 - GET_THREAD_INFO(%r10)
8303 + GET_THREAD_INFO(%r11)
8304 DISABLE_INTERRUPTS(CLBR_NONE)
8305 TRACE_IRQS_OFF
8306 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8307 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8308 jnz sysexit_audit
8309 sysexit_from_sys_call:
8310 - andl $~TS_COMPAT,TI_status(%r10)
8311 + pax_exit_kernel_user
8312 + pax_erase_kstack
8313 + andl $~TS_COMPAT,TI_status(%r11)
8314 /* clear IF, that popfq doesn't enable interrupts early */
8315 andl $~0x200,EFLAGS-R11(%rsp)
8316 movl RIP-R11(%rsp),%edx /* User %eip */
8317 @@ -194,6 +232,9 @@ sysexit_from_sys_call:
8318 movl %eax,%esi /* 2nd arg: syscall number */
8319 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8320 call audit_syscall_entry
8321 +
8322 + pax_erase_kstack
8323 +
8324 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8325 cmpq $(IA32_NR_syscalls-1),%rax
8326 ja ia32_badsys
8327 @@ -205,7 +246,7 @@ sysexit_from_sys_call:
8328 .endm
8329
8330 .macro auditsys_exit exit
8331 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8332 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8333 jnz ia32_ret_from_sys_call
8334 TRACE_IRQS_ON
8335 sti
8336 @@ -215,12 +256,12 @@ sysexit_from_sys_call:
8337 movzbl %al,%edi /* zero-extend that into %edi */
8338 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
8339 call audit_syscall_exit
8340 - GET_THREAD_INFO(%r10)
8341 + GET_THREAD_INFO(%r11)
8342 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
8343 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8344 cli
8345 TRACE_IRQS_OFF
8346 - testl %edi,TI_flags(%r10)
8347 + testl %edi,TI_flags(%r11)
8348 jz \exit
8349 CLEAR_RREGS -ARGOFFSET
8350 jmp int_with_check
8351 @@ -238,7 +279,7 @@ sysexit_audit:
8352
8353 sysenter_tracesys:
8354 #ifdef CONFIG_AUDITSYSCALL
8355 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8356 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8357 jz sysenter_auditsys
8358 #endif
8359 SAVE_REST
8360 @@ -246,6 +287,9 @@ sysenter_tracesys:
8361 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8362 movq %rsp,%rdi /* &pt_regs -> arg1 */
8363 call syscall_trace_enter
8364 +
8365 + pax_erase_kstack
8366 +
8367 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8368 RESTORE_REST
8369 cmpq $(IA32_NR_syscalls-1),%rax
8370 @@ -277,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8371 ENTRY(ia32_cstar_target)
8372 CFI_STARTPROC32 simple
8373 CFI_SIGNAL_FRAME
8374 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8375 + CFI_DEF_CFA rsp,0
8376 CFI_REGISTER rip,rcx
8377 /*CFI_REGISTER rflags,r11*/
8378 SWAPGS_UNSAFE_STACK
8379 movl %esp,%r8d
8380 CFI_REGISTER rsp,r8
8381 movq PER_CPU_VAR(kernel_stack),%rsp
8382 + SAVE_ARGS 8*6,0,0
8383 + pax_enter_kernel_user
8384 /*
8385 * No need to follow this irqs on/off section: the syscall
8386 * disabled irqs and here we enable it straight after entry:
8387 */
8388 ENABLE_INTERRUPTS(CLBR_NONE)
8389 - SAVE_ARGS 8,0,0
8390 movl %eax,%eax /* zero extension */
8391 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8392 movq %rcx,RIP-ARGOFFSET(%rsp)
8393 @@ -305,13 +350,19 @@ ENTRY(ia32_cstar_target)
8394 /* no need to do an access_ok check here because r8 has been
8395 32bit zero extended */
8396 /* hardware stack frame is complete now */
8397 +
8398 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8399 + mov $PAX_USER_SHADOW_BASE,%r11
8400 + add %r11,%r8
8401 +#endif
8402 +
8403 1: movl (%r8),%r9d
8404 .section __ex_table,"a"
8405 .quad 1b,ia32_badarg
8406 .previous
8407 - GET_THREAD_INFO(%r10)
8408 - orl $TS_COMPAT,TI_status(%r10)
8409 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8410 + GET_THREAD_INFO(%r11)
8411 + orl $TS_COMPAT,TI_status(%r11)
8412 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8413 CFI_REMEMBER_STATE
8414 jnz cstar_tracesys
8415 cmpq $IA32_NR_syscalls-1,%rax
8416 @@ -321,13 +372,15 @@ cstar_do_call:
8417 cstar_dispatch:
8418 call *ia32_sys_call_table(,%rax,8)
8419 movq %rax,RAX-ARGOFFSET(%rsp)
8420 - GET_THREAD_INFO(%r10)
8421 + GET_THREAD_INFO(%r11)
8422 DISABLE_INTERRUPTS(CLBR_NONE)
8423 TRACE_IRQS_OFF
8424 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8425 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8426 jnz sysretl_audit
8427 sysretl_from_sys_call:
8428 - andl $~TS_COMPAT,TI_status(%r10)
8429 + pax_exit_kernel_user
8430 + pax_erase_kstack
8431 + andl $~TS_COMPAT,TI_status(%r11)
8432 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8433 movl RIP-ARGOFFSET(%rsp),%ecx
8434 CFI_REGISTER rip,rcx
8435 @@ -355,7 +408,7 @@ sysretl_audit:
8436
8437 cstar_tracesys:
8438 #ifdef CONFIG_AUDITSYSCALL
8439 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8440 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8441 jz cstar_auditsys
8442 #endif
8443 xchgl %r9d,%ebp
8444 @@ -364,6 +417,9 @@ cstar_tracesys:
8445 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8446 movq %rsp,%rdi /* &pt_regs -> arg1 */
8447 call syscall_trace_enter
8448 +
8449 + pax_erase_kstack
8450 +
8451 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8452 RESTORE_REST
8453 xchgl %ebp,%r9d
8454 @@ -409,20 +465,21 @@ ENTRY(ia32_syscall)
8455 CFI_REL_OFFSET rip,RIP-RIP
8456 PARAVIRT_ADJUST_EXCEPTION_FRAME
8457 SWAPGS
8458 - /*
8459 - * No need to follow this irqs on/off section: the syscall
8460 - * disabled irqs and here we enable it straight after entry:
8461 - */
8462 - ENABLE_INTERRUPTS(CLBR_NONE)
8463 movl %eax,%eax
8464 pushq_cfi %rax
8465 cld
8466 /* note the registers are not zero extended to the sf.
8467 this could be a problem. */
8468 SAVE_ARGS 0,1,0
8469 - GET_THREAD_INFO(%r10)
8470 - orl $TS_COMPAT,TI_status(%r10)
8471 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8472 + pax_enter_kernel_user
8473 + /*
8474 + * No need to follow this irqs on/off section: the syscall
8475 + * disabled irqs and here we enable it straight after entry:
8476 + */
8477 + ENABLE_INTERRUPTS(CLBR_NONE)
8478 + GET_THREAD_INFO(%r11)
8479 + orl $TS_COMPAT,TI_status(%r11)
8480 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8481 jnz ia32_tracesys
8482 cmpq $(IA32_NR_syscalls-1),%rax
8483 ja ia32_badsys
8484 @@ -441,6 +498,9 @@ ia32_tracesys:
8485 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8486 movq %rsp,%rdi /* &pt_regs -> arg1 */
8487 call syscall_trace_enter
8488 +
8489 + pax_erase_kstack
8490 +
8491 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8492 RESTORE_REST
8493 cmpq $(IA32_NR_syscalls-1),%rax
8494 @@ -455,6 +515,7 @@ ia32_badsys:
8495
8496 quiet_ni_syscall:
8497 movq $-ENOSYS,%rax
8498 + pax_force_retaddr
8499 ret
8500 CFI_ENDPROC
8501
8502 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8503 index f6f5c53..b358b28 100644
8504 --- a/arch/x86/ia32/sys_ia32.c
8505 +++ b/arch/x86/ia32/sys_ia32.c
8506 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8507 */
8508 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8509 {
8510 - typeof(ubuf->st_uid) uid = 0;
8511 - typeof(ubuf->st_gid) gid = 0;
8512 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8513 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8514 SET_UID(uid, stat->uid);
8515 SET_GID(gid, stat->gid);
8516 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8517 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8518 }
8519 set_fs(KERNEL_DS);
8520 ret = sys_rt_sigprocmask(how,
8521 - set ? (sigset_t __user *)&s : NULL,
8522 - oset ? (sigset_t __user *)&s : NULL,
8523 + set ? (sigset_t __force_user *)&s : NULL,
8524 + oset ? (sigset_t __force_user *)&s : NULL,
8525 sigsetsize);
8526 set_fs(old_fs);
8527 if (ret)
8528 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8529 return alarm_setitimer(seconds);
8530 }
8531
8532 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8533 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8534 int options)
8535 {
8536 return compat_sys_wait4(pid, stat_addr, options, NULL);
8537 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8538 mm_segment_t old_fs = get_fs();
8539
8540 set_fs(KERNEL_DS);
8541 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8542 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8543 set_fs(old_fs);
8544 if (put_compat_timespec(&t, interval))
8545 return -EFAULT;
8546 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8547 mm_segment_t old_fs = get_fs();
8548
8549 set_fs(KERNEL_DS);
8550 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8551 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8552 set_fs(old_fs);
8553 if (!ret) {
8554 switch (_NSIG_WORDS) {
8555 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8556 if (copy_siginfo_from_user32(&info, uinfo))
8557 return -EFAULT;
8558 set_fs(KERNEL_DS);
8559 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8560 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8561 set_fs(old_fs);
8562 return ret;
8563 }
8564 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8565 return -EFAULT;
8566
8567 set_fs(KERNEL_DS);
8568 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8569 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8570 count);
8571 set_fs(old_fs);
8572
8573 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8574 index 091508b..7692c6f 100644
8575 --- a/arch/x86/include/asm/alternative-asm.h
8576 +++ b/arch/x86/include/asm/alternative-asm.h
8577 @@ -4,10 +4,10 @@
8578
8579 #ifdef CONFIG_SMP
8580 .macro LOCK_PREFIX
8581 -1: lock
8582 +672: lock
8583 .section .smp_locks,"a"
8584 .balign 4
8585 - .long 1b - .
8586 + .long 672b - .
8587 .previous
8588 .endm
8589 #else
8590 @@ -15,6 +15,45 @@
8591 .endm
8592 #endif
8593
8594 +#ifdef KERNEXEC_PLUGIN
8595 + .macro pax_force_retaddr_bts rip=0
8596 + btsq $63,\rip(%rsp)
8597 + .endm
8598 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8599 + .macro pax_force_retaddr rip=0, reload=0
8600 + btsq $63,\rip(%rsp)
8601 + .endm
8602 + .macro pax_force_fptr ptr
8603 + btsq $63,\ptr
8604 + .endm
8605 + .macro pax_set_fptr_mask
8606 + .endm
8607 +#endif
8608 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8609 + .macro pax_force_retaddr rip=0, reload=0
8610 + .if \reload
8611 + pax_set_fptr_mask
8612 + .endif
8613 + orq %r10,\rip(%rsp)
8614 + .endm
8615 + .macro pax_force_fptr ptr
8616 + orq %r10,\ptr
8617 + .endm
8618 + .macro pax_set_fptr_mask
8619 + movabs $0x8000000000000000,%r10
8620 + .endm
8621 +#endif
8622 +#else
8623 + .macro pax_force_retaddr rip=0, reload=0
8624 + .endm
8625 + .macro pax_force_fptr ptr
8626 + .endm
8627 + .macro pax_force_retaddr_bts rip=0
8628 + .endm
8629 + .macro pax_set_fptr_mask
8630 + .endm
8631 +#endif
8632 +
8633 .macro altinstruction_entry orig alt feature orig_len alt_len
8634 .long \orig - .
8635 .long \alt - .
8636 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8637 index 37ad100..7d47faa 100644
8638 --- a/arch/x86/include/asm/alternative.h
8639 +++ b/arch/x86/include/asm/alternative.h
8640 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8641 ".section .discard,\"aw\",@progbits\n" \
8642 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8643 ".previous\n" \
8644 - ".section .altinstr_replacement, \"ax\"\n" \
8645 + ".section .altinstr_replacement, \"a\"\n" \
8646 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8647 ".previous"
8648
8649 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8650 index 1a6c09a..fec2432 100644
8651 --- a/arch/x86/include/asm/apic.h
8652 +++ b/arch/x86/include/asm/apic.h
8653 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8654
8655 #ifdef CONFIG_X86_LOCAL_APIC
8656
8657 -extern unsigned int apic_verbosity;
8658 +extern int apic_verbosity;
8659 extern int local_apic_timer_c2_ok;
8660
8661 extern int disable_apic;
8662 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8663 index 20370c6..a2eb9b0 100644
8664 --- a/arch/x86/include/asm/apm.h
8665 +++ b/arch/x86/include/asm/apm.h
8666 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8667 __asm__ __volatile__(APM_DO_ZERO_SEGS
8668 "pushl %%edi\n\t"
8669 "pushl %%ebp\n\t"
8670 - "lcall *%%cs:apm_bios_entry\n\t"
8671 + "lcall *%%ss:apm_bios_entry\n\t"
8672 "setc %%al\n\t"
8673 "popl %%ebp\n\t"
8674 "popl %%edi\n\t"
8675 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8676 __asm__ __volatile__(APM_DO_ZERO_SEGS
8677 "pushl %%edi\n\t"
8678 "pushl %%ebp\n\t"
8679 - "lcall *%%cs:apm_bios_entry\n\t"
8680 + "lcall *%%ss:apm_bios_entry\n\t"
8681 "setc %%bl\n\t"
8682 "popl %%ebp\n\t"
8683 "popl %%edi\n\t"
8684 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8685 index 58cb6d4..ca9010d 100644
8686 --- a/arch/x86/include/asm/atomic.h
8687 +++ b/arch/x86/include/asm/atomic.h
8688 @@ -22,7 +22,18 @@
8689 */
8690 static inline int atomic_read(const atomic_t *v)
8691 {
8692 - return (*(volatile int *)&(v)->counter);
8693 + return (*(volatile const int *)&(v)->counter);
8694 +}
8695 +
8696 +/**
8697 + * atomic_read_unchecked - read atomic variable
8698 + * @v: pointer of type atomic_unchecked_t
8699 + *
8700 + * Atomically reads the value of @v.
8701 + */
8702 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8703 +{
8704 + return (*(volatile const int *)&(v)->counter);
8705 }
8706
8707 /**
8708 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8709 }
8710
8711 /**
8712 + * atomic_set_unchecked - set atomic variable
8713 + * @v: pointer of type atomic_unchecked_t
8714 + * @i: required value
8715 + *
8716 + * Atomically sets the value of @v to @i.
8717 + */
8718 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8719 +{
8720 + v->counter = i;
8721 +}
8722 +
8723 +/**
8724 * atomic_add - add integer to atomic variable
8725 * @i: integer value to add
8726 * @v: pointer of type atomic_t
8727 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8728 */
8729 static inline void atomic_add(int i, atomic_t *v)
8730 {
8731 - asm volatile(LOCK_PREFIX "addl %1,%0"
8732 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8733 +
8734 +#ifdef CONFIG_PAX_REFCOUNT
8735 + "jno 0f\n"
8736 + LOCK_PREFIX "subl %1,%0\n"
8737 + "int $4\n0:\n"
8738 + _ASM_EXTABLE(0b, 0b)
8739 +#endif
8740 +
8741 + : "+m" (v->counter)
8742 + : "ir" (i));
8743 +}
8744 +
8745 +/**
8746 + * atomic_add_unchecked - add integer to atomic variable
8747 + * @i: integer value to add
8748 + * @v: pointer of type atomic_unchecked_t
8749 + *
8750 + * Atomically adds @i to @v.
8751 + */
8752 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8753 +{
8754 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8755 : "+m" (v->counter)
8756 : "ir" (i));
8757 }
8758 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8759 */
8760 static inline void atomic_sub(int i, atomic_t *v)
8761 {
8762 - asm volatile(LOCK_PREFIX "subl %1,%0"
8763 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8764 +
8765 +#ifdef CONFIG_PAX_REFCOUNT
8766 + "jno 0f\n"
8767 + LOCK_PREFIX "addl %1,%0\n"
8768 + "int $4\n0:\n"
8769 + _ASM_EXTABLE(0b, 0b)
8770 +#endif
8771 +
8772 + : "+m" (v->counter)
8773 + : "ir" (i));
8774 +}
8775 +
8776 +/**
8777 + * atomic_sub_unchecked - subtract integer from atomic variable
8778 + * @i: integer value to subtract
8779 + * @v: pointer of type atomic_unchecked_t
8780 + *
8781 + * Atomically subtracts @i from @v.
8782 + */
8783 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8784 +{
8785 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8786 : "+m" (v->counter)
8787 : "ir" (i));
8788 }
8789 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8790 {
8791 unsigned char c;
8792
8793 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8794 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8795 +
8796 +#ifdef CONFIG_PAX_REFCOUNT
8797 + "jno 0f\n"
8798 + LOCK_PREFIX "addl %2,%0\n"
8799 + "int $4\n0:\n"
8800 + _ASM_EXTABLE(0b, 0b)
8801 +#endif
8802 +
8803 + "sete %1\n"
8804 : "+m" (v->counter), "=qm" (c)
8805 : "ir" (i) : "memory");
8806 return c;
8807 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8808 */
8809 static inline void atomic_inc(atomic_t *v)
8810 {
8811 - asm volatile(LOCK_PREFIX "incl %0"
8812 + asm volatile(LOCK_PREFIX "incl %0\n"
8813 +
8814 +#ifdef CONFIG_PAX_REFCOUNT
8815 + "jno 0f\n"
8816 + LOCK_PREFIX "decl %0\n"
8817 + "int $4\n0:\n"
8818 + _ASM_EXTABLE(0b, 0b)
8819 +#endif
8820 +
8821 + : "+m" (v->counter));
8822 +}
8823 +
8824 +/**
8825 + * atomic_inc_unchecked - increment atomic variable
8826 + * @v: pointer of type atomic_unchecked_t
8827 + *
8828 + * Atomically increments @v by 1.
8829 + */
8830 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8831 +{
8832 + asm volatile(LOCK_PREFIX "incl %0\n"
8833 : "+m" (v->counter));
8834 }
8835
8836 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
8837 */
8838 static inline void atomic_dec(atomic_t *v)
8839 {
8840 - asm volatile(LOCK_PREFIX "decl %0"
8841 + asm volatile(LOCK_PREFIX "decl %0\n"
8842 +
8843 +#ifdef CONFIG_PAX_REFCOUNT
8844 + "jno 0f\n"
8845 + LOCK_PREFIX "incl %0\n"
8846 + "int $4\n0:\n"
8847 + _ASM_EXTABLE(0b, 0b)
8848 +#endif
8849 +
8850 + : "+m" (v->counter));
8851 +}
8852 +
8853 +/**
8854 + * atomic_dec_unchecked - decrement atomic variable
8855 + * @v: pointer of type atomic_unchecked_t
8856 + *
8857 + * Atomically decrements @v by 1.
8858 + */
8859 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8860 +{
8861 + asm volatile(LOCK_PREFIX "decl %0\n"
8862 : "+m" (v->counter));
8863 }
8864
8865 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8866 {
8867 unsigned char c;
8868
8869 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8870 + asm volatile(LOCK_PREFIX "decl %0\n"
8871 +
8872 +#ifdef CONFIG_PAX_REFCOUNT
8873 + "jno 0f\n"
8874 + LOCK_PREFIX "incl %0\n"
8875 + "int $4\n0:\n"
8876 + _ASM_EXTABLE(0b, 0b)
8877 +#endif
8878 +
8879 + "sete %1\n"
8880 : "+m" (v->counter), "=qm" (c)
8881 : : "memory");
8882 return c != 0;
8883 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8884 {
8885 unsigned char c;
8886
8887 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8888 + asm volatile(LOCK_PREFIX "incl %0\n"
8889 +
8890 +#ifdef CONFIG_PAX_REFCOUNT
8891 + "jno 0f\n"
8892 + LOCK_PREFIX "decl %0\n"
8893 + "int $4\n0:\n"
8894 + _ASM_EXTABLE(0b, 0b)
8895 +#endif
8896 +
8897 + "sete %1\n"
8898 + : "+m" (v->counter), "=qm" (c)
8899 + : : "memory");
8900 + return c != 0;
8901 +}
8902 +
8903 +/**
8904 + * atomic_inc_and_test_unchecked - increment and test
8905 + * @v: pointer of type atomic_unchecked_t
8906 + *
8907 + * Atomically increments @v by 1
8908 + * and returns true if the result is zero, or false for all
8909 + * other cases.
8910 + */
8911 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8912 +{
8913 + unsigned char c;
8914 +
8915 + asm volatile(LOCK_PREFIX "incl %0\n"
8916 + "sete %1\n"
8917 : "+m" (v->counter), "=qm" (c)
8918 : : "memory");
8919 return c != 0;
8920 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8921 {
8922 unsigned char c;
8923
8924 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8925 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8926 +
8927 +#ifdef CONFIG_PAX_REFCOUNT
8928 + "jno 0f\n"
8929 + LOCK_PREFIX "subl %2,%0\n"
8930 + "int $4\n0:\n"
8931 + _ASM_EXTABLE(0b, 0b)
8932 +#endif
8933 +
8934 + "sets %1\n"
8935 : "+m" (v->counter), "=qm" (c)
8936 : "ir" (i) : "memory");
8937 return c;
8938 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
8939 goto no_xadd;
8940 #endif
8941 /* Modern 486+ processor */
8942 - return i + xadd(&v->counter, i);
8943 + return i + xadd_check_overflow(&v->counter, i);
8944
8945 #ifdef CONFIG_M386
8946 no_xadd: /* Legacy 386 processor */
8947 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
8948 }
8949
8950 /**
8951 + * atomic_add_return_unchecked - add integer and return
8952 + * @i: integer value to add
8953 + * @v: pointer of type atomic_unchecked_t
8954 + *
8955 + * Atomically adds @i to @v and returns @i + @v
8956 + */
8957 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8958 +{
8959 +#ifdef CONFIG_M386
8960 + int __i;
8961 + unsigned long flags;
8962 + if (unlikely(boot_cpu_data.x86 <= 3))
8963 + goto no_xadd;
8964 +#endif
8965 + /* Modern 486+ processor */
8966 + return i + xadd(&v->counter, i);
8967 +
8968 +#ifdef CONFIG_M386
8969 +no_xadd: /* Legacy 386 processor */
8970 + raw_local_irq_save(flags);
8971 + __i = atomic_read_unchecked(v);
8972 + atomic_set_unchecked(v, i + __i);
8973 + raw_local_irq_restore(flags);
8974 + return i + __i;
8975 +#endif
8976 +}
8977 +
8978 +/**
8979 * atomic_sub_return - subtract integer and return
8980 * @v: pointer of type atomic_t
8981 * @i: integer value to subtract
8982 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
8983 }
8984
8985 #define atomic_inc_return(v) (atomic_add_return(1, v))
8986 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8987 +{
8988 + return atomic_add_return_unchecked(1, v);
8989 +}
8990 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8991
8992 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8993 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8994 return cmpxchg(&v->counter, old, new);
8995 }
8996
8997 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8998 +{
8999 + return cmpxchg(&v->counter, old, new);
9000 +}
9001 +
9002 static inline int atomic_xchg(atomic_t *v, int new)
9003 {
9004 return xchg(&v->counter, new);
9005 }
9006
9007 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9008 +{
9009 + return xchg(&v->counter, new);
9010 +}
9011 +
9012 /**
9013 * __atomic_add_unless - add unless the number is already a given value
9014 * @v: pointer of type atomic_t
9015 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9016 */
9017 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9018 {
9019 - int c, old;
9020 + int c, old, new;
9021 c = atomic_read(v);
9022 for (;;) {
9023 - if (unlikely(c == (u)))
9024 + if (unlikely(c == u))
9025 break;
9026 - old = atomic_cmpxchg((v), c, c + (a));
9027 +
9028 + asm volatile("addl %2,%0\n"
9029 +
9030 +#ifdef CONFIG_PAX_REFCOUNT
9031 + "jno 0f\n"
9032 + "subl %2,%0\n"
9033 + "int $4\n0:\n"
9034 + _ASM_EXTABLE(0b, 0b)
9035 +#endif
9036 +
9037 + : "=r" (new)
9038 + : "0" (c), "ir" (a));
9039 +
9040 + old = atomic_cmpxchg(v, c, new);
9041 if (likely(old == c))
9042 break;
9043 c = old;
9044 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9045 return c;
9046 }
9047
9048 +/**
9049 + * atomic_inc_not_zero_hint - increment if not null
9050 + * @v: pointer of type atomic_t
9051 + * @hint: probable value of the atomic before the increment
9052 + *
9053 + * This version of atomic_inc_not_zero() gives a hint of probable
9054 + * value of the atomic. This helps processor to not read the memory
9055 + * before doing the atomic read/modify/write cycle, lowering
9056 + * number of bus transactions on some arches.
9057 + *
9058 + * Returns: 0 if increment was not done, 1 otherwise.
9059 + */
9060 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9061 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9062 +{
9063 + int val, c = hint, new;
9064 +
9065 + /* sanity test, should be removed by compiler if hint is a constant */
9066 + if (!hint)
9067 + return __atomic_add_unless(v, 1, 0);
9068 +
9069 + do {
9070 + asm volatile("incl %0\n"
9071 +
9072 +#ifdef CONFIG_PAX_REFCOUNT
9073 + "jno 0f\n"
9074 + "decl %0\n"
9075 + "int $4\n0:\n"
9076 + _ASM_EXTABLE(0b, 0b)
9077 +#endif
9078 +
9079 + : "=r" (new)
9080 + : "0" (c));
9081 +
9082 + val = atomic_cmpxchg(v, c, new);
9083 + if (val == c)
9084 + return 1;
9085 + c = val;
9086 + } while (c);
9087 +
9088 + return 0;
9089 +}
9090
9091 /*
9092 * atomic_dec_if_positive - decrement by 1 if old value positive
9093 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9094 index 24098aa..1e37723 100644
9095 --- a/arch/x86/include/asm/atomic64_32.h
9096 +++ b/arch/x86/include/asm/atomic64_32.h
9097 @@ -12,6 +12,14 @@ typedef struct {
9098 u64 __aligned(8) counter;
9099 } atomic64_t;
9100
9101 +#ifdef CONFIG_PAX_REFCOUNT
9102 +typedef struct {
9103 + u64 __aligned(8) counter;
9104 +} atomic64_unchecked_t;
9105 +#else
9106 +typedef atomic64_t atomic64_unchecked_t;
9107 +#endif
9108 +
9109 #define ATOMIC64_INIT(val) { (val) }
9110
9111 #ifdef CONFIG_X86_CMPXCHG64
9112 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9113 }
9114
9115 /**
9116 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9117 + * @p: pointer to type atomic64_unchecked_t
9118 + * @o: expected value
9119 + * @n: new value
9120 + *
9121 + * Atomically sets @v to @n if it was equal to @o and returns
9122 + * the old value.
9123 + */
9124 +
9125 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9126 +{
9127 + return cmpxchg64(&v->counter, o, n);
9128 +}
9129 +
9130 +/**
9131 * atomic64_xchg - xchg atomic64 variable
9132 * @v: pointer to type atomic64_t
9133 * @n: value to assign
9134 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9135 }
9136
9137 /**
9138 + * atomic64_set_unchecked - set atomic64 variable
9139 + * @v: pointer to type atomic64_unchecked_t
9140 + * @n: value to assign
9141 + *
9142 + * Atomically sets the value of @v to @n.
9143 + */
9144 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9145 +{
9146 + unsigned high = (unsigned)(i >> 32);
9147 + unsigned low = (unsigned)i;
9148 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9149 + : "+b" (low), "+c" (high)
9150 + : "S" (v)
9151 + : "eax", "edx", "memory"
9152 + );
9153 +}
9154 +
9155 +/**
9156 * atomic64_read - read atomic64 variable
9157 * @v: pointer to type atomic64_t
9158 *
9159 @@ -93,6 +134,22 @@ static inline long long atomic64_read(atomic64_t *v)
9160 }
9161
9162 /**
9163 + * atomic64_read_unchecked - read atomic64 variable
9164 + * @v: pointer to type atomic64_unchecked_t
9165 + *
9166 + * Atomically reads the value of @v and returns it.
9167 + */
9168 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9169 +{
9170 + long long r;
9171 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9172 + : "=A" (r), "+c" (v)
9173 + : : "memory"
9174 + );
9175 + return r;
9176 + }
9177 +
9178 +/**
9179 * atomic64_add_return - add and return
9180 * @i: integer value to add
9181 * @v: pointer to type atomic64_t
9182 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9183 return i;
9184 }
9185
9186 +/**
9187 + * atomic64_add_return_unchecked - add and return
9188 + * @i: integer value to add
9189 + * @v: pointer to type atomic64_unchecked_t
9190 + *
9191 + * Atomically adds @i to @v and returns @i + *@v
9192 + */
9193 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9194 +{
9195 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9196 + : "+A" (i), "+c" (v)
9197 + : : "memory"
9198 + );
9199 + return i;
9200 +}
9201 +
9202 /*
9203 * Other variants with different arithmetic operators:
9204 */
9205 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9206 return a;
9207 }
9208
9209 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9210 +{
9211 + long long a;
9212 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9213 + : "=A" (a)
9214 + : "S" (v)
9215 + : "memory", "ecx"
9216 + );
9217 + return a;
9218 +}
9219 +
9220 static inline long long atomic64_dec_return(atomic64_t *v)
9221 {
9222 long long a;
9223 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9224 }
9225
9226 /**
9227 + * atomic64_add_unchecked - add integer to atomic64 variable
9228 + * @i: integer value to add
9229 + * @v: pointer to type atomic64_unchecked_t
9230 + *
9231 + * Atomically adds @i to @v.
9232 + */
9233 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9234 +{
9235 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9236 + : "+A" (i), "+c" (v)
9237 + : : "memory"
9238 + );
9239 + return i;
9240 +}
9241 +
9242 +/**
9243 * atomic64_sub - subtract the atomic64 variable
9244 * @i: integer value to subtract
9245 * @v: pointer to type atomic64_t
9246 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9247 index 0e1cbfc..5623683 100644
9248 --- a/arch/x86/include/asm/atomic64_64.h
9249 +++ b/arch/x86/include/asm/atomic64_64.h
9250 @@ -18,7 +18,19 @@
9251 */
9252 static inline long atomic64_read(const atomic64_t *v)
9253 {
9254 - return (*(volatile long *)&(v)->counter);
9255 + return (*(volatile const long *)&(v)->counter);
9256 +}
9257 +
9258 +/**
9259 + * atomic64_read_unchecked - read atomic64 variable
9260 + * @v: pointer of type atomic64_unchecked_t
9261 + *
9262 + * Atomically reads the value of @v.
9263 + * Doesn't imply a read memory barrier.
9264 + */
9265 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9266 +{
9267 + return (*(volatile const long *)&(v)->counter);
9268 }
9269
9270 /**
9271 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9272 }
9273
9274 /**
9275 + * atomic64_set_unchecked - set atomic64 variable
9276 + * @v: pointer to type atomic64_unchecked_t
9277 + * @i: required value
9278 + *
9279 + * Atomically sets the value of @v to @i.
9280 + */
9281 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9282 +{
9283 + v->counter = i;
9284 +}
9285 +
9286 +/**
9287 * atomic64_add - add integer to atomic64 variable
9288 * @i: integer value to add
9289 * @v: pointer to type atomic64_t
9290 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9291 */
9292 static inline void atomic64_add(long i, atomic64_t *v)
9293 {
9294 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9295 +
9296 +#ifdef CONFIG_PAX_REFCOUNT
9297 + "jno 0f\n"
9298 + LOCK_PREFIX "subq %1,%0\n"
9299 + "int $4\n0:\n"
9300 + _ASM_EXTABLE(0b, 0b)
9301 +#endif
9302 +
9303 + : "=m" (v->counter)
9304 + : "er" (i), "m" (v->counter));
9305 +}
9306 +
9307 +/**
9308 + * atomic64_add_unchecked - add integer to atomic64 variable
9309 + * @i: integer value to add
9310 + * @v: pointer to type atomic64_unchecked_t
9311 + *
9312 + * Atomically adds @i to @v.
9313 + */
9314 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9315 +{
9316 asm volatile(LOCK_PREFIX "addq %1,%0"
9317 : "=m" (v->counter)
9318 : "er" (i), "m" (v->counter));
9319 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9320 */
9321 static inline void atomic64_sub(long i, atomic64_t *v)
9322 {
9323 - asm volatile(LOCK_PREFIX "subq %1,%0"
9324 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9325 +
9326 +#ifdef CONFIG_PAX_REFCOUNT
9327 + "jno 0f\n"
9328 + LOCK_PREFIX "addq %1,%0\n"
9329 + "int $4\n0:\n"
9330 + _ASM_EXTABLE(0b, 0b)
9331 +#endif
9332 +
9333 + : "=m" (v->counter)
9334 + : "er" (i), "m" (v->counter));
9335 +}
9336 +
9337 +/**
9338 + * atomic64_sub_unchecked - subtract the atomic64 variable
9339 + * @i: integer value to subtract
9340 + * @v: pointer to type atomic64_unchecked_t
9341 + *
9342 + * Atomically subtracts @i from @v.
9343 + */
9344 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9345 +{
9346 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9347 : "=m" (v->counter)
9348 : "er" (i), "m" (v->counter));
9349 }
9350 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9351 {
9352 unsigned char c;
9353
9354 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9355 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9356 +
9357 +#ifdef CONFIG_PAX_REFCOUNT
9358 + "jno 0f\n"
9359 + LOCK_PREFIX "addq %2,%0\n"
9360 + "int $4\n0:\n"
9361 + _ASM_EXTABLE(0b, 0b)
9362 +#endif
9363 +
9364 + "sete %1\n"
9365 : "=m" (v->counter), "=qm" (c)
9366 : "er" (i), "m" (v->counter) : "memory");
9367 return c;
9368 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9369 */
9370 static inline void atomic64_inc(atomic64_t *v)
9371 {
9372 + asm volatile(LOCK_PREFIX "incq %0\n"
9373 +
9374 +#ifdef CONFIG_PAX_REFCOUNT
9375 + "jno 0f\n"
9376 + LOCK_PREFIX "decq %0\n"
9377 + "int $4\n0:\n"
9378 + _ASM_EXTABLE(0b, 0b)
9379 +#endif
9380 +
9381 + : "=m" (v->counter)
9382 + : "m" (v->counter));
9383 +}
9384 +
9385 +/**
9386 + * atomic64_inc_unchecked - increment atomic64 variable
9387 + * @v: pointer to type atomic64_unchecked_t
9388 + *
9389 + * Atomically increments @v by 1.
9390 + */
9391 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9392 +{
9393 asm volatile(LOCK_PREFIX "incq %0"
9394 : "=m" (v->counter)
9395 : "m" (v->counter));
9396 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9397 */
9398 static inline void atomic64_dec(atomic64_t *v)
9399 {
9400 - asm volatile(LOCK_PREFIX "decq %0"
9401 + asm volatile(LOCK_PREFIX "decq %0\n"
9402 +
9403 +#ifdef CONFIG_PAX_REFCOUNT
9404 + "jno 0f\n"
9405 + LOCK_PREFIX "incq %0\n"
9406 + "int $4\n0:\n"
9407 + _ASM_EXTABLE(0b, 0b)
9408 +#endif
9409 +
9410 + : "=m" (v->counter)
9411 + : "m" (v->counter));
9412 +}
9413 +
9414 +/**
9415 + * atomic64_dec_unchecked - decrement atomic64 variable
9416 + * @v: pointer to type atomic64_t
9417 + *
9418 + * Atomically decrements @v by 1.
9419 + */
9420 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9421 +{
9422 + asm volatile(LOCK_PREFIX "decq %0\n"
9423 : "=m" (v->counter)
9424 : "m" (v->counter));
9425 }
9426 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9427 {
9428 unsigned char c;
9429
9430 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9431 + asm volatile(LOCK_PREFIX "decq %0\n"
9432 +
9433 +#ifdef CONFIG_PAX_REFCOUNT
9434 + "jno 0f\n"
9435 + LOCK_PREFIX "incq %0\n"
9436 + "int $4\n0:\n"
9437 + _ASM_EXTABLE(0b, 0b)
9438 +#endif
9439 +
9440 + "sete %1\n"
9441 : "=m" (v->counter), "=qm" (c)
9442 : "m" (v->counter) : "memory");
9443 return c != 0;
9444 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9445 {
9446 unsigned char c;
9447
9448 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9449 + asm volatile(LOCK_PREFIX "incq %0\n"
9450 +
9451 +#ifdef CONFIG_PAX_REFCOUNT
9452 + "jno 0f\n"
9453 + LOCK_PREFIX "decq %0\n"
9454 + "int $4\n0:\n"
9455 + _ASM_EXTABLE(0b, 0b)
9456 +#endif
9457 +
9458 + "sete %1\n"
9459 : "=m" (v->counter), "=qm" (c)
9460 : "m" (v->counter) : "memory");
9461 return c != 0;
9462 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9463 {
9464 unsigned char c;
9465
9466 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9467 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9468 +
9469 +#ifdef CONFIG_PAX_REFCOUNT
9470 + "jno 0f\n"
9471 + LOCK_PREFIX "subq %2,%0\n"
9472 + "int $4\n0:\n"
9473 + _ASM_EXTABLE(0b, 0b)
9474 +#endif
9475 +
9476 + "sets %1\n"
9477 : "=m" (v->counter), "=qm" (c)
9478 : "er" (i), "m" (v->counter) : "memory");
9479 return c;
9480 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9481 */
9482 static inline long atomic64_add_return(long i, atomic64_t *v)
9483 {
9484 + return i + xadd_check_overflow(&v->counter, i);
9485 +}
9486 +
9487 +/**
9488 + * atomic64_add_return_unchecked - add and return
9489 + * @i: integer value to add
9490 + * @v: pointer to type atomic64_unchecked_t
9491 + *
9492 + * Atomically adds @i to @v and returns @i + @v
9493 + */
9494 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9495 +{
9496 return i + xadd(&v->counter, i);
9497 }
9498
9499 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9500 }
9501
9502 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9503 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9504 +{
9505 + return atomic64_add_return_unchecked(1, v);
9506 +}
9507 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9508
9509 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9510 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9511 return cmpxchg(&v->counter, old, new);
9512 }
9513
9514 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9515 +{
9516 + return cmpxchg(&v->counter, old, new);
9517 +}
9518 +
9519 static inline long atomic64_xchg(atomic64_t *v, long new)
9520 {
9521 return xchg(&v->counter, new);
9522 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9523 */
9524 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9525 {
9526 - long c, old;
9527 + long c, old, new;
9528 c = atomic64_read(v);
9529 for (;;) {
9530 - if (unlikely(c == (u)))
9531 + if (unlikely(c == u))
9532 break;
9533 - old = atomic64_cmpxchg((v), c, c + (a));
9534 +
9535 + asm volatile("add %2,%0\n"
9536 +
9537 +#ifdef CONFIG_PAX_REFCOUNT
9538 + "jno 0f\n"
9539 + "sub %2,%0\n"
9540 + "int $4\n0:\n"
9541 + _ASM_EXTABLE(0b, 0b)
9542 +#endif
9543 +
9544 + : "=r" (new)
9545 + : "0" (c), "ir" (a));
9546 +
9547 + old = atomic64_cmpxchg(v, c, new);
9548 if (likely(old == c))
9549 break;
9550 c = old;
9551 }
9552 - return c != (u);
9553 + return c != u;
9554 }
9555
9556 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9557 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9558 index 1775d6e..b65017f 100644
9559 --- a/arch/x86/include/asm/bitops.h
9560 +++ b/arch/x86/include/asm/bitops.h
9561 @@ -38,7 +38,7 @@
9562 * a mask operation on a byte.
9563 */
9564 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9565 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9566 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9567 #define CONST_MASK(nr) (1 << ((nr) & 7))
9568
9569 /**
9570 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9571 index 5e1a2ee..c9f9533 100644
9572 --- a/arch/x86/include/asm/boot.h
9573 +++ b/arch/x86/include/asm/boot.h
9574 @@ -11,10 +11,15 @@
9575 #include <asm/pgtable_types.h>
9576
9577 /* Physical address where kernel should be loaded. */
9578 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9579 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9580 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9581 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9582
9583 +#ifndef __ASSEMBLY__
9584 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9585 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9586 +#endif
9587 +
9588 /* Minimum kernel alignment, as a power of two */
9589 #ifdef CONFIG_X86_64
9590 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9591 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9592 index 48f99f1..d78ebf9 100644
9593 --- a/arch/x86/include/asm/cache.h
9594 +++ b/arch/x86/include/asm/cache.h
9595 @@ -5,12 +5,13 @@
9596
9597 /* L1 cache line size */
9598 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9599 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9600 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9601
9602 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9603 +#define __read_only __attribute__((__section__(".data..read_only")))
9604
9605 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9606 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9607 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9608
9609 #ifdef CONFIG_X86_VSMP
9610 #ifdef CONFIG_SMP
9611 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9612 index 4e12668..501d239 100644
9613 --- a/arch/x86/include/asm/cacheflush.h
9614 +++ b/arch/x86/include/asm/cacheflush.h
9615 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9616 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9617
9618 if (pg_flags == _PGMT_DEFAULT)
9619 - return -1;
9620 + return ~0UL;
9621 else if (pg_flags == _PGMT_WC)
9622 return _PAGE_CACHE_WC;
9623 else if (pg_flags == _PGMT_UC_MINUS)
9624 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9625 index 46fc474..b02b0f9 100644
9626 --- a/arch/x86/include/asm/checksum_32.h
9627 +++ b/arch/x86/include/asm/checksum_32.h
9628 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9629 int len, __wsum sum,
9630 int *src_err_ptr, int *dst_err_ptr);
9631
9632 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9633 + int len, __wsum sum,
9634 + int *src_err_ptr, int *dst_err_ptr);
9635 +
9636 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9637 + int len, __wsum sum,
9638 + int *src_err_ptr, int *dst_err_ptr);
9639 +
9640 /*
9641 * Note: when you get a NULL pointer exception here this means someone
9642 * passed in an incorrect kernel address to one of these functions.
9643 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9644 int *err_ptr)
9645 {
9646 might_sleep();
9647 - return csum_partial_copy_generic((__force void *)src, dst,
9648 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9649 len, sum, err_ptr, NULL);
9650 }
9651
9652 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9653 {
9654 might_sleep();
9655 if (access_ok(VERIFY_WRITE, dst, len))
9656 - return csum_partial_copy_generic(src, (__force void *)dst,
9657 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9658 len, sum, NULL, err_ptr);
9659
9660 if (len)
9661 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9662 index 5d3acdf..6447a02 100644
9663 --- a/arch/x86/include/asm/cmpxchg.h
9664 +++ b/arch/x86/include/asm/cmpxchg.h
9665 @@ -14,6 +14,8 @@ extern void __cmpxchg_wrong_size(void)
9666 __compiletime_error("Bad argument size for cmpxchg");
9667 extern void __xadd_wrong_size(void)
9668 __compiletime_error("Bad argument size for xadd");
9669 +extern void __xadd_check_overflow_wrong_size(void)
9670 + __compiletime_error("Bad argument size for xadd_check_overflow");
9671
9672 /*
9673 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9674 @@ -195,6 +197,34 @@ extern void __xadd_wrong_size(void)
9675 __ret; \
9676 })
9677
9678 +#define __xadd_check_overflow(ptr, inc, lock) \
9679 + ({ \
9680 + __typeof__ (*(ptr)) __ret = (inc); \
9681 + switch (sizeof(*(ptr))) { \
9682 + case __X86_CASE_L: \
9683 + asm volatile (lock "xaddl %0, %1\n" \
9684 + "jno 0f\n" \
9685 + "mov %0,%1\n" \
9686 + "int $4\n0:\n" \
9687 + _ASM_EXTABLE(0b, 0b) \
9688 + : "+r" (__ret), "+m" (*(ptr)) \
9689 + : : "memory", "cc"); \
9690 + break; \
9691 + case __X86_CASE_Q: \
9692 + asm volatile (lock "xaddq %q0, %1\n" \
9693 + "jno 0f\n" \
9694 + "mov %0,%1\n" \
9695 + "int $4\n0:\n" \
9696 + _ASM_EXTABLE(0b, 0b) \
9697 + : "+r" (__ret), "+m" (*(ptr)) \
9698 + : : "memory", "cc"); \
9699 + break; \
9700 + default: \
9701 + __xadd_check_overflow_wrong_size(); \
9702 + } \
9703 + __ret; \
9704 + })
9705 +
9706 /*
9707 * xadd() adds "inc" to "*ptr" and atomically returns the previous
9708 * value of "*ptr".
9709 @@ -207,4 +237,6 @@ extern void __xadd_wrong_size(void)
9710 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9711 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9712
9713 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9714 +
9715 #endif /* ASM_X86_CMPXCHG_H */
9716 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9717 index f3444f7..051a196 100644
9718 --- a/arch/x86/include/asm/cpufeature.h
9719 +++ b/arch/x86/include/asm/cpufeature.h
9720 @@ -363,7 +363,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9721 ".section .discard,\"aw\",@progbits\n"
9722 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9723 ".previous\n"
9724 - ".section .altinstr_replacement,\"ax\"\n"
9725 + ".section .altinstr_replacement,\"a\"\n"
9726 "3: movb $1,%0\n"
9727 "4:\n"
9728 ".previous\n"
9729 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9730 index 41935fa..3b40db8 100644
9731 --- a/arch/x86/include/asm/desc.h
9732 +++ b/arch/x86/include/asm/desc.h
9733 @@ -4,6 +4,7 @@
9734 #include <asm/desc_defs.h>
9735 #include <asm/ldt.h>
9736 #include <asm/mmu.h>
9737 +#include <asm/pgtable.h>
9738
9739 #include <linux/smp.h>
9740
9741 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9742
9743 desc->type = (info->read_exec_only ^ 1) << 1;
9744 desc->type |= info->contents << 2;
9745 + desc->type |= info->seg_not_present ^ 1;
9746
9747 desc->s = 1;
9748 desc->dpl = 0x3;
9749 @@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9750 }
9751
9752 extern struct desc_ptr idt_descr;
9753 -extern gate_desc idt_table[];
9754 -
9755 -struct gdt_page {
9756 - struct desc_struct gdt[GDT_ENTRIES];
9757 -} __attribute__((aligned(PAGE_SIZE)));
9758 -
9759 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9760 +extern gate_desc idt_table[256];
9761
9762 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9763 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9764 {
9765 - return per_cpu(gdt_page, cpu).gdt;
9766 + return cpu_gdt_table[cpu];
9767 }
9768
9769 #ifdef CONFIG_X86_64
9770 @@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9771 unsigned long base, unsigned dpl, unsigned flags,
9772 unsigned short seg)
9773 {
9774 - gate->a = (seg << 16) | (base & 0xffff);
9775 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9776 + gate->gate.offset_low = base;
9777 + gate->gate.seg = seg;
9778 + gate->gate.reserved = 0;
9779 + gate->gate.type = type;
9780 + gate->gate.s = 0;
9781 + gate->gate.dpl = dpl;
9782 + gate->gate.p = 1;
9783 + gate->gate.offset_high = base >> 16;
9784 }
9785
9786 #endif
9787 @@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9788
9789 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9790 {
9791 + pax_open_kernel();
9792 memcpy(&idt[entry], gate, sizeof(*gate));
9793 + pax_close_kernel();
9794 }
9795
9796 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9797 {
9798 + pax_open_kernel();
9799 memcpy(&ldt[entry], desc, 8);
9800 + pax_close_kernel();
9801 }
9802
9803 static inline void
9804 @@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9805 default: size = sizeof(*gdt); break;
9806 }
9807
9808 + pax_open_kernel();
9809 memcpy(&gdt[entry], desc, size);
9810 + pax_close_kernel();
9811 }
9812
9813 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9814 @@ -207,7 +216,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9815
9816 static inline void native_load_tr_desc(void)
9817 {
9818 + pax_open_kernel();
9819 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9820 + pax_close_kernel();
9821 }
9822
9823 static inline void native_load_gdt(const struct desc_ptr *dtr)
9824 @@ -244,8 +255,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9825 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9826 unsigned int i;
9827
9828 + pax_open_kernel();
9829 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9830 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9831 + pax_close_kernel();
9832 }
9833
9834 #define _LDT_empty(info) \
9835 @@ -307,7 +320,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9836 desc->limit = (limit >> 16) & 0xf;
9837 }
9838
9839 -static inline void _set_gate(int gate, unsigned type, void *addr,
9840 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9841 unsigned dpl, unsigned ist, unsigned seg)
9842 {
9843 gate_desc s;
9844 @@ -326,7 +339,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9845 * Pentium F0 0F bugfix can have resulted in the mapped
9846 * IDT being write-protected.
9847 */
9848 -static inline void set_intr_gate(unsigned int n, void *addr)
9849 +static inline void set_intr_gate(unsigned int n, const void *addr)
9850 {
9851 BUG_ON((unsigned)n > 0xFF);
9852 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9853 @@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9854 /*
9855 * This routine sets up an interrupt gate at directory privilege level 3.
9856 */
9857 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9858 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9859 {
9860 BUG_ON((unsigned)n > 0xFF);
9861 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9862 }
9863
9864 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9865 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9866 {
9867 BUG_ON((unsigned)n > 0xFF);
9868 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9869 }
9870
9871 -static inline void set_trap_gate(unsigned int n, void *addr)
9872 +static inline void set_trap_gate(unsigned int n, const void *addr)
9873 {
9874 BUG_ON((unsigned)n > 0xFF);
9875 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9876 @@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9877 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9878 {
9879 BUG_ON((unsigned)n > 0xFF);
9880 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9881 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9882 }
9883
9884 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9885 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9886 {
9887 BUG_ON((unsigned)n > 0xFF);
9888 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9889 }
9890
9891 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9892 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9893 {
9894 BUG_ON((unsigned)n > 0xFF);
9895 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9896 }
9897
9898 +#ifdef CONFIG_X86_32
9899 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9900 +{
9901 + struct desc_struct d;
9902 +
9903 + if (likely(limit))
9904 + limit = (limit - 1UL) >> PAGE_SHIFT;
9905 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9906 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9907 +}
9908 +#endif
9909 +
9910 #endif /* _ASM_X86_DESC_H */
9911 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9912 index 278441f..b95a174 100644
9913 --- a/arch/x86/include/asm/desc_defs.h
9914 +++ b/arch/x86/include/asm/desc_defs.h
9915 @@ -31,6 +31,12 @@ struct desc_struct {
9916 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9917 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9918 };
9919 + struct {
9920 + u16 offset_low;
9921 + u16 seg;
9922 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9923 + unsigned offset_high: 16;
9924 + } gate;
9925 };
9926 } __attribute__((packed));
9927
9928 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9929 index 908b969..a1f4eb4 100644
9930 --- a/arch/x86/include/asm/e820.h
9931 +++ b/arch/x86/include/asm/e820.h
9932 @@ -69,7 +69,7 @@ struct e820map {
9933 #define ISA_START_ADDRESS 0xa0000
9934 #define ISA_END_ADDRESS 0x100000
9935
9936 -#define BIOS_BEGIN 0x000a0000
9937 +#define BIOS_BEGIN 0x000c0000
9938 #define BIOS_END 0x00100000
9939
9940 #define BIOS_ROM_BASE 0xffe00000
9941 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9942 index 5f962df..7289f09 100644
9943 --- a/arch/x86/include/asm/elf.h
9944 +++ b/arch/x86/include/asm/elf.h
9945 @@ -238,7 +238,25 @@ extern int force_personality32;
9946 the loader. We need to make sure that it is out of the way of the program
9947 that it will "exec", and that there is sufficient room for the brk. */
9948
9949 +#ifdef CONFIG_PAX_SEGMEXEC
9950 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9951 +#else
9952 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9953 +#endif
9954 +
9955 +#ifdef CONFIG_PAX_ASLR
9956 +#ifdef CONFIG_X86_32
9957 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9958 +
9959 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9960 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9961 +#else
9962 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9963 +
9964 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9965 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9966 +#endif
9967 +#endif
9968
9969 /* This yields a mask that user programs can use to figure out what
9970 instruction set this CPU supports. This could be done in user space,
9971 @@ -291,9 +309,7 @@ do { \
9972
9973 #define ARCH_DLINFO \
9974 do { \
9975 - if (vdso_enabled) \
9976 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9977 - (unsigned long)current->mm->context.vdso); \
9978 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9979 } while (0)
9980
9981 #define AT_SYSINFO 32
9982 @@ -304,7 +320,7 @@ do { \
9983
9984 #endif /* !CONFIG_X86_32 */
9985
9986 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9987 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9988
9989 #define VDSO_ENTRY \
9990 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9991 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
9992 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9993 #define compat_arch_setup_additional_pages syscall32_setup_pages
9994
9995 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9996 -#define arch_randomize_brk arch_randomize_brk
9997 -
9998 /*
9999 * True on X86_32 or when emulating IA32 on X86_64
10000 */
10001 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10002 index cc70c1c..d96d011 100644
10003 --- a/arch/x86/include/asm/emergency-restart.h
10004 +++ b/arch/x86/include/asm/emergency-restart.h
10005 @@ -15,6 +15,6 @@ enum reboot_type {
10006
10007 extern enum reboot_type reboot_type;
10008
10009 -extern void machine_emergency_restart(void);
10010 +extern void machine_emergency_restart(void) __noreturn;
10011
10012 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10013 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10014 index d09bb03..4ea4194 100644
10015 --- a/arch/x86/include/asm/futex.h
10016 +++ b/arch/x86/include/asm/futex.h
10017 @@ -12,16 +12,18 @@
10018 #include <asm/system.h>
10019
10020 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10021 + typecheck(u32 __user *, uaddr); \
10022 asm volatile("1:\t" insn "\n" \
10023 "2:\t.section .fixup,\"ax\"\n" \
10024 "3:\tmov\t%3, %1\n" \
10025 "\tjmp\t2b\n" \
10026 "\t.previous\n" \
10027 _ASM_EXTABLE(1b, 3b) \
10028 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10029 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10030 : "i" (-EFAULT), "0" (oparg), "1" (0))
10031
10032 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10033 + typecheck(u32 __user *, uaddr); \
10034 asm volatile("1:\tmovl %2, %0\n" \
10035 "\tmovl\t%0, %3\n" \
10036 "\t" insn "\n" \
10037 @@ -34,7 +36,7 @@
10038 _ASM_EXTABLE(1b, 4b) \
10039 _ASM_EXTABLE(2b, 4b) \
10040 : "=&a" (oldval), "=&r" (ret), \
10041 - "+m" (*uaddr), "=&r" (tem) \
10042 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10043 : "r" (oparg), "i" (-EFAULT), "1" (0))
10044
10045 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10046 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10047
10048 switch (op) {
10049 case FUTEX_OP_SET:
10050 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10051 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10052 break;
10053 case FUTEX_OP_ADD:
10054 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10055 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10056 uaddr, oparg);
10057 break;
10058 case FUTEX_OP_OR:
10059 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10060 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10061 return -EFAULT;
10062
10063 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10064 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10065 "2:\t.section .fixup, \"ax\"\n"
10066 "3:\tmov %3, %0\n"
10067 "\tjmp 2b\n"
10068 "\t.previous\n"
10069 _ASM_EXTABLE(1b, 3b)
10070 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10071 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10072 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10073 : "memory"
10074 );
10075 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10076 index eb92a6e..b98b2f4 100644
10077 --- a/arch/x86/include/asm/hw_irq.h
10078 +++ b/arch/x86/include/asm/hw_irq.h
10079 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10080 extern void enable_IO_APIC(void);
10081
10082 /* Statistics */
10083 -extern atomic_t irq_err_count;
10084 -extern atomic_t irq_mis_count;
10085 +extern atomic_unchecked_t irq_err_count;
10086 +extern atomic_unchecked_t irq_mis_count;
10087
10088 /* EISA */
10089 extern void eisa_set_level_irq(unsigned int irq);
10090 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10091 index a850b4d..bae26dc 100644
10092 --- a/arch/x86/include/asm/i387.h
10093 +++ b/arch/x86/include/asm/i387.h
10094 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10095 {
10096 int err;
10097
10098 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10099 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10100 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10101 +#endif
10102 +
10103 /* See comment in fxsave() below. */
10104 #ifdef CONFIG_AS_FXSAVEQ
10105 asm volatile("1: fxrstorq %[fx]\n\t"
10106 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10107 {
10108 int err;
10109
10110 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10111 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10112 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10113 +#endif
10114 +
10115 /*
10116 * Clear the bytes not touched by the fxsave and reserved
10117 * for the SW usage.
10118 @@ -424,7 +434,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10119 static inline bool interrupted_user_mode(void)
10120 {
10121 struct pt_regs *regs = get_irq_regs();
10122 - return regs && user_mode_vm(regs);
10123 + return regs && user_mode(regs);
10124 }
10125
10126 /*
10127 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10128 index d8e8eef..99f81ae 100644
10129 --- a/arch/x86/include/asm/io.h
10130 +++ b/arch/x86/include/asm/io.h
10131 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10132
10133 #include <linux/vmalloc.h>
10134
10135 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10136 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10137 +{
10138 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10139 +}
10140 +
10141 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10142 +{
10143 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10144 +}
10145 +
10146 /*
10147 * Convert a virtual cached pointer to an uncached pointer
10148 */
10149 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10150 index bba3cf8..06bc8da 100644
10151 --- a/arch/x86/include/asm/irqflags.h
10152 +++ b/arch/x86/include/asm/irqflags.h
10153 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10154 sti; \
10155 sysexit
10156
10157 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10158 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10159 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10160 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10161 +
10162 #else
10163 #define INTERRUPT_RETURN iret
10164 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10165 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10166 index 5478825..839e88c 100644
10167 --- a/arch/x86/include/asm/kprobes.h
10168 +++ b/arch/x86/include/asm/kprobes.h
10169 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10170 #define RELATIVEJUMP_SIZE 5
10171 #define RELATIVECALL_OPCODE 0xe8
10172 #define RELATIVE_ADDR_SIZE 4
10173 -#define MAX_STACK_SIZE 64
10174 -#define MIN_STACK_SIZE(ADDR) \
10175 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10176 - THREAD_SIZE - (unsigned long)(ADDR))) \
10177 - ? (MAX_STACK_SIZE) \
10178 - : (((unsigned long)current_thread_info()) + \
10179 - THREAD_SIZE - (unsigned long)(ADDR)))
10180 +#define MAX_STACK_SIZE 64UL
10181 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10182
10183 #define flush_insn_slot(p) do { } while (0)
10184
10185 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10186 index b4973f4..7c4d3fc 100644
10187 --- a/arch/x86/include/asm/kvm_host.h
10188 +++ b/arch/x86/include/asm/kvm_host.h
10189 @@ -459,7 +459,7 @@ struct kvm_arch {
10190 unsigned int n_requested_mmu_pages;
10191 unsigned int n_max_mmu_pages;
10192 unsigned int indirect_shadow_pages;
10193 - atomic_t invlpg_counter;
10194 + atomic_unchecked_t invlpg_counter;
10195 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
10196 /*
10197 * Hash table of struct kvm_mmu_page.
10198 @@ -638,7 +638,7 @@ struct kvm_x86_ops {
10199 int (*check_intercept)(struct kvm_vcpu *vcpu,
10200 struct x86_instruction_info *info,
10201 enum x86_intercept_stage stage);
10202 -};
10203 +} __do_const;
10204
10205 struct kvm_arch_async_pf {
10206 u32 token;
10207 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10208 index 9cdae5d..300d20f 100644
10209 --- a/arch/x86/include/asm/local.h
10210 +++ b/arch/x86/include/asm/local.h
10211 @@ -18,26 +18,58 @@ typedef struct {
10212
10213 static inline void local_inc(local_t *l)
10214 {
10215 - asm volatile(_ASM_INC "%0"
10216 + asm volatile(_ASM_INC "%0\n"
10217 +
10218 +#ifdef CONFIG_PAX_REFCOUNT
10219 + "jno 0f\n"
10220 + _ASM_DEC "%0\n"
10221 + "int $4\n0:\n"
10222 + _ASM_EXTABLE(0b, 0b)
10223 +#endif
10224 +
10225 : "+m" (l->a.counter));
10226 }
10227
10228 static inline void local_dec(local_t *l)
10229 {
10230 - asm volatile(_ASM_DEC "%0"
10231 + asm volatile(_ASM_DEC "%0\n"
10232 +
10233 +#ifdef CONFIG_PAX_REFCOUNT
10234 + "jno 0f\n"
10235 + _ASM_INC "%0\n"
10236 + "int $4\n0:\n"
10237 + _ASM_EXTABLE(0b, 0b)
10238 +#endif
10239 +
10240 : "+m" (l->a.counter));
10241 }
10242
10243 static inline void local_add(long i, local_t *l)
10244 {
10245 - asm volatile(_ASM_ADD "%1,%0"
10246 + asm volatile(_ASM_ADD "%1,%0\n"
10247 +
10248 +#ifdef CONFIG_PAX_REFCOUNT
10249 + "jno 0f\n"
10250 + _ASM_SUB "%1,%0\n"
10251 + "int $4\n0:\n"
10252 + _ASM_EXTABLE(0b, 0b)
10253 +#endif
10254 +
10255 : "+m" (l->a.counter)
10256 : "ir" (i));
10257 }
10258
10259 static inline void local_sub(long i, local_t *l)
10260 {
10261 - asm volatile(_ASM_SUB "%1,%0"
10262 + asm volatile(_ASM_SUB "%1,%0\n"
10263 +
10264 +#ifdef CONFIG_PAX_REFCOUNT
10265 + "jno 0f\n"
10266 + _ASM_ADD "%1,%0\n"
10267 + "int $4\n0:\n"
10268 + _ASM_EXTABLE(0b, 0b)
10269 +#endif
10270 +
10271 : "+m" (l->a.counter)
10272 : "ir" (i));
10273 }
10274 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10275 {
10276 unsigned char c;
10277
10278 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10279 + asm volatile(_ASM_SUB "%2,%0\n"
10280 +
10281 +#ifdef CONFIG_PAX_REFCOUNT
10282 + "jno 0f\n"
10283 + _ASM_ADD "%2,%0\n"
10284 + "int $4\n0:\n"
10285 + _ASM_EXTABLE(0b, 0b)
10286 +#endif
10287 +
10288 + "sete %1\n"
10289 : "+m" (l->a.counter), "=qm" (c)
10290 : "ir" (i) : "memory");
10291 return c;
10292 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10293 {
10294 unsigned char c;
10295
10296 - asm volatile(_ASM_DEC "%0; sete %1"
10297 + asm volatile(_ASM_DEC "%0\n"
10298 +
10299 +#ifdef CONFIG_PAX_REFCOUNT
10300 + "jno 0f\n"
10301 + _ASM_INC "%0\n"
10302 + "int $4\n0:\n"
10303 + _ASM_EXTABLE(0b, 0b)
10304 +#endif
10305 +
10306 + "sete %1\n"
10307 : "+m" (l->a.counter), "=qm" (c)
10308 : : "memory");
10309 return c != 0;
10310 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10311 {
10312 unsigned char c;
10313
10314 - asm volatile(_ASM_INC "%0; sete %1"
10315 + asm volatile(_ASM_INC "%0\n"
10316 +
10317 +#ifdef CONFIG_PAX_REFCOUNT
10318 + "jno 0f\n"
10319 + _ASM_DEC "%0\n"
10320 + "int $4\n0:\n"
10321 + _ASM_EXTABLE(0b, 0b)
10322 +#endif
10323 +
10324 + "sete %1\n"
10325 : "+m" (l->a.counter), "=qm" (c)
10326 : : "memory");
10327 return c != 0;
10328 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10329 {
10330 unsigned char c;
10331
10332 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10333 + asm volatile(_ASM_ADD "%2,%0\n"
10334 +
10335 +#ifdef CONFIG_PAX_REFCOUNT
10336 + "jno 0f\n"
10337 + _ASM_SUB "%2,%0\n"
10338 + "int $4\n0:\n"
10339 + _ASM_EXTABLE(0b, 0b)
10340 +#endif
10341 +
10342 + "sets %1\n"
10343 : "+m" (l->a.counter), "=qm" (c)
10344 : "ir" (i) : "memory");
10345 return c;
10346 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10347 #endif
10348 /* Modern 486+ processor */
10349 __i = i;
10350 - asm volatile(_ASM_XADD "%0, %1;"
10351 + asm volatile(_ASM_XADD "%0, %1\n"
10352 +
10353 +#ifdef CONFIG_PAX_REFCOUNT
10354 + "jno 0f\n"
10355 + _ASM_MOV "%0,%1\n"
10356 + "int $4\n0:\n"
10357 + _ASM_EXTABLE(0b, 0b)
10358 +#endif
10359 +
10360 : "+r" (i), "+m" (l->a.counter)
10361 : : "memory");
10362 return i + __i;
10363 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10364 index 593e51d..fa69c9a 100644
10365 --- a/arch/x86/include/asm/mman.h
10366 +++ b/arch/x86/include/asm/mman.h
10367 @@ -5,4 +5,14 @@
10368
10369 #include <asm-generic/mman.h>
10370
10371 +#ifdef __KERNEL__
10372 +#ifndef __ASSEMBLY__
10373 +#ifdef CONFIG_X86_32
10374 +#define arch_mmap_check i386_mmap_check
10375 +int i386_mmap_check(unsigned long addr, unsigned long len,
10376 + unsigned long flags);
10377 +#endif
10378 +#endif
10379 +#endif
10380 +
10381 #endif /* _ASM_X86_MMAN_H */
10382 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10383 index 5f55e69..e20bfb1 100644
10384 --- a/arch/x86/include/asm/mmu.h
10385 +++ b/arch/x86/include/asm/mmu.h
10386 @@ -9,7 +9,7 @@
10387 * we put the segment information here.
10388 */
10389 typedef struct {
10390 - void *ldt;
10391 + struct desc_struct *ldt;
10392 int size;
10393
10394 #ifdef CONFIG_X86_64
10395 @@ -18,7 +18,19 @@ typedef struct {
10396 #endif
10397
10398 struct mutex lock;
10399 - void *vdso;
10400 + unsigned long vdso;
10401 +
10402 +#ifdef CONFIG_X86_32
10403 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10404 + unsigned long user_cs_base;
10405 + unsigned long user_cs_limit;
10406 +
10407 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10408 + cpumask_t cpu_user_cs_mask;
10409 +#endif
10410 +
10411 +#endif
10412 +#endif
10413 } mm_context_t;
10414
10415 #ifdef CONFIG_SMP
10416 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10417 index 6902152..399f3a2 100644
10418 --- a/arch/x86/include/asm/mmu_context.h
10419 +++ b/arch/x86/include/asm/mmu_context.h
10420 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10421
10422 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10423 {
10424 +
10425 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10426 + unsigned int i;
10427 + pgd_t *pgd;
10428 +
10429 + pax_open_kernel();
10430 + pgd = get_cpu_pgd(smp_processor_id());
10431 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10432 + set_pgd_batched(pgd+i, native_make_pgd(0));
10433 + pax_close_kernel();
10434 +#endif
10435 +
10436 #ifdef CONFIG_SMP
10437 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10438 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10439 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10440 struct task_struct *tsk)
10441 {
10442 unsigned cpu = smp_processor_id();
10443 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10444 + int tlbstate = TLBSTATE_OK;
10445 +#endif
10446
10447 if (likely(prev != next)) {
10448 #ifdef CONFIG_SMP
10449 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10450 + tlbstate = percpu_read(cpu_tlbstate.state);
10451 +#endif
10452 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10453 percpu_write(cpu_tlbstate.active_mm, next);
10454 #endif
10455 cpumask_set_cpu(cpu, mm_cpumask(next));
10456
10457 /* Re-load page tables */
10458 +#ifdef CONFIG_PAX_PER_CPU_PGD
10459 + pax_open_kernel();
10460 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10461 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10462 + pax_close_kernel();
10463 + load_cr3(get_cpu_pgd(cpu));
10464 +#else
10465 load_cr3(next->pgd);
10466 +#endif
10467
10468 /* stop flush ipis for the previous mm */
10469 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10470 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10471 */
10472 if (unlikely(prev->context.ldt != next->context.ldt))
10473 load_LDT_nolock(&next->context);
10474 - }
10475 +
10476 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10477 + if (!(__supported_pte_mask & _PAGE_NX)) {
10478 + smp_mb__before_clear_bit();
10479 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10480 + smp_mb__after_clear_bit();
10481 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10482 + }
10483 +#endif
10484 +
10485 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10486 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10487 + prev->context.user_cs_limit != next->context.user_cs_limit))
10488 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10489 #ifdef CONFIG_SMP
10490 + else if (unlikely(tlbstate != TLBSTATE_OK))
10491 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10492 +#endif
10493 +#endif
10494 +
10495 + }
10496 else {
10497 +
10498 +#ifdef CONFIG_PAX_PER_CPU_PGD
10499 + pax_open_kernel();
10500 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10501 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10502 + pax_close_kernel();
10503 + load_cr3(get_cpu_pgd(cpu));
10504 +#endif
10505 +
10506 +#ifdef CONFIG_SMP
10507 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10508 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10509
10510 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10511 * tlb flush IPI delivery. We must reload CR3
10512 * to make sure to use no freed page tables.
10513 */
10514 +
10515 +#ifndef CONFIG_PAX_PER_CPU_PGD
10516 load_cr3(next->pgd);
10517 +#endif
10518 +
10519 load_LDT_nolock(&next->context);
10520 +
10521 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10522 + if (!(__supported_pte_mask & _PAGE_NX))
10523 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10524 +#endif
10525 +
10526 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10527 +#ifdef CONFIG_PAX_PAGEEXEC
10528 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10529 +#endif
10530 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10531 +#endif
10532 +
10533 }
10534 +#endif
10535 }
10536 -#endif
10537 }
10538
10539 #define activate_mm(prev, next) \
10540 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10541 index 9eae775..c914fea 100644
10542 --- a/arch/x86/include/asm/module.h
10543 +++ b/arch/x86/include/asm/module.h
10544 @@ -5,6 +5,7 @@
10545
10546 #ifdef CONFIG_X86_64
10547 /* X86_64 does not define MODULE_PROC_FAMILY */
10548 +#define MODULE_PROC_FAMILY ""
10549 #elif defined CONFIG_M386
10550 #define MODULE_PROC_FAMILY "386 "
10551 #elif defined CONFIG_M486
10552 @@ -59,8 +60,20 @@
10553 #error unknown processor family
10554 #endif
10555
10556 -#ifdef CONFIG_X86_32
10557 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10558 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10559 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10560 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10561 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10562 +#else
10563 +#define MODULE_PAX_KERNEXEC ""
10564 #endif
10565
10566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10567 +#define MODULE_PAX_UDEREF "UDEREF "
10568 +#else
10569 +#define MODULE_PAX_UDEREF ""
10570 +#endif
10571 +
10572 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10573 +
10574 #endif /* _ASM_X86_MODULE_H */
10575 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10576 index 7639dbf..e08a58c 100644
10577 --- a/arch/x86/include/asm/page_64_types.h
10578 +++ b/arch/x86/include/asm/page_64_types.h
10579 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10580
10581 /* duplicated to the one in bootmem.h */
10582 extern unsigned long max_pfn;
10583 -extern unsigned long phys_base;
10584 +extern const unsigned long phys_base;
10585
10586 extern unsigned long __phys_addr(unsigned long);
10587 #define __phys_reloc_hide(x) (x)
10588 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10589 index a7d2db9..edb023e 100644
10590 --- a/arch/x86/include/asm/paravirt.h
10591 +++ b/arch/x86/include/asm/paravirt.h
10592 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10593 val);
10594 }
10595
10596 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10597 +{
10598 + pgdval_t val = native_pgd_val(pgd);
10599 +
10600 + if (sizeof(pgdval_t) > sizeof(long))
10601 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10602 + val, (u64)val >> 32);
10603 + else
10604 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10605 + val);
10606 +}
10607 +
10608 static inline void pgd_clear(pgd_t *pgdp)
10609 {
10610 set_pgd(pgdp, __pgd(0));
10611 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10612 pv_mmu_ops.set_fixmap(idx, phys, flags);
10613 }
10614
10615 +#ifdef CONFIG_PAX_KERNEXEC
10616 +static inline unsigned long pax_open_kernel(void)
10617 +{
10618 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10619 +}
10620 +
10621 +static inline unsigned long pax_close_kernel(void)
10622 +{
10623 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10624 +}
10625 +#else
10626 +static inline unsigned long pax_open_kernel(void) { return 0; }
10627 +static inline unsigned long pax_close_kernel(void) { return 0; }
10628 +#endif
10629 +
10630 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10631
10632 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10633 @@ -964,7 +991,7 @@ extern void default_banner(void);
10634
10635 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10636 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10637 -#define PARA_INDIRECT(addr) *%cs:addr
10638 +#define PARA_INDIRECT(addr) *%ss:addr
10639 #endif
10640
10641 #define INTERRUPT_RETURN \
10642 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10643 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10644 CLBR_NONE, \
10645 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10646 +
10647 +#define GET_CR0_INTO_RDI \
10648 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10649 + mov %rax,%rdi
10650 +
10651 +#define SET_RDI_INTO_CR0 \
10652 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10653 +
10654 +#define GET_CR3_INTO_RDI \
10655 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10656 + mov %rax,%rdi
10657 +
10658 +#define SET_RDI_INTO_CR3 \
10659 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10660 +
10661 #endif /* CONFIG_X86_32 */
10662
10663 #endif /* __ASSEMBLY__ */
10664 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10665 index 8e8b9a4..f07d725 100644
10666 --- a/arch/x86/include/asm/paravirt_types.h
10667 +++ b/arch/x86/include/asm/paravirt_types.h
10668 @@ -84,20 +84,20 @@ struct pv_init_ops {
10669 */
10670 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10671 unsigned long addr, unsigned len);
10672 -};
10673 +} __no_const;
10674
10675
10676 struct pv_lazy_ops {
10677 /* Set deferred update mode, used for batching operations. */
10678 void (*enter)(void);
10679 void (*leave)(void);
10680 -};
10681 +} __no_const;
10682
10683 struct pv_time_ops {
10684 unsigned long long (*sched_clock)(void);
10685 unsigned long long (*steal_clock)(int cpu);
10686 unsigned long (*get_tsc_khz)(void);
10687 -};
10688 +} __no_const;
10689
10690 struct pv_cpu_ops {
10691 /* hooks for various privileged instructions */
10692 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10693
10694 void (*start_context_switch)(struct task_struct *prev);
10695 void (*end_context_switch)(struct task_struct *next);
10696 -};
10697 +} __no_const;
10698
10699 struct pv_irq_ops {
10700 /*
10701 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10702 unsigned long start_eip,
10703 unsigned long start_esp);
10704 #endif
10705 -};
10706 +} __no_const;
10707
10708 struct pv_mmu_ops {
10709 unsigned long (*read_cr2)(void);
10710 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10711 struct paravirt_callee_save make_pud;
10712
10713 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10714 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10715 #endif /* PAGETABLE_LEVELS == 4 */
10716 #endif /* PAGETABLE_LEVELS >= 3 */
10717
10718 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10719 an mfn. We can tell which is which from the index. */
10720 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10721 phys_addr_t phys, pgprot_t flags);
10722 +
10723 +#ifdef CONFIG_PAX_KERNEXEC
10724 + unsigned long (*pax_open_kernel)(void);
10725 + unsigned long (*pax_close_kernel)(void);
10726 +#endif
10727 +
10728 };
10729
10730 struct arch_spinlock;
10731 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10732 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10733 int (*spin_trylock)(struct arch_spinlock *lock);
10734 void (*spin_unlock)(struct arch_spinlock *lock);
10735 -};
10736 +} __no_const;
10737
10738 /* This contains all the paravirt structures: we get a convenient
10739 * number for each function using the offset which we use to indicate
10740 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10741 index b4389a4..b7ff22c 100644
10742 --- a/arch/x86/include/asm/pgalloc.h
10743 +++ b/arch/x86/include/asm/pgalloc.h
10744 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10745 pmd_t *pmd, pte_t *pte)
10746 {
10747 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10748 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10749 +}
10750 +
10751 +static inline void pmd_populate_user(struct mm_struct *mm,
10752 + pmd_t *pmd, pte_t *pte)
10753 +{
10754 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10755 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10756 }
10757
10758 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10759 index 98391db..8f6984e 100644
10760 --- a/arch/x86/include/asm/pgtable-2level.h
10761 +++ b/arch/x86/include/asm/pgtable-2level.h
10762 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10763
10764 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10765 {
10766 + pax_open_kernel();
10767 *pmdp = pmd;
10768 + pax_close_kernel();
10769 }
10770
10771 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10772 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10773 index effff47..f9e4035 100644
10774 --- a/arch/x86/include/asm/pgtable-3level.h
10775 +++ b/arch/x86/include/asm/pgtable-3level.h
10776 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10777
10778 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10779 {
10780 + pax_open_kernel();
10781 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10782 + pax_close_kernel();
10783 }
10784
10785 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10786 {
10787 + pax_open_kernel();
10788 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10789 + pax_close_kernel();
10790 }
10791
10792 /*
10793 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10794 index 18601c8..3d716d1 100644
10795 --- a/arch/x86/include/asm/pgtable.h
10796 +++ b/arch/x86/include/asm/pgtable.h
10797 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10798
10799 #ifndef __PAGETABLE_PUD_FOLDED
10800 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10801 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10802 #define pgd_clear(pgd) native_pgd_clear(pgd)
10803 #endif
10804
10805 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10806
10807 #define arch_end_context_switch(prev) do {} while(0)
10808
10809 +#define pax_open_kernel() native_pax_open_kernel()
10810 +#define pax_close_kernel() native_pax_close_kernel()
10811 #endif /* CONFIG_PARAVIRT */
10812
10813 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10814 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10815 +
10816 +#ifdef CONFIG_PAX_KERNEXEC
10817 +static inline unsigned long native_pax_open_kernel(void)
10818 +{
10819 + unsigned long cr0;
10820 +
10821 + preempt_disable();
10822 + barrier();
10823 + cr0 = read_cr0() ^ X86_CR0_WP;
10824 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10825 + write_cr0(cr0);
10826 + return cr0 ^ X86_CR0_WP;
10827 +}
10828 +
10829 +static inline unsigned long native_pax_close_kernel(void)
10830 +{
10831 + unsigned long cr0;
10832 +
10833 + cr0 = read_cr0() ^ X86_CR0_WP;
10834 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10835 + write_cr0(cr0);
10836 + barrier();
10837 + preempt_enable_no_resched();
10838 + return cr0 ^ X86_CR0_WP;
10839 +}
10840 +#else
10841 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10842 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10843 +#endif
10844 +
10845 /*
10846 * The following only work if pte_present() is true.
10847 * Undefined behaviour if not..
10848 */
10849 +static inline int pte_user(pte_t pte)
10850 +{
10851 + return pte_val(pte) & _PAGE_USER;
10852 +}
10853 +
10854 static inline int pte_dirty(pte_t pte)
10855 {
10856 return pte_flags(pte) & _PAGE_DIRTY;
10857 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10858 return pte_clear_flags(pte, _PAGE_RW);
10859 }
10860
10861 +static inline pte_t pte_mkread(pte_t pte)
10862 +{
10863 + return __pte(pte_val(pte) | _PAGE_USER);
10864 +}
10865 +
10866 static inline pte_t pte_mkexec(pte_t pte)
10867 {
10868 - return pte_clear_flags(pte, _PAGE_NX);
10869 +#ifdef CONFIG_X86_PAE
10870 + if (__supported_pte_mask & _PAGE_NX)
10871 + return pte_clear_flags(pte, _PAGE_NX);
10872 + else
10873 +#endif
10874 + return pte_set_flags(pte, _PAGE_USER);
10875 +}
10876 +
10877 +static inline pte_t pte_exprotect(pte_t pte)
10878 +{
10879 +#ifdef CONFIG_X86_PAE
10880 + if (__supported_pte_mask & _PAGE_NX)
10881 + return pte_set_flags(pte, _PAGE_NX);
10882 + else
10883 +#endif
10884 + return pte_clear_flags(pte, _PAGE_USER);
10885 }
10886
10887 static inline pte_t pte_mkdirty(pte_t pte)
10888 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10889 #endif
10890
10891 #ifndef __ASSEMBLY__
10892 +
10893 +#ifdef CONFIG_PAX_PER_CPU_PGD
10894 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10895 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10896 +{
10897 + return cpu_pgd[cpu];
10898 +}
10899 +#endif
10900 +
10901 #include <linux/mm_types.h>
10902
10903 static inline int pte_none(pte_t pte)
10904 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10905
10906 static inline int pgd_bad(pgd_t pgd)
10907 {
10908 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10909 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10910 }
10911
10912 static inline int pgd_none(pgd_t pgd)
10913 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10914 * pgd_offset() returns a (pgd_t *)
10915 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10916 */
10917 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10918 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10919 +
10920 +#ifdef CONFIG_PAX_PER_CPU_PGD
10921 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10922 +#endif
10923 +
10924 /*
10925 * a shortcut which implies the use of the kernel's pgd, instead
10926 * of a process's
10927 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10928 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10929 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10930
10931 +#ifdef CONFIG_X86_32
10932 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10933 +#else
10934 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10935 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10936 +
10937 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10938 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10939 +#else
10940 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10941 +#endif
10942 +
10943 +#endif
10944 +
10945 #ifndef __ASSEMBLY__
10946
10947 extern int direct_gbpages;
10948 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
10949 * dst and src can be on the same page, but the range must not overlap,
10950 * and must not cross a page boundary.
10951 */
10952 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10953 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10954 {
10955 - memcpy(dst, src, count * sizeof(pgd_t));
10956 + pax_open_kernel();
10957 + while (count--)
10958 + *dst++ = *src++;
10959 + pax_close_kernel();
10960 }
10961
10962 +#ifdef CONFIG_PAX_PER_CPU_PGD
10963 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10964 +#endif
10965 +
10966 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10967 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10968 +#else
10969 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10970 +#endif
10971
10972 #include <asm-generic/pgtable.h>
10973 #endif /* __ASSEMBLY__ */
10974 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
10975 index 0c92113..34a77c6 100644
10976 --- a/arch/x86/include/asm/pgtable_32.h
10977 +++ b/arch/x86/include/asm/pgtable_32.h
10978 @@ -25,9 +25,6 @@
10979 struct mm_struct;
10980 struct vm_area_struct;
10981
10982 -extern pgd_t swapper_pg_dir[1024];
10983 -extern pgd_t initial_page_table[1024];
10984 -
10985 static inline void pgtable_cache_init(void) { }
10986 static inline void check_pgt_cache(void) { }
10987 void paging_init(void);
10988 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
10989 # include <asm/pgtable-2level.h>
10990 #endif
10991
10992 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10993 +extern pgd_t initial_page_table[PTRS_PER_PGD];
10994 +#ifdef CONFIG_X86_PAE
10995 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10996 +#endif
10997 +
10998 #if defined(CONFIG_HIGHPTE)
10999 #define pte_offset_map(dir, address) \
11000 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11001 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11002 /* Clear a kernel PTE and flush it from the TLB */
11003 #define kpte_clear_flush(ptep, vaddr) \
11004 do { \
11005 + pax_open_kernel(); \
11006 pte_clear(&init_mm, (vaddr), (ptep)); \
11007 + pax_close_kernel(); \
11008 __flush_tlb_one((vaddr)); \
11009 } while (0)
11010
11011 @@ -74,6 +79,9 @@ do { \
11012
11013 #endif /* !__ASSEMBLY__ */
11014
11015 +#define HAVE_ARCH_UNMAPPED_AREA
11016 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11017 +
11018 /*
11019 * kern_addr_valid() is (1) for FLATMEM and (0) for
11020 * SPARSEMEM and DISCONTIGMEM
11021 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11022 index ed5903b..c7fe163 100644
11023 --- a/arch/x86/include/asm/pgtable_32_types.h
11024 +++ b/arch/x86/include/asm/pgtable_32_types.h
11025 @@ -8,7 +8,7 @@
11026 */
11027 #ifdef CONFIG_X86_PAE
11028 # include <asm/pgtable-3level_types.h>
11029 -# define PMD_SIZE (1UL << PMD_SHIFT)
11030 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11031 # define PMD_MASK (~(PMD_SIZE - 1))
11032 #else
11033 # include <asm/pgtable-2level_types.h>
11034 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11035 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11036 #endif
11037
11038 +#ifdef CONFIG_PAX_KERNEXEC
11039 +#ifndef __ASSEMBLY__
11040 +extern unsigned char MODULES_EXEC_VADDR[];
11041 +extern unsigned char MODULES_EXEC_END[];
11042 +#endif
11043 +#include <asm/boot.h>
11044 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11045 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11046 +#else
11047 +#define ktla_ktva(addr) (addr)
11048 +#define ktva_ktla(addr) (addr)
11049 +#endif
11050 +
11051 #define MODULES_VADDR VMALLOC_START
11052 #define MODULES_END VMALLOC_END
11053 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11054 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11055 index 975f709..107976d 100644
11056 --- a/arch/x86/include/asm/pgtable_64.h
11057 +++ b/arch/x86/include/asm/pgtable_64.h
11058 @@ -16,10 +16,14 @@
11059
11060 extern pud_t level3_kernel_pgt[512];
11061 extern pud_t level3_ident_pgt[512];
11062 +extern pud_t level3_vmalloc_start_pgt[512];
11063 +extern pud_t level3_vmalloc_end_pgt[512];
11064 +extern pud_t level3_vmemmap_pgt[512];
11065 +extern pud_t level2_vmemmap_pgt[512];
11066 extern pmd_t level2_kernel_pgt[512];
11067 extern pmd_t level2_fixmap_pgt[512];
11068 -extern pmd_t level2_ident_pgt[512];
11069 -extern pgd_t init_level4_pgt[];
11070 +extern pmd_t level2_ident_pgt[512*2];
11071 +extern pgd_t init_level4_pgt[512];
11072
11073 #define swapper_pg_dir init_level4_pgt
11074
11075 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11076
11077 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11078 {
11079 + pax_open_kernel();
11080 *pmdp = pmd;
11081 + pax_close_kernel();
11082 }
11083
11084 static inline void native_pmd_clear(pmd_t *pmd)
11085 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11086
11087 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11088 {
11089 + pax_open_kernel();
11090 + *pgdp = pgd;
11091 + pax_close_kernel();
11092 +}
11093 +
11094 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11095 +{
11096 *pgdp = pgd;
11097 }
11098
11099 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11100 index 766ea16..5b96cb3 100644
11101 --- a/arch/x86/include/asm/pgtable_64_types.h
11102 +++ b/arch/x86/include/asm/pgtable_64_types.h
11103 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11104 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11105 #define MODULES_END _AC(0xffffffffff000000, UL)
11106 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11107 +#define MODULES_EXEC_VADDR MODULES_VADDR
11108 +#define MODULES_EXEC_END MODULES_END
11109 +
11110 +#define ktla_ktva(addr) (addr)
11111 +#define ktva_ktla(addr) (addr)
11112
11113 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11114 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11115 index 013286a..8b42f4f 100644
11116 --- a/arch/x86/include/asm/pgtable_types.h
11117 +++ b/arch/x86/include/asm/pgtable_types.h
11118 @@ -16,13 +16,12 @@
11119 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11120 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11121 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11122 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11123 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11124 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11125 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11126 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11127 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11128 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11129 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11130 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11131 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11132 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11133
11134 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11135 @@ -40,7 +39,6 @@
11136 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11137 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11138 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11139 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11140 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11141 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11142 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11143 @@ -57,8 +55,10 @@
11144
11145 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11146 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11147 -#else
11148 +#elif defined(CONFIG_KMEMCHECK)
11149 #define _PAGE_NX (_AT(pteval_t, 0))
11150 +#else
11151 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11152 #endif
11153
11154 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11155 @@ -96,6 +96,9 @@
11156 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11157 _PAGE_ACCESSED)
11158
11159 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11160 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11161 +
11162 #define __PAGE_KERNEL_EXEC \
11163 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11164 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11165 @@ -106,7 +109,7 @@
11166 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11167 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11168 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11169 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11170 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11171 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11172 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11173 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11174 @@ -168,8 +171,8 @@
11175 * bits are combined, this will alow user to access the high address mapped
11176 * VDSO in the presence of CONFIG_COMPAT_VDSO
11177 */
11178 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11179 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11180 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11181 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11182 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11183 #endif
11184
11185 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11186 {
11187 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11188 }
11189 +#endif
11190
11191 +#if PAGETABLE_LEVELS == 3
11192 +#include <asm-generic/pgtable-nopud.h>
11193 +#endif
11194 +
11195 +#if PAGETABLE_LEVELS == 2
11196 +#include <asm-generic/pgtable-nopmd.h>
11197 +#endif
11198 +
11199 +#ifndef __ASSEMBLY__
11200 #if PAGETABLE_LEVELS > 3
11201 typedef struct { pudval_t pud; } pud_t;
11202
11203 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11204 return pud.pud;
11205 }
11206 #else
11207 -#include <asm-generic/pgtable-nopud.h>
11208 -
11209 static inline pudval_t native_pud_val(pud_t pud)
11210 {
11211 return native_pgd_val(pud.pgd);
11212 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11213 return pmd.pmd;
11214 }
11215 #else
11216 -#include <asm-generic/pgtable-nopmd.h>
11217 -
11218 static inline pmdval_t native_pmd_val(pmd_t pmd)
11219 {
11220 return native_pgd_val(pmd.pud.pgd);
11221 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11222
11223 extern pteval_t __supported_pte_mask;
11224 extern void set_nx(void);
11225 -extern int nx_enabled;
11226
11227 #define pgprot_writecombine pgprot_writecombine
11228 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11229 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11230 index bb3ee36..781a6b8 100644
11231 --- a/arch/x86/include/asm/processor.h
11232 +++ b/arch/x86/include/asm/processor.h
11233 @@ -268,7 +268,7 @@ struct tss_struct {
11234
11235 } ____cacheline_aligned;
11236
11237 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11238 +extern struct tss_struct init_tss[NR_CPUS];
11239
11240 /*
11241 * Save the original ist values for checking stack pointers during debugging
11242 @@ -861,11 +861,18 @@ static inline void spin_lock_prefetch(const void *x)
11243 */
11244 #define TASK_SIZE PAGE_OFFSET
11245 #define TASK_SIZE_MAX TASK_SIZE
11246 +
11247 +#ifdef CONFIG_PAX_SEGMEXEC
11248 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11249 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11250 +#else
11251 #define STACK_TOP TASK_SIZE
11252 -#define STACK_TOP_MAX STACK_TOP
11253 +#endif
11254 +
11255 +#define STACK_TOP_MAX TASK_SIZE
11256
11257 #define INIT_THREAD { \
11258 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11259 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11260 .vm86_info = NULL, \
11261 .sysenter_cs = __KERNEL_CS, \
11262 .io_bitmap_ptr = NULL, \
11263 @@ -879,7 +886,7 @@ static inline void spin_lock_prefetch(const void *x)
11264 */
11265 #define INIT_TSS { \
11266 .x86_tss = { \
11267 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11268 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11269 .ss0 = __KERNEL_DS, \
11270 .ss1 = __KERNEL_CS, \
11271 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11272 @@ -890,11 +897,7 @@ static inline void spin_lock_prefetch(const void *x)
11273 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11274
11275 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11276 -#define KSTK_TOP(info) \
11277 -({ \
11278 - unsigned long *__ptr = (unsigned long *)(info); \
11279 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11280 -})
11281 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11282
11283 /*
11284 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11285 @@ -909,7 +912,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11286 #define task_pt_regs(task) \
11287 ({ \
11288 struct pt_regs *__regs__; \
11289 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11290 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11291 __regs__ - 1; \
11292 })
11293
11294 @@ -919,13 +922,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11295 /*
11296 * User space process size. 47bits minus one guard page.
11297 */
11298 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11299 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11300
11301 /* This decides where the kernel will search for a free chunk of vm
11302 * space during mmap's.
11303 */
11304 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11305 - 0xc0000000 : 0xFFFFe000)
11306 + 0xc0000000 : 0xFFFFf000)
11307
11308 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11309 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11310 @@ -936,11 +939,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11311 #define STACK_TOP_MAX TASK_SIZE_MAX
11312
11313 #define INIT_THREAD { \
11314 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11315 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11316 }
11317
11318 #define INIT_TSS { \
11319 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11320 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11321 }
11322
11323 /*
11324 @@ -962,6 +965,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11325 */
11326 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11327
11328 +#ifdef CONFIG_PAX_SEGMEXEC
11329 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11330 +#endif
11331 +
11332 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11333
11334 /* Get/set a process' ability to use the timestamp counter instruction */
11335 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11336 index 3566454..4bdfb8c 100644
11337 --- a/arch/x86/include/asm/ptrace.h
11338 +++ b/arch/x86/include/asm/ptrace.h
11339 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11340 }
11341
11342 /*
11343 - * user_mode_vm(regs) determines whether a register set came from user mode.
11344 + * user_mode(regs) determines whether a register set came from user mode.
11345 * This is true if V8086 mode was enabled OR if the register set was from
11346 * protected mode with RPL-3 CS value. This tricky test checks that with
11347 * one comparison. Many places in the kernel can bypass this full check
11348 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11349 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11350 + * be used.
11351 */
11352 -static inline int user_mode(struct pt_regs *regs)
11353 +static inline int user_mode_novm(struct pt_regs *regs)
11354 {
11355 #ifdef CONFIG_X86_32
11356 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11357 #else
11358 - return !!(regs->cs & 3);
11359 + return !!(regs->cs & SEGMENT_RPL_MASK);
11360 #endif
11361 }
11362
11363 -static inline int user_mode_vm(struct pt_regs *regs)
11364 +static inline int user_mode(struct pt_regs *regs)
11365 {
11366 #ifdef CONFIG_X86_32
11367 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11368 USER_RPL;
11369 #else
11370 - return user_mode(regs);
11371 + return user_mode_novm(regs);
11372 #endif
11373 }
11374
11375 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11376 #ifdef CONFIG_X86_64
11377 static inline bool user_64bit_mode(struct pt_regs *regs)
11378 {
11379 + unsigned long cs = regs->cs & 0xffff;
11380 #ifndef CONFIG_PARAVIRT
11381 /*
11382 * On non-paravirt systems, this is the only long mode CPL 3
11383 * selector. We do not allow long mode selectors in the LDT.
11384 */
11385 - return regs->cs == __USER_CS;
11386 + return cs == __USER_CS;
11387 #else
11388 /* Headers are too twisted for this to go in paravirt.h. */
11389 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11390 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11391 #endif
11392 }
11393 #endif
11394 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11395 index 92f29706..a79cbbb 100644
11396 --- a/arch/x86/include/asm/reboot.h
11397 +++ b/arch/x86/include/asm/reboot.h
11398 @@ -6,19 +6,19 @@
11399 struct pt_regs;
11400
11401 struct machine_ops {
11402 - void (*restart)(char *cmd);
11403 - void (*halt)(void);
11404 - void (*power_off)(void);
11405 + void (* __noreturn restart)(char *cmd);
11406 + void (* __noreturn halt)(void);
11407 + void (* __noreturn power_off)(void);
11408 void (*shutdown)(void);
11409 void (*crash_shutdown)(struct pt_regs *);
11410 - void (*emergency_restart)(void);
11411 -};
11412 + void (* __noreturn emergency_restart)(void);
11413 +} __no_const;
11414
11415 extern struct machine_ops machine_ops;
11416
11417 void native_machine_crash_shutdown(struct pt_regs *regs);
11418 void native_machine_shutdown(void);
11419 -void machine_real_restart(unsigned int type);
11420 +void machine_real_restart(unsigned int type) __noreturn;
11421 /* These must match dispatch_table in reboot_32.S */
11422 #define MRR_BIOS 0
11423 #define MRR_APM 1
11424 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11425 index 2dbe4a7..ce1db00 100644
11426 --- a/arch/x86/include/asm/rwsem.h
11427 +++ b/arch/x86/include/asm/rwsem.h
11428 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11429 {
11430 asm volatile("# beginning down_read\n\t"
11431 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11432 +
11433 +#ifdef CONFIG_PAX_REFCOUNT
11434 + "jno 0f\n"
11435 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11436 + "int $4\n0:\n"
11437 + _ASM_EXTABLE(0b, 0b)
11438 +#endif
11439 +
11440 /* adds 0x00000001 */
11441 " jns 1f\n"
11442 " call call_rwsem_down_read_failed\n"
11443 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11444 "1:\n\t"
11445 " mov %1,%2\n\t"
11446 " add %3,%2\n\t"
11447 +
11448 +#ifdef CONFIG_PAX_REFCOUNT
11449 + "jno 0f\n"
11450 + "sub %3,%2\n"
11451 + "int $4\n0:\n"
11452 + _ASM_EXTABLE(0b, 0b)
11453 +#endif
11454 +
11455 " jle 2f\n\t"
11456 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11457 " jnz 1b\n\t"
11458 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11459 long tmp;
11460 asm volatile("# beginning down_write\n\t"
11461 LOCK_PREFIX " xadd %1,(%2)\n\t"
11462 +
11463 +#ifdef CONFIG_PAX_REFCOUNT
11464 + "jno 0f\n"
11465 + "mov %1,(%2)\n"
11466 + "int $4\n0:\n"
11467 + _ASM_EXTABLE(0b, 0b)
11468 +#endif
11469 +
11470 /* adds 0xffff0001, returns the old value */
11471 " test %1,%1\n\t"
11472 /* was the count 0 before? */
11473 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11474 long tmp;
11475 asm volatile("# beginning __up_read\n\t"
11476 LOCK_PREFIX " xadd %1,(%2)\n\t"
11477 +
11478 +#ifdef CONFIG_PAX_REFCOUNT
11479 + "jno 0f\n"
11480 + "mov %1,(%2)\n"
11481 + "int $4\n0:\n"
11482 + _ASM_EXTABLE(0b, 0b)
11483 +#endif
11484 +
11485 /* subtracts 1, returns the old value */
11486 " jns 1f\n\t"
11487 " call call_rwsem_wake\n" /* expects old value in %edx */
11488 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11489 long tmp;
11490 asm volatile("# beginning __up_write\n\t"
11491 LOCK_PREFIX " xadd %1,(%2)\n\t"
11492 +
11493 +#ifdef CONFIG_PAX_REFCOUNT
11494 + "jno 0f\n"
11495 + "mov %1,(%2)\n"
11496 + "int $4\n0:\n"
11497 + _ASM_EXTABLE(0b, 0b)
11498 +#endif
11499 +
11500 /* subtracts 0xffff0001, returns the old value */
11501 " jns 1f\n\t"
11502 " call call_rwsem_wake\n" /* expects old value in %edx */
11503 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11504 {
11505 asm volatile("# beginning __downgrade_write\n\t"
11506 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11507 +
11508 +#ifdef CONFIG_PAX_REFCOUNT
11509 + "jno 0f\n"
11510 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11511 + "int $4\n0:\n"
11512 + _ASM_EXTABLE(0b, 0b)
11513 +#endif
11514 +
11515 /*
11516 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11517 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11518 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11519 */
11520 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11521 {
11522 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11523 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11524 +
11525 +#ifdef CONFIG_PAX_REFCOUNT
11526 + "jno 0f\n"
11527 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11528 + "int $4\n0:\n"
11529 + _ASM_EXTABLE(0b, 0b)
11530 +#endif
11531 +
11532 : "+m" (sem->count)
11533 : "er" (delta));
11534 }
11535 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11536 */
11537 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11538 {
11539 - return delta + xadd(&sem->count, delta);
11540 + return delta + xadd_check_overflow(&sem->count, delta);
11541 }
11542
11543 #endif /* __KERNEL__ */
11544 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11545 index 5e64171..f58957e 100644
11546 --- a/arch/x86/include/asm/segment.h
11547 +++ b/arch/x86/include/asm/segment.h
11548 @@ -64,10 +64,15 @@
11549 * 26 - ESPFIX small SS
11550 * 27 - per-cpu [ offset to per-cpu data area ]
11551 * 28 - stack_canary-20 [ for stack protector ]
11552 - * 29 - unused
11553 - * 30 - unused
11554 + * 29 - PCI BIOS CS
11555 + * 30 - PCI BIOS DS
11556 * 31 - TSS for double fault handler
11557 */
11558 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11559 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11560 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11561 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11562 +
11563 #define GDT_ENTRY_TLS_MIN 6
11564 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11565
11566 @@ -79,6 +84,8 @@
11567
11568 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11569
11570 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11571 +
11572 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11573
11574 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11575 @@ -104,6 +111,12 @@
11576 #define __KERNEL_STACK_CANARY 0
11577 #endif
11578
11579 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11580 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11581 +
11582 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11583 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11584 +
11585 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11586
11587 /*
11588 @@ -141,7 +154,7 @@
11589 */
11590
11591 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11592 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11593 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11594
11595
11596 #else
11597 @@ -165,6 +178,8 @@
11598 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11599 #define __USER32_DS __USER_DS
11600
11601 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11602 +
11603 #define GDT_ENTRY_TSS 8 /* needs two entries */
11604 #define GDT_ENTRY_LDT 10 /* needs two entries */
11605 #define GDT_ENTRY_TLS_MIN 12
11606 @@ -185,6 +200,7 @@
11607 #endif
11608
11609 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11610 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11611 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11612 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11613 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11614 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11615 index 73b11bc..d4a3b63 100644
11616 --- a/arch/x86/include/asm/smp.h
11617 +++ b/arch/x86/include/asm/smp.h
11618 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11619 /* cpus sharing the last level cache: */
11620 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11621 DECLARE_PER_CPU(u16, cpu_llc_id);
11622 -DECLARE_PER_CPU(int, cpu_number);
11623 +DECLARE_PER_CPU(unsigned int, cpu_number);
11624
11625 static inline struct cpumask *cpu_sibling_mask(int cpu)
11626 {
11627 @@ -77,7 +77,7 @@ struct smp_ops {
11628
11629 void (*send_call_func_ipi)(const struct cpumask *mask);
11630 void (*send_call_func_single_ipi)(int cpu);
11631 -};
11632 +} __no_const;
11633
11634 /* Globals due to paravirt */
11635 extern void set_cpu_sibling_map(int cpu);
11636 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11637 extern int safe_smp_processor_id(void);
11638
11639 #elif defined(CONFIG_X86_64_SMP)
11640 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11641 -
11642 -#define stack_smp_processor_id() \
11643 -({ \
11644 - struct thread_info *ti; \
11645 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11646 - ti->cpu; \
11647 -})
11648 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11649 +#define stack_smp_processor_id() raw_smp_processor_id()
11650 #define safe_smp_processor_id() smp_processor_id()
11651
11652 #endif
11653 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11654 index 972c260..43ab1fd 100644
11655 --- a/arch/x86/include/asm/spinlock.h
11656 +++ b/arch/x86/include/asm/spinlock.h
11657 @@ -188,6 +188,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11658 static inline void arch_read_lock(arch_rwlock_t *rw)
11659 {
11660 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11661 +
11662 +#ifdef CONFIG_PAX_REFCOUNT
11663 + "jno 0f\n"
11664 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11665 + "int $4\n0:\n"
11666 + _ASM_EXTABLE(0b, 0b)
11667 +#endif
11668 +
11669 "jns 1f\n"
11670 "call __read_lock_failed\n\t"
11671 "1:\n"
11672 @@ -197,6 +205,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11673 static inline void arch_write_lock(arch_rwlock_t *rw)
11674 {
11675 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11676 +
11677 +#ifdef CONFIG_PAX_REFCOUNT
11678 + "jno 0f\n"
11679 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11680 + "int $4\n0:\n"
11681 + _ASM_EXTABLE(0b, 0b)
11682 +#endif
11683 +
11684 "jz 1f\n"
11685 "call __write_lock_failed\n\t"
11686 "1:\n"
11687 @@ -226,13 +242,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11688
11689 static inline void arch_read_unlock(arch_rwlock_t *rw)
11690 {
11691 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11692 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11693 +
11694 +#ifdef CONFIG_PAX_REFCOUNT
11695 + "jno 0f\n"
11696 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11697 + "int $4\n0:\n"
11698 + _ASM_EXTABLE(0b, 0b)
11699 +#endif
11700 +
11701 :"+m" (rw->lock) : : "memory");
11702 }
11703
11704 static inline void arch_write_unlock(arch_rwlock_t *rw)
11705 {
11706 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11707 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11708 +
11709 +#ifdef CONFIG_PAX_REFCOUNT
11710 + "jno 0f\n"
11711 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11712 + "int $4\n0:\n"
11713 + _ASM_EXTABLE(0b, 0b)
11714 +#endif
11715 +
11716 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11717 }
11718
11719 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11720 index 1575177..cb23f52 100644
11721 --- a/arch/x86/include/asm/stackprotector.h
11722 +++ b/arch/x86/include/asm/stackprotector.h
11723 @@ -48,7 +48,7 @@
11724 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11725 */
11726 #define GDT_STACK_CANARY_INIT \
11727 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11728 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11729
11730 /*
11731 * Initialize the stackprotector canary value.
11732 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11733
11734 static inline void load_stack_canary_segment(void)
11735 {
11736 -#ifdef CONFIG_X86_32
11737 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11738 asm volatile ("mov %0, %%gs" : : "r" (0));
11739 #endif
11740 }
11741 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11742 index 70bbe39..4ae2bd4 100644
11743 --- a/arch/x86/include/asm/stacktrace.h
11744 +++ b/arch/x86/include/asm/stacktrace.h
11745 @@ -11,28 +11,20 @@
11746
11747 extern int kstack_depth_to_print;
11748
11749 -struct thread_info;
11750 +struct task_struct;
11751 struct stacktrace_ops;
11752
11753 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11754 - unsigned long *stack,
11755 - unsigned long bp,
11756 - const struct stacktrace_ops *ops,
11757 - void *data,
11758 - unsigned long *end,
11759 - int *graph);
11760 +typedef unsigned long walk_stack_t(struct task_struct *task,
11761 + void *stack_start,
11762 + unsigned long *stack,
11763 + unsigned long bp,
11764 + const struct stacktrace_ops *ops,
11765 + void *data,
11766 + unsigned long *end,
11767 + int *graph);
11768
11769 -extern unsigned long
11770 -print_context_stack(struct thread_info *tinfo,
11771 - unsigned long *stack, unsigned long bp,
11772 - const struct stacktrace_ops *ops, void *data,
11773 - unsigned long *end, int *graph);
11774 -
11775 -extern unsigned long
11776 -print_context_stack_bp(struct thread_info *tinfo,
11777 - unsigned long *stack, unsigned long bp,
11778 - const struct stacktrace_ops *ops, void *data,
11779 - unsigned long *end, int *graph);
11780 +extern walk_stack_t print_context_stack;
11781 +extern walk_stack_t print_context_stack_bp;
11782
11783 /* Generic stack tracer with callbacks */
11784
11785 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11786 void (*address)(void *data, unsigned long address, int reliable);
11787 /* On negative return stop dumping */
11788 int (*stack)(void *data, char *name);
11789 - walk_stack_t walk_stack;
11790 + walk_stack_t *walk_stack;
11791 };
11792
11793 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11794 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11795 index cb23852..2dde194 100644
11796 --- a/arch/x86/include/asm/sys_ia32.h
11797 +++ b/arch/x86/include/asm/sys_ia32.h
11798 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11799 compat_sigset_t __user *, unsigned int);
11800 asmlinkage long sys32_alarm(unsigned int);
11801
11802 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11803 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11804 asmlinkage long sys32_sysfs(int, u32, u32);
11805
11806 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11807 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11808 index 2d2f01c..f985723 100644
11809 --- a/arch/x86/include/asm/system.h
11810 +++ b/arch/x86/include/asm/system.h
11811 @@ -129,7 +129,7 @@ do { \
11812 "call __switch_to\n\t" \
11813 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11814 __switch_canary \
11815 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11816 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11817 "movq %%rax,%%rdi\n\t" \
11818 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11819 "jnz ret_from_fork\n\t" \
11820 @@ -140,7 +140,7 @@ do { \
11821 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11822 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11823 [_tif_fork] "i" (_TIF_FORK), \
11824 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11825 + [thread_info] "m" (current_tinfo), \
11826 [current_task] "m" (current_task) \
11827 __switch_canary_iparam \
11828 : "memory", "cc" __EXTRA_CLOBBER)
11829 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11830 {
11831 unsigned long __limit;
11832 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11833 - return __limit + 1;
11834 + return __limit;
11835 }
11836
11837 static inline void native_clts(void)
11838 @@ -397,13 +397,13 @@ void enable_hlt(void);
11839
11840 void cpu_idle_wait(void);
11841
11842 -extern unsigned long arch_align_stack(unsigned long sp);
11843 +#define arch_align_stack(x) ((x) & ~0xfUL)
11844 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11845
11846 void default_idle(void);
11847 bool set_pm_idle_to_default(void);
11848
11849 -void stop_this_cpu(void *dummy);
11850 +void stop_this_cpu(void *dummy) __noreturn;
11851
11852 /*
11853 * Force strict CPU ordering.
11854 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11855 index d7ef849..6af292e 100644
11856 --- a/arch/x86/include/asm/thread_info.h
11857 +++ b/arch/x86/include/asm/thread_info.h
11858 @@ -10,6 +10,7 @@
11859 #include <linux/compiler.h>
11860 #include <asm/page.h>
11861 #include <asm/types.h>
11862 +#include <asm/percpu.h>
11863
11864 /*
11865 * low level task data that entry.S needs immediate access to
11866 @@ -24,7 +25,6 @@ struct exec_domain;
11867 #include <linux/atomic.h>
11868
11869 struct thread_info {
11870 - struct task_struct *task; /* main task structure */
11871 struct exec_domain *exec_domain; /* execution domain */
11872 __u32 flags; /* low level flags */
11873 __u32 status; /* thread synchronous flags */
11874 @@ -34,18 +34,12 @@ struct thread_info {
11875 mm_segment_t addr_limit;
11876 struct restart_block restart_block;
11877 void __user *sysenter_return;
11878 -#ifdef CONFIG_X86_32
11879 - unsigned long previous_esp; /* ESP of the previous stack in
11880 - case of nested (IRQ) stacks
11881 - */
11882 - __u8 supervisor_stack[0];
11883 -#endif
11884 + unsigned long lowest_stack;
11885 int uaccess_err;
11886 };
11887
11888 -#define INIT_THREAD_INFO(tsk) \
11889 +#define INIT_THREAD_INFO \
11890 { \
11891 - .task = &tsk, \
11892 .exec_domain = &default_exec_domain, \
11893 .flags = 0, \
11894 .cpu = 0, \
11895 @@ -56,7 +50,7 @@ struct thread_info {
11896 }, \
11897 }
11898
11899 -#define init_thread_info (init_thread_union.thread_info)
11900 +#define init_thread_info (init_thread_union.stack)
11901 #define init_stack (init_thread_union.stack)
11902
11903 #else /* !__ASSEMBLY__ */
11904 @@ -170,45 +164,40 @@ struct thread_info {
11905 ret; \
11906 })
11907
11908 -#ifdef CONFIG_X86_32
11909 -
11910 -#define STACK_WARN (THREAD_SIZE/8)
11911 -/*
11912 - * macros/functions for gaining access to the thread information structure
11913 - *
11914 - * preempt_count needs to be 1 initially, until the scheduler is functional.
11915 - */
11916 -#ifndef __ASSEMBLY__
11917 -
11918 -
11919 -/* how to get the current stack pointer from C */
11920 -register unsigned long current_stack_pointer asm("esp") __used;
11921 -
11922 -/* how to get the thread information struct from C */
11923 -static inline struct thread_info *current_thread_info(void)
11924 -{
11925 - return (struct thread_info *)
11926 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11927 -}
11928 -
11929 -#else /* !__ASSEMBLY__ */
11930 -
11931 +#ifdef __ASSEMBLY__
11932 /* how to get the thread information struct from ASM */
11933 #define GET_THREAD_INFO(reg) \
11934 - movl $-THREAD_SIZE, reg; \
11935 - andl %esp, reg
11936 + mov PER_CPU_VAR(current_tinfo), reg
11937
11938 /* use this one if reg already contains %esp */
11939 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11940 - andl $-THREAD_SIZE, reg
11941 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11942 +#else
11943 +/* how to get the thread information struct from C */
11944 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11945 +
11946 +static __always_inline struct thread_info *current_thread_info(void)
11947 +{
11948 + return percpu_read_stable(current_tinfo);
11949 +}
11950 +#endif
11951 +
11952 +#ifdef CONFIG_X86_32
11953 +
11954 +#define STACK_WARN (THREAD_SIZE/8)
11955 +/*
11956 + * macros/functions for gaining access to the thread information structure
11957 + *
11958 + * preempt_count needs to be 1 initially, until the scheduler is functional.
11959 + */
11960 +#ifndef __ASSEMBLY__
11961 +
11962 +/* how to get the current stack pointer from C */
11963 +register unsigned long current_stack_pointer asm("esp") __used;
11964
11965 #endif
11966
11967 #else /* X86_32 */
11968
11969 -#include <asm/percpu.h>
11970 -#define KERNEL_STACK_OFFSET (5*8)
11971 -
11972 /*
11973 * macros/functions for gaining access to the thread information structure
11974 * preempt_count needs to be 1 initially, until the scheduler is functional.
11975 @@ -216,21 +205,8 @@ static inline struct thread_info *current_thread_info(void)
11976 #ifndef __ASSEMBLY__
11977 DECLARE_PER_CPU(unsigned long, kernel_stack);
11978
11979 -static inline struct thread_info *current_thread_info(void)
11980 -{
11981 - struct thread_info *ti;
11982 - ti = (void *)(percpu_read_stable(kernel_stack) +
11983 - KERNEL_STACK_OFFSET - THREAD_SIZE);
11984 - return ti;
11985 -}
11986 -
11987 -#else /* !__ASSEMBLY__ */
11988 -
11989 -/* how to get the thread information struct from ASM */
11990 -#define GET_THREAD_INFO(reg) \
11991 - movq PER_CPU_VAR(kernel_stack),reg ; \
11992 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11993 -
11994 +/* how to get the current stack pointer from C */
11995 +register unsigned long current_stack_pointer asm("rsp") __used;
11996 #endif
11997
11998 #endif /* !X86_32 */
11999 @@ -264,5 +240,16 @@ extern void arch_task_cache_init(void);
12000 extern void free_thread_info(struct thread_info *ti);
12001 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12002 #define arch_task_cache_init arch_task_cache_init
12003 +
12004 +#define __HAVE_THREAD_FUNCTIONS
12005 +#define task_thread_info(task) (&(task)->tinfo)
12006 +#define task_stack_page(task) ((task)->stack)
12007 +#define setup_thread_stack(p, org) do {} while (0)
12008 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12009 +
12010 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12011 +extern struct task_struct *alloc_task_struct_node(int node);
12012 +extern void free_task_struct(struct task_struct *);
12013 +
12014 #endif
12015 #endif /* _ASM_X86_THREAD_INFO_H */
12016 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12017 index 36361bf..324f262 100644
12018 --- a/arch/x86/include/asm/uaccess.h
12019 +++ b/arch/x86/include/asm/uaccess.h
12020 @@ -7,12 +7,15 @@
12021 #include <linux/compiler.h>
12022 #include <linux/thread_info.h>
12023 #include <linux/string.h>
12024 +#include <linux/sched.h>
12025 #include <asm/asm.h>
12026 #include <asm/page.h>
12027
12028 #define VERIFY_READ 0
12029 #define VERIFY_WRITE 1
12030
12031 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12032 +
12033 /*
12034 * The fs value determines whether argument validity checking should be
12035 * performed or not. If get_fs() == USER_DS, checking is performed, with
12036 @@ -28,7 +31,12 @@
12037
12038 #define get_ds() (KERNEL_DS)
12039 #define get_fs() (current_thread_info()->addr_limit)
12040 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12041 +void __set_fs(mm_segment_t x);
12042 +void set_fs(mm_segment_t x);
12043 +#else
12044 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12045 +#endif
12046
12047 #define segment_eq(a, b) ((a).seg == (b).seg)
12048
12049 @@ -76,7 +84,33 @@
12050 * checks that the pointer is in the user space range - after calling
12051 * this function, memory access functions may still return -EFAULT.
12052 */
12053 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12054 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12055 +#define access_ok(type, addr, size) \
12056 +({ \
12057 + long __size = size; \
12058 + unsigned long __addr = (unsigned long)addr; \
12059 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12060 + unsigned long __end_ao = __addr + __size - 1; \
12061 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12062 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12063 + while(__addr_ao <= __end_ao) { \
12064 + char __c_ao; \
12065 + __addr_ao += PAGE_SIZE; \
12066 + if (__size > PAGE_SIZE) \
12067 + cond_resched(); \
12068 + if (__get_user(__c_ao, (char __user *)__addr)) \
12069 + break; \
12070 + if (type != VERIFY_WRITE) { \
12071 + __addr = __addr_ao; \
12072 + continue; \
12073 + } \
12074 + if (__put_user(__c_ao, (char __user *)__addr)) \
12075 + break; \
12076 + __addr = __addr_ao; \
12077 + } \
12078 + } \
12079 + __ret_ao; \
12080 +})
12081
12082 /*
12083 * The exception table consists of pairs of addresses: the first is the
12084 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12085 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12086 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12087
12088 -
12089 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12090 +#define __copyuser_seg "gs;"
12091 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12092 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12093 +#else
12094 +#define __copyuser_seg
12095 +#define __COPYUSER_SET_ES
12096 +#define __COPYUSER_RESTORE_ES
12097 +#endif
12098
12099 #ifdef CONFIG_X86_32
12100 #define __put_user_asm_u64(x, addr, err, errret) \
12101 - asm volatile("1: movl %%eax,0(%2)\n" \
12102 - "2: movl %%edx,4(%2)\n" \
12103 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12104 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12105 "3:\n" \
12106 ".section .fixup,\"ax\"\n" \
12107 "4: movl %3,%0\n" \
12108 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12109 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12110
12111 #define __put_user_asm_ex_u64(x, addr) \
12112 - asm volatile("1: movl %%eax,0(%1)\n" \
12113 - "2: movl %%edx,4(%1)\n" \
12114 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12115 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12116 "3:\n" \
12117 _ASM_EXTABLE(1b, 2b - 1b) \
12118 _ASM_EXTABLE(2b, 3b - 2b) \
12119 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12120 __typeof__(*(ptr)) __pu_val; \
12121 __chk_user_ptr(ptr); \
12122 might_fault(); \
12123 - __pu_val = x; \
12124 + __pu_val = (x); \
12125 switch (sizeof(*(ptr))) { \
12126 case 1: \
12127 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12128 @@ -373,7 +415,7 @@ do { \
12129 } while (0)
12130
12131 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12132 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12133 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12134 "2:\n" \
12135 ".section .fixup,\"ax\"\n" \
12136 "3: mov %3,%0\n" \
12137 @@ -381,7 +423,7 @@ do { \
12138 " jmp 2b\n" \
12139 ".previous\n" \
12140 _ASM_EXTABLE(1b, 3b) \
12141 - : "=r" (err), ltype(x) \
12142 + : "=r" (err), ltype (x) \
12143 : "m" (__m(addr)), "i" (errret), "0" (err))
12144
12145 #define __get_user_size_ex(x, ptr, size) \
12146 @@ -406,7 +448,7 @@ do { \
12147 } while (0)
12148
12149 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12150 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12151 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12152 "2:\n" \
12153 _ASM_EXTABLE(1b, 2b - 1b) \
12154 : ltype(x) : "m" (__m(addr)))
12155 @@ -423,13 +465,24 @@ do { \
12156 int __gu_err; \
12157 unsigned long __gu_val; \
12158 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12159 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12160 + (x) = (__typeof__(*(ptr)))__gu_val; \
12161 __gu_err; \
12162 })
12163
12164 /* FIXME: this hack is definitely wrong -AK */
12165 struct __large_struct { unsigned long buf[100]; };
12166 -#define __m(x) (*(struct __large_struct __user *)(x))
12167 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12168 +#define ____m(x) \
12169 +({ \
12170 + unsigned long ____x = (unsigned long)(x); \
12171 + if (____x < PAX_USER_SHADOW_BASE) \
12172 + ____x += PAX_USER_SHADOW_BASE; \
12173 + (void __user *)____x; \
12174 +})
12175 +#else
12176 +#define ____m(x) (x)
12177 +#endif
12178 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12179
12180 /*
12181 * Tell gcc we read from memory instead of writing: this is because
12182 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12183 * aliasing issues.
12184 */
12185 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12186 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12187 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12188 "2:\n" \
12189 ".section .fixup,\"ax\"\n" \
12190 "3: mov %3,%0\n" \
12191 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12192 ".previous\n" \
12193 _ASM_EXTABLE(1b, 3b) \
12194 : "=r"(err) \
12195 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12196 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12197
12198 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12199 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12200 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12201 "2:\n" \
12202 _ASM_EXTABLE(1b, 2b - 1b) \
12203 : : ltype(x), "m" (__m(addr)))
12204 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12205 * On error, the variable @x is set to zero.
12206 */
12207
12208 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12209 +#define __get_user(x, ptr) get_user((x), (ptr))
12210 +#else
12211 #define __get_user(x, ptr) \
12212 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12213 +#endif
12214
12215 /**
12216 * __put_user: - Write a simple value into user space, with less checking.
12217 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12218 * Returns zero on success, or -EFAULT on error.
12219 */
12220
12221 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12222 +#define __put_user(x, ptr) put_user((x), (ptr))
12223 +#else
12224 #define __put_user(x, ptr) \
12225 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12226 +#endif
12227
12228 #define __get_user_unaligned __get_user
12229 #define __put_user_unaligned __put_user
12230 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12231 #define get_user_ex(x, ptr) do { \
12232 unsigned long __gue_val; \
12233 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12234 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12235 + (x) = (__typeof__(*(ptr)))__gue_val; \
12236 } while (0)
12237
12238 #ifdef CONFIG_X86_WP_WORKS_OK
12239 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12240 index 566e803..b9521e9 100644
12241 --- a/arch/x86/include/asm/uaccess_32.h
12242 +++ b/arch/x86/include/asm/uaccess_32.h
12243 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12244 static __always_inline unsigned long __must_check
12245 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12246 {
12247 + if ((long)n < 0)
12248 + return n;
12249 +
12250 if (__builtin_constant_p(n)) {
12251 unsigned long ret;
12252
12253 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12254 return ret;
12255 }
12256 }
12257 + if (!__builtin_constant_p(n))
12258 + check_object_size(from, n, true);
12259 return __copy_to_user_ll(to, from, n);
12260 }
12261
12262 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12263 __copy_to_user(void __user *to, const void *from, unsigned long n)
12264 {
12265 might_fault();
12266 +
12267 return __copy_to_user_inatomic(to, from, n);
12268 }
12269
12270 static __always_inline unsigned long
12271 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12272 {
12273 + if ((long)n < 0)
12274 + return n;
12275 +
12276 /* Avoid zeroing the tail if the copy fails..
12277 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12278 * but as the zeroing behaviour is only significant when n is not
12279 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12280 __copy_from_user(void *to, const void __user *from, unsigned long n)
12281 {
12282 might_fault();
12283 +
12284 + if ((long)n < 0)
12285 + return n;
12286 +
12287 if (__builtin_constant_p(n)) {
12288 unsigned long ret;
12289
12290 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12291 return ret;
12292 }
12293 }
12294 + if (!__builtin_constant_p(n))
12295 + check_object_size(to, n, false);
12296 return __copy_from_user_ll(to, from, n);
12297 }
12298
12299 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12300 const void __user *from, unsigned long n)
12301 {
12302 might_fault();
12303 +
12304 + if ((long)n < 0)
12305 + return n;
12306 +
12307 if (__builtin_constant_p(n)) {
12308 unsigned long ret;
12309
12310 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12311 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12312 unsigned long n)
12313 {
12314 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12315 + if ((long)n < 0)
12316 + return n;
12317 +
12318 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12319 }
12320
12321 -unsigned long __must_check copy_to_user(void __user *to,
12322 - const void *from, unsigned long n);
12323 -unsigned long __must_check _copy_from_user(void *to,
12324 - const void __user *from,
12325 - unsigned long n);
12326 -
12327 +extern void copy_to_user_overflow(void)
12328 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12329 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12330 +#else
12331 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12332 +#endif
12333 +;
12334
12335 extern void copy_from_user_overflow(void)
12336 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12337 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12338 #endif
12339 ;
12340
12341 -static inline unsigned long __must_check copy_from_user(void *to,
12342 - const void __user *from,
12343 - unsigned long n)
12344 +/**
12345 + * copy_to_user: - Copy a block of data into user space.
12346 + * @to: Destination address, in user space.
12347 + * @from: Source address, in kernel space.
12348 + * @n: Number of bytes to copy.
12349 + *
12350 + * Context: User context only. This function may sleep.
12351 + *
12352 + * Copy data from kernel space to user space.
12353 + *
12354 + * Returns number of bytes that could not be copied.
12355 + * On success, this will be zero.
12356 + */
12357 +static inline unsigned long __must_check
12358 +copy_to_user(void __user *to, const void *from, unsigned long n)
12359 +{
12360 + int sz = __compiletime_object_size(from);
12361 +
12362 + if (unlikely(sz != -1 && sz < n))
12363 + copy_to_user_overflow();
12364 + else if (access_ok(VERIFY_WRITE, to, n))
12365 + n = __copy_to_user(to, from, n);
12366 + return n;
12367 +}
12368 +
12369 +/**
12370 + * copy_from_user: - Copy a block of data from user space.
12371 + * @to: Destination address, in kernel space.
12372 + * @from: Source address, in user space.
12373 + * @n: Number of bytes to copy.
12374 + *
12375 + * Context: User context only. This function may sleep.
12376 + *
12377 + * Copy data from user space to kernel space.
12378 + *
12379 + * Returns number of bytes that could not be copied.
12380 + * On success, this will be zero.
12381 + *
12382 + * If some data could not be copied, this function will pad the copied
12383 + * data to the requested size using zero bytes.
12384 + */
12385 +static inline unsigned long __must_check
12386 +copy_from_user(void *to, const void __user *from, unsigned long n)
12387 {
12388 int sz = __compiletime_object_size(to);
12389
12390 - if (likely(sz == -1 || sz >= n))
12391 - n = _copy_from_user(to, from, n);
12392 - else
12393 + if (unlikely(sz != -1 && sz < n))
12394 copy_from_user_overflow();
12395 -
12396 + else if (access_ok(VERIFY_READ, from, n))
12397 + n = __copy_from_user(to, from, n);
12398 + else if ((long)n > 0) {
12399 + if (!__builtin_constant_p(n))
12400 + check_object_size(to, n, false);
12401 + memset(to, 0, n);
12402 + }
12403 return n;
12404 }
12405
12406 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12407 index 1c66d30..e66922c 100644
12408 --- a/arch/x86/include/asm/uaccess_64.h
12409 +++ b/arch/x86/include/asm/uaccess_64.h
12410 @@ -10,6 +10,9 @@
12411 #include <asm/alternative.h>
12412 #include <asm/cpufeature.h>
12413 #include <asm/page.h>
12414 +#include <asm/pgtable.h>
12415 +
12416 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12417
12418 /*
12419 * Copy To/From Userspace
12420 @@ -17,12 +20,12 @@
12421
12422 /* Handles exceptions in both to and from, but doesn't do access_ok */
12423 __must_check unsigned long
12424 -copy_user_generic_string(void *to, const void *from, unsigned len);
12425 +copy_user_generic_string(void *to, const void *from, unsigned long len);
12426 __must_check unsigned long
12427 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12428 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
12429
12430 static __always_inline __must_check unsigned long
12431 -copy_user_generic(void *to, const void *from, unsigned len)
12432 +copy_user_generic(void *to, const void *from, unsigned long len)
12433 {
12434 unsigned ret;
12435
12436 @@ -32,142 +35,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
12437 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12438 "=d" (len)),
12439 "1" (to), "2" (from), "3" (len)
12440 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12441 + : "memory", "rcx", "r8", "r9", "r11");
12442 return ret;
12443 }
12444
12445 +static __always_inline __must_check unsigned long
12446 +__copy_to_user(void __user *to, const void *from, unsigned long len);
12447 +static __always_inline __must_check unsigned long
12448 +__copy_from_user(void *to, const void __user *from, unsigned long len);
12449 __must_check unsigned long
12450 -_copy_to_user(void __user *to, const void *from, unsigned len);
12451 -__must_check unsigned long
12452 -_copy_from_user(void *to, const void __user *from, unsigned len);
12453 -__must_check unsigned long
12454 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12455 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
12456
12457 static inline unsigned long __must_check copy_from_user(void *to,
12458 const void __user *from,
12459 unsigned long n)
12460 {
12461 - int sz = __compiletime_object_size(to);
12462 -
12463 might_fault();
12464 - if (likely(sz == -1 || sz >= n))
12465 - n = _copy_from_user(to, from, n);
12466 -#ifdef CONFIG_DEBUG_VM
12467 - else
12468 - WARN(1, "Buffer overflow detected!\n");
12469 -#endif
12470 +
12471 + if (access_ok(VERIFY_READ, from, n))
12472 + n = __copy_from_user(to, from, n);
12473 + else if (n < INT_MAX) {
12474 + if (!__builtin_constant_p(n))
12475 + check_object_size(to, n, false);
12476 + memset(to, 0, n);
12477 + }
12478 return n;
12479 }
12480
12481 static __always_inline __must_check
12482 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12483 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12484 {
12485 might_fault();
12486
12487 - return _copy_to_user(dst, src, size);
12488 + if (access_ok(VERIFY_WRITE, dst, size))
12489 + size = __copy_to_user(dst, src, size);
12490 + return size;
12491 }
12492
12493 static __always_inline __must_check
12494 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12495 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12496 {
12497 - int ret = 0;
12498 + int sz = __compiletime_object_size(dst);
12499 + unsigned ret = 0;
12500
12501 might_fault();
12502 - if (!__builtin_constant_p(size))
12503 - return copy_user_generic(dst, (__force void *)src, size);
12504 +
12505 + if (size > INT_MAX)
12506 + return size;
12507 +
12508 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12509 + if (!__access_ok(VERIFY_READ, src, size))
12510 + return size;
12511 +#endif
12512 +
12513 + if (unlikely(sz != -1 && sz < size)) {
12514 +#ifdef CONFIG_DEBUG_VM
12515 + WARN(1, "Buffer overflow detected!\n");
12516 +#endif
12517 + return size;
12518 + }
12519 +
12520 + if (!__builtin_constant_p(size)) {
12521 + check_object_size(dst, size, false);
12522 +
12523 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12524 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12525 + src += PAX_USER_SHADOW_BASE;
12526 +#endif
12527 +
12528 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12529 + }
12530 switch (size) {
12531 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12532 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12533 ret, "b", "b", "=q", 1);
12534 return ret;
12535 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12536 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12537 ret, "w", "w", "=r", 2);
12538 return ret;
12539 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12540 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12541 ret, "l", "k", "=r", 4);
12542 return ret;
12543 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12544 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12545 ret, "q", "", "=r", 8);
12546 return ret;
12547 case 10:
12548 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12549 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12550 ret, "q", "", "=r", 10);
12551 if (unlikely(ret))
12552 return ret;
12553 __get_user_asm(*(u16 *)(8 + (char *)dst),
12554 - (u16 __user *)(8 + (char __user *)src),
12555 + (const u16 __user *)(8 + (const char __user *)src),
12556 ret, "w", "w", "=r", 2);
12557 return ret;
12558 case 16:
12559 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12560 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12561 ret, "q", "", "=r", 16);
12562 if (unlikely(ret))
12563 return ret;
12564 __get_user_asm(*(u64 *)(8 + (char *)dst),
12565 - (u64 __user *)(8 + (char __user *)src),
12566 + (const u64 __user *)(8 + (const char __user *)src),
12567 ret, "q", "", "=r", 8);
12568 return ret;
12569 default:
12570 - return copy_user_generic(dst, (__force void *)src, size);
12571 +
12572 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12573 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12574 + src += PAX_USER_SHADOW_BASE;
12575 +#endif
12576 +
12577 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12578 }
12579 }
12580
12581 static __always_inline __must_check
12582 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12583 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12584 {
12585 - int ret = 0;
12586 + int sz = __compiletime_object_size(src);
12587 + unsigned ret = 0;
12588
12589 might_fault();
12590 - if (!__builtin_constant_p(size))
12591 - return copy_user_generic((__force void *)dst, src, size);
12592 +
12593 + if (size > INT_MAX)
12594 + return size;
12595 +
12596 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12597 + if (!__access_ok(VERIFY_WRITE, dst, size))
12598 + return size;
12599 +#endif
12600 +
12601 + if (unlikely(sz != -1 && sz < size)) {
12602 +#ifdef CONFIG_DEBUG_VM
12603 + WARN(1, "Buffer overflow detected!\n");
12604 +#endif
12605 + return size;
12606 + }
12607 +
12608 + if (!__builtin_constant_p(size)) {
12609 + check_object_size(src, size, true);
12610 +
12611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12612 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12613 + dst += PAX_USER_SHADOW_BASE;
12614 +#endif
12615 +
12616 + return copy_user_generic((__force_kernel void *)dst, src, size);
12617 + }
12618 switch (size) {
12619 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12620 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12621 ret, "b", "b", "iq", 1);
12622 return ret;
12623 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12624 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12625 ret, "w", "w", "ir", 2);
12626 return ret;
12627 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12628 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12629 ret, "l", "k", "ir", 4);
12630 return ret;
12631 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12632 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12633 ret, "q", "", "er", 8);
12634 return ret;
12635 case 10:
12636 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12637 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12638 ret, "q", "", "er", 10);
12639 if (unlikely(ret))
12640 return ret;
12641 asm("":::"memory");
12642 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12643 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12644 ret, "w", "w", "ir", 2);
12645 return ret;
12646 case 16:
12647 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12648 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12649 ret, "q", "", "er", 16);
12650 if (unlikely(ret))
12651 return ret;
12652 asm("":::"memory");
12653 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12654 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12655 ret, "q", "", "er", 8);
12656 return ret;
12657 default:
12658 - return copy_user_generic((__force void *)dst, src, size);
12659 +
12660 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12661 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12662 + dst += PAX_USER_SHADOW_BASE;
12663 +#endif
12664 +
12665 + return copy_user_generic((__force_kernel void *)dst, src, size);
12666 }
12667 }
12668
12669 static __always_inline __must_check
12670 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12671 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12672 {
12673 - int ret = 0;
12674 + unsigned ret = 0;
12675
12676 might_fault();
12677 - if (!__builtin_constant_p(size))
12678 - return copy_user_generic((__force void *)dst,
12679 - (__force void *)src, size);
12680 +
12681 + if (size > INT_MAX)
12682 + return size;
12683 +
12684 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12685 + if (!__access_ok(VERIFY_READ, src, size))
12686 + return size;
12687 + if (!__access_ok(VERIFY_WRITE, dst, size))
12688 + return size;
12689 +#endif
12690 +
12691 + if (!__builtin_constant_p(size)) {
12692 +
12693 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12694 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12695 + src += PAX_USER_SHADOW_BASE;
12696 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12697 + dst += PAX_USER_SHADOW_BASE;
12698 +#endif
12699 +
12700 + return copy_user_generic((__force_kernel void *)dst,
12701 + (__force_kernel const void *)src, size);
12702 + }
12703 switch (size) {
12704 case 1: {
12705 u8 tmp;
12706 - __get_user_asm(tmp, (u8 __user *)src,
12707 + __get_user_asm(tmp, (const u8 __user *)src,
12708 ret, "b", "b", "=q", 1);
12709 if (likely(!ret))
12710 __put_user_asm(tmp, (u8 __user *)dst,
12711 @@ -176,7 +263,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12712 }
12713 case 2: {
12714 u16 tmp;
12715 - __get_user_asm(tmp, (u16 __user *)src,
12716 + __get_user_asm(tmp, (const u16 __user *)src,
12717 ret, "w", "w", "=r", 2);
12718 if (likely(!ret))
12719 __put_user_asm(tmp, (u16 __user *)dst,
12720 @@ -186,7 +273,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12721
12722 case 4: {
12723 u32 tmp;
12724 - __get_user_asm(tmp, (u32 __user *)src,
12725 + __get_user_asm(tmp, (const u32 __user *)src,
12726 ret, "l", "k", "=r", 4);
12727 if (likely(!ret))
12728 __put_user_asm(tmp, (u32 __user *)dst,
12729 @@ -195,7 +282,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12730 }
12731 case 8: {
12732 u64 tmp;
12733 - __get_user_asm(tmp, (u64 __user *)src,
12734 + __get_user_asm(tmp, (const u64 __user *)src,
12735 ret, "q", "", "=r", 8);
12736 if (likely(!ret))
12737 __put_user_asm(tmp, (u64 __user *)dst,
12738 @@ -203,8 +290,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12739 return ret;
12740 }
12741 default:
12742 - return copy_user_generic((__force void *)dst,
12743 - (__force void *)src, size);
12744 +
12745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12746 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12747 + src += PAX_USER_SHADOW_BASE;
12748 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12749 + dst += PAX_USER_SHADOW_BASE;
12750 +#endif
12751 +
12752 + return copy_user_generic((__force_kernel void *)dst,
12753 + (__force_kernel const void *)src, size);
12754 }
12755 }
12756
12757 @@ -219,35 +314,72 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12758 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12759
12760 static __must_check __always_inline int
12761 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12762 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12763 {
12764 - return copy_user_generic(dst, (__force const void *)src, size);
12765 + if (size > INT_MAX)
12766 + return size;
12767 +
12768 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12769 + if (!__access_ok(VERIFY_READ, src, size))
12770 + return size;
12771 +
12772 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12773 + src += PAX_USER_SHADOW_BASE;
12774 +#endif
12775 +
12776 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12777 }
12778
12779 -static __must_check __always_inline int
12780 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12781 +static __must_check __always_inline unsigned long
12782 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12783 {
12784 - return copy_user_generic((__force void *)dst, src, size);
12785 + if (size > INT_MAX)
12786 + return size;
12787 +
12788 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12789 + if (!__access_ok(VERIFY_WRITE, dst, size))
12790 + return size;
12791 +
12792 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12793 + dst += PAX_USER_SHADOW_BASE;
12794 +#endif
12795 +
12796 + return copy_user_generic((__force_kernel void *)dst, src, size);
12797 }
12798
12799 -extern long __copy_user_nocache(void *dst, const void __user *src,
12800 - unsigned size, int zerorest);
12801 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12802 + unsigned long size, int zerorest);
12803
12804 -static inline int
12805 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12806 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12807 {
12808 might_sleep();
12809 +
12810 + if (size > INT_MAX)
12811 + return size;
12812 +
12813 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12814 + if (!__access_ok(VERIFY_READ, src, size))
12815 + return size;
12816 +#endif
12817 +
12818 return __copy_user_nocache(dst, src, size, 1);
12819 }
12820
12821 -static inline int
12822 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12823 - unsigned size)
12824 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12825 + unsigned long size)
12826 {
12827 + if (size > INT_MAX)
12828 + return size;
12829 +
12830 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12831 + if (!__access_ok(VERIFY_READ, src, size))
12832 + return size;
12833 +#endif
12834 +
12835 return __copy_user_nocache(dst, src, size, 0);
12836 }
12837
12838 -unsigned long
12839 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12840 +extern unsigned long
12841 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
12842
12843 #endif /* _ASM_X86_UACCESS_64_H */
12844 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12845 index bb05228..d763d5b 100644
12846 --- a/arch/x86/include/asm/vdso.h
12847 +++ b/arch/x86/include/asm/vdso.h
12848 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
12849 #define VDSO32_SYMBOL(base, name) \
12850 ({ \
12851 extern const char VDSO32_##name[]; \
12852 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12853 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12854 })
12855 #endif
12856
12857 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
12858 index 1971e65..1e3559b 100644
12859 --- a/arch/x86/include/asm/x86_init.h
12860 +++ b/arch/x86/include/asm/x86_init.h
12861 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
12862 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
12863 void (*find_smp_config)(void);
12864 void (*get_smp_config)(unsigned int early);
12865 -};
12866 +} __no_const;
12867
12868 /**
12869 * struct x86_init_resources - platform specific resource related ops
12870 @@ -42,7 +42,7 @@ struct x86_init_resources {
12871 void (*probe_roms)(void);
12872 void (*reserve_resources)(void);
12873 char *(*memory_setup)(void);
12874 -};
12875 +} __no_const;
12876
12877 /**
12878 * struct x86_init_irqs - platform specific interrupt setup
12879 @@ -55,7 +55,7 @@ struct x86_init_irqs {
12880 void (*pre_vector_init)(void);
12881 void (*intr_init)(void);
12882 void (*trap_init)(void);
12883 -};
12884 +} __no_const;
12885
12886 /**
12887 * struct x86_init_oem - oem platform specific customizing functions
12888 @@ -65,7 +65,7 @@ struct x86_init_irqs {
12889 struct x86_init_oem {
12890 void (*arch_setup)(void);
12891 void (*banner)(void);
12892 -};
12893 +} __no_const;
12894
12895 /**
12896 * struct x86_init_mapping - platform specific initial kernel pagetable setup
12897 @@ -76,7 +76,7 @@ struct x86_init_oem {
12898 */
12899 struct x86_init_mapping {
12900 void (*pagetable_reserve)(u64 start, u64 end);
12901 -};
12902 +} __no_const;
12903
12904 /**
12905 * struct x86_init_paging - platform specific paging functions
12906 @@ -86,7 +86,7 @@ struct x86_init_mapping {
12907 struct x86_init_paging {
12908 void (*pagetable_setup_start)(pgd_t *base);
12909 void (*pagetable_setup_done)(pgd_t *base);
12910 -};
12911 +} __no_const;
12912
12913 /**
12914 * struct x86_init_timers - platform specific timer setup
12915 @@ -101,7 +101,7 @@ struct x86_init_timers {
12916 void (*tsc_pre_init)(void);
12917 void (*timer_init)(void);
12918 void (*wallclock_init)(void);
12919 -};
12920 +} __no_const;
12921
12922 /**
12923 * struct x86_init_iommu - platform specific iommu setup
12924 @@ -109,7 +109,7 @@ struct x86_init_timers {
12925 */
12926 struct x86_init_iommu {
12927 int (*iommu_init)(void);
12928 -};
12929 +} __no_const;
12930
12931 /**
12932 * struct x86_init_pci - platform specific pci init functions
12933 @@ -123,7 +123,7 @@ struct x86_init_pci {
12934 int (*init)(void);
12935 void (*init_irq)(void);
12936 void (*fixup_irqs)(void);
12937 -};
12938 +} __no_const;
12939
12940 /**
12941 * struct x86_init_ops - functions for platform specific setup
12942 @@ -139,7 +139,7 @@ struct x86_init_ops {
12943 struct x86_init_timers timers;
12944 struct x86_init_iommu iommu;
12945 struct x86_init_pci pci;
12946 -};
12947 +} __no_const;
12948
12949 /**
12950 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
12951 @@ -147,7 +147,7 @@ struct x86_init_ops {
12952 */
12953 struct x86_cpuinit_ops {
12954 void (*setup_percpu_clockev)(void);
12955 -};
12956 +} __no_const;
12957
12958 /**
12959 * struct x86_platform_ops - platform specific runtime functions
12960 @@ -169,7 +169,7 @@ struct x86_platform_ops {
12961 void (*nmi_init)(void);
12962 unsigned char (*get_nmi_reason)(void);
12963 int (*i8042_detect)(void);
12964 -};
12965 +} __no_const;
12966
12967 struct pci_dev;
12968
12969 @@ -177,7 +177,7 @@ struct x86_msi_ops {
12970 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
12971 void (*teardown_msi_irq)(unsigned int irq);
12972 void (*teardown_msi_irqs)(struct pci_dev *dev);
12973 -};
12974 +} __no_const;
12975
12976 extern struct x86_init_ops x86_init;
12977 extern struct x86_cpuinit_ops x86_cpuinit;
12978 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
12979 index c6ce245..ffbdab7 100644
12980 --- a/arch/x86/include/asm/xsave.h
12981 +++ b/arch/x86/include/asm/xsave.h
12982 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12983 {
12984 int err;
12985
12986 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12987 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12988 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12989 +#endif
12990 +
12991 /*
12992 * Clear the xsave header first, so that reserved fields are
12993 * initialized to zero.
12994 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12995 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
12996 {
12997 int err;
12998 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
12999 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13000 u32 lmask = mask;
13001 u32 hmask = mask >> 32;
13002
13003 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13004 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13005 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13006 +#endif
13007 +
13008 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13009 "2:\n"
13010 ".section .fixup,\"ax\"\n"
13011 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13012 index 6a564ac..9b1340c 100644
13013 --- a/arch/x86/kernel/acpi/realmode/Makefile
13014 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13015 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13016 $(call cc-option, -fno-stack-protector) \
13017 $(call cc-option, -mpreferred-stack-boundary=2)
13018 KBUILD_CFLAGS += $(call cc-option, -m32)
13019 +ifdef CONSTIFY_PLUGIN
13020 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13021 +endif
13022 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13023 GCOV_PROFILE := n
13024
13025 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13026 index b4fd836..4358fe3 100644
13027 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13028 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13029 @@ -108,6 +108,9 @@ wakeup_code:
13030 /* Do any other stuff... */
13031
13032 #ifndef CONFIG_64BIT
13033 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13034 + call verify_cpu
13035 +
13036 /* This could also be done in C code... */
13037 movl pmode_cr3, %eax
13038 movl %eax, %cr3
13039 @@ -131,6 +134,7 @@ wakeup_code:
13040 movl pmode_cr0, %eax
13041 movl %eax, %cr0
13042 jmp pmode_return
13043 +# include "../../verify_cpu.S"
13044 #else
13045 pushw $0
13046 pushw trampoline_segment
13047 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13048 index 103b6ab..2004d0a 100644
13049 --- a/arch/x86/kernel/acpi/sleep.c
13050 +++ b/arch/x86/kernel/acpi/sleep.c
13051 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13052 header->trampoline_segment = trampoline_address() >> 4;
13053 #ifdef CONFIG_SMP
13054 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13055 +
13056 + pax_open_kernel();
13057 early_gdt_descr.address =
13058 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13059 + pax_close_kernel();
13060 +
13061 initial_gs = per_cpu_offset(smp_processor_id());
13062 #endif
13063 initial_code = (unsigned long)wakeup_long64;
13064 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13065 index 13ab720..95d5442 100644
13066 --- a/arch/x86/kernel/acpi/wakeup_32.S
13067 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13068 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13069 # and restore the stack ... but you need gdt for this to work
13070 movl saved_context_esp, %esp
13071
13072 - movl %cs:saved_magic, %eax
13073 - cmpl $0x12345678, %eax
13074 + cmpl $0x12345678, saved_magic
13075 jne bogus_magic
13076
13077 # jump to place where we left off
13078 - movl saved_eip, %eax
13079 - jmp *%eax
13080 + jmp *(saved_eip)
13081
13082 bogus_magic:
13083 jmp bogus_magic
13084 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13085 index 1f84794..e23f862 100644
13086 --- a/arch/x86/kernel/alternative.c
13087 +++ b/arch/x86/kernel/alternative.c
13088 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13089 */
13090 for (a = start; a < end; a++) {
13091 instr = (u8 *)&a->instr_offset + a->instr_offset;
13092 +
13093 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13094 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13095 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13096 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13097 +#endif
13098 +
13099 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13100 BUG_ON(a->replacementlen > a->instrlen);
13101 BUG_ON(a->instrlen > sizeof(insnbuf));
13102 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13103 for (poff = start; poff < end; poff++) {
13104 u8 *ptr = (u8 *)poff + *poff;
13105
13106 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13107 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13108 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13109 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13110 +#endif
13111 +
13112 if (!*poff || ptr < text || ptr >= text_end)
13113 continue;
13114 /* turn DS segment override prefix into lock prefix */
13115 - if (*ptr == 0x3e)
13116 + if (*ktla_ktva(ptr) == 0x3e)
13117 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13118 };
13119 mutex_unlock(&text_mutex);
13120 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13121 for (poff = start; poff < end; poff++) {
13122 u8 *ptr = (u8 *)poff + *poff;
13123
13124 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13125 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13126 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13127 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13128 +#endif
13129 +
13130 if (!*poff || ptr < text || ptr >= text_end)
13131 continue;
13132 /* turn lock prefix into DS segment override prefix */
13133 - if (*ptr == 0xf0)
13134 + if (*ktla_ktva(ptr) == 0xf0)
13135 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13136 };
13137 mutex_unlock(&text_mutex);
13138 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13139
13140 BUG_ON(p->len > MAX_PATCH_LEN);
13141 /* prep the buffer with the original instructions */
13142 - memcpy(insnbuf, p->instr, p->len);
13143 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13144 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13145 (unsigned long)p->instr, p->len);
13146
13147 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13148 if (smp_alt_once)
13149 free_init_pages("SMP alternatives",
13150 (unsigned long)__smp_locks,
13151 - (unsigned long)__smp_locks_end);
13152 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13153
13154 restart_nmi();
13155 }
13156 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13157 * instructions. And on the local CPU you need to be protected again NMI or MCE
13158 * handlers seeing an inconsistent instruction while you patch.
13159 */
13160 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13161 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13162 size_t len)
13163 {
13164 unsigned long flags;
13165 local_irq_save(flags);
13166 - memcpy(addr, opcode, len);
13167 +
13168 + pax_open_kernel();
13169 + memcpy(ktla_ktva(addr), opcode, len);
13170 sync_core();
13171 + pax_close_kernel();
13172 +
13173 local_irq_restore(flags);
13174 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13175 that causes hangs on some VIA CPUs. */
13176 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13177 */
13178 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13179 {
13180 - unsigned long flags;
13181 - char *vaddr;
13182 + unsigned char *vaddr = ktla_ktva(addr);
13183 struct page *pages[2];
13184 - int i;
13185 + size_t i;
13186
13187 if (!core_kernel_text((unsigned long)addr)) {
13188 - pages[0] = vmalloc_to_page(addr);
13189 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13190 + pages[0] = vmalloc_to_page(vaddr);
13191 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13192 } else {
13193 - pages[0] = virt_to_page(addr);
13194 + pages[0] = virt_to_page(vaddr);
13195 WARN_ON(!PageReserved(pages[0]));
13196 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13197 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13198 }
13199 BUG_ON(!pages[0]);
13200 - local_irq_save(flags);
13201 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13202 - if (pages[1])
13203 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13204 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13205 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13206 - clear_fixmap(FIX_TEXT_POKE0);
13207 - if (pages[1])
13208 - clear_fixmap(FIX_TEXT_POKE1);
13209 - local_flush_tlb();
13210 - sync_core();
13211 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13212 - that causes hangs on some VIA CPUs. */
13213 + text_poke_early(addr, opcode, len);
13214 for (i = 0; i < len; i++)
13215 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13216 - local_irq_restore(flags);
13217 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13218 return addr;
13219 }
13220
13221 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13222 index f98d84c..e402a69 100644
13223 --- a/arch/x86/kernel/apic/apic.c
13224 +++ b/arch/x86/kernel/apic/apic.c
13225 @@ -174,7 +174,7 @@ int first_system_vector = 0xfe;
13226 /*
13227 * Debug level, exported for io_apic.c
13228 */
13229 -unsigned int apic_verbosity;
13230 +int apic_verbosity;
13231
13232 int pic_mode;
13233
13234 @@ -1853,7 +1853,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13235 apic_write(APIC_ESR, 0);
13236 v1 = apic_read(APIC_ESR);
13237 ack_APIC_irq();
13238 - atomic_inc(&irq_err_count);
13239 + atomic_inc_unchecked(&irq_err_count);
13240
13241 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13242 smp_processor_id(), v0 , v1);
13243 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13244 index 6d939d7..0697fcc 100644
13245 --- a/arch/x86/kernel/apic/io_apic.c
13246 +++ b/arch/x86/kernel/apic/io_apic.c
13247 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13248 }
13249 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13250
13251 -void lock_vector_lock(void)
13252 +void lock_vector_lock(void) __acquires(vector_lock)
13253 {
13254 /* Used to the online set of cpus does not change
13255 * during assign_irq_vector.
13256 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13257 raw_spin_lock(&vector_lock);
13258 }
13259
13260 -void unlock_vector_lock(void)
13261 +void unlock_vector_lock(void) __releases(vector_lock)
13262 {
13263 raw_spin_unlock(&vector_lock);
13264 }
13265 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13266 ack_APIC_irq();
13267 }
13268
13269 -atomic_t irq_mis_count;
13270 +atomic_unchecked_t irq_mis_count;
13271
13272 static void ack_apic_level(struct irq_data *data)
13273 {
13274 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13275 * at the cpu.
13276 */
13277 if (!(v & (1 << (i & 0x1f)))) {
13278 - atomic_inc(&irq_mis_count);
13279 + atomic_inc_unchecked(&irq_mis_count);
13280
13281 eoi_ioapic_irq(irq, cfg);
13282 }
13283 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13284 index a46bd38..6b906d7 100644
13285 --- a/arch/x86/kernel/apm_32.c
13286 +++ b/arch/x86/kernel/apm_32.c
13287 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13288 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13289 * even though they are called in protected mode.
13290 */
13291 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13292 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13293 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13294
13295 static const char driver_version[] = "1.16ac"; /* no spaces */
13296 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13297 BUG_ON(cpu != 0);
13298 gdt = get_cpu_gdt_table(cpu);
13299 save_desc_40 = gdt[0x40 / 8];
13300 +
13301 + pax_open_kernel();
13302 gdt[0x40 / 8] = bad_bios_desc;
13303 + pax_close_kernel();
13304
13305 apm_irq_save(flags);
13306 APM_DO_SAVE_SEGS;
13307 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13308 &call->esi);
13309 APM_DO_RESTORE_SEGS;
13310 apm_irq_restore(flags);
13311 +
13312 + pax_open_kernel();
13313 gdt[0x40 / 8] = save_desc_40;
13314 + pax_close_kernel();
13315 +
13316 put_cpu();
13317
13318 return call->eax & 0xff;
13319 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13320 BUG_ON(cpu != 0);
13321 gdt = get_cpu_gdt_table(cpu);
13322 save_desc_40 = gdt[0x40 / 8];
13323 +
13324 + pax_open_kernel();
13325 gdt[0x40 / 8] = bad_bios_desc;
13326 + pax_close_kernel();
13327
13328 apm_irq_save(flags);
13329 APM_DO_SAVE_SEGS;
13330 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13331 &call->eax);
13332 APM_DO_RESTORE_SEGS;
13333 apm_irq_restore(flags);
13334 +
13335 + pax_open_kernel();
13336 gdt[0x40 / 8] = save_desc_40;
13337 + pax_close_kernel();
13338 +
13339 put_cpu();
13340 return error;
13341 }
13342 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13343 * code to that CPU.
13344 */
13345 gdt = get_cpu_gdt_table(0);
13346 +
13347 + pax_open_kernel();
13348 set_desc_base(&gdt[APM_CS >> 3],
13349 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13350 set_desc_base(&gdt[APM_CS_16 >> 3],
13351 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13352 set_desc_base(&gdt[APM_DS >> 3],
13353 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13354 + pax_close_kernel();
13355
13356 proc_create("apm", 0, NULL, &apm_file_ops);
13357
13358 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13359 index 4f13faf..87db5d2 100644
13360 --- a/arch/x86/kernel/asm-offsets.c
13361 +++ b/arch/x86/kernel/asm-offsets.c
13362 @@ -33,6 +33,8 @@ void common(void) {
13363 OFFSET(TI_status, thread_info, status);
13364 OFFSET(TI_addr_limit, thread_info, addr_limit);
13365 OFFSET(TI_preempt_count, thread_info, preempt_count);
13366 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13367 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13368
13369 BLANK();
13370 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13371 @@ -53,8 +55,26 @@ void common(void) {
13372 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13373 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13374 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13375 +
13376 +#ifdef CONFIG_PAX_KERNEXEC
13377 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13378 #endif
13379
13380 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13381 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13382 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13383 +#ifdef CONFIG_X86_64
13384 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13385 +#endif
13386 +#endif
13387 +
13388 +#endif
13389 +
13390 + BLANK();
13391 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13392 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13393 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13394 +
13395 #ifdef CONFIG_XEN
13396 BLANK();
13397 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13398 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13399 index e72a119..6e2955d 100644
13400 --- a/arch/x86/kernel/asm-offsets_64.c
13401 +++ b/arch/x86/kernel/asm-offsets_64.c
13402 @@ -69,6 +69,7 @@ int main(void)
13403 BLANK();
13404 #undef ENTRY
13405
13406 + DEFINE(TSS_size, sizeof(struct tss_struct));
13407 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13408 BLANK();
13409
13410 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13411 index 25f24dc..4094a7f 100644
13412 --- a/arch/x86/kernel/cpu/Makefile
13413 +++ b/arch/x86/kernel/cpu/Makefile
13414 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13415 CFLAGS_REMOVE_perf_event.o = -pg
13416 endif
13417
13418 -# Make sure load_percpu_segment has no stackprotector
13419 -nostackp := $(call cc-option, -fno-stack-protector)
13420 -CFLAGS_common.o := $(nostackp)
13421 -
13422 obj-y := intel_cacheinfo.o scattered.o topology.o
13423 obj-y += proc.o capflags.o powerflags.o common.o
13424 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13425 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13426 index 0bab2b1..d0a1bf8 100644
13427 --- a/arch/x86/kernel/cpu/amd.c
13428 +++ b/arch/x86/kernel/cpu/amd.c
13429 @@ -664,7 +664,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13430 unsigned int size)
13431 {
13432 /* AMD errata T13 (order #21922) */
13433 - if ((c->x86 == 6)) {
13434 + if (c->x86 == 6) {
13435 /* Duron Rev A0 */
13436 if (c->x86_model == 3 && c->x86_mask == 0)
13437 size = 64;
13438 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13439 index aa003b1..47ea638 100644
13440 --- a/arch/x86/kernel/cpu/common.c
13441 +++ b/arch/x86/kernel/cpu/common.c
13442 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13443
13444 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13445
13446 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13447 -#ifdef CONFIG_X86_64
13448 - /*
13449 - * We need valid kernel segments for data and code in long mode too
13450 - * IRET will check the segment types kkeil 2000/10/28
13451 - * Also sysret mandates a special GDT layout
13452 - *
13453 - * TLS descriptors are currently at a different place compared to i386.
13454 - * Hopefully nobody expects them at a fixed place (Wine?)
13455 - */
13456 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13457 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13458 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13459 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13460 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13461 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13462 -#else
13463 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13464 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13465 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13466 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13467 - /*
13468 - * Segments used for calling PnP BIOS have byte granularity.
13469 - * They code segments and data segments have fixed 64k limits,
13470 - * the transfer segment sizes are set at run time.
13471 - */
13472 - /* 32-bit code */
13473 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13474 - /* 16-bit code */
13475 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13476 - /* 16-bit data */
13477 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13478 - /* 16-bit data */
13479 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13480 - /* 16-bit data */
13481 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13482 - /*
13483 - * The APM segments have byte granularity and their bases
13484 - * are set at run time. All have 64k limits.
13485 - */
13486 - /* 32-bit code */
13487 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13488 - /* 16-bit code */
13489 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13490 - /* data */
13491 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13492 -
13493 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13494 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13495 - GDT_STACK_CANARY_INIT
13496 -#endif
13497 -} };
13498 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13499 -
13500 static int __init x86_xsave_setup(char *s)
13501 {
13502 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13503 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13504 {
13505 struct desc_ptr gdt_descr;
13506
13507 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13508 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13509 gdt_descr.size = GDT_SIZE - 1;
13510 load_gdt(&gdt_descr);
13511 /* Reload the per-cpu base */
13512 @@ -844,6 +790,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13513 /* Filter out anything that depends on CPUID levels we don't have */
13514 filter_cpuid_features(c, true);
13515
13516 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13517 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13518 +#endif
13519 +
13520 /* If the model name is still unset, do table lookup. */
13521 if (!c->x86_model_id[0]) {
13522 const char *p;
13523 @@ -1024,6 +974,9 @@ static __init int setup_disablecpuid(char *arg)
13524 }
13525 __setup("clearcpuid=", setup_disablecpuid);
13526
13527 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13528 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13529 +
13530 #ifdef CONFIG_X86_64
13531 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13532
13533 @@ -1039,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13534 EXPORT_PER_CPU_SYMBOL(current_task);
13535
13536 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13537 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13538 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13539 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13540
13541 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13542 @@ -1104,7 +1057,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13543 {
13544 memset(regs, 0, sizeof(struct pt_regs));
13545 regs->fs = __KERNEL_PERCPU;
13546 - regs->gs = __KERNEL_STACK_CANARY;
13547 + savesegment(gs, regs->gs);
13548
13549 return regs;
13550 }
13551 @@ -1159,7 +1112,7 @@ void __cpuinit cpu_init(void)
13552 int i;
13553
13554 cpu = stack_smp_processor_id();
13555 - t = &per_cpu(init_tss, cpu);
13556 + t = init_tss + cpu;
13557 oist = &per_cpu(orig_ist, cpu);
13558
13559 #ifdef CONFIG_NUMA
13560 @@ -1185,7 +1138,7 @@ void __cpuinit cpu_init(void)
13561 switch_to_new_gdt(cpu);
13562 loadsegment(fs, 0);
13563
13564 - load_idt((const struct desc_ptr *)&idt_descr);
13565 + load_idt(&idt_descr);
13566
13567 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13568 syscall_init();
13569 @@ -1194,7 +1147,6 @@ void __cpuinit cpu_init(void)
13570 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13571 barrier();
13572
13573 - x86_configure_nx();
13574 if (cpu != 0)
13575 enable_x2apic();
13576
13577 @@ -1248,7 +1200,7 @@ void __cpuinit cpu_init(void)
13578 {
13579 int cpu = smp_processor_id();
13580 struct task_struct *curr = current;
13581 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13582 + struct tss_struct *t = init_tss + cpu;
13583 struct thread_struct *thread = &curr->thread;
13584
13585 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13586 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13587 index 5231312..a78a987 100644
13588 --- a/arch/x86/kernel/cpu/intel.c
13589 +++ b/arch/x86/kernel/cpu/intel.c
13590 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13591 * Update the IDT descriptor and reload the IDT so that
13592 * it uses the read-only mapped virtual address.
13593 */
13594 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13595 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13596 load_idt(&idt_descr);
13597 }
13598 #endif
13599 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13600 index 2af127d..8ff7ac0 100644
13601 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13602 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13603 @@ -42,6 +42,7 @@
13604 #include <asm/processor.h>
13605 #include <asm/mce.h>
13606 #include <asm/msr.h>
13607 +#include <asm/local.h>
13608
13609 #include "mce-internal.h"
13610
13611 @@ -202,7 +203,7 @@ static void print_mce(struct mce *m)
13612 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13613 m->cs, m->ip);
13614
13615 - if (m->cs == __KERNEL_CS)
13616 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13617 print_symbol("{%s}", m->ip);
13618 pr_cont("\n");
13619 }
13620 @@ -235,10 +236,10 @@ static void print_mce(struct mce *m)
13621
13622 #define PANIC_TIMEOUT 5 /* 5 seconds */
13623
13624 -static atomic_t mce_paniced;
13625 +static atomic_unchecked_t mce_paniced;
13626
13627 static int fake_panic;
13628 -static atomic_t mce_fake_paniced;
13629 +static atomic_unchecked_t mce_fake_paniced;
13630
13631 /* Panic in progress. Enable interrupts and wait for final IPI */
13632 static void wait_for_panic(void)
13633 @@ -262,7 +263,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13634 /*
13635 * Make sure only one CPU runs in machine check panic
13636 */
13637 - if (atomic_inc_return(&mce_paniced) > 1)
13638 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13639 wait_for_panic();
13640 barrier();
13641
13642 @@ -270,7 +271,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13643 console_verbose();
13644 } else {
13645 /* Don't log too much for fake panic */
13646 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13647 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13648 return;
13649 }
13650 /* First print corrected ones that are still unlogged */
13651 @@ -610,7 +611,7 @@ static int mce_timed_out(u64 *t)
13652 * might have been modified by someone else.
13653 */
13654 rmb();
13655 - if (atomic_read(&mce_paniced))
13656 + if (atomic_read_unchecked(&mce_paniced))
13657 wait_for_panic();
13658 if (!monarch_timeout)
13659 goto out;
13660 @@ -1398,7 +1399,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13661 }
13662
13663 /* Call the installed machine check handler for this CPU setup. */
13664 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13665 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13666 unexpected_machine_check;
13667
13668 /*
13669 @@ -1421,7 +1422,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13670 return;
13671 }
13672
13673 + pax_open_kernel();
13674 machine_check_vector = do_machine_check;
13675 + pax_close_kernel();
13676
13677 __mcheck_cpu_init_generic();
13678 __mcheck_cpu_init_vendor(c);
13679 @@ -1435,7 +1438,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13680 */
13681
13682 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13683 -static int mce_chrdev_open_count; /* #times opened */
13684 +static local_t mce_chrdev_open_count; /* #times opened */
13685 static int mce_chrdev_open_exclu; /* already open exclusive? */
13686
13687 static int mce_chrdev_open(struct inode *inode, struct file *file)
13688 @@ -1443,7 +1446,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13689 spin_lock(&mce_chrdev_state_lock);
13690
13691 if (mce_chrdev_open_exclu ||
13692 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13693 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13694 spin_unlock(&mce_chrdev_state_lock);
13695
13696 return -EBUSY;
13697 @@ -1451,7 +1454,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13698
13699 if (file->f_flags & O_EXCL)
13700 mce_chrdev_open_exclu = 1;
13701 - mce_chrdev_open_count++;
13702 + local_inc(&mce_chrdev_open_count);
13703
13704 spin_unlock(&mce_chrdev_state_lock);
13705
13706 @@ -1462,7 +1465,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13707 {
13708 spin_lock(&mce_chrdev_state_lock);
13709
13710 - mce_chrdev_open_count--;
13711 + local_dec(&mce_chrdev_open_count);
13712 mce_chrdev_open_exclu = 0;
13713
13714 spin_unlock(&mce_chrdev_state_lock);
13715 @@ -2171,7 +2174,7 @@ struct dentry *mce_get_debugfs_dir(void)
13716 static void mce_reset(void)
13717 {
13718 cpu_missing = 0;
13719 - atomic_set(&mce_fake_paniced, 0);
13720 + atomic_set_unchecked(&mce_fake_paniced, 0);
13721 atomic_set(&mce_executing, 0);
13722 atomic_set(&mce_callin, 0);
13723 atomic_set(&global_nwo, 0);
13724 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13725 index 5c0e653..0882b0a 100644
13726 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13727 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13728 @@ -12,6 +12,7 @@
13729 #include <asm/system.h>
13730 #include <asm/mce.h>
13731 #include <asm/msr.h>
13732 +#include <asm/pgtable.h>
13733
13734 /* By default disabled */
13735 int mce_p5_enabled __read_mostly;
13736 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13737 if (!cpu_has(c, X86_FEATURE_MCE))
13738 return;
13739
13740 + pax_open_kernel();
13741 machine_check_vector = pentium_machine_check;
13742 + pax_close_kernel();
13743 /* Make sure the vector pointer is visible before we enable MCEs: */
13744 wmb();
13745
13746 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13747 index 54060f5..c1a7577 100644
13748 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13749 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13750 @@ -11,6 +11,7 @@
13751 #include <asm/system.h>
13752 #include <asm/mce.h>
13753 #include <asm/msr.h>
13754 +#include <asm/pgtable.h>
13755
13756 /* Machine check handler for WinChip C6: */
13757 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13758 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13759 {
13760 u32 lo, hi;
13761
13762 + pax_open_kernel();
13763 machine_check_vector = winchip_machine_check;
13764 + pax_close_kernel();
13765 /* Make sure the vector pointer is visible before we enable MCEs: */
13766 wmb();
13767
13768 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13769 index 6b96110..0da73eb 100644
13770 --- a/arch/x86/kernel/cpu/mtrr/main.c
13771 +++ b/arch/x86/kernel/cpu/mtrr/main.c
13772 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13773 u64 size_or_mask, size_and_mask;
13774 static bool mtrr_aps_delayed_init;
13775
13776 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13777 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13778
13779 const struct mtrr_ops *mtrr_if;
13780
13781 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13782 index df5e41f..816c719 100644
13783 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13784 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13785 @@ -25,7 +25,7 @@ struct mtrr_ops {
13786 int (*validate_add_page)(unsigned long base, unsigned long size,
13787 unsigned int type);
13788 int (*have_wrcomb)(void);
13789 -};
13790 +} __do_const;
13791
13792 extern int generic_get_free_region(unsigned long base, unsigned long size,
13793 int replace_reg);
13794 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13795 index 2bda212..78cc605 100644
13796 --- a/arch/x86/kernel/cpu/perf_event.c
13797 +++ b/arch/x86/kernel/cpu/perf_event.c
13798 @@ -1529,7 +1529,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13799 break;
13800
13801 perf_callchain_store(entry, frame.return_address);
13802 - fp = frame.next_frame;
13803 + fp = (const void __force_user *)frame.next_frame;
13804 }
13805 }
13806
13807 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
13808 index 13ad899..f642b9a 100644
13809 --- a/arch/x86/kernel/crash.c
13810 +++ b/arch/x86/kernel/crash.c
13811 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
13812 {
13813 #ifdef CONFIG_X86_32
13814 struct pt_regs fixed_regs;
13815 -#endif
13816
13817 -#ifdef CONFIG_X86_32
13818 - if (!user_mode_vm(regs)) {
13819 + if (!user_mode(regs)) {
13820 crash_fixup_ss_esp(&fixed_regs, regs);
13821 regs = &fixed_regs;
13822 }
13823 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
13824 index 37250fe..bf2ec74 100644
13825 --- a/arch/x86/kernel/doublefault_32.c
13826 +++ b/arch/x86/kernel/doublefault_32.c
13827 @@ -11,7 +11,7 @@
13828
13829 #define DOUBLEFAULT_STACKSIZE (1024)
13830 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13831 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13832 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13833
13834 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13835
13836 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
13837 unsigned long gdt, tss;
13838
13839 store_gdt(&gdt_desc);
13840 - gdt = gdt_desc.address;
13841 + gdt = (unsigned long)gdt_desc.address;
13842
13843 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13844
13845 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
13846 /* 0x2 bit is always set */
13847 .flags = X86_EFLAGS_SF | 0x2,
13848 .sp = STACK_START,
13849 - .es = __USER_DS,
13850 + .es = __KERNEL_DS,
13851 .cs = __KERNEL_CS,
13852 .ss = __KERNEL_DS,
13853 - .ds = __USER_DS,
13854 + .ds = __KERNEL_DS,
13855 .fs = __KERNEL_PERCPU,
13856
13857 .__cr3 = __pa_nodebug(swapper_pg_dir),
13858 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
13859 index 1aae78f..aab3a3d 100644
13860 --- a/arch/x86/kernel/dumpstack.c
13861 +++ b/arch/x86/kernel/dumpstack.c
13862 @@ -2,6 +2,9 @@
13863 * Copyright (C) 1991, 1992 Linus Torvalds
13864 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13865 */
13866 +#ifdef CONFIG_GRKERNSEC_HIDESYM
13867 +#define __INCLUDED_BY_HIDESYM 1
13868 +#endif
13869 #include <linux/kallsyms.h>
13870 #include <linux/kprobes.h>
13871 #include <linux/uaccess.h>
13872 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
13873 static void
13874 print_ftrace_graph_addr(unsigned long addr, void *data,
13875 const struct stacktrace_ops *ops,
13876 - struct thread_info *tinfo, int *graph)
13877 + struct task_struct *task, int *graph)
13878 {
13879 - struct task_struct *task = tinfo->task;
13880 unsigned long ret_addr;
13881 int index = task->curr_ret_stack;
13882
13883 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13884 static inline void
13885 print_ftrace_graph_addr(unsigned long addr, void *data,
13886 const struct stacktrace_ops *ops,
13887 - struct thread_info *tinfo, int *graph)
13888 + struct task_struct *task, int *graph)
13889 { }
13890 #endif
13891
13892 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13893 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13894 */
13895
13896 -static inline int valid_stack_ptr(struct thread_info *tinfo,
13897 - void *p, unsigned int size, void *end)
13898 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13899 {
13900 - void *t = tinfo;
13901 if (end) {
13902 if (p < end && p >= (end-THREAD_SIZE))
13903 return 1;
13904 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
13905 }
13906
13907 unsigned long
13908 -print_context_stack(struct thread_info *tinfo,
13909 +print_context_stack(struct task_struct *task, void *stack_start,
13910 unsigned long *stack, unsigned long bp,
13911 const struct stacktrace_ops *ops, void *data,
13912 unsigned long *end, int *graph)
13913 {
13914 struct stack_frame *frame = (struct stack_frame *)bp;
13915
13916 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13917 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13918 unsigned long addr;
13919
13920 addr = *stack;
13921 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
13922 } else {
13923 ops->address(data, addr, 0);
13924 }
13925 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13926 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13927 }
13928 stack++;
13929 }
13930 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
13931 EXPORT_SYMBOL_GPL(print_context_stack);
13932
13933 unsigned long
13934 -print_context_stack_bp(struct thread_info *tinfo,
13935 +print_context_stack_bp(struct task_struct *task, void *stack_start,
13936 unsigned long *stack, unsigned long bp,
13937 const struct stacktrace_ops *ops, void *data,
13938 unsigned long *end, int *graph)
13939 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13940 struct stack_frame *frame = (struct stack_frame *)bp;
13941 unsigned long *ret_addr = &frame->return_address;
13942
13943 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13944 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13945 unsigned long addr = *ret_addr;
13946
13947 if (!__kernel_text_address(addr))
13948 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13949 ops->address(data, addr, 1);
13950 frame = frame->next_frame;
13951 ret_addr = &frame->return_address;
13952 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13953 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13954 }
13955
13956 return (unsigned long)frame;
13957 @@ -186,7 +186,7 @@ void dump_stack(void)
13958
13959 bp = stack_frame(current, NULL);
13960 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13961 - current->pid, current->comm, print_tainted(),
13962 + task_pid_nr(current), current->comm, print_tainted(),
13963 init_utsname()->release,
13964 (int)strcspn(init_utsname()->version, " "),
13965 init_utsname()->version);
13966 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
13967 }
13968 EXPORT_SYMBOL_GPL(oops_begin);
13969
13970 +extern void gr_handle_kernel_exploit(void);
13971 +
13972 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13973 {
13974 if (regs && kexec_should_crash(current))
13975 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13976 panic("Fatal exception in interrupt");
13977 if (panic_on_oops)
13978 panic("Fatal exception");
13979 - do_exit(signr);
13980 +
13981 + gr_handle_kernel_exploit();
13982 +
13983 + do_group_exit(signr);
13984 }
13985
13986 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13987 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13988
13989 show_registers(regs);
13990 #ifdef CONFIG_X86_32
13991 - if (user_mode_vm(regs)) {
13992 + if (user_mode(regs)) {
13993 sp = regs->sp;
13994 ss = regs->ss & 0xffff;
13995 } else {
13996 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
13997 unsigned long flags = oops_begin();
13998 int sig = SIGSEGV;
13999
14000 - if (!user_mode_vm(regs))
14001 + if (!user_mode(regs))
14002 report_bug(regs->ip, regs);
14003
14004 if (__die(str, regs, err))
14005 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14006 index c99f9ed..2a15d80 100644
14007 --- a/arch/x86/kernel/dumpstack_32.c
14008 +++ b/arch/x86/kernel/dumpstack_32.c
14009 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14010 bp = stack_frame(task, regs);
14011
14012 for (;;) {
14013 - struct thread_info *context;
14014 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14015
14016 - context = (struct thread_info *)
14017 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14018 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14019 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14020
14021 - stack = (unsigned long *)context->previous_esp;
14022 - if (!stack)
14023 + if (stack_start == task_stack_page(task))
14024 break;
14025 + stack = *(unsigned long **)stack_start;
14026 if (ops->stack(data, "IRQ") < 0)
14027 break;
14028 touch_nmi_watchdog();
14029 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14030 * When in-kernel, we also print out the stack and code at the
14031 * time of the fault..
14032 */
14033 - if (!user_mode_vm(regs)) {
14034 + if (!user_mode(regs)) {
14035 unsigned int code_prologue = code_bytes * 43 / 64;
14036 unsigned int code_len = code_bytes;
14037 unsigned char c;
14038 u8 *ip;
14039 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14040
14041 printk(KERN_EMERG "Stack:\n");
14042 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14043
14044 printk(KERN_EMERG "Code: ");
14045
14046 - ip = (u8 *)regs->ip - code_prologue;
14047 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14048 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14049 /* try starting at IP */
14050 - ip = (u8 *)regs->ip;
14051 + ip = (u8 *)regs->ip + cs_base;
14052 code_len = code_len - code_prologue + 1;
14053 }
14054 for (i = 0; i < code_len; i++, ip++) {
14055 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14056 printk(KERN_CONT " Bad EIP value.");
14057 break;
14058 }
14059 - if (ip == (u8 *)regs->ip)
14060 + if (ip == (u8 *)regs->ip + cs_base)
14061 printk(KERN_CONT "<%02x> ", c);
14062 else
14063 printk(KERN_CONT "%02x ", c);
14064 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14065 {
14066 unsigned short ud2;
14067
14068 + ip = ktla_ktva(ip);
14069 if (ip < PAGE_OFFSET)
14070 return 0;
14071 if (probe_kernel_address((unsigned short *)ip, ud2))
14072 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14073
14074 return ud2 == 0x0b0f;
14075 }
14076 +
14077 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14078 +void pax_check_alloca(unsigned long size)
14079 +{
14080 + unsigned long sp = (unsigned long)&sp, stack_left;
14081 +
14082 + /* all kernel stacks are of the same size */
14083 + stack_left = sp & (THREAD_SIZE - 1);
14084 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14085 +}
14086 +EXPORT_SYMBOL(pax_check_alloca);
14087 +#endif
14088 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14089 index 6d728d9..279514e 100644
14090 --- a/arch/x86/kernel/dumpstack_64.c
14091 +++ b/arch/x86/kernel/dumpstack_64.c
14092 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14093 unsigned long *irq_stack_end =
14094 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14095 unsigned used = 0;
14096 - struct thread_info *tinfo;
14097 int graph = 0;
14098 unsigned long dummy;
14099 + void *stack_start;
14100
14101 if (!task)
14102 task = current;
14103 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14104 * current stack address. If the stacks consist of nested
14105 * exceptions
14106 */
14107 - tinfo = task_thread_info(task);
14108 for (;;) {
14109 char *id;
14110 unsigned long *estack_end;
14111 +
14112 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14113 &used, &id);
14114
14115 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14116 if (ops->stack(data, id) < 0)
14117 break;
14118
14119 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14120 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14121 data, estack_end, &graph);
14122 ops->stack(data, "<EOE>");
14123 /*
14124 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14125 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14126 if (ops->stack(data, "IRQ") < 0)
14127 break;
14128 - bp = ops->walk_stack(tinfo, stack, bp,
14129 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14130 ops, data, irq_stack_end, &graph);
14131 /*
14132 * We link to the next stack (which would be
14133 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14134 /*
14135 * This handles the process stack:
14136 */
14137 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14138 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14139 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14140 put_cpu();
14141 }
14142 EXPORT_SYMBOL(dump_trace);
14143 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14144
14145 return ud2 == 0x0b0f;
14146 }
14147 +
14148 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14149 +void pax_check_alloca(unsigned long size)
14150 +{
14151 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14152 + unsigned cpu, used;
14153 + char *id;
14154 +
14155 + /* check the process stack first */
14156 + stack_start = (unsigned long)task_stack_page(current);
14157 + stack_end = stack_start + THREAD_SIZE;
14158 + if (likely(stack_start <= sp && sp < stack_end)) {
14159 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14160 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14161 + return;
14162 + }
14163 +
14164 + cpu = get_cpu();
14165 +
14166 + /* check the irq stacks */
14167 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14168 + stack_start = stack_end - IRQ_STACK_SIZE;
14169 + if (stack_start <= sp && sp < stack_end) {
14170 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14171 + put_cpu();
14172 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14173 + return;
14174 + }
14175 +
14176 + /* check the exception stacks */
14177 + used = 0;
14178 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14179 + stack_start = stack_end - EXCEPTION_STKSZ;
14180 + if (stack_end && stack_start <= sp && sp < stack_end) {
14181 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14182 + put_cpu();
14183 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14184 + return;
14185 + }
14186 +
14187 + put_cpu();
14188 +
14189 + /* unknown stack */
14190 + BUG();
14191 +}
14192 +EXPORT_SYMBOL(pax_check_alloca);
14193 +#endif
14194 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14195 index cd28a35..c72ed9a 100644
14196 --- a/arch/x86/kernel/early_printk.c
14197 +++ b/arch/x86/kernel/early_printk.c
14198 @@ -7,6 +7,7 @@
14199 #include <linux/pci_regs.h>
14200 #include <linux/pci_ids.h>
14201 #include <linux/errno.h>
14202 +#include <linux/sched.h>
14203 #include <asm/io.h>
14204 #include <asm/processor.h>
14205 #include <asm/fcntl.h>
14206 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14207 index f3f6f53..0841b66 100644
14208 --- a/arch/x86/kernel/entry_32.S
14209 +++ b/arch/x86/kernel/entry_32.S
14210 @@ -186,13 +186,146 @@
14211 /*CFI_REL_OFFSET gs, PT_GS*/
14212 .endm
14213 .macro SET_KERNEL_GS reg
14214 +
14215 +#ifdef CONFIG_CC_STACKPROTECTOR
14216 movl $(__KERNEL_STACK_CANARY), \reg
14217 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14218 + movl $(__USER_DS), \reg
14219 +#else
14220 + xorl \reg, \reg
14221 +#endif
14222 +
14223 movl \reg, %gs
14224 .endm
14225
14226 #endif /* CONFIG_X86_32_LAZY_GS */
14227
14228 -.macro SAVE_ALL
14229 +.macro pax_enter_kernel
14230 +#ifdef CONFIG_PAX_KERNEXEC
14231 + call pax_enter_kernel
14232 +#endif
14233 +.endm
14234 +
14235 +.macro pax_exit_kernel
14236 +#ifdef CONFIG_PAX_KERNEXEC
14237 + call pax_exit_kernel
14238 +#endif
14239 +.endm
14240 +
14241 +#ifdef CONFIG_PAX_KERNEXEC
14242 +ENTRY(pax_enter_kernel)
14243 +#ifdef CONFIG_PARAVIRT
14244 + pushl %eax
14245 + pushl %ecx
14246 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14247 + mov %eax, %esi
14248 +#else
14249 + mov %cr0, %esi
14250 +#endif
14251 + bts $16, %esi
14252 + jnc 1f
14253 + mov %cs, %esi
14254 + cmp $__KERNEL_CS, %esi
14255 + jz 3f
14256 + ljmp $__KERNEL_CS, $3f
14257 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14258 +2:
14259 +#ifdef CONFIG_PARAVIRT
14260 + mov %esi, %eax
14261 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14262 +#else
14263 + mov %esi, %cr0
14264 +#endif
14265 +3:
14266 +#ifdef CONFIG_PARAVIRT
14267 + popl %ecx
14268 + popl %eax
14269 +#endif
14270 + ret
14271 +ENDPROC(pax_enter_kernel)
14272 +
14273 +ENTRY(pax_exit_kernel)
14274 +#ifdef CONFIG_PARAVIRT
14275 + pushl %eax
14276 + pushl %ecx
14277 +#endif
14278 + mov %cs, %esi
14279 + cmp $__KERNEXEC_KERNEL_CS, %esi
14280 + jnz 2f
14281 +#ifdef CONFIG_PARAVIRT
14282 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14283 + mov %eax, %esi
14284 +#else
14285 + mov %cr0, %esi
14286 +#endif
14287 + btr $16, %esi
14288 + ljmp $__KERNEL_CS, $1f
14289 +1:
14290 +#ifdef CONFIG_PARAVIRT
14291 + mov %esi, %eax
14292 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14293 +#else
14294 + mov %esi, %cr0
14295 +#endif
14296 +2:
14297 +#ifdef CONFIG_PARAVIRT
14298 + popl %ecx
14299 + popl %eax
14300 +#endif
14301 + ret
14302 +ENDPROC(pax_exit_kernel)
14303 +#endif
14304 +
14305 +.macro pax_erase_kstack
14306 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14307 + call pax_erase_kstack
14308 +#endif
14309 +.endm
14310 +
14311 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14312 +/*
14313 + * ebp: thread_info
14314 + * ecx, edx: can be clobbered
14315 + */
14316 +ENTRY(pax_erase_kstack)
14317 + pushl %edi
14318 + pushl %eax
14319 +
14320 + mov TI_lowest_stack(%ebp), %edi
14321 + mov $-0xBEEF, %eax
14322 + std
14323 +
14324 +1: mov %edi, %ecx
14325 + and $THREAD_SIZE_asm - 1, %ecx
14326 + shr $2, %ecx
14327 + repne scasl
14328 + jecxz 2f
14329 +
14330 + cmp $2*16, %ecx
14331 + jc 2f
14332 +
14333 + mov $2*16, %ecx
14334 + repe scasl
14335 + jecxz 2f
14336 + jne 1b
14337 +
14338 +2: cld
14339 + mov %esp, %ecx
14340 + sub %edi, %ecx
14341 + shr $2, %ecx
14342 + rep stosl
14343 +
14344 + mov TI_task_thread_sp0(%ebp), %edi
14345 + sub $128, %edi
14346 + mov %edi, TI_lowest_stack(%ebp)
14347 +
14348 + popl %eax
14349 + popl %edi
14350 + ret
14351 +ENDPROC(pax_erase_kstack)
14352 +#endif
14353 +
14354 +.macro __SAVE_ALL _DS
14355 cld
14356 PUSH_GS
14357 pushl_cfi %fs
14358 @@ -215,7 +348,7 @@
14359 CFI_REL_OFFSET ecx, 0
14360 pushl_cfi %ebx
14361 CFI_REL_OFFSET ebx, 0
14362 - movl $(__USER_DS), %edx
14363 + movl $\_DS, %edx
14364 movl %edx, %ds
14365 movl %edx, %es
14366 movl $(__KERNEL_PERCPU), %edx
14367 @@ -223,6 +356,15 @@
14368 SET_KERNEL_GS %edx
14369 .endm
14370
14371 +.macro SAVE_ALL
14372 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14373 + __SAVE_ALL __KERNEL_DS
14374 + pax_enter_kernel
14375 +#else
14376 + __SAVE_ALL __USER_DS
14377 +#endif
14378 +.endm
14379 +
14380 .macro RESTORE_INT_REGS
14381 popl_cfi %ebx
14382 CFI_RESTORE ebx
14383 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
14384 popfl_cfi
14385 jmp syscall_exit
14386 CFI_ENDPROC
14387 -END(ret_from_fork)
14388 +ENDPROC(ret_from_fork)
14389
14390 /*
14391 * Interrupt exit functions should be protected against kprobes
14392 @@ -333,7 +475,15 @@ check_userspace:
14393 movb PT_CS(%esp), %al
14394 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
14395 cmpl $USER_RPL, %eax
14396 +
14397 +#ifdef CONFIG_PAX_KERNEXEC
14398 + jae resume_userspace
14399 +
14400 + PAX_EXIT_KERNEL
14401 + jmp resume_kernel
14402 +#else
14403 jb resume_kernel # not returning to v8086 or userspace
14404 +#endif
14405
14406 ENTRY(resume_userspace)
14407 LOCKDEP_SYS_EXIT
14408 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
14409 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14410 # int/exception return?
14411 jne work_pending
14412 - jmp restore_all
14413 -END(ret_from_exception)
14414 + jmp restore_all_pax
14415 +ENDPROC(ret_from_exception)
14416
14417 #ifdef CONFIG_PREEMPT
14418 ENTRY(resume_kernel)
14419 @@ -361,7 +511,7 @@ need_resched:
14420 jz restore_all
14421 call preempt_schedule_irq
14422 jmp need_resched
14423 -END(resume_kernel)
14424 +ENDPROC(resume_kernel)
14425 #endif
14426 CFI_ENDPROC
14427 /*
14428 @@ -395,23 +545,34 @@ sysenter_past_esp:
14429 /*CFI_REL_OFFSET cs, 0*/
14430 /*
14431 * Push current_thread_info()->sysenter_return to the stack.
14432 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14433 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14434 */
14435 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14436 + pushl_cfi $0
14437 CFI_REL_OFFSET eip, 0
14438
14439 pushl_cfi %eax
14440 SAVE_ALL
14441 + GET_THREAD_INFO(%ebp)
14442 + movl TI_sysenter_return(%ebp),%ebp
14443 + movl %ebp,PT_EIP(%esp)
14444 ENABLE_INTERRUPTS(CLBR_NONE)
14445
14446 /*
14447 * Load the potential sixth argument from user stack.
14448 * Careful about security.
14449 */
14450 + movl PT_OLDESP(%esp),%ebp
14451 +
14452 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14453 + mov PT_OLDSS(%esp),%ds
14454 +1: movl %ds:(%ebp),%ebp
14455 + push %ss
14456 + pop %ds
14457 +#else
14458 cmpl $__PAGE_OFFSET-3,%ebp
14459 jae syscall_fault
14460 1: movl (%ebp),%ebp
14461 +#endif
14462 +
14463 movl %ebp,PT_EBP(%esp)
14464 .section __ex_table,"a"
14465 .align 4
14466 @@ -434,12 +595,24 @@ sysenter_do_call:
14467 testl $_TIF_ALLWORK_MASK, %ecx
14468 jne sysexit_audit
14469 sysenter_exit:
14470 +
14471 +#ifdef CONFIG_PAX_RANDKSTACK
14472 + pushl_cfi %eax
14473 + movl %esp, %eax
14474 + call pax_randomize_kstack
14475 + popl_cfi %eax
14476 +#endif
14477 +
14478 + pax_erase_kstack
14479 +
14480 /* if something modifies registers it must also disable sysexit */
14481 movl PT_EIP(%esp), %edx
14482 movl PT_OLDESP(%esp), %ecx
14483 xorl %ebp,%ebp
14484 TRACE_IRQS_ON
14485 1: mov PT_FS(%esp), %fs
14486 +2: mov PT_DS(%esp), %ds
14487 +3: mov PT_ES(%esp), %es
14488 PTGS_TO_GS
14489 ENABLE_INTERRUPTS_SYSEXIT
14490
14491 @@ -456,6 +629,9 @@ sysenter_audit:
14492 movl %eax,%edx /* 2nd arg: syscall number */
14493 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14494 call audit_syscall_entry
14495 +
14496 + pax_erase_kstack
14497 +
14498 pushl_cfi %ebx
14499 movl PT_EAX(%esp),%eax /* reload syscall number */
14500 jmp sysenter_do_call
14501 @@ -482,11 +658,17 @@ sysexit_audit:
14502
14503 CFI_ENDPROC
14504 .pushsection .fixup,"ax"
14505 -2: movl $0,PT_FS(%esp)
14506 +4: movl $0,PT_FS(%esp)
14507 + jmp 1b
14508 +5: movl $0,PT_DS(%esp)
14509 + jmp 1b
14510 +6: movl $0,PT_ES(%esp)
14511 jmp 1b
14512 .section __ex_table,"a"
14513 .align 4
14514 - .long 1b,2b
14515 + .long 1b,4b
14516 + .long 2b,5b
14517 + .long 3b,6b
14518 .popsection
14519 PTGS_TO_GS_EX
14520 ENDPROC(ia32_sysenter_target)
14521 @@ -519,6 +701,15 @@ syscall_exit:
14522 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14523 jne syscall_exit_work
14524
14525 +restore_all_pax:
14526 +
14527 +#ifdef CONFIG_PAX_RANDKSTACK
14528 + movl %esp, %eax
14529 + call pax_randomize_kstack
14530 +#endif
14531 +
14532 + pax_erase_kstack
14533 +
14534 restore_all:
14535 TRACE_IRQS_IRET
14536 restore_all_notrace:
14537 @@ -578,14 +769,34 @@ ldt_ss:
14538 * compensating for the offset by changing to the ESPFIX segment with
14539 * a base address that matches for the difference.
14540 */
14541 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14542 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14543 mov %esp, %edx /* load kernel esp */
14544 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14545 mov %dx, %ax /* eax: new kernel esp */
14546 sub %eax, %edx /* offset (low word is 0) */
14547 +#ifdef CONFIG_SMP
14548 + movl PER_CPU_VAR(cpu_number), %ebx
14549 + shll $PAGE_SHIFT_asm, %ebx
14550 + addl $cpu_gdt_table, %ebx
14551 +#else
14552 + movl $cpu_gdt_table, %ebx
14553 +#endif
14554 shr $16, %edx
14555 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14556 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14557 +
14558 +#ifdef CONFIG_PAX_KERNEXEC
14559 + mov %cr0, %esi
14560 + btr $16, %esi
14561 + mov %esi, %cr0
14562 +#endif
14563 +
14564 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14565 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14566 +
14567 +#ifdef CONFIG_PAX_KERNEXEC
14568 + bts $16, %esi
14569 + mov %esi, %cr0
14570 +#endif
14571 +
14572 pushl_cfi $__ESPFIX_SS
14573 pushl_cfi %eax /* new kernel esp */
14574 /* Disable interrupts, but do not irqtrace this section: we
14575 @@ -614,34 +825,28 @@ work_resched:
14576 movl TI_flags(%ebp), %ecx
14577 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14578 # than syscall tracing?
14579 - jz restore_all
14580 + jz restore_all_pax
14581 testb $_TIF_NEED_RESCHED, %cl
14582 jnz work_resched
14583
14584 work_notifysig: # deal with pending signals and
14585 # notify-resume requests
14586 + movl %esp, %eax
14587 #ifdef CONFIG_VM86
14588 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14589 - movl %esp, %eax
14590 - jne work_notifysig_v86 # returning to kernel-space or
14591 + jz 1f # returning to kernel-space or
14592 # vm86-space
14593 - xorl %edx, %edx
14594 - call do_notify_resume
14595 - jmp resume_userspace_sig
14596
14597 - ALIGN
14598 -work_notifysig_v86:
14599 pushl_cfi %ecx # save ti_flags for do_notify_resume
14600 call save_v86_state # %eax contains pt_regs pointer
14601 popl_cfi %ecx
14602 movl %eax, %esp
14603 -#else
14604 - movl %esp, %eax
14605 +1:
14606 #endif
14607 xorl %edx, %edx
14608 call do_notify_resume
14609 jmp resume_userspace_sig
14610 -END(work_pending)
14611 +ENDPROC(work_pending)
14612
14613 # perform syscall exit tracing
14614 ALIGN
14615 @@ -649,11 +854,14 @@ syscall_trace_entry:
14616 movl $-ENOSYS,PT_EAX(%esp)
14617 movl %esp, %eax
14618 call syscall_trace_enter
14619 +
14620 + pax_erase_kstack
14621 +
14622 /* What it returned is what we'll actually use. */
14623 cmpl $(nr_syscalls), %eax
14624 jnae syscall_call
14625 jmp syscall_exit
14626 -END(syscall_trace_entry)
14627 +ENDPROC(syscall_trace_entry)
14628
14629 # perform syscall exit tracing
14630 ALIGN
14631 @@ -666,20 +874,24 @@ syscall_exit_work:
14632 movl %esp, %eax
14633 call syscall_trace_leave
14634 jmp resume_userspace
14635 -END(syscall_exit_work)
14636 +ENDPROC(syscall_exit_work)
14637 CFI_ENDPROC
14638
14639 RING0_INT_FRAME # can't unwind into user space anyway
14640 syscall_fault:
14641 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14642 + push %ss
14643 + pop %ds
14644 +#endif
14645 GET_THREAD_INFO(%ebp)
14646 movl $-EFAULT,PT_EAX(%esp)
14647 jmp resume_userspace
14648 -END(syscall_fault)
14649 +ENDPROC(syscall_fault)
14650
14651 syscall_badsys:
14652 movl $-ENOSYS,PT_EAX(%esp)
14653 jmp resume_userspace
14654 -END(syscall_badsys)
14655 +ENDPROC(syscall_badsys)
14656 CFI_ENDPROC
14657 /*
14658 * End of kprobes section
14659 @@ -753,6 +965,36 @@ ptregs_clone:
14660 CFI_ENDPROC
14661 ENDPROC(ptregs_clone)
14662
14663 + ALIGN;
14664 +ENTRY(kernel_execve)
14665 + CFI_STARTPROC
14666 + pushl_cfi %ebp
14667 + sub $PT_OLDSS+4,%esp
14668 + pushl_cfi %edi
14669 + pushl_cfi %ecx
14670 + pushl_cfi %eax
14671 + lea 3*4(%esp),%edi
14672 + mov $PT_OLDSS/4+1,%ecx
14673 + xorl %eax,%eax
14674 + rep stosl
14675 + popl_cfi %eax
14676 + popl_cfi %ecx
14677 + popl_cfi %edi
14678 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14679 + pushl_cfi %esp
14680 + call sys_execve
14681 + add $4,%esp
14682 + CFI_ADJUST_CFA_OFFSET -4
14683 + GET_THREAD_INFO(%ebp)
14684 + test %eax,%eax
14685 + jz syscall_exit
14686 + add $PT_OLDSS+4,%esp
14687 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14688 + popl_cfi %ebp
14689 + ret
14690 + CFI_ENDPROC
14691 +ENDPROC(kernel_execve)
14692 +
14693 .macro FIXUP_ESPFIX_STACK
14694 /*
14695 * Switch back for ESPFIX stack to the normal zerobased stack
14696 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
14697 * normal stack and adjusts ESP with the matching offset.
14698 */
14699 /* fixup the stack */
14700 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14701 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14702 +#ifdef CONFIG_SMP
14703 + movl PER_CPU_VAR(cpu_number), %ebx
14704 + shll $PAGE_SHIFT_asm, %ebx
14705 + addl $cpu_gdt_table, %ebx
14706 +#else
14707 + movl $cpu_gdt_table, %ebx
14708 +#endif
14709 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14710 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14711 shl $16, %eax
14712 addl %esp, %eax /* the adjusted stack pointer */
14713 pushl_cfi $__KERNEL_DS
14714 @@ -816,7 +1065,7 @@ vector=vector+1
14715 .endr
14716 2: jmp common_interrupt
14717 .endr
14718 -END(irq_entries_start)
14719 +ENDPROC(irq_entries_start)
14720
14721 .previous
14722 END(interrupt)
14723 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
14724 pushl_cfi $do_coprocessor_error
14725 jmp error_code
14726 CFI_ENDPROC
14727 -END(coprocessor_error)
14728 +ENDPROC(coprocessor_error)
14729
14730 ENTRY(simd_coprocessor_error)
14731 RING0_INT_FRAME
14732 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
14733 #endif
14734 jmp error_code
14735 CFI_ENDPROC
14736 -END(simd_coprocessor_error)
14737 +ENDPROC(simd_coprocessor_error)
14738
14739 ENTRY(device_not_available)
14740 RING0_INT_FRAME
14741 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
14742 pushl_cfi $do_device_not_available
14743 jmp error_code
14744 CFI_ENDPROC
14745 -END(device_not_available)
14746 +ENDPROC(device_not_available)
14747
14748 #ifdef CONFIG_PARAVIRT
14749 ENTRY(native_iret)
14750 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
14751 .align 4
14752 .long native_iret, iret_exc
14753 .previous
14754 -END(native_iret)
14755 +ENDPROC(native_iret)
14756
14757 ENTRY(native_irq_enable_sysexit)
14758 sti
14759 sysexit
14760 -END(native_irq_enable_sysexit)
14761 +ENDPROC(native_irq_enable_sysexit)
14762 #endif
14763
14764 ENTRY(overflow)
14765 @@ -916,7 +1165,7 @@ ENTRY(overflow)
14766 pushl_cfi $do_overflow
14767 jmp error_code
14768 CFI_ENDPROC
14769 -END(overflow)
14770 +ENDPROC(overflow)
14771
14772 ENTRY(bounds)
14773 RING0_INT_FRAME
14774 @@ -924,7 +1173,7 @@ ENTRY(bounds)
14775 pushl_cfi $do_bounds
14776 jmp error_code
14777 CFI_ENDPROC
14778 -END(bounds)
14779 +ENDPROC(bounds)
14780
14781 ENTRY(invalid_op)
14782 RING0_INT_FRAME
14783 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
14784 pushl_cfi $do_invalid_op
14785 jmp error_code
14786 CFI_ENDPROC
14787 -END(invalid_op)
14788 +ENDPROC(invalid_op)
14789
14790 ENTRY(coprocessor_segment_overrun)
14791 RING0_INT_FRAME
14792 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
14793 pushl_cfi $do_coprocessor_segment_overrun
14794 jmp error_code
14795 CFI_ENDPROC
14796 -END(coprocessor_segment_overrun)
14797 +ENDPROC(coprocessor_segment_overrun)
14798
14799 ENTRY(invalid_TSS)
14800 RING0_EC_FRAME
14801 pushl_cfi $do_invalid_TSS
14802 jmp error_code
14803 CFI_ENDPROC
14804 -END(invalid_TSS)
14805 +ENDPROC(invalid_TSS)
14806
14807 ENTRY(segment_not_present)
14808 RING0_EC_FRAME
14809 pushl_cfi $do_segment_not_present
14810 jmp error_code
14811 CFI_ENDPROC
14812 -END(segment_not_present)
14813 +ENDPROC(segment_not_present)
14814
14815 ENTRY(stack_segment)
14816 RING0_EC_FRAME
14817 pushl_cfi $do_stack_segment
14818 jmp error_code
14819 CFI_ENDPROC
14820 -END(stack_segment)
14821 +ENDPROC(stack_segment)
14822
14823 ENTRY(alignment_check)
14824 RING0_EC_FRAME
14825 pushl_cfi $do_alignment_check
14826 jmp error_code
14827 CFI_ENDPROC
14828 -END(alignment_check)
14829 +ENDPROC(alignment_check)
14830
14831 ENTRY(divide_error)
14832 RING0_INT_FRAME
14833 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
14834 pushl_cfi $do_divide_error
14835 jmp error_code
14836 CFI_ENDPROC
14837 -END(divide_error)
14838 +ENDPROC(divide_error)
14839
14840 #ifdef CONFIG_X86_MCE
14841 ENTRY(machine_check)
14842 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
14843 pushl_cfi machine_check_vector
14844 jmp error_code
14845 CFI_ENDPROC
14846 -END(machine_check)
14847 +ENDPROC(machine_check)
14848 #endif
14849
14850 ENTRY(spurious_interrupt_bug)
14851 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
14852 pushl_cfi $do_spurious_interrupt_bug
14853 jmp error_code
14854 CFI_ENDPROC
14855 -END(spurious_interrupt_bug)
14856 +ENDPROC(spurious_interrupt_bug)
14857 /*
14858 * End of kprobes section
14859 */
14860 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
14861
14862 ENTRY(mcount)
14863 ret
14864 -END(mcount)
14865 +ENDPROC(mcount)
14866
14867 ENTRY(ftrace_caller)
14868 cmpl $0, function_trace_stop
14869 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
14870 .globl ftrace_stub
14871 ftrace_stub:
14872 ret
14873 -END(ftrace_caller)
14874 +ENDPROC(ftrace_caller)
14875
14876 #else /* ! CONFIG_DYNAMIC_FTRACE */
14877
14878 @@ -1174,7 +1423,7 @@ trace:
14879 popl %ecx
14880 popl %eax
14881 jmp ftrace_stub
14882 -END(mcount)
14883 +ENDPROC(mcount)
14884 #endif /* CONFIG_DYNAMIC_FTRACE */
14885 #endif /* CONFIG_FUNCTION_TRACER */
14886
14887 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
14888 popl %ecx
14889 popl %eax
14890 ret
14891 -END(ftrace_graph_caller)
14892 +ENDPROC(ftrace_graph_caller)
14893
14894 .globl return_to_handler
14895 return_to_handler:
14896 @@ -1209,7 +1458,6 @@ return_to_handler:
14897 jmp *%ecx
14898 #endif
14899
14900 -.section .rodata,"a"
14901 #include "syscall_table_32.S"
14902
14903 syscall_table_size=(.-sys_call_table)
14904 @@ -1255,15 +1503,18 @@ error_code:
14905 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14906 REG_TO_PTGS %ecx
14907 SET_KERNEL_GS %ecx
14908 - movl $(__USER_DS), %ecx
14909 + movl $(__KERNEL_DS), %ecx
14910 movl %ecx, %ds
14911 movl %ecx, %es
14912 +
14913 + pax_enter_kernel
14914 +
14915 TRACE_IRQS_OFF
14916 movl %esp,%eax # pt_regs pointer
14917 call *%edi
14918 jmp ret_from_exception
14919 CFI_ENDPROC
14920 -END(page_fault)
14921 +ENDPROC(page_fault)
14922
14923 /*
14924 * Debug traps and NMI can happen at the one SYSENTER instruction
14925 @@ -1305,7 +1556,7 @@ debug_stack_correct:
14926 call do_debug
14927 jmp ret_from_exception
14928 CFI_ENDPROC
14929 -END(debug)
14930 +ENDPROC(debug)
14931
14932 /*
14933 * NMI is doubly nasty. It can happen _while_ we're handling
14934 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
14935 xorl %edx,%edx # zero error code
14936 movl %esp,%eax # pt_regs pointer
14937 call do_nmi
14938 +
14939 + pax_exit_kernel
14940 +
14941 jmp restore_all_notrace
14942 CFI_ENDPROC
14943
14944 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
14945 FIXUP_ESPFIX_STACK # %eax == %esp
14946 xorl %edx,%edx # zero error code
14947 call do_nmi
14948 +
14949 + pax_exit_kernel
14950 +
14951 RESTORE_REGS
14952 lss 12+4(%esp), %esp # back to espfix stack
14953 CFI_ADJUST_CFA_OFFSET -24
14954 jmp irq_return
14955 CFI_ENDPROC
14956 -END(nmi)
14957 +ENDPROC(nmi)
14958
14959 ENTRY(int3)
14960 RING0_INT_FRAME
14961 @@ -1395,14 +1652,14 @@ ENTRY(int3)
14962 call do_int3
14963 jmp ret_from_exception
14964 CFI_ENDPROC
14965 -END(int3)
14966 +ENDPROC(int3)
14967
14968 ENTRY(general_protection)
14969 RING0_EC_FRAME
14970 pushl_cfi $do_general_protection
14971 jmp error_code
14972 CFI_ENDPROC
14973 -END(general_protection)
14974 +ENDPROC(general_protection)
14975
14976 #ifdef CONFIG_KVM_GUEST
14977 ENTRY(async_page_fault)
14978 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
14979 pushl_cfi $do_async_page_fault
14980 jmp error_code
14981 CFI_ENDPROC
14982 -END(async_page_fault)
14983 +ENDPROC(async_page_fault)
14984 #endif
14985
14986 /*
14987 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
14988 index faf8d5e..4f16a68 100644
14989 --- a/arch/x86/kernel/entry_64.S
14990 +++ b/arch/x86/kernel/entry_64.S
14991 @@ -55,6 +55,8 @@
14992 #include <asm/paravirt.h>
14993 #include <asm/ftrace.h>
14994 #include <asm/percpu.h>
14995 +#include <asm/pgtable.h>
14996 +#include <asm/alternative-asm.h>
14997
14998 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14999 #include <linux/elf-em.h>
15000 @@ -68,8 +70,9 @@
15001 #ifdef CONFIG_FUNCTION_TRACER
15002 #ifdef CONFIG_DYNAMIC_FTRACE
15003 ENTRY(mcount)
15004 + pax_force_retaddr
15005 retq
15006 -END(mcount)
15007 +ENDPROC(mcount)
15008
15009 ENTRY(ftrace_caller)
15010 cmpl $0, function_trace_stop
15011 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
15012 #endif
15013
15014 GLOBAL(ftrace_stub)
15015 + pax_force_retaddr
15016 retq
15017 -END(ftrace_caller)
15018 +ENDPROC(ftrace_caller)
15019
15020 #else /* ! CONFIG_DYNAMIC_FTRACE */
15021 ENTRY(mcount)
15022 @@ -112,6 +116,7 @@ ENTRY(mcount)
15023 #endif
15024
15025 GLOBAL(ftrace_stub)
15026 + pax_force_retaddr
15027 retq
15028
15029 trace:
15030 @@ -121,12 +126,13 @@ trace:
15031 movq 8(%rbp), %rsi
15032 subq $MCOUNT_INSN_SIZE, %rdi
15033
15034 + pax_force_fptr ftrace_trace_function
15035 call *ftrace_trace_function
15036
15037 MCOUNT_RESTORE_FRAME
15038
15039 jmp ftrace_stub
15040 -END(mcount)
15041 +ENDPROC(mcount)
15042 #endif /* CONFIG_DYNAMIC_FTRACE */
15043 #endif /* CONFIG_FUNCTION_TRACER */
15044
15045 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
15046
15047 MCOUNT_RESTORE_FRAME
15048
15049 + pax_force_retaddr
15050 retq
15051 -END(ftrace_graph_caller)
15052 +ENDPROC(ftrace_graph_caller)
15053
15054 GLOBAL(return_to_handler)
15055 subq $24, %rsp
15056 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
15057 movq 8(%rsp), %rdx
15058 movq (%rsp), %rax
15059 addq $24, %rsp
15060 + pax_force_fptr %rdi
15061 jmp *%rdi
15062 #endif
15063
15064 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
15065 ENDPROC(native_usergs_sysret64)
15066 #endif /* CONFIG_PARAVIRT */
15067
15068 + .macro ljmpq sel, off
15069 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15070 + .byte 0x48; ljmp *1234f(%rip)
15071 + .pushsection .rodata
15072 + .align 16
15073 + 1234: .quad \off; .word \sel
15074 + .popsection
15075 +#else
15076 + pushq $\sel
15077 + pushq $\off
15078 + lretq
15079 +#endif
15080 + .endm
15081 +
15082 + .macro pax_enter_kernel
15083 + pax_set_fptr_mask
15084 +#ifdef CONFIG_PAX_KERNEXEC
15085 + call pax_enter_kernel
15086 +#endif
15087 + .endm
15088 +
15089 + .macro pax_exit_kernel
15090 +#ifdef CONFIG_PAX_KERNEXEC
15091 + call pax_exit_kernel
15092 +#endif
15093 + .endm
15094 +
15095 +#ifdef CONFIG_PAX_KERNEXEC
15096 +ENTRY(pax_enter_kernel)
15097 + pushq %rdi
15098 +
15099 +#ifdef CONFIG_PARAVIRT
15100 + PV_SAVE_REGS(CLBR_RDI)
15101 +#endif
15102 +
15103 + GET_CR0_INTO_RDI
15104 + bts $16,%rdi
15105 + jnc 3f
15106 + mov %cs,%edi
15107 + cmp $__KERNEL_CS,%edi
15108 + jnz 2f
15109 +1:
15110 +
15111 +#ifdef CONFIG_PARAVIRT
15112 + PV_RESTORE_REGS(CLBR_RDI)
15113 +#endif
15114 +
15115 + popq %rdi
15116 + pax_force_retaddr
15117 + retq
15118 +
15119 +2: ljmpq __KERNEL_CS,1f
15120 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15121 +4: SET_RDI_INTO_CR0
15122 + jmp 1b
15123 +ENDPROC(pax_enter_kernel)
15124 +
15125 +ENTRY(pax_exit_kernel)
15126 + pushq %rdi
15127 +
15128 +#ifdef CONFIG_PARAVIRT
15129 + PV_SAVE_REGS(CLBR_RDI)
15130 +#endif
15131 +
15132 + mov %cs,%rdi
15133 + cmp $__KERNEXEC_KERNEL_CS,%edi
15134 + jz 2f
15135 +1:
15136 +
15137 +#ifdef CONFIG_PARAVIRT
15138 + PV_RESTORE_REGS(CLBR_RDI);
15139 +#endif
15140 +
15141 + popq %rdi
15142 + pax_force_retaddr
15143 + retq
15144 +
15145 +2: GET_CR0_INTO_RDI
15146 + btr $16,%rdi
15147 + ljmpq __KERNEL_CS,3f
15148 +3: SET_RDI_INTO_CR0
15149 + jmp 1b
15150 +#ifdef CONFIG_PARAVIRT
15151 + PV_RESTORE_REGS(CLBR_RDI);
15152 +#endif
15153 +
15154 + popq %rdi
15155 + pax_force_retaddr
15156 + retq
15157 +ENDPROC(pax_exit_kernel)
15158 +#endif
15159 +
15160 + .macro pax_enter_kernel_user
15161 + pax_set_fptr_mask
15162 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15163 + call pax_enter_kernel_user
15164 +#endif
15165 + .endm
15166 +
15167 + .macro pax_exit_kernel_user
15168 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15169 + call pax_exit_kernel_user
15170 +#endif
15171 +#ifdef CONFIG_PAX_RANDKSTACK
15172 + pushq %rax
15173 + call pax_randomize_kstack
15174 + popq %rax
15175 +#endif
15176 + .endm
15177 +
15178 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15179 +ENTRY(pax_enter_kernel_user)
15180 + pushq %rdi
15181 + pushq %rbx
15182 +
15183 +#ifdef CONFIG_PARAVIRT
15184 + PV_SAVE_REGS(CLBR_RDI)
15185 +#endif
15186 +
15187 + GET_CR3_INTO_RDI
15188 + mov %rdi,%rbx
15189 + add $__START_KERNEL_map,%rbx
15190 + sub phys_base(%rip),%rbx
15191 +
15192 +#ifdef CONFIG_PARAVIRT
15193 + pushq %rdi
15194 + cmpl $0, pv_info+PARAVIRT_enabled
15195 + jz 1f
15196 + i = 0
15197 + .rept USER_PGD_PTRS
15198 + mov i*8(%rbx),%rsi
15199 + mov $0,%sil
15200 + lea i*8(%rbx),%rdi
15201 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15202 + i = i + 1
15203 + .endr
15204 + jmp 2f
15205 +1:
15206 +#endif
15207 +
15208 + i = 0
15209 + .rept USER_PGD_PTRS
15210 + movb $0,i*8(%rbx)
15211 + i = i + 1
15212 + .endr
15213 +
15214 +#ifdef CONFIG_PARAVIRT
15215 +2: popq %rdi
15216 +#endif
15217 + SET_RDI_INTO_CR3
15218 +
15219 +#ifdef CONFIG_PAX_KERNEXEC
15220 + GET_CR0_INTO_RDI
15221 + bts $16,%rdi
15222 + SET_RDI_INTO_CR0
15223 +#endif
15224 +
15225 +#ifdef CONFIG_PARAVIRT
15226 + PV_RESTORE_REGS(CLBR_RDI)
15227 +#endif
15228 +
15229 + popq %rbx
15230 + popq %rdi
15231 + pax_force_retaddr
15232 + retq
15233 +ENDPROC(pax_enter_kernel_user)
15234 +
15235 +ENTRY(pax_exit_kernel_user)
15236 + push %rdi
15237 +
15238 +#ifdef CONFIG_PARAVIRT
15239 + pushq %rbx
15240 + PV_SAVE_REGS(CLBR_RDI)
15241 +#endif
15242 +
15243 +#ifdef CONFIG_PAX_KERNEXEC
15244 + GET_CR0_INTO_RDI
15245 + btr $16,%rdi
15246 + SET_RDI_INTO_CR0
15247 +#endif
15248 +
15249 + GET_CR3_INTO_RDI
15250 + add $__START_KERNEL_map,%rdi
15251 + sub phys_base(%rip),%rdi
15252 +
15253 +#ifdef CONFIG_PARAVIRT
15254 + cmpl $0, pv_info+PARAVIRT_enabled
15255 + jz 1f
15256 + mov %rdi,%rbx
15257 + i = 0
15258 + .rept USER_PGD_PTRS
15259 + mov i*8(%rbx),%rsi
15260 + mov $0x67,%sil
15261 + lea i*8(%rbx),%rdi
15262 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15263 + i = i + 1
15264 + .endr
15265 + jmp 2f
15266 +1:
15267 +#endif
15268 +
15269 + i = 0
15270 + .rept USER_PGD_PTRS
15271 + movb $0x67,i*8(%rdi)
15272 + i = i + 1
15273 + .endr
15274 +
15275 +#ifdef CONFIG_PARAVIRT
15276 +2: PV_RESTORE_REGS(CLBR_RDI)
15277 + popq %rbx
15278 +#endif
15279 +
15280 + popq %rdi
15281 + pax_force_retaddr
15282 + retq
15283 +ENDPROC(pax_exit_kernel_user)
15284 +#endif
15285 +
15286 +.macro pax_erase_kstack
15287 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15288 + call pax_erase_kstack
15289 +#endif
15290 +.endm
15291 +
15292 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15293 +/*
15294 + * r11: thread_info
15295 + * rcx, rdx: can be clobbered
15296 + */
15297 +ENTRY(pax_erase_kstack)
15298 + pushq %rdi
15299 + pushq %rax
15300 + pushq %r11
15301 +
15302 + GET_THREAD_INFO(%r11)
15303 + mov TI_lowest_stack(%r11), %rdi
15304 + mov $-0xBEEF, %rax
15305 + std
15306 +
15307 +1: mov %edi, %ecx
15308 + and $THREAD_SIZE_asm - 1, %ecx
15309 + shr $3, %ecx
15310 + repne scasq
15311 + jecxz 2f
15312 +
15313 + cmp $2*8, %ecx
15314 + jc 2f
15315 +
15316 + mov $2*8, %ecx
15317 + repe scasq
15318 + jecxz 2f
15319 + jne 1b
15320 +
15321 +2: cld
15322 + mov %esp, %ecx
15323 + sub %edi, %ecx
15324 +
15325 + cmp $THREAD_SIZE_asm, %rcx
15326 + jb 3f
15327 + ud2
15328 +3:
15329 +
15330 + shr $3, %ecx
15331 + rep stosq
15332 +
15333 + mov TI_task_thread_sp0(%r11), %rdi
15334 + sub $256, %rdi
15335 + mov %rdi, TI_lowest_stack(%r11)
15336 +
15337 + popq %r11
15338 + popq %rax
15339 + popq %rdi
15340 + pax_force_retaddr
15341 + ret
15342 +ENDPROC(pax_erase_kstack)
15343 +#endif
15344
15345 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15346 #ifdef CONFIG_TRACE_IRQFLAGS
15347 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
15348 .endm
15349
15350 .macro UNFAKE_STACK_FRAME
15351 - addq $8*6, %rsp
15352 - CFI_ADJUST_CFA_OFFSET -(6*8)
15353 + addq $8*6 + ARG_SKIP, %rsp
15354 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15355 .endm
15356
15357 /*
15358 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
15359 movq %rsp, %rsi
15360
15361 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15362 - testl $3, CS(%rdi)
15363 + testb $3, CS(%rdi)
15364 je 1f
15365 SWAPGS
15366 /*
15367 @@ -355,9 +639,10 @@ ENTRY(save_rest)
15368 movq_cfi r15, R15+16
15369 movq %r11, 8(%rsp) /* return address */
15370 FIXUP_TOP_OF_STACK %r11, 16
15371 + pax_force_retaddr
15372 ret
15373 CFI_ENDPROC
15374 -END(save_rest)
15375 +ENDPROC(save_rest)
15376
15377 /* save complete stack frame */
15378 .pushsection .kprobes.text, "ax"
15379 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
15380 js 1f /* negative -> in kernel */
15381 SWAPGS
15382 xorl %ebx,%ebx
15383 -1: ret
15384 +1: pax_force_retaddr_bts
15385 + ret
15386 CFI_ENDPROC
15387 -END(save_paranoid)
15388 +ENDPROC(save_paranoid)
15389 .popsection
15390
15391 /*
15392 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
15393
15394 RESTORE_REST
15395
15396 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15397 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15398 je int_ret_from_sys_call
15399
15400 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15401 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
15402 jmp ret_from_sys_call # go to the SYSRET fastpath
15403
15404 CFI_ENDPROC
15405 -END(ret_from_fork)
15406 +ENDPROC(ret_from_fork)
15407
15408 /*
15409 * System call entry. Up to 6 arguments in registers are supported.
15410 @@ -456,7 +742,7 @@ END(ret_from_fork)
15411 ENTRY(system_call)
15412 CFI_STARTPROC simple
15413 CFI_SIGNAL_FRAME
15414 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15415 + CFI_DEF_CFA rsp,0
15416 CFI_REGISTER rip,rcx
15417 /*CFI_REGISTER rflags,r11*/
15418 SWAPGS_UNSAFE_STACK
15419 @@ -469,12 +755,13 @@ ENTRY(system_call_after_swapgs)
15420
15421 movq %rsp,PER_CPU_VAR(old_rsp)
15422 movq PER_CPU_VAR(kernel_stack),%rsp
15423 + SAVE_ARGS 8*6,0
15424 + pax_enter_kernel_user
15425 /*
15426 * No need to follow this irqs off/on section - it's straight
15427 * and short:
15428 */
15429 ENABLE_INTERRUPTS(CLBR_NONE)
15430 - SAVE_ARGS 8,0
15431 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15432 movq %rcx,RIP-ARGOFFSET(%rsp)
15433 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15434 @@ -484,7 +771,7 @@ ENTRY(system_call_after_swapgs)
15435 system_call_fastpath:
15436 cmpq $__NR_syscall_max,%rax
15437 ja badsys
15438 - movq %r10,%rcx
15439 + movq R10-ARGOFFSET(%rsp),%rcx
15440 call *sys_call_table(,%rax,8) # XXX: rip relative
15441 movq %rax,RAX-ARGOFFSET(%rsp)
15442 /*
15443 @@ -503,6 +790,8 @@ sysret_check:
15444 andl %edi,%edx
15445 jnz sysret_careful
15446 CFI_REMEMBER_STATE
15447 + pax_exit_kernel_user
15448 + pax_erase_kstack
15449 /*
15450 * sysretq will re-enable interrupts:
15451 */
15452 @@ -554,14 +843,18 @@ badsys:
15453 * jump back to the normal fast path.
15454 */
15455 auditsys:
15456 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15457 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15458 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15459 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15460 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15461 movq %rax,%rsi /* 2nd arg: syscall number */
15462 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15463 call audit_syscall_entry
15464 +
15465 + pax_erase_kstack
15466 +
15467 LOAD_ARGS 0 /* reload call-clobbered registers */
15468 + pax_set_fptr_mask
15469 jmp system_call_fastpath
15470
15471 /*
15472 @@ -591,16 +884,20 @@ tracesys:
15473 FIXUP_TOP_OF_STACK %rdi
15474 movq %rsp,%rdi
15475 call syscall_trace_enter
15476 +
15477 + pax_erase_kstack
15478 +
15479 /*
15480 * Reload arg registers from stack in case ptrace changed them.
15481 * We don't reload %rax because syscall_trace_enter() returned
15482 * the value it wants us to use in the table lookup.
15483 */
15484 LOAD_ARGS ARGOFFSET, 1
15485 + pax_set_fptr_mask
15486 RESTORE_REST
15487 cmpq $__NR_syscall_max,%rax
15488 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15489 - movq %r10,%rcx /* fixup for C */
15490 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15491 call *sys_call_table(,%rax,8)
15492 movq %rax,RAX-ARGOFFSET(%rsp)
15493 /* Use IRET because user could have changed frame */
15494 @@ -612,7 +909,7 @@ tracesys:
15495 GLOBAL(int_ret_from_sys_call)
15496 DISABLE_INTERRUPTS(CLBR_NONE)
15497 TRACE_IRQS_OFF
15498 - testl $3,CS-ARGOFFSET(%rsp)
15499 + testb $3,CS-ARGOFFSET(%rsp)
15500 je retint_restore_args
15501 movl $_TIF_ALLWORK_MASK,%edi
15502 /* edi: mask to check */
15503 @@ -623,6 +920,7 @@ GLOBAL(int_with_check)
15504 andl %edi,%edx
15505 jnz int_careful
15506 andl $~TS_COMPAT,TI_status(%rcx)
15507 + pax_erase_kstack
15508 jmp retint_swapgs
15509
15510 /* Either reschedule or signal or syscall exit tracking needed. */
15511 @@ -669,7 +967,7 @@ int_restore_rest:
15512 TRACE_IRQS_OFF
15513 jmp int_with_check
15514 CFI_ENDPROC
15515 -END(system_call)
15516 +ENDPROC(system_call)
15517
15518 /*
15519 * Certain special system calls that need to save a complete full stack frame.
15520 @@ -685,7 +983,7 @@ ENTRY(\label)
15521 call \func
15522 jmp ptregscall_common
15523 CFI_ENDPROC
15524 -END(\label)
15525 +ENDPROC(\label)
15526 .endm
15527
15528 PTREGSCALL stub_clone, sys_clone, %r8
15529 @@ -703,9 +1001,10 @@ ENTRY(ptregscall_common)
15530 movq_cfi_restore R12+8, r12
15531 movq_cfi_restore RBP+8, rbp
15532 movq_cfi_restore RBX+8, rbx
15533 + pax_force_retaddr
15534 ret $REST_SKIP /* pop extended registers */
15535 CFI_ENDPROC
15536 -END(ptregscall_common)
15537 +ENDPROC(ptregscall_common)
15538
15539 ENTRY(stub_execve)
15540 CFI_STARTPROC
15541 @@ -720,7 +1019,7 @@ ENTRY(stub_execve)
15542 RESTORE_REST
15543 jmp int_ret_from_sys_call
15544 CFI_ENDPROC
15545 -END(stub_execve)
15546 +ENDPROC(stub_execve)
15547
15548 /*
15549 * sigreturn is special because it needs to restore all registers on return.
15550 @@ -738,7 +1037,7 @@ ENTRY(stub_rt_sigreturn)
15551 RESTORE_REST
15552 jmp int_ret_from_sys_call
15553 CFI_ENDPROC
15554 -END(stub_rt_sigreturn)
15555 +ENDPROC(stub_rt_sigreturn)
15556
15557 /*
15558 * Build the entry stubs and pointer table with some assembler magic.
15559 @@ -773,7 +1072,7 @@ vector=vector+1
15560 2: jmp common_interrupt
15561 .endr
15562 CFI_ENDPROC
15563 -END(irq_entries_start)
15564 +ENDPROC(irq_entries_start)
15565
15566 .previous
15567 END(interrupt)
15568 @@ -793,6 +1092,16 @@ END(interrupt)
15569 subq $ORIG_RAX-RBP, %rsp
15570 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15571 SAVE_ARGS_IRQ
15572 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15573 + testb $3, CS(%rdi)
15574 + jnz 1f
15575 + pax_enter_kernel
15576 + jmp 2f
15577 +1: pax_enter_kernel_user
15578 +2:
15579 +#else
15580 + pax_enter_kernel
15581 +#endif
15582 call \func
15583 .endm
15584
15585 @@ -824,7 +1133,7 @@ ret_from_intr:
15586
15587 exit_intr:
15588 GET_THREAD_INFO(%rcx)
15589 - testl $3,CS-ARGOFFSET(%rsp)
15590 + testb $3,CS-ARGOFFSET(%rsp)
15591 je retint_kernel
15592
15593 /* Interrupt came from user space */
15594 @@ -846,12 +1155,15 @@ retint_swapgs: /* return to user-space */
15595 * The iretq could re-enable interrupts:
15596 */
15597 DISABLE_INTERRUPTS(CLBR_ANY)
15598 + pax_exit_kernel_user
15599 TRACE_IRQS_IRETQ
15600 SWAPGS
15601 jmp restore_args
15602
15603 retint_restore_args: /* return to kernel space */
15604 DISABLE_INTERRUPTS(CLBR_ANY)
15605 + pax_exit_kernel
15606 + pax_force_retaddr RIP-ARGOFFSET
15607 /*
15608 * The iretq could re-enable interrupts:
15609 */
15610 @@ -940,7 +1252,7 @@ ENTRY(retint_kernel)
15611 #endif
15612
15613 CFI_ENDPROC
15614 -END(common_interrupt)
15615 +ENDPROC(common_interrupt)
15616 /*
15617 * End of kprobes section
15618 */
15619 @@ -956,7 +1268,7 @@ ENTRY(\sym)
15620 interrupt \do_sym
15621 jmp ret_from_intr
15622 CFI_ENDPROC
15623 -END(\sym)
15624 +ENDPROC(\sym)
15625 .endm
15626
15627 #ifdef CONFIG_SMP
15628 @@ -1021,12 +1333,22 @@ ENTRY(\sym)
15629 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15630 call error_entry
15631 DEFAULT_FRAME 0
15632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15633 + testb $3, CS(%rsp)
15634 + jnz 1f
15635 + pax_enter_kernel
15636 + jmp 2f
15637 +1: pax_enter_kernel_user
15638 +2:
15639 +#else
15640 + pax_enter_kernel
15641 +#endif
15642 movq %rsp,%rdi /* pt_regs pointer */
15643 xorl %esi,%esi /* no error code */
15644 call \do_sym
15645 jmp error_exit /* %ebx: no swapgs flag */
15646 CFI_ENDPROC
15647 -END(\sym)
15648 +ENDPROC(\sym)
15649 .endm
15650
15651 .macro paranoidzeroentry sym do_sym
15652 @@ -1038,15 +1360,25 @@ ENTRY(\sym)
15653 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15654 call save_paranoid
15655 TRACE_IRQS_OFF
15656 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15657 + testb $3, CS(%rsp)
15658 + jnz 1f
15659 + pax_enter_kernel
15660 + jmp 2f
15661 +1: pax_enter_kernel_user
15662 +2:
15663 +#else
15664 + pax_enter_kernel
15665 +#endif
15666 movq %rsp,%rdi /* pt_regs pointer */
15667 xorl %esi,%esi /* no error code */
15668 call \do_sym
15669 jmp paranoid_exit /* %ebx: no swapgs flag */
15670 CFI_ENDPROC
15671 -END(\sym)
15672 +ENDPROC(\sym)
15673 .endm
15674
15675 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15676 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15677 .macro paranoidzeroentry_ist sym do_sym ist
15678 ENTRY(\sym)
15679 INTR_FRAME
15680 @@ -1056,14 +1388,30 @@ ENTRY(\sym)
15681 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15682 call save_paranoid
15683 TRACE_IRQS_OFF
15684 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15685 + testb $3, CS(%rsp)
15686 + jnz 1f
15687 + pax_enter_kernel
15688 + jmp 2f
15689 +1: pax_enter_kernel_user
15690 +2:
15691 +#else
15692 + pax_enter_kernel
15693 +#endif
15694 movq %rsp,%rdi /* pt_regs pointer */
15695 xorl %esi,%esi /* no error code */
15696 +#ifdef CONFIG_SMP
15697 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15698 + lea init_tss(%r12), %r12
15699 +#else
15700 + lea init_tss(%rip), %r12
15701 +#endif
15702 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15703 call \do_sym
15704 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15705 jmp paranoid_exit /* %ebx: no swapgs flag */
15706 CFI_ENDPROC
15707 -END(\sym)
15708 +ENDPROC(\sym)
15709 .endm
15710
15711 .macro errorentry sym do_sym
15712 @@ -1074,13 +1422,23 @@ ENTRY(\sym)
15713 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15714 call error_entry
15715 DEFAULT_FRAME 0
15716 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15717 + testb $3, CS(%rsp)
15718 + jnz 1f
15719 + pax_enter_kernel
15720 + jmp 2f
15721 +1: pax_enter_kernel_user
15722 +2:
15723 +#else
15724 + pax_enter_kernel
15725 +#endif
15726 movq %rsp,%rdi /* pt_regs pointer */
15727 movq ORIG_RAX(%rsp),%rsi /* get error code */
15728 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15729 call \do_sym
15730 jmp error_exit /* %ebx: no swapgs flag */
15731 CFI_ENDPROC
15732 -END(\sym)
15733 +ENDPROC(\sym)
15734 .endm
15735
15736 /* error code is on the stack already */
15737 @@ -1093,13 +1451,23 @@ ENTRY(\sym)
15738 call save_paranoid
15739 DEFAULT_FRAME 0
15740 TRACE_IRQS_OFF
15741 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15742 + testb $3, CS(%rsp)
15743 + jnz 1f
15744 + pax_enter_kernel
15745 + jmp 2f
15746 +1: pax_enter_kernel_user
15747 +2:
15748 +#else
15749 + pax_enter_kernel
15750 +#endif
15751 movq %rsp,%rdi /* pt_regs pointer */
15752 movq ORIG_RAX(%rsp),%rsi /* get error code */
15753 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15754 call \do_sym
15755 jmp paranoid_exit /* %ebx: no swapgs flag */
15756 CFI_ENDPROC
15757 -END(\sym)
15758 +ENDPROC(\sym)
15759 .endm
15760
15761 zeroentry divide_error do_divide_error
15762 @@ -1129,9 +1497,10 @@ gs_change:
15763 2: mfence /* workaround */
15764 SWAPGS
15765 popfq_cfi
15766 + pax_force_retaddr
15767 ret
15768 CFI_ENDPROC
15769 -END(native_load_gs_index)
15770 +ENDPROC(native_load_gs_index)
15771
15772 .section __ex_table,"a"
15773 .align 8
15774 @@ -1153,13 +1522,14 @@ ENTRY(kernel_thread_helper)
15775 * Here we are in the child and the registers are set as they were
15776 * at kernel_thread() invocation in the parent.
15777 */
15778 + pax_force_fptr %rsi
15779 call *%rsi
15780 # exit
15781 mov %eax, %edi
15782 call do_exit
15783 ud2 # padding for call trace
15784 CFI_ENDPROC
15785 -END(kernel_thread_helper)
15786 +ENDPROC(kernel_thread_helper)
15787
15788 /*
15789 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15790 @@ -1186,11 +1556,11 @@ ENTRY(kernel_execve)
15791 RESTORE_REST
15792 testq %rax,%rax
15793 je int_ret_from_sys_call
15794 - RESTORE_ARGS
15795 UNFAKE_STACK_FRAME
15796 + pax_force_retaddr
15797 ret
15798 CFI_ENDPROC
15799 -END(kernel_execve)
15800 +ENDPROC(kernel_execve)
15801
15802 /* Call softirq on interrupt stack. Interrupts are off. */
15803 ENTRY(call_softirq)
15804 @@ -1208,9 +1578,10 @@ ENTRY(call_softirq)
15805 CFI_DEF_CFA_REGISTER rsp
15806 CFI_ADJUST_CFA_OFFSET -8
15807 decl PER_CPU_VAR(irq_count)
15808 + pax_force_retaddr
15809 ret
15810 CFI_ENDPROC
15811 -END(call_softirq)
15812 +ENDPROC(call_softirq)
15813
15814 #ifdef CONFIG_XEN
15815 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
15816 @@ -1248,7 +1619,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
15817 decl PER_CPU_VAR(irq_count)
15818 jmp error_exit
15819 CFI_ENDPROC
15820 -END(xen_do_hypervisor_callback)
15821 +ENDPROC(xen_do_hypervisor_callback)
15822
15823 /*
15824 * Hypervisor uses this for application faults while it executes.
15825 @@ -1307,7 +1678,7 @@ ENTRY(xen_failsafe_callback)
15826 SAVE_ALL
15827 jmp error_exit
15828 CFI_ENDPROC
15829 -END(xen_failsafe_callback)
15830 +ENDPROC(xen_failsafe_callback)
15831
15832 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
15833 xen_hvm_callback_vector xen_evtchn_do_upcall
15834 @@ -1356,16 +1727,31 @@ ENTRY(paranoid_exit)
15835 TRACE_IRQS_OFF
15836 testl %ebx,%ebx /* swapgs needed? */
15837 jnz paranoid_restore
15838 - testl $3,CS(%rsp)
15839 + testb $3,CS(%rsp)
15840 jnz paranoid_userspace
15841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15842 + pax_exit_kernel
15843 + TRACE_IRQS_IRETQ 0
15844 + SWAPGS_UNSAFE_STACK
15845 + RESTORE_ALL 8
15846 + pax_force_retaddr_bts
15847 + jmp irq_return
15848 +#endif
15849 paranoid_swapgs:
15850 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15851 + pax_exit_kernel_user
15852 +#else
15853 + pax_exit_kernel
15854 +#endif
15855 TRACE_IRQS_IRETQ 0
15856 SWAPGS_UNSAFE_STACK
15857 RESTORE_ALL 8
15858 jmp irq_return
15859 paranoid_restore:
15860 + pax_exit_kernel
15861 TRACE_IRQS_IRETQ 0
15862 RESTORE_ALL 8
15863 + pax_force_retaddr_bts
15864 jmp irq_return
15865 paranoid_userspace:
15866 GET_THREAD_INFO(%rcx)
15867 @@ -1394,7 +1780,7 @@ paranoid_schedule:
15868 TRACE_IRQS_OFF
15869 jmp paranoid_userspace
15870 CFI_ENDPROC
15871 -END(paranoid_exit)
15872 +ENDPROC(paranoid_exit)
15873
15874 /*
15875 * Exception entry point. This expects an error code/orig_rax on the stack.
15876 @@ -1421,12 +1807,13 @@ ENTRY(error_entry)
15877 movq_cfi r14, R14+8
15878 movq_cfi r15, R15+8
15879 xorl %ebx,%ebx
15880 - testl $3,CS+8(%rsp)
15881 + testb $3,CS+8(%rsp)
15882 je error_kernelspace
15883 error_swapgs:
15884 SWAPGS
15885 error_sti:
15886 TRACE_IRQS_OFF
15887 + pax_force_retaddr_bts
15888 ret
15889
15890 /*
15891 @@ -1453,7 +1840,7 @@ bstep_iret:
15892 movq %rcx,RIP+8(%rsp)
15893 jmp error_swapgs
15894 CFI_ENDPROC
15895 -END(error_entry)
15896 +ENDPROC(error_entry)
15897
15898
15899 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
15900 @@ -1473,7 +1860,7 @@ ENTRY(error_exit)
15901 jnz retint_careful
15902 jmp retint_swapgs
15903 CFI_ENDPROC
15904 -END(error_exit)
15905 +ENDPROC(error_exit)
15906
15907
15908 /* runs on exception stack */
15909 @@ -1485,6 +1872,16 @@ ENTRY(nmi)
15910 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15911 call save_paranoid
15912 DEFAULT_FRAME 0
15913 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15914 + testb $3, CS(%rsp)
15915 + jnz 1f
15916 + pax_enter_kernel
15917 + jmp 2f
15918 +1: pax_enter_kernel_user
15919 +2:
15920 +#else
15921 + pax_enter_kernel
15922 +#endif
15923 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
15924 movq %rsp,%rdi
15925 movq $-1,%rsi
15926 @@ -1495,12 +1892,28 @@ ENTRY(nmi)
15927 DISABLE_INTERRUPTS(CLBR_NONE)
15928 testl %ebx,%ebx /* swapgs needed? */
15929 jnz nmi_restore
15930 - testl $3,CS(%rsp)
15931 + testb $3,CS(%rsp)
15932 jnz nmi_userspace
15933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15934 + pax_exit_kernel
15935 + SWAPGS_UNSAFE_STACK
15936 + RESTORE_ALL 8
15937 + pax_force_retaddr_bts
15938 + jmp irq_return
15939 +#endif
15940 nmi_swapgs:
15941 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15942 + pax_exit_kernel_user
15943 +#else
15944 + pax_exit_kernel
15945 +#endif
15946 SWAPGS_UNSAFE_STACK
15947 + RESTORE_ALL 8
15948 + jmp irq_return
15949 nmi_restore:
15950 + pax_exit_kernel
15951 RESTORE_ALL 8
15952 + pax_force_retaddr_bts
15953 jmp irq_return
15954 nmi_userspace:
15955 GET_THREAD_INFO(%rcx)
15956 @@ -1529,14 +1942,14 @@ nmi_schedule:
15957 jmp paranoid_exit
15958 CFI_ENDPROC
15959 #endif
15960 -END(nmi)
15961 +ENDPROC(nmi)
15962
15963 ENTRY(ignore_sysret)
15964 CFI_STARTPROC
15965 mov $-ENOSYS,%eax
15966 sysret
15967 CFI_ENDPROC
15968 -END(ignore_sysret)
15969 +ENDPROC(ignore_sysret)
15970
15971 /*
15972 * End of kprobes section
15973 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
15974 index c9a281f..ce2f317 100644
15975 --- a/arch/x86/kernel/ftrace.c
15976 +++ b/arch/x86/kernel/ftrace.c
15977 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
15978 static const void *mod_code_newcode; /* holds the text to write to the IP */
15979
15980 static unsigned nmi_wait_count;
15981 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
15982 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
15983
15984 int ftrace_arch_read_dyn_info(char *buf, int size)
15985 {
15986 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
15987
15988 r = snprintf(buf, size, "%u %u",
15989 nmi_wait_count,
15990 - atomic_read(&nmi_update_count));
15991 + atomic_read_unchecked(&nmi_update_count));
15992 return r;
15993 }
15994
15995 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
15996
15997 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
15998 smp_rmb();
15999 + pax_open_kernel();
16000 ftrace_mod_code();
16001 - atomic_inc(&nmi_update_count);
16002 + pax_close_kernel();
16003 + atomic_inc_unchecked(&nmi_update_count);
16004 }
16005 /* Must have previous changes seen before executions */
16006 smp_mb();
16007 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16008 {
16009 unsigned char replaced[MCOUNT_INSN_SIZE];
16010
16011 + ip = ktla_ktva(ip);
16012 +
16013 /*
16014 * Note: Due to modules and __init, code can
16015 * disappear and change, we need to protect against faulting
16016 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16017 unsigned char old[MCOUNT_INSN_SIZE], *new;
16018 int ret;
16019
16020 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16021 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16022 new = ftrace_call_replace(ip, (unsigned long)func);
16023 ret = ftrace_modify_code(ip, old, new);
16024
16025 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16026 {
16027 unsigned char code[MCOUNT_INSN_SIZE];
16028
16029 + ip = ktla_ktva(ip);
16030 +
16031 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16032 return -EFAULT;
16033
16034 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16035 index 3bb0850..55a56f4 100644
16036 --- a/arch/x86/kernel/head32.c
16037 +++ b/arch/x86/kernel/head32.c
16038 @@ -19,6 +19,7 @@
16039 #include <asm/io_apic.h>
16040 #include <asm/bios_ebda.h>
16041 #include <asm/tlbflush.h>
16042 +#include <asm/boot.h>
16043
16044 static void __init i386_default_early_setup(void)
16045 {
16046 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
16047 {
16048 memblock_init();
16049
16050 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16051 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16052
16053 #ifdef CONFIG_BLK_DEV_INITRD
16054 /* Reserve INITRD */
16055 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16056 index ce0be7c..c41476e 100644
16057 --- a/arch/x86/kernel/head_32.S
16058 +++ b/arch/x86/kernel/head_32.S
16059 @@ -25,6 +25,12 @@
16060 /* Physical address */
16061 #define pa(X) ((X) - __PAGE_OFFSET)
16062
16063 +#ifdef CONFIG_PAX_KERNEXEC
16064 +#define ta(X) (X)
16065 +#else
16066 +#define ta(X) ((X) - __PAGE_OFFSET)
16067 +#endif
16068 +
16069 /*
16070 * References to members of the new_cpu_data structure.
16071 */
16072 @@ -54,11 +60,7 @@
16073 * and small than max_low_pfn, otherwise will waste some page table entries
16074 */
16075
16076 -#if PTRS_PER_PMD > 1
16077 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16078 -#else
16079 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16080 -#endif
16081 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16082
16083 /* Number of possible pages in the lowmem region */
16084 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16085 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16086 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16087
16088 /*
16089 + * Real beginning of normal "text" segment
16090 + */
16091 +ENTRY(stext)
16092 +ENTRY(_stext)
16093 +
16094 +/*
16095 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16096 * %esi points to the real-mode code as a 32-bit pointer.
16097 * CS and DS must be 4 GB flat segments, but we don't depend on
16098 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16099 * can.
16100 */
16101 __HEAD
16102 +
16103 +#ifdef CONFIG_PAX_KERNEXEC
16104 + jmp startup_32
16105 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16106 +.fill PAGE_SIZE-5,1,0xcc
16107 +#endif
16108 +
16109 ENTRY(startup_32)
16110 movl pa(stack_start),%ecx
16111
16112 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16113 2:
16114 leal -__PAGE_OFFSET(%ecx),%esp
16115
16116 +#ifdef CONFIG_SMP
16117 + movl $pa(cpu_gdt_table),%edi
16118 + movl $__per_cpu_load,%eax
16119 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16120 + rorl $16,%eax
16121 + movb %al,__KERNEL_PERCPU + 4(%edi)
16122 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16123 + movl $__per_cpu_end - 1,%eax
16124 + subl $__per_cpu_start,%eax
16125 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16126 +#endif
16127 +
16128 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16129 + movl $NR_CPUS,%ecx
16130 + movl $pa(cpu_gdt_table),%edi
16131 +1:
16132 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16133 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16134 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16135 + addl $PAGE_SIZE_asm,%edi
16136 + loop 1b
16137 +#endif
16138 +
16139 +#ifdef CONFIG_PAX_KERNEXEC
16140 + movl $pa(boot_gdt),%edi
16141 + movl $__LOAD_PHYSICAL_ADDR,%eax
16142 + movw %ax,__BOOT_CS + 2(%edi)
16143 + rorl $16,%eax
16144 + movb %al,__BOOT_CS + 4(%edi)
16145 + movb %ah,__BOOT_CS + 7(%edi)
16146 + rorl $16,%eax
16147 +
16148 + ljmp $(__BOOT_CS),$1f
16149 +1:
16150 +
16151 + movl $NR_CPUS,%ecx
16152 + movl $pa(cpu_gdt_table),%edi
16153 + addl $__PAGE_OFFSET,%eax
16154 +1:
16155 + movw %ax,__KERNEL_CS + 2(%edi)
16156 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16157 + rorl $16,%eax
16158 + movb %al,__KERNEL_CS + 4(%edi)
16159 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16160 + movb %ah,__KERNEL_CS + 7(%edi)
16161 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16162 + rorl $16,%eax
16163 + addl $PAGE_SIZE_asm,%edi
16164 + loop 1b
16165 +#endif
16166 +
16167 /*
16168 * Clear BSS first so that there are no surprises...
16169 */
16170 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16171 movl %eax, pa(max_pfn_mapped)
16172
16173 /* Do early initialization of the fixmap area */
16174 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16175 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16176 +#ifdef CONFIG_COMPAT_VDSO
16177 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16178 +#else
16179 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16180 +#endif
16181 #else /* Not PAE */
16182
16183 page_pde_offset = (__PAGE_OFFSET >> 20);
16184 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16185 movl %eax, pa(max_pfn_mapped)
16186
16187 /* Do early initialization of the fixmap area */
16188 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16189 - movl %eax,pa(initial_page_table+0xffc)
16190 +#ifdef CONFIG_COMPAT_VDSO
16191 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16192 +#else
16193 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16194 +#endif
16195 #endif
16196
16197 #ifdef CONFIG_PARAVIRT
16198 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16199 cmpl $num_subarch_entries, %eax
16200 jae bad_subarch
16201
16202 - movl pa(subarch_entries)(,%eax,4), %eax
16203 - subl $__PAGE_OFFSET, %eax
16204 - jmp *%eax
16205 + jmp *pa(subarch_entries)(,%eax,4)
16206
16207 bad_subarch:
16208 WEAK(lguest_entry)
16209 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16210 __INITDATA
16211
16212 subarch_entries:
16213 - .long default_entry /* normal x86/PC */
16214 - .long lguest_entry /* lguest hypervisor */
16215 - .long xen_entry /* Xen hypervisor */
16216 - .long default_entry /* Moorestown MID */
16217 + .long ta(default_entry) /* normal x86/PC */
16218 + .long ta(lguest_entry) /* lguest hypervisor */
16219 + .long ta(xen_entry) /* Xen hypervisor */
16220 + .long ta(default_entry) /* Moorestown MID */
16221 num_subarch_entries = (. - subarch_entries) / 4
16222 .previous
16223 #else
16224 @@ -312,6 +382,7 @@ default_entry:
16225 orl %edx,%eax
16226 movl %eax,%cr4
16227
16228 +#ifdef CONFIG_X86_PAE
16229 testb $X86_CR4_PAE, %al # check if PAE is enabled
16230 jz 6f
16231
16232 @@ -340,6 +411,9 @@ default_entry:
16233 /* Make changes effective */
16234 wrmsr
16235
16236 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16237 +#endif
16238 +
16239 6:
16240
16241 /*
16242 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16243 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16244 movl %eax,%ss # after changing gdt.
16245
16246 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16247 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16248 movl %eax,%ds
16249 movl %eax,%es
16250
16251 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16252 */
16253 cmpb $0,ready
16254 jne 1f
16255 - movl $gdt_page,%eax
16256 + movl $cpu_gdt_table,%eax
16257 movl $stack_canary,%ecx
16258 +#ifdef CONFIG_SMP
16259 + addl $__per_cpu_load,%ecx
16260 +#endif
16261 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16262 shrl $16, %ecx
16263 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16264 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16265 1:
16266 -#endif
16267 movl $(__KERNEL_STACK_CANARY),%eax
16268 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16269 + movl $(__USER_DS),%eax
16270 +#else
16271 + xorl %eax,%eax
16272 +#endif
16273 movl %eax,%gs
16274
16275 xorl %eax,%eax # Clear LDT
16276 @@ -558,22 +639,22 @@ early_page_fault:
16277 jmp early_fault
16278
16279 early_fault:
16280 - cld
16281 #ifdef CONFIG_PRINTK
16282 + cmpl $1,%ss:early_recursion_flag
16283 + je hlt_loop
16284 + incl %ss:early_recursion_flag
16285 + cld
16286 pusha
16287 movl $(__KERNEL_DS),%eax
16288 movl %eax,%ds
16289 movl %eax,%es
16290 - cmpl $2,early_recursion_flag
16291 - je hlt_loop
16292 - incl early_recursion_flag
16293 movl %cr2,%eax
16294 pushl %eax
16295 pushl %edx /* trapno */
16296 pushl $fault_msg
16297 call printk
16298 +; call dump_stack
16299 #endif
16300 - call dump_stack
16301 hlt_loop:
16302 hlt
16303 jmp hlt_loop
16304 @@ -581,8 +662,11 @@ hlt_loop:
16305 /* This is the default interrupt "handler" :-) */
16306 ALIGN
16307 ignore_int:
16308 - cld
16309 #ifdef CONFIG_PRINTK
16310 + cmpl $2,%ss:early_recursion_flag
16311 + je hlt_loop
16312 + incl %ss:early_recursion_flag
16313 + cld
16314 pushl %eax
16315 pushl %ecx
16316 pushl %edx
16317 @@ -591,9 +675,6 @@ ignore_int:
16318 movl $(__KERNEL_DS),%eax
16319 movl %eax,%ds
16320 movl %eax,%es
16321 - cmpl $2,early_recursion_flag
16322 - je hlt_loop
16323 - incl early_recursion_flag
16324 pushl 16(%esp)
16325 pushl 24(%esp)
16326 pushl 32(%esp)
16327 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16328 /*
16329 * BSS section
16330 */
16331 -__PAGE_ALIGNED_BSS
16332 - .align PAGE_SIZE
16333 #ifdef CONFIG_X86_PAE
16334 +.section .initial_pg_pmd,"a",@progbits
16335 initial_pg_pmd:
16336 .fill 1024*KPMDS,4,0
16337 #else
16338 +.section .initial_page_table,"a",@progbits
16339 ENTRY(initial_page_table)
16340 .fill 1024,4,0
16341 #endif
16342 +.section .initial_pg_fixmap,"a",@progbits
16343 initial_pg_fixmap:
16344 .fill 1024,4,0
16345 +.section .empty_zero_page,"a",@progbits
16346 ENTRY(empty_zero_page)
16347 .fill 4096,1,0
16348 +.section .swapper_pg_dir,"a",@progbits
16349 ENTRY(swapper_pg_dir)
16350 +#ifdef CONFIG_X86_PAE
16351 + .fill 4,8,0
16352 +#else
16353 .fill 1024,4,0
16354 +#endif
16355 +
16356 +/*
16357 + * The IDT has to be page-aligned to simplify the Pentium
16358 + * F0 0F bug workaround.. We have a special link segment
16359 + * for this.
16360 + */
16361 +.section .idt,"a",@progbits
16362 +ENTRY(idt_table)
16363 + .fill 256,8,0
16364
16365 /*
16366 * This starts the data section.
16367 */
16368 #ifdef CONFIG_X86_PAE
16369 -__PAGE_ALIGNED_DATA
16370 - /* Page-aligned for the benefit of paravirt? */
16371 - .align PAGE_SIZE
16372 +.section .initial_page_table,"a",@progbits
16373 ENTRY(initial_page_table)
16374 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16375 # if KPMDS == 3
16376 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16377 # error "Kernel PMDs should be 1, 2 or 3"
16378 # endif
16379 .align PAGE_SIZE /* needs to be page-sized too */
16380 +
16381 +#ifdef CONFIG_PAX_PER_CPU_PGD
16382 +ENTRY(cpu_pgd)
16383 + .rept NR_CPUS
16384 + .fill 4,8,0
16385 + .endr
16386 +#endif
16387 +
16388 #endif
16389
16390 .data
16391 .balign 4
16392 ENTRY(stack_start)
16393 - .long init_thread_union+THREAD_SIZE
16394 + .long init_thread_union+THREAD_SIZE-8
16395
16396 +ready: .byte 0
16397 +
16398 +.section .rodata,"a",@progbits
16399 early_recursion_flag:
16400 .long 0
16401
16402 -ready: .byte 0
16403 -
16404 int_msg:
16405 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16406
16407 @@ -707,7 +811,7 @@ fault_msg:
16408 .word 0 # 32 bit align gdt_desc.address
16409 boot_gdt_descr:
16410 .word __BOOT_DS+7
16411 - .long boot_gdt - __PAGE_OFFSET
16412 + .long pa(boot_gdt)
16413
16414 .word 0 # 32-bit align idt_desc.address
16415 idt_descr:
16416 @@ -718,7 +822,7 @@ idt_descr:
16417 .word 0 # 32 bit align gdt_desc.address
16418 ENTRY(early_gdt_descr)
16419 .word GDT_ENTRIES*8-1
16420 - .long gdt_page /* Overwritten for secondary CPUs */
16421 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16422
16423 /*
16424 * The boot_gdt must mirror the equivalent in setup.S and is
16425 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16426 .align L1_CACHE_BYTES
16427 ENTRY(boot_gdt)
16428 .fill GDT_ENTRY_BOOT_CS,8,0
16429 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16430 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16431 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16432 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16433 +
16434 + .align PAGE_SIZE_asm
16435 +ENTRY(cpu_gdt_table)
16436 + .rept NR_CPUS
16437 + .quad 0x0000000000000000 /* NULL descriptor */
16438 + .quad 0x0000000000000000 /* 0x0b reserved */
16439 + .quad 0x0000000000000000 /* 0x13 reserved */
16440 + .quad 0x0000000000000000 /* 0x1b reserved */
16441 +
16442 +#ifdef CONFIG_PAX_KERNEXEC
16443 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16444 +#else
16445 + .quad 0x0000000000000000 /* 0x20 unused */
16446 +#endif
16447 +
16448 + .quad 0x0000000000000000 /* 0x28 unused */
16449 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16450 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16451 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16452 + .quad 0x0000000000000000 /* 0x4b reserved */
16453 + .quad 0x0000000000000000 /* 0x53 reserved */
16454 + .quad 0x0000000000000000 /* 0x5b reserved */
16455 +
16456 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16457 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16458 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16459 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16460 +
16461 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16462 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16463 +
16464 + /*
16465 + * Segments used for calling PnP BIOS have byte granularity.
16466 + * The code segments and data segments have fixed 64k limits,
16467 + * the transfer segment sizes are set at run time.
16468 + */
16469 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16470 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16471 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16472 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16473 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16474 +
16475 + /*
16476 + * The APM segments have byte granularity and their bases
16477 + * are set at run time. All have 64k limits.
16478 + */
16479 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16480 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16481 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16482 +
16483 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16484 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16485 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16486 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16487 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16488 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16489 +
16490 + /* Be sure this is zeroed to avoid false validations in Xen */
16491 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16492 + .endr
16493 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16494 index e11e394..9aebc5d 100644
16495 --- a/arch/x86/kernel/head_64.S
16496 +++ b/arch/x86/kernel/head_64.S
16497 @@ -19,6 +19,8 @@
16498 #include <asm/cache.h>
16499 #include <asm/processor-flags.h>
16500 #include <asm/percpu.h>
16501 +#include <asm/cpufeature.h>
16502 +#include <asm/alternative-asm.h>
16503
16504 #ifdef CONFIG_PARAVIRT
16505 #include <asm/asm-offsets.h>
16506 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16507 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16508 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16509 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16510 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16511 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16512 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16513 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16514 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16515 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16516
16517 .text
16518 __HEAD
16519 @@ -85,35 +93,23 @@ startup_64:
16520 */
16521 addq %rbp, init_level4_pgt + 0(%rip)
16522 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16523 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16524 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16525 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16526 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16527
16528 addq %rbp, level3_ident_pgt + 0(%rip)
16529 +#ifndef CONFIG_XEN
16530 + addq %rbp, level3_ident_pgt + 8(%rip)
16531 +#endif
16532
16533 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16534 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16535 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16536 +
16537 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16538 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16539
16540 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16541 -
16542 - /* Add an Identity mapping if I am above 1G */
16543 - leaq _text(%rip), %rdi
16544 - andq $PMD_PAGE_MASK, %rdi
16545 -
16546 - movq %rdi, %rax
16547 - shrq $PUD_SHIFT, %rax
16548 - andq $(PTRS_PER_PUD - 1), %rax
16549 - jz ident_complete
16550 -
16551 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16552 - leaq level3_ident_pgt(%rip), %rbx
16553 - movq %rdx, 0(%rbx, %rax, 8)
16554 -
16555 - movq %rdi, %rax
16556 - shrq $PMD_SHIFT, %rax
16557 - andq $(PTRS_PER_PMD - 1), %rax
16558 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16559 - leaq level2_spare_pgt(%rip), %rbx
16560 - movq %rdx, 0(%rbx, %rax, 8)
16561 -ident_complete:
16562 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16563
16564 /*
16565 * Fixup the kernel text+data virtual addresses. Note that
16566 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16567 * after the boot processor executes this code.
16568 */
16569
16570 - /* Enable PAE mode and PGE */
16571 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16572 + /* Enable PAE mode and PSE/PGE */
16573 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16574 movq %rax, %cr4
16575
16576 /* Setup early boot stage 4 level pagetables. */
16577 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16578 movl $MSR_EFER, %ecx
16579 rdmsr
16580 btsl $_EFER_SCE, %eax /* Enable System Call */
16581 - btl $20,%edi /* No Execute supported? */
16582 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16583 jnc 1f
16584 btsl $_EFER_NX, %eax
16585 + leaq init_level4_pgt(%rip), %rdi
16586 +#ifndef CONFIG_EFI
16587 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16588 +#endif
16589 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16590 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16591 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16592 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16593 1: wrmsr /* Make changes effective */
16594
16595 /* Setup cr0 */
16596 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16597 * jump. In addition we need to ensure %cs is set so we make this
16598 * a far return.
16599 */
16600 + pax_set_fptr_mask
16601 movq initial_code(%rip),%rax
16602 pushq $0 # fake return address to stop unwinder
16603 pushq $__KERNEL_CS # set correct cs
16604 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16605 bad_address:
16606 jmp bad_address
16607
16608 - .section ".init.text","ax"
16609 + __INIT
16610 #ifdef CONFIG_EARLY_PRINTK
16611 .globl early_idt_handlers
16612 early_idt_handlers:
16613 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16614 #endif /* EARLY_PRINTK */
16615 1: hlt
16616 jmp 1b
16617 + .previous
16618
16619 #ifdef CONFIG_EARLY_PRINTK
16620 + __INITDATA
16621 early_recursion_flag:
16622 .long 0
16623 + .previous
16624
16625 + .section .rodata,"a",@progbits
16626 early_idt_msg:
16627 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16628 early_idt_ripmsg:
16629 .asciz "RIP %s\n"
16630 + .previous
16631 #endif /* CONFIG_EARLY_PRINTK */
16632 - .previous
16633
16634 + .section .rodata,"a",@progbits
16635 #define NEXT_PAGE(name) \
16636 .balign PAGE_SIZE; \
16637 ENTRY(name)
16638 @@ -338,7 +348,6 @@ ENTRY(name)
16639 i = i + 1 ; \
16640 .endr
16641
16642 - .data
16643 /*
16644 * This default setting generates an ident mapping at address 0x100000
16645 * and a mapping for the kernel that precisely maps virtual address
16646 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16647 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16648 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16649 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16650 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16651 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16652 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16653 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16654 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16655 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16656 .org init_level4_pgt + L4_START_KERNEL*8, 0
16657 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16658 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16659
16660 +#ifdef CONFIG_PAX_PER_CPU_PGD
16661 +NEXT_PAGE(cpu_pgd)
16662 + .rept NR_CPUS
16663 + .fill 512,8,0
16664 + .endr
16665 +#endif
16666 +
16667 NEXT_PAGE(level3_ident_pgt)
16668 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16669 +#ifdef CONFIG_XEN
16670 .fill 511,8,0
16671 +#else
16672 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16673 + .fill 510,8,0
16674 +#endif
16675 +
16676 +NEXT_PAGE(level3_vmalloc_start_pgt)
16677 + .fill 512,8,0
16678 +
16679 +NEXT_PAGE(level3_vmalloc_end_pgt)
16680 + .fill 512,8,0
16681 +
16682 +NEXT_PAGE(level3_vmemmap_pgt)
16683 + .fill L3_VMEMMAP_START,8,0
16684 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16685
16686 NEXT_PAGE(level3_kernel_pgt)
16687 .fill L3_START_KERNEL,8,0
16688 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16689 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16690 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16691
16692 +NEXT_PAGE(level2_vmemmap_pgt)
16693 + .fill 512,8,0
16694 +
16695 NEXT_PAGE(level2_fixmap_pgt)
16696 - .fill 506,8,0
16697 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16698 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16699 - .fill 5,8,0
16700 + .fill 507,8,0
16701 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16702 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16703 + .fill 4,8,0
16704
16705 -NEXT_PAGE(level1_fixmap_pgt)
16706 +NEXT_PAGE(level1_vsyscall_pgt)
16707 .fill 512,8,0
16708
16709 -NEXT_PAGE(level2_ident_pgt)
16710 - /* Since I easily can, map the first 1G.
16711 + /* Since I easily can, map the first 2G.
16712 * Don't set NX because code runs from these pages.
16713 */
16714 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16715 +NEXT_PAGE(level2_ident_pgt)
16716 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16717
16718 NEXT_PAGE(level2_kernel_pgt)
16719 /*
16720 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
16721 * If you want to increase this then increase MODULES_VADDR
16722 * too.)
16723 */
16724 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16725 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16726 -
16727 -NEXT_PAGE(level2_spare_pgt)
16728 - .fill 512, 8, 0
16729 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16730
16731 #undef PMDS
16732 #undef NEXT_PAGE
16733
16734 - .data
16735 + .align PAGE_SIZE
16736 +ENTRY(cpu_gdt_table)
16737 + .rept NR_CPUS
16738 + .quad 0x0000000000000000 /* NULL descriptor */
16739 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16740 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16741 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16742 + .quad 0x00cffb000000ffff /* __USER32_CS */
16743 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16744 + .quad 0x00affb000000ffff /* __USER_CS */
16745 +
16746 +#ifdef CONFIG_PAX_KERNEXEC
16747 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16748 +#else
16749 + .quad 0x0 /* unused */
16750 +#endif
16751 +
16752 + .quad 0,0 /* TSS */
16753 + .quad 0,0 /* LDT */
16754 + .quad 0,0,0 /* three TLS descriptors */
16755 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16756 + /* asm/segment.h:GDT_ENTRIES must match this */
16757 +
16758 + /* zero the remaining page */
16759 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16760 + .endr
16761 +
16762 .align 16
16763 .globl early_gdt_descr
16764 early_gdt_descr:
16765 .word GDT_ENTRIES*8-1
16766 early_gdt_descr_base:
16767 - .quad INIT_PER_CPU_VAR(gdt_page)
16768 + .quad cpu_gdt_table
16769
16770 ENTRY(phys_base)
16771 /* This must match the first entry in level2_kernel_pgt */
16772 .quad 0x0000000000000000
16773
16774 #include "../../x86/xen/xen-head.S"
16775 -
16776 - .section .bss, "aw", @nobits
16777 +
16778 + .section .rodata,"a",@progbits
16779 .align L1_CACHE_BYTES
16780 ENTRY(idt_table)
16781 - .skip IDT_ENTRIES * 16
16782 + .fill 512,8,0
16783
16784 __PAGE_ALIGNED_BSS
16785 .align PAGE_SIZE
16786 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16787 index 9c3bd4a..e1d9b35 100644
16788 --- a/arch/x86/kernel/i386_ksyms_32.c
16789 +++ b/arch/x86/kernel/i386_ksyms_32.c
16790 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16791 EXPORT_SYMBOL(cmpxchg8b_emu);
16792 #endif
16793
16794 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
16795 +
16796 /* Networking helper routines. */
16797 EXPORT_SYMBOL(csum_partial_copy_generic);
16798 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16799 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16800
16801 EXPORT_SYMBOL(__get_user_1);
16802 EXPORT_SYMBOL(__get_user_2);
16803 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
16804
16805 EXPORT_SYMBOL(csum_partial);
16806 EXPORT_SYMBOL(empty_zero_page);
16807 +
16808 +#ifdef CONFIG_PAX_KERNEXEC
16809 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
16810 +#endif
16811 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
16812 index 6104852..6114160 100644
16813 --- a/arch/x86/kernel/i8259.c
16814 +++ b/arch/x86/kernel/i8259.c
16815 @@ -210,7 +210,7 @@ spurious_8259A_irq:
16816 "spurious 8259A interrupt: IRQ%d.\n", irq);
16817 spurious_irq_mask |= irqmask;
16818 }
16819 - atomic_inc(&irq_err_count);
16820 + atomic_inc_unchecked(&irq_err_count);
16821 /*
16822 * Theoretically we do not have to handle this IRQ,
16823 * but in Linux this does not cause problems and is
16824 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
16825 index 43e9ccf..44ccf6f 100644
16826 --- a/arch/x86/kernel/init_task.c
16827 +++ b/arch/x86/kernel/init_task.c
16828 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
16829 * way process stacks are handled. This is done by having a special
16830 * "init_task" linker map entry..
16831 */
16832 -union thread_union init_thread_union __init_task_data =
16833 - { INIT_THREAD_INFO(init_task) };
16834 +union thread_union init_thread_union __init_task_data;
16835
16836 /*
16837 * Initial task structure.
16838 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
16839 * section. Since TSS's are completely CPU-local, we want them
16840 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
16841 */
16842 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
16843 -
16844 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
16845 +EXPORT_SYMBOL(init_tss);
16846 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
16847 index 8c96897..be66bfa 100644
16848 --- a/arch/x86/kernel/ioport.c
16849 +++ b/arch/x86/kernel/ioport.c
16850 @@ -6,6 +6,7 @@
16851 #include <linux/sched.h>
16852 #include <linux/kernel.h>
16853 #include <linux/capability.h>
16854 +#include <linux/security.h>
16855 #include <linux/errno.h>
16856 #include <linux/types.h>
16857 #include <linux/ioport.h>
16858 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16859
16860 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
16861 return -EINVAL;
16862 +#ifdef CONFIG_GRKERNSEC_IO
16863 + if (turn_on && grsec_disable_privio) {
16864 + gr_handle_ioperm();
16865 + return -EPERM;
16866 + }
16867 +#endif
16868 if (turn_on && !capable(CAP_SYS_RAWIO))
16869 return -EPERM;
16870
16871 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16872 * because the ->io_bitmap_max value must match the bitmap
16873 * contents:
16874 */
16875 - tss = &per_cpu(init_tss, get_cpu());
16876 + tss = init_tss + get_cpu();
16877
16878 if (turn_on)
16879 bitmap_clear(t->io_bitmap_ptr, from, num);
16880 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
16881 return -EINVAL;
16882 /* Trying to gain more privileges? */
16883 if (level > old) {
16884 +#ifdef CONFIG_GRKERNSEC_IO
16885 + if (grsec_disable_privio) {
16886 + gr_handle_iopl();
16887 + return -EPERM;
16888 + }
16889 +#endif
16890 if (!capable(CAP_SYS_RAWIO))
16891 return -EPERM;
16892 }
16893 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
16894 index 429e0c9..17b3ece 100644
16895 --- a/arch/x86/kernel/irq.c
16896 +++ b/arch/x86/kernel/irq.c
16897 @@ -18,7 +18,7 @@
16898 #include <asm/mce.h>
16899 #include <asm/hw_irq.h>
16900
16901 -atomic_t irq_err_count;
16902 +atomic_unchecked_t irq_err_count;
16903
16904 /* Function pointer for generic interrupt vector handling */
16905 void (*x86_platform_ipi_callback)(void) = NULL;
16906 @@ -117,9 +117,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
16907 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
16908 seq_printf(p, " Machine check polls\n");
16909 #endif
16910 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
16911 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
16912 #if defined(CONFIG_X86_IO_APIC)
16913 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
16914 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
16915 #endif
16916 return 0;
16917 }
16918 @@ -159,10 +159,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
16919
16920 u64 arch_irq_stat(void)
16921 {
16922 - u64 sum = atomic_read(&irq_err_count);
16923 + u64 sum = atomic_read_unchecked(&irq_err_count);
16924
16925 #ifdef CONFIG_X86_IO_APIC
16926 - sum += atomic_read(&irq_mis_count);
16927 + sum += atomic_read_unchecked(&irq_mis_count);
16928 #endif
16929 return sum;
16930 }
16931 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
16932 index 7209070..cbcd71a 100644
16933 --- a/arch/x86/kernel/irq_32.c
16934 +++ b/arch/x86/kernel/irq_32.c
16935 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
16936 __asm__ __volatile__("andl %%esp,%0" :
16937 "=r" (sp) : "0" (THREAD_SIZE - 1));
16938
16939 - return sp < (sizeof(struct thread_info) + STACK_WARN);
16940 + return sp < STACK_WARN;
16941 }
16942
16943 static void print_stack_overflow(void)
16944 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
16945 * per-CPU IRQ handling contexts (thread information and stack)
16946 */
16947 union irq_ctx {
16948 - struct thread_info tinfo;
16949 - u32 stack[THREAD_SIZE/sizeof(u32)];
16950 + unsigned long previous_esp;
16951 + u32 stack[THREAD_SIZE/sizeof(u32)];
16952 } __attribute__((aligned(THREAD_SIZE)));
16953
16954 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
16955 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
16956 static inline int
16957 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16958 {
16959 - union irq_ctx *curctx, *irqctx;
16960 + union irq_ctx *irqctx;
16961 u32 *isp, arg1, arg2;
16962
16963 - curctx = (union irq_ctx *) current_thread_info();
16964 irqctx = __this_cpu_read(hardirq_ctx);
16965
16966 /*
16967 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16968 * handler) we can't do that and just have to keep using the
16969 * current stack (which is the irq stack already after all)
16970 */
16971 - if (unlikely(curctx == irqctx))
16972 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
16973 return 0;
16974
16975 /* build the stack frame on the IRQ stack */
16976 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
16977 - irqctx->tinfo.task = curctx->tinfo.task;
16978 - irqctx->tinfo.previous_esp = current_stack_pointer;
16979 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
16980 + irqctx->previous_esp = current_stack_pointer;
16981
16982 - /*
16983 - * Copy the softirq bits in preempt_count so that the
16984 - * softirq checks work in the hardirq context.
16985 - */
16986 - irqctx->tinfo.preempt_count =
16987 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
16988 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
16989 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16990 + __set_fs(MAKE_MM_SEG(0));
16991 +#endif
16992
16993 if (unlikely(overflow))
16994 call_on_stack(print_stack_overflow, isp);
16995 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16996 : "0" (irq), "1" (desc), "2" (isp),
16997 "D" (desc->handle_irq)
16998 : "memory", "cc", "ecx");
16999 +
17000 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17001 + __set_fs(current_thread_info()->addr_limit);
17002 +#endif
17003 +
17004 return 1;
17005 }
17006
17007 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17008 */
17009 void __cpuinit irq_ctx_init(int cpu)
17010 {
17011 - union irq_ctx *irqctx;
17012 -
17013 if (per_cpu(hardirq_ctx, cpu))
17014 return;
17015
17016 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17017 - THREAD_FLAGS,
17018 - THREAD_ORDER));
17019 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17020 - irqctx->tinfo.cpu = cpu;
17021 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17022 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17023 -
17024 - per_cpu(hardirq_ctx, cpu) = irqctx;
17025 -
17026 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17027 - THREAD_FLAGS,
17028 - THREAD_ORDER));
17029 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17030 - irqctx->tinfo.cpu = cpu;
17031 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17032 -
17033 - per_cpu(softirq_ctx, cpu) = irqctx;
17034 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17035 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17036
17037 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17038 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17039 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
17040 asmlinkage void do_softirq(void)
17041 {
17042 unsigned long flags;
17043 - struct thread_info *curctx;
17044 union irq_ctx *irqctx;
17045 u32 *isp;
17046
17047 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
17048 local_irq_save(flags);
17049
17050 if (local_softirq_pending()) {
17051 - curctx = current_thread_info();
17052 irqctx = __this_cpu_read(softirq_ctx);
17053 - irqctx->tinfo.task = curctx->task;
17054 - irqctx->tinfo.previous_esp = current_stack_pointer;
17055 + irqctx->previous_esp = current_stack_pointer;
17056
17057 /* build the stack frame on the softirq stack */
17058 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17059 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17060 +
17061 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17062 + __set_fs(MAKE_MM_SEG(0));
17063 +#endif
17064
17065 call_on_stack(__do_softirq, isp);
17066 +
17067 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17068 + __set_fs(current_thread_info()->addr_limit);
17069 +#endif
17070 +
17071 /*
17072 * Shouldn't happen, we returned above if in_interrupt():
17073 */
17074 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17075 index 69bca46..0bac999 100644
17076 --- a/arch/x86/kernel/irq_64.c
17077 +++ b/arch/x86/kernel/irq_64.c
17078 @@ -38,7 +38,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17079 #ifdef CONFIG_DEBUG_STACKOVERFLOW
17080 u64 curbase = (u64)task_stack_page(current);
17081
17082 - if (user_mode_vm(regs))
17083 + if (user_mode(regs))
17084 return;
17085
17086 WARN_ONCE(regs->sp >= curbase &&
17087 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17088 index faba577..93b9e71 100644
17089 --- a/arch/x86/kernel/kgdb.c
17090 +++ b/arch/x86/kernel/kgdb.c
17091 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17092 #ifdef CONFIG_X86_32
17093 switch (regno) {
17094 case GDB_SS:
17095 - if (!user_mode_vm(regs))
17096 + if (!user_mode(regs))
17097 *(unsigned long *)mem = __KERNEL_DS;
17098 break;
17099 case GDB_SP:
17100 - if (!user_mode_vm(regs))
17101 + if (!user_mode(regs))
17102 *(unsigned long *)mem = kernel_stack_pointer(regs);
17103 break;
17104 case GDB_GS:
17105 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17106 case 'k':
17107 /* clear the trace bit */
17108 linux_regs->flags &= ~X86_EFLAGS_TF;
17109 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17110 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17111
17112 /* set the trace bit if we're stepping */
17113 if (remcomInBuffer[0] == 's') {
17114 linux_regs->flags |= X86_EFLAGS_TF;
17115 - atomic_set(&kgdb_cpu_doing_single_step,
17116 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17117 raw_smp_processor_id());
17118 }
17119
17120 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17121
17122 switch (cmd) {
17123 case DIE_DEBUG:
17124 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17125 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17126 if (user_mode(regs))
17127 return single_step_cont(regs, args);
17128 break;
17129 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17130 index 7da647d..56fe348 100644
17131 --- a/arch/x86/kernel/kprobes.c
17132 +++ b/arch/x86/kernel/kprobes.c
17133 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17134 } __attribute__((packed)) *insn;
17135
17136 insn = (struct __arch_relative_insn *)from;
17137 +
17138 + pax_open_kernel();
17139 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17140 insn->op = op;
17141 + pax_close_kernel();
17142 }
17143
17144 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17145 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17146 kprobe_opcode_t opcode;
17147 kprobe_opcode_t *orig_opcodes = opcodes;
17148
17149 - if (search_exception_tables((unsigned long)opcodes))
17150 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17151 return 0; /* Page fault may occur on this address. */
17152
17153 retry:
17154 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17155 }
17156 }
17157 insn_get_length(&insn);
17158 + pax_open_kernel();
17159 memcpy(dest, insn.kaddr, insn.length);
17160 + pax_close_kernel();
17161
17162 #ifdef CONFIG_X86_64
17163 if (insn_rip_relative(&insn)) {
17164 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17165 (u8 *) dest;
17166 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17167 disp = (u8 *) dest + insn_offset_displacement(&insn);
17168 + pax_open_kernel();
17169 *(s32 *) disp = (s32) newdisp;
17170 + pax_close_kernel();
17171 }
17172 #endif
17173 return insn.length;
17174 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17175 */
17176 __copy_instruction(p->ainsn.insn, p->addr, 0);
17177
17178 - if (can_boost(p->addr))
17179 + if (can_boost(ktla_ktva(p->addr)))
17180 p->ainsn.boostable = 0;
17181 else
17182 p->ainsn.boostable = -1;
17183
17184 - p->opcode = *p->addr;
17185 + p->opcode = *(ktla_ktva(p->addr));
17186 }
17187
17188 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17189 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17190 * nor set current_kprobe, because it doesn't use single
17191 * stepping.
17192 */
17193 - regs->ip = (unsigned long)p->ainsn.insn;
17194 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17195 preempt_enable_no_resched();
17196 return;
17197 }
17198 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17199 if (p->opcode == BREAKPOINT_INSTRUCTION)
17200 regs->ip = (unsigned long)p->addr;
17201 else
17202 - regs->ip = (unsigned long)p->ainsn.insn;
17203 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17204 }
17205
17206 /*
17207 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17208 setup_singlestep(p, regs, kcb, 0);
17209 return 1;
17210 }
17211 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17212 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17213 /*
17214 * The breakpoint instruction was removed right
17215 * after we hit it. Another cpu has removed
17216 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17217 " movq %rax, 152(%rsp)\n"
17218 RESTORE_REGS_STRING
17219 " popfq\n"
17220 +#ifdef KERNEXEC_PLUGIN
17221 + " btsq $63,(%rsp)\n"
17222 +#endif
17223 #else
17224 " pushf\n"
17225 SAVE_REGS_STRING
17226 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17227 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17228 {
17229 unsigned long *tos = stack_addr(regs);
17230 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17231 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17232 unsigned long orig_ip = (unsigned long)p->addr;
17233 kprobe_opcode_t *insn = p->ainsn.insn;
17234
17235 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17236 struct die_args *args = data;
17237 int ret = NOTIFY_DONE;
17238
17239 - if (args->regs && user_mode_vm(args->regs))
17240 + if (args->regs && user_mode(args->regs))
17241 return ret;
17242
17243 switch (val) {
17244 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17245 * Verify if the address gap is in 2GB range, because this uses
17246 * a relative jump.
17247 */
17248 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17249 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17250 if (abs(rel) > 0x7fffffff)
17251 return -ERANGE;
17252
17253 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17254 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17255
17256 /* Set probe function call */
17257 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17258 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17259
17260 /* Set returning jmp instruction at the tail of out-of-line buffer */
17261 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17262 - (u8 *)op->kp.addr + op->optinsn.size);
17263 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17264
17265 flush_icache_range((unsigned long) buf,
17266 (unsigned long) buf + TMPL_END_IDX +
17267 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17268 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17269
17270 /* Backup instructions which will be replaced by jump address */
17271 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17272 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17273 RELATIVE_ADDR_SIZE);
17274
17275 insn_buf[0] = RELATIVEJUMP_OPCODE;
17276 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
17277 index a9c2116..a52d4fc 100644
17278 --- a/arch/x86/kernel/kvm.c
17279 +++ b/arch/x86/kernel/kvm.c
17280 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
17281 pv_mmu_ops.set_pud = kvm_set_pud;
17282 #if PAGETABLE_LEVELS == 4
17283 pv_mmu_ops.set_pgd = kvm_set_pgd;
17284 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
17285 #endif
17286 #endif
17287 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
17288 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17289 index ea69726..604d066 100644
17290 --- a/arch/x86/kernel/ldt.c
17291 +++ b/arch/x86/kernel/ldt.c
17292 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17293 if (reload) {
17294 #ifdef CONFIG_SMP
17295 preempt_disable();
17296 - load_LDT(pc);
17297 + load_LDT_nolock(pc);
17298 if (!cpumask_equal(mm_cpumask(current->mm),
17299 cpumask_of(smp_processor_id())))
17300 smp_call_function(flush_ldt, current->mm, 1);
17301 preempt_enable();
17302 #else
17303 - load_LDT(pc);
17304 + load_LDT_nolock(pc);
17305 #endif
17306 }
17307 if (oldsize) {
17308 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17309 return err;
17310
17311 for (i = 0; i < old->size; i++)
17312 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17313 + write_ldt_entry(new->ldt, i, old->ldt + i);
17314 return 0;
17315 }
17316
17317 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17318 retval = copy_ldt(&mm->context, &old_mm->context);
17319 mutex_unlock(&old_mm->context.lock);
17320 }
17321 +
17322 + if (tsk == current) {
17323 + mm->context.vdso = 0;
17324 +
17325 +#ifdef CONFIG_X86_32
17326 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17327 + mm->context.user_cs_base = 0UL;
17328 + mm->context.user_cs_limit = ~0UL;
17329 +
17330 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17331 + cpus_clear(mm->context.cpu_user_cs_mask);
17332 +#endif
17333 +
17334 +#endif
17335 +#endif
17336 +
17337 + }
17338 +
17339 return retval;
17340 }
17341
17342 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17343 }
17344 }
17345
17346 +#ifdef CONFIG_PAX_SEGMEXEC
17347 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17348 + error = -EINVAL;
17349 + goto out_unlock;
17350 + }
17351 +#endif
17352 +
17353 fill_ldt(&ldt, &ldt_info);
17354 if (oldmode)
17355 ldt.avl = 0;
17356 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17357 index a3fa43b..8966f4c 100644
17358 --- a/arch/x86/kernel/machine_kexec_32.c
17359 +++ b/arch/x86/kernel/machine_kexec_32.c
17360 @@ -27,7 +27,7 @@
17361 #include <asm/cacheflush.h>
17362 #include <asm/debugreg.h>
17363
17364 -static void set_idt(void *newidt, __u16 limit)
17365 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17366 {
17367 struct desc_ptr curidt;
17368
17369 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17370 }
17371
17372
17373 -static void set_gdt(void *newgdt, __u16 limit)
17374 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17375 {
17376 struct desc_ptr curgdt;
17377
17378 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17379 }
17380
17381 control_page = page_address(image->control_code_page);
17382 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17383 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17384
17385 relocate_kernel_ptr = control_page;
17386 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17387 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17388 index 3ca42d0..7cff8cc 100644
17389 --- a/arch/x86/kernel/microcode_intel.c
17390 +++ b/arch/x86/kernel/microcode_intel.c
17391 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17392
17393 static int get_ucode_user(void *to, const void *from, size_t n)
17394 {
17395 - return copy_from_user(to, from, n);
17396 + return copy_from_user(to, (const void __force_user *)from, n);
17397 }
17398
17399 static enum ucode_state
17400 request_microcode_user(int cpu, const void __user *buf, size_t size)
17401 {
17402 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17403 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17404 }
17405
17406 static void microcode_fini_cpu(int cpu)
17407 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17408 index 925179f..267ac7a 100644
17409 --- a/arch/x86/kernel/module.c
17410 +++ b/arch/x86/kernel/module.c
17411 @@ -36,15 +36,60 @@
17412 #define DEBUGP(fmt...)
17413 #endif
17414
17415 -void *module_alloc(unsigned long size)
17416 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17417 {
17418 - if (PAGE_ALIGN(size) > MODULES_LEN)
17419 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17420 return NULL;
17421 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17422 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17423 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17424 -1, __builtin_return_address(0));
17425 }
17426
17427 +void *module_alloc(unsigned long size)
17428 +{
17429 +
17430 +#ifdef CONFIG_PAX_KERNEXEC
17431 + return __module_alloc(size, PAGE_KERNEL);
17432 +#else
17433 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17434 +#endif
17435 +
17436 +}
17437 +
17438 +#ifdef CONFIG_PAX_KERNEXEC
17439 +#ifdef CONFIG_X86_32
17440 +void *module_alloc_exec(unsigned long size)
17441 +{
17442 + struct vm_struct *area;
17443 +
17444 + if (size == 0)
17445 + return NULL;
17446 +
17447 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17448 + return area ? area->addr : NULL;
17449 +}
17450 +EXPORT_SYMBOL(module_alloc_exec);
17451 +
17452 +void module_free_exec(struct module *mod, void *module_region)
17453 +{
17454 + vunmap(module_region);
17455 +}
17456 +EXPORT_SYMBOL(module_free_exec);
17457 +#else
17458 +void module_free_exec(struct module *mod, void *module_region)
17459 +{
17460 + module_free(mod, module_region);
17461 +}
17462 +EXPORT_SYMBOL(module_free_exec);
17463 +
17464 +void *module_alloc_exec(unsigned long size)
17465 +{
17466 + return __module_alloc(size, PAGE_KERNEL_RX);
17467 +}
17468 +EXPORT_SYMBOL(module_alloc_exec);
17469 +#endif
17470 +#endif
17471 +
17472 #ifdef CONFIG_X86_32
17473 int apply_relocate(Elf32_Shdr *sechdrs,
17474 const char *strtab,
17475 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17476 unsigned int i;
17477 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17478 Elf32_Sym *sym;
17479 - uint32_t *location;
17480 + uint32_t *plocation, location;
17481
17482 DEBUGP("Applying relocate section %u to %u\n", relsec,
17483 sechdrs[relsec].sh_info);
17484 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17485 /* This is where to make the change */
17486 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17487 - + rel[i].r_offset;
17488 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17489 + location = (uint32_t)plocation;
17490 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17491 + plocation = ktla_ktva((void *)plocation);
17492 /* This is the symbol it is referring to. Note that all
17493 undefined symbols have been resolved. */
17494 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17495 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17496 switch (ELF32_R_TYPE(rel[i].r_info)) {
17497 case R_386_32:
17498 /* We add the value into the location given */
17499 - *location += sym->st_value;
17500 + pax_open_kernel();
17501 + *plocation += sym->st_value;
17502 + pax_close_kernel();
17503 break;
17504 case R_386_PC32:
17505 /* Add the value, subtract its postition */
17506 - *location += sym->st_value - (uint32_t)location;
17507 + pax_open_kernel();
17508 + *plocation += sym->st_value - location;
17509 + pax_close_kernel();
17510 break;
17511 default:
17512 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17513 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17514 case R_X86_64_NONE:
17515 break;
17516 case R_X86_64_64:
17517 + pax_open_kernel();
17518 *(u64 *)loc = val;
17519 + pax_close_kernel();
17520 break;
17521 case R_X86_64_32:
17522 + pax_open_kernel();
17523 *(u32 *)loc = val;
17524 + pax_close_kernel();
17525 if (val != *(u32 *)loc)
17526 goto overflow;
17527 break;
17528 case R_X86_64_32S:
17529 + pax_open_kernel();
17530 *(s32 *)loc = val;
17531 + pax_close_kernel();
17532 if ((s64)val != *(s32 *)loc)
17533 goto overflow;
17534 break;
17535 case R_X86_64_PC32:
17536 val -= (u64)loc;
17537 + pax_open_kernel();
17538 *(u32 *)loc = val;
17539 + pax_close_kernel();
17540 +
17541 #if 0
17542 if ((s64)val != *(s32 *)loc)
17543 goto overflow;
17544 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17545 index e88f37b..1353db6 100644
17546 --- a/arch/x86/kernel/nmi.c
17547 +++ b/arch/x86/kernel/nmi.c
17548 @@ -408,6 +408,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
17549 dotraplinkage notrace __kprobes void
17550 do_nmi(struct pt_regs *regs, long error_code)
17551 {
17552 +
17553 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17554 + if (!user_mode(regs)) {
17555 + unsigned long cs = regs->cs & 0xFFFF;
17556 + unsigned long ip = ktva_ktla(regs->ip);
17557 +
17558 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17559 + regs->ip = ip;
17560 + }
17561 +#endif
17562 +
17563 nmi_enter();
17564
17565 inc_irq_stat(__nmi_count);
17566 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17567 index 676b8c7..870ba04 100644
17568 --- a/arch/x86/kernel/paravirt-spinlocks.c
17569 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17570 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17571 arch_spin_lock(lock);
17572 }
17573
17574 -struct pv_lock_ops pv_lock_ops = {
17575 +struct pv_lock_ops pv_lock_ops __read_only = {
17576 #ifdef CONFIG_SMP
17577 .spin_is_locked = __ticket_spin_is_locked,
17578 .spin_is_contended = __ticket_spin_is_contended,
17579 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17580 index d90272e..6bb013b 100644
17581 --- a/arch/x86/kernel/paravirt.c
17582 +++ b/arch/x86/kernel/paravirt.c
17583 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17584 {
17585 return x;
17586 }
17587 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17588 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17589 +#endif
17590
17591 void __init default_banner(void)
17592 {
17593 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17594 if (opfunc == NULL)
17595 /* If there's no function, patch it with a ud2a (BUG) */
17596 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17597 - else if (opfunc == _paravirt_nop)
17598 + else if (opfunc == (void *)_paravirt_nop)
17599 /* If the operation is a nop, then nop the callsite */
17600 ret = paravirt_patch_nop();
17601
17602 /* identity functions just return their single argument */
17603 - else if (opfunc == _paravirt_ident_32)
17604 + else if (opfunc == (void *)_paravirt_ident_32)
17605 ret = paravirt_patch_ident_32(insnbuf, len);
17606 - else if (opfunc == _paravirt_ident_64)
17607 + else if (opfunc == (void *)_paravirt_ident_64)
17608 ret = paravirt_patch_ident_64(insnbuf, len);
17609 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17610 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17611 + ret = paravirt_patch_ident_64(insnbuf, len);
17612 +#endif
17613
17614 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17615 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17616 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17617 if (insn_len > len || start == NULL)
17618 insn_len = len;
17619 else
17620 - memcpy(insnbuf, start, insn_len);
17621 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17622
17623 return insn_len;
17624 }
17625 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17626 preempt_enable();
17627 }
17628
17629 -struct pv_info pv_info = {
17630 +struct pv_info pv_info __read_only = {
17631 .name = "bare hardware",
17632 .paravirt_enabled = 0,
17633 .kernel_rpl = 0,
17634 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17635 #endif
17636 };
17637
17638 -struct pv_init_ops pv_init_ops = {
17639 +struct pv_init_ops pv_init_ops __read_only = {
17640 .patch = native_patch,
17641 };
17642
17643 -struct pv_time_ops pv_time_ops = {
17644 +struct pv_time_ops pv_time_ops __read_only = {
17645 .sched_clock = native_sched_clock,
17646 .steal_clock = native_steal_clock,
17647 };
17648
17649 -struct pv_irq_ops pv_irq_ops = {
17650 +struct pv_irq_ops pv_irq_ops __read_only = {
17651 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17652 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17653 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17654 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17655 #endif
17656 };
17657
17658 -struct pv_cpu_ops pv_cpu_ops = {
17659 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17660 .cpuid = native_cpuid,
17661 .get_debugreg = native_get_debugreg,
17662 .set_debugreg = native_set_debugreg,
17663 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17664 .end_context_switch = paravirt_nop,
17665 };
17666
17667 -struct pv_apic_ops pv_apic_ops = {
17668 +struct pv_apic_ops pv_apic_ops __read_only = {
17669 #ifdef CONFIG_X86_LOCAL_APIC
17670 .startup_ipi_hook = paravirt_nop,
17671 #endif
17672 };
17673
17674 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17675 +#ifdef CONFIG_X86_32
17676 +#ifdef CONFIG_X86_PAE
17677 +/* 64-bit pagetable entries */
17678 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17679 +#else
17680 /* 32-bit pagetable entries */
17681 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17682 +#endif
17683 #else
17684 /* 64-bit pagetable entries */
17685 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17686 #endif
17687
17688 -struct pv_mmu_ops pv_mmu_ops = {
17689 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17690
17691 .read_cr2 = native_read_cr2,
17692 .write_cr2 = native_write_cr2,
17693 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17694 .make_pud = PTE_IDENT,
17695
17696 .set_pgd = native_set_pgd,
17697 + .set_pgd_batched = native_set_pgd_batched,
17698 #endif
17699 #endif /* PAGETABLE_LEVELS >= 3 */
17700
17701 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17702 },
17703
17704 .set_fixmap = native_set_fixmap,
17705 +
17706 +#ifdef CONFIG_PAX_KERNEXEC
17707 + .pax_open_kernel = native_pax_open_kernel,
17708 + .pax_close_kernel = native_pax_close_kernel,
17709 +#endif
17710 +
17711 };
17712
17713 EXPORT_SYMBOL_GPL(pv_time_ops);
17714 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
17715 index 35ccf75..7a15747 100644
17716 --- a/arch/x86/kernel/pci-iommu_table.c
17717 +++ b/arch/x86/kernel/pci-iommu_table.c
17718 @@ -2,7 +2,7 @@
17719 #include <asm/iommu_table.h>
17720 #include <linux/string.h>
17721 #include <linux/kallsyms.h>
17722 -
17723 +#include <linux/sched.h>
17724
17725 #define DEBUG 1
17726
17727 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
17728 index ee5d4fb..426649b 100644
17729 --- a/arch/x86/kernel/process.c
17730 +++ b/arch/x86/kernel/process.c
17731 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
17732
17733 void free_thread_info(struct thread_info *ti)
17734 {
17735 - free_thread_xstate(ti->task);
17736 free_pages((unsigned long)ti, THREAD_ORDER);
17737 }
17738
17739 +static struct kmem_cache *task_struct_cachep;
17740 +
17741 void arch_task_cache_init(void)
17742 {
17743 - task_xstate_cachep =
17744 - kmem_cache_create("task_xstate", xstate_size,
17745 + /* create a slab on which task_structs can be allocated */
17746 + task_struct_cachep =
17747 + kmem_cache_create("task_struct", sizeof(struct task_struct),
17748 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
17749 +
17750 + task_xstate_cachep =
17751 + kmem_cache_create("task_xstate", xstate_size,
17752 __alignof__(union thread_xstate),
17753 - SLAB_PANIC | SLAB_NOTRACK, NULL);
17754 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
17755 +}
17756 +
17757 +struct task_struct *alloc_task_struct_node(int node)
17758 +{
17759 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
17760 +}
17761 +
17762 +void free_task_struct(struct task_struct *task)
17763 +{
17764 + free_thread_xstate(task);
17765 + kmem_cache_free(task_struct_cachep, task);
17766 }
17767
17768 /*
17769 @@ -70,7 +87,7 @@ void exit_thread(void)
17770 unsigned long *bp = t->io_bitmap_ptr;
17771
17772 if (bp) {
17773 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
17774 + struct tss_struct *tss = init_tss + get_cpu();
17775
17776 t->io_bitmap_ptr = NULL;
17777 clear_thread_flag(TIF_IO_BITMAP);
17778 @@ -106,7 +123,7 @@ void show_regs_common(void)
17779
17780 printk(KERN_CONT "\n");
17781 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
17782 - current->pid, current->comm, print_tainted(),
17783 + task_pid_nr(current), current->comm, print_tainted(),
17784 init_utsname()->release,
17785 (int)strcspn(init_utsname()->version, " "),
17786 init_utsname()->version);
17787 @@ -120,6 +137,9 @@ void flush_thread(void)
17788 {
17789 struct task_struct *tsk = current;
17790
17791 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17792 + loadsegment(gs, 0);
17793 +#endif
17794 flush_ptrace_hw_breakpoint(tsk);
17795 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
17796 /*
17797 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
17798 regs.di = (unsigned long) arg;
17799
17800 #ifdef CONFIG_X86_32
17801 - regs.ds = __USER_DS;
17802 - regs.es = __USER_DS;
17803 + regs.ds = __KERNEL_DS;
17804 + regs.es = __KERNEL_DS;
17805 regs.fs = __KERNEL_PERCPU;
17806 - regs.gs = __KERNEL_STACK_CANARY;
17807 + savesegment(gs, regs.gs);
17808 #else
17809 regs.ss = __KERNEL_DS;
17810 #endif
17811 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
17812
17813 return ret;
17814 }
17815 -void stop_this_cpu(void *dummy)
17816 +__noreturn void stop_this_cpu(void *dummy)
17817 {
17818 local_irq_disable();
17819 /*
17820 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
17821 }
17822 early_param("idle", idle_setup);
17823
17824 -unsigned long arch_align_stack(unsigned long sp)
17825 +#ifdef CONFIG_PAX_RANDKSTACK
17826 +void pax_randomize_kstack(struct pt_regs *regs)
17827 {
17828 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
17829 - sp -= get_random_int() % 8192;
17830 - return sp & ~0xf;
17831 -}
17832 + struct thread_struct *thread = &current->thread;
17833 + unsigned long time;
17834
17835 -unsigned long arch_randomize_brk(struct mm_struct *mm)
17836 -{
17837 - unsigned long range_end = mm->brk + 0x02000000;
17838 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
17839 -}
17840 + if (!randomize_va_space)
17841 + return;
17842 +
17843 + if (v8086_mode(regs))
17844 + return;
17845
17846 + rdtscl(time);
17847 +
17848 + /* P4 seems to return a 0 LSB, ignore it */
17849 +#ifdef CONFIG_MPENTIUM4
17850 + time &= 0x3EUL;
17851 + time <<= 2;
17852 +#elif defined(CONFIG_X86_64)
17853 + time &= 0xFUL;
17854 + time <<= 4;
17855 +#else
17856 + time &= 0x1FUL;
17857 + time <<= 3;
17858 +#endif
17859 +
17860 + thread->sp0 ^= time;
17861 + load_sp0(init_tss + smp_processor_id(), thread);
17862 +
17863 +#ifdef CONFIG_X86_64
17864 + percpu_write(kernel_stack, thread->sp0);
17865 +#endif
17866 +}
17867 +#endif
17868 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
17869 index 8598296..bfadef0 100644
17870 --- a/arch/x86/kernel/process_32.c
17871 +++ b/arch/x86/kernel/process_32.c
17872 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
17873 unsigned long thread_saved_pc(struct task_struct *tsk)
17874 {
17875 return ((unsigned long *)tsk->thread.sp)[3];
17876 +//XXX return tsk->thread.eip;
17877 }
17878
17879 #ifndef CONFIG_SMP
17880 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, int all)
17881 unsigned long sp;
17882 unsigned short ss, gs;
17883
17884 - if (user_mode_vm(regs)) {
17885 + if (user_mode(regs)) {
17886 sp = regs->sp;
17887 ss = regs->ss & 0xffff;
17888 - gs = get_user_gs(regs);
17889 } else {
17890 sp = kernel_stack_pointer(regs);
17891 savesegment(ss, ss);
17892 - savesegment(gs, gs);
17893 }
17894 + gs = get_user_gs(regs);
17895
17896 show_regs_common();
17897
17898 @@ -200,13 +200,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17899 struct task_struct *tsk;
17900 int err;
17901
17902 - childregs = task_pt_regs(p);
17903 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
17904 *childregs = *regs;
17905 childregs->ax = 0;
17906 childregs->sp = sp;
17907
17908 p->thread.sp = (unsigned long) childregs;
17909 p->thread.sp0 = (unsigned long) (childregs+1);
17910 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17911
17912 p->thread.ip = (unsigned long) ret_from_fork;
17913
17914 @@ -296,7 +297,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17915 struct thread_struct *prev = &prev_p->thread,
17916 *next = &next_p->thread;
17917 int cpu = smp_processor_id();
17918 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17919 + struct tss_struct *tss = init_tss + cpu;
17920 fpu_switch_t fpu;
17921
17922 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
17923 @@ -320,6 +321,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17924 */
17925 lazy_save_gs(prev->gs);
17926
17927 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17928 + __set_fs(task_thread_info(next_p)->addr_limit);
17929 +#endif
17930 +
17931 /*
17932 * Load the per-thread Thread-Local Storage descriptor.
17933 */
17934 @@ -350,6 +355,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17935 */
17936 arch_end_context_switch(next_p);
17937
17938 + percpu_write(current_task, next_p);
17939 + percpu_write(current_tinfo, &next_p->tinfo);
17940 +
17941 /*
17942 * Restore %gs if needed (which is common)
17943 */
17944 @@ -358,8 +366,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17945
17946 switch_fpu_finish(next_p, fpu);
17947
17948 - percpu_write(current_task, next_p);
17949 -
17950 return prev_p;
17951 }
17952
17953 @@ -389,4 +395,3 @@ unsigned long get_wchan(struct task_struct *p)
17954 } while (count++ < 16);
17955 return 0;
17956 }
17957 -
17958 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
17959 index 6a364a6..b147d11 100644
17960 --- a/arch/x86/kernel/process_64.c
17961 +++ b/arch/x86/kernel/process_64.c
17962 @@ -89,7 +89,7 @@ static void __exit_idle(void)
17963 void exit_idle(void)
17964 {
17965 /* idle loop has pid 0 */
17966 - if (current->pid)
17967 + if (task_pid_nr(current))
17968 return;
17969 __exit_idle();
17970 }
17971 @@ -264,8 +264,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17972 struct pt_regs *childregs;
17973 struct task_struct *me = current;
17974
17975 - childregs = ((struct pt_regs *)
17976 - (THREAD_SIZE + task_stack_page(p))) - 1;
17977 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
17978 *childregs = *regs;
17979
17980 childregs->ax = 0;
17981 @@ -277,6 +276,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17982 p->thread.sp = (unsigned long) childregs;
17983 p->thread.sp0 = (unsigned long) (childregs+1);
17984 p->thread.usersp = me->thread.usersp;
17985 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17986
17987 set_tsk_thread_flag(p, TIF_FORK);
17988
17989 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17990 struct thread_struct *prev = &prev_p->thread;
17991 struct thread_struct *next = &next_p->thread;
17992 int cpu = smp_processor_id();
17993 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17994 + struct tss_struct *tss = init_tss + cpu;
17995 unsigned fsindex, gsindex;
17996 fpu_switch_t fpu;
17997
17998 @@ -461,10 +461,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17999 prev->usersp = percpu_read(old_rsp);
18000 percpu_write(old_rsp, next->usersp);
18001 percpu_write(current_task, next_p);
18002 + percpu_write(current_tinfo, &next_p->tinfo);
18003
18004 - percpu_write(kernel_stack,
18005 - (unsigned long)task_stack_page(next_p) +
18006 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18007 + percpu_write(kernel_stack, next->sp0);
18008
18009 /*
18010 * Now maybe reload the debug registers and handle I/O bitmaps
18011 @@ -519,12 +518,11 @@ unsigned long get_wchan(struct task_struct *p)
18012 if (!p || p == current || p->state == TASK_RUNNING)
18013 return 0;
18014 stack = (unsigned long)task_stack_page(p);
18015 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18016 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18017 return 0;
18018 fp = *(u64 *)(p->thread.sp);
18019 do {
18020 - if (fp < (unsigned long)stack ||
18021 - fp >= (unsigned long)stack+THREAD_SIZE)
18022 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18023 return 0;
18024 ip = *(u64 *)(fp+8);
18025 if (!in_sched_functions(ip))
18026 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18027 index 8252879..d3219e0 100644
18028 --- a/arch/x86/kernel/ptrace.c
18029 +++ b/arch/x86/kernel/ptrace.c
18030 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
18031 unsigned long addr, unsigned long data)
18032 {
18033 int ret;
18034 - unsigned long __user *datap = (unsigned long __user *)data;
18035 + unsigned long __user *datap = (__force unsigned long __user *)data;
18036
18037 switch (request) {
18038 /* read the word at location addr in the USER area. */
18039 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
18040 if ((int) addr < 0)
18041 return -EIO;
18042 ret = do_get_thread_area(child, addr,
18043 - (struct user_desc __user *)data);
18044 + (__force struct user_desc __user *) data);
18045 break;
18046
18047 case PTRACE_SET_THREAD_AREA:
18048 if ((int) addr < 0)
18049 return -EIO;
18050 ret = do_set_thread_area(child, addr,
18051 - (struct user_desc __user *)data, 0);
18052 + (__force struct user_desc __user *) data, 0);
18053 break;
18054 #endif
18055
18056 @@ -1331,7 +1331,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18057 memset(info, 0, sizeof(*info));
18058 info->si_signo = SIGTRAP;
18059 info->si_code = si_code;
18060 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18061 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18062 }
18063
18064 void user_single_step_siginfo(struct task_struct *tsk,
18065 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18066 index 42eb330..139955c 100644
18067 --- a/arch/x86/kernel/pvclock.c
18068 +++ b/arch/x86/kernel/pvclock.c
18069 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18070 return pv_tsc_khz;
18071 }
18072
18073 -static atomic64_t last_value = ATOMIC64_INIT(0);
18074 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18075
18076 void pvclock_resume(void)
18077 {
18078 - atomic64_set(&last_value, 0);
18079 + atomic64_set_unchecked(&last_value, 0);
18080 }
18081
18082 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18083 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18084 * updating at the same time, and one of them could be slightly behind,
18085 * making the assumption that last_value always go forward fail to hold.
18086 */
18087 - last = atomic64_read(&last_value);
18088 + last = atomic64_read_unchecked(&last_value);
18089 do {
18090 if (ret < last)
18091 return last;
18092 - last = atomic64_cmpxchg(&last_value, last, ret);
18093 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18094 } while (unlikely(last != ret));
18095
18096 return ret;
18097 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18098 index 37a458b..e63d183 100644
18099 --- a/arch/x86/kernel/reboot.c
18100 +++ b/arch/x86/kernel/reboot.c
18101 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18102 EXPORT_SYMBOL(pm_power_off);
18103
18104 static const struct desc_ptr no_idt = {};
18105 -static int reboot_mode;
18106 +static unsigned short reboot_mode;
18107 enum reboot_type reboot_type = BOOT_ACPI;
18108 int reboot_force;
18109
18110 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
18111 extern const unsigned char machine_real_restart_asm[];
18112 extern const u64 machine_real_restart_gdt[3];
18113
18114 -void machine_real_restart(unsigned int type)
18115 +__noreturn void machine_real_restart(unsigned int type)
18116 {
18117 void *restart_va;
18118 unsigned long restart_pa;
18119 - void (*restart_lowmem)(unsigned int);
18120 + void (* __noreturn restart_lowmem)(unsigned int);
18121 u64 *lowmem_gdt;
18122
18123 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18124 + struct desc_struct *gdt;
18125 +#endif
18126 +
18127 local_irq_disable();
18128
18129 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18130 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
18131 boot)". This seems like a fairly standard thing that gets set by
18132 REBOOT.COM programs, and the previous reset routine did this
18133 too. */
18134 - *((unsigned short *)0x472) = reboot_mode;
18135 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18136
18137 /* Patch the GDT in the low memory trampoline */
18138 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18139
18140 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18141 restart_pa = virt_to_phys(restart_va);
18142 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18143 + restart_lowmem = (void *)restart_pa;
18144
18145 /* GDT[0]: GDT self-pointer */
18146 lowmem_gdt[0] =
18147 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
18148 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18149
18150 /* Jump to the identity-mapped low memory code */
18151 +
18152 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18153 + gdt = get_cpu_gdt_table(smp_processor_id());
18154 + pax_open_kernel();
18155 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18156 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18157 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18158 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18159 +#endif
18160 +#ifdef CONFIG_PAX_KERNEXEC
18161 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18162 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18163 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18164 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18165 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18166 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18167 +#endif
18168 + pax_close_kernel();
18169 +#endif
18170 +
18171 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18172 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18173 + unreachable();
18174 +#else
18175 restart_lowmem(type);
18176 +#endif
18177 +
18178 }
18179 #ifdef CONFIG_APM_MODULE
18180 EXPORT_SYMBOL(machine_real_restart);
18181 @@ -540,7 +570,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18182 * try to force a triple fault and then cycle between hitting the keyboard
18183 * controller and doing that
18184 */
18185 -static void native_machine_emergency_restart(void)
18186 +__noreturn static void native_machine_emergency_restart(void)
18187 {
18188 int i;
18189 int attempt = 0;
18190 @@ -664,13 +694,13 @@ void native_machine_shutdown(void)
18191 #endif
18192 }
18193
18194 -static void __machine_emergency_restart(int emergency)
18195 +static __noreturn void __machine_emergency_restart(int emergency)
18196 {
18197 reboot_emergency = emergency;
18198 machine_ops.emergency_restart();
18199 }
18200
18201 -static void native_machine_restart(char *__unused)
18202 +static __noreturn void native_machine_restart(char *__unused)
18203 {
18204 printk("machine restart\n");
18205
18206 @@ -679,7 +709,7 @@ static void native_machine_restart(char *__unused)
18207 __machine_emergency_restart(0);
18208 }
18209
18210 -static void native_machine_halt(void)
18211 +static __noreturn void native_machine_halt(void)
18212 {
18213 /* stop other cpus and apics */
18214 machine_shutdown();
18215 @@ -690,7 +720,7 @@ static void native_machine_halt(void)
18216 stop_this_cpu(NULL);
18217 }
18218
18219 -static void native_machine_power_off(void)
18220 +__noreturn static void native_machine_power_off(void)
18221 {
18222 if (pm_power_off) {
18223 if (!reboot_force)
18224 @@ -699,6 +729,7 @@ static void native_machine_power_off(void)
18225 }
18226 /* a fallback in case there is no PM info available */
18227 tboot_shutdown(TB_SHUTDOWN_HALT);
18228 + unreachable();
18229 }
18230
18231 struct machine_ops machine_ops = {
18232 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18233 index 7a6f3b3..bed145d7 100644
18234 --- a/arch/x86/kernel/relocate_kernel_64.S
18235 +++ b/arch/x86/kernel/relocate_kernel_64.S
18236 @@ -11,6 +11,7 @@
18237 #include <asm/kexec.h>
18238 #include <asm/processor-flags.h>
18239 #include <asm/pgtable_types.h>
18240 +#include <asm/alternative-asm.h>
18241
18242 /*
18243 * Must be relocatable PIC code callable as a C function
18244 @@ -160,13 +161,14 @@ identity_mapped:
18245 xorq %rbp, %rbp
18246 xorq %r8, %r8
18247 xorq %r9, %r9
18248 - xorq %r10, %r9
18249 + xorq %r10, %r10
18250 xorq %r11, %r11
18251 xorq %r12, %r12
18252 xorq %r13, %r13
18253 xorq %r14, %r14
18254 xorq %r15, %r15
18255
18256 + pax_force_retaddr 0, 1
18257 ret
18258
18259 1:
18260 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18261 index cf0ef98..e3f780b 100644
18262 --- a/arch/x86/kernel/setup.c
18263 +++ b/arch/x86/kernel/setup.c
18264 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
18265
18266 switch (data->type) {
18267 case SETUP_E820_EXT:
18268 - parse_e820_ext(data);
18269 + parse_e820_ext((struct setup_data __force_kernel *)data);
18270 break;
18271 case SETUP_DTB:
18272 add_dtb(pa_data);
18273 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
18274 * area (640->1Mb) as ram even though it is not.
18275 * take them out.
18276 */
18277 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18278 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18279 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18280 }
18281
18282 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
18283
18284 if (!boot_params.hdr.root_flags)
18285 root_mountflags &= ~MS_RDONLY;
18286 - init_mm.start_code = (unsigned long) _text;
18287 - init_mm.end_code = (unsigned long) _etext;
18288 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18289 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18290 init_mm.end_data = (unsigned long) _edata;
18291 init_mm.brk = _brk_end;
18292
18293 - code_resource.start = virt_to_phys(_text);
18294 - code_resource.end = virt_to_phys(_etext)-1;
18295 - data_resource.start = virt_to_phys(_etext);
18296 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18297 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18298 + data_resource.start = virt_to_phys(_sdata);
18299 data_resource.end = virt_to_phys(_edata)-1;
18300 bss_resource.start = virt_to_phys(&__bss_start);
18301 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18302 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18303 index 71f4727..16dc9f7 100644
18304 --- a/arch/x86/kernel/setup_percpu.c
18305 +++ b/arch/x86/kernel/setup_percpu.c
18306 @@ -21,19 +21,17 @@
18307 #include <asm/cpu.h>
18308 #include <asm/stackprotector.h>
18309
18310 -DEFINE_PER_CPU(int, cpu_number);
18311 +#ifdef CONFIG_SMP
18312 +DEFINE_PER_CPU(unsigned int, cpu_number);
18313 EXPORT_PER_CPU_SYMBOL(cpu_number);
18314 +#endif
18315
18316 -#ifdef CONFIG_X86_64
18317 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18318 -#else
18319 -#define BOOT_PERCPU_OFFSET 0
18320 -#endif
18321
18322 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18323 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18324
18325 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18326 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18327 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18328 };
18329 EXPORT_SYMBOL(__per_cpu_offset);
18330 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18331 {
18332 #ifdef CONFIG_X86_32
18333 struct desc_struct gdt;
18334 + unsigned long base = per_cpu_offset(cpu);
18335
18336 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18337 - 0x2 | DESCTYPE_S, 0x8);
18338 - gdt.s = 1;
18339 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18340 + 0x83 | DESCTYPE_S, 0xC);
18341 write_gdt_entry(get_cpu_gdt_table(cpu),
18342 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18343 #endif
18344 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
18345 /* alrighty, percpu areas up and running */
18346 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18347 for_each_possible_cpu(cpu) {
18348 +#ifdef CONFIG_CC_STACKPROTECTOR
18349 +#ifdef CONFIG_X86_32
18350 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18351 +#endif
18352 +#endif
18353 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18354 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18355 per_cpu(cpu_number, cpu) = cpu;
18356 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
18357 */
18358 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18359 #endif
18360 +#ifdef CONFIG_CC_STACKPROTECTOR
18361 +#ifdef CONFIG_X86_32
18362 + if (!cpu)
18363 + per_cpu(stack_canary.canary, cpu) = canary;
18364 +#endif
18365 +#endif
18366 /*
18367 * Up to this point, the boot CPU has been using .init.data
18368 * area. Reload any changed state for the boot CPU.
18369 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18370 index 54ddaeb2..22c3bdc 100644
18371 --- a/arch/x86/kernel/signal.c
18372 +++ b/arch/x86/kernel/signal.c
18373 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18374 * Align the stack pointer according to the i386 ABI,
18375 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18376 */
18377 - sp = ((sp + 4) & -16ul) - 4;
18378 + sp = ((sp - 12) & -16ul) - 4;
18379 #else /* !CONFIG_X86_32 */
18380 sp = round_down(sp, 16) - 8;
18381 #endif
18382 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18383 * Return an always-bogus address instead so we will die with SIGSEGV.
18384 */
18385 if (onsigstack && !likely(on_sig_stack(sp)))
18386 - return (void __user *)-1L;
18387 + return (__force void __user *)-1L;
18388
18389 /* save i387 state */
18390 if (used_math() && save_i387_xstate(*fpstate) < 0)
18391 - return (void __user *)-1L;
18392 + return (__force void __user *)-1L;
18393
18394 return (void __user *)sp;
18395 }
18396 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18397 }
18398
18399 if (current->mm->context.vdso)
18400 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18401 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18402 else
18403 - restorer = &frame->retcode;
18404 + restorer = (void __user *)&frame->retcode;
18405 if (ka->sa.sa_flags & SA_RESTORER)
18406 restorer = ka->sa.sa_restorer;
18407
18408 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18409 * reasons and because gdb uses it as a signature to notice
18410 * signal handler stack frames.
18411 */
18412 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18413 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18414
18415 if (err)
18416 return -EFAULT;
18417 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18418 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18419
18420 /* Set up to return from userspace. */
18421 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18422 + if (current->mm->context.vdso)
18423 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18424 + else
18425 + restorer = (void __user *)&frame->retcode;
18426 if (ka->sa.sa_flags & SA_RESTORER)
18427 restorer = ka->sa.sa_restorer;
18428 put_user_ex(restorer, &frame->pretcode);
18429 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18430 * reasons and because gdb uses it as a signature to notice
18431 * signal handler stack frames.
18432 */
18433 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18434 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18435 } put_user_catch(err);
18436
18437 if (err)
18438 @@ -769,7 +772,7 @@ static void do_signal(struct pt_regs *regs)
18439 * X86_32: vm86 regs switched out by assembly code before reaching
18440 * here, so testing against kernel CS suffices.
18441 */
18442 - if (!user_mode(regs))
18443 + if (!user_mode_novm(regs))
18444 return;
18445
18446 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18447 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18448 index 9f548cb..caf76f7 100644
18449 --- a/arch/x86/kernel/smpboot.c
18450 +++ b/arch/x86/kernel/smpboot.c
18451 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18452 set_idle_for_cpu(cpu, c_idle.idle);
18453 do_rest:
18454 per_cpu(current_task, cpu) = c_idle.idle;
18455 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18456 #ifdef CONFIG_X86_32
18457 /* Stack for startup_32 can be just as for start_secondary onwards */
18458 irq_ctx_init(cpu);
18459 #else
18460 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18461 initial_gs = per_cpu_offset(cpu);
18462 - per_cpu(kernel_stack, cpu) =
18463 - (unsigned long)task_stack_page(c_idle.idle) -
18464 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18465 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18466 #endif
18467 +
18468 + pax_open_kernel();
18469 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18470 + pax_close_kernel();
18471 +
18472 initial_code = (unsigned long)start_secondary;
18473 stack_start = c_idle.idle->thread.sp;
18474
18475 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18476
18477 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18478
18479 +#ifdef CONFIG_PAX_PER_CPU_PGD
18480 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18481 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18482 + KERNEL_PGD_PTRS);
18483 +#endif
18484 +
18485 err = do_boot_cpu(apicid, cpu);
18486 if (err) {
18487 pr_debug("do_boot_cpu failed %d\n", err);
18488 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18489 index c346d11..d43b163 100644
18490 --- a/arch/x86/kernel/step.c
18491 +++ b/arch/x86/kernel/step.c
18492 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18493 struct desc_struct *desc;
18494 unsigned long base;
18495
18496 - seg &= ~7UL;
18497 + seg >>= 3;
18498
18499 mutex_lock(&child->mm->context.lock);
18500 - if (unlikely((seg >> 3) >= child->mm->context.size))
18501 + if (unlikely(seg >= child->mm->context.size))
18502 addr = -1L; /* bogus selector, access would fault */
18503 else {
18504 desc = child->mm->context.ldt + seg;
18505 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18506 addr += base;
18507 }
18508 mutex_unlock(&child->mm->context.lock);
18509 - }
18510 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18511 + addr = ktla_ktva(addr);
18512
18513 return addr;
18514 }
18515 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18516 unsigned char opcode[15];
18517 unsigned long addr = convert_ip_to_linear(child, regs);
18518
18519 + if (addr == -EINVAL)
18520 + return 0;
18521 +
18522 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18523 for (i = 0; i < copied; i++) {
18524 switch (opcode[i]) {
18525 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18526 index 0b0cb5f..db6b9ed 100644
18527 --- a/arch/x86/kernel/sys_i386_32.c
18528 +++ b/arch/x86/kernel/sys_i386_32.c
18529 @@ -24,17 +24,224 @@
18530
18531 #include <asm/syscalls.h>
18532
18533 -/*
18534 - * Do a system call from kernel instead of calling sys_execve so we
18535 - * end up with proper pt_regs.
18536 - */
18537 -int kernel_execve(const char *filename,
18538 - const char *const argv[],
18539 - const char *const envp[])
18540 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18541 {
18542 - long __res;
18543 - asm volatile ("int $0x80"
18544 - : "=a" (__res)
18545 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18546 - return __res;
18547 + unsigned long pax_task_size = TASK_SIZE;
18548 +
18549 +#ifdef CONFIG_PAX_SEGMEXEC
18550 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18551 + pax_task_size = SEGMEXEC_TASK_SIZE;
18552 +#endif
18553 +
18554 + if (len > pax_task_size || addr > pax_task_size - len)
18555 + return -EINVAL;
18556 +
18557 + return 0;
18558 +}
18559 +
18560 +unsigned long
18561 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18562 + unsigned long len, unsigned long pgoff, unsigned long flags)
18563 +{
18564 + struct mm_struct *mm = current->mm;
18565 + struct vm_area_struct *vma;
18566 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18567 +
18568 +#ifdef CONFIG_PAX_SEGMEXEC
18569 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18570 + pax_task_size = SEGMEXEC_TASK_SIZE;
18571 +#endif
18572 +
18573 + pax_task_size -= PAGE_SIZE;
18574 +
18575 + if (len > pax_task_size)
18576 + return -ENOMEM;
18577 +
18578 + if (flags & MAP_FIXED)
18579 + return addr;
18580 +
18581 +#ifdef CONFIG_PAX_RANDMMAP
18582 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18583 +#endif
18584 +
18585 + if (addr) {
18586 + addr = PAGE_ALIGN(addr);
18587 + if (pax_task_size - len >= addr) {
18588 + vma = find_vma(mm, addr);
18589 + if (check_heap_stack_gap(vma, addr, len))
18590 + return addr;
18591 + }
18592 + }
18593 + if (len > mm->cached_hole_size) {
18594 + start_addr = addr = mm->free_area_cache;
18595 + } else {
18596 + start_addr = addr = mm->mmap_base;
18597 + mm->cached_hole_size = 0;
18598 + }
18599 +
18600 +#ifdef CONFIG_PAX_PAGEEXEC
18601 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18602 + start_addr = 0x00110000UL;
18603 +
18604 +#ifdef CONFIG_PAX_RANDMMAP
18605 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18606 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18607 +#endif
18608 +
18609 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18610 + start_addr = addr = mm->mmap_base;
18611 + else
18612 + addr = start_addr;
18613 + }
18614 +#endif
18615 +
18616 +full_search:
18617 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18618 + /* At this point: (!vma || addr < vma->vm_end). */
18619 + if (pax_task_size - len < addr) {
18620 + /*
18621 + * Start a new search - just in case we missed
18622 + * some holes.
18623 + */
18624 + if (start_addr != mm->mmap_base) {
18625 + start_addr = addr = mm->mmap_base;
18626 + mm->cached_hole_size = 0;
18627 + goto full_search;
18628 + }
18629 + return -ENOMEM;
18630 + }
18631 + if (check_heap_stack_gap(vma, addr, len))
18632 + break;
18633 + if (addr + mm->cached_hole_size < vma->vm_start)
18634 + mm->cached_hole_size = vma->vm_start - addr;
18635 + addr = vma->vm_end;
18636 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18637 + start_addr = addr = mm->mmap_base;
18638 + mm->cached_hole_size = 0;
18639 + goto full_search;
18640 + }
18641 + }
18642 +
18643 + /*
18644 + * Remember the place where we stopped the search:
18645 + */
18646 + mm->free_area_cache = addr + len;
18647 + return addr;
18648 +}
18649 +
18650 +unsigned long
18651 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18652 + const unsigned long len, const unsigned long pgoff,
18653 + const unsigned long flags)
18654 +{
18655 + struct vm_area_struct *vma;
18656 + struct mm_struct *mm = current->mm;
18657 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18658 +
18659 +#ifdef CONFIG_PAX_SEGMEXEC
18660 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18661 + pax_task_size = SEGMEXEC_TASK_SIZE;
18662 +#endif
18663 +
18664 + pax_task_size -= PAGE_SIZE;
18665 +
18666 + /* requested length too big for entire address space */
18667 + if (len > pax_task_size)
18668 + return -ENOMEM;
18669 +
18670 + if (flags & MAP_FIXED)
18671 + return addr;
18672 +
18673 +#ifdef CONFIG_PAX_PAGEEXEC
18674 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18675 + goto bottomup;
18676 +#endif
18677 +
18678 +#ifdef CONFIG_PAX_RANDMMAP
18679 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18680 +#endif
18681 +
18682 + /* requesting a specific address */
18683 + if (addr) {
18684 + addr = PAGE_ALIGN(addr);
18685 + if (pax_task_size - len >= addr) {
18686 + vma = find_vma(mm, addr);
18687 + if (check_heap_stack_gap(vma, addr, len))
18688 + return addr;
18689 + }
18690 + }
18691 +
18692 + /* check if free_area_cache is useful for us */
18693 + if (len <= mm->cached_hole_size) {
18694 + mm->cached_hole_size = 0;
18695 + mm->free_area_cache = mm->mmap_base;
18696 + }
18697 +
18698 + /* either no address requested or can't fit in requested address hole */
18699 + addr = mm->free_area_cache;
18700 +
18701 + /* make sure it can fit in the remaining address space */
18702 + if (addr > len) {
18703 + vma = find_vma(mm, addr-len);
18704 + if (check_heap_stack_gap(vma, addr - len, len))
18705 + /* remember the address as a hint for next time */
18706 + return (mm->free_area_cache = addr-len);
18707 + }
18708 +
18709 + if (mm->mmap_base < len)
18710 + goto bottomup;
18711 +
18712 + addr = mm->mmap_base-len;
18713 +
18714 + do {
18715 + /*
18716 + * Lookup failure means no vma is above this address,
18717 + * else if new region fits below vma->vm_start,
18718 + * return with success:
18719 + */
18720 + vma = find_vma(mm, addr);
18721 + if (check_heap_stack_gap(vma, addr, len))
18722 + /* remember the address as a hint for next time */
18723 + return (mm->free_area_cache = addr);
18724 +
18725 + /* remember the largest hole we saw so far */
18726 + if (addr + mm->cached_hole_size < vma->vm_start)
18727 + mm->cached_hole_size = vma->vm_start - addr;
18728 +
18729 + /* try just below the current vma->vm_start */
18730 + addr = skip_heap_stack_gap(vma, len);
18731 + } while (!IS_ERR_VALUE(addr));
18732 +
18733 +bottomup:
18734 + /*
18735 + * A failed mmap() very likely causes application failure,
18736 + * so fall back to the bottom-up function here. This scenario
18737 + * can happen with large stack limits and large mmap()
18738 + * allocations.
18739 + */
18740 +
18741 +#ifdef CONFIG_PAX_SEGMEXEC
18742 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18743 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
18744 + else
18745 +#endif
18746 +
18747 + mm->mmap_base = TASK_UNMAPPED_BASE;
18748 +
18749 +#ifdef CONFIG_PAX_RANDMMAP
18750 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18751 + mm->mmap_base += mm->delta_mmap;
18752 +#endif
18753 +
18754 + mm->free_area_cache = mm->mmap_base;
18755 + mm->cached_hole_size = ~0UL;
18756 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18757 + /*
18758 + * Restore the topdown base:
18759 + */
18760 + mm->mmap_base = base;
18761 + mm->free_area_cache = base;
18762 + mm->cached_hole_size = ~0UL;
18763 +
18764 + return addr;
18765 }
18766 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
18767 index 0514890..3dbebce 100644
18768 --- a/arch/x86/kernel/sys_x86_64.c
18769 +++ b/arch/x86/kernel/sys_x86_64.c
18770 @@ -95,8 +95,8 @@ out:
18771 return error;
18772 }
18773
18774 -static void find_start_end(unsigned long flags, unsigned long *begin,
18775 - unsigned long *end)
18776 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
18777 + unsigned long *begin, unsigned long *end)
18778 {
18779 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
18780 unsigned long new_begin;
18781 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
18782 *begin = new_begin;
18783 }
18784 } else {
18785 - *begin = TASK_UNMAPPED_BASE;
18786 + *begin = mm->mmap_base;
18787 *end = TASK_SIZE;
18788 }
18789 }
18790 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
18791 if (flags & MAP_FIXED)
18792 return addr;
18793
18794 - find_start_end(flags, &begin, &end);
18795 + find_start_end(mm, flags, &begin, &end);
18796
18797 if (len > end)
18798 return -ENOMEM;
18799
18800 +#ifdef CONFIG_PAX_RANDMMAP
18801 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18802 +#endif
18803 +
18804 if (addr) {
18805 addr = PAGE_ALIGN(addr);
18806 vma = find_vma(mm, addr);
18807 - if (end - len >= addr &&
18808 - (!vma || addr + len <= vma->vm_start))
18809 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
18810 return addr;
18811 }
18812 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
18813 @@ -172,7 +175,7 @@ full_search:
18814 }
18815 return -ENOMEM;
18816 }
18817 - if (!vma || addr + len <= vma->vm_start) {
18818 + if (check_heap_stack_gap(vma, addr, len)) {
18819 /*
18820 * Remember the place where we stopped the search:
18821 */
18822 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18823 {
18824 struct vm_area_struct *vma;
18825 struct mm_struct *mm = current->mm;
18826 - unsigned long addr = addr0;
18827 + unsigned long base = mm->mmap_base, addr = addr0;
18828
18829 /* requested length too big for entire address space */
18830 if (len > TASK_SIZE)
18831 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18832 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
18833 goto bottomup;
18834
18835 +#ifdef CONFIG_PAX_RANDMMAP
18836 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18837 +#endif
18838 +
18839 /* requesting a specific address */
18840 if (addr) {
18841 addr = PAGE_ALIGN(addr);
18842 - vma = find_vma(mm, addr);
18843 - if (TASK_SIZE - len >= addr &&
18844 - (!vma || addr + len <= vma->vm_start))
18845 - return addr;
18846 + if (TASK_SIZE - len >= addr) {
18847 + vma = find_vma(mm, addr);
18848 + if (check_heap_stack_gap(vma, addr, len))
18849 + return addr;
18850 + }
18851 }
18852
18853 /* check if free_area_cache is useful for us */
18854 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18855 ALIGN_TOPDOWN);
18856
18857 vma = find_vma(mm, tmp_addr);
18858 - if (!vma || tmp_addr + len <= vma->vm_start)
18859 + if (check_heap_stack_gap(vma, tmp_addr, len))
18860 /* remember the address as a hint for next time */
18861 return mm->free_area_cache = tmp_addr;
18862 }
18863 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18864 * return with success:
18865 */
18866 vma = find_vma(mm, addr);
18867 - if (!vma || addr+len <= vma->vm_start)
18868 + if (check_heap_stack_gap(vma, addr, len))
18869 /* remember the address as a hint for next time */
18870 return mm->free_area_cache = addr;
18871
18872 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18873 mm->cached_hole_size = vma->vm_start - addr;
18874
18875 /* try just below the current vma->vm_start */
18876 - addr = vma->vm_start-len;
18877 - } while (len < vma->vm_start);
18878 + addr = skip_heap_stack_gap(vma, len);
18879 + } while (!IS_ERR_VALUE(addr));
18880
18881 bottomup:
18882 /*
18883 @@ -270,13 +278,21 @@ bottomup:
18884 * can happen with large stack limits and large mmap()
18885 * allocations.
18886 */
18887 + mm->mmap_base = TASK_UNMAPPED_BASE;
18888 +
18889 +#ifdef CONFIG_PAX_RANDMMAP
18890 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18891 + mm->mmap_base += mm->delta_mmap;
18892 +#endif
18893 +
18894 + mm->free_area_cache = mm->mmap_base;
18895 mm->cached_hole_size = ~0UL;
18896 - mm->free_area_cache = TASK_UNMAPPED_BASE;
18897 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18898 /*
18899 * Restore the topdown base:
18900 */
18901 - mm->free_area_cache = mm->mmap_base;
18902 + mm->mmap_base = base;
18903 + mm->free_area_cache = base;
18904 mm->cached_hole_size = ~0UL;
18905
18906 return addr;
18907 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
18908 index 9a0e312..e6f66f2 100644
18909 --- a/arch/x86/kernel/syscall_table_32.S
18910 +++ b/arch/x86/kernel/syscall_table_32.S
18911 @@ -1,3 +1,4 @@
18912 +.section .rodata,"a",@progbits
18913 ENTRY(sys_call_table)
18914 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
18915 .long sys_exit
18916 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
18917 index e2410e2..4fe3fbc 100644
18918 --- a/arch/x86/kernel/tboot.c
18919 +++ b/arch/x86/kernel/tboot.c
18920 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
18921
18922 void tboot_shutdown(u32 shutdown_type)
18923 {
18924 - void (*shutdown)(void);
18925 + void (* __noreturn shutdown)(void);
18926
18927 if (!tboot_enabled())
18928 return;
18929 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
18930
18931 switch_to_tboot_pt();
18932
18933 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
18934 + shutdown = (void *)tboot->shutdown_entry;
18935 shutdown();
18936
18937 /* should not reach here */
18938 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
18939 tboot_shutdown(acpi_shutdown_map[sleep_state]);
18940 }
18941
18942 -static atomic_t ap_wfs_count;
18943 +static atomic_unchecked_t ap_wfs_count;
18944
18945 static int tboot_wait_for_aps(int num_aps)
18946 {
18947 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
18948 {
18949 switch (action) {
18950 case CPU_DYING:
18951 - atomic_inc(&ap_wfs_count);
18952 + atomic_inc_unchecked(&ap_wfs_count);
18953 if (num_online_cpus() == 1)
18954 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
18955 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
18956 return NOTIFY_BAD;
18957 break;
18958 }
18959 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
18960
18961 tboot_create_trampoline();
18962
18963 - atomic_set(&ap_wfs_count, 0);
18964 + atomic_set_unchecked(&ap_wfs_count, 0);
18965 register_hotcpu_notifier(&tboot_cpu_notifier);
18966 return 0;
18967 }
18968 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
18969 index dd5fbf4..b7f2232 100644
18970 --- a/arch/x86/kernel/time.c
18971 +++ b/arch/x86/kernel/time.c
18972 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
18973 {
18974 unsigned long pc = instruction_pointer(regs);
18975
18976 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
18977 + if (!user_mode(regs) && in_lock_functions(pc)) {
18978 #ifdef CONFIG_FRAME_POINTER
18979 - return *(unsigned long *)(regs->bp + sizeof(long));
18980 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
18981 #else
18982 unsigned long *sp =
18983 (unsigned long *)kernel_stack_pointer(regs);
18984 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
18985 * or above a saved flags. Eflags has bits 22-31 zero,
18986 * kernel addresses don't.
18987 */
18988 +
18989 +#ifdef CONFIG_PAX_KERNEXEC
18990 + return ktla_ktva(sp[0]);
18991 +#else
18992 if (sp[0] >> 22)
18993 return sp[0];
18994 if (sp[1] >> 22)
18995 return sp[1];
18996 #endif
18997 +
18998 +#endif
18999 }
19000 return pc;
19001 }
19002 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19003 index 6bb7b85..dd853e1 100644
19004 --- a/arch/x86/kernel/tls.c
19005 +++ b/arch/x86/kernel/tls.c
19006 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19007 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19008 return -EINVAL;
19009
19010 +#ifdef CONFIG_PAX_SEGMEXEC
19011 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19012 + return -EINVAL;
19013 +#endif
19014 +
19015 set_tls_desc(p, idx, &info, 1);
19016
19017 return 0;
19018 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19019 index 451c0a7..e57f551 100644
19020 --- a/arch/x86/kernel/trampoline_32.S
19021 +++ b/arch/x86/kernel/trampoline_32.S
19022 @@ -32,6 +32,12 @@
19023 #include <asm/segment.h>
19024 #include <asm/page_types.h>
19025
19026 +#ifdef CONFIG_PAX_KERNEXEC
19027 +#define ta(X) (X)
19028 +#else
19029 +#define ta(X) ((X) - __PAGE_OFFSET)
19030 +#endif
19031 +
19032 #ifdef CONFIG_SMP
19033
19034 .section ".x86_trampoline","a"
19035 @@ -62,7 +68,7 @@ r_base = .
19036 inc %ax # protected mode (PE) bit
19037 lmsw %ax # into protected mode
19038 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19039 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19040 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19041
19042 # These need to be in the same 64K segment as the above;
19043 # hence we don't use the boot_gdt_descr defined in head.S
19044 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19045 index 09ff517..df19fbff 100644
19046 --- a/arch/x86/kernel/trampoline_64.S
19047 +++ b/arch/x86/kernel/trampoline_64.S
19048 @@ -90,7 +90,7 @@ startup_32:
19049 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19050 movl %eax, %ds
19051
19052 - movl $X86_CR4_PAE, %eax
19053 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19054 movl %eax, %cr4 # Enable PAE mode
19055
19056 # Setup trampoline 4 level pagetables
19057 @@ -138,7 +138,7 @@ tidt:
19058 # so the kernel can live anywhere
19059 .balign 4
19060 tgdt:
19061 - .short tgdt_end - tgdt # gdt limit
19062 + .short tgdt_end - tgdt - 1 # gdt limit
19063 .long tgdt - r_base
19064 .short 0
19065 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19066 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19067 index 31d9d0f..e244dd9 100644
19068 --- a/arch/x86/kernel/traps.c
19069 +++ b/arch/x86/kernel/traps.c
19070 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19071
19072 /* Do we ignore FPU interrupts ? */
19073 char ignore_fpu_irq;
19074 -
19075 -/*
19076 - * The IDT has to be page-aligned to simplify the Pentium
19077 - * F0 0F bug workaround.
19078 - */
19079 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19080 #endif
19081
19082 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19083 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19084 }
19085
19086 static void __kprobes
19087 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19088 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19089 long error_code, siginfo_t *info)
19090 {
19091 struct task_struct *tsk = current;
19092
19093 #ifdef CONFIG_X86_32
19094 - if (regs->flags & X86_VM_MASK) {
19095 + if (v8086_mode(regs)) {
19096 /*
19097 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19098 * On nmi (interrupt 2), do_trap should not be called.
19099 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19100 }
19101 #endif
19102
19103 - if (!user_mode(regs))
19104 + if (!user_mode_novm(regs))
19105 goto kernel_trap;
19106
19107 #ifdef CONFIG_X86_32
19108 @@ -148,7 +142,7 @@ trap_signal:
19109 printk_ratelimit()) {
19110 printk(KERN_INFO
19111 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19112 - tsk->comm, tsk->pid, str,
19113 + tsk->comm, task_pid_nr(tsk), str,
19114 regs->ip, regs->sp, error_code);
19115 print_vma_addr(" in ", regs->ip);
19116 printk("\n");
19117 @@ -165,8 +159,20 @@ kernel_trap:
19118 if (!fixup_exception(regs)) {
19119 tsk->thread.error_code = error_code;
19120 tsk->thread.trap_no = trapnr;
19121 +
19122 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19123 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19124 + str = "PAX: suspicious stack segment fault";
19125 +#endif
19126 +
19127 die(str, regs, error_code);
19128 }
19129 +
19130 +#ifdef CONFIG_PAX_REFCOUNT
19131 + if (trapnr == 4)
19132 + pax_report_refcount_overflow(regs);
19133 +#endif
19134 +
19135 return;
19136
19137 #ifdef CONFIG_X86_32
19138 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19139 conditional_sti(regs);
19140
19141 #ifdef CONFIG_X86_32
19142 - if (regs->flags & X86_VM_MASK)
19143 + if (v8086_mode(regs))
19144 goto gp_in_vm86;
19145 #endif
19146
19147 tsk = current;
19148 - if (!user_mode(regs))
19149 + if (!user_mode_novm(regs))
19150 goto gp_in_kernel;
19151
19152 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19153 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19154 + struct mm_struct *mm = tsk->mm;
19155 + unsigned long limit;
19156 +
19157 + down_write(&mm->mmap_sem);
19158 + limit = mm->context.user_cs_limit;
19159 + if (limit < TASK_SIZE) {
19160 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19161 + up_write(&mm->mmap_sem);
19162 + return;
19163 + }
19164 + up_write(&mm->mmap_sem);
19165 + }
19166 +#endif
19167 +
19168 tsk->thread.error_code = error_code;
19169 tsk->thread.trap_no = 13;
19170
19171 @@ -295,6 +317,13 @@ gp_in_kernel:
19172 if (notify_die(DIE_GPF, "general protection fault", regs,
19173 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19174 return;
19175 +
19176 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19177 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19178 + die("PAX: suspicious general protection fault", regs, error_code);
19179 + else
19180 +#endif
19181 +
19182 die("general protection fault", regs, error_code);
19183 }
19184
19185 @@ -414,7 +443,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19186 /* It's safe to allow irq's after DR6 has been saved */
19187 preempt_conditional_sti(regs);
19188
19189 - if (regs->flags & X86_VM_MASK) {
19190 + if (v8086_mode(regs)) {
19191 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19192 error_code, 1);
19193 preempt_conditional_cli(regs);
19194 @@ -428,7 +457,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19195 * We already checked v86 mode above, so we can check for kernel mode
19196 * by just checking the CPL of CS.
19197 */
19198 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19199 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19200 tsk->thread.debugreg6 &= ~DR_STEP;
19201 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19202 regs->flags &= ~X86_EFLAGS_TF;
19203 @@ -457,7 +486,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19204 return;
19205 conditional_sti(regs);
19206
19207 - if (!user_mode_vm(regs))
19208 + if (!user_mode(regs))
19209 {
19210 if (!fixup_exception(regs)) {
19211 task->thread.error_code = error_code;
19212 @@ -569,8 +598,8 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
19213 void __math_state_restore(struct task_struct *tsk)
19214 {
19215 /* We need a safe address that is cheap to find and that is already
19216 - in L1. We've just brought in "tsk->thread.has_fpu", so use that */
19217 -#define safe_address (tsk->thread.has_fpu)
19218 + in L1. */
19219 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
19220
19221 /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
19222 is pending. Clear the x87 state here by setting it to fixed
19223 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19224 index b9242ba..50c5edd 100644
19225 --- a/arch/x86/kernel/verify_cpu.S
19226 +++ b/arch/x86/kernel/verify_cpu.S
19227 @@ -20,6 +20,7 @@
19228 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19229 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19230 * arch/x86/kernel/head_32.S: processor startup
19231 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19232 *
19233 * verify_cpu, returns the status of longmode and SSE in register %eax.
19234 * 0: Success 1: Failure
19235 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19236 index 863f875..4307295 100644
19237 --- a/arch/x86/kernel/vm86_32.c
19238 +++ b/arch/x86/kernel/vm86_32.c
19239 @@ -41,6 +41,7 @@
19240 #include <linux/ptrace.h>
19241 #include <linux/audit.h>
19242 #include <linux/stddef.h>
19243 +#include <linux/grsecurity.h>
19244
19245 #include <asm/uaccess.h>
19246 #include <asm/io.h>
19247 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19248 do_exit(SIGSEGV);
19249 }
19250
19251 - tss = &per_cpu(init_tss, get_cpu());
19252 + tss = init_tss + get_cpu();
19253 current->thread.sp0 = current->thread.saved_sp0;
19254 current->thread.sysenter_cs = __KERNEL_CS;
19255 load_sp0(tss, &current->thread);
19256 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19257 struct task_struct *tsk;
19258 int tmp, ret = -EPERM;
19259
19260 +#ifdef CONFIG_GRKERNSEC_VM86
19261 + if (!capable(CAP_SYS_RAWIO)) {
19262 + gr_handle_vm86();
19263 + goto out;
19264 + }
19265 +#endif
19266 +
19267 tsk = current;
19268 if (tsk->thread.saved_sp0)
19269 goto out;
19270 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19271 int tmp, ret;
19272 struct vm86plus_struct __user *v86;
19273
19274 +#ifdef CONFIG_GRKERNSEC_VM86
19275 + if (!capable(CAP_SYS_RAWIO)) {
19276 + gr_handle_vm86();
19277 + ret = -EPERM;
19278 + goto out;
19279 + }
19280 +#endif
19281 +
19282 tsk = current;
19283 switch (cmd) {
19284 case VM86_REQUEST_IRQ:
19285 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19286 tsk->thread.saved_fs = info->regs32->fs;
19287 tsk->thread.saved_gs = get_user_gs(info->regs32);
19288
19289 - tss = &per_cpu(init_tss, get_cpu());
19290 + tss = init_tss + get_cpu();
19291 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19292 if (cpu_has_sep)
19293 tsk->thread.sysenter_cs = 0;
19294 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19295 goto cannot_handle;
19296 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19297 goto cannot_handle;
19298 - intr_ptr = (unsigned long __user *) (i << 2);
19299 + intr_ptr = (__force unsigned long __user *) (i << 2);
19300 if (get_user(segoffs, intr_ptr))
19301 goto cannot_handle;
19302 if ((segoffs >> 16) == BIOSSEG)
19303 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19304 index 0f703f1..9e15f64 100644
19305 --- a/arch/x86/kernel/vmlinux.lds.S
19306 +++ b/arch/x86/kernel/vmlinux.lds.S
19307 @@ -26,6 +26,13 @@
19308 #include <asm/page_types.h>
19309 #include <asm/cache.h>
19310 #include <asm/boot.h>
19311 +#include <asm/segment.h>
19312 +
19313 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19314 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19315 +#else
19316 +#define __KERNEL_TEXT_OFFSET 0
19317 +#endif
19318
19319 #undef i386 /* in case the preprocessor is a 32bit one */
19320
19321 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19322
19323 PHDRS {
19324 text PT_LOAD FLAGS(5); /* R_E */
19325 +#ifdef CONFIG_X86_32
19326 + module PT_LOAD FLAGS(5); /* R_E */
19327 +#endif
19328 +#ifdef CONFIG_XEN
19329 + rodata PT_LOAD FLAGS(5); /* R_E */
19330 +#else
19331 + rodata PT_LOAD FLAGS(4); /* R__ */
19332 +#endif
19333 data PT_LOAD FLAGS(6); /* RW_ */
19334 -#ifdef CONFIG_X86_64
19335 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19336 #ifdef CONFIG_SMP
19337 percpu PT_LOAD FLAGS(6); /* RW_ */
19338 #endif
19339 + text.init PT_LOAD FLAGS(5); /* R_E */
19340 + text.exit PT_LOAD FLAGS(5); /* R_E */
19341 init PT_LOAD FLAGS(7); /* RWE */
19342 -#endif
19343 note PT_NOTE FLAGS(0); /* ___ */
19344 }
19345
19346 SECTIONS
19347 {
19348 #ifdef CONFIG_X86_32
19349 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19350 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19351 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19352 #else
19353 - . = __START_KERNEL;
19354 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19355 + . = __START_KERNEL;
19356 #endif
19357
19358 /* Text and read-only data */
19359 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19360 - _text = .;
19361 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19362 /* bootstrapping code */
19363 +#ifdef CONFIG_X86_32
19364 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19365 +#else
19366 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19367 +#endif
19368 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19369 + _text = .;
19370 HEAD_TEXT
19371 #ifdef CONFIG_X86_32
19372 . = ALIGN(PAGE_SIZE);
19373 @@ -108,13 +128,47 @@ SECTIONS
19374 IRQENTRY_TEXT
19375 *(.fixup)
19376 *(.gnu.warning)
19377 - /* End of text section */
19378 - _etext = .;
19379 } :text = 0x9090
19380
19381 - NOTES :text :note
19382 + . += __KERNEL_TEXT_OFFSET;
19383
19384 - EXCEPTION_TABLE(16) :text = 0x9090
19385 +#ifdef CONFIG_X86_32
19386 + . = ALIGN(PAGE_SIZE);
19387 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19388 +
19389 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19390 + MODULES_EXEC_VADDR = .;
19391 + BYTE(0)
19392 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19393 + . = ALIGN(HPAGE_SIZE);
19394 + MODULES_EXEC_END = . - 1;
19395 +#endif
19396 +
19397 + } :module
19398 +#endif
19399 +
19400 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19401 + /* End of text section */
19402 + _etext = . - __KERNEL_TEXT_OFFSET;
19403 + }
19404 +
19405 +#ifdef CONFIG_X86_32
19406 + . = ALIGN(PAGE_SIZE);
19407 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19408 + *(.idt)
19409 + . = ALIGN(PAGE_SIZE);
19410 + *(.empty_zero_page)
19411 + *(.initial_pg_fixmap)
19412 + *(.initial_pg_pmd)
19413 + *(.initial_page_table)
19414 + *(.swapper_pg_dir)
19415 + } :rodata
19416 +#endif
19417 +
19418 + . = ALIGN(PAGE_SIZE);
19419 + NOTES :rodata :note
19420 +
19421 + EXCEPTION_TABLE(16) :rodata
19422
19423 #if defined(CONFIG_DEBUG_RODATA)
19424 /* .text should occupy whole number of pages */
19425 @@ -126,16 +180,20 @@ SECTIONS
19426
19427 /* Data */
19428 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19429 +
19430 +#ifdef CONFIG_PAX_KERNEXEC
19431 + . = ALIGN(HPAGE_SIZE);
19432 +#else
19433 + . = ALIGN(PAGE_SIZE);
19434 +#endif
19435 +
19436 /* Start of data section */
19437 _sdata = .;
19438
19439 /* init_task */
19440 INIT_TASK_DATA(THREAD_SIZE)
19441
19442 -#ifdef CONFIG_X86_32
19443 - /* 32 bit has nosave before _edata */
19444 NOSAVE_DATA
19445 -#endif
19446
19447 PAGE_ALIGNED_DATA(PAGE_SIZE)
19448
19449 @@ -176,12 +234,19 @@ SECTIONS
19450 #endif /* CONFIG_X86_64 */
19451
19452 /* Init code and data - will be freed after init */
19453 - . = ALIGN(PAGE_SIZE);
19454 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19455 + BYTE(0)
19456 +
19457 +#ifdef CONFIG_PAX_KERNEXEC
19458 + . = ALIGN(HPAGE_SIZE);
19459 +#else
19460 + . = ALIGN(PAGE_SIZE);
19461 +#endif
19462 +
19463 __init_begin = .; /* paired with __init_end */
19464 - }
19465 + } :init.begin
19466
19467 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19468 +#ifdef CONFIG_SMP
19469 /*
19470 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19471 * output PHDR, so the next output section - .init.text - should
19472 @@ -190,12 +255,27 @@ SECTIONS
19473 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19474 #endif
19475
19476 - INIT_TEXT_SECTION(PAGE_SIZE)
19477 -#ifdef CONFIG_X86_64
19478 - :init
19479 -#endif
19480 + . = ALIGN(PAGE_SIZE);
19481 + init_begin = .;
19482 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19483 + VMLINUX_SYMBOL(_sinittext) = .;
19484 + INIT_TEXT
19485 + VMLINUX_SYMBOL(_einittext) = .;
19486 + . = ALIGN(PAGE_SIZE);
19487 + } :text.init
19488
19489 - INIT_DATA_SECTION(16)
19490 + /*
19491 + * .exit.text is discard at runtime, not link time, to deal with
19492 + * references from .altinstructions and .eh_frame
19493 + */
19494 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19495 + EXIT_TEXT
19496 + . = ALIGN(16);
19497 + } :text.exit
19498 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19499 +
19500 + . = ALIGN(PAGE_SIZE);
19501 + INIT_DATA_SECTION(16) :init
19502
19503 /*
19504 * Code and data for a variety of lowlevel trampolines, to be
19505 @@ -269,19 +349,12 @@ SECTIONS
19506 }
19507
19508 . = ALIGN(8);
19509 - /*
19510 - * .exit.text is discard at runtime, not link time, to deal with
19511 - * references from .altinstructions and .eh_frame
19512 - */
19513 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19514 - EXIT_TEXT
19515 - }
19516
19517 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19518 EXIT_DATA
19519 }
19520
19521 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19522 +#ifndef CONFIG_SMP
19523 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19524 #endif
19525
19526 @@ -300,16 +373,10 @@ SECTIONS
19527 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19528 __smp_locks = .;
19529 *(.smp_locks)
19530 - . = ALIGN(PAGE_SIZE);
19531 __smp_locks_end = .;
19532 + . = ALIGN(PAGE_SIZE);
19533 }
19534
19535 -#ifdef CONFIG_X86_64
19536 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19537 - NOSAVE_DATA
19538 - }
19539 -#endif
19540 -
19541 /* BSS */
19542 . = ALIGN(PAGE_SIZE);
19543 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19544 @@ -325,6 +392,7 @@ SECTIONS
19545 __brk_base = .;
19546 . += 64 * 1024; /* 64k alignment slop space */
19547 *(.brk_reservation) /* areas brk users have reserved */
19548 + . = ALIGN(HPAGE_SIZE);
19549 __brk_limit = .;
19550 }
19551
19552 @@ -351,13 +419,12 @@ SECTIONS
19553 * for the boot processor.
19554 */
19555 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19556 -INIT_PER_CPU(gdt_page);
19557 INIT_PER_CPU(irq_stack_union);
19558
19559 /*
19560 * Build-time check on the image size:
19561 */
19562 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19563 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19564 "kernel image bigger than KERNEL_IMAGE_SIZE");
19565
19566 #ifdef CONFIG_SMP
19567 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19568 index e4d4a22..47ee71f 100644
19569 --- a/arch/x86/kernel/vsyscall_64.c
19570 +++ b/arch/x86/kernel/vsyscall_64.c
19571 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19572 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19573 };
19574
19575 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
19576 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19577
19578 static int __init vsyscall_setup(char *str)
19579 {
19580 if (str) {
19581 if (!strcmp("emulate", str))
19582 vsyscall_mode = EMULATE;
19583 - else if (!strcmp("native", str))
19584 - vsyscall_mode = NATIVE;
19585 else if (!strcmp("none", str))
19586 vsyscall_mode = NONE;
19587 else
19588 @@ -178,7 +176,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19589
19590 tsk = current;
19591 if (seccomp_mode(&tsk->seccomp))
19592 - do_exit(SIGKILL);
19593 + do_group_exit(SIGKILL);
19594
19595 switch (vsyscall_nr) {
19596 case 0:
19597 @@ -220,8 +218,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19598 return true;
19599
19600 sigsegv:
19601 - force_sig(SIGSEGV, current);
19602 - return true;
19603 + do_group_exit(SIGKILL);
19604 }
19605
19606 /*
19607 @@ -274,10 +271,7 @@ void __init map_vsyscall(void)
19608 extern char __vvar_page;
19609 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19610
19611 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19612 - vsyscall_mode == NATIVE
19613 - ? PAGE_KERNEL_VSYSCALL
19614 - : PAGE_KERNEL_VVAR);
19615 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19616 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19617 (unsigned long)VSYSCALL_START);
19618
19619 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19620 index 9796c2f..f686fbf 100644
19621 --- a/arch/x86/kernel/x8664_ksyms_64.c
19622 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19623 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19624 EXPORT_SYMBOL(copy_user_generic_string);
19625 EXPORT_SYMBOL(copy_user_generic_unrolled);
19626 EXPORT_SYMBOL(__copy_user_nocache);
19627 -EXPORT_SYMBOL(_copy_from_user);
19628 -EXPORT_SYMBOL(_copy_to_user);
19629
19630 EXPORT_SYMBOL(copy_page);
19631 EXPORT_SYMBOL(clear_page);
19632 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19633 index 7110911..e8cdee5 100644
19634 --- a/arch/x86/kernel/xsave.c
19635 +++ b/arch/x86/kernel/xsave.c
19636 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19637 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19638 return -EINVAL;
19639
19640 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19641 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19642 fx_sw_user->extended_size -
19643 FP_XSTATE_MAGIC2_SIZE));
19644 if (err)
19645 @@ -266,7 +266,7 @@ fx_only:
19646 * the other extended state.
19647 */
19648 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19649 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19650 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19651 }
19652
19653 /*
19654 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19655 if (use_xsave())
19656 err = restore_user_xstate(buf);
19657 else
19658 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19659 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19660 buf);
19661 if (unlikely(err)) {
19662 /*
19663 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
19664 index f1e3be1..588efc8 100644
19665 --- a/arch/x86/kvm/emulate.c
19666 +++ b/arch/x86/kvm/emulate.c
19667 @@ -249,6 +249,7 @@ struct gprefix {
19668
19669 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
19670 do { \
19671 + unsigned long _tmp; \
19672 __asm__ __volatile__ ( \
19673 _PRE_EFLAGS("0", "4", "2") \
19674 _op _suffix " %"_x"3,%1; " \
19675 @@ -263,8 +264,6 @@ struct gprefix {
19676 /* Raw emulation: instruction has two explicit operands. */
19677 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
19678 do { \
19679 - unsigned long _tmp; \
19680 - \
19681 switch ((ctxt)->dst.bytes) { \
19682 case 2: \
19683 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
19684 @@ -280,7 +279,6 @@ struct gprefix {
19685
19686 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
19687 do { \
19688 - unsigned long _tmp; \
19689 switch ((ctxt)->dst.bytes) { \
19690 case 1: \
19691 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
19692 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
19693 index 54abb40..a192606 100644
19694 --- a/arch/x86/kvm/lapic.c
19695 +++ b/arch/x86/kvm/lapic.c
19696 @@ -53,7 +53,7 @@
19697 #define APIC_BUS_CYCLE_NS 1
19698
19699 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
19700 -#define apic_debug(fmt, arg...)
19701 +#define apic_debug(fmt, arg...) do {} while (0)
19702
19703 #define APIC_LVT_NUM 6
19704 /* 14 is the version for Xeon and Pentium 8.4.8*/
19705 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
19706 index f1b36cf..af8a124 100644
19707 --- a/arch/x86/kvm/mmu.c
19708 +++ b/arch/x86/kvm/mmu.c
19709 @@ -3555,7 +3555,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
19710
19711 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
19712
19713 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
19714 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
19715
19716 /*
19717 * Assume that the pte write on a page table of the same type
19718 @@ -3587,7 +3587,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
19719 }
19720
19721 spin_lock(&vcpu->kvm->mmu_lock);
19722 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
19723 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
19724 gentry = 0;
19725 kvm_mmu_free_some_pages(vcpu);
19726 ++vcpu->kvm->stat.mmu_pte_write;
19727 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
19728 index 9299410..ade2f9b 100644
19729 --- a/arch/x86/kvm/paging_tmpl.h
19730 +++ b/arch/x86/kvm/paging_tmpl.h
19731 @@ -197,7 +197,7 @@ retry_walk:
19732 if (unlikely(kvm_is_error_hva(host_addr)))
19733 goto error;
19734
19735 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
19736 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
19737 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
19738 goto error;
19739
19740 @@ -705,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
19741 if (need_flush)
19742 kvm_flush_remote_tlbs(vcpu->kvm);
19743
19744 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
19745 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
19746
19747 spin_unlock(&vcpu->kvm->mmu_lock);
19748
19749 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
19750 index 94a4672..5c6b853 100644
19751 --- a/arch/x86/kvm/svm.c
19752 +++ b/arch/x86/kvm/svm.c
19753 @@ -3405,7 +3405,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
19754 int cpu = raw_smp_processor_id();
19755
19756 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
19757 +
19758 + pax_open_kernel();
19759 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
19760 + pax_close_kernel();
19761 +
19762 load_TR_desc();
19763 }
19764
19765 @@ -3783,6 +3787,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
19766 #endif
19767 #endif
19768
19769 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19770 + __set_fs(current_thread_info()->addr_limit);
19771 +#endif
19772 +
19773 reload_tss(vcpu);
19774
19775 local_irq_disable();
19776 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
19777 index 4ea7678..b3a7084 100644
19778 --- a/arch/x86/kvm/vmx.c
19779 +++ b/arch/x86/kvm/vmx.c
19780 @@ -1305,7 +1305,11 @@ static void reload_tss(void)
19781 struct desc_struct *descs;
19782
19783 descs = (void *)gdt->address;
19784 +
19785 + pax_open_kernel();
19786 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
19787 + pax_close_kernel();
19788 +
19789 load_TR_desc();
19790 }
19791
19792 @@ -2633,8 +2637,11 @@ static __init int hardware_setup(void)
19793 if (!cpu_has_vmx_flexpriority())
19794 flexpriority_enabled = 0;
19795
19796 - if (!cpu_has_vmx_tpr_shadow())
19797 - kvm_x86_ops->update_cr8_intercept = NULL;
19798 + if (!cpu_has_vmx_tpr_shadow()) {
19799 + pax_open_kernel();
19800 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
19801 + pax_close_kernel();
19802 + }
19803
19804 if (enable_ept && !cpu_has_vmx_ept_2m_page())
19805 kvm_disable_largepages();
19806 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
19807 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
19808
19809 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
19810 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
19811 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
19812
19813 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
19814 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
19815 @@ -6169,6 +6176,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19816 "jmp .Lkvm_vmx_return \n\t"
19817 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
19818 ".Lkvm_vmx_return: "
19819 +
19820 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19821 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
19822 + ".Lkvm_vmx_return2: "
19823 +#endif
19824 +
19825 /* Save guest registers, load host registers, keep flags */
19826 "mov %0, %c[wordsize](%%"R"sp) \n\t"
19827 "pop %0 \n\t"
19828 @@ -6217,6 +6230,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19829 #endif
19830 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
19831 [wordsize]"i"(sizeof(ulong))
19832 +
19833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19834 + ,[cs]"i"(__KERNEL_CS)
19835 +#endif
19836 +
19837 : "cc", "memory"
19838 , R"ax", R"bx", R"di", R"si"
19839 #ifdef CONFIG_X86_64
19840 @@ -6245,7 +6263,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19841 }
19842 }
19843
19844 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
19845 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
19846 +
19847 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19848 + loadsegment(fs, __KERNEL_PERCPU);
19849 +#endif
19850 +
19851 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19852 + __set_fs(current_thread_info()->addr_limit);
19853 +#endif
19854 +
19855 vmx->loaded_vmcs->launched = 1;
19856
19857 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
19858 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
19859 index 4c938da..4ddef65 100644
19860 --- a/arch/x86/kvm/x86.c
19861 +++ b/arch/x86/kvm/x86.c
19862 @@ -1345,8 +1345,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
19863 {
19864 struct kvm *kvm = vcpu->kvm;
19865 int lm = is_long_mode(vcpu);
19866 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19867 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19868 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19869 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19870 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
19871 : kvm->arch.xen_hvm_config.blob_size_32;
19872 u32 page_num = data & ~PAGE_MASK;
19873 @@ -2165,6 +2165,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
19874 if (n < msr_list.nmsrs)
19875 goto out;
19876 r = -EFAULT;
19877 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
19878 + goto out;
19879 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
19880 num_msrs_to_save * sizeof(u32)))
19881 goto out;
19882 @@ -2340,15 +2342,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
19883 struct kvm_cpuid2 *cpuid,
19884 struct kvm_cpuid_entry2 __user *entries)
19885 {
19886 - int r;
19887 + int r, i;
19888
19889 r = -E2BIG;
19890 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
19891 goto out;
19892 r = -EFAULT;
19893 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
19894 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19895 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19896 goto out;
19897 + for (i = 0; i < cpuid->nent; ++i) {
19898 + struct kvm_cpuid_entry2 cpuid_entry;
19899 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
19900 + goto out;
19901 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
19902 + }
19903 vcpu->arch.cpuid_nent = cpuid->nent;
19904 kvm_apic_set_version(vcpu);
19905 kvm_x86_ops->cpuid_update(vcpu);
19906 @@ -2363,15 +2370,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
19907 struct kvm_cpuid2 *cpuid,
19908 struct kvm_cpuid_entry2 __user *entries)
19909 {
19910 - int r;
19911 + int r, i;
19912
19913 r = -E2BIG;
19914 if (cpuid->nent < vcpu->arch.cpuid_nent)
19915 goto out;
19916 r = -EFAULT;
19917 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
19918 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19919 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19920 goto out;
19921 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
19922 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
19923 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
19924 + goto out;
19925 + }
19926 return 0;
19927
19928 out:
19929 @@ -2746,7 +2757,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
19930 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
19931 struct kvm_interrupt *irq)
19932 {
19933 - if (irq->irq < 0 || irq->irq >= 256)
19934 + if (irq->irq >= 256)
19935 return -EINVAL;
19936 if (irqchip_in_kernel(vcpu->kvm))
19937 return -ENXIO;
19938 @@ -5162,7 +5173,7 @@ static void kvm_set_mmio_spte_mask(void)
19939 kvm_mmu_set_mmio_spte_mask(mask);
19940 }
19941
19942 -int kvm_arch_init(void *opaque)
19943 +int kvm_arch_init(const void *opaque)
19944 {
19945 int r;
19946 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
19947 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
19948 index cf4603b..7cdde38 100644
19949 --- a/arch/x86/lguest/boot.c
19950 +++ b/arch/x86/lguest/boot.c
19951 @@ -1195,9 +1195,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
19952 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
19953 * Launcher to reboot us.
19954 */
19955 -static void lguest_restart(char *reason)
19956 +static __noreturn void lguest_restart(char *reason)
19957 {
19958 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
19959 + BUG();
19960 }
19961
19962 /*G:050
19963 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
19964 index 042f682..c92afb6 100644
19965 --- a/arch/x86/lib/atomic64_32.c
19966 +++ b/arch/x86/lib/atomic64_32.c
19967 @@ -8,18 +8,30 @@
19968
19969 long long atomic64_read_cx8(long long, const atomic64_t *v);
19970 EXPORT_SYMBOL(atomic64_read_cx8);
19971 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19972 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
19973 long long atomic64_set_cx8(long long, const atomic64_t *v);
19974 EXPORT_SYMBOL(atomic64_set_cx8);
19975 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19976 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
19977 long long atomic64_xchg_cx8(long long, unsigned high);
19978 EXPORT_SYMBOL(atomic64_xchg_cx8);
19979 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
19980 EXPORT_SYMBOL(atomic64_add_return_cx8);
19981 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19982 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
19983 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
19984 EXPORT_SYMBOL(atomic64_sub_return_cx8);
19985 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19986 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
19987 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
19988 EXPORT_SYMBOL(atomic64_inc_return_cx8);
19989 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19990 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
19991 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
19992 EXPORT_SYMBOL(atomic64_dec_return_cx8);
19993 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19994 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
19995 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
19996 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
19997 int atomic64_inc_not_zero_cx8(atomic64_t *v);
19998 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
19999 #ifndef CONFIG_X86_CMPXCHG64
20000 long long atomic64_read_386(long long, const atomic64_t *v);
20001 EXPORT_SYMBOL(atomic64_read_386);
20002 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20003 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
20004 long long atomic64_set_386(long long, const atomic64_t *v);
20005 EXPORT_SYMBOL(atomic64_set_386);
20006 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20007 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
20008 long long atomic64_xchg_386(long long, unsigned high);
20009 EXPORT_SYMBOL(atomic64_xchg_386);
20010 long long atomic64_add_return_386(long long a, atomic64_t *v);
20011 EXPORT_SYMBOL(atomic64_add_return_386);
20012 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20013 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20014 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20015 EXPORT_SYMBOL(atomic64_sub_return_386);
20016 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20017 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20018 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20019 EXPORT_SYMBOL(atomic64_inc_return_386);
20020 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20021 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20022 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20023 EXPORT_SYMBOL(atomic64_dec_return_386);
20024 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20025 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20026 long long atomic64_add_386(long long a, atomic64_t *v);
20027 EXPORT_SYMBOL(atomic64_add_386);
20028 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20029 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
20030 long long atomic64_sub_386(long long a, atomic64_t *v);
20031 EXPORT_SYMBOL(atomic64_sub_386);
20032 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20033 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20034 long long atomic64_inc_386(long long a, atomic64_t *v);
20035 EXPORT_SYMBOL(atomic64_inc_386);
20036 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20037 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20038 long long atomic64_dec_386(long long a, atomic64_t *v);
20039 EXPORT_SYMBOL(atomic64_dec_386);
20040 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20041 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20042 long long atomic64_dec_if_positive_386(atomic64_t *v);
20043 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20044 int atomic64_inc_not_zero_386(atomic64_t *v);
20045 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20046 index e8e7e0d..56fd1b0 100644
20047 --- a/arch/x86/lib/atomic64_386_32.S
20048 +++ b/arch/x86/lib/atomic64_386_32.S
20049 @@ -48,6 +48,10 @@ BEGIN(read)
20050 movl (v), %eax
20051 movl 4(v), %edx
20052 RET_ENDP
20053 +BEGIN(read_unchecked)
20054 + movl (v), %eax
20055 + movl 4(v), %edx
20056 +RET_ENDP
20057 #undef v
20058
20059 #define v %esi
20060 @@ -55,6 +59,10 @@ BEGIN(set)
20061 movl %ebx, (v)
20062 movl %ecx, 4(v)
20063 RET_ENDP
20064 +BEGIN(set_unchecked)
20065 + movl %ebx, (v)
20066 + movl %ecx, 4(v)
20067 +RET_ENDP
20068 #undef v
20069
20070 #define v %esi
20071 @@ -70,6 +78,20 @@ RET_ENDP
20072 BEGIN(add)
20073 addl %eax, (v)
20074 adcl %edx, 4(v)
20075 +
20076 +#ifdef CONFIG_PAX_REFCOUNT
20077 + jno 0f
20078 + subl %eax, (v)
20079 + sbbl %edx, 4(v)
20080 + int $4
20081 +0:
20082 + _ASM_EXTABLE(0b, 0b)
20083 +#endif
20084 +
20085 +RET_ENDP
20086 +BEGIN(add_unchecked)
20087 + addl %eax, (v)
20088 + adcl %edx, 4(v)
20089 RET_ENDP
20090 #undef v
20091
20092 @@ -77,6 +99,24 @@ RET_ENDP
20093 BEGIN(add_return)
20094 addl (v), %eax
20095 adcl 4(v), %edx
20096 +
20097 +#ifdef CONFIG_PAX_REFCOUNT
20098 + into
20099 +1234:
20100 + _ASM_EXTABLE(1234b, 2f)
20101 +#endif
20102 +
20103 + movl %eax, (v)
20104 + movl %edx, 4(v)
20105 +
20106 +#ifdef CONFIG_PAX_REFCOUNT
20107 +2:
20108 +#endif
20109 +
20110 +RET_ENDP
20111 +BEGIN(add_return_unchecked)
20112 + addl (v), %eax
20113 + adcl 4(v), %edx
20114 movl %eax, (v)
20115 movl %edx, 4(v)
20116 RET_ENDP
20117 @@ -86,6 +126,20 @@ RET_ENDP
20118 BEGIN(sub)
20119 subl %eax, (v)
20120 sbbl %edx, 4(v)
20121 +
20122 +#ifdef CONFIG_PAX_REFCOUNT
20123 + jno 0f
20124 + addl %eax, (v)
20125 + adcl %edx, 4(v)
20126 + int $4
20127 +0:
20128 + _ASM_EXTABLE(0b, 0b)
20129 +#endif
20130 +
20131 +RET_ENDP
20132 +BEGIN(sub_unchecked)
20133 + subl %eax, (v)
20134 + sbbl %edx, 4(v)
20135 RET_ENDP
20136 #undef v
20137
20138 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20139 sbbl $0, %edx
20140 addl (v), %eax
20141 adcl 4(v), %edx
20142 +
20143 +#ifdef CONFIG_PAX_REFCOUNT
20144 + into
20145 +1234:
20146 + _ASM_EXTABLE(1234b, 2f)
20147 +#endif
20148 +
20149 + movl %eax, (v)
20150 + movl %edx, 4(v)
20151 +
20152 +#ifdef CONFIG_PAX_REFCOUNT
20153 +2:
20154 +#endif
20155 +
20156 +RET_ENDP
20157 +BEGIN(sub_return_unchecked)
20158 + negl %edx
20159 + negl %eax
20160 + sbbl $0, %edx
20161 + addl (v), %eax
20162 + adcl 4(v), %edx
20163 movl %eax, (v)
20164 movl %edx, 4(v)
20165 RET_ENDP
20166 @@ -105,6 +180,20 @@ RET_ENDP
20167 BEGIN(inc)
20168 addl $1, (v)
20169 adcl $0, 4(v)
20170 +
20171 +#ifdef CONFIG_PAX_REFCOUNT
20172 + jno 0f
20173 + subl $1, (v)
20174 + sbbl $0, 4(v)
20175 + int $4
20176 +0:
20177 + _ASM_EXTABLE(0b, 0b)
20178 +#endif
20179 +
20180 +RET_ENDP
20181 +BEGIN(inc_unchecked)
20182 + addl $1, (v)
20183 + adcl $0, 4(v)
20184 RET_ENDP
20185 #undef v
20186
20187 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20188 movl 4(v), %edx
20189 addl $1, %eax
20190 adcl $0, %edx
20191 +
20192 +#ifdef CONFIG_PAX_REFCOUNT
20193 + into
20194 +1234:
20195 + _ASM_EXTABLE(1234b, 2f)
20196 +#endif
20197 +
20198 + movl %eax, (v)
20199 + movl %edx, 4(v)
20200 +
20201 +#ifdef CONFIG_PAX_REFCOUNT
20202 +2:
20203 +#endif
20204 +
20205 +RET_ENDP
20206 +BEGIN(inc_return_unchecked)
20207 + movl (v), %eax
20208 + movl 4(v), %edx
20209 + addl $1, %eax
20210 + adcl $0, %edx
20211 movl %eax, (v)
20212 movl %edx, 4(v)
20213 RET_ENDP
20214 @@ -123,6 +232,20 @@ RET_ENDP
20215 BEGIN(dec)
20216 subl $1, (v)
20217 sbbl $0, 4(v)
20218 +
20219 +#ifdef CONFIG_PAX_REFCOUNT
20220 + jno 0f
20221 + addl $1, (v)
20222 + adcl $0, 4(v)
20223 + int $4
20224 +0:
20225 + _ASM_EXTABLE(0b, 0b)
20226 +#endif
20227 +
20228 +RET_ENDP
20229 +BEGIN(dec_unchecked)
20230 + subl $1, (v)
20231 + sbbl $0, 4(v)
20232 RET_ENDP
20233 #undef v
20234
20235 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20236 movl 4(v), %edx
20237 subl $1, %eax
20238 sbbl $0, %edx
20239 +
20240 +#ifdef CONFIG_PAX_REFCOUNT
20241 + into
20242 +1234:
20243 + _ASM_EXTABLE(1234b, 2f)
20244 +#endif
20245 +
20246 + movl %eax, (v)
20247 + movl %edx, 4(v)
20248 +
20249 +#ifdef CONFIG_PAX_REFCOUNT
20250 +2:
20251 +#endif
20252 +
20253 +RET_ENDP
20254 +BEGIN(dec_return_unchecked)
20255 + movl (v), %eax
20256 + movl 4(v), %edx
20257 + subl $1, %eax
20258 + sbbl $0, %edx
20259 movl %eax, (v)
20260 movl %edx, 4(v)
20261 RET_ENDP
20262 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20263 adcl %edx, %edi
20264 addl (v), %eax
20265 adcl 4(v), %edx
20266 +
20267 +#ifdef CONFIG_PAX_REFCOUNT
20268 + into
20269 +1234:
20270 + _ASM_EXTABLE(1234b, 2f)
20271 +#endif
20272 +
20273 cmpl %eax, %esi
20274 je 3f
20275 1:
20276 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20277 1:
20278 addl $1, %eax
20279 adcl $0, %edx
20280 +
20281 +#ifdef CONFIG_PAX_REFCOUNT
20282 + into
20283 +1234:
20284 + _ASM_EXTABLE(1234b, 2f)
20285 +#endif
20286 +
20287 movl %eax, (v)
20288 movl %edx, 4(v)
20289 movl $1, %eax
20290 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20291 movl 4(v), %edx
20292 subl $1, %eax
20293 sbbl $0, %edx
20294 +
20295 +#ifdef CONFIG_PAX_REFCOUNT
20296 + into
20297 +1234:
20298 + _ASM_EXTABLE(1234b, 1f)
20299 +#endif
20300 +
20301 js 1f
20302 movl %eax, (v)
20303 movl %edx, 4(v)
20304 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20305 index 391a083..d658e9f 100644
20306 --- a/arch/x86/lib/atomic64_cx8_32.S
20307 +++ b/arch/x86/lib/atomic64_cx8_32.S
20308 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20309 CFI_STARTPROC
20310
20311 read64 %ecx
20312 + pax_force_retaddr
20313 ret
20314 CFI_ENDPROC
20315 ENDPROC(atomic64_read_cx8)
20316
20317 +ENTRY(atomic64_read_unchecked_cx8)
20318 + CFI_STARTPROC
20319 +
20320 + read64 %ecx
20321 + pax_force_retaddr
20322 + ret
20323 + CFI_ENDPROC
20324 +ENDPROC(atomic64_read_unchecked_cx8)
20325 +
20326 ENTRY(atomic64_set_cx8)
20327 CFI_STARTPROC
20328
20329 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20330 cmpxchg8b (%esi)
20331 jne 1b
20332
20333 + pax_force_retaddr
20334 ret
20335 CFI_ENDPROC
20336 ENDPROC(atomic64_set_cx8)
20337
20338 +ENTRY(atomic64_set_unchecked_cx8)
20339 + CFI_STARTPROC
20340 +
20341 +1:
20342 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20343 + * are atomic on 586 and newer */
20344 + cmpxchg8b (%esi)
20345 + jne 1b
20346 +
20347 + pax_force_retaddr
20348 + ret
20349 + CFI_ENDPROC
20350 +ENDPROC(atomic64_set_unchecked_cx8)
20351 +
20352 ENTRY(atomic64_xchg_cx8)
20353 CFI_STARTPROC
20354
20355 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20356 cmpxchg8b (%esi)
20357 jne 1b
20358
20359 + pax_force_retaddr
20360 ret
20361 CFI_ENDPROC
20362 ENDPROC(atomic64_xchg_cx8)
20363
20364 -.macro addsub_return func ins insc
20365 -ENTRY(atomic64_\func\()_return_cx8)
20366 +.macro addsub_return func ins insc unchecked=""
20367 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20368 CFI_STARTPROC
20369 SAVE ebp
20370 SAVE ebx
20371 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20372 movl %edx, %ecx
20373 \ins\()l %esi, %ebx
20374 \insc\()l %edi, %ecx
20375 +
20376 +.ifb \unchecked
20377 +#ifdef CONFIG_PAX_REFCOUNT
20378 + into
20379 +2:
20380 + _ASM_EXTABLE(2b, 3f)
20381 +#endif
20382 +.endif
20383 +
20384 LOCK_PREFIX
20385 cmpxchg8b (%ebp)
20386 jne 1b
20387 -
20388 -10:
20389 movl %ebx, %eax
20390 movl %ecx, %edx
20391 +
20392 +.ifb \unchecked
20393 +#ifdef CONFIG_PAX_REFCOUNT
20394 +3:
20395 +#endif
20396 +.endif
20397 +
20398 RESTORE edi
20399 RESTORE esi
20400 RESTORE ebx
20401 RESTORE ebp
20402 + pax_force_retaddr
20403 ret
20404 CFI_ENDPROC
20405 -ENDPROC(atomic64_\func\()_return_cx8)
20406 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20407 .endm
20408
20409 addsub_return add add adc
20410 addsub_return sub sub sbb
20411 +addsub_return add add adc _unchecked
20412 +addsub_return sub sub sbb _unchecked
20413
20414 -.macro incdec_return func ins insc
20415 -ENTRY(atomic64_\func\()_return_cx8)
20416 +.macro incdec_return func ins insc unchecked
20417 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20418 CFI_STARTPROC
20419 SAVE ebx
20420
20421 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20422 movl %edx, %ecx
20423 \ins\()l $1, %ebx
20424 \insc\()l $0, %ecx
20425 +
20426 +.ifb \unchecked
20427 +#ifdef CONFIG_PAX_REFCOUNT
20428 + into
20429 +2:
20430 + _ASM_EXTABLE(2b, 3f)
20431 +#endif
20432 +.endif
20433 +
20434 LOCK_PREFIX
20435 cmpxchg8b (%esi)
20436 jne 1b
20437
20438 -10:
20439 movl %ebx, %eax
20440 movl %ecx, %edx
20441 +
20442 +.ifb \unchecked
20443 +#ifdef CONFIG_PAX_REFCOUNT
20444 +3:
20445 +#endif
20446 +.endif
20447 +
20448 RESTORE ebx
20449 + pax_force_retaddr
20450 ret
20451 CFI_ENDPROC
20452 -ENDPROC(atomic64_\func\()_return_cx8)
20453 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20454 .endm
20455
20456 incdec_return inc add adc
20457 incdec_return dec sub sbb
20458 +incdec_return inc add adc _unchecked
20459 +incdec_return dec sub sbb _unchecked
20460
20461 ENTRY(atomic64_dec_if_positive_cx8)
20462 CFI_STARTPROC
20463 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20464 movl %edx, %ecx
20465 subl $1, %ebx
20466 sbb $0, %ecx
20467 +
20468 +#ifdef CONFIG_PAX_REFCOUNT
20469 + into
20470 +1234:
20471 + _ASM_EXTABLE(1234b, 2f)
20472 +#endif
20473 +
20474 js 2f
20475 LOCK_PREFIX
20476 cmpxchg8b (%esi)
20477 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20478 movl %ebx, %eax
20479 movl %ecx, %edx
20480 RESTORE ebx
20481 + pax_force_retaddr
20482 ret
20483 CFI_ENDPROC
20484 ENDPROC(atomic64_dec_if_positive_cx8)
20485 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20486 movl %edx, %ecx
20487 addl %esi, %ebx
20488 adcl %edi, %ecx
20489 +
20490 +#ifdef CONFIG_PAX_REFCOUNT
20491 + into
20492 +1234:
20493 + _ASM_EXTABLE(1234b, 3f)
20494 +#endif
20495 +
20496 LOCK_PREFIX
20497 cmpxchg8b (%ebp)
20498 jne 1b
20499 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20500 CFI_ADJUST_CFA_OFFSET -8
20501 RESTORE ebx
20502 RESTORE ebp
20503 + pax_force_retaddr
20504 ret
20505 4:
20506 cmpl %edx, 4(%esp)
20507 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20508 movl %edx, %ecx
20509 addl $1, %ebx
20510 adcl $0, %ecx
20511 +
20512 +#ifdef CONFIG_PAX_REFCOUNT
20513 + into
20514 +1234:
20515 + _ASM_EXTABLE(1234b, 3f)
20516 +#endif
20517 +
20518 LOCK_PREFIX
20519 cmpxchg8b (%esi)
20520 jne 1b
20521 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20522 movl $1, %eax
20523 3:
20524 RESTORE ebx
20525 + pax_force_retaddr
20526 ret
20527 4:
20528 testl %edx, %edx
20529 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20530 index 78d16a5..fbcf666 100644
20531 --- a/arch/x86/lib/checksum_32.S
20532 +++ b/arch/x86/lib/checksum_32.S
20533 @@ -28,7 +28,8 @@
20534 #include <linux/linkage.h>
20535 #include <asm/dwarf2.h>
20536 #include <asm/errno.h>
20537 -
20538 +#include <asm/segment.h>
20539 +
20540 /*
20541 * computes a partial checksum, e.g. for TCP/UDP fragments
20542 */
20543 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20544
20545 #define ARGBASE 16
20546 #define FP 12
20547 -
20548 -ENTRY(csum_partial_copy_generic)
20549 +
20550 +ENTRY(csum_partial_copy_generic_to_user)
20551 CFI_STARTPROC
20552 +
20553 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20554 + pushl_cfi %gs
20555 + popl_cfi %es
20556 + jmp csum_partial_copy_generic
20557 +#endif
20558 +
20559 +ENTRY(csum_partial_copy_generic_from_user)
20560 +
20561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20562 + pushl_cfi %gs
20563 + popl_cfi %ds
20564 +#endif
20565 +
20566 +ENTRY(csum_partial_copy_generic)
20567 subl $4,%esp
20568 CFI_ADJUST_CFA_OFFSET 4
20569 pushl_cfi %edi
20570 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
20571 jmp 4f
20572 SRC(1: movw (%esi), %bx )
20573 addl $2, %esi
20574 -DST( movw %bx, (%edi) )
20575 +DST( movw %bx, %es:(%edi) )
20576 addl $2, %edi
20577 addw %bx, %ax
20578 adcl $0, %eax
20579 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
20580 SRC(1: movl (%esi), %ebx )
20581 SRC( movl 4(%esi), %edx )
20582 adcl %ebx, %eax
20583 -DST( movl %ebx, (%edi) )
20584 +DST( movl %ebx, %es:(%edi) )
20585 adcl %edx, %eax
20586 -DST( movl %edx, 4(%edi) )
20587 +DST( movl %edx, %es:4(%edi) )
20588
20589 SRC( movl 8(%esi), %ebx )
20590 SRC( movl 12(%esi), %edx )
20591 adcl %ebx, %eax
20592 -DST( movl %ebx, 8(%edi) )
20593 +DST( movl %ebx, %es:8(%edi) )
20594 adcl %edx, %eax
20595 -DST( movl %edx, 12(%edi) )
20596 +DST( movl %edx, %es:12(%edi) )
20597
20598 SRC( movl 16(%esi), %ebx )
20599 SRC( movl 20(%esi), %edx )
20600 adcl %ebx, %eax
20601 -DST( movl %ebx, 16(%edi) )
20602 +DST( movl %ebx, %es:16(%edi) )
20603 adcl %edx, %eax
20604 -DST( movl %edx, 20(%edi) )
20605 +DST( movl %edx, %es:20(%edi) )
20606
20607 SRC( movl 24(%esi), %ebx )
20608 SRC( movl 28(%esi), %edx )
20609 adcl %ebx, %eax
20610 -DST( movl %ebx, 24(%edi) )
20611 +DST( movl %ebx, %es:24(%edi) )
20612 adcl %edx, %eax
20613 -DST( movl %edx, 28(%edi) )
20614 +DST( movl %edx, %es:28(%edi) )
20615
20616 lea 32(%esi), %esi
20617 lea 32(%edi), %edi
20618 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
20619 shrl $2, %edx # This clears CF
20620 SRC(3: movl (%esi), %ebx )
20621 adcl %ebx, %eax
20622 -DST( movl %ebx, (%edi) )
20623 +DST( movl %ebx, %es:(%edi) )
20624 lea 4(%esi), %esi
20625 lea 4(%edi), %edi
20626 dec %edx
20627 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
20628 jb 5f
20629 SRC( movw (%esi), %cx )
20630 leal 2(%esi), %esi
20631 -DST( movw %cx, (%edi) )
20632 +DST( movw %cx, %es:(%edi) )
20633 leal 2(%edi), %edi
20634 je 6f
20635 shll $16,%ecx
20636 SRC(5: movb (%esi), %cl )
20637 -DST( movb %cl, (%edi) )
20638 +DST( movb %cl, %es:(%edi) )
20639 6: addl %ecx, %eax
20640 adcl $0, %eax
20641 7:
20642 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
20643
20644 6001:
20645 movl ARGBASE+20(%esp), %ebx # src_err_ptr
20646 - movl $-EFAULT, (%ebx)
20647 + movl $-EFAULT, %ss:(%ebx)
20648
20649 # zero the complete destination - computing the rest
20650 # is too much work
20651 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
20652
20653 6002:
20654 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20655 - movl $-EFAULT,(%ebx)
20656 + movl $-EFAULT,%ss:(%ebx)
20657 jmp 5000b
20658
20659 .previous
20660
20661 + pushl_cfi %ss
20662 + popl_cfi %ds
20663 + pushl_cfi %ss
20664 + popl_cfi %es
20665 popl_cfi %ebx
20666 CFI_RESTORE ebx
20667 popl_cfi %esi
20668 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
20669 popl_cfi %ecx # equivalent to addl $4,%esp
20670 ret
20671 CFI_ENDPROC
20672 -ENDPROC(csum_partial_copy_generic)
20673 +ENDPROC(csum_partial_copy_generic_to_user)
20674
20675 #else
20676
20677 /* Version for PentiumII/PPro */
20678
20679 #define ROUND1(x) \
20680 + nop; nop; nop; \
20681 SRC(movl x(%esi), %ebx ) ; \
20682 addl %ebx, %eax ; \
20683 - DST(movl %ebx, x(%edi) ) ;
20684 + DST(movl %ebx, %es:x(%edi)) ;
20685
20686 #define ROUND(x) \
20687 + nop; nop; nop; \
20688 SRC(movl x(%esi), %ebx ) ; \
20689 adcl %ebx, %eax ; \
20690 - DST(movl %ebx, x(%edi) ) ;
20691 + DST(movl %ebx, %es:x(%edi)) ;
20692
20693 #define ARGBASE 12
20694 -
20695 -ENTRY(csum_partial_copy_generic)
20696 +
20697 +ENTRY(csum_partial_copy_generic_to_user)
20698 CFI_STARTPROC
20699 +
20700 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20701 + pushl_cfi %gs
20702 + popl_cfi %es
20703 + jmp csum_partial_copy_generic
20704 +#endif
20705 +
20706 +ENTRY(csum_partial_copy_generic_from_user)
20707 +
20708 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20709 + pushl_cfi %gs
20710 + popl_cfi %ds
20711 +#endif
20712 +
20713 +ENTRY(csum_partial_copy_generic)
20714 pushl_cfi %ebx
20715 CFI_REL_OFFSET ebx, 0
20716 pushl_cfi %edi
20717 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
20718 subl %ebx, %edi
20719 lea -1(%esi),%edx
20720 andl $-32,%edx
20721 - lea 3f(%ebx,%ebx), %ebx
20722 + lea 3f(%ebx,%ebx,2), %ebx
20723 testl %esi, %esi
20724 jmp *%ebx
20725 1: addl $64,%esi
20726 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
20727 jb 5f
20728 SRC( movw (%esi), %dx )
20729 leal 2(%esi), %esi
20730 -DST( movw %dx, (%edi) )
20731 +DST( movw %dx, %es:(%edi) )
20732 leal 2(%edi), %edi
20733 je 6f
20734 shll $16,%edx
20735 5:
20736 SRC( movb (%esi), %dl )
20737 -DST( movb %dl, (%edi) )
20738 +DST( movb %dl, %es:(%edi) )
20739 6: addl %edx, %eax
20740 adcl $0, %eax
20741 7:
20742 .section .fixup, "ax"
20743 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
20744 - movl $-EFAULT, (%ebx)
20745 + movl $-EFAULT, %ss:(%ebx)
20746 # zero the complete destination (computing the rest is too much work)
20747 movl ARGBASE+8(%esp),%edi # dst
20748 movl ARGBASE+12(%esp),%ecx # len
20749 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
20750 rep; stosb
20751 jmp 7b
20752 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20753 - movl $-EFAULT, (%ebx)
20754 + movl $-EFAULT, %ss:(%ebx)
20755 jmp 7b
20756 .previous
20757
20758 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20759 + pushl_cfi %ss
20760 + popl_cfi %ds
20761 + pushl_cfi %ss
20762 + popl_cfi %es
20763 +#endif
20764 +
20765 popl_cfi %esi
20766 CFI_RESTORE esi
20767 popl_cfi %edi
20768 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
20769 CFI_RESTORE ebx
20770 ret
20771 CFI_ENDPROC
20772 -ENDPROC(csum_partial_copy_generic)
20773 +ENDPROC(csum_partial_copy_generic_to_user)
20774
20775 #undef ROUND
20776 #undef ROUND1
20777 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
20778 index f2145cf..cea889d 100644
20779 --- a/arch/x86/lib/clear_page_64.S
20780 +++ b/arch/x86/lib/clear_page_64.S
20781 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
20782 movl $4096/8,%ecx
20783 xorl %eax,%eax
20784 rep stosq
20785 + pax_force_retaddr
20786 ret
20787 CFI_ENDPROC
20788 ENDPROC(clear_page_c)
20789 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
20790 movl $4096,%ecx
20791 xorl %eax,%eax
20792 rep stosb
20793 + pax_force_retaddr
20794 ret
20795 CFI_ENDPROC
20796 ENDPROC(clear_page_c_e)
20797 @@ -43,6 +45,7 @@ ENTRY(clear_page)
20798 leaq 64(%rdi),%rdi
20799 jnz .Lloop
20800 nop
20801 + pax_force_retaddr
20802 ret
20803 CFI_ENDPROC
20804 .Lclear_page_end:
20805 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
20806
20807 #include <asm/cpufeature.h>
20808
20809 - .section .altinstr_replacement,"ax"
20810 + .section .altinstr_replacement,"a"
20811 1: .byte 0xeb /* jmp <disp8> */
20812 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
20813 2: .byte 0xeb /* jmp <disp8> */
20814 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
20815 index 1e572c5..2a162cd 100644
20816 --- a/arch/x86/lib/cmpxchg16b_emu.S
20817 +++ b/arch/x86/lib/cmpxchg16b_emu.S
20818 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
20819
20820 popf
20821 mov $1, %al
20822 + pax_force_retaddr
20823 ret
20824
20825 not_same:
20826 popf
20827 xor %al,%al
20828 + pax_force_retaddr
20829 ret
20830
20831 CFI_ENDPROC
20832 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
20833 index 01c805b..dccb07f 100644
20834 --- a/arch/x86/lib/copy_page_64.S
20835 +++ b/arch/x86/lib/copy_page_64.S
20836 @@ -9,6 +9,7 @@ copy_page_c:
20837 CFI_STARTPROC
20838 movl $4096/8,%ecx
20839 rep movsq
20840 + pax_force_retaddr
20841 ret
20842 CFI_ENDPROC
20843 ENDPROC(copy_page_c)
20844 @@ -39,7 +40,7 @@ ENTRY(copy_page)
20845 movq 16 (%rsi), %rdx
20846 movq 24 (%rsi), %r8
20847 movq 32 (%rsi), %r9
20848 - movq 40 (%rsi), %r10
20849 + movq 40 (%rsi), %r13
20850 movq 48 (%rsi), %r11
20851 movq 56 (%rsi), %r12
20852
20853 @@ -50,7 +51,7 @@ ENTRY(copy_page)
20854 movq %rdx, 16 (%rdi)
20855 movq %r8, 24 (%rdi)
20856 movq %r9, 32 (%rdi)
20857 - movq %r10, 40 (%rdi)
20858 + movq %r13, 40 (%rdi)
20859 movq %r11, 48 (%rdi)
20860 movq %r12, 56 (%rdi)
20861
20862 @@ -69,7 +70,7 @@ ENTRY(copy_page)
20863 movq 16 (%rsi), %rdx
20864 movq 24 (%rsi), %r8
20865 movq 32 (%rsi), %r9
20866 - movq 40 (%rsi), %r10
20867 + movq 40 (%rsi), %r13
20868 movq 48 (%rsi), %r11
20869 movq 56 (%rsi), %r12
20870
20871 @@ -78,7 +79,7 @@ ENTRY(copy_page)
20872 movq %rdx, 16 (%rdi)
20873 movq %r8, 24 (%rdi)
20874 movq %r9, 32 (%rdi)
20875 - movq %r10, 40 (%rdi)
20876 + movq %r13, 40 (%rdi)
20877 movq %r11, 48 (%rdi)
20878 movq %r12, 56 (%rdi)
20879
20880 @@ -95,6 +96,7 @@ ENTRY(copy_page)
20881 CFI_RESTORE r13
20882 addq $3*8,%rsp
20883 CFI_ADJUST_CFA_OFFSET -3*8
20884 + pax_force_retaddr
20885 ret
20886 .Lcopy_page_end:
20887 CFI_ENDPROC
20888 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
20889
20890 #include <asm/cpufeature.h>
20891
20892 - .section .altinstr_replacement,"ax"
20893 + .section .altinstr_replacement,"a"
20894 1: .byte 0xeb /* jmp <disp8> */
20895 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
20896 2:
20897 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
20898 index 0248402..821c786 100644
20899 --- a/arch/x86/lib/copy_user_64.S
20900 +++ b/arch/x86/lib/copy_user_64.S
20901 @@ -16,6 +16,7 @@
20902 #include <asm/thread_info.h>
20903 #include <asm/cpufeature.h>
20904 #include <asm/alternative-asm.h>
20905 +#include <asm/pgtable.h>
20906
20907 /*
20908 * By placing feature2 after feature1 in altinstructions section, we logically
20909 @@ -29,7 +30,7 @@
20910 .byte 0xe9 /* 32bit jump */
20911 .long \orig-1f /* by default jump to orig */
20912 1:
20913 - .section .altinstr_replacement,"ax"
20914 + .section .altinstr_replacement,"a"
20915 2: .byte 0xe9 /* near jump with 32bit immediate */
20916 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
20917 3: .byte 0xe9 /* near jump with 32bit immediate */
20918 @@ -71,47 +72,20 @@
20919 #endif
20920 .endm
20921
20922 -/* Standard copy_to_user with segment limit checking */
20923 -ENTRY(_copy_to_user)
20924 - CFI_STARTPROC
20925 - GET_THREAD_INFO(%rax)
20926 - movq %rdi,%rcx
20927 - addq %rdx,%rcx
20928 - jc bad_to_user
20929 - cmpq TI_addr_limit(%rax),%rcx
20930 - ja bad_to_user
20931 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20932 - copy_user_generic_unrolled,copy_user_generic_string, \
20933 - copy_user_enhanced_fast_string
20934 - CFI_ENDPROC
20935 -ENDPROC(_copy_to_user)
20936 -
20937 -/* Standard copy_from_user with segment limit checking */
20938 -ENTRY(_copy_from_user)
20939 - CFI_STARTPROC
20940 - GET_THREAD_INFO(%rax)
20941 - movq %rsi,%rcx
20942 - addq %rdx,%rcx
20943 - jc bad_from_user
20944 - cmpq TI_addr_limit(%rax),%rcx
20945 - ja bad_from_user
20946 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20947 - copy_user_generic_unrolled,copy_user_generic_string, \
20948 - copy_user_enhanced_fast_string
20949 - CFI_ENDPROC
20950 -ENDPROC(_copy_from_user)
20951 -
20952 .section .fixup,"ax"
20953 /* must zero dest */
20954 ENTRY(bad_from_user)
20955 bad_from_user:
20956 CFI_STARTPROC
20957 + testl %edx,%edx
20958 + js bad_to_user
20959 movl %edx,%ecx
20960 xorl %eax,%eax
20961 rep
20962 stosb
20963 bad_to_user:
20964 movl %edx,%eax
20965 + pax_force_retaddr
20966 ret
20967 CFI_ENDPROC
20968 ENDPROC(bad_from_user)
20969 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
20970 jz 17f
20971 1: movq (%rsi),%r8
20972 2: movq 1*8(%rsi),%r9
20973 -3: movq 2*8(%rsi),%r10
20974 +3: movq 2*8(%rsi),%rax
20975 4: movq 3*8(%rsi),%r11
20976 5: movq %r8,(%rdi)
20977 6: movq %r9,1*8(%rdi)
20978 -7: movq %r10,2*8(%rdi)
20979 +7: movq %rax,2*8(%rdi)
20980 8: movq %r11,3*8(%rdi)
20981 9: movq 4*8(%rsi),%r8
20982 10: movq 5*8(%rsi),%r9
20983 -11: movq 6*8(%rsi),%r10
20984 +11: movq 6*8(%rsi),%rax
20985 12: movq 7*8(%rsi),%r11
20986 13: movq %r8,4*8(%rdi)
20987 14: movq %r9,5*8(%rdi)
20988 -15: movq %r10,6*8(%rdi)
20989 +15: movq %rax,6*8(%rdi)
20990 16: movq %r11,7*8(%rdi)
20991 leaq 64(%rsi),%rsi
20992 leaq 64(%rdi),%rdi
20993 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
20994 decl %ecx
20995 jnz 21b
20996 23: xor %eax,%eax
20997 + pax_force_retaddr
20998 ret
20999
21000 .section .fixup,"ax"
21001 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21002 3: rep
21003 movsb
21004 4: xorl %eax,%eax
21005 + pax_force_retaddr
21006 ret
21007
21008 .section .fixup,"ax"
21009 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21010 1: rep
21011 movsb
21012 2: xorl %eax,%eax
21013 + pax_force_retaddr
21014 ret
21015
21016 .section .fixup,"ax"
21017 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21018 index cb0c112..e3a6895 100644
21019 --- a/arch/x86/lib/copy_user_nocache_64.S
21020 +++ b/arch/x86/lib/copy_user_nocache_64.S
21021 @@ -8,12 +8,14 @@
21022
21023 #include <linux/linkage.h>
21024 #include <asm/dwarf2.h>
21025 +#include <asm/alternative-asm.h>
21026
21027 #define FIX_ALIGNMENT 1
21028
21029 #include <asm/current.h>
21030 #include <asm/asm-offsets.h>
21031 #include <asm/thread_info.h>
21032 +#include <asm/pgtable.h>
21033
21034 .macro ALIGN_DESTINATION
21035 #ifdef FIX_ALIGNMENT
21036 @@ -50,6 +52,15 @@
21037 */
21038 ENTRY(__copy_user_nocache)
21039 CFI_STARTPROC
21040 +
21041 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21042 + mov $PAX_USER_SHADOW_BASE,%rcx
21043 + cmp %rcx,%rsi
21044 + jae 1f
21045 + add %rcx,%rsi
21046 +1:
21047 +#endif
21048 +
21049 cmpl $8,%edx
21050 jb 20f /* less then 8 bytes, go to byte copy loop */
21051 ALIGN_DESTINATION
21052 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21053 jz 17f
21054 1: movq (%rsi),%r8
21055 2: movq 1*8(%rsi),%r9
21056 -3: movq 2*8(%rsi),%r10
21057 +3: movq 2*8(%rsi),%rax
21058 4: movq 3*8(%rsi),%r11
21059 5: movnti %r8,(%rdi)
21060 6: movnti %r9,1*8(%rdi)
21061 -7: movnti %r10,2*8(%rdi)
21062 +7: movnti %rax,2*8(%rdi)
21063 8: movnti %r11,3*8(%rdi)
21064 9: movq 4*8(%rsi),%r8
21065 10: movq 5*8(%rsi),%r9
21066 -11: movq 6*8(%rsi),%r10
21067 +11: movq 6*8(%rsi),%rax
21068 12: movq 7*8(%rsi),%r11
21069 13: movnti %r8,4*8(%rdi)
21070 14: movnti %r9,5*8(%rdi)
21071 -15: movnti %r10,6*8(%rdi)
21072 +15: movnti %rax,6*8(%rdi)
21073 16: movnti %r11,7*8(%rdi)
21074 leaq 64(%rsi),%rsi
21075 leaq 64(%rdi),%rdi
21076 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21077 jnz 21b
21078 23: xorl %eax,%eax
21079 sfence
21080 + pax_force_retaddr
21081 ret
21082
21083 .section .fixup,"ax"
21084 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21085 index fb903b7..c92b7f7 100644
21086 --- a/arch/x86/lib/csum-copy_64.S
21087 +++ b/arch/x86/lib/csum-copy_64.S
21088 @@ -8,6 +8,7 @@
21089 #include <linux/linkage.h>
21090 #include <asm/dwarf2.h>
21091 #include <asm/errno.h>
21092 +#include <asm/alternative-asm.h>
21093
21094 /*
21095 * Checksum copy with exception handling.
21096 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21097 CFI_RESTORE rbp
21098 addq $7*8, %rsp
21099 CFI_ADJUST_CFA_OFFSET -7*8
21100 + pax_force_retaddr 0, 1
21101 ret
21102 CFI_RESTORE_STATE
21103
21104 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21105 index 459b58a..9570bc7 100644
21106 --- a/arch/x86/lib/csum-wrappers_64.c
21107 +++ b/arch/x86/lib/csum-wrappers_64.c
21108 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21109 len -= 2;
21110 }
21111 }
21112 - isum = csum_partial_copy_generic((__force const void *)src,
21113 +
21114 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21115 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21116 + src += PAX_USER_SHADOW_BASE;
21117 +#endif
21118 +
21119 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21120 dst, len, isum, errp, NULL);
21121 if (unlikely(*errp))
21122 goto out_err;
21123 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21124 }
21125
21126 *errp = 0;
21127 - return csum_partial_copy_generic(src, (void __force *)dst,
21128 +
21129 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21130 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21131 + dst += PAX_USER_SHADOW_BASE;
21132 +#endif
21133 +
21134 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21135 len, isum, NULL, errp);
21136 }
21137 EXPORT_SYMBOL(csum_partial_copy_to_user);
21138 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21139 index 51f1504..ddac4c1 100644
21140 --- a/arch/x86/lib/getuser.S
21141 +++ b/arch/x86/lib/getuser.S
21142 @@ -33,15 +33,38 @@
21143 #include <asm/asm-offsets.h>
21144 #include <asm/thread_info.h>
21145 #include <asm/asm.h>
21146 +#include <asm/segment.h>
21147 +#include <asm/pgtable.h>
21148 +#include <asm/alternative-asm.h>
21149 +
21150 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21151 +#define __copyuser_seg gs;
21152 +#else
21153 +#define __copyuser_seg
21154 +#endif
21155
21156 .text
21157 ENTRY(__get_user_1)
21158 CFI_STARTPROC
21159 +
21160 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21161 GET_THREAD_INFO(%_ASM_DX)
21162 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21163 jae bad_get_user
21164 -1: movzb (%_ASM_AX),%edx
21165 +
21166 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21167 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21168 + cmp %_ASM_DX,%_ASM_AX
21169 + jae 1234f
21170 + add %_ASM_DX,%_ASM_AX
21171 +1234:
21172 +#endif
21173 +
21174 +#endif
21175 +
21176 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21177 xor %eax,%eax
21178 + pax_force_retaddr
21179 ret
21180 CFI_ENDPROC
21181 ENDPROC(__get_user_1)
21182 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21183 ENTRY(__get_user_2)
21184 CFI_STARTPROC
21185 add $1,%_ASM_AX
21186 +
21187 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21188 jc bad_get_user
21189 GET_THREAD_INFO(%_ASM_DX)
21190 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21191 jae bad_get_user
21192 -2: movzwl -1(%_ASM_AX),%edx
21193 +
21194 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21195 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21196 + cmp %_ASM_DX,%_ASM_AX
21197 + jae 1234f
21198 + add %_ASM_DX,%_ASM_AX
21199 +1234:
21200 +#endif
21201 +
21202 +#endif
21203 +
21204 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21205 xor %eax,%eax
21206 + pax_force_retaddr
21207 ret
21208 CFI_ENDPROC
21209 ENDPROC(__get_user_2)
21210 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21211 ENTRY(__get_user_4)
21212 CFI_STARTPROC
21213 add $3,%_ASM_AX
21214 +
21215 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21216 jc bad_get_user
21217 GET_THREAD_INFO(%_ASM_DX)
21218 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21219 jae bad_get_user
21220 -3: mov -3(%_ASM_AX),%edx
21221 +
21222 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21223 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21224 + cmp %_ASM_DX,%_ASM_AX
21225 + jae 1234f
21226 + add %_ASM_DX,%_ASM_AX
21227 +1234:
21228 +#endif
21229 +
21230 +#endif
21231 +
21232 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21233 xor %eax,%eax
21234 + pax_force_retaddr
21235 ret
21236 CFI_ENDPROC
21237 ENDPROC(__get_user_4)
21238 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21239 GET_THREAD_INFO(%_ASM_DX)
21240 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21241 jae bad_get_user
21242 +
21243 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21244 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21245 + cmp %_ASM_DX,%_ASM_AX
21246 + jae 1234f
21247 + add %_ASM_DX,%_ASM_AX
21248 +1234:
21249 +#endif
21250 +
21251 4: movq -7(%_ASM_AX),%_ASM_DX
21252 xor %eax,%eax
21253 + pax_force_retaddr
21254 ret
21255 CFI_ENDPROC
21256 ENDPROC(__get_user_8)
21257 @@ -91,6 +152,7 @@ bad_get_user:
21258 CFI_STARTPROC
21259 xor %edx,%edx
21260 mov $(-EFAULT),%_ASM_AX
21261 + pax_force_retaddr
21262 ret
21263 CFI_ENDPROC
21264 END(bad_get_user)
21265 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21266 index 374562e..a75830b 100644
21267 --- a/arch/x86/lib/insn.c
21268 +++ b/arch/x86/lib/insn.c
21269 @@ -21,6 +21,11 @@
21270 #include <linux/string.h>
21271 #include <asm/inat.h>
21272 #include <asm/insn.h>
21273 +#ifdef __KERNEL__
21274 +#include <asm/pgtable_types.h>
21275 +#else
21276 +#define ktla_ktva(addr) addr
21277 +#endif
21278
21279 /* Verify next sizeof(t) bytes can be on the same instruction */
21280 #define validate_next(t, insn, n) \
21281 @@ -49,8 +54,8 @@
21282 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21283 {
21284 memset(insn, 0, sizeof(*insn));
21285 - insn->kaddr = kaddr;
21286 - insn->next_byte = kaddr;
21287 + insn->kaddr = ktla_ktva(kaddr);
21288 + insn->next_byte = ktla_ktva(kaddr);
21289 insn->x86_64 = x86_64 ? 1 : 0;
21290 insn->opnd_bytes = 4;
21291 if (x86_64)
21292 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21293 index 05a95e7..326f2fa 100644
21294 --- a/arch/x86/lib/iomap_copy_64.S
21295 +++ b/arch/x86/lib/iomap_copy_64.S
21296 @@ -17,6 +17,7 @@
21297
21298 #include <linux/linkage.h>
21299 #include <asm/dwarf2.h>
21300 +#include <asm/alternative-asm.h>
21301
21302 /*
21303 * override generic version in lib/iomap_copy.c
21304 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21305 CFI_STARTPROC
21306 movl %edx,%ecx
21307 rep movsd
21308 + pax_force_retaddr
21309 ret
21310 CFI_ENDPROC
21311 ENDPROC(__iowrite32_copy)
21312 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21313 index efbf2a0..8893637 100644
21314 --- a/arch/x86/lib/memcpy_64.S
21315 +++ b/arch/x86/lib/memcpy_64.S
21316 @@ -34,6 +34,7 @@
21317 rep movsq
21318 movl %edx, %ecx
21319 rep movsb
21320 + pax_force_retaddr
21321 ret
21322 .Lmemcpy_e:
21323 .previous
21324 @@ -51,6 +52,7 @@
21325
21326 movl %edx, %ecx
21327 rep movsb
21328 + pax_force_retaddr
21329 ret
21330 .Lmemcpy_e_e:
21331 .previous
21332 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21333 */
21334 movq 0*8(%rsi), %r8
21335 movq 1*8(%rsi), %r9
21336 - movq 2*8(%rsi), %r10
21337 + movq 2*8(%rsi), %rcx
21338 movq 3*8(%rsi), %r11
21339 leaq 4*8(%rsi), %rsi
21340
21341 movq %r8, 0*8(%rdi)
21342 movq %r9, 1*8(%rdi)
21343 - movq %r10, 2*8(%rdi)
21344 + movq %rcx, 2*8(%rdi)
21345 movq %r11, 3*8(%rdi)
21346 leaq 4*8(%rdi), %rdi
21347 jae .Lcopy_forward_loop
21348 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21349 subq $0x20, %rdx
21350 movq -1*8(%rsi), %r8
21351 movq -2*8(%rsi), %r9
21352 - movq -3*8(%rsi), %r10
21353 + movq -3*8(%rsi), %rcx
21354 movq -4*8(%rsi), %r11
21355 leaq -4*8(%rsi), %rsi
21356 movq %r8, -1*8(%rdi)
21357 movq %r9, -2*8(%rdi)
21358 - movq %r10, -3*8(%rdi)
21359 + movq %rcx, -3*8(%rdi)
21360 movq %r11, -4*8(%rdi)
21361 leaq -4*8(%rdi), %rdi
21362 jae .Lcopy_backward_loop
21363 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21364 */
21365 movq 0*8(%rsi), %r8
21366 movq 1*8(%rsi), %r9
21367 - movq -2*8(%rsi, %rdx), %r10
21368 + movq -2*8(%rsi, %rdx), %rcx
21369 movq -1*8(%rsi, %rdx), %r11
21370 movq %r8, 0*8(%rdi)
21371 movq %r9, 1*8(%rdi)
21372 - movq %r10, -2*8(%rdi, %rdx)
21373 + movq %rcx, -2*8(%rdi, %rdx)
21374 movq %r11, -1*8(%rdi, %rdx)
21375 + pax_force_retaddr
21376 retq
21377 .p2align 4
21378 .Lless_16bytes:
21379 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21380 movq -1*8(%rsi, %rdx), %r9
21381 movq %r8, 0*8(%rdi)
21382 movq %r9, -1*8(%rdi, %rdx)
21383 + pax_force_retaddr
21384 retq
21385 .p2align 4
21386 .Lless_8bytes:
21387 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21388 movl -4(%rsi, %rdx), %r8d
21389 movl %ecx, (%rdi)
21390 movl %r8d, -4(%rdi, %rdx)
21391 + pax_force_retaddr
21392 retq
21393 .p2align 4
21394 .Lless_3bytes:
21395 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21396 jnz .Lloop_1
21397
21398 .Lend:
21399 + pax_force_retaddr
21400 retq
21401 CFI_ENDPROC
21402 ENDPROC(memcpy)
21403 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21404 index ee16461..c39c199 100644
21405 --- a/arch/x86/lib/memmove_64.S
21406 +++ b/arch/x86/lib/memmove_64.S
21407 @@ -61,13 +61,13 @@ ENTRY(memmove)
21408 5:
21409 sub $0x20, %rdx
21410 movq 0*8(%rsi), %r11
21411 - movq 1*8(%rsi), %r10
21412 + movq 1*8(%rsi), %rcx
21413 movq 2*8(%rsi), %r9
21414 movq 3*8(%rsi), %r8
21415 leaq 4*8(%rsi), %rsi
21416
21417 movq %r11, 0*8(%rdi)
21418 - movq %r10, 1*8(%rdi)
21419 + movq %rcx, 1*8(%rdi)
21420 movq %r9, 2*8(%rdi)
21421 movq %r8, 3*8(%rdi)
21422 leaq 4*8(%rdi), %rdi
21423 @@ -81,10 +81,10 @@ ENTRY(memmove)
21424 4:
21425 movq %rdx, %rcx
21426 movq -8(%rsi, %rdx), %r11
21427 - lea -8(%rdi, %rdx), %r10
21428 + lea -8(%rdi, %rdx), %r9
21429 shrq $3, %rcx
21430 rep movsq
21431 - movq %r11, (%r10)
21432 + movq %r11, (%r9)
21433 jmp 13f
21434 .Lmemmove_end_forward:
21435
21436 @@ -95,14 +95,14 @@ ENTRY(memmove)
21437 7:
21438 movq %rdx, %rcx
21439 movq (%rsi), %r11
21440 - movq %rdi, %r10
21441 + movq %rdi, %r9
21442 leaq -8(%rsi, %rdx), %rsi
21443 leaq -8(%rdi, %rdx), %rdi
21444 shrq $3, %rcx
21445 std
21446 rep movsq
21447 cld
21448 - movq %r11, (%r10)
21449 + movq %r11, (%r9)
21450 jmp 13f
21451
21452 /*
21453 @@ -127,13 +127,13 @@ ENTRY(memmove)
21454 8:
21455 subq $0x20, %rdx
21456 movq -1*8(%rsi), %r11
21457 - movq -2*8(%rsi), %r10
21458 + movq -2*8(%rsi), %rcx
21459 movq -3*8(%rsi), %r9
21460 movq -4*8(%rsi), %r8
21461 leaq -4*8(%rsi), %rsi
21462
21463 movq %r11, -1*8(%rdi)
21464 - movq %r10, -2*8(%rdi)
21465 + movq %rcx, -2*8(%rdi)
21466 movq %r9, -3*8(%rdi)
21467 movq %r8, -4*8(%rdi)
21468 leaq -4*8(%rdi), %rdi
21469 @@ -151,11 +151,11 @@ ENTRY(memmove)
21470 * Move data from 16 bytes to 31 bytes.
21471 */
21472 movq 0*8(%rsi), %r11
21473 - movq 1*8(%rsi), %r10
21474 + movq 1*8(%rsi), %rcx
21475 movq -2*8(%rsi, %rdx), %r9
21476 movq -1*8(%rsi, %rdx), %r8
21477 movq %r11, 0*8(%rdi)
21478 - movq %r10, 1*8(%rdi)
21479 + movq %rcx, 1*8(%rdi)
21480 movq %r9, -2*8(%rdi, %rdx)
21481 movq %r8, -1*8(%rdi, %rdx)
21482 jmp 13f
21483 @@ -167,9 +167,9 @@ ENTRY(memmove)
21484 * Move data from 8 bytes to 15 bytes.
21485 */
21486 movq 0*8(%rsi), %r11
21487 - movq -1*8(%rsi, %rdx), %r10
21488 + movq -1*8(%rsi, %rdx), %r9
21489 movq %r11, 0*8(%rdi)
21490 - movq %r10, -1*8(%rdi, %rdx)
21491 + movq %r9, -1*8(%rdi, %rdx)
21492 jmp 13f
21493 10:
21494 cmpq $4, %rdx
21495 @@ -178,9 +178,9 @@ ENTRY(memmove)
21496 * Move data from 4 bytes to 7 bytes.
21497 */
21498 movl (%rsi), %r11d
21499 - movl -4(%rsi, %rdx), %r10d
21500 + movl -4(%rsi, %rdx), %r9d
21501 movl %r11d, (%rdi)
21502 - movl %r10d, -4(%rdi, %rdx)
21503 + movl %r9d, -4(%rdi, %rdx)
21504 jmp 13f
21505 11:
21506 cmp $2, %rdx
21507 @@ -189,9 +189,9 @@ ENTRY(memmove)
21508 * Move data from 2 bytes to 3 bytes.
21509 */
21510 movw (%rsi), %r11w
21511 - movw -2(%rsi, %rdx), %r10w
21512 + movw -2(%rsi, %rdx), %r9w
21513 movw %r11w, (%rdi)
21514 - movw %r10w, -2(%rdi, %rdx)
21515 + movw %r9w, -2(%rdi, %rdx)
21516 jmp 13f
21517 12:
21518 cmp $1, %rdx
21519 @@ -202,6 +202,7 @@ ENTRY(memmove)
21520 movb (%rsi), %r11b
21521 movb %r11b, (%rdi)
21522 13:
21523 + pax_force_retaddr
21524 retq
21525 CFI_ENDPROC
21526
21527 @@ -210,6 +211,7 @@ ENTRY(memmove)
21528 /* Forward moving data. */
21529 movq %rdx, %rcx
21530 rep movsb
21531 + pax_force_retaddr
21532 retq
21533 .Lmemmove_end_forward_efs:
21534 .previous
21535 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21536 index 79bd454..dff325a 100644
21537 --- a/arch/x86/lib/memset_64.S
21538 +++ b/arch/x86/lib/memset_64.S
21539 @@ -31,6 +31,7 @@
21540 movl %r8d,%ecx
21541 rep stosb
21542 movq %r9,%rax
21543 + pax_force_retaddr
21544 ret
21545 .Lmemset_e:
21546 .previous
21547 @@ -53,6 +54,7 @@
21548 movl %edx,%ecx
21549 rep stosb
21550 movq %r9,%rax
21551 + pax_force_retaddr
21552 ret
21553 .Lmemset_e_e:
21554 .previous
21555 @@ -60,13 +62,13 @@
21556 ENTRY(memset)
21557 ENTRY(__memset)
21558 CFI_STARTPROC
21559 - movq %rdi,%r10
21560 movq %rdx,%r11
21561
21562 /* expand byte value */
21563 movzbl %sil,%ecx
21564 movabs $0x0101010101010101,%rax
21565 mul %rcx /* with rax, clobbers rdx */
21566 + movq %rdi,%rdx
21567
21568 /* align dst */
21569 movl %edi,%r9d
21570 @@ -120,7 +122,8 @@ ENTRY(__memset)
21571 jnz .Lloop_1
21572
21573 .Lende:
21574 - movq %r10,%rax
21575 + movq %rdx,%rax
21576 + pax_force_retaddr
21577 ret
21578
21579 CFI_RESTORE_STATE
21580 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21581 index c9f2d9b..e7fd2c0 100644
21582 --- a/arch/x86/lib/mmx_32.c
21583 +++ b/arch/x86/lib/mmx_32.c
21584 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21585 {
21586 void *p;
21587 int i;
21588 + unsigned long cr0;
21589
21590 if (unlikely(in_interrupt()))
21591 return __memcpy(to, from, len);
21592 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21593 kernel_fpu_begin();
21594
21595 __asm__ __volatile__ (
21596 - "1: prefetch (%0)\n" /* This set is 28 bytes */
21597 - " prefetch 64(%0)\n"
21598 - " prefetch 128(%0)\n"
21599 - " prefetch 192(%0)\n"
21600 - " prefetch 256(%0)\n"
21601 + "1: prefetch (%1)\n" /* This set is 28 bytes */
21602 + " prefetch 64(%1)\n"
21603 + " prefetch 128(%1)\n"
21604 + " prefetch 192(%1)\n"
21605 + " prefetch 256(%1)\n"
21606 "2: \n"
21607 ".section .fixup, \"ax\"\n"
21608 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21609 + "3: \n"
21610 +
21611 +#ifdef CONFIG_PAX_KERNEXEC
21612 + " movl %%cr0, %0\n"
21613 + " movl %0, %%eax\n"
21614 + " andl $0xFFFEFFFF, %%eax\n"
21615 + " movl %%eax, %%cr0\n"
21616 +#endif
21617 +
21618 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21619 +
21620 +#ifdef CONFIG_PAX_KERNEXEC
21621 + " movl %0, %%cr0\n"
21622 +#endif
21623 +
21624 " jmp 2b\n"
21625 ".previous\n"
21626 _ASM_EXTABLE(1b, 3b)
21627 - : : "r" (from));
21628 + : "=&r" (cr0) : "r" (from) : "ax");
21629
21630 for ( ; i > 5; i--) {
21631 __asm__ __volatile__ (
21632 - "1: prefetch 320(%0)\n"
21633 - "2: movq (%0), %%mm0\n"
21634 - " movq 8(%0), %%mm1\n"
21635 - " movq 16(%0), %%mm2\n"
21636 - " movq 24(%0), %%mm3\n"
21637 - " movq %%mm0, (%1)\n"
21638 - " movq %%mm1, 8(%1)\n"
21639 - " movq %%mm2, 16(%1)\n"
21640 - " movq %%mm3, 24(%1)\n"
21641 - " movq 32(%0), %%mm0\n"
21642 - " movq 40(%0), %%mm1\n"
21643 - " movq 48(%0), %%mm2\n"
21644 - " movq 56(%0), %%mm3\n"
21645 - " movq %%mm0, 32(%1)\n"
21646 - " movq %%mm1, 40(%1)\n"
21647 - " movq %%mm2, 48(%1)\n"
21648 - " movq %%mm3, 56(%1)\n"
21649 + "1: prefetch 320(%1)\n"
21650 + "2: movq (%1), %%mm0\n"
21651 + " movq 8(%1), %%mm1\n"
21652 + " movq 16(%1), %%mm2\n"
21653 + " movq 24(%1), %%mm3\n"
21654 + " movq %%mm0, (%2)\n"
21655 + " movq %%mm1, 8(%2)\n"
21656 + " movq %%mm2, 16(%2)\n"
21657 + " movq %%mm3, 24(%2)\n"
21658 + " movq 32(%1), %%mm0\n"
21659 + " movq 40(%1), %%mm1\n"
21660 + " movq 48(%1), %%mm2\n"
21661 + " movq 56(%1), %%mm3\n"
21662 + " movq %%mm0, 32(%2)\n"
21663 + " movq %%mm1, 40(%2)\n"
21664 + " movq %%mm2, 48(%2)\n"
21665 + " movq %%mm3, 56(%2)\n"
21666 ".section .fixup, \"ax\"\n"
21667 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21668 + "3:\n"
21669 +
21670 +#ifdef CONFIG_PAX_KERNEXEC
21671 + " movl %%cr0, %0\n"
21672 + " movl %0, %%eax\n"
21673 + " andl $0xFFFEFFFF, %%eax\n"
21674 + " movl %%eax, %%cr0\n"
21675 +#endif
21676 +
21677 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21678 +
21679 +#ifdef CONFIG_PAX_KERNEXEC
21680 + " movl %0, %%cr0\n"
21681 +#endif
21682 +
21683 " jmp 2b\n"
21684 ".previous\n"
21685 _ASM_EXTABLE(1b, 3b)
21686 - : : "r" (from), "r" (to) : "memory");
21687 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21688
21689 from += 64;
21690 to += 64;
21691 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
21692 static void fast_copy_page(void *to, void *from)
21693 {
21694 int i;
21695 + unsigned long cr0;
21696
21697 kernel_fpu_begin();
21698
21699 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
21700 * but that is for later. -AV
21701 */
21702 __asm__ __volatile__(
21703 - "1: prefetch (%0)\n"
21704 - " prefetch 64(%0)\n"
21705 - " prefetch 128(%0)\n"
21706 - " prefetch 192(%0)\n"
21707 - " prefetch 256(%0)\n"
21708 + "1: prefetch (%1)\n"
21709 + " prefetch 64(%1)\n"
21710 + " prefetch 128(%1)\n"
21711 + " prefetch 192(%1)\n"
21712 + " prefetch 256(%1)\n"
21713 "2: \n"
21714 ".section .fixup, \"ax\"\n"
21715 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21716 + "3: \n"
21717 +
21718 +#ifdef CONFIG_PAX_KERNEXEC
21719 + " movl %%cr0, %0\n"
21720 + " movl %0, %%eax\n"
21721 + " andl $0xFFFEFFFF, %%eax\n"
21722 + " movl %%eax, %%cr0\n"
21723 +#endif
21724 +
21725 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21726 +
21727 +#ifdef CONFIG_PAX_KERNEXEC
21728 + " movl %0, %%cr0\n"
21729 +#endif
21730 +
21731 " jmp 2b\n"
21732 ".previous\n"
21733 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
21734 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21735
21736 for (i = 0; i < (4096-320)/64; i++) {
21737 __asm__ __volatile__ (
21738 - "1: prefetch 320(%0)\n"
21739 - "2: movq (%0), %%mm0\n"
21740 - " movntq %%mm0, (%1)\n"
21741 - " movq 8(%0), %%mm1\n"
21742 - " movntq %%mm1, 8(%1)\n"
21743 - " movq 16(%0), %%mm2\n"
21744 - " movntq %%mm2, 16(%1)\n"
21745 - " movq 24(%0), %%mm3\n"
21746 - " movntq %%mm3, 24(%1)\n"
21747 - " movq 32(%0), %%mm4\n"
21748 - " movntq %%mm4, 32(%1)\n"
21749 - " movq 40(%0), %%mm5\n"
21750 - " movntq %%mm5, 40(%1)\n"
21751 - " movq 48(%0), %%mm6\n"
21752 - " movntq %%mm6, 48(%1)\n"
21753 - " movq 56(%0), %%mm7\n"
21754 - " movntq %%mm7, 56(%1)\n"
21755 + "1: prefetch 320(%1)\n"
21756 + "2: movq (%1), %%mm0\n"
21757 + " movntq %%mm0, (%2)\n"
21758 + " movq 8(%1), %%mm1\n"
21759 + " movntq %%mm1, 8(%2)\n"
21760 + " movq 16(%1), %%mm2\n"
21761 + " movntq %%mm2, 16(%2)\n"
21762 + " movq 24(%1), %%mm3\n"
21763 + " movntq %%mm3, 24(%2)\n"
21764 + " movq 32(%1), %%mm4\n"
21765 + " movntq %%mm4, 32(%2)\n"
21766 + " movq 40(%1), %%mm5\n"
21767 + " movntq %%mm5, 40(%2)\n"
21768 + " movq 48(%1), %%mm6\n"
21769 + " movntq %%mm6, 48(%2)\n"
21770 + " movq 56(%1), %%mm7\n"
21771 + " movntq %%mm7, 56(%2)\n"
21772 ".section .fixup, \"ax\"\n"
21773 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21774 + "3:\n"
21775 +
21776 +#ifdef CONFIG_PAX_KERNEXEC
21777 + " movl %%cr0, %0\n"
21778 + " movl %0, %%eax\n"
21779 + " andl $0xFFFEFFFF, %%eax\n"
21780 + " movl %%eax, %%cr0\n"
21781 +#endif
21782 +
21783 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21784 +
21785 +#ifdef CONFIG_PAX_KERNEXEC
21786 + " movl %0, %%cr0\n"
21787 +#endif
21788 +
21789 " jmp 2b\n"
21790 ".previous\n"
21791 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
21792 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21793
21794 from += 64;
21795 to += 64;
21796 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
21797 static void fast_copy_page(void *to, void *from)
21798 {
21799 int i;
21800 + unsigned long cr0;
21801
21802 kernel_fpu_begin();
21803
21804 __asm__ __volatile__ (
21805 - "1: prefetch (%0)\n"
21806 - " prefetch 64(%0)\n"
21807 - " prefetch 128(%0)\n"
21808 - " prefetch 192(%0)\n"
21809 - " prefetch 256(%0)\n"
21810 + "1: prefetch (%1)\n"
21811 + " prefetch 64(%1)\n"
21812 + " prefetch 128(%1)\n"
21813 + " prefetch 192(%1)\n"
21814 + " prefetch 256(%1)\n"
21815 "2: \n"
21816 ".section .fixup, \"ax\"\n"
21817 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21818 + "3: \n"
21819 +
21820 +#ifdef CONFIG_PAX_KERNEXEC
21821 + " movl %%cr0, %0\n"
21822 + " movl %0, %%eax\n"
21823 + " andl $0xFFFEFFFF, %%eax\n"
21824 + " movl %%eax, %%cr0\n"
21825 +#endif
21826 +
21827 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21828 +
21829 +#ifdef CONFIG_PAX_KERNEXEC
21830 + " movl %0, %%cr0\n"
21831 +#endif
21832 +
21833 " jmp 2b\n"
21834 ".previous\n"
21835 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
21836 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21837
21838 for (i = 0; i < 4096/64; i++) {
21839 __asm__ __volatile__ (
21840 - "1: prefetch 320(%0)\n"
21841 - "2: movq (%0), %%mm0\n"
21842 - " movq 8(%0), %%mm1\n"
21843 - " movq 16(%0), %%mm2\n"
21844 - " movq 24(%0), %%mm3\n"
21845 - " movq %%mm0, (%1)\n"
21846 - " movq %%mm1, 8(%1)\n"
21847 - " movq %%mm2, 16(%1)\n"
21848 - " movq %%mm3, 24(%1)\n"
21849 - " movq 32(%0), %%mm0\n"
21850 - " movq 40(%0), %%mm1\n"
21851 - " movq 48(%0), %%mm2\n"
21852 - " movq 56(%0), %%mm3\n"
21853 - " movq %%mm0, 32(%1)\n"
21854 - " movq %%mm1, 40(%1)\n"
21855 - " movq %%mm2, 48(%1)\n"
21856 - " movq %%mm3, 56(%1)\n"
21857 + "1: prefetch 320(%1)\n"
21858 + "2: movq (%1), %%mm0\n"
21859 + " movq 8(%1), %%mm1\n"
21860 + " movq 16(%1), %%mm2\n"
21861 + " movq 24(%1), %%mm3\n"
21862 + " movq %%mm0, (%2)\n"
21863 + " movq %%mm1, 8(%2)\n"
21864 + " movq %%mm2, 16(%2)\n"
21865 + " movq %%mm3, 24(%2)\n"
21866 + " movq 32(%1), %%mm0\n"
21867 + " movq 40(%1), %%mm1\n"
21868 + " movq 48(%1), %%mm2\n"
21869 + " movq 56(%1), %%mm3\n"
21870 + " movq %%mm0, 32(%2)\n"
21871 + " movq %%mm1, 40(%2)\n"
21872 + " movq %%mm2, 48(%2)\n"
21873 + " movq %%mm3, 56(%2)\n"
21874 ".section .fixup, \"ax\"\n"
21875 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21876 + "3:\n"
21877 +
21878 +#ifdef CONFIG_PAX_KERNEXEC
21879 + " movl %%cr0, %0\n"
21880 + " movl %0, %%eax\n"
21881 + " andl $0xFFFEFFFF, %%eax\n"
21882 + " movl %%eax, %%cr0\n"
21883 +#endif
21884 +
21885 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21886 +
21887 +#ifdef CONFIG_PAX_KERNEXEC
21888 + " movl %0, %%cr0\n"
21889 +#endif
21890 +
21891 " jmp 2b\n"
21892 ".previous\n"
21893 _ASM_EXTABLE(1b, 3b)
21894 - : : "r" (from), "r" (to) : "memory");
21895 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21896
21897 from += 64;
21898 to += 64;
21899 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
21900 index 69fa106..adda88b 100644
21901 --- a/arch/x86/lib/msr-reg.S
21902 +++ b/arch/x86/lib/msr-reg.S
21903 @@ -3,6 +3,7 @@
21904 #include <asm/dwarf2.h>
21905 #include <asm/asm.h>
21906 #include <asm/msr.h>
21907 +#include <asm/alternative-asm.h>
21908
21909 #ifdef CONFIG_X86_64
21910 /*
21911 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
21912 CFI_STARTPROC
21913 pushq_cfi %rbx
21914 pushq_cfi %rbp
21915 - movq %rdi, %r10 /* Save pointer */
21916 + movq %rdi, %r9 /* Save pointer */
21917 xorl %r11d, %r11d /* Return value */
21918 movl (%rdi), %eax
21919 movl 4(%rdi), %ecx
21920 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
21921 movl 28(%rdi), %edi
21922 CFI_REMEMBER_STATE
21923 1: \op
21924 -2: movl %eax, (%r10)
21925 +2: movl %eax, (%r9)
21926 movl %r11d, %eax /* Return value */
21927 - movl %ecx, 4(%r10)
21928 - movl %edx, 8(%r10)
21929 - movl %ebx, 12(%r10)
21930 - movl %ebp, 20(%r10)
21931 - movl %esi, 24(%r10)
21932 - movl %edi, 28(%r10)
21933 + movl %ecx, 4(%r9)
21934 + movl %edx, 8(%r9)
21935 + movl %ebx, 12(%r9)
21936 + movl %ebp, 20(%r9)
21937 + movl %esi, 24(%r9)
21938 + movl %edi, 28(%r9)
21939 popq_cfi %rbp
21940 popq_cfi %rbx
21941 + pax_force_retaddr
21942 ret
21943 3:
21944 CFI_RESTORE_STATE
21945 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
21946 index 36b0d15..d381858 100644
21947 --- a/arch/x86/lib/putuser.S
21948 +++ b/arch/x86/lib/putuser.S
21949 @@ -15,7 +15,9 @@
21950 #include <asm/thread_info.h>
21951 #include <asm/errno.h>
21952 #include <asm/asm.h>
21953 -
21954 +#include <asm/segment.h>
21955 +#include <asm/pgtable.h>
21956 +#include <asm/alternative-asm.h>
21957
21958 /*
21959 * __put_user_X
21960 @@ -29,52 +31,119 @@
21961 * as they get called from within inline assembly.
21962 */
21963
21964 -#define ENTER CFI_STARTPROC ; \
21965 - GET_THREAD_INFO(%_ASM_BX)
21966 -#define EXIT ret ; \
21967 +#define ENTER CFI_STARTPROC
21968 +#define EXIT pax_force_retaddr; ret ; \
21969 CFI_ENDPROC
21970
21971 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21972 +#define _DEST %_ASM_CX,%_ASM_BX
21973 +#else
21974 +#define _DEST %_ASM_CX
21975 +#endif
21976 +
21977 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21978 +#define __copyuser_seg gs;
21979 +#else
21980 +#define __copyuser_seg
21981 +#endif
21982 +
21983 .text
21984 ENTRY(__put_user_1)
21985 ENTER
21986 +
21987 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21988 + GET_THREAD_INFO(%_ASM_BX)
21989 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
21990 jae bad_put_user
21991 -1: movb %al,(%_ASM_CX)
21992 +
21993 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21994 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21995 + cmp %_ASM_BX,%_ASM_CX
21996 + jb 1234f
21997 + xor %ebx,%ebx
21998 +1234:
21999 +#endif
22000 +
22001 +#endif
22002 +
22003 +1: __copyuser_seg movb %al,(_DEST)
22004 xor %eax,%eax
22005 EXIT
22006 ENDPROC(__put_user_1)
22007
22008 ENTRY(__put_user_2)
22009 ENTER
22010 +
22011 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22012 + GET_THREAD_INFO(%_ASM_BX)
22013 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22014 sub $1,%_ASM_BX
22015 cmp %_ASM_BX,%_ASM_CX
22016 jae bad_put_user
22017 -2: movw %ax,(%_ASM_CX)
22018 +
22019 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22020 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22021 + cmp %_ASM_BX,%_ASM_CX
22022 + jb 1234f
22023 + xor %ebx,%ebx
22024 +1234:
22025 +#endif
22026 +
22027 +#endif
22028 +
22029 +2: __copyuser_seg movw %ax,(_DEST)
22030 xor %eax,%eax
22031 EXIT
22032 ENDPROC(__put_user_2)
22033
22034 ENTRY(__put_user_4)
22035 ENTER
22036 +
22037 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22038 + GET_THREAD_INFO(%_ASM_BX)
22039 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22040 sub $3,%_ASM_BX
22041 cmp %_ASM_BX,%_ASM_CX
22042 jae bad_put_user
22043 -3: movl %eax,(%_ASM_CX)
22044 +
22045 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22046 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22047 + cmp %_ASM_BX,%_ASM_CX
22048 + jb 1234f
22049 + xor %ebx,%ebx
22050 +1234:
22051 +#endif
22052 +
22053 +#endif
22054 +
22055 +3: __copyuser_seg movl %eax,(_DEST)
22056 xor %eax,%eax
22057 EXIT
22058 ENDPROC(__put_user_4)
22059
22060 ENTRY(__put_user_8)
22061 ENTER
22062 +
22063 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22064 + GET_THREAD_INFO(%_ASM_BX)
22065 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22066 sub $7,%_ASM_BX
22067 cmp %_ASM_BX,%_ASM_CX
22068 jae bad_put_user
22069 -4: mov %_ASM_AX,(%_ASM_CX)
22070 +
22071 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22072 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22073 + cmp %_ASM_BX,%_ASM_CX
22074 + jb 1234f
22075 + xor %ebx,%ebx
22076 +1234:
22077 +#endif
22078 +
22079 +#endif
22080 +
22081 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22082 #ifdef CONFIG_X86_32
22083 -5: movl %edx,4(%_ASM_CX)
22084 +5: __copyuser_seg movl %edx,4(_DEST)
22085 #endif
22086 xor %eax,%eax
22087 EXIT
22088 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22089 index 1cad221..de671ee 100644
22090 --- a/arch/x86/lib/rwlock.S
22091 +++ b/arch/x86/lib/rwlock.S
22092 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22093 FRAME
22094 0: LOCK_PREFIX
22095 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22096 +
22097 +#ifdef CONFIG_PAX_REFCOUNT
22098 + jno 1234f
22099 + LOCK_PREFIX
22100 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22101 + int $4
22102 +1234:
22103 + _ASM_EXTABLE(1234b, 1234b)
22104 +#endif
22105 +
22106 1: rep; nop
22107 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22108 jne 1b
22109 LOCK_PREFIX
22110 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22111 +
22112 +#ifdef CONFIG_PAX_REFCOUNT
22113 + jno 1234f
22114 + LOCK_PREFIX
22115 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22116 + int $4
22117 +1234:
22118 + _ASM_EXTABLE(1234b, 1234b)
22119 +#endif
22120 +
22121 jnz 0b
22122 ENDFRAME
22123 + pax_force_retaddr
22124 ret
22125 CFI_ENDPROC
22126 END(__write_lock_failed)
22127 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22128 FRAME
22129 0: LOCK_PREFIX
22130 READ_LOCK_SIZE(inc) (%__lock_ptr)
22131 +
22132 +#ifdef CONFIG_PAX_REFCOUNT
22133 + jno 1234f
22134 + LOCK_PREFIX
22135 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22136 + int $4
22137 +1234:
22138 + _ASM_EXTABLE(1234b, 1234b)
22139 +#endif
22140 +
22141 1: rep; nop
22142 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22143 js 1b
22144 LOCK_PREFIX
22145 READ_LOCK_SIZE(dec) (%__lock_ptr)
22146 +
22147 +#ifdef CONFIG_PAX_REFCOUNT
22148 + jno 1234f
22149 + LOCK_PREFIX
22150 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22151 + int $4
22152 +1234:
22153 + _ASM_EXTABLE(1234b, 1234b)
22154 +#endif
22155 +
22156 js 0b
22157 ENDFRAME
22158 + pax_force_retaddr
22159 ret
22160 CFI_ENDPROC
22161 END(__read_lock_failed)
22162 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22163 index 5dff5f0..cadebf4 100644
22164 --- a/arch/x86/lib/rwsem.S
22165 +++ b/arch/x86/lib/rwsem.S
22166 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22167 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22168 CFI_RESTORE __ASM_REG(dx)
22169 restore_common_regs
22170 + pax_force_retaddr
22171 ret
22172 CFI_ENDPROC
22173 ENDPROC(call_rwsem_down_read_failed)
22174 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22175 movq %rax,%rdi
22176 call rwsem_down_write_failed
22177 restore_common_regs
22178 + pax_force_retaddr
22179 ret
22180 CFI_ENDPROC
22181 ENDPROC(call_rwsem_down_write_failed)
22182 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22183 movq %rax,%rdi
22184 call rwsem_wake
22185 restore_common_regs
22186 -1: ret
22187 +1: pax_force_retaddr
22188 + ret
22189 CFI_ENDPROC
22190 ENDPROC(call_rwsem_wake)
22191
22192 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22193 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22194 CFI_RESTORE __ASM_REG(dx)
22195 restore_common_regs
22196 + pax_force_retaddr
22197 ret
22198 CFI_ENDPROC
22199 ENDPROC(call_rwsem_downgrade_wake)
22200 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22201 index a63efd6..ccecad8 100644
22202 --- a/arch/x86/lib/thunk_64.S
22203 +++ b/arch/x86/lib/thunk_64.S
22204 @@ -8,6 +8,7 @@
22205 #include <linux/linkage.h>
22206 #include <asm/dwarf2.h>
22207 #include <asm/calling.h>
22208 +#include <asm/alternative-asm.h>
22209
22210 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22211 .macro THUNK name, func, put_ret_addr_in_rdi=0
22212 @@ -41,5 +42,6 @@
22213 SAVE_ARGS
22214 restore:
22215 RESTORE_ARGS
22216 + pax_force_retaddr
22217 ret
22218 CFI_ENDPROC
22219 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22220 index e218d5d..35679b4 100644
22221 --- a/arch/x86/lib/usercopy_32.c
22222 +++ b/arch/x86/lib/usercopy_32.c
22223 @@ -43,7 +43,7 @@ do { \
22224 __asm__ __volatile__( \
22225 " testl %1,%1\n" \
22226 " jz 2f\n" \
22227 - "0: lodsb\n" \
22228 + "0: "__copyuser_seg"lodsb\n" \
22229 " stosb\n" \
22230 " testb %%al,%%al\n" \
22231 " jz 1f\n" \
22232 @@ -128,10 +128,12 @@ do { \
22233 int __d0; \
22234 might_fault(); \
22235 __asm__ __volatile__( \
22236 + __COPYUSER_SET_ES \
22237 "0: rep; stosl\n" \
22238 " movl %2,%0\n" \
22239 "1: rep; stosb\n" \
22240 "2:\n" \
22241 + __COPYUSER_RESTORE_ES \
22242 ".section .fixup,\"ax\"\n" \
22243 "3: lea 0(%2,%0,4),%0\n" \
22244 " jmp 2b\n" \
22245 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22246 might_fault();
22247
22248 __asm__ __volatile__(
22249 + __COPYUSER_SET_ES
22250 " testl %0, %0\n"
22251 " jz 3f\n"
22252 " andl %0,%%ecx\n"
22253 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22254 " subl %%ecx,%0\n"
22255 " addl %0,%%eax\n"
22256 "1:\n"
22257 + __COPYUSER_RESTORE_ES
22258 ".section .fixup,\"ax\"\n"
22259 "2: xorl %%eax,%%eax\n"
22260 " jmp 1b\n"
22261 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22262
22263 #ifdef CONFIG_X86_INTEL_USERCOPY
22264 static unsigned long
22265 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22266 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22267 {
22268 int d0, d1;
22269 __asm__ __volatile__(
22270 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22271 " .align 2,0x90\n"
22272 "3: movl 0(%4), %%eax\n"
22273 "4: movl 4(%4), %%edx\n"
22274 - "5: movl %%eax, 0(%3)\n"
22275 - "6: movl %%edx, 4(%3)\n"
22276 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22277 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22278 "7: movl 8(%4), %%eax\n"
22279 "8: movl 12(%4),%%edx\n"
22280 - "9: movl %%eax, 8(%3)\n"
22281 - "10: movl %%edx, 12(%3)\n"
22282 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22283 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22284 "11: movl 16(%4), %%eax\n"
22285 "12: movl 20(%4), %%edx\n"
22286 - "13: movl %%eax, 16(%3)\n"
22287 - "14: movl %%edx, 20(%3)\n"
22288 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22289 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22290 "15: movl 24(%4), %%eax\n"
22291 "16: movl 28(%4), %%edx\n"
22292 - "17: movl %%eax, 24(%3)\n"
22293 - "18: movl %%edx, 28(%3)\n"
22294 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22295 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22296 "19: movl 32(%4), %%eax\n"
22297 "20: movl 36(%4), %%edx\n"
22298 - "21: movl %%eax, 32(%3)\n"
22299 - "22: movl %%edx, 36(%3)\n"
22300 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22301 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22302 "23: movl 40(%4), %%eax\n"
22303 "24: movl 44(%4), %%edx\n"
22304 - "25: movl %%eax, 40(%3)\n"
22305 - "26: movl %%edx, 44(%3)\n"
22306 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22307 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22308 "27: movl 48(%4), %%eax\n"
22309 "28: movl 52(%4), %%edx\n"
22310 - "29: movl %%eax, 48(%3)\n"
22311 - "30: movl %%edx, 52(%3)\n"
22312 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22313 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22314 "31: movl 56(%4), %%eax\n"
22315 "32: movl 60(%4), %%edx\n"
22316 - "33: movl %%eax, 56(%3)\n"
22317 - "34: movl %%edx, 60(%3)\n"
22318 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22319 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22320 " addl $-64, %0\n"
22321 " addl $64, %4\n"
22322 " addl $64, %3\n"
22323 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22324 " shrl $2, %0\n"
22325 " andl $3, %%eax\n"
22326 " cld\n"
22327 + __COPYUSER_SET_ES
22328 "99: rep; movsl\n"
22329 "36: movl %%eax, %0\n"
22330 "37: rep; movsb\n"
22331 "100:\n"
22332 + __COPYUSER_RESTORE_ES
22333 + ".section .fixup,\"ax\"\n"
22334 + "101: lea 0(%%eax,%0,4),%0\n"
22335 + " jmp 100b\n"
22336 + ".previous\n"
22337 + ".section __ex_table,\"a\"\n"
22338 + " .align 4\n"
22339 + " .long 1b,100b\n"
22340 + " .long 2b,100b\n"
22341 + " .long 3b,100b\n"
22342 + " .long 4b,100b\n"
22343 + " .long 5b,100b\n"
22344 + " .long 6b,100b\n"
22345 + " .long 7b,100b\n"
22346 + " .long 8b,100b\n"
22347 + " .long 9b,100b\n"
22348 + " .long 10b,100b\n"
22349 + " .long 11b,100b\n"
22350 + " .long 12b,100b\n"
22351 + " .long 13b,100b\n"
22352 + " .long 14b,100b\n"
22353 + " .long 15b,100b\n"
22354 + " .long 16b,100b\n"
22355 + " .long 17b,100b\n"
22356 + " .long 18b,100b\n"
22357 + " .long 19b,100b\n"
22358 + " .long 20b,100b\n"
22359 + " .long 21b,100b\n"
22360 + " .long 22b,100b\n"
22361 + " .long 23b,100b\n"
22362 + " .long 24b,100b\n"
22363 + " .long 25b,100b\n"
22364 + " .long 26b,100b\n"
22365 + " .long 27b,100b\n"
22366 + " .long 28b,100b\n"
22367 + " .long 29b,100b\n"
22368 + " .long 30b,100b\n"
22369 + " .long 31b,100b\n"
22370 + " .long 32b,100b\n"
22371 + " .long 33b,100b\n"
22372 + " .long 34b,100b\n"
22373 + " .long 35b,100b\n"
22374 + " .long 36b,100b\n"
22375 + " .long 37b,100b\n"
22376 + " .long 99b,101b\n"
22377 + ".previous"
22378 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22379 + : "1"(to), "2"(from), "0"(size)
22380 + : "eax", "edx", "memory");
22381 + return size;
22382 +}
22383 +
22384 +static unsigned long
22385 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22386 +{
22387 + int d0, d1;
22388 + __asm__ __volatile__(
22389 + " .align 2,0x90\n"
22390 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22391 + " cmpl $67, %0\n"
22392 + " jbe 3f\n"
22393 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22394 + " .align 2,0x90\n"
22395 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22396 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22397 + "5: movl %%eax, 0(%3)\n"
22398 + "6: movl %%edx, 4(%3)\n"
22399 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22400 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22401 + "9: movl %%eax, 8(%3)\n"
22402 + "10: movl %%edx, 12(%3)\n"
22403 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22404 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22405 + "13: movl %%eax, 16(%3)\n"
22406 + "14: movl %%edx, 20(%3)\n"
22407 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22408 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22409 + "17: movl %%eax, 24(%3)\n"
22410 + "18: movl %%edx, 28(%3)\n"
22411 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22412 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22413 + "21: movl %%eax, 32(%3)\n"
22414 + "22: movl %%edx, 36(%3)\n"
22415 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22416 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22417 + "25: movl %%eax, 40(%3)\n"
22418 + "26: movl %%edx, 44(%3)\n"
22419 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22420 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22421 + "29: movl %%eax, 48(%3)\n"
22422 + "30: movl %%edx, 52(%3)\n"
22423 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22424 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22425 + "33: movl %%eax, 56(%3)\n"
22426 + "34: movl %%edx, 60(%3)\n"
22427 + " addl $-64, %0\n"
22428 + " addl $64, %4\n"
22429 + " addl $64, %3\n"
22430 + " cmpl $63, %0\n"
22431 + " ja 1b\n"
22432 + "35: movl %0, %%eax\n"
22433 + " shrl $2, %0\n"
22434 + " andl $3, %%eax\n"
22435 + " cld\n"
22436 + "99: rep; "__copyuser_seg" movsl\n"
22437 + "36: movl %%eax, %0\n"
22438 + "37: rep; "__copyuser_seg" movsb\n"
22439 + "100:\n"
22440 ".section .fixup,\"ax\"\n"
22441 "101: lea 0(%%eax,%0,4),%0\n"
22442 " jmp 100b\n"
22443 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22444 int d0, d1;
22445 __asm__ __volatile__(
22446 " .align 2,0x90\n"
22447 - "0: movl 32(%4), %%eax\n"
22448 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22449 " cmpl $67, %0\n"
22450 " jbe 2f\n"
22451 - "1: movl 64(%4), %%eax\n"
22452 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22453 " .align 2,0x90\n"
22454 - "2: movl 0(%4), %%eax\n"
22455 - "21: movl 4(%4), %%edx\n"
22456 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22457 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22458 " movl %%eax, 0(%3)\n"
22459 " movl %%edx, 4(%3)\n"
22460 - "3: movl 8(%4), %%eax\n"
22461 - "31: movl 12(%4),%%edx\n"
22462 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22463 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22464 " movl %%eax, 8(%3)\n"
22465 " movl %%edx, 12(%3)\n"
22466 - "4: movl 16(%4), %%eax\n"
22467 - "41: movl 20(%4), %%edx\n"
22468 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22469 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22470 " movl %%eax, 16(%3)\n"
22471 " movl %%edx, 20(%3)\n"
22472 - "10: movl 24(%4), %%eax\n"
22473 - "51: movl 28(%4), %%edx\n"
22474 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22475 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22476 " movl %%eax, 24(%3)\n"
22477 " movl %%edx, 28(%3)\n"
22478 - "11: movl 32(%4), %%eax\n"
22479 - "61: movl 36(%4), %%edx\n"
22480 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22481 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22482 " movl %%eax, 32(%3)\n"
22483 " movl %%edx, 36(%3)\n"
22484 - "12: movl 40(%4), %%eax\n"
22485 - "71: movl 44(%4), %%edx\n"
22486 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22487 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22488 " movl %%eax, 40(%3)\n"
22489 " movl %%edx, 44(%3)\n"
22490 - "13: movl 48(%4), %%eax\n"
22491 - "81: movl 52(%4), %%edx\n"
22492 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22493 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22494 " movl %%eax, 48(%3)\n"
22495 " movl %%edx, 52(%3)\n"
22496 - "14: movl 56(%4), %%eax\n"
22497 - "91: movl 60(%4), %%edx\n"
22498 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22499 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22500 " movl %%eax, 56(%3)\n"
22501 " movl %%edx, 60(%3)\n"
22502 " addl $-64, %0\n"
22503 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22504 " shrl $2, %0\n"
22505 " andl $3, %%eax\n"
22506 " cld\n"
22507 - "6: rep; movsl\n"
22508 + "6: rep; "__copyuser_seg" movsl\n"
22509 " movl %%eax,%0\n"
22510 - "7: rep; movsb\n"
22511 + "7: rep; "__copyuser_seg" movsb\n"
22512 "8:\n"
22513 ".section .fixup,\"ax\"\n"
22514 "9: lea 0(%%eax,%0,4),%0\n"
22515 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22516
22517 __asm__ __volatile__(
22518 " .align 2,0x90\n"
22519 - "0: movl 32(%4), %%eax\n"
22520 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22521 " cmpl $67, %0\n"
22522 " jbe 2f\n"
22523 - "1: movl 64(%4), %%eax\n"
22524 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22525 " .align 2,0x90\n"
22526 - "2: movl 0(%4), %%eax\n"
22527 - "21: movl 4(%4), %%edx\n"
22528 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22529 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22530 " movnti %%eax, 0(%3)\n"
22531 " movnti %%edx, 4(%3)\n"
22532 - "3: movl 8(%4), %%eax\n"
22533 - "31: movl 12(%4),%%edx\n"
22534 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22535 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22536 " movnti %%eax, 8(%3)\n"
22537 " movnti %%edx, 12(%3)\n"
22538 - "4: movl 16(%4), %%eax\n"
22539 - "41: movl 20(%4), %%edx\n"
22540 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22541 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22542 " movnti %%eax, 16(%3)\n"
22543 " movnti %%edx, 20(%3)\n"
22544 - "10: movl 24(%4), %%eax\n"
22545 - "51: movl 28(%4), %%edx\n"
22546 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22547 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22548 " movnti %%eax, 24(%3)\n"
22549 " movnti %%edx, 28(%3)\n"
22550 - "11: movl 32(%4), %%eax\n"
22551 - "61: movl 36(%4), %%edx\n"
22552 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22553 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22554 " movnti %%eax, 32(%3)\n"
22555 " movnti %%edx, 36(%3)\n"
22556 - "12: movl 40(%4), %%eax\n"
22557 - "71: movl 44(%4), %%edx\n"
22558 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22559 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22560 " movnti %%eax, 40(%3)\n"
22561 " movnti %%edx, 44(%3)\n"
22562 - "13: movl 48(%4), %%eax\n"
22563 - "81: movl 52(%4), %%edx\n"
22564 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22565 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22566 " movnti %%eax, 48(%3)\n"
22567 " movnti %%edx, 52(%3)\n"
22568 - "14: movl 56(%4), %%eax\n"
22569 - "91: movl 60(%4), %%edx\n"
22570 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22571 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22572 " movnti %%eax, 56(%3)\n"
22573 " movnti %%edx, 60(%3)\n"
22574 " addl $-64, %0\n"
22575 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22576 " shrl $2, %0\n"
22577 " andl $3, %%eax\n"
22578 " cld\n"
22579 - "6: rep; movsl\n"
22580 + "6: rep; "__copyuser_seg" movsl\n"
22581 " movl %%eax,%0\n"
22582 - "7: rep; movsb\n"
22583 + "7: rep; "__copyuser_seg" movsb\n"
22584 "8:\n"
22585 ".section .fixup,\"ax\"\n"
22586 "9: lea 0(%%eax,%0,4),%0\n"
22587 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
22588
22589 __asm__ __volatile__(
22590 " .align 2,0x90\n"
22591 - "0: movl 32(%4), %%eax\n"
22592 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22593 " cmpl $67, %0\n"
22594 " jbe 2f\n"
22595 - "1: movl 64(%4), %%eax\n"
22596 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22597 " .align 2,0x90\n"
22598 - "2: movl 0(%4), %%eax\n"
22599 - "21: movl 4(%4), %%edx\n"
22600 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22601 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22602 " movnti %%eax, 0(%3)\n"
22603 " movnti %%edx, 4(%3)\n"
22604 - "3: movl 8(%4), %%eax\n"
22605 - "31: movl 12(%4),%%edx\n"
22606 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22607 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22608 " movnti %%eax, 8(%3)\n"
22609 " movnti %%edx, 12(%3)\n"
22610 - "4: movl 16(%4), %%eax\n"
22611 - "41: movl 20(%4), %%edx\n"
22612 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22613 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22614 " movnti %%eax, 16(%3)\n"
22615 " movnti %%edx, 20(%3)\n"
22616 - "10: movl 24(%4), %%eax\n"
22617 - "51: movl 28(%4), %%edx\n"
22618 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22619 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22620 " movnti %%eax, 24(%3)\n"
22621 " movnti %%edx, 28(%3)\n"
22622 - "11: movl 32(%4), %%eax\n"
22623 - "61: movl 36(%4), %%edx\n"
22624 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22625 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22626 " movnti %%eax, 32(%3)\n"
22627 " movnti %%edx, 36(%3)\n"
22628 - "12: movl 40(%4), %%eax\n"
22629 - "71: movl 44(%4), %%edx\n"
22630 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22631 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22632 " movnti %%eax, 40(%3)\n"
22633 " movnti %%edx, 44(%3)\n"
22634 - "13: movl 48(%4), %%eax\n"
22635 - "81: movl 52(%4), %%edx\n"
22636 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22637 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22638 " movnti %%eax, 48(%3)\n"
22639 " movnti %%edx, 52(%3)\n"
22640 - "14: movl 56(%4), %%eax\n"
22641 - "91: movl 60(%4), %%edx\n"
22642 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22643 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22644 " movnti %%eax, 56(%3)\n"
22645 " movnti %%edx, 60(%3)\n"
22646 " addl $-64, %0\n"
22647 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
22648 " shrl $2, %0\n"
22649 " andl $3, %%eax\n"
22650 " cld\n"
22651 - "6: rep; movsl\n"
22652 + "6: rep; "__copyuser_seg" movsl\n"
22653 " movl %%eax,%0\n"
22654 - "7: rep; movsb\n"
22655 + "7: rep; "__copyuser_seg" movsb\n"
22656 "8:\n"
22657 ".section .fixup,\"ax\"\n"
22658 "9: lea 0(%%eax,%0,4),%0\n"
22659 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
22660 */
22661 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
22662 unsigned long size);
22663 -unsigned long __copy_user_intel(void __user *to, const void *from,
22664 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
22665 + unsigned long size);
22666 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
22667 unsigned long size);
22668 unsigned long __copy_user_zeroing_intel_nocache(void *to,
22669 const void __user *from, unsigned long size);
22670 #endif /* CONFIG_X86_INTEL_USERCOPY */
22671
22672 /* Generic arbitrary sized copy. */
22673 -#define __copy_user(to, from, size) \
22674 +#define __copy_user(to, from, size, prefix, set, restore) \
22675 do { \
22676 int __d0, __d1, __d2; \
22677 __asm__ __volatile__( \
22678 + set \
22679 " cmp $7,%0\n" \
22680 " jbe 1f\n" \
22681 " movl %1,%0\n" \
22682 " negl %0\n" \
22683 " andl $7,%0\n" \
22684 " subl %0,%3\n" \
22685 - "4: rep; movsb\n" \
22686 + "4: rep; "prefix"movsb\n" \
22687 " movl %3,%0\n" \
22688 " shrl $2,%0\n" \
22689 " andl $3,%3\n" \
22690 " .align 2,0x90\n" \
22691 - "0: rep; movsl\n" \
22692 + "0: rep; "prefix"movsl\n" \
22693 " movl %3,%0\n" \
22694 - "1: rep; movsb\n" \
22695 + "1: rep; "prefix"movsb\n" \
22696 "2:\n" \
22697 + restore \
22698 ".section .fixup,\"ax\"\n" \
22699 "5: addl %3,%0\n" \
22700 " jmp 2b\n" \
22701 @@ -682,14 +799,14 @@ do { \
22702 " negl %0\n" \
22703 " andl $7,%0\n" \
22704 " subl %0,%3\n" \
22705 - "4: rep; movsb\n" \
22706 + "4: rep; "__copyuser_seg"movsb\n" \
22707 " movl %3,%0\n" \
22708 " shrl $2,%0\n" \
22709 " andl $3,%3\n" \
22710 " .align 2,0x90\n" \
22711 - "0: rep; movsl\n" \
22712 + "0: rep; "__copyuser_seg"movsl\n" \
22713 " movl %3,%0\n" \
22714 - "1: rep; movsb\n" \
22715 + "1: rep; "__copyuser_seg"movsb\n" \
22716 "2:\n" \
22717 ".section .fixup,\"ax\"\n" \
22718 "5: addl %3,%0\n" \
22719 @@ -775,9 +892,9 @@ survive:
22720 }
22721 #endif
22722 if (movsl_is_ok(to, from, n))
22723 - __copy_user(to, from, n);
22724 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
22725 else
22726 - n = __copy_user_intel(to, from, n);
22727 + n = __generic_copy_to_user_intel(to, from, n);
22728 return n;
22729 }
22730 EXPORT_SYMBOL(__copy_to_user_ll);
22731 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
22732 unsigned long n)
22733 {
22734 if (movsl_is_ok(to, from, n))
22735 - __copy_user(to, from, n);
22736 + __copy_user(to, from, n, __copyuser_seg, "", "");
22737 else
22738 - n = __copy_user_intel((void __user *)to,
22739 - (const void *)from, n);
22740 + n = __generic_copy_from_user_intel(to, from, n);
22741 return n;
22742 }
22743 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
22744 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
22745 if (n > 64 && cpu_has_xmm2)
22746 n = __copy_user_intel_nocache(to, from, n);
22747 else
22748 - __copy_user(to, from, n);
22749 + __copy_user(to, from, n, __copyuser_seg, "", "");
22750 #else
22751 - __copy_user(to, from, n);
22752 + __copy_user(to, from, n, __copyuser_seg, "", "");
22753 #endif
22754 return n;
22755 }
22756 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
22757
22758 -/**
22759 - * copy_to_user: - Copy a block of data into user space.
22760 - * @to: Destination address, in user space.
22761 - * @from: Source address, in kernel space.
22762 - * @n: Number of bytes to copy.
22763 - *
22764 - * Context: User context only. This function may sleep.
22765 - *
22766 - * Copy data from kernel space to user space.
22767 - *
22768 - * Returns number of bytes that could not be copied.
22769 - * On success, this will be zero.
22770 - */
22771 -unsigned long
22772 -copy_to_user(void __user *to, const void *from, unsigned long n)
22773 -{
22774 - if (access_ok(VERIFY_WRITE, to, n))
22775 - n = __copy_to_user(to, from, n);
22776 - return n;
22777 -}
22778 -EXPORT_SYMBOL(copy_to_user);
22779 -
22780 -/**
22781 - * copy_from_user: - Copy a block of data from user space.
22782 - * @to: Destination address, in kernel space.
22783 - * @from: Source address, in user space.
22784 - * @n: Number of bytes to copy.
22785 - *
22786 - * Context: User context only. This function may sleep.
22787 - *
22788 - * Copy data from user space to kernel space.
22789 - *
22790 - * Returns number of bytes that could not be copied.
22791 - * On success, this will be zero.
22792 - *
22793 - * If some data could not be copied, this function will pad the copied
22794 - * data to the requested size using zero bytes.
22795 - */
22796 -unsigned long
22797 -_copy_from_user(void *to, const void __user *from, unsigned long n)
22798 -{
22799 - if (access_ok(VERIFY_READ, from, n))
22800 - n = __copy_from_user(to, from, n);
22801 - else
22802 - memset(to, 0, n);
22803 - return n;
22804 -}
22805 -EXPORT_SYMBOL(_copy_from_user);
22806 -
22807 void copy_from_user_overflow(void)
22808 {
22809 WARN(1, "Buffer overflow detected!\n");
22810 }
22811 EXPORT_SYMBOL(copy_from_user_overflow);
22812 +
22813 +void copy_to_user_overflow(void)
22814 +{
22815 + WARN(1, "Buffer overflow detected!\n");
22816 +}
22817 +EXPORT_SYMBOL(copy_to_user_overflow);
22818 +
22819 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22820 +void __set_fs(mm_segment_t x)
22821 +{
22822 + switch (x.seg) {
22823 + case 0:
22824 + loadsegment(gs, 0);
22825 + break;
22826 + case TASK_SIZE_MAX:
22827 + loadsegment(gs, __USER_DS);
22828 + break;
22829 + case -1UL:
22830 + loadsegment(gs, __KERNEL_DS);
22831 + break;
22832 + default:
22833 + BUG();
22834 + }
22835 + return;
22836 +}
22837 +EXPORT_SYMBOL(__set_fs);
22838 +
22839 +void set_fs(mm_segment_t x)
22840 +{
22841 + current_thread_info()->addr_limit = x;
22842 + __set_fs(x);
22843 +}
22844 +EXPORT_SYMBOL(set_fs);
22845 +#endif
22846 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
22847 index b7c2849..8633ad8 100644
22848 --- a/arch/x86/lib/usercopy_64.c
22849 +++ b/arch/x86/lib/usercopy_64.c
22850 @@ -42,6 +42,12 @@ long
22851 __strncpy_from_user(char *dst, const char __user *src, long count)
22852 {
22853 long res;
22854 +
22855 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22856 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22857 + src += PAX_USER_SHADOW_BASE;
22858 +#endif
22859 +
22860 __do_strncpy_from_user(dst, src, count, res);
22861 return res;
22862 }
22863 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
22864 {
22865 long __d0;
22866 might_fault();
22867 +
22868 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22869 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
22870 + addr += PAX_USER_SHADOW_BASE;
22871 +#endif
22872 +
22873 /* no memory constraint because it doesn't change any memory gcc knows
22874 about */
22875 asm volatile(
22876 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
22877 }
22878 EXPORT_SYMBOL(strlen_user);
22879
22880 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
22881 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
22882 {
22883 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22884 - return copy_user_generic((__force void *)to, (__force void *)from, len);
22885 - }
22886 - return len;
22887 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22888 +
22889 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22890 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
22891 + to += PAX_USER_SHADOW_BASE;
22892 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
22893 + from += PAX_USER_SHADOW_BASE;
22894 +#endif
22895 +
22896 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
22897 + }
22898 + return len;
22899 }
22900 EXPORT_SYMBOL(copy_in_user);
22901
22902 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
22903 * it is not necessary to optimize tail handling.
22904 */
22905 unsigned long
22906 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
22907 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
22908 {
22909 char c;
22910 unsigned zero_len;
22911 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
22912 index d0474ad..36e9257 100644
22913 --- a/arch/x86/mm/extable.c
22914 +++ b/arch/x86/mm/extable.c
22915 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
22916 const struct exception_table_entry *fixup;
22917
22918 #ifdef CONFIG_PNPBIOS
22919 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
22920 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
22921 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
22922 extern u32 pnp_bios_is_utter_crap;
22923 pnp_bios_is_utter_crap = 1;
22924 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
22925 index 5db0490..2ddce45 100644
22926 --- a/arch/x86/mm/fault.c
22927 +++ b/arch/x86/mm/fault.c
22928 @@ -13,11 +13,18 @@
22929 #include <linux/perf_event.h> /* perf_sw_event */
22930 #include <linux/hugetlb.h> /* hstate_index_to_shift */
22931 #include <linux/prefetch.h> /* prefetchw */
22932 +#include <linux/unistd.h>
22933 +#include <linux/compiler.h>
22934
22935 #include <asm/traps.h> /* dotraplinkage, ... */
22936 #include <asm/pgalloc.h> /* pgd_*(), ... */
22937 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
22938 #include <asm/fixmap.h> /* VSYSCALL_START */
22939 +#include <asm/tlbflush.h>
22940 +
22941 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22942 +#include <asm/stacktrace.h>
22943 +#endif
22944
22945 /*
22946 * Page fault error code bits:
22947 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
22948 int ret = 0;
22949
22950 /* kprobe_running() needs smp_processor_id() */
22951 - if (kprobes_built_in() && !user_mode_vm(regs)) {
22952 + if (kprobes_built_in() && !user_mode(regs)) {
22953 preempt_disable();
22954 if (kprobe_running() && kprobe_fault_handler(regs, 14))
22955 ret = 1;
22956 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
22957 return !instr_lo || (instr_lo>>1) == 1;
22958 case 0x00:
22959 /* Prefetch instruction is 0x0F0D or 0x0F18 */
22960 - if (probe_kernel_address(instr, opcode))
22961 + if (user_mode(regs)) {
22962 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22963 + return 0;
22964 + } else if (probe_kernel_address(instr, opcode))
22965 return 0;
22966
22967 *prefetch = (instr_lo == 0xF) &&
22968 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
22969 while (instr < max_instr) {
22970 unsigned char opcode;
22971
22972 - if (probe_kernel_address(instr, opcode))
22973 + if (user_mode(regs)) {
22974 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22975 + break;
22976 + } else if (probe_kernel_address(instr, opcode))
22977 break;
22978
22979 instr++;
22980 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
22981 force_sig_info(si_signo, &info, tsk);
22982 }
22983
22984 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22985 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
22986 +#endif
22987 +
22988 +#ifdef CONFIG_PAX_EMUTRAMP
22989 +static int pax_handle_fetch_fault(struct pt_regs *regs);
22990 +#endif
22991 +
22992 +#ifdef CONFIG_PAX_PAGEEXEC
22993 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
22994 +{
22995 + pgd_t *pgd;
22996 + pud_t *pud;
22997 + pmd_t *pmd;
22998 +
22999 + pgd = pgd_offset(mm, address);
23000 + if (!pgd_present(*pgd))
23001 + return NULL;
23002 + pud = pud_offset(pgd, address);
23003 + if (!pud_present(*pud))
23004 + return NULL;
23005 + pmd = pmd_offset(pud, address);
23006 + if (!pmd_present(*pmd))
23007 + return NULL;
23008 + return pmd;
23009 +}
23010 +#endif
23011 +
23012 DEFINE_SPINLOCK(pgd_lock);
23013 LIST_HEAD(pgd_list);
23014
23015 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23016 for (address = VMALLOC_START & PMD_MASK;
23017 address >= TASK_SIZE && address < FIXADDR_TOP;
23018 address += PMD_SIZE) {
23019 +
23020 +#ifdef CONFIG_PAX_PER_CPU_PGD
23021 + unsigned long cpu;
23022 +#else
23023 struct page *page;
23024 +#endif
23025
23026 spin_lock(&pgd_lock);
23027 +
23028 +#ifdef CONFIG_PAX_PER_CPU_PGD
23029 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23030 + pgd_t *pgd = get_cpu_pgd(cpu);
23031 + pmd_t *ret;
23032 +#else
23033 list_for_each_entry(page, &pgd_list, lru) {
23034 + pgd_t *pgd = page_address(page);
23035 spinlock_t *pgt_lock;
23036 pmd_t *ret;
23037
23038 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23039 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23040
23041 spin_lock(pgt_lock);
23042 - ret = vmalloc_sync_one(page_address(page), address);
23043 +#endif
23044 +
23045 + ret = vmalloc_sync_one(pgd, address);
23046 +
23047 +#ifndef CONFIG_PAX_PER_CPU_PGD
23048 spin_unlock(pgt_lock);
23049 +#endif
23050
23051 if (!ret)
23052 break;
23053 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23054 * an interrupt in the middle of a task switch..
23055 */
23056 pgd_paddr = read_cr3();
23057 +
23058 +#ifdef CONFIG_PAX_PER_CPU_PGD
23059 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23060 +#endif
23061 +
23062 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23063 if (!pmd_k)
23064 return -1;
23065 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23066 * happen within a race in page table update. In the later
23067 * case just flush:
23068 */
23069 +
23070 +#ifdef CONFIG_PAX_PER_CPU_PGD
23071 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23072 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23073 +#else
23074 pgd = pgd_offset(current->active_mm, address);
23075 +#endif
23076 +
23077 pgd_ref = pgd_offset_k(address);
23078 if (pgd_none(*pgd_ref))
23079 return -1;
23080 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23081 static int is_errata100(struct pt_regs *regs, unsigned long address)
23082 {
23083 #ifdef CONFIG_X86_64
23084 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23085 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23086 return 1;
23087 #endif
23088 return 0;
23089 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23090 }
23091
23092 static const char nx_warning[] = KERN_CRIT
23093 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23094 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23095
23096 static void
23097 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23098 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23099 if (!oops_may_print())
23100 return;
23101
23102 - if (error_code & PF_INSTR) {
23103 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23104 unsigned int level;
23105
23106 pte_t *pte = lookup_address(address, &level);
23107
23108 if (pte && pte_present(*pte) && !pte_exec(*pte))
23109 - printk(nx_warning, current_uid());
23110 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23111 }
23112
23113 +#ifdef CONFIG_PAX_KERNEXEC
23114 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23115 + if (current->signal->curr_ip)
23116 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23117 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23118 + else
23119 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23120 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23121 + }
23122 +#endif
23123 +
23124 printk(KERN_ALERT "BUG: unable to handle kernel ");
23125 if (address < PAGE_SIZE)
23126 printk(KERN_CONT "NULL pointer dereference");
23127 @@ -739,6 +820,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23128 }
23129 #endif
23130
23131 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23132 + if (pax_is_fetch_fault(regs, error_code, address)) {
23133 +
23134 +#ifdef CONFIG_PAX_EMUTRAMP
23135 + switch (pax_handle_fetch_fault(regs)) {
23136 + case 2:
23137 + return;
23138 + }
23139 +#endif
23140 +
23141 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23142 + do_group_exit(SIGKILL);
23143 + }
23144 +#endif
23145 +
23146 if (unlikely(show_unhandled_signals))
23147 show_signal_msg(regs, error_code, address, tsk);
23148
23149 @@ -835,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23150 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23151 printk(KERN_ERR
23152 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23153 - tsk->comm, tsk->pid, address);
23154 + tsk->comm, task_pid_nr(tsk), address);
23155 code = BUS_MCEERR_AR;
23156 }
23157 #endif
23158 @@ -890,6 +986,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23159 return 1;
23160 }
23161
23162 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23163 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23164 +{
23165 + pte_t *pte;
23166 + pmd_t *pmd;
23167 + spinlock_t *ptl;
23168 + unsigned char pte_mask;
23169 +
23170 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23171 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23172 + return 0;
23173 +
23174 + /* PaX: it's our fault, let's handle it if we can */
23175 +
23176 + /* PaX: take a look at read faults before acquiring any locks */
23177 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23178 + /* instruction fetch attempt from a protected page in user mode */
23179 + up_read(&mm->mmap_sem);
23180 +
23181 +#ifdef CONFIG_PAX_EMUTRAMP
23182 + switch (pax_handle_fetch_fault(regs)) {
23183 + case 2:
23184 + return 1;
23185 + }
23186 +#endif
23187 +
23188 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23189 + do_group_exit(SIGKILL);
23190 + }
23191 +
23192 + pmd = pax_get_pmd(mm, address);
23193 + if (unlikely(!pmd))
23194 + return 0;
23195 +
23196 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23197 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23198 + pte_unmap_unlock(pte, ptl);
23199 + return 0;
23200 + }
23201 +
23202 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23203 + /* write attempt to a protected page in user mode */
23204 + pte_unmap_unlock(pte, ptl);
23205 + return 0;
23206 + }
23207 +
23208 +#ifdef CONFIG_SMP
23209 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23210 +#else
23211 + if (likely(address > get_limit(regs->cs)))
23212 +#endif
23213 + {
23214 + set_pte(pte, pte_mkread(*pte));
23215 + __flush_tlb_one(address);
23216 + pte_unmap_unlock(pte, ptl);
23217 + up_read(&mm->mmap_sem);
23218 + return 1;
23219 + }
23220 +
23221 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23222 +
23223 + /*
23224 + * PaX: fill DTLB with user rights and retry
23225 + */
23226 + __asm__ __volatile__ (
23227 + "orb %2,(%1)\n"
23228 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23229 +/*
23230 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23231 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23232 + * page fault when examined during a TLB load attempt. this is true not only
23233 + * for PTEs holding a non-present entry but also present entries that will
23234 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23235 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23236 + * for our target pages since their PTEs are simply not in the TLBs at all.
23237 +
23238 + * the best thing in omitting it is that we gain around 15-20% speed in the
23239 + * fast path of the page fault handler and can get rid of tracing since we
23240 + * can no longer flush unintended entries.
23241 + */
23242 + "invlpg (%0)\n"
23243 +#endif
23244 + __copyuser_seg"testb $0,(%0)\n"
23245 + "xorb %3,(%1)\n"
23246 + :
23247 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23248 + : "memory", "cc");
23249 + pte_unmap_unlock(pte, ptl);
23250 + up_read(&mm->mmap_sem);
23251 + return 1;
23252 +}
23253 +#endif
23254 +
23255 /*
23256 * Handle a spurious fault caused by a stale TLB entry.
23257 *
23258 @@ -962,6 +1151,9 @@ int show_unhandled_signals = 1;
23259 static inline int
23260 access_error(unsigned long error_code, struct vm_area_struct *vma)
23261 {
23262 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23263 + return 1;
23264 +
23265 if (error_code & PF_WRITE) {
23266 /* write, present and write, not present: */
23267 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23268 @@ -995,18 +1187,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23269 {
23270 struct vm_area_struct *vma;
23271 struct task_struct *tsk;
23272 - unsigned long address;
23273 struct mm_struct *mm;
23274 int fault;
23275 int write = error_code & PF_WRITE;
23276 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23277 (write ? FAULT_FLAG_WRITE : 0);
23278
23279 - tsk = current;
23280 - mm = tsk->mm;
23281 -
23282 /* Get the faulting address: */
23283 - address = read_cr2();
23284 + unsigned long address = read_cr2();
23285 +
23286 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23287 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23288 + if (!search_exception_tables(regs->ip)) {
23289 + bad_area_nosemaphore(regs, error_code, address);
23290 + return;
23291 + }
23292 + if (address < PAX_USER_SHADOW_BASE) {
23293 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23294 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23295 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23296 + } else
23297 + address -= PAX_USER_SHADOW_BASE;
23298 + }
23299 +#endif
23300 +
23301 + tsk = current;
23302 + mm = tsk->mm;
23303
23304 /*
23305 * Detect and handle instructions that would cause a page fault for
23306 @@ -1067,7 +1273,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23307 * User-mode registers count as a user access even for any
23308 * potential system fault or CPU buglet:
23309 */
23310 - if (user_mode_vm(regs)) {
23311 + if (user_mode(regs)) {
23312 local_irq_enable();
23313 error_code |= PF_USER;
23314 } else {
23315 @@ -1122,6 +1328,11 @@ retry:
23316 might_sleep();
23317 }
23318
23319 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23320 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23321 + return;
23322 +#endif
23323 +
23324 vma = find_vma(mm, address);
23325 if (unlikely(!vma)) {
23326 bad_area(regs, error_code, address);
23327 @@ -1133,18 +1344,24 @@ retry:
23328 bad_area(regs, error_code, address);
23329 return;
23330 }
23331 - if (error_code & PF_USER) {
23332 - /*
23333 - * Accessing the stack below %sp is always a bug.
23334 - * The large cushion allows instructions like enter
23335 - * and pusha to work. ("enter $65535, $31" pushes
23336 - * 32 pointers and then decrements %sp by 65535.)
23337 - */
23338 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23339 - bad_area(regs, error_code, address);
23340 - return;
23341 - }
23342 + /*
23343 + * Accessing the stack below %sp is always a bug.
23344 + * The large cushion allows instructions like enter
23345 + * and pusha to work. ("enter $65535, $31" pushes
23346 + * 32 pointers and then decrements %sp by 65535.)
23347 + */
23348 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23349 + bad_area(regs, error_code, address);
23350 + return;
23351 }
23352 +
23353 +#ifdef CONFIG_PAX_SEGMEXEC
23354 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23355 + bad_area(regs, error_code, address);
23356 + return;
23357 + }
23358 +#endif
23359 +
23360 if (unlikely(expand_stack(vma, address))) {
23361 bad_area(regs, error_code, address);
23362 return;
23363 @@ -1199,3 +1416,292 @@ good_area:
23364
23365 up_read(&mm->mmap_sem);
23366 }
23367 +
23368 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23369 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23370 +{
23371 + struct mm_struct *mm = current->mm;
23372 + unsigned long ip = regs->ip;
23373 +
23374 + if (v8086_mode(regs))
23375 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23376 +
23377 +#ifdef CONFIG_PAX_PAGEEXEC
23378 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23379 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23380 + return true;
23381 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23382 + return true;
23383 + return false;
23384 + }
23385 +#endif
23386 +
23387 +#ifdef CONFIG_PAX_SEGMEXEC
23388 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23389 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23390 + return true;
23391 + return false;
23392 + }
23393 +#endif
23394 +
23395 + return false;
23396 +}
23397 +#endif
23398 +
23399 +#ifdef CONFIG_PAX_EMUTRAMP
23400 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23401 +{
23402 + int err;
23403 +
23404 + do { /* PaX: libffi trampoline emulation */
23405 + unsigned char mov, jmp;
23406 + unsigned int addr1, addr2;
23407 +
23408 +#ifdef CONFIG_X86_64
23409 + if ((regs->ip + 9) >> 32)
23410 + break;
23411 +#endif
23412 +
23413 + err = get_user(mov, (unsigned char __user *)regs->ip);
23414 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23415 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23416 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23417 +
23418 + if (err)
23419 + break;
23420 +
23421 + if (mov == 0xB8 && jmp == 0xE9) {
23422 + regs->ax = addr1;
23423 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23424 + return 2;
23425 + }
23426 + } while (0);
23427 +
23428 + do { /* PaX: gcc trampoline emulation #1 */
23429 + unsigned char mov1, mov2;
23430 + unsigned short jmp;
23431 + unsigned int addr1, addr2;
23432 +
23433 +#ifdef CONFIG_X86_64
23434 + if ((regs->ip + 11) >> 32)
23435 + break;
23436 +#endif
23437 +
23438 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23439 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23440 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23441 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23442 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23443 +
23444 + if (err)
23445 + break;
23446 +
23447 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23448 + regs->cx = addr1;
23449 + regs->ax = addr2;
23450 + regs->ip = addr2;
23451 + return 2;
23452 + }
23453 + } while (0);
23454 +
23455 + do { /* PaX: gcc trampoline emulation #2 */
23456 + unsigned char mov, jmp;
23457 + unsigned int addr1, addr2;
23458 +
23459 +#ifdef CONFIG_X86_64
23460 + if ((regs->ip + 9) >> 32)
23461 + break;
23462 +#endif
23463 +
23464 + err = get_user(mov, (unsigned char __user *)regs->ip);
23465 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23466 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23467 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23468 +
23469 + if (err)
23470 + break;
23471 +
23472 + if (mov == 0xB9 && jmp == 0xE9) {
23473 + regs->cx = addr1;
23474 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23475 + return 2;
23476 + }
23477 + } while (0);
23478 +
23479 + return 1; /* PaX in action */
23480 +}
23481 +
23482 +#ifdef CONFIG_X86_64
23483 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23484 +{
23485 + int err;
23486 +
23487 + do { /* PaX: libffi trampoline emulation */
23488 + unsigned short mov1, mov2, jmp1;
23489 + unsigned char stcclc, jmp2;
23490 + unsigned long addr1, addr2;
23491 +
23492 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23493 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23494 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23495 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23496 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23497 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23498 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23499 +
23500 + if (err)
23501 + break;
23502 +
23503 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23504 + regs->r11 = addr1;
23505 + regs->r10 = addr2;
23506 + if (stcclc == 0xF8)
23507 + regs->flags &= ~X86_EFLAGS_CF;
23508 + else
23509 + regs->flags |= X86_EFLAGS_CF;
23510 + regs->ip = addr1;
23511 + return 2;
23512 + }
23513 + } while (0);
23514 +
23515 + do { /* PaX: gcc trampoline emulation #1 */
23516 + unsigned short mov1, mov2, jmp1;
23517 + unsigned char jmp2;
23518 + unsigned int addr1;
23519 + unsigned long addr2;
23520 +
23521 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23522 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23523 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23524 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23525 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23526 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23527 +
23528 + if (err)
23529 + break;
23530 +
23531 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23532 + regs->r11 = addr1;
23533 + regs->r10 = addr2;
23534 + regs->ip = addr1;
23535 + return 2;
23536 + }
23537 + } while (0);
23538 +
23539 + do { /* PaX: gcc trampoline emulation #2 */
23540 + unsigned short mov1, mov2, jmp1;
23541 + unsigned char jmp2;
23542 + unsigned long addr1, addr2;
23543 +
23544 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23545 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23546 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23547 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23548 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23549 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23550 +
23551 + if (err)
23552 + break;
23553 +
23554 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23555 + regs->r11 = addr1;
23556 + regs->r10 = addr2;
23557 + regs->ip = addr1;
23558 + return 2;
23559 + }
23560 + } while (0);
23561 +
23562 + return 1; /* PaX in action */
23563 +}
23564 +#endif
23565 +
23566 +/*
23567 + * PaX: decide what to do with offenders (regs->ip = fault address)
23568 + *
23569 + * returns 1 when task should be killed
23570 + * 2 when gcc trampoline was detected
23571 + */
23572 +static int pax_handle_fetch_fault(struct pt_regs *regs)
23573 +{
23574 + if (v8086_mode(regs))
23575 + return 1;
23576 +
23577 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
23578 + return 1;
23579 +
23580 +#ifdef CONFIG_X86_32
23581 + return pax_handle_fetch_fault_32(regs);
23582 +#else
23583 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
23584 + return pax_handle_fetch_fault_32(regs);
23585 + else
23586 + return pax_handle_fetch_fault_64(regs);
23587 +#endif
23588 +}
23589 +#endif
23590 +
23591 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23592 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
23593 +{
23594 + long i;
23595 +
23596 + printk(KERN_ERR "PAX: bytes at PC: ");
23597 + for (i = 0; i < 20; i++) {
23598 + unsigned char c;
23599 + if (get_user(c, (unsigned char __force_user *)pc+i))
23600 + printk(KERN_CONT "?? ");
23601 + else
23602 + printk(KERN_CONT "%02x ", c);
23603 + }
23604 + printk("\n");
23605 +
23606 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
23607 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
23608 + unsigned long c;
23609 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
23610 +#ifdef CONFIG_X86_32
23611 + printk(KERN_CONT "???????? ");
23612 +#else
23613 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
23614 + printk(KERN_CONT "???????? ???????? ");
23615 + else
23616 + printk(KERN_CONT "???????????????? ");
23617 +#endif
23618 + } else {
23619 +#ifdef CONFIG_X86_64
23620 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
23621 + printk(KERN_CONT "%08x ", (unsigned int)c);
23622 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
23623 + } else
23624 +#endif
23625 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
23626 + }
23627 + }
23628 + printk("\n");
23629 +}
23630 +#endif
23631 +
23632 +/**
23633 + * probe_kernel_write(): safely attempt to write to a location
23634 + * @dst: address to write to
23635 + * @src: pointer to the data that shall be written
23636 + * @size: size of the data chunk
23637 + *
23638 + * Safely write to address @dst from the buffer at @src. If a kernel fault
23639 + * happens, handle that and return -EFAULT.
23640 + */
23641 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
23642 +{
23643 + long ret;
23644 + mm_segment_t old_fs = get_fs();
23645 +
23646 + set_fs(KERNEL_DS);
23647 + pagefault_disable();
23648 + pax_open_kernel();
23649 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
23650 + pax_close_kernel();
23651 + pagefault_enable();
23652 + set_fs(old_fs);
23653 +
23654 + return ret ? -EFAULT : 0;
23655 +}
23656 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
23657 index dd74e46..7d26398 100644
23658 --- a/arch/x86/mm/gup.c
23659 +++ b/arch/x86/mm/gup.c
23660 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
23661 addr = start;
23662 len = (unsigned long) nr_pages << PAGE_SHIFT;
23663 end = start + len;
23664 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23665 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23666 (void __user *)start, len)))
23667 return 0;
23668
23669 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
23670 index f4f29b1..5cac4fb 100644
23671 --- a/arch/x86/mm/highmem_32.c
23672 +++ b/arch/x86/mm/highmem_32.c
23673 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
23674 idx = type + KM_TYPE_NR*smp_processor_id();
23675 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
23676 BUG_ON(!pte_none(*(kmap_pte-idx)));
23677 +
23678 + pax_open_kernel();
23679 set_pte(kmap_pte-idx, mk_pte(page, prot));
23680 + pax_close_kernel();
23681 +
23682 arch_flush_lazy_mmu_mode();
23683
23684 return (void *)vaddr;
23685 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
23686 index f581a18..29efd37 100644
23687 --- a/arch/x86/mm/hugetlbpage.c
23688 +++ b/arch/x86/mm/hugetlbpage.c
23689 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
23690 struct hstate *h = hstate_file(file);
23691 struct mm_struct *mm = current->mm;
23692 struct vm_area_struct *vma;
23693 - unsigned long start_addr;
23694 + unsigned long start_addr, pax_task_size = TASK_SIZE;
23695 +
23696 +#ifdef CONFIG_PAX_SEGMEXEC
23697 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23698 + pax_task_size = SEGMEXEC_TASK_SIZE;
23699 +#endif
23700 +
23701 + pax_task_size -= PAGE_SIZE;
23702
23703 if (len > mm->cached_hole_size) {
23704 - start_addr = mm->free_area_cache;
23705 + start_addr = mm->free_area_cache;
23706 } else {
23707 - start_addr = TASK_UNMAPPED_BASE;
23708 - mm->cached_hole_size = 0;
23709 + start_addr = mm->mmap_base;
23710 + mm->cached_hole_size = 0;
23711 }
23712
23713 full_search:
23714 @@ -280,26 +287,27 @@ full_search:
23715
23716 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23717 /* At this point: (!vma || addr < vma->vm_end). */
23718 - if (TASK_SIZE - len < addr) {
23719 + if (pax_task_size - len < addr) {
23720 /*
23721 * Start a new search - just in case we missed
23722 * some holes.
23723 */
23724 - if (start_addr != TASK_UNMAPPED_BASE) {
23725 - start_addr = TASK_UNMAPPED_BASE;
23726 + if (start_addr != mm->mmap_base) {
23727 + start_addr = mm->mmap_base;
23728 mm->cached_hole_size = 0;
23729 goto full_search;
23730 }
23731 return -ENOMEM;
23732 }
23733 - if (!vma || addr + len <= vma->vm_start) {
23734 - mm->free_area_cache = addr + len;
23735 - return addr;
23736 - }
23737 + if (check_heap_stack_gap(vma, addr, len))
23738 + break;
23739 if (addr + mm->cached_hole_size < vma->vm_start)
23740 mm->cached_hole_size = vma->vm_start - addr;
23741 addr = ALIGN(vma->vm_end, huge_page_size(h));
23742 }
23743 +
23744 + mm->free_area_cache = addr + len;
23745 + return addr;
23746 }
23747
23748 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23749 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23750 {
23751 struct hstate *h = hstate_file(file);
23752 struct mm_struct *mm = current->mm;
23753 - struct vm_area_struct *vma, *prev_vma;
23754 - unsigned long base = mm->mmap_base, addr = addr0;
23755 + struct vm_area_struct *vma;
23756 + unsigned long base = mm->mmap_base, addr;
23757 unsigned long largest_hole = mm->cached_hole_size;
23758 - int first_time = 1;
23759
23760 /* don't allow allocations above current base */
23761 if (mm->free_area_cache > base)
23762 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23763 largest_hole = 0;
23764 mm->free_area_cache = base;
23765 }
23766 -try_again:
23767 +
23768 /* make sure it can fit in the remaining address space */
23769 if (mm->free_area_cache < len)
23770 goto fail;
23771
23772 /* either no address requested or can't fit in requested address hole */
23773 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
23774 + addr = (mm->free_area_cache - len);
23775 do {
23776 + addr &= huge_page_mask(h);
23777 + vma = find_vma(mm, addr);
23778 /*
23779 * Lookup failure means no vma is above this address,
23780 * i.e. return with success:
23781 - */
23782 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
23783 - return addr;
23784 -
23785 - /*
23786 * new region fits between prev_vma->vm_end and
23787 * vma->vm_start, use it:
23788 */
23789 - if (addr + len <= vma->vm_start &&
23790 - (!prev_vma || (addr >= prev_vma->vm_end))) {
23791 + if (check_heap_stack_gap(vma, addr, len)) {
23792 /* remember the address as a hint for next time */
23793 - mm->cached_hole_size = largest_hole;
23794 - return (mm->free_area_cache = addr);
23795 - } else {
23796 - /* pull free_area_cache down to the first hole */
23797 - if (mm->free_area_cache == vma->vm_end) {
23798 - mm->free_area_cache = vma->vm_start;
23799 - mm->cached_hole_size = largest_hole;
23800 - }
23801 + mm->cached_hole_size = largest_hole;
23802 + return (mm->free_area_cache = addr);
23803 + }
23804 + /* pull free_area_cache down to the first hole */
23805 + if (mm->free_area_cache == vma->vm_end) {
23806 + mm->free_area_cache = vma->vm_start;
23807 + mm->cached_hole_size = largest_hole;
23808 }
23809
23810 /* remember the largest hole we saw so far */
23811 if (addr + largest_hole < vma->vm_start)
23812 - largest_hole = vma->vm_start - addr;
23813 + largest_hole = vma->vm_start - addr;
23814
23815 /* try just below the current vma->vm_start */
23816 - addr = (vma->vm_start - len) & huge_page_mask(h);
23817 - } while (len <= vma->vm_start);
23818 + addr = skip_heap_stack_gap(vma, len);
23819 + } while (!IS_ERR_VALUE(addr));
23820
23821 fail:
23822 /*
23823 - * if hint left us with no space for the requested
23824 - * mapping then try again:
23825 - */
23826 - if (first_time) {
23827 - mm->free_area_cache = base;
23828 - largest_hole = 0;
23829 - first_time = 0;
23830 - goto try_again;
23831 - }
23832 - /*
23833 * A failed mmap() very likely causes application failure,
23834 * so fall back to the bottom-up function here. This scenario
23835 * can happen with large stack limits and large mmap()
23836 * allocations.
23837 */
23838 - mm->free_area_cache = TASK_UNMAPPED_BASE;
23839 +
23840 +#ifdef CONFIG_PAX_SEGMEXEC
23841 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23842 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23843 + else
23844 +#endif
23845 +
23846 + mm->mmap_base = TASK_UNMAPPED_BASE;
23847 +
23848 +#ifdef CONFIG_PAX_RANDMMAP
23849 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23850 + mm->mmap_base += mm->delta_mmap;
23851 +#endif
23852 +
23853 + mm->free_area_cache = mm->mmap_base;
23854 mm->cached_hole_size = ~0UL;
23855 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
23856 len, pgoff, flags);
23857 @@ -386,6 +392,7 @@ fail:
23858 /*
23859 * Restore the topdown base:
23860 */
23861 + mm->mmap_base = base;
23862 mm->free_area_cache = base;
23863 mm->cached_hole_size = ~0UL;
23864
23865 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23866 struct hstate *h = hstate_file(file);
23867 struct mm_struct *mm = current->mm;
23868 struct vm_area_struct *vma;
23869 + unsigned long pax_task_size = TASK_SIZE;
23870
23871 if (len & ~huge_page_mask(h))
23872 return -EINVAL;
23873 - if (len > TASK_SIZE)
23874 +
23875 +#ifdef CONFIG_PAX_SEGMEXEC
23876 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23877 + pax_task_size = SEGMEXEC_TASK_SIZE;
23878 +#endif
23879 +
23880 + pax_task_size -= PAGE_SIZE;
23881 +
23882 + if (len > pax_task_size)
23883 return -ENOMEM;
23884
23885 if (flags & MAP_FIXED) {
23886 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23887 if (addr) {
23888 addr = ALIGN(addr, huge_page_size(h));
23889 vma = find_vma(mm, addr);
23890 - if (TASK_SIZE - len >= addr &&
23891 - (!vma || addr + len <= vma->vm_start))
23892 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
23893 return addr;
23894 }
23895 if (mm->get_unmapped_area == arch_get_unmapped_area)
23896 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
23897 index 87488b9..399f416 100644
23898 --- a/arch/x86/mm/init.c
23899 +++ b/arch/x86/mm/init.c
23900 @@ -15,6 +15,7 @@
23901 #include <asm/tlbflush.h>
23902 #include <asm/tlb.h>
23903 #include <asm/proto.h>
23904 +#include <asm/desc.h>
23905
23906 unsigned long __initdata pgt_buf_start;
23907 unsigned long __meminitdata pgt_buf_end;
23908 @@ -31,7 +32,7 @@ int direct_gbpages
23909 static void __init find_early_table_space(unsigned long end, int use_pse,
23910 int use_gbpages)
23911 {
23912 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
23913 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
23914 phys_addr_t base;
23915
23916 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
23917 @@ -312,8 +313,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
23918 */
23919 int devmem_is_allowed(unsigned long pagenr)
23920 {
23921 +#ifdef CONFIG_GRKERNSEC_KMEM
23922 + /* allow BDA */
23923 + if (!pagenr)
23924 + return 1;
23925 + /* allow EBDA */
23926 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
23927 + return 1;
23928 +#else
23929 + if (!pagenr)
23930 + return 1;
23931 +#ifdef CONFIG_VM86
23932 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
23933 + return 1;
23934 +#endif
23935 +#endif
23936 +
23937 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
23938 + return 1;
23939 +#ifdef CONFIG_GRKERNSEC_KMEM
23940 + /* throw out everything else below 1MB */
23941 if (pagenr <= 256)
23942 - return 1;
23943 + return 0;
23944 +#endif
23945 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
23946 return 0;
23947 if (!page_is_ram(pagenr))
23948 @@ -372,6 +394,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
23949
23950 void free_initmem(void)
23951 {
23952 +
23953 +#ifdef CONFIG_PAX_KERNEXEC
23954 +#ifdef CONFIG_X86_32
23955 + /* PaX: limit KERNEL_CS to actual size */
23956 + unsigned long addr, limit;
23957 + struct desc_struct d;
23958 + int cpu;
23959 +
23960 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
23961 + limit = (limit - 1UL) >> PAGE_SHIFT;
23962 +
23963 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
23964 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
23965 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
23966 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
23967 + }
23968 +
23969 + /* PaX: make KERNEL_CS read-only */
23970 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
23971 + if (!paravirt_enabled())
23972 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
23973 +/*
23974 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
23975 + pgd = pgd_offset_k(addr);
23976 + pud = pud_offset(pgd, addr);
23977 + pmd = pmd_offset(pud, addr);
23978 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23979 + }
23980 +*/
23981 +#ifdef CONFIG_X86_PAE
23982 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
23983 +/*
23984 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
23985 + pgd = pgd_offset_k(addr);
23986 + pud = pud_offset(pgd, addr);
23987 + pmd = pmd_offset(pud, addr);
23988 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23989 + }
23990 +*/
23991 +#endif
23992 +
23993 +#ifdef CONFIG_MODULES
23994 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
23995 +#endif
23996 +
23997 +#else
23998 + pgd_t *pgd;
23999 + pud_t *pud;
24000 + pmd_t *pmd;
24001 + unsigned long addr, end;
24002 +
24003 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24004 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24005 + pgd = pgd_offset_k(addr);
24006 + pud = pud_offset(pgd, addr);
24007 + pmd = pmd_offset(pud, addr);
24008 + if (!pmd_present(*pmd))
24009 + continue;
24010 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24011 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24012 + else
24013 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24014 + }
24015 +
24016 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24017 + end = addr + KERNEL_IMAGE_SIZE;
24018 + for (; addr < end; addr += PMD_SIZE) {
24019 + pgd = pgd_offset_k(addr);
24020 + pud = pud_offset(pgd, addr);
24021 + pmd = pmd_offset(pud, addr);
24022 + if (!pmd_present(*pmd))
24023 + continue;
24024 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24025 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24026 + }
24027 +#endif
24028 +
24029 + flush_tlb_all();
24030 +#endif
24031 +
24032 free_init_pages("unused kernel memory",
24033 (unsigned long)(&__init_begin),
24034 (unsigned long)(&__init_end));
24035 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24036 index 29f7c6d..b46b35b 100644
24037 --- a/arch/x86/mm/init_32.c
24038 +++ b/arch/x86/mm/init_32.c
24039 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24040 }
24041
24042 /*
24043 - * Creates a middle page table and puts a pointer to it in the
24044 - * given global directory entry. This only returns the gd entry
24045 - * in non-PAE compilation mode, since the middle layer is folded.
24046 - */
24047 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24048 -{
24049 - pud_t *pud;
24050 - pmd_t *pmd_table;
24051 -
24052 -#ifdef CONFIG_X86_PAE
24053 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24054 - if (after_bootmem)
24055 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24056 - else
24057 - pmd_table = (pmd_t *)alloc_low_page();
24058 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24059 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24060 - pud = pud_offset(pgd, 0);
24061 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24062 -
24063 - return pmd_table;
24064 - }
24065 -#endif
24066 - pud = pud_offset(pgd, 0);
24067 - pmd_table = pmd_offset(pud, 0);
24068 -
24069 - return pmd_table;
24070 -}
24071 -
24072 -/*
24073 * Create a page table and place a pointer to it in a middle page
24074 * directory entry:
24075 */
24076 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24077 page_table = (pte_t *)alloc_low_page();
24078
24079 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24080 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24081 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24082 +#else
24083 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24084 +#endif
24085 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24086 }
24087
24088 return pte_offset_kernel(pmd, 0);
24089 }
24090
24091 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24092 +{
24093 + pud_t *pud;
24094 + pmd_t *pmd_table;
24095 +
24096 + pud = pud_offset(pgd, 0);
24097 + pmd_table = pmd_offset(pud, 0);
24098 +
24099 + return pmd_table;
24100 +}
24101 +
24102 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24103 {
24104 int pgd_idx = pgd_index(vaddr);
24105 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24106 int pgd_idx, pmd_idx;
24107 unsigned long vaddr;
24108 pgd_t *pgd;
24109 + pud_t *pud;
24110 pmd_t *pmd;
24111 pte_t *pte = NULL;
24112
24113 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24114 pgd = pgd_base + pgd_idx;
24115
24116 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24117 - pmd = one_md_table_init(pgd);
24118 - pmd = pmd + pmd_index(vaddr);
24119 + pud = pud_offset(pgd, vaddr);
24120 + pmd = pmd_offset(pud, vaddr);
24121 +
24122 +#ifdef CONFIG_X86_PAE
24123 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24124 +#endif
24125 +
24126 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24127 pmd++, pmd_idx++) {
24128 pte = page_table_kmap_check(one_page_table_init(pmd),
24129 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24130 }
24131 }
24132
24133 -static inline int is_kernel_text(unsigned long addr)
24134 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24135 {
24136 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24137 - return 1;
24138 - return 0;
24139 + if ((start > ktla_ktva((unsigned long)_etext) ||
24140 + end <= ktla_ktva((unsigned long)_stext)) &&
24141 + (start > ktla_ktva((unsigned long)_einittext) ||
24142 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24143 +
24144 +#ifdef CONFIG_ACPI_SLEEP
24145 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24146 +#endif
24147 +
24148 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24149 + return 0;
24150 + return 1;
24151 }
24152
24153 /*
24154 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24155 unsigned long last_map_addr = end;
24156 unsigned long start_pfn, end_pfn;
24157 pgd_t *pgd_base = swapper_pg_dir;
24158 - int pgd_idx, pmd_idx, pte_ofs;
24159 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24160 unsigned long pfn;
24161 pgd_t *pgd;
24162 + pud_t *pud;
24163 pmd_t *pmd;
24164 pte_t *pte;
24165 unsigned pages_2m, pages_4k;
24166 @@ -281,8 +282,13 @@ repeat:
24167 pfn = start_pfn;
24168 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24169 pgd = pgd_base + pgd_idx;
24170 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24171 - pmd = one_md_table_init(pgd);
24172 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24173 + pud = pud_offset(pgd, 0);
24174 + pmd = pmd_offset(pud, 0);
24175 +
24176 +#ifdef CONFIG_X86_PAE
24177 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24178 +#endif
24179
24180 if (pfn >= end_pfn)
24181 continue;
24182 @@ -294,14 +300,13 @@ repeat:
24183 #endif
24184 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24185 pmd++, pmd_idx++) {
24186 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24187 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24188
24189 /*
24190 * Map with big pages if possible, otherwise
24191 * create normal page tables:
24192 */
24193 if (use_pse) {
24194 - unsigned int addr2;
24195 pgprot_t prot = PAGE_KERNEL_LARGE;
24196 /*
24197 * first pass will use the same initial
24198 @@ -311,11 +316,7 @@ repeat:
24199 __pgprot(PTE_IDENT_ATTR |
24200 _PAGE_PSE);
24201
24202 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24203 - PAGE_OFFSET + PAGE_SIZE-1;
24204 -
24205 - if (is_kernel_text(addr) ||
24206 - is_kernel_text(addr2))
24207 + if (is_kernel_text(address, address + PMD_SIZE))
24208 prot = PAGE_KERNEL_LARGE_EXEC;
24209
24210 pages_2m++;
24211 @@ -332,7 +333,7 @@ repeat:
24212 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24213 pte += pte_ofs;
24214 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24215 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24216 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24217 pgprot_t prot = PAGE_KERNEL;
24218 /*
24219 * first pass will use the same initial
24220 @@ -340,7 +341,7 @@ repeat:
24221 */
24222 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24223
24224 - if (is_kernel_text(addr))
24225 + if (is_kernel_text(address, address + PAGE_SIZE))
24226 prot = PAGE_KERNEL_EXEC;
24227
24228 pages_4k++;
24229 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24230
24231 pud = pud_offset(pgd, va);
24232 pmd = pmd_offset(pud, va);
24233 - if (!pmd_present(*pmd))
24234 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24235 break;
24236
24237 pte = pte_offset_kernel(pmd, va);
24238 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
24239
24240 static void __init pagetable_init(void)
24241 {
24242 - pgd_t *pgd_base = swapper_pg_dir;
24243 -
24244 - permanent_kmaps_init(pgd_base);
24245 + permanent_kmaps_init(swapper_pg_dir);
24246 }
24247
24248 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24249 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24250 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24251
24252 /* user-defined highmem size */
24253 @@ -757,6 +756,12 @@ void __init mem_init(void)
24254
24255 pci_iommu_alloc();
24256
24257 +#ifdef CONFIG_PAX_PER_CPU_PGD
24258 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24259 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24260 + KERNEL_PGD_PTRS);
24261 +#endif
24262 +
24263 #ifdef CONFIG_FLATMEM
24264 BUG_ON(!mem_map);
24265 #endif
24266 @@ -774,7 +779,7 @@ void __init mem_init(void)
24267 set_highmem_pages_init();
24268
24269 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24270 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24271 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24272 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24273
24274 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24275 @@ -815,10 +820,10 @@ void __init mem_init(void)
24276 ((unsigned long)&__init_end -
24277 (unsigned long)&__init_begin) >> 10,
24278
24279 - (unsigned long)&_etext, (unsigned long)&_edata,
24280 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24281 + (unsigned long)&_sdata, (unsigned long)&_edata,
24282 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24283
24284 - (unsigned long)&_text, (unsigned long)&_etext,
24285 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24286 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24287
24288 /*
24289 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
24290 if (!kernel_set_to_readonly)
24291 return;
24292
24293 + start = ktla_ktva(start);
24294 pr_debug("Set kernel text: %lx - %lx for read write\n",
24295 start, start+size);
24296
24297 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
24298 if (!kernel_set_to_readonly)
24299 return;
24300
24301 + start = ktla_ktva(start);
24302 pr_debug("Set kernel text: %lx - %lx for read only\n",
24303 start, start+size);
24304
24305 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
24306 unsigned long start = PFN_ALIGN(_text);
24307 unsigned long size = PFN_ALIGN(_etext) - start;
24308
24309 + start = ktla_ktva(start);
24310 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24311 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24312 size >> 10);
24313 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24314 index bbaaa00..796fa65 100644
24315 --- a/arch/x86/mm/init_64.c
24316 +++ b/arch/x86/mm/init_64.c
24317 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24318 * around without checking the pgd every time.
24319 */
24320
24321 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24322 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24323 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24324
24325 int force_personality32;
24326 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24327
24328 for (address = start; address <= end; address += PGDIR_SIZE) {
24329 const pgd_t *pgd_ref = pgd_offset_k(address);
24330 +
24331 +#ifdef CONFIG_PAX_PER_CPU_PGD
24332 + unsigned long cpu;
24333 +#else
24334 struct page *page;
24335 +#endif
24336
24337 if (pgd_none(*pgd_ref))
24338 continue;
24339
24340 spin_lock(&pgd_lock);
24341 +
24342 +#ifdef CONFIG_PAX_PER_CPU_PGD
24343 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24344 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24345 +#else
24346 list_for_each_entry(page, &pgd_list, lru) {
24347 pgd_t *pgd;
24348 spinlock_t *pgt_lock;
24349 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24350 /* the pgt_lock only for Xen */
24351 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24352 spin_lock(pgt_lock);
24353 +#endif
24354
24355 if (pgd_none(*pgd))
24356 set_pgd(pgd, *pgd_ref);
24357 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24358 BUG_ON(pgd_page_vaddr(*pgd)
24359 != pgd_page_vaddr(*pgd_ref));
24360
24361 +#ifndef CONFIG_PAX_PER_CPU_PGD
24362 spin_unlock(pgt_lock);
24363 +#endif
24364 +
24365 }
24366 spin_unlock(&pgd_lock);
24367 }
24368 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24369 pmd = fill_pmd(pud, vaddr);
24370 pte = fill_pte(pmd, vaddr);
24371
24372 + pax_open_kernel();
24373 set_pte(pte, new_pte);
24374 + pax_close_kernel();
24375
24376 /*
24377 * It's enough to flush this one mapping.
24378 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24379 pgd = pgd_offset_k((unsigned long)__va(phys));
24380 if (pgd_none(*pgd)) {
24381 pud = (pud_t *) spp_getpage();
24382 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24383 - _PAGE_USER));
24384 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24385 }
24386 pud = pud_offset(pgd, (unsigned long)__va(phys));
24387 if (pud_none(*pud)) {
24388 pmd = (pmd_t *) spp_getpage();
24389 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24390 - _PAGE_USER));
24391 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24392 }
24393 pmd = pmd_offset(pud, phys);
24394 BUG_ON(!pmd_none(*pmd));
24395 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24396 if (pfn >= pgt_buf_top)
24397 panic("alloc_low_page: ran out of memory");
24398
24399 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24400 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24401 clear_page(adr);
24402 *phys = pfn * PAGE_SIZE;
24403 return adr;
24404 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24405
24406 phys = __pa(virt);
24407 left = phys & (PAGE_SIZE - 1);
24408 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24409 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24410 adr = (void *)(((unsigned long)adr) | left);
24411
24412 return adr;
24413 @@ -693,6 +707,12 @@ void __init mem_init(void)
24414
24415 pci_iommu_alloc();
24416
24417 +#ifdef CONFIG_PAX_PER_CPU_PGD
24418 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24419 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24420 + KERNEL_PGD_PTRS);
24421 +#endif
24422 +
24423 /* clear_bss() already clear the empty_zero_page */
24424
24425 reservedpages = 0;
24426 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
24427 static struct vm_area_struct gate_vma = {
24428 .vm_start = VSYSCALL_START,
24429 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24430 - .vm_page_prot = PAGE_READONLY_EXEC,
24431 - .vm_flags = VM_READ | VM_EXEC
24432 + .vm_page_prot = PAGE_READONLY,
24433 + .vm_flags = VM_READ
24434 };
24435
24436 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24437 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
24438
24439 const char *arch_vma_name(struct vm_area_struct *vma)
24440 {
24441 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24442 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24443 return "[vdso]";
24444 if (vma == &gate_vma)
24445 return "[vsyscall]";
24446 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24447 index 7b179b4..6bd1777 100644
24448 --- a/arch/x86/mm/iomap_32.c
24449 +++ b/arch/x86/mm/iomap_32.c
24450 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24451 type = kmap_atomic_idx_push();
24452 idx = type + KM_TYPE_NR * smp_processor_id();
24453 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24454 +
24455 + pax_open_kernel();
24456 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24457 + pax_close_kernel();
24458 +
24459 arch_flush_lazy_mmu_mode();
24460
24461 return (void *)vaddr;
24462 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24463 index be1ef57..55f0160 100644
24464 --- a/arch/x86/mm/ioremap.c
24465 +++ b/arch/x86/mm/ioremap.c
24466 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24467 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24468 int is_ram = page_is_ram(pfn);
24469
24470 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24471 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24472 return NULL;
24473 WARN_ON_ONCE(is_ram);
24474 }
24475 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24476
24477 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24478 if (page_is_ram(start >> PAGE_SHIFT))
24479 +#ifdef CONFIG_HIGHMEM
24480 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24481 +#endif
24482 return __va(phys);
24483
24484 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24485 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24486 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24487
24488 static __initdata int after_paging_init;
24489 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24490 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24491
24492 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24493 {
24494 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24495 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24496
24497 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24498 - memset(bm_pte, 0, sizeof(bm_pte));
24499 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
24500 + pmd_populate_user(&init_mm, pmd, bm_pte);
24501
24502 /*
24503 * The boot-ioremap range spans multiple pmds, for which
24504 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
24505 index d87dd6d..bf3fa66 100644
24506 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
24507 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
24508 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
24509 * memory (e.g. tracked pages)? For now, we need this to avoid
24510 * invoking kmemcheck for PnP BIOS calls.
24511 */
24512 - if (regs->flags & X86_VM_MASK)
24513 + if (v8086_mode(regs))
24514 return false;
24515 - if (regs->cs != __KERNEL_CS)
24516 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
24517 return false;
24518
24519 pte = kmemcheck_pte_lookup(address);
24520 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
24521 index 845df68..1d8d29f 100644
24522 --- a/arch/x86/mm/mmap.c
24523 +++ b/arch/x86/mm/mmap.c
24524 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
24525 * Leave an at least ~128 MB hole with possible stack randomization.
24526 */
24527 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
24528 -#define MAX_GAP (TASK_SIZE/6*5)
24529 +#define MAX_GAP (pax_task_size/6*5)
24530
24531 static int mmap_is_legacy(void)
24532 {
24533 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
24534 return rnd << PAGE_SHIFT;
24535 }
24536
24537 -static unsigned long mmap_base(void)
24538 +static unsigned long mmap_base(struct mm_struct *mm)
24539 {
24540 unsigned long gap = rlimit(RLIMIT_STACK);
24541 + unsigned long pax_task_size = TASK_SIZE;
24542 +
24543 +#ifdef CONFIG_PAX_SEGMEXEC
24544 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24545 + pax_task_size = SEGMEXEC_TASK_SIZE;
24546 +#endif
24547
24548 if (gap < MIN_GAP)
24549 gap = MIN_GAP;
24550 else if (gap > MAX_GAP)
24551 gap = MAX_GAP;
24552
24553 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
24554 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
24555 }
24556
24557 /*
24558 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
24559 * does, but not when emulating X86_32
24560 */
24561 -static unsigned long mmap_legacy_base(void)
24562 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
24563 {
24564 - if (mmap_is_ia32())
24565 + if (mmap_is_ia32()) {
24566 +
24567 +#ifdef CONFIG_PAX_SEGMEXEC
24568 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24569 + return SEGMEXEC_TASK_UNMAPPED_BASE;
24570 + else
24571 +#endif
24572 +
24573 return TASK_UNMAPPED_BASE;
24574 - else
24575 + } else
24576 return TASK_UNMAPPED_BASE + mmap_rnd();
24577 }
24578
24579 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
24580 void arch_pick_mmap_layout(struct mm_struct *mm)
24581 {
24582 if (mmap_is_legacy()) {
24583 - mm->mmap_base = mmap_legacy_base();
24584 + mm->mmap_base = mmap_legacy_base(mm);
24585 +
24586 +#ifdef CONFIG_PAX_RANDMMAP
24587 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24588 + mm->mmap_base += mm->delta_mmap;
24589 +#endif
24590 +
24591 mm->get_unmapped_area = arch_get_unmapped_area;
24592 mm->unmap_area = arch_unmap_area;
24593 } else {
24594 - mm->mmap_base = mmap_base();
24595 + mm->mmap_base = mmap_base(mm);
24596 +
24597 +#ifdef CONFIG_PAX_RANDMMAP
24598 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24599 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
24600 +#endif
24601 +
24602 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
24603 mm->unmap_area = arch_unmap_area_topdown;
24604 }
24605 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
24606 index de54b9b..799051e 100644
24607 --- a/arch/x86/mm/mmio-mod.c
24608 +++ b/arch/x86/mm/mmio-mod.c
24609 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
24610 break;
24611 default:
24612 {
24613 - unsigned char *ip = (unsigned char *)instptr;
24614 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
24615 my_trace->opcode = MMIO_UNKNOWN_OP;
24616 my_trace->width = 0;
24617 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
24618 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
24619 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24620 void __iomem *addr)
24621 {
24622 - static atomic_t next_id;
24623 + static atomic_unchecked_t next_id;
24624 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
24625 /* These are page-unaligned. */
24626 struct mmiotrace_map map = {
24627 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24628 .private = trace
24629 },
24630 .phys = offset,
24631 - .id = atomic_inc_return(&next_id)
24632 + .id = atomic_inc_return_unchecked(&next_id)
24633 };
24634 map.map_id = trace->id;
24635
24636 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
24637 index b008656..773eac2 100644
24638 --- a/arch/x86/mm/pageattr-test.c
24639 +++ b/arch/x86/mm/pageattr-test.c
24640 @@ -36,7 +36,7 @@ enum {
24641
24642 static int pte_testbit(pte_t pte)
24643 {
24644 - return pte_flags(pte) & _PAGE_UNUSED1;
24645 + return pte_flags(pte) & _PAGE_CPA_TEST;
24646 }
24647
24648 struct split_state {
24649 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
24650 index f9e5267..77b1a40 100644
24651 --- a/arch/x86/mm/pageattr.c
24652 +++ b/arch/x86/mm/pageattr.c
24653 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24654 */
24655 #ifdef CONFIG_PCI_BIOS
24656 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
24657 - pgprot_val(forbidden) |= _PAGE_NX;
24658 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24659 #endif
24660
24661 /*
24662 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24663 * Does not cover __inittext since that is gone later on. On
24664 * 64bit we do not enforce !NX on the low mapping
24665 */
24666 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
24667 - pgprot_val(forbidden) |= _PAGE_NX;
24668 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
24669 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24670
24671 +#ifdef CONFIG_DEBUG_RODATA
24672 /*
24673 * The .rodata section needs to be read-only. Using the pfn
24674 * catches all aliases.
24675 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24676 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
24677 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
24678 pgprot_val(forbidden) |= _PAGE_RW;
24679 +#endif
24680
24681 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
24682 /*
24683 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24684 }
24685 #endif
24686
24687 +#ifdef CONFIG_PAX_KERNEXEC
24688 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
24689 + pgprot_val(forbidden) |= _PAGE_RW;
24690 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24691 + }
24692 +#endif
24693 +
24694 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
24695
24696 return prot;
24697 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
24698 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
24699 {
24700 /* change init_mm */
24701 + pax_open_kernel();
24702 set_pte_atomic(kpte, pte);
24703 +
24704 #ifdef CONFIG_X86_32
24705 if (!SHARED_KERNEL_PMD) {
24706 +
24707 +#ifdef CONFIG_PAX_PER_CPU_PGD
24708 + unsigned long cpu;
24709 +#else
24710 struct page *page;
24711 +#endif
24712
24713 +#ifdef CONFIG_PAX_PER_CPU_PGD
24714 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24715 + pgd_t *pgd = get_cpu_pgd(cpu);
24716 +#else
24717 list_for_each_entry(page, &pgd_list, lru) {
24718 - pgd_t *pgd;
24719 + pgd_t *pgd = (pgd_t *)page_address(page);
24720 +#endif
24721 +
24722 pud_t *pud;
24723 pmd_t *pmd;
24724
24725 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
24726 + pgd += pgd_index(address);
24727 pud = pud_offset(pgd, address);
24728 pmd = pmd_offset(pud, address);
24729 set_pte_atomic((pte_t *)pmd, pte);
24730 }
24731 }
24732 #endif
24733 + pax_close_kernel();
24734 }
24735
24736 static int
24737 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
24738 index f6ff57b..481690f 100644
24739 --- a/arch/x86/mm/pat.c
24740 +++ b/arch/x86/mm/pat.c
24741 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
24742
24743 if (!entry) {
24744 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
24745 - current->comm, current->pid, start, end);
24746 + current->comm, task_pid_nr(current), start, end);
24747 return -EINVAL;
24748 }
24749
24750 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
24751 while (cursor < to) {
24752 if (!devmem_is_allowed(pfn)) {
24753 printk(KERN_INFO
24754 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
24755 - current->comm, from, to);
24756 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
24757 + current->comm, from, to, cursor);
24758 return 0;
24759 }
24760 cursor += PAGE_SIZE;
24761 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
24762 printk(KERN_INFO
24763 "%s:%d ioremap_change_attr failed %s "
24764 "for %Lx-%Lx\n",
24765 - current->comm, current->pid,
24766 + current->comm, task_pid_nr(current),
24767 cattr_name(flags),
24768 base, (unsigned long long)(base + size));
24769 return -EINVAL;
24770 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24771 if (want_flags != flags) {
24772 printk(KERN_WARNING
24773 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
24774 - current->comm, current->pid,
24775 + current->comm, task_pid_nr(current),
24776 cattr_name(want_flags),
24777 (unsigned long long)paddr,
24778 (unsigned long long)(paddr + size),
24779 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24780 free_memtype(paddr, paddr + size);
24781 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
24782 " for %Lx-%Lx, got %s\n",
24783 - current->comm, current->pid,
24784 + current->comm, task_pid_nr(current),
24785 cattr_name(want_flags),
24786 (unsigned long long)paddr,
24787 (unsigned long long)(paddr + size),
24788 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
24789 index 9f0614d..92ae64a 100644
24790 --- a/arch/x86/mm/pf_in.c
24791 +++ b/arch/x86/mm/pf_in.c
24792 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
24793 int i;
24794 enum reason_type rv = OTHERS;
24795
24796 - p = (unsigned char *)ins_addr;
24797 + p = (unsigned char *)ktla_ktva(ins_addr);
24798 p += skip_prefix(p, &prf);
24799 p += get_opcode(p, &opcode);
24800
24801 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
24802 struct prefix_bits prf;
24803 int i;
24804
24805 - p = (unsigned char *)ins_addr;
24806 + p = (unsigned char *)ktla_ktva(ins_addr);
24807 p += skip_prefix(p, &prf);
24808 p += get_opcode(p, &opcode);
24809
24810 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
24811 struct prefix_bits prf;
24812 int i;
24813
24814 - p = (unsigned char *)ins_addr;
24815 + p = (unsigned char *)ktla_ktva(ins_addr);
24816 p += skip_prefix(p, &prf);
24817 p += get_opcode(p, &opcode);
24818
24819 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
24820 struct prefix_bits prf;
24821 int i;
24822
24823 - p = (unsigned char *)ins_addr;
24824 + p = (unsigned char *)ktla_ktva(ins_addr);
24825 p += skip_prefix(p, &prf);
24826 p += get_opcode(p, &opcode);
24827 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
24828 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
24829 struct prefix_bits prf;
24830 int i;
24831
24832 - p = (unsigned char *)ins_addr;
24833 + p = (unsigned char *)ktla_ktva(ins_addr);
24834 p += skip_prefix(p, &prf);
24835 p += get_opcode(p, &opcode);
24836 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
24837 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
24838 index 8573b83..c3b1a30 100644
24839 --- a/arch/x86/mm/pgtable.c
24840 +++ b/arch/x86/mm/pgtable.c
24841 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
24842 list_del(&page->lru);
24843 }
24844
24845 -#define UNSHARED_PTRS_PER_PGD \
24846 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24847 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24848 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
24849
24850 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24851 +{
24852 + while (count--)
24853 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
24854 +}
24855 +#endif
24856
24857 +#ifdef CONFIG_PAX_PER_CPU_PGD
24858 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24859 +{
24860 + while (count--)
24861 +
24862 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24863 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
24864 +#else
24865 + *dst++ = *src++;
24866 +#endif
24867 +
24868 +}
24869 +#endif
24870 +
24871 +#ifdef CONFIG_X86_64
24872 +#define pxd_t pud_t
24873 +#define pyd_t pgd_t
24874 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
24875 +#define pxd_free(mm, pud) pud_free((mm), (pud))
24876 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
24877 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
24878 +#define PYD_SIZE PGDIR_SIZE
24879 +#else
24880 +#define pxd_t pmd_t
24881 +#define pyd_t pud_t
24882 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
24883 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
24884 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
24885 +#define pyd_offset(mm, address) pud_offset((mm), (address))
24886 +#define PYD_SIZE PUD_SIZE
24887 +#endif
24888 +
24889 +#ifdef CONFIG_PAX_PER_CPU_PGD
24890 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
24891 +static inline void pgd_dtor(pgd_t *pgd) {}
24892 +#else
24893 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
24894 {
24895 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
24896 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
24897 pgd_list_del(pgd);
24898 spin_unlock(&pgd_lock);
24899 }
24900 +#endif
24901
24902 /*
24903 * List of all pgd's needed for non-PAE so it can invalidate entries
24904 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
24905 * -- wli
24906 */
24907
24908 -#ifdef CONFIG_X86_PAE
24909 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24910 /*
24911 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
24912 * updating the top-level pagetable entries to guarantee the
24913 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
24914 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
24915 * and initialize the kernel pmds here.
24916 */
24917 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
24918 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24919
24920 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24921 {
24922 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24923 */
24924 flush_tlb_mm(mm);
24925 }
24926 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
24927 +#define PREALLOCATED_PXDS USER_PGD_PTRS
24928 #else /* !CONFIG_X86_PAE */
24929
24930 /* No need to prepopulate any pagetable entries in non-PAE modes. */
24931 -#define PREALLOCATED_PMDS 0
24932 +#define PREALLOCATED_PXDS 0
24933
24934 #endif /* CONFIG_X86_PAE */
24935
24936 -static void free_pmds(pmd_t *pmds[])
24937 +static void free_pxds(pxd_t *pxds[])
24938 {
24939 int i;
24940
24941 - for(i = 0; i < PREALLOCATED_PMDS; i++)
24942 - if (pmds[i])
24943 - free_page((unsigned long)pmds[i]);
24944 + for(i = 0; i < PREALLOCATED_PXDS; i++)
24945 + if (pxds[i])
24946 + free_page((unsigned long)pxds[i]);
24947 }
24948
24949 -static int preallocate_pmds(pmd_t *pmds[])
24950 +static int preallocate_pxds(pxd_t *pxds[])
24951 {
24952 int i;
24953 bool failed = false;
24954
24955 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24956 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
24957 - if (pmd == NULL)
24958 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24959 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
24960 + if (pxd == NULL)
24961 failed = true;
24962 - pmds[i] = pmd;
24963 + pxds[i] = pxd;
24964 }
24965
24966 if (failed) {
24967 - free_pmds(pmds);
24968 + free_pxds(pxds);
24969 return -ENOMEM;
24970 }
24971
24972 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
24973 * preallocate which never got a corresponding vma will need to be
24974 * freed manually.
24975 */
24976 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
24977 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
24978 {
24979 int i;
24980
24981 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24982 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24983 pgd_t pgd = pgdp[i];
24984
24985 if (pgd_val(pgd) != 0) {
24986 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
24987 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
24988
24989 - pgdp[i] = native_make_pgd(0);
24990 + set_pgd(pgdp + i, native_make_pgd(0));
24991
24992 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
24993 - pmd_free(mm, pmd);
24994 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
24995 + pxd_free(mm, pxd);
24996 }
24997 }
24998 }
24999
25000 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25001 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25002 {
25003 - pud_t *pud;
25004 + pyd_t *pyd;
25005 unsigned long addr;
25006 int i;
25007
25008 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25009 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25010 return;
25011
25012 - pud = pud_offset(pgd, 0);
25013 +#ifdef CONFIG_X86_64
25014 + pyd = pyd_offset(mm, 0L);
25015 +#else
25016 + pyd = pyd_offset(pgd, 0L);
25017 +#endif
25018
25019 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25020 - i++, pud++, addr += PUD_SIZE) {
25021 - pmd_t *pmd = pmds[i];
25022 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25023 + i++, pyd++, addr += PYD_SIZE) {
25024 + pxd_t *pxd = pxds[i];
25025
25026 if (i >= KERNEL_PGD_BOUNDARY)
25027 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25028 - sizeof(pmd_t) * PTRS_PER_PMD);
25029 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25030 + sizeof(pxd_t) * PTRS_PER_PMD);
25031
25032 - pud_populate(mm, pud, pmd);
25033 + pyd_populate(mm, pyd, pxd);
25034 }
25035 }
25036
25037 pgd_t *pgd_alloc(struct mm_struct *mm)
25038 {
25039 pgd_t *pgd;
25040 - pmd_t *pmds[PREALLOCATED_PMDS];
25041 + pxd_t *pxds[PREALLOCATED_PXDS];
25042
25043 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25044
25045 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25046
25047 mm->pgd = pgd;
25048
25049 - if (preallocate_pmds(pmds) != 0)
25050 + if (preallocate_pxds(pxds) != 0)
25051 goto out_free_pgd;
25052
25053 if (paravirt_pgd_alloc(mm) != 0)
25054 - goto out_free_pmds;
25055 + goto out_free_pxds;
25056
25057 /*
25058 * Make sure that pre-populating the pmds is atomic with
25059 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25060 spin_lock(&pgd_lock);
25061
25062 pgd_ctor(mm, pgd);
25063 - pgd_prepopulate_pmd(mm, pgd, pmds);
25064 + pgd_prepopulate_pxd(mm, pgd, pxds);
25065
25066 spin_unlock(&pgd_lock);
25067
25068 return pgd;
25069
25070 -out_free_pmds:
25071 - free_pmds(pmds);
25072 +out_free_pxds:
25073 + free_pxds(pxds);
25074 out_free_pgd:
25075 free_page((unsigned long)pgd);
25076 out:
25077 @@ -295,7 +344,7 @@ out:
25078
25079 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25080 {
25081 - pgd_mop_up_pmds(mm, pgd);
25082 + pgd_mop_up_pxds(mm, pgd);
25083 pgd_dtor(pgd);
25084 paravirt_pgd_free(mm, pgd);
25085 free_page((unsigned long)pgd);
25086 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25087 index cac7184..09a39fa 100644
25088 --- a/arch/x86/mm/pgtable_32.c
25089 +++ b/arch/x86/mm/pgtable_32.c
25090 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25091 return;
25092 }
25093 pte = pte_offset_kernel(pmd, vaddr);
25094 +
25095 + pax_open_kernel();
25096 if (pte_val(pteval))
25097 set_pte_at(&init_mm, vaddr, pte, pteval);
25098 else
25099 pte_clear(&init_mm, vaddr, pte);
25100 + pax_close_kernel();
25101
25102 /*
25103 * It's enough to flush this one mapping.
25104 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25105 index 410531d..0f16030 100644
25106 --- a/arch/x86/mm/setup_nx.c
25107 +++ b/arch/x86/mm/setup_nx.c
25108 @@ -5,8 +5,10 @@
25109 #include <asm/pgtable.h>
25110 #include <asm/proto.h>
25111
25112 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25113 static int disable_nx __cpuinitdata;
25114
25115 +#ifndef CONFIG_PAX_PAGEEXEC
25116 /*
25117 * noexec = on|off
25118 *
25119 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25120 return 0;
25121 }
25122 early_param("noexec", noexec_setup);
25123 +#endif
25124 +
25125 +#endif
25126
25127 void __cpuinit x86_configure_nx(void)
25128 {
25129 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25130 if (cpu_has_nx && !disable_nx)
25131 __supported_pte_mask |= _PAGE_NX;
25132 else
25133 +#endif
25134 __supported_pte_mask &= ~_PAGE_NX;
25135 }
25136
25137 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25138 index d6c0418..06a0ad5 100644
25139 --- a/arch/x86/mm/tlb.c
25140 +++ b/arch/x86/mm/tlb.c
25141 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25142 BUG();
25143 cpumask_clear_cpu(cpu,
25144 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25145 +
25146 +#ifndef CONFIG_PAX_PER_CPU_PGD
25147 load_cr3(swapper_pg_dir);
25148 +#endif
25149 +
25150 }
25151 EXPORT_SYMBOL_GPL(leave_mm);
25152
25153 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25154 index 6687022..ceabcfa 100644
25155 --- a/arch/x86/net/bpf_jit.S
25156 +++ b/arch/x86/net/bpf_jit.S
25157 @@ -9,6 +9,7 @@
25158 */
25159 #include <linux/linkage.h>
25160 #include <asm/dwarf2.h>
25161 +#include <asm/alternative-asm.h>
25162
25163 /*
25164 * Calling convention :
25165 @@ -35,6 +36,7 @@ sk_load_word:
25166 jle bpf_slow_path_word
25167 mov (SKBDATA,%rsi),%eax
25168 bswap %eax /* ntohl() */
25169 + pax_force_retaddr
25170 ret
25171
25172
25173 @@ -53,6 +55,7 @@ sk_load_half:
25174 jle bpf_slow_path_half
25175 movzwl (SKBDATA,%rsi),%eax
25176 rol $8,%ax # ntohs()
25177 + pax_force_retaddr
25178 ret
25179
25180 sk_load_byte_ind:
25181 @@ -66,6 +69,7 @@ sk_load_byte:
25182 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25183 jle bpf_slow_path_byte
25184 movzbl (SKBDATA,%rsi),%eax
25185 + pax_force_retaddr
25186 ret
25187
25188 /**
25189 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25190 movzbl (SKBDATA,%rsi),%ebx
25191 and $15,%bl
25192 shl $2,%bl
25193 + pax_force_retaddr
25194 ret
25195 CFI_ENDPROC
25196 ENDPROC(sk_load_byte_msh)
25197 @@ -91,6 +96,7 @@ bpf_error:
25198 xor %eax,%eax
25199 mov -8(%rbp),%rbx
25200 leaveq
25201 + pax_force_retaddr
25202 ret
25203
25204 /* rsi contains offset and can be scratched */
25205 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25206 js bpf_error
25207 mov -12(%rbp),%eax
25208 bswap %eax
25209 + pax_force_retaddr
25210 ret
25211
25212 bpf_slow_path_half:
25213 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25214 mov -12(%rbp),%ax
25215 rol $8,%ax
25216 movzwl %ax,%eax
25217 + pax_force_retaddr
25218 ret
25219
25220 bpf_slow_path_byte:
25221 bpf_slow_path_common(1)
25222 js bpf_error
25223 movzbl -12(%rbp),%eax
25224 + pax_force_retaddr
25225 ret
25226
25227 bpf_slow_path_byte_msh:
25228 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25229 and $15,%al
25230 shl $2,%al
25231 xchg %eax,%ebx
25232 + pax_force_retaddr
25233 ret
25234 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25235 index 7c1b765..8c072c6 100644
25236 --- a/arch/x86/net/bpf_jit_comp.c
25237 +++ b/arch/x86/net/bpf_jit_comp.c
25238 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25239 set_fs(old_fs);
25240 }
25241
25242 +struct bpf_jit_work {
25243 + struct work_struct work;
25244 + void *image;
25245 +};
25246
25247 void bpf_jit_compile(struct sk_filter *fp)
25248 {
25249 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25250 if (addrs == NULL)
25251 return;
25252
25253 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25254 + if (!fp->work)
25255 + goto out;
25256 +
25257 /* Before first pass, make a rough estimation of addrs[]
25258 * each bpf instruction is translated to less than 64 bytes
25259 */
25260 @@ -476,7 +484,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25261 func = sk_load_word;
25262 common_load: seen |= SEEN_DATAREF;
25263 if ((int)K < 0)
25264 - goto out;
25265 + goto error;
25266 t_offset = func - (image + addrs[i]);
25267 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25268 EMIT1_off32(0xe8, t_offset); /* call */
25269 @@ -586,17 +594,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25270 break;
25271 default:
25272 /* hmm, too complex filter, give up with jit compiler */
25273 - goto out;
25274 + goto error;
25275 }
25276 ilen = prog - temp;
25277 if (image) {
25278 if (unlikely(proglen + ilen > oldproglen)) {
25279 pr_err("bpb_jit_compile fatal error\n");
25280 - kfree(addrs);
25281 - module_free(NULL, image);
25282 - return;
25283 + module_free_exec(NULL, image);
25284 + goto error;
25285 }
25286 + pax_open_kernel();
25287 memcpy(image + proglen, temp, ilen);
25288 + pax_close_kernel();
25289 }
25290 proglen += ilen;
25291 addrs[i] = proglen;
25292 @@ -617,11 +626,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25293 break;
25294 }
25295 if (proglen == oldproglen) {
25296 - image = module_alloc(max_t(unsigned int,
25297 - proglen,
25298 - sizeof(struct work_struct)));
25299 + image = module_alloc_exec(proglen);
25300 if (!image)
25301 - goto out;
25302 + goto error;
25303 }
25304 oldproglen = proglen;
25305 }
25306 @@ -637,7 +644,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25307 bpf_flush_icache(image, image + proglen);
25308
25309 fp->bpf_func = (void *)image;
25310 - }
25311 + } else
25312 +error:
25313 + kfree(fp->work);
25314 +
25315 out:
25316 kfree(addrs);
25317 return;
25318 @@ -645,18 +655,20 @@ out:
25319
25320 static void jit_free_defer(struct work_struct *arg)
25321 {
25322 - module_free(NULL, arg);
25323 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25324 + kfree(arg);
25325 }
25326
25327 /* run from softirq, we must use a work_struct to call
25328 - * module_free() from process context
25329 + * module_free_exec() from process context
25330 */
25331 void bpf_jit_free(struct sk_filter *fp)
25332 {
25333 if (fp->bpf_func != sk_run_filter) {
25334 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25335 + struct work_struct *work = &fp->work->work;
25336
25337 INIT_WORK(work, jit_free_defer);
25338 + fp->work->image = fp->bpf_func;
25339 schedule_work(work);
25340 }
25341 }
25342 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25343 index bff89df..377758a 100644
25344 --- a/arch/x86/oprofile/backtrace.c
25345 +++ b/arch/x86/oprofile/backtrace.c
25346 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25347 struct stack_frame_ia32 *fp;
25348 unsigned long bytes;
25349
25350 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25351 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25352 if (bytes != sizeof(bufhead))
25353 return NULL;
25354
25355 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25356 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25357
25358 oprofile_add_trace(bufhead[0].return_address);
25359
25360 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25361 struct stack_frame bufhead[2];
25362 unsigned long bytes;
25363
25364 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25365 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25366 if (bytes != sizeof(bufhead))
25367 return NULL;
25368
25369 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25370 {
25371 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25372
25373 - if (!user_mode_vm(regs)) {
25374 + if (!user_mode(regs)) {
25375 unsigned long stack = kernel_stack_pointer(regs);
25376 if (depth)
25377 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25378 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25379 index cb29191..036766d 100644
25380 --- a/arch/x86/pci/mrst.c
25381 +++ b/arch/x86/pci/mrst.c
25382 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25383 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25384 pci_mmcfg_late_init();
25385 pcibios_enable_irq = mrst_pci_irq_enable;
25386 - pci_root_ops = pci_mrst_ops;
25387 + pax_open_kernel();
25388 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25389 + pax_close_kernel();
25390 /* Continue with standard init */
25391 return 1;
25392 }
25393 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25394 index db0e9a5..0372c14 100644
25395 --- a/arch/x86/pci/pcbios.c
25396 +++ b/arch/x86/pci/pcbios.c
25397 @@ -79,50 +79,93 @@ union bios32 {
25398 static struct {
25399 unsigned long address;
25400 unsigned short segment;
25401 -} bios32_indirect = { 0, __KERNEL_CS };
25402 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25403
25404 /*
25405 * Returns the entry point for the given service, NULL on error
25406 */
25407
25408 -static unsigned long bios32_service(unsigned long service)
25409 +static unsigned long __devinit bios32_service(unsigned long service)
25410 {
25411 unsigned char return_code; /* %al */
25412 unsigned long address; /* %ebx */
25413 unsigned long length; /* %ecx */
25414 unsigned long entry; /* %edx */
25415 unsigned long flags;
25416 + struct desc_struct d, *gdt;
25417
25418 local_irq_save(flags);
25419 - __asm__("lcall *(%%edi); cld"
25420 +
25421 + gdt = get_cpu_gdt_table(smp_processor_id());
25422 +
25423 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25424 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25425 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25426 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25427 +
25428 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25429 : "=a" (return_code),
25430 "=b" (address),
25431 "=c" (length),
25432 "=d" (entry)
25433 : "0" (service),
25434 "1" (0),
25435 - "D" (&bios32_indirect));
25436 + "D" (&bios32_indirect),
25437 + "r"(__PCIBIOS_DS)
25438 + : "memory");
25439 +
25440 + pax_open_kernel();
25441 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25442 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25443 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25444 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25445 + pax_close_kernel();
25446 +
25447 local_irq_restore(flags);
25448
25449 switch (return_code) {
25450 - case 0:
25451 - return address + entry;
25452 - case 0x80: /* Not present */
25453 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25454 - return 0;
25455 - default: /* Shouldn't happen */
25456 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25457 - service, return_code);
25458 + case 0: {
25459 + int cpu;
25460 + unsigned char flags;
25461 +
25462 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25463 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25464 + printk(KERN_WARNING "bios32_service: not valid\n");
25465 return 0;
25466 + }
25467 + address = address + PAGE_OFFSET;
25468 + length += 16UL; /* some BIOSs underreport this... */
25469 + flags = 4;
25470 + if (length >= 64*1024*1024) {
25471 + length >>= PAGE_SHIFT;
25472 + flags |= 8;
25473 + }
25474 +
25475 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25476 + gdt = get_cpu_gdt_table(cpu);
25477 + pack_descriptor(&d, address, length, 0x9b, flags);
25478 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25479 + pack_descriptor(&d, address, length, 0x93, flags);
25480 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25481 + }
25482 + return entry;
25483 + }
25484 + case 0x80: /* Not present */
25485 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25486 + return 0;
25487 + default: /* Shouldn't happen */
25488 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25489 + service, return_code);
25490 + return 0;
25491 }
25492 }
25493
25494 static struct {
25495 unsigned long address;
25496 unsigned short segment;
25497 -} pci_indirect = { 0, __KERNEL_CS };
25498 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25499
25500 -static int pci_bios_present;
25501 +static int pci_bios_present __read_only;
25502
25503 static int __devinit check_pcibios(void)
25504 {
25505 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
25506 unsigned long flags, pcibios_entry;
25507
25508 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
25509 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
25510 + pci_indirect.address = pcibios_entry;
25511
25512 local_irq_save(flags);
25513 - __asm__(
25514 - "lcall *(%%edi); cld\n\t"
25515 + __asm__("movw %w6, %%ds\n\t"
25516 + "lcall *%%ss:(%%edi); cld\n\t"
25517 + "push %%ss\n\t"
25518 + "pop %%ds\n\t"
25519 "jc 1f\n\t"
25520 "xor %%ah, %%ah\n"
25521 "1:"
25522 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
25523 "=b" (ebx),
25524 "=c" (ecx)
25525 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
25526 - "D" (&pci_indirect)
25527 + "D" (&pci_indirect),
25528 + "r" (__PCIBIOS_DS)
25529 : "memory");
25530 local_irq_restore(flags);
25531
25532 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25533
25534 switch (len) {
25535 case 1:
25536 - __asm__("lcall *(%%esi); cld\n\t"
25537 + __asm__("movw %w6, %%ds\n\t"
25538 + "lcall *%%ss:(%%esi); cld\n\t"
25539 + "push %%ss\n\t"
25540 + "pop %%ds\n\t"
25541 "jc 1f\n\t"
25542 "xor %%ah, %%ah\n"
25543 "1:"
25544 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25545 : "1" (PCIBIOS_READ_CONFIG_BYTE),
25546 "b" (bx),
25547 "D" ((long)reg),
25548 - "S" (&pci_indirect));
25549 + "S" (&pci_indirect),
25550 + "r" (__PCIBIOS_DS));
25551 /*
25552 * Zero-extend the result beyond 8 bits, do not trust the
25553 * BIOS having done it:
25554 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25555 *value &= 0xff;
25556 break;
25557 case 2:
25558 - __asm__("lcall *(%%esi); cld\n\t"
25559 + __asm__("movw %w6, %%ds\n\t"
25560 + "lcall *%%ss:(%%esi); cld\n\t"
25561 + "push %%ss\n\t"
25562 + "pop %%ds\n\t"
25563 "jc 1f\n\t"
25564 "xor %%ah, %%ah\n"
25565 "1:"
25566 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25567 : "1" (PCIBIOS_READ_CONFIG_WORD),
25568 "b" (bx),
25569 "D" ((long)reg),
25570 - "S" (&pci_indirect));
25571 + "S" (&pci_indirect),
25572 + "r" (__PCIBIOS_DS));
25573 /*
25574 * Zero-extend the result beyond 16 bits, do not trust the
25575 * BIOS having done it:
25576 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25577 *value &= 0xffff;
25578 break;
25579 case 4:
25580 - __asm__("lcall *(%%esi); cld\n\t"
25581 + __asm__("movw %w6, %%ds\n\t"
25582 + "lcall *%%ss:(%%esi); cld\n\t"
25583 + "push %%ss\n\t"
25584 + "pop %%ds\n\t"
25585 "jc 1f\n\t"
25586 "xor %%ah, %%ah\n"
25587 "1:"
25588 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25589 : "1" (PCIBIOS_READ_CONFIG_DWORD),
25590 "b" (bx),
25591 "D" ((long)reg),
25592 - "S" (&pci_indirect));
25593 + "S" (&pci_indirect),
25594 + "r" (__PCIBIOS_DS));
25595 break;
25596 }
25597
25598 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25599
25600 switch (len) {
25601 case 1:
25602 - __asm__("lcall *(%%esi); cld\n\t"
25603 + __asm__("movw %w6, %%ds\n\t"
25604 + "lcall *%%ss:(%%esi); cld\n\t"
25605 + "push %%ss\n\t"
25606 + "pop %%ds\n\t"
25607 "jc 1f\n\t"
25608 "xor %%ah, %%ah\n"
25609 "1:"
25610 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25611 "c" (value),
25612 "b" (bx),
25613 "D" ((long)reg),
25614 - "S" (&pci_indirect));
25615 + "S" (&pci_indirect),
25616 + "r" (__PCIBIOS_DS));
25617 break;
25618 case 2:
25619 - __asm__("lcall *(%%esi); cld\n\t"
25620 + __asm__("movw %w6, %%ds\n\t"
25621 + "lcall *%%ss:(%%esi); cld\n\t"
25622 + "push %%ss\n\t"
25623 + "pop %%ds\n\t"
25624 "jc 1f\n\t"
25625 "xor %%ah, %%ah\n"
25626 "1:"
25627 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25628 "c" (value),
25629 "b" (bx),
25630 "D" ((long)reg),
25631 - "S" (&pci_indirect));
25632 + "S" (&pci_indirect),
25633 + "r" (__PCIBIOS_DS));
25634 break;
25635 case 4:
25636 - __asm__("lcall *(%%esi); cld\n\t"
25637 + __asm__("movw %w6, %%ds\n\t"
25638 + "lcall *%%ss:(%%esi); cld\n\t"
25639 + "push %%ss\n\t"
25640 + "pop %%ds\n\t"
25641 "jc 1f\n\t"
25642 "xor %%ah, %%ah\n"
25643 "1:"
25644 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25645 "c" (value),
25646 "b" (bx),
25647 "D" ((long)reg),
25648 - "S" (&pci_indirect));
25649 + "S" (&pci_indirect),
25650 + "r" (__PCIBIOS_DS));
25651 break;
25652 }
25653
25654 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25655
25656 DBG("PCI: Fetching IRQ routing table... ");
25657 __asm__("push %%es\n\t"
25658 + "movw %w8, %%ds\n\t"
25659 "push %%ds\n\t"
25660 "pop %%es\n\t"
25661 - "lcall *(%%esi); cld\n\t"
25662 + "lcall *%%ss:(%%esi); cld\n\t"
25663 "pop %%es\n\t"
25664 + "push %%ss\n\t"
25665 + "pop %%ds\n"
25666 "jc 1f\n\t"
25667 "xor %%ah, %%ah\n"
25668 "1:"
25669 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25670 "1" (0),
25671 "D" ((long) &opt),
25672 "S" (&pci_indirect),
25673 - "m" (opt)
25674 + "m" (opt),
25675 + "r" (__PCIBIOS_DS)
25676 : "memory");
25677 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
25678 if (ret & 0xff00)
25679 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25680 {
25681 int ret;
25682
25683 - __asm__("lcall *(%%esi); cld\n\t"
25684 + __asm__("movw %w5, %%ds\n\t"
25685 + "lcall *%%ss:(%%esi); cld\n\t"
25686 + "push %%ss\n\t"
25687 + "pop %%ds\n"
25688 "jc 1f\n\t"
25689 "xor %%ah, %%ah\n"
25690 "1:"
25691 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25692 : "0" (PCIBIOS_SET_PCI_HW_INT),
25693 "b" ((dev->bus->number << 8) | dev->devfn),
25694 "c" ((irq << 8) | (pin + 10)),
25695 - "S" (&pci_indirect));
25696 + "S" (&pci_indirect),
25697 + "r" (__PCIBIOS_DS));
25698 return !(ret & 0xff00);
25699 }
25700 EXPORT_SYMBOL(pcibios_set_irq_routing);
25701 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
25702 index 40e4469..1ab536e 100644
25703 --- a/arch/x86/platform/efi/efi_32.c
25704 +++ b/arch/x86/platform/efi/efi_32.c
25705 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
25706 {
25707 struct desc_ptr gdt_descr;
25708
25709 +#ifdef CONFIG_PAX_KERNEXEC
25710 + struct desc_struct d;
25711 +#endif
25712 +
25713 local_irq_save(efi_rt_eflags);
25714
25715 load_cr3(initial_page_table);
25716 __flush_tlb_all();
25717
25718 +#ifdef CONFIG_PAX_KERNEXEC
25719 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
25720 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25721 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
25722 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25723 +#endif
25724 +
25725 gdt_descr.address = __pa(get_cpu_gdt_table(0));
25726 gdt_descr.size = GDT_SIZE - 1;
25727 load_gdt(&gdt_descr);
25728 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
25729 {
25730 struct desc_ptr gdt_descr;
25731
25732 +#ifdef CONFIG_PAX_KERNEXEC
25733 + struct desc_struct d;
25734 +
25735 + memset(&d, 0, sizeof d);
25736 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25737 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25738 +#endif
25739 +
25740 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
25741 gdt_descr.size = GDT_SIZE - 1;
25742 load_gdt(&gdt_descr);
25743 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
25744 index fbe66e6..c5c0dd2 100644
25745 --- a/arch/x86/platform/efi/efi_stub_32.S
25746 +++ b/arch/x86/platform/efi/efi_stub_32.S
25747 @@ -6,7 +6,9 @@
25748 */
25749
25750 #include <linux/linkage.h>
25751 +#include <linux/init.h>
25752 #include <asm/page_types.h>
25753 +#include <asm/segment.h>
25754
25755 /*
25756 * efi_call_phys(void *, ...) is a function with variable parameters.
25757 @@ -20,7 +22,7 @@
25758 * service functions will comply with gcc calling convention, too.
25759 */
25760
25761 -.text
25762 +__INIT
25763 ENTRY(efi_call_phys)
25764 /*
25765 * 0. The function can only be called in Linux kernel. So CS has been
25766 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
25767 * The mapping of lower virtual memory has been created in prelog and
25768 * epilog.
25769 */
25770 - movl $1f, %edx
25771 - subl $__PAGE_OFFSET, %edx
25772 - jmp *%edx
25773 + movl $(__KERNEXEC_EFI_DS), %edx
25774 + mov %edx, %ds
25775 + mov %edx, %es
25776 + mov %edx, %ss
25777 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
25778 1:
25779
25780 /*
25781 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
25782 * parameter 2, ..., param n. To make things easy, we save the return
25783 * address of efi_call_phys in a global variable.
25784 */
25785 - popl %edx
25786 - movl %edx, saved_return_addr
25787 - /* get the function pointer into ECX*/
25788 - popl %ecx
25789 - movl %ecx, efi_rt_function_ptr
25790 - movl $2f, %edx
25791 - subl $__PAGE_OFFSET, %edx
25792 - pushl %edx
25793 + popl (saved_return_addr)
25794 + popl (efi_rt_function_ptr)
25795
25796 /*
25797 * 3. Clear PG bit in %CR0.
25798 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
25799 /*
25800 * 5. Call the physical function.
25801 */
25802 - jmp *%ecx
25803 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
25804
25805 -2:
25806 /*
25807 * 6. After EFI runtime service returns, control will return to
25808 * following instruction. We'd better readjust stack pointer first.
25809 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
25810 movl %cr0, %edx
25811 orl $0x80000000, %edx
25812 movl %edx, %cr0
25813 - jmp 1f
25814 -1:
25815 +
25816 /*
25817 * 8. Now restore the virtual mode from flat mode by
25818 * adding EIP with PAGE_OFFSET.
25819 */
25820 - movl $1f, %edx
25821 - jmp *%edx
25822 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
25823 1:
25824 + movl $(__KERNEL_DS), %edx
25825 + mov %edx, %ds
25826 + mov %edx, %es
25827 + mov %edx, %ss
25828
25829 /*
25830 * 9. Balance the stack. And because EAX contain the return value,
25831 * we'd better not clobber it.
25832 */
25833 - leal efi_rt_function_ptr, %edx
25834 - movl (%edx), %ecx
25835 - pushl %ecx
25836 + pushl (efi_rt_function_ptr)
25837
25838 /*
25839 - * 10. Push the saved return address onto the stack and return.
25840 + * 10. Return to the saved return address.
25841 */
25842 - leal saved_return_addr, %edx
25843 - movl (%edx), %ecx
25844 - pushl %ecx
25845 - ret
25846 + jmpl *(saved_return_addr)
25847 ENDPROC(efi_call_phys)
25848 .previous
25849
25850 -.data
25851 +__INITDATA
25852 saved_return_addr:
25853 .long 0
25854 efi_rt_function_ptr:
25855 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
25856 index 4c07cca..2c8427d 100644
25857 --- a/arch/x86/platform/efi/efi_stub_64.S
25858 +++ b/arch/x86/platform/efi/efi_stub_64.S
25859 @@ -7,6 +7,7 @@
25860 */
25861
25862 #include <linux/linkage.h>
25863 +#include <asm/alternative-asm.h>
25864
25865 #define SAVE_XMM \
25866 mov %rsp, %rax; \
25867 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
25868 call *%rdi
25869 addq $32, %rsp
25870 RESTORE_XMM
25871 + pax_force_retaddr 0, 1
25872 ret
25873 ENDPROC(efi_call0)
25874
25875 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
25876 call *%rdi
25877 addq $32, %rsp
25878 RESTORE_XMM
25879 + pax_force_retaddr 0, 1
25880 ret
25881 ENDPROC(efi_call1)
25882
25883 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
25884 call *%rdi
25885 addq $32, %rsp
25886 RESTORE_XMM
25887 + pax_force_retaddr 0, 1
25888 ret
25889 ENDPROC(efi_call2)
25890
25891 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
25892 call *%rdi
25893 addq $32, %rsp
25894 RESTORE_XMM
25895 + pax_force_retaddr 0, 1
25896 ret
25897 ENDPROC(efi_call3)
25898
25899 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
25900 call *%rdi
25901 addq $32, %rsp
25902 RESTORE_XMM
25903 + pax_force_retaddr 0, 1
25904 ret
25905 ENDPROC(efi_call4)
25906
25907 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
25908 call *%rdi
25909 addq $48, %rsp
25910 RESTORE_XMM
25911 + pax_force_retaddr 0, 1
25912 ret
25913 ENDPROC(efi_call5)
25914
25915 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
25916 call *%rdi
25917 addq $48, %rsp
25918 RESTORE_XMM
25919 + pax_force_retaddr 0, 1
25920 ret
25921 ENDPROC(efi_call6)
25922 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
25923 index ad4ec1c..686479e 100644
25924 --- a/arch/x86/platform/mrst/mrst.c
25925 +++ b/arch/x86/platform/mrst/mrst.c
25926 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
25927 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
25928 int sfi_mrtc_num;
25929
25930 -static void mrst_power_off(void)
25931 +static __noreturn void mrst_power_off(void)
25932 {
25933 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25934 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
25935 + BUG();
25936 }
25937
25938 -static void mrst_reboot(void)
25939 +static __noreturn void mrst_reboot(void)
25940 {
25941 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25942 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
25943 else
25944 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
25945 + BUG();
25946 }
25947
25948 /* parse all the mtimer info to a static mtimer array */
25949 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
25950 index f10c0af..3ec1f95 100644
25951 --- a/arch/x86/power/cpu.c
25952 +++ b/arch/x86/power/cpu.c
25953 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
25954 static void fix_processor_context(void)
25955 {
25956 int cpu = smp_processor_id();
25957 - struct tss_struct *t = &per_cpu(init_tss, cpu);
25958 + struct tss_struct *t = init_tss + cpu;
25959
25960 set_tss_desc(cpu, t); /*
25961 * This just modifies memory; should not be
25962 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
25963 */
25964
25965 #ifdef CONFIG_X86_64
25966 + pax_open_kernel();
25967 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
25968 + pax_close_kernel();
25969
25970 syscall_init(); /* This sets MSR_*STAR and related */
25971 #endif
25972 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
25973 index 5d17950..2253fc9 100644
25974 --- a/arch/x86/vdso/Makefile
25975 +++ b/arch/x86/vdso/Makefile
25976 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
25977 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
25978 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
25979
25980 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25981 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25982 GCOV_PROFILE := n
25983
25984 #
25985 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
25986 index 468d591..8e80a0a 100644
25987 --- a/arch/x86/vdso/vdso32-setup.c
25988 +++ b/arch/x86/vdso/vdso32-setup.c
25989 @@ -25,6 +25,7 @@
25990 #include <asm/tlbflush.h>
25991 #include <asm/vdso.h>
25992 #include <asm/proto.h>
25993 +#include <asm/mman.h>
25994
25995 enum {
25996 VDSO_DISABLED = 0,
25997 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
25998 void enable_sep_cpu(void)
25999 {
26000 int cpu = get_cpu();
26001 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26002 + struct tss_struct *tss = init_tss + cpu;
26003
26004 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26005 put_cpu();
26006 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26007 gate_vma.vm_start = FIXADDR_USER_START;
26008 gate_vma.vm_end = FIXADDR_USER_END;
26009 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26010 - gate_vma.vm_page_prot = __P101;
26011 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26012 /*
26013 * Make sure the vDSO gets into every core dump.
26014 * Dumping its contents makes post-mortem fully interpretable later
26015 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26016 if (compat)
26017 addr = VDSO_HIGH_BASE;
26018 else {
26019 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26020 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26021 if (IS_ERR_VALUE(addr)) {
26022 ret = addr;
26023 goto up_fail;
26024 }
26025 }
26026
26027 - current->mm->context.vdso = (void *)addr;
26028 + current->mm->context.vdso = addr;
26029
26030 if (compat_uses_vma || !compat) {
26031 /*
26032 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26033 }
26034
26035 current_thread_info()->sysenter_return =
26036 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26037 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26038
26039 up_fail:
26040 if (ret)
26041 - current->mm->context.vdso = NULL;
26042 + current->mm->context.vdso = 0;
26043
26044 up_write(&mm->mmap_sem);
26045
26046 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26047
26048 const char *arch_vma_name(struct vm_area_struct *vma)
26049 {
26050 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26051 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26052 return "[vdso]";
26053 +
26054 +#ifdef CONFIG_PAX_SEGMEXEC
26055 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26056 + return "[vdso]";
26057 +#endif
26058 +
26059 return NULL;
26060 }
26061
26062 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26063 * Check to see if the corresponding task was created in compat vdso
26064 * mode.
26065 */
26066 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26067 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26068 return &gate_vma;
26069 return NULL;
26070 }
26071 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26072 index 153407c..611cba9 100644
26073 --- a/arch/x86/vdso/vma.c
26074 +++ b/arch/x86/vdso/vma.c
26075 @@ -16,8 +16,6 @@
26076 #include <asm/vdso.h>
26077 #include <asm/page.h>
26078
26079 -unsigned int __read_mostly vdso_enabled = 1;
26080 -
26081 extern char vdso_start[], vdso_end[];
26082 extern unsigned short vdso_sync_cpuid;
26083
26084 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26085 * unaligned here as a result of stack start randomization.
26086 */
26087 addr = PAGE_ALIGN(addr);
26088 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26089
26090 return addr;
26091 }
26092 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26093 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26094 {
26095 struct mm_struct *mm = current->mm;
26096 - unsigned long addr;
26097 + unsigned long addr = 0;
26098 int ret;
26099
26100 - if (!vdso_enabled)
26101 - return 0;
26102 -
26103 down_write(&mm->mmap_sem);
26104 +
26105 +#ifdef CONFIG_PAX_RANDMMAP
26106 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26107 +#endif
26108 +
26109 addr = vdso_addr(mm->start_stack, vdso_size);
26110 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26111 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26112 if (IS_ERR_VALUE(addr)) {
26113 ret = addr;
26114 goto up_fail;
26115 }
26116
26117 - current->mm->context.vdso = (void *)addr;
26118 + mm->context.vdso = addr;
26119
26120 ret = install_special_mapping(mm, addr, vdso_size,
26121 VM_READ|VM_EXEC|
26122 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26123 VM_ALWAYSDUMP,
26124 vdso_pages);
26125 - if (ret) {
26126 - current->mm->context.vdso = NULL;
26127 - goto up_fail;
26128 - }
26129 +
26130 + if (ret)
26131 + mm->context.vdso = 0;
26132
26133 up_fail:
26134 up_write(&mm->mmap_sem);
26135 return ret;
26136 }
26137 -
26138 -static __init int vdso_setup(char *s)
26139 -{
26140 - vdso_enabled = simple_strtoul(s, NULL, 0);
26141 - return 0;
26142 -}
26143 -__setup("vdso=", vdso_setup);
26144 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26145 index 1f92865..c843b20 100644
26146 --- a/arch/x86/xen/enlighten.c
26147 +++ b/arch/x86/xen/enlighten.c
26148 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26149
26150 struct shared_info xen_dummy_shared_info;
26151
26152 -void *xen_initial_gdt;
26153 -
26154 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26155 __read_mostly int xen_have_vector_callback;
26156 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26157 @@ -1029,7 +1027,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26158 #endif
26159 };
26160
26161 -static void xen_reboot(int reason)
26162 +static __noreturn void xen_reboot(int reason)
26163 {
26164 struct sched_shutdown r = { .reason = reason };
26165
26166 @@ -1037,17 +1035,17 @@ static void xen_reboot(int reason)
26167 BUG();
26168 }
26169
26170 -static void xen_restart(char *msg)
26171 +static __noreturn void xen_restart(char *msg)
26172 {
26173 xen_reboot(SHUTDOWN_reboot);
26174 }
26175
26176 -static void xen_emergency_restart(void)
26177 +static __noreturn void xen_emergency_restart(void)
26178 {
26179 xen_reboot(SHUTDOWN_reboot);
26180 }
26181
26182 -static void xen_machine_halt(void)
26183 +static __noreturn void xen_machine_halt(void)
26184 {
26185 xen_reboot(SHUTDOWN_poweroff);
26186 }
26187 @@ -1153,7 +1151,17 @@ asmlinkage void __init xen_start_kernel(void)
26188 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26189
26190 /* Work out if we support NX */
26191 - x86_configure_nx();
26192 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26193 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26194 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26195 + unsigned l, h;
26196 +
26197 + __supported_pte_mask |= _PAGE_NX;
26198 + rdmsr(MSR_EFER, l, h);
26199 + l |= EFER_NX;
26200 + wrmsr(MSR_EFER, l, h);
26201 + }
26202 +#endif
26203
26204 xen_setup_features();
26205
26206 @@ -1184,13 +1192,6 @@ asmlinkage void __init xen_start_kernel(void)
26207
26208 machine_ops = xen_machine_ops;
26209
26210 - /*
26211 - * The only reliable way to retain the initial address of the
26212 - * percpu gdt_page is to remember it here, so we can go and
26213 - * mark it RW later, when the initial percpu area is freed.
26214 - */
26215 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26216 -
26217 xen_smp_init();
26218
26219 #ifdef CONFIG_ACPI_NUMA
26220 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26221 index 87f6673..e2555a6 100644
26222 --- a/arch/x86/xen/mmu.c
26223 +++ b/arch/x86/xen/mmu.c
26224 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26225 convert_pfn_mfn(init_level4_pgt);
26226 convert_pfn_mfn(level3_ident_pgt);
26227 convert_pfn_mfn(level3_kernel_pgt);
26228 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26229 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26230 + convert_pfn_mfn(level3_vmemmap_pgt);
26231
26232 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26233 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26234 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26235 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26236 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26237 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26238 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26239 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26240 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26241 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26242 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26243 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26244 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26245
26246 @@ -1962,6 +1969,7 @@ static void __init xen_post_allocator_init(void)
26247 pv_mmu_ops.set_pud = xen_set_pud;
26248 #if PAGETABLE_LEVELS == 4
26249 pv_mmu_ops.set_pgd = xen_set_pgd;
26250 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26251 #endif
26252
26253 /* This will work as long as patching hasn't happened yet
26254 @@ -2043,6 +2051,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26255 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26256 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26257 .set_pgd = xen_set_pgd_hyper,
26258 + .set_pgd_batched = xen_set_pgd_hyper,
26259
26260 .alloc_pud = xen_alloc_pmd_init,
26261 .release_pud = xen_release_pmd_init,
26262 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26263 index 041d4fe..7666b7e 100644
26264 --- a/arch/x86/xen/smp.c
26265 +++ b/arch/x86/xen/smp.c
26266 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26267 {
26268 BUG_ON(smp_processor_id() != 0);
26269 native_smp_prepare_boot_cpu();
26270 -
26271 - /* We've switched to the "real" per-cpu gdt, so make sure the
26272 - old memory can be recycled */
26273 - make_lowmem_page_readwrite(xen_initial_gdt);
26274 -
26275 xen_filter_cpu_maps();
26276 xen_setup_vcpu_info_placement();
26277 }
26278 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26279 gdt = get_cpu_gdt_table(cpu);
26280
26281 ctxt->flags = VGCF_IN_KERNEL;
26282 - ctxt->user_regs.ds = __USER_DS;
26283 - ctxt->user_regs.es = __USER_DS;
26284 + ctxt->user_regs.ds = __KERNEL_DS;
26285 + ctxt->user_regs.es = __KERNEL_DS;
26286 ctxt->user_regs.ss = __KERNEL_DS;
26287 #ifdef CONFIG_X86_32
26288 ctxt->user_regs.fs = __KERNEL_PERCPU;
26289 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26290 + savesegment(gs, ctxt->user_regs.gs);
26291 #else
26292 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26293 #endif
26294 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26295 int rc;
26296
26297 per_cpu(current_task, cpu) = idle;
26298 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26299 #ifdef CONFIG_X86_32
26300 irq_ctx_init(cpu);
26301 #else
26302 clear_tsk_thread_flag(idle, TIF_FORK);
26303 - per_cpu(kernel_stack, cpu) =
26304 - (unsigned long)task_stack_page(idle) -
26305 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26306 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26307 #endif
26308 xen_setup_runstate_info(cpu);
26309 xen_setup_timer(cpu);
26310 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26311 index b040b0e..8cc4fe0 100644
26312 --- a/arch/x86/xen/xen-asm_32.S
26313 +++ b/arch/x86/xen/xen-asm_32.S
26314 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26315 ESP_OFFSET=4 # bytes pushed onto stack
26316
26317 /*
26318 - * Store vcpu_info pointer for easy access. Do it this way to
26319 - * avoid having to reload %fs
26320 + * Store vcpu_info pointer for easy access.
26321 */
26322 #ifdef CONFIG_SMP
26323 - GET_THREAD_INFO(%eax)
26324 - movl TI_cpu(%eax), %eax
26325 - movl __per_cpu_offset(,%eax,4), %eax
26326 - mov xen_vcpu(%eax), %eax
26327 + push %fs
26328 + mov $(__KERNEL_PERCPU), %eax
26329 + mov %eax, %fs
26330 + mov PER_CPU_VAR(xen_vcpu), %eax
26331 + pop %fs
26332 #else
26333 movl xen_vcpu, %eax
26334 #endif
26335 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26336 index aaa7291..3f77960 100644
26337 --- a/arch/x86/xen/xen-head.S
26338 +++ b/arch/x86/xen/xen-head.S
26339 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
26340 #ifdef CONFIG_X86_32
26341 mov %esi,xen_start_info
26342 mov $init_thread_union+THREAD_SIZE,%esp
26343 +#ifdef CONFIG_SMP
26344 + movl $cpu_gdt_table,%edi
26345 + movl $__per_cpu_load,%eax
26346 + movw %ax,__KERNEL_PERCPU + 2(%edi)
26347 + rorl $16,%eax
26348 + movb %al,__KERNEL_PERCPU + 4(%edi)
26349 + movb %ah,__KERNEL_PERCPU + 7(%edi)
26350 + movl $__per_cpu_end - 1,%eax
26351 + subl $__per_cpu_start,%eax
26352 + movw %ax,__KERNEL_PERCPU + 0(%edi)
26353 +#endif
26354 #else
26355 mov %rsi,xen_start_info
26356 mov $init_thread_union+THREAD_SIZE,%rsp
26357 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26358 index b095739..8c17bcd 100644
26359 --- a/arch/x86/xen/xen-ops.h
26360 +++ b/arch/x86/xen/xen-ops.h
26361 @@ -10,8 +10,6 @@
26362 extern const char xen_hypervisor_callback[];
26363 extern const char xen_failsafe_callback[];
26364
26365 -extern void *xen_initial_gdt;
26366 -
26367 struct trap_info;
26368 void xen_copy_trap_info(struct trap_info *traps);
26369
26370 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26371 index 525bd3d..ef888b1 100644
26372 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
26373 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26374 @@ -119,9 +119,9 @@
26375 ----------------------------------------------------------------------*/
26376
26377 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26378 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26379 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26380 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26381 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26382
26383 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26384 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26385 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26386 index 2f33760..835e50a 100644
26387 --- a/arch/xtensa/variants/fsf/include/variant/core.h
26388 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
26389 @@ -11,6 +11,7 @@
26390 #ifndef _XTENSA_CORE_H
26391 #define _XTENSA_CORE_H
26392
26393 +#include <linux/const.h>
26394
26395 /****************************************************************************
26396 Parameters Useful for Any Code, USER or PRIVILEGED
26397 @@ -112,9 +113,9 @@
26398 ----------------------------------------------------------------------*/
26399
26400 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26401 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26402 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26403 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26404 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26405
26406 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26407 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26408 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26409 index af00795..2bb8105 100644
26410 --- a/arch/xtensa/variants/s6000/include/variant/core.h
26411 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
26412 @@ -11,6 +11,7 @@
26413 #ifndef _XTENSA_CORE_CONFIGURATION_H
26414 #define _XTENSA_CORE_CONFIGURATION_H
26415
26416 +#include <linux/const.h>
26417
26418 /****************************************************************************
26419 Parameters Useful for Any Code, USER or PRIVILEGED
26420 @@ -118,9 +119,9 @@
26421 ----------------------------------------------------------------------*/
26422
26423 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26424 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26425 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26426 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26427 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26428
26429 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26430 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26431 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26432 index 58916af..9cb880b 100644
26433 --- a/block/blk-iopoll.c
26434 +++ b/block/blk-iopoll.c
26435 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26436 }
26437 EXPORT_SYMBOL(blk_iopoll_complete);
26438
26439 -static void blk_iopoll_softirq(struct softirq_action *h)
26440 +static void blk_iopoll_softirq(void)
26441 {
26442 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26443 int rearm = 0, budget = blk_iopoll_budget;
26444 diff --git a/block/blk-map.c b/block/blk-map.c
26445 index 623e1cd..ca1e109 100644
26446 --- a/block/blk-map.c
26447 +++ b/block/blk-map.c
26448 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26449 if (!len || !kbuf)
26450 return -EINVAL;
26451
26452 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26453 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26454 if (do_copy)
26455 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26456 else
26457 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26458 index 1366a89..e17f54b 100644
26459 --- a/block/blk-softirq.c
26460 +++ b/block/blk-softirq.c
26461 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26462 * Softirq action handler - move entries to local list and loop over them
26463 * while passing them to the queue registered handler.
26464 */
26465 -static void blk_done_softirq(struct softirq_action *h)
26466 +static void blk_done_softirq(void)
26467 {
26468 struct list_head *cpu_list, local_list;
26469
26470 diff --git a/block/bsg.c b/block/bsg.c
26471 index c0ab25c..9d49f8f 100644
26472 --- a/block/bsg.c
26473 +++ b/block/bsg.c
26474 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26475 struct sg_io_v4 *hdr, struct bsg_device *bd,
26476 fmode_t has_write_perm)
26477 {
26478 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26479 + unsigned char *cmdptr;
26480 +
26481 if (hdr->request_len > BLK_MAX_CDB) {
26482 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
26483 if (!rq->cmd)
26484 return -ENOMEM;
26485 - }
26486 + cmdptr = rq->cmd;
26487 + } else
26488 + cmdptr = tmpcmd;
26489
26490 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
26491 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
26492 hdr->request_len))
26493 return -EFAULT;
26494
26495 + if (cmdptr != rq->cmd)
26496 + memcpy(rq->cmd, cmdptr, hdr->request_len);
26497 +
26498 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
26499 if (blk_verify_command(rq->cmd, has_write_perm))
26500 return -EPERM;
26501 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
26502 index 7b72502..646105c 100644
26503 --- a/block/compat_ioctl.c
26504 +++ b/block/compat_ioctl.c
26505 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
26506 err |= __get_user(f->spec1, &uf->spec1);
26507 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
26508 err |= __get_user(name, &uf->name);
26509 - f->name = compat_ptr(name);
26510 + f->name = (void __force_kernel *)compat_ptr(name);
26511 if (err) {
26512 err = -EFAULT;
26513 goto out;
26514 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
26515 index 688be8a..8a37d98 100644
26516 --- a/block/scsi_ioctl.c
26517 +++ b/block/scsi_ioctl.c
26518 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
26519 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
26520 struct sg_io_hdr *hdr, fmode_t mode)
26521 {
26522 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
26523 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26524 + unsigned char *cmdptr;
26525 +
26526 + if (rq->cmd != rq->__cmd)
26527 + cmdptr = rq->cmd;
26528 + else
26529 + cmdptr = tmpcmd;
26530 +
26531 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
26532 return -EFAULT;
26533 +
26534 + if (cmdptr != rq->cmd)
26535 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
26536 +
26537 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
26538 return -EPERM;
26539
26540 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26541 int err;
26542 unsigned int in_len, out_len, bytes, opcode, cmdlen;
26543 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
26544 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26545 + unsigned char *cmdptr;
26546
26547 if (!sic)
26548 return -EINVAL;
26549 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26550 */
26551 err = -EFAULT;
26552 rq->cmd_len = cmdlen;
26553 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
26554 +
26555 + if (rq->cmd != rq->__cmd)
26556 + cmdptr = rq->cmd;
26557 + else
26558 + cmdptr = tmpcmd;
26559 +
26560 + if (copy_from_user(cmdptr, sic->data, cmdlen))
26561 goto error;
26562
26563 + if (rq->cmd != cmdptr)
26564 + memcpy(rq->cmd, cmdptr, cmdlen);
26565 +
26566 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
26567 goto error;
26568
26569 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
26570 index 671d4d6..5f24030 100644
26571 --- a/crypto/cryptd.c
26572 +++ b/crypto/cryptd.c
26573 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
26574
26575 struct cryptd_blkcipher_request_ctx {
26576 crypto_completion_t complete;
26577 -};
26578 +} __no_const;
26579
26580 struct cryptd_hash_ctx {
26581 struct crypto_shash *child;
26582 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
26583
26584 struct cryptd_aead_request_ctx {
26585 crypto_completion_t complete;
26586 -};
26587 +} __no_const;
26588
26589 static void cryptd_queue_worker(struct work_struct *work);
26590
26591 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
26592 index 5d41894..22021e4 100644
26593 --- a/drivers/acpi/apei/cper.c
26594 +++ b/drivers/acpi/apei/cper.c
26595 @@ -38,12 +38,12 @@
26596 */
26597 u64 cper_next_record_id(void)
26598 {
26599 - static atomic64_t seq;
26600 + static atomic64_unchecked_t seq;
26601
26602 - if (!atomic64_read(&seq))
26603 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
26604 + if (!atomic64_read_unchecked(&seq))
26605 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
26606
26607 - return atomic64_inc_return(&seq);
26608 + return atomic64_inc_return_unchecked(&seq);
26609 }
26610 EXPORT_SYMBOL_GPL(cper_next_record_id);
26611
26612 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
26613 index 6c47ae9..abfdd63 100644
26614 --- a/drivers/acpi/ec_sys.c
26615 +++ b/drivers/acpi/ec_sys.c
26616 @@ -12,6 +12,7 @@
26617 #include <linux/acpi.h>
26618 #include <linux/debugfs.h>
26619 #include <linux/module.h>
26620 +#include <linux/uaccess.h>
26621 #include "internal.h"
26622
26623 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
26624 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26625 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
26626 */
26627 unsigned int size = EC_SPACE_SIZE;
26628 - u8 *data = (u8 *) buf;
26629 + u8 data;
26630 loff_t init_off = *off;
26631 int err = 0;
26632
26633 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26634 size = count;
26635
26636 while (size) {
26637 - err = ec_read(*off, &data[*off - init_off]);
26638 + err = ec_read(*off, &data);
26639 if (err)
26640 return err;
26641 + if (put_user(data, &buf[*off - init_off]))
26642 + return -EFAULT;
26643 *off += 1;
26644 size--;
26645 }
26646 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26647
26648 unsigned int size = count;
26649 loff_t init_off = *off;
26650 - u8 *data = (u8 *) buf;
26651 int err = 0;
26652
26653 if (*off >= EC_SPACE_SIZE)
26654 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26655 }
26656
26657 while (size) {
26658 - u8 byte_write = data[*off - init_off];
26659 + u8 byte_write;
26660 + if (get_user(byte_write, &buf[*off - init_off]))
26661 + return -EFAULT;
26662 err = ec_write(*off, byte_write);
26663 if (err)
26664 return err;
26665 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
26666 index 251c7b62..000462d 100644
26667 --- a/drivers/acpi/proc.c
26668 +++ b/drivers/acpi/proc.c
26669 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
26670 size_t count, loff_t * ppos)
26671 {
26672 struct list_head *node, *next;
26673 - char strbuf[5];
26674 - char str[5] = "";
26675 - unsigned int len = count;
26676 + char strbuf[5] = {0};
26677
26678 - if (len > 4)
26679 - len = 4;
26680 - if (len < 0)
26681 + if (count > 4)
26682 + count = 4;
26683 + if (copy_from_user(strbuf, buffer, count))
26684 return -EFAULT;
26685 -
26686 - if (copy_from_user(strbuf, buffer, len))
26687 - return -EFAULT;
26688 - strbuf[len] = '\0';
26689 - sscanf(strbuf, "%s", str);
26690 + strbuf[count] = '\0';
26691
26692 mutex_lock(&acpi_device_lock);
26693 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
26694 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
26695 if (!dev->wakeup.flags.valid)
26696 continue;
26697
26698 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
26699 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
26700 if (device_can_wakeup(&dev->dev)) {
26701 bool enable = !device_may_wakeup(&dev->dev);
26702 device_set_wakeup_enable(&dev->dev, enable);
26703 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
26704 index 9d7bc9f..a6fc091 100644
26705 --- a/drivers/acpi/processor_driver.c
26706 +++ b/drivers/acpi/processor_driver.c
26707 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
26708 return 0;
26709 #endif
26710
26711 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
26712 + BUG_ON(pr->id >= nr_cpu_ids);
26713
26714 /*
26715 * Buggy BIOS check
26716 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
26717 index c04ad68..0b99473 100644
26718 --- a/drivers/ata/libata-core.c
26719 +++ b/drivers/ata/libata-core.c
26720 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
26721 struct ata_port *ap;
26722 unsigned int tag;
26723
26724 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26725 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26726 ap = qc->ap;
26727
26728 qc->flags = 0;
26729 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
26730 struct ata_port *ap;
26731 struct ata_link *link;
26732
26733 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26734 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26735 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
26736 ap = qc->ap;
26737 link = qc->dev->link;
26738 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26739 return;
26740
26741 spin_lock(&lock);
26742 + pax_open_kernel();
26743
26744 for (cur = ops->inherits; cur; cur = cur->inherits) {
26745 void **inherit = (void **)cur;
26746 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26747 if (IS_ERR(*pp))
26748 *pp = NULL;
26749
26750 - ops->inherits = NULL;
26751 + *(struct ata_port_operations **)&ops->inherits = NULL;
26752
26753 + pax_close_kernel();
26754 spin_unlock(&lock);
26755 }
26756
26757 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
26758 index e8574bb..f9f6a72 100644
26759 --- a/drivers/ata/pata_arasan_cf.c
26760 +++ b/drivers/ata/pata_arasan_cf.c
26761 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
26762 /* Handle platform specific quirks */
26763 if (pdata->quirk) {
26764 if (pdata->quirk & CF_BROKEN_PIO) {
26765 - ap->ops->set_piomode = NULL;
26766 + pax_open_kernel();
26767 + *(void **)&ap->ops->set_piomode = NULL;
26768 + pax_close_kernel();
26769 ap->pio_mask = 0;
26770 }
26771 if (pdata->quirk & CF_BROKEN_MWDMA)
26772 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
26773 index f9b983a..887b9d8 100644
26774 --- a/drivers/atm/adummy.c
26775 +++ b/drivers/atm/adummy.c
26776 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
26777 vcc->pop(vcc, skb);
26778 else
26779 dev_kfree_skb_any(skb);
26780 - atomic_inc(&vcc->stats->tx);
26781 + atomic_inc_unchecked(&vcc->stats->tx);
26782
26783 return 0;
26784 }
26785 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
26786 index f8f41e0..1f987dd 100644
26787 --- a/drivers/atm/ambassador.c
26788 +++ b/drivers/atm/ambassador.c
26789 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
26790 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26791
26792 // VC layer stats
26793 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26794 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26795
26796 // free the descriptor
26797 kfree (tx_descr);
26798 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26799 dump_skb ("<<<", vc, skb);
26800
26801 // VC layer stats
26802 - atomic_inc(&atm_vcc->stats->rx);
26803 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26804 __net_timestamp(skb);
26805 // end of our responsibility
26806 atm_vcc->push (atm_vcc, skb);
26807 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26808 } else {
26809 PRINTK (KERN_INFO, "dropped over-size frame");
26810 // should we count this?
26811 - atomic_inc(&atm_vcc->stats->rx_drop);
26812 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26813 }
26814
26815 } else {
26816 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
26817 }
26818
26819 if (check_area (skb->data, skb->len)) {
26820 - atomic_inc(&atm_vcc->stats->tx_err);
26821 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26822 return -ENOMEM; // ?
26823 }
26824
26825 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
26826 index b22d71c..d6e1049 100644
26827 --- a/drivers/atm/atmtcp.c
26828 +++ b/drivers/atm/atmtcp.c
26829 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26830 if (vcc->pop) vcc->pop(vcc,skb);
26831 else dev_kfree_skb(skb);
26832 if (dev_data) return 0;
26833 - atomic_inc(&vcc->stats->tx_err);
26834 + atomic_inc_unchecked(&vcc->stats->tx_err);
26835 return -ENOLINK;
26836 }
26837 size = skb->len+sizeof(struct atmtcp_hdr);
26838 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26839 if (!new_skb) {
26840 if (vcc->pop) vcc->pop(vcc,skb);
26841 else dev_kfree_skb(skb);
26842 - atomic_inc(&vcc->stats->tx_err);
26843 + atomic_inc_unchecked(&vcc->stats->tx_err);
26844 return -ENOBUFS;
26845 }
26846 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26847 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26848 if (vcc->pop) vcc->pop(vcc,skb);
26849 else dev_kfree_skb(skb);
26850 out_vcc->push(out_vcc,new_skb);
26851 - atomic_inc(&vcc->stats->tx);
26852 - atomic_inc(&out_vcc->stats->rx);
26853 + atomic_inc_unchecked(&vcc->stats->tx);
26854 + atomic_inc_unchecked(&out_vcc->stats->rx);
26855 return 0;
26856 }
26857
26858 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26859 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26860 read_unlock(&vcc_sklist_lock);
26861 if (!out_vcc) {
26862 - atomic_inc(&vcc->stats->tx_err);
26863 + atomic_inc_unchecked(&vcc->stats->tx_err);
26864 goto done;
26865 }
26866 skb_pull(skb,sizeof(struct atmtcp_hdr));
26867 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26868 __net_timestamp(new_skb);
26869 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26870 out_vcc->push(out_vcc,new_skb);
26871 - atomic_inc(&vcc->stats->tx);
26872 - atomic_inc(&out_vcc->stats->rx);
26873 + atomic_inc_unchecked(&vcc->stats->tx);
26874 + atomic_inc_unchecked(&out_vcc->stats->rx);
26875 done:
26876 if (vcc->pop) vcc->pop(vcc,skb);
26877 else dev_kfree_skb(skb);
26878 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
26879 index 956e9ac..133516d 100644
26880 --- a/drivers/atm/eni.c
26881 +++ b/drivers/atm/eni.c
26882 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26883 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26884 vcc->dev->number);
26885 length = 0;
26886 - atomic_inc(&vcc->stats->rx_err);
26887 + atomic_inc_unchecked(&vcc->stats->rx_err);
26888 }
26889 else {
26890 length = ATM_CELL_SIZE-1; /* no HEC */
26891 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26892 size);
26893 }
26894 eff = length = 0;
26895 - atomic_inc(&vcc->stats->rx_err);
26896 + atomic_inc_unchecked(&vcc->stats->rx_err);
26897 }
26898 else {
26899 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26900 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26901 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26902 vcc->dev->number,vcc->vci,length,size << 2,descr);
26903 length = eff = 0;
26904 - atomic_inc(&vcc->stats->rx_err);
26905 + atomic_inc_unchecked(&vcc->stats->rx_err);
26906 }
26907 }
26908 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26909 @@ -771,7 +771,7 @@ rx_dequeued++;
26910 vcc->push(vcc,skb);
26911 pushed++;
26912 }
26913 - atomic_inc(&vcc->stats->rx);
26914 + atomic_inc_unchecked(&vcc->stats->rx);
26915 }
26916 wake_up(&eni_dev->rx_wait);
26917 }
26918 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
26919 PCI_DMA_TODEVICE);
26920 if (vcc->pop) vcc->pop(vcc,skb);
26921 else dev_kfree_skb_irq(skb);
26922 - atomic_inc(&vcc->stats->tx);
26923 + atomic_inc_unchecked(&vcc->stats->tx);
26924 wake_up(&eni_dev->tx_wait);
26925 dma_complete++;
26926 }
26927 @@ -1569,7 +1569,7 @@ tx_complete++;
26928 /*--------------------------------- entries ---------------------------------*/
26929
26930
26931 -static const char *media_name[] __devinitdata = {
26932 +static const char *media_name[] __devinitconst = {
26933 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
26934 "UTP", "05?", "06?", "07?", /* 4- 7 */
26935 "TAXI","09?", "10?", "11?", /* 8-11 */
26936 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
26937 index 5072f8a..fa52520d 100644
26938 --- a/drivers/atm/firestream.c
26939 +++ b/drivers/atm/firestream.c
26940 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
26941 }
26942 }
26943
26944 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26945 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26946
26947 fs_dprintk (FS_DEBUG_TXMEM, "i");
26948 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26949 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26950 #endif
26951 skb_put (skb, qe->p1 & 0xffff);
26952 ATM_SKB(skb)->vcc = atm_vcc;
26953 - atomic_inc(&atm_vcc->stats->rx);
26954 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26955 __net_timestamp(skb);
26956 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26957 atm_vcc->push (atm_vcc, skb);
26958 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26959 kfree (pe);
26960 }
26961 if (atm_vcc)
26962 - atomic_inc(&atm_vcc->stats->rx_drop);
26963 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26964 break;
26965 case 0x1f: /* Reassembly abort: no buffers. */
26966 /* Silently increment error counter. */
26967 if (atm_vcc)
26968 - atomic_inc(&atm_vcc->stats->rx_drop);
26969 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26970 break;
26971 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26972 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26973 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
26974 index 361f5ae..7fc552d 100644
26975 --- a/drivers/atm/fore200e.c
26976 +++ b/drivers/atm/fore200e.c
26977 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
26978 #endif
26979 /* check error condition */
26980 if (*entry->status & STATUS_ERROR)
26981 - atomic_inc(&vcc->stats->tx_err);
26982 + atomic_inc_unchecked(&vcc->stats->tx_err);
26983 else
26984 - atomic_inc(&vcc->stats->tx);
26985 + atomic_inc_unchecked(&vcc->stats->tx);
26986 }
26987 }
26988
26989 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26990 if (skb == NULL) {
26991 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26992
26993 - atomic_inc(&vcc->stats->rx_drop);
26994 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26995 return -ENOMEM;
26996 }
26997
26998 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26999
27000 dev_kfree_skb_any(skb);
27001
27002 - atomic_inc(&vcc->stats->rx_drop);
27003 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27004 return -ENOMEM;
27005 }
27006
27007 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27008
27009 vcc->push(vcc, skb);
27010 - atomic_inc(&vcc->stats->rx);
27011 + atomic_inc_unchecked(&vcc->stats->rx);
27012
27013 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27014
27015 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27016 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27017 fore200e->atm_dev->number,
27018 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27019 - atomic_inc(&vcc->stats->rx_err);
27020 + atomic_inc_unchecked(&vcc->stats->rx_err);
27021 }
27022 }
27023
27024 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27025 goto retry_here;
27026 }
27027
27028 - atomic_inc(&vcc->stats->tx_err);
27029 + atomic_inc_unchecked(&vcc->stats->tx_err);
27030
27031 fore200e->tx_sat++;
27032 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27033 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27034 index 9a51df4..f3bb5f8 100644
27035 --- a/drivers/atm/he.c
27036 +++ b/drivers/atm/he.c
27037 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27038
27039 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27040 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27041 - atomic_inc(&vcc->stats->rx_drop);
27042 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27043 goto return_host_buffers;
27044 }
27045
27046 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27047 RBRQ_LEN_ERR(he_dev->rbrq_head)
27048 ? "LEN_ERR" : "",
27049 vcc->vpi, vcc->vci);
27050 - atomic_inc(&vcc->stats->rx_err);
27051 + atomic_inc_unchecked(&vcc->stats->rx_err);
27052 goto return_host_buffers;
27053 }
27054
27055 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27056 vcc->push(vcc, skb);
27057 spin_lock(&he_dev->global_lock);
27058
27059 - atomic_inc(&vcc->stats->rx);
27060 + atomic_inc_unchecked(&vcc->stats->rx);
27061
27062 return_host_buffers:
27063 ++pdus_assembled;
27064 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27065 tpd->vcc->pop(tpd->vcc, tpd->skb);
27066 else
27067 dev_kfree_skb_any(tpd->skb);
27068 - atomic_inc(&tpd->vcc->stats->tx_err);
27069 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27070 }
27071 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27072 return;
27073 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27074 vcc->pop(vcc, skb);
27075 else
27076 dev_kfree_skb_any(skb);
27077 - atomic_inc(&vcc->stats->tx_err);
27078 + atomic_inc_unchecked(&vcc->stats->tx_err);
27079 return -EINVAL;
27080 }
27081
27082 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27083 vcc->pop(vcc, skb);
27084 else
27085 dev_kfree_skb_any(skb);
27086 - atomic_inc(&vcc->stats->tx_err);
27087 + atomic_inc_unchecked(&vcc->stats->tx_err);
27088 return -EINVAL;
27089 }
27090 #endif
27091 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27092 vcc->pop(vcc, skb);
27093 else
27094 dev_kfree_skb_any(skb);
27095 - atomic_inc(&vcc->stats->tx_err);
27096 + atomic_inc_unchecked(&vcc->stats->tx_err);
27097 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27098 return -ENOMEM;
27099 }
27100 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27101 vcc->pop(vcc, skb);
27102 else
27103 dev_kfree_skb_any(skb);
27104 - atomic_inc(&vcc->stats->tx_err);
27105 + atomic_inc_unchecked(&vcc->stats->tx_err);
27106 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27107 return -ENOMEM;
27108 }
27109 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27110 __enqueue_tpd(he_dev, tpd, cid);
27111 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27112
27113 - atomic_inc(&vcc->stats->tx);
27114 + atomic_inc_unchecked(&vcc->stats->tx);
27115
27116 return 0;
27117 }
27118 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27119 index b812103..e391a49 100644
27120 --- a/drivers/atm/horizon.c
27121 +++ b/drivers/atm/horizon.c
27122 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27123 {
27124 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27125 // VC layer stats
27126 - atomic_inc(&vcc->stats->rx);
27127 + atomic_inc_unchecked(&vcc->stats->rx);
27128 __net_timestamp(skb);
27129 // end of our responsibility
27130 vcc->push (vcc, skb);
27131 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27132 dev->tx_iovec = NULL;
27133
27134 // VC layer stats
27135 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27136 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27137
27138 // free the skb
27139 hrz_kfree_skb (skb);
27140 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27141 index 1c05212..c28e200 100644
27142 --- a/drivers/atm/idt77252.c
27143 +++ b/drivers/atm/idt77252.c
27144 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27145 else
27146 dev_kfree_skb(skb);
27147
27148 - atomic_inc(&vcc->stats->tx);
27149 + atomic_inc_unchecked(&vcc->stats->tx);
27150 }
27151
27152 atomic_dec(&scq->used);
27153 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27154 if ((sb = dev_alloc_skb(64)) == NULL) {
27155 printk("%s: Can't allocate buffers for aal0.\n",
27156 card->name);
27157 - atomic_add(i, &vcc->stats->rx_drop);
27158 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27159 break;
27160 }
27161 if (!atm_charge(vcc, sb->truesize)) {
27162 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27163 card->name);
27164 - atomic_add(i - 1, &vcc->stats->rx_drop);
27165 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27166 dev_kfree_skb(sb);
27167 break;
27168 }
27169 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27170 ATM_SKB(sb)->vcc = vcc;
27171 __net_timestamp(sb);
27172 vcc->push(vcc, sb);
27173 - atomic_inc(&vcc->stats->rx);
27174 + atomic_inc_unchecked(&vcc->stats->rx);
27175
27176 cell += ATM_CELL_PAYLOAD;
27177 }
27178 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27179 "(CDC: %08x)\n",
27180 card->name, len, rpp->len, readl(SAR_REG_CDC));
27181 recycle_rx_pool_skb(card, rpp);
27182 - atomic_inc(&vcc->stats->rx_err);
27183 + atomic_inc_unchecked(&vcc->stats->rx_err);
27184 return;
27185 }
27186 if (stat & SAR_RSQE_CRC) {
27187 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27188 recycle_rx_pool_skb(card, rpp);
27189 - atomic_inc(&vcc->stats->rx_err);
27190 + atomic_inc_unchecked(&vcc->stats->rx_err);
27191 return;
27192 }
27193 if (skb_queue_len(&rpp->queue) > 1) {
27194 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27195 RXPRINTK("%s: Can't alloc RX skb.\n",
27196 card->name);
27197 recycle_rx_pool_skb(card, rpp);
27198 - atomic_inc(&vcc->stats->rx_err);
27199 + atomic_inc_unchecked(&vcc->stats->rx_err);
27200 return;
27201 }
27202 if (!atm_charge(vcc, skb->truesize)) {
27203 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27204 __net_timestamp(skb);
27205
27206 vcc->push(vcc, skb);
27207 - atomic_inc(&vcc->stats->rx);
27208 + atomic_inc_unchecked(&vcc->stats->rx);
27209
27210 return;
27211 }
27212 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27213 __net_timestamp(skb);
27214
27215 vcc->push(vcc, skb);
27216 - atomic_inc(&vcc->stats->rx);
27217 + atomic_inc_unchecked(&vcc->stats->rx);
27218
27219 if (skb->truesize > SAR_FB_SIZE_3)
27220 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27221 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
27222 if (vcc->qos.aal != ATM_AAL0) {
27223 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27224 card->name, vpi, vci);
27225 - atomic_inc(&vcc->stats->rx_drop);
27226 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27227 goto drop;
27228 }
27229
27230 if ((sb = dev_alloc_skb(64)) == NULL) {
27231 printk("%s: Can't allocate buffers for AAL0.\n",
27232 card->name);
27233 - atomic_inc(&vcc->stats->rx_err);
27234 + atomic_inc_unchecked(&vcc->stats->rx_err);
27235 goto drop;
27236 }
27237
27238 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
27239 ATM_SKB(sb)->vcc = vcc;
27240 __net_timestamp(sb);
27241 vcc->push(vcc, sb);
27242 - atomic_inc(&vcc->stats->rx);
27243 + atomic_inc_unchecked(&vcc->stats->rx);
27244
27245 drop:
27246 skb_pull(queue, 64);
27247 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27248
27249 if (vc == NULL) {
27250 printk("%s: NULL connection in send().\n", card->name);
27251 - atomic_inc(&vcc->stats->tx_err);
27252 + atomic_inc_unchecked(&vcc->stats->tx_err);
27253 dev_kfree_skb(skb);
27254 return -EINVAL;
27255 }
27256 if (!test_bit(VCF_TX, &vc->flags)) {
27257 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27258 - atomic_inc(&vcc->stats->tx_err);
27259 + atomic_inc_unchecked(&vcc->stats->tx_err);
27260 dev_kfree_skb(skb);
27261 return -EINVAL;
27262 }
27263 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27264 break;
27265 default:
27266 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27267 - atomic_inc(&vcc->stats->tx_err);
27268 + atomic_inc_unchecked(&vcc->stats->tx_err);
27269 dev_kfree_skb(skb);
27270 return -EINVAL;
27271 }
27272
27273 if (skb_shinfo(skb)->nr_frags != 0) {
27274 printk("%s: No scatter-gather yet.\n", card->name);
27275 - atomic_inc(&vcc->stats->tx_err);
27276 + atomic_inc_unchecked(&vcc->stats->tx_err);
27277 dev_kfree_skb(skb);
27278 return -EINVAL;
27279 }
27280 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27281
27282 err = queue_skb(card, vc, skb, oam);
27283 if (err) {
27284 - atomic_inc(&vcc->stats->tx_err);
27285 + atomic_inc_unchecked(&vcc->stats->tx_err);
27286 dev_kfree_skb(skb);
27287 return err;
27288 }
27289 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27290 skb = dev_alloc_skb(64);
27291 if (!skb) {
27292 printk("%s: Out of memory in send_oam().\n", card->name);
27293 - atomic_inc(&vcc->stats->tx_err);
27294 + atomic_inc_unchecked(&vcc->stats->tx_err);
27295 return -ENOMEM;
27296 }
27297 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27298 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27299 index 3d0c2b0..45441fa 100644
27300 --- a/drivers/atm/iphase.c
27301 +++ b/drivers/atm/iphase.c
27302 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27303 status = (u_short) (buf_desc_ptr->desc_mode);
27304 if (status & (RX_CER | RX_PTE | RX_OFL))
27305 {
27306 - atomic_inc(&vcc->stats->rx_err);
27307 + atomic_inc_unchecked(&vcc->stats->rx_err);
27308 IF_ERR(printk("IA: bad packet, dropping it");)
27309 if (status & RX_CER) {
27310 IF_ERR(printk(" cause: packet CRC error\n");)
27311 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27312 len = dma_addr - buf_addr;
27313 if (len > iadev->rx_buf_sz) {
27314 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27315 - atomic_inc(&vcc->stats->rx_err);
27316 + atomic_inc_unchecked(&vcc->stats->rx_err);
27317 goto out_free_desc;
27318 }
27319
27320 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27321 ia_vcc = INPH_IA_VCC(vcc);
27322 if (ia_vcc == NULL)
27323 {
27324 - atomic_inc(&vcc->stats->rx_err);
27325 + atomic_inc_unchecked(&vcc->stats->rx_err);
27326 dev_kfree_skb_any(skb);
27327 atm_return(vcc, atm_guess_pdu2truesize(len));
27328 goto INCR_DLE;
27329 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27330 if ((length > iadev->rx_buf_sz) || (length >
27331 (skb->len - sizeof(struct cpcs_trailer))))
27332 {
27333 - atomic_inc(&vcc->stats->rx_err);
27334 + atomic_inc_unchecked(&vcc->stats->rx_err);
27335 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27336 length, skb->len);)
27337 dev_kfree_skb_any(skb);
27338 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27339
27340 IF_RX(printk("rx_dle_intr: skb push");)
27341 vcc->push(vcc,skb);
27342 - atomic_inc(&vcc->stats->rx);
27343 + atomic_inc_unchecked(&vcc->stats->rx);
27344 iadev->rx_pkt_cnt++;
27345 }
27346 INCR_DLE:
27347 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27348 {
27349 struct k_sonet_stats *stats;
27350 stats = &PRIV(_ia_dev[board])->sonet_stats;
27351 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27352 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27353 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27354 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27355 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27356 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27357 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27358 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27359 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27360 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27361 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27362 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27363 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27364 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27365 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27366 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27367 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27368 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27369 }
27370 ia_cmds.status = 0;
27371 break;
27372 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27373 if ((desc == 0) || (desc > iadev->num_tx_desc))
27374 {
27375 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27376 - atomic_inc(&vcc->stats->tx);
27377 + atomic_inc_unchecked(&vcc->stats->tx);
27378 if (vcc->pop)
27379 vcc->pop(vcc, skb);
27380 else
27381 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27382 ATM_DESC(skb) = vcc->vci;
27383 skb_queue_tail(&iadev->tx_dma_q, skb);
27384
27385 - atomic_inc(&vcc->stats->tx);
27386 + atomic_inc_unchecked(&vcc->stats->tx);
27387 iadev->tx_pkt_cnt++;
27388 /* Increment transaction counter */
27389 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27390
27391 #if 0
27392 /* add flow control logic */
27393 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27394 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27395 if (iavcc->vc_desc_cnt > 10) {
27396 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27397 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27398 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
27399 index f556969..0da15eb 100644
27400 --- a/drivers/atm/lanai.c
27401 +++ b/drivers/atm/lanai.c
27402 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
27403 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27404 lanai_endtx(lanai, lvcc);
27405 lanai_free_skb(lvcc->tx.atmvcc, skb);
27406 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27407 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27408 }
27409
27410 /* Try to fill the buffer - don't call unless there is backlog */
27411 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
27412 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27413 __net_timestamp(skb);
27414 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27415 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27416 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27417 out:
27418 lvcc->rx.buf.ptr = end;
27419 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27420 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27421 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27422 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27423 lanai->stats.service_rxnotaal5++;
27424 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27425 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27426 return 0;
27427 }
27428 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27429 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27430 int bytes;
27431 read_unlock(&vcc_sklist_lock);
27432 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27433 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27434 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27435 lvcc->stats.x.aal5.service_trash++;
27436 bytes = (SERVICE_GET_END(s) * 16) -
27437 (((unsigned long) lvcc->rx.buf.ptr) -
27438 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27439 }
27440 if (s & SERVICE_STREAM) {
27441 read_unlock(&vcc_sklist_lock);
27442 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27443 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27444 lvcc->stats.x.aal5.service_stream++;
27445 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27446 "PDU on VCI %d!\n", lanai->number, vci);
27447 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27448 return 0;
27449 }
27450 DPRINTK("got rx crc error on vci %d\n", vci);
27451 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27452 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27453 lvcc->stats.x.aal5.service_rxcrc++;
27454 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27455 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27456 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
27457 index 1c70c45..300718d 100644
27458 --- a/drivers/atm/nicstar.c
27459 +++ b/drivers/atm/nicstar.c
27460 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27461 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27462 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27463 card->index);
27464 - atomic_inc(&vcc->stats->tx_err);
27465 + atomic_inc_unchecked(&vcc->stats->tx_err);
27466 dev_kfree_skb_any(skb);
27467 return -EINVAL;
27468 }
27469 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27470 if (!vc->tx) {
27471 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27472 card->index);
27473 - atomic_inc(&vcc->stats->tx_err);
27474 + atomic_inc_unchecked(&vcc->stats->tx_err);
27475 dev_kfree_skb_any(skb);
27476 return -EINVAL;
27477 }
27478 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27479 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27480 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27481 card->index);
27482 - atomic_inc(&vcc->stats->tx_err);
27483 + atomic_inc_unchecked(&vcc->stats->tx_err);
27484 dev_kfree_skb_any(skb);
27485 return -EINVAL;
27486 }
27487
27488 if (skb_shinfo(skb)->nr_frags != 0) {
27489 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27490 - atomic_inc(&vcc->stats->tx_err);
27491 + atomic_inc_unchecked(&vcc->stats->tx_err);
27492 dev_kfree_skb_any(skb);
27493 return -EINVAL;
27494 }
27495 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27496 }
27497
27498 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27499 - atomic_inc(&vcc->stats->tx_err);
27500 + atomic_inc_unchecked(&vcc->stats->tx_err);
27501 dev_kfree_skb_any(skb);
27502 return -EIO;
27503 }
27504 - atomic_inc(&vcc->stats->tx);
27505 + atomic_inc_unchecked(&vcc->stats->tx);
27506
27507 return 0;
27508 }
27509 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27510 printk
27511 ("nicstar%d: Can't allocate buffers for aal0.\n",
27512 card->index);
27513 - atomic_add(i, &vcc->stats->rx_drop);
27514 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27515 break;
27516 }
27517 if (!atm_charge(vcc, sb->truesize)) {
27518 RXPRINTK
27519 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27520 card->index);
27521 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27522 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27523 dev_kfree_skb_any(sb);
27524 break;
27525 }
27526 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27527 ATM_SKB(sb)->vcc = vcc;
27528 __net_timestamp(sb);
27529 vcc->push(vcc, sb);
27530 - atomic_inc(&vcc->stats->rx);
27531 + atomic_inc_unchecked(&vcc->stats->rx);
27532 cell += ATM_CELL_PAYLOAD;
27533 }
27534
27535 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27536 if (iovb == NULL) {
27537 printk("nicstar%d: Out of iovec buffers.\n",
27538 card->index);
27539 - atomic_inc(&vcc->stats->rx_drop);
27540 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27541 recycle_rx_buf(card, skb);
27542 return;
27543 }
27544 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27545 small or large buffer itself. */
27546 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27547 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27548 - atomic_inc(&vcc->stats->rx_err);
27549 + atomic_inc_unchecked(&vcc->stats->rx_err);
27550 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27551 NS_MAX_IOVECS);
27552 NS_PRV_IOVCNT(iovb) = 0;
27553 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27554 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27555 card->index);
27556 which_list(card, skb);
27557 - atomic_inc(&vcc->stats->rx_err);
27558 + atomic_inc_unchecked(&vcc->stats->rx_err);
27559 recycle_rx_buf(card, skb);
27560 vc->rx_iov = NULL;
27561 recycle_iov_buf(card, iovb);
27562 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27563 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27564 card->index);
27565 which_list(card, skb);
27566 - atomic_inc(&vcc->stats->rx_err);
27567 + atomic_inc_unchecked(&vcc->stats->rx_err);
27568 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27569 NS_PRV_IOVCNT(iovb));
27570 vc->rx_iov = NULL;
27571 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27572 printk(" - PDU size mismatch.\n");
27573 else
27574 printk(".\n");
27575 - atomic_inc(&vcc->stats->rx_err);
27576 + atomic_inc_unchecked(&vcc->stats->rx_err);
27577 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27578 NS_PRV_IOVCNT(iovb));
27579 vc->rx_iov = NULL;
27580 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27581 /* skb points to a small buffer */
27582 if (!atm_charge(vcc, skb->truesize)) {
27583 push_rxbufs(card, skb);
27584 - atomic_inc(&vcc->stats->rx_drop);
27585 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27586 } else {
27587 skb_put(skb, len);
27588 dequeue_sm_buf(card, skb);
27589 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27590 ATM_SKB(skb)->vcc = vcc;
27591 __net_timestamp(skb);
27592 vcc->push(vcc, skb);
27593 - atomic_inc(&vcc->stats->rx);
27594 + atomic_inc_unchecked(&vcc->stats->rx);
27595 }
27596 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27597 struct sk_buff *sb;
27598 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27599 if (len <= NS_SMBUFSIZE) {
27600 if (!atm_charge(vcc, sb->truesize)) {
27601 push_rxbufs(card, sb);
27602 - atomic_inc(&vcc->stats->rx_drop);
27603 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27604 } else {
27605 skb_put(sb, len);
27606 dequeue_sm_buf(card, sb);
27607 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27608 ATM_SKB(sb)->vcc = vcc;
27609 __net_timestamp(sb);
27610 vcc->push(vcc, sb);
27611 - atomic_inc(&vcc->stats->rx);
27612 + atomic_inc_unchecked(&vcc->stats->rx);
27613 }
27614
27615 push_rxbufs(card, skb);
27616 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27617
27618 if (!atm_charge(vcc, skb->truesize)) {
27619 push_rxbufs(card, skb);
27620 - atomic_inc(&vcc->stats->rx_drop);
27621 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27622 } else {
27623 dequeue_lg_buf(card, skb);
27624 #ifdef NS_USE_DESTRUCTORS
27625 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27626 ATM_SKB(skb)->vcc = vcc;
27627 __net_timestamp(skb);
27628 vcc->push(vcc, skb);
27629 - atomic_inc(&vcc->stats->rx);
27630 + atomic_inc_unchecked(&vcc->stats->rx);
27631 }
27632
27633 push_rxbufs(card, sb);
27634 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27635 printk
27636 ("nicstar%d: Out of huge buffers.\n",
27637 card->index);
27638 - atomic_inc(&vcc->stats->rx_drop);
27639 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27640 recycle_iovec_rx_bufs(card,
27641 (struct iovec *)
27642 iovb->data,
27643 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27644 card->hbpool.count++;
27645 } else
27646 dev_kfree_skb_any(hb);
27647 - atomic_inc(&vcc->stats->rx_drop);
27648 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27649 } else {
27650 /* Copy the small buffer to the huge buffer */
27651 sb = (struct sk_buff *)iov->iov_base;
27652 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27653 #endif /* NS_USE_DESTRUCTORS */
27654 __net_timestamp(hb);
27655 vcc->push(vcc, hb);
27656 - atomic_inc(&vcc->stats->rx);
27657 + atomic_inc_unchecked(&vcc->stats->rx);
27658 }
27659 }
27660
27661 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
27662 index 5d1d076..12fbca4 100644
27663 --- a/drivers/atm/solos-pci.c
27664 +++ b/drivers/atm/solos-pci.c
27665 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
27666 }
27667 atm_charge(vcc, skb->truesize);
27668 vcc->push(vcc, skb);
27669 - atomic_inc(&vcc->stats->rx);
27670 + atomic_inc_unchecked(&vcc->stats->rx);
27671 break;
27672
27673 case PKT_STATUS:
27674 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
27675 vcc = SKB_CB(oldskb)->vcc;
27676
27677 if (vcc) {
27678 - atomic_inc(&vcc->stats->tx);
27679 + atomic_inc_unchecked(&vcc->stats->tx);
27680 solos_pop(vcc, oldskb);
27681 } else
27682 dev_kfree_skb_irq(oldskb);
27683 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
27684 index 90f1ccc..04c4a1e 100644
27685 --- a/drivers/atm/suni.c
27686 +++ b/drivers/atm/suni.c
27687 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27688
27689
27690 #define ADD_LIMITED(s,v) \
27691 - atomic_add((v),&stats->s); \
27692 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27693 + atomic_add_unchecked((v),&stats->s); \
27694 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27695
27696
27697 static void suni_hz(unsigned long from_timer)
27698 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
27699 index 5120a96..e2572bd 100644
27700 --- a/drivers/atm/uPD98402.c
27701 +++ b/drivers/atm/uPD98402.c
27702 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
27703 struct sonet_stats tmp;
27704 int error = 0;
27705
27706 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27707 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27708 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27709 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27710 if (zero && !error) {
27711 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
27712
27713
27714 #define ADD_LIMITED(s,v) \
27715 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27716 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27717 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27718 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27719 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27720 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27721
27722
27723 static void stat_event(struct atm_dev *dev)
27724 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
27725 if (reason & uPD98402_INT_PFM) stat_event(dev);
27726 if (reason & uPD98402_INT_PCO) {
27727 (void) GET(PCOCR); /* clear interrupt cause */
27728 - atomic_add(GET(HECCT),
27729 + atomic_add_unchecked(GET(HECCT),
27730 &PRIV(dev)->sonet_stats.uncorr_hcs);
27731 }
27732 if ((reason & uPD98402_INT_RFO) &&
27733 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
27734 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27735 uPD98402_INT_LOS),PIMR); /* enable them */
27736 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27737 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27738 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27739 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27740 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27741 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27742 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27743 return 0;
27744 }
27745
27746 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
27747 index d889f56..17eb71e 100644
27748 --- a/drivers/atm/zatm.c
27749 +++ b/drivers/atm/zatm.c
27750 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27751 }
27752 if (!size) {
27753 dev_kfree_skb_irq(skb);
27754 - if (vcc) atomic_inc(&vcc->stats->rx_err);
27755 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27756 continue;
27757 }
27758 if (!atm_charge(vcc,skb->truesize)) {
27759 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27760 skb->len = size;
27761 ATM_SKB(skb)->vcc = vcc;
27762 vcc->push(vcc,skb);
27763 - atomic_inc(&vcc->stats->rx);
27764 + atomic_inc_unchecked(&vcc->stats->rx);
27765 }
27766 zout(pos & 0xffff,MTA(mbx));
27767 #if 0 /* probably a stupid idea */
27768 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
27769 skb_queue_head(&zatm_vcc->backlog,skb);
27770 break;
27771 }
27772 - atomic_inc(&vcc->stats->tx);
27773 + atomic_inc_unchecked(&vcc->stats->tx);
27774 wake_up(&zatm_vcc->tx_wait);
27775 }
27776
27777 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
27778 index a4760e0..51283cf 100644
27779 --- a/drivers/base/devtmpfs.c
27780 +++ b/drivers/base/devtmpfs.c
27781 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
27782 if (!thread)
27783 return 0;
27784
27785 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
27786 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
27787 if (err)
27788 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
27789 else
27790 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
27791 index caf995f..6f76697 100644
27792 --- a/drivers/base/power/wakeup.c
27793 +++ b/drivers/base/power/wakeup.c
27794 @@ -30,14 +30,14 @@ bool events_check_enabled;
27795 * They need to be modified together atomically, so it's better to use one
27796 * atomic variable to hold them both.
27797 */
27798 -static atomic_t combined_event_count = ATOMIC_INIT(0);
27799 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27800
27801 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27802 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27803
27804 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27805 {
27806 - unsigned int comb = atomic_read(&combined_event_count);
27807 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
27808
27809 *cnt = (comb >> IN_PROGRESS_BITS);
27810 *inpr = comb & MAX_IN_PROGRESS;
27811 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
27812 ws->last_time = ktime_get();
27813
27814 /* Increment the counter of events in progress. */
27815 - atomic_inc(&combined_event_count);
27816 + atomic_inc_unchecked(&combined_event_count);
27817 }
27818
27819 /**
27820 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
27821 * Increment the counter of registered wakeup events and decrement the
27822 * couter of wakeup events in progress simultaneously.
27823 */
27824 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27825 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27826 }
27827
27828 /**
27829 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
27830 index b0f553b..77b928b 100644
27831 --- a/drivers/block/cciss.c
27832 +++ b/drivers/block/cciss.c
27833 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
27834 int err;
27835 u32 cp;
27836
27837 + memset(&arg64, 0, sizeof(arg64));
27838 +
27839 err = 0;
27840 err |=
27841 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27842 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
27843 while (!list_empty(&h->reqQ)) {
27844 c = list_entry(h->reqQ.next, CommandList_struct, list);
27845 /* can't do anything if fifo is full */
27846 - if ((h->access.fifo_full(h))) {
27847 + if ((h->access->fifo_full(h))) {
27848 dev_warn(&h->pdev->dev, "fifo full\n");
27849 break;
27850 }
27851 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
27852 h->Qdepth--;
27853
27854 /* Tell the controller execute command */
27855 - h->access.submit_command(h, c);
27856 + h->access->submit_command(h, c);
27857
27858 /* Put job onto the completed Q */
27859 addQ(&h->cmpQ, c);
27860 @@ -3443,17 +3445,17 @@ startio:
27861
27862 static inline unsigned long get_next_completion(ctlr_info_t *h)
27863 {
27864 - return h->access.command_completed(h);
27865 + return h->access->command_completed(h);
27866 }
27867
27868 static inline int interrupt_pending(ctlr_info_t *h)
27869 {
27870 - return h->access.intr_pending(h);
27871 + return h->access->intr_pending(h);
27872 }
27873
27874 static inline long interrupt_not_for_us(ctlr_info_t *h)
27875 {
27876 - return ((h->access.intr_pending(h) == 0) ||
27877 + return ((h->access->intr_pending(h) == 0) ||
27878 (h->interrupts_enabled == 0));
27879 }
27880
27881 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
27882 u32 a;
27883
27884 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
27885 - return h->access.command_completed(h);
27886 + return h->access->command_completed(h);
27887
27888 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
27889 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
27890 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
27891 trans_support & CFGTBL_Trans_use_short_tags);
27892
27893 /* Change the access methods to the performant access methods */
27894 - h->access = SA5_performant_access;
27895 + h->access = &SA5_performant_access;
27896 h->transMethod = CFGTBL_Trans_Performant;
27897
27898 return;
27899 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
27900 if (prod_index < 0)
27901 return -ENODEV;
27902 h->product_name = products[prod_index].product_name;
27903 - h->access = *(products[prod_index].access);
27904 + h->access = products[prod_index].access;
27905
27906 if (cciss_board_disabled(h)) {
27907 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
27908 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
27909 }
27910
27911 /* make sure the board interrupts are off */
27912 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27913 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27914 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
27915 if (rc)
27916 goto clean2;
27917 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
27918 * fake ones to scoop up any residual completions.
27919 */
27920 spin_lock_irqsave(&h->lock, flags);
27921 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27922 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27923 spin_unlock_irqrestore(&h->lock, flags);
27924 free_irq(h->intr[h->intr_mode], h);
27925 rc = cciss_request_irq(h, cciss_msix_discard_completions,
27926 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
27927 dev_info(&h->pdev->dev, "Board READY.\n");
27928 dev_info(&h->pdev->dev,
27929 "Waiting for stale completions to drain.\n");
27930 - h->access.set_intr_mask(h, CCISS_INTR_ON);
27931 + h->access->set_intr_mask(h, CCISS_INTR_ON);
27932 msleep(10000);
27933 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27934 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27935
27936 rc = controller_reset_failed(h->cfgtable);
27937 if (rc)
27938 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
27939 cciss_scsi_setup(h);
27940
27941 /* Turn the interrupts on so we can service requests */
27942 - h->access.set_intr_mask(h, CCISS_INTR_ON);
27943 + h->access->set_intr_mask(h, CCISS_INTR_ON);
27944
27945 /* Get the firmware version */
27946 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
27947 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
27948 kfree(flush_buf);
27949 if (return_code != IO_OK)
27950 dev_warn(&h->pdev->dev, "Error flushing cache\n");
27951 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27952 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27953 free_irq(h->intr[h->intr_mode], h);
27954 }
27955
27956 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
27957 index 7fda30e..eb5dfe0 100644
27958 --- a/drivers/block/cciss.h
27959 +++ b/drivers/block/cciss.h
27960 @@ -101,7 +101,7 @@ struct ctlr_info
27961 /* information about each logical volume */
27962 drive_info_struct *drv[CISS_MAX_LUN];
27963
27964 - struct access_method access;
27965 + struct access_method *access;
27966
27967 /* queue and queue Info */
27968 struct list_head reqQ;
27969 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
27970 index 9125bbe..eede5c8 100644
27971 --- a/drivers/block/cpqarray.c
27972 +++ b/drivers/block/cpqarray.c
27973 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27974 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
27975 goto Enomem4;
27976 }
27977 - hba[i]->access.set_intr_mask(hba[i], 0);
27978 + hba[i]->access->set_intr_mask(hba[i], 0);
27979 if (request_irq(hba[i]->intr, do_ida_intr,
27980 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
27981 {
27982 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27983 add_timer(&hba[i]->timer);
27984
27985 /* Enable IRQ now that spinlock and rate limit timer are set up */
27986 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27987 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27988
27989 for(j=0; j<NWD; j++) {
27990 struct gendisk *disk = ida_gendisk[i][j];
27991 @@ -694,7 +694,7 @@ DBGINFO(
27992 for(i=0; i<NR_PRODUCTS; i++) {
27993 if (board_id == products[i].board_id) {
27994 c->product_name = products[i].product_name;
27995 - c->access = *(products[i].access);
27996 + c->access = products[i].access;
27997 break;
27998 }
27999 }
28000 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28001 hba[ctlr]->intr = intr;
28002 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28003 hba[ctlr]->product_name = products[j].product_name;
28004 - hba[ctlr]->access = *(products[j].access);
28005 + hba[ctlr]->access = products[j].access;
28006 hba[ctlr]->ctlr = ctlr;
28007 hba[ctlr]->board_id = board_id;
28008 hba[ctlr]->pci_dev = NULL; /* not PCI */
28009 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28010
28011 while((c = h->reqQ) != NULL) {
28012 /* Can't do anything if we're busy */
28013 - if (h->access.fifo_full(h) == 0)
28014 + if (h->access->fifo_full(h) == 0)
28015 return;
28016
28017 /* Get the first entry from the request Q */
28018 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28019 h->Qdepth--;
28020
28021 /* Tell the controller to do our bidding */
28022 - h->access.submit_command(h, c);
28023 + h->access->submit_command(h, c);
28024
28025 /* Get onto the completion Q */
28026 addQ(&h->cmpQ, c);
28027 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28028 unsigned long flags;
28029 __u32 a,a1;
28030
28031 - istat = h->access.intr_pending(h);
28032 + istat = h->access->intr_pending(h);
28033 /* Is this interrupt for us? */
28034 if (istat == 0)
28035 return IRQ_NONE;
28036 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28037 */
28038 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28039 if (istat & FIFO_NOT_EMPTY) {
28040 - while((a = h->access.command_completed(h))) {
28041 + while((a = h->access->command_completed(h))) {
28042 a1 = a; a &= ~3;
28043 if ((c = h->cmpQ) == NULL)
28044 {
28045 @@ -1449,11 +1449,11 @@ static int sendcmd(
28046 /*
28047 * Disable interrupt
28048 */
28049 - info_p->access.set_intr_mask(info_p, 0);
28050 + info_p->access->set_intr_mask(info_p, 0);
28051 /* Make sure there is room in the command FIFO */
28052 /* Actually it should be completely empty at this time. */
28053 for (i = 200000; i > 0; i--) {
28054 - temp = info_p->access.fifo_full(info_p);
28055 + temp = info_p->access->fifo_full(info_p);
28056 if (temp != 0) {
28057 break;
28058 }
28059 @@ -1466,7 +1466,7 @@ DBG(
28060 /*
28061 * Send the cmd
28062 */
28063 - info_p->access.submit_command(info_p, c);
28064 + info_p->access->submit_command(info_p, c);
28065 complete = pollcomplete(ctlr);
28066
28067 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28068 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28069 * we check the new geometry. Then turn interrupts back on when
28070 * we're done.
28071 */
28072 - host->access.set_intr_mask(host, 0);
28073 + host->access->set_intr_mask(host, 0);
28074 getgeometry(ctlr);
28075 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28076 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28077
28078 for(i=0; i<NWD; i++) {
28079 struct gendisk *disk = ida_gendisk[ctlr][i];
28080 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28081 /* Wait (up to 2 seconds) for a command to complete */
28082
28083 for (i = 200000; i > 0; i--) {
28084 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28085 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28086 if (done == 0) {
28087 udelay(10); /* a short fixed delay */
28088 } else
28089 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28090 index be73e9d..7fbf140 100644
28091 --- a/drivers/block/cpqarray.h
28092 +++ b/drivers/block/cpqarray.h
28093 @@ -99,7 +99,7 @@ struct ctlr_info {
28094 drv_info_t drv[NWD];
28095 struct proc_dir_entry *proc;
28096
28097 - struct access_method access;
28098 + struct access_method *access;
28099
28100 cmdlist_t *reqQ;
28101 cmdlist_t *cmpQ;
28102 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28103 index 9cf2035..bffca95 100644
28104 --- a/drivers/block/drbd/drbd_int.h
28105 +++ b/drivers/block/drbd/drbd_int.h
28106 @@ -736,7 +736,7 @@ struct drbd_request;
28107 struct drbd_epoch {
28108 struct list_head list;
28109 unsigned int barrier_nr;
28110 - atomic_t epoch_size; /* increased on every request added. */
28111 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28112 atomic_t active; /* increased on every req. added, and dec on every finished. */
28113 unsigned long flags;
28114 };
28115 @@ -1108,7 +1108,7 @@ struct drbd_conf {
28116 void *int_dig_in;
28117 void *int_dig_vv;
28118 wait_queue_head_t seq_wait;
28119 - atomic_t packet_seq;
28120 + atomic_unchecked_t packet_seq;
28121 unsigned int peer_seq;
28122 spinlock_t peer_seq_lock;
28123 unsigned int minor;
28124 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28125
28126 static inline void drbd_tcp_cork(struct socket *sock)
28127 {
28128 - int __user val = 1;
28129 + int val = 1;
28130 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28131 - (char __user *)&val, sizeof(val));
28132 + (char __force_user *)&val, sizeof(val));
28133 }
28134
28135 static inline void drbd_tcp_uncork(struct socket *sock)
28136 {
28137 - int __user val = 0;
28138 + int val = 0;
28139 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28140 - (char __user *)&val, sizeof(val));
28141 + (char __force_user *)&val, sizeof(val));
28142 }
28143
28144 static inline void drbd_tcp_nodelay(struct socket *sock)
28145 {
28146 - int __user val = 1;
28147 + int val = 1;
28148 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28149 - (char __user *)&val, sizeof(val));
28150 + (char __force_user *)&val, sizeof(val));
28151 }
28152
28153 static inline void drbd_tcp_quickack(struct socket *sock)
28154 {
28155 - int __user val = 2;
28156 + int val = 2;
28157 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
28158 - (char __user *)&val, sizeof(val));
28159 + (char __force_user *)&val, sizeof(val));
28160 }
28161
28162 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
28163 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
28164 index 0358e55..bc33689 100644
28165 --- a/drivers/block/drbd/drbd_main.c
28166 +++ b/drivers/block/drbd/drbd_main.c
28167 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
28168 p.sector = sector;
28169 p.block_id = block_id;
28170 p.blksize = blksize;
28171 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
28172 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
28173
28174 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
28175 return false;
28176 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
28177 p.sector = cpu_to_be64(req->sector);
28178 p.block_id = (unsigned long)req;
28179 p.seq_num = cpu_to_be32(req->seq_num =
28180 - atomic_add_return(1, &mdev->packet_seq));
28181 + atomic_add_return_unchecked(1, &mdev->packet_seq));
28182
28183 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
28184
28185 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
28186 atomic_set(&mdev->unacked_cnt, 0);
28187 atomic_set(&mdev->local_cnt, 0);
28188 atomic_set(&mdev->net_cnt, 0);
28189 - atomic_set(&mdev->packet_seq, 0);
28190 + atomic_set_unchecked(&mdev->packet_seq, 0);
28191 atomic_set(&mdev->pp_in_use, 0);
28192 atomic_set(&mdev->pp_in_use_by_net, 0);
28193 atomic_set(&mdev->rs_sect_in, 0);
28194 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
28195 mdev->receiver.t_state);
28196
28197 /* no need to lock it, I'm the only thread alive */
28198 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
28199 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
28200 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
28201 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
28202 mdev->al_writ_cnt =
28203 mdev->bm_writ_cnt =
28204 mdev->read_cnt =
28205 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
28206 index af2a250..219c74b 100644
28207 --- a/drivers/block/drbd/drbd_nl.c
28208 +++ b/drivers/block/drbd/drbd_nl.c
28209 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
28210 module_put(THIS_MODULE);
28211 }
28212
28213 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28214 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28215
28216 static unsigned short *
28217 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
28218 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
28219 cn_reply->id.idx = CN_IDX_DRBD;
28220 cn_reply->id.val = CN_VAL_DRBD;
28221
28222 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28223 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28224 cn_reply->ack = 0; /* not used here. */
28225 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28226 (int)((char *)tl - (char *)reply->tag_list);
28227 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
28228 cn_reply->id.idx = CN_IDX_DRBD;
28229 cn_reply->id.val = CN_VAL_DRBD;
28230
28231 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28232 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28233 cn_reply->ack = 0; /* not used here. */
28234 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28235 (int)((char *)tl - (char *)reply->tag_list);
28236 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
28237 cn_reply->id.idx = CN_IDX_DRBD;
28238 cn_reply->id.val = CN_VAL_DRBD;
28239
28240 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
28241 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
28242 cn_reply->ack = 0; // not used here.
28243 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28244 (int)((char*)tl - (char*)reply->tag_list);
28245 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
28246 cn_reply->id.idx = CN_IDX_DRBD;
28247 cn_reply->id.val = CN_VAL_DRBD;
28248
28249 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28250 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28251 cn_reply->ack = 0; /* not used here. */
28252 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28253 (int)((char *)tl - (char *)reply->tag_list);
28254 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
28255 index 43beaca..4a5b1dd 100644
28256 --- a/drivers/block/drbd/drbd_receiver.c
28257 +++ b/drivers/block/drbd/drbd_receiver.c
28258 @@ -894,7 +894,7 @@ retry:
28259 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
28260 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28261
28262 - atomic_set(&mdev->packet_seq, 0);
28263 + atomic_set_unchecked(&mdev->packet_seq, 0);
28264 mdev->peer_seq = 0;
28265
28266 drbd_thread_start(&mdev->asender);
28267 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28268 do {
28269 next_epoch = NULL;
28270
28271 - epoch_size = atomic_read(&epoch->epoch_size);
28272 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28273
28274 switch (ev & ~EV_CLEANUP) {
28275 case EV_PUT:
28276 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28277 rv = FE_DESTROYED;
28278 } else {
28279 epoch->flags = 0;
28280 - atomic_set(&epoch->epoch_size, 0);
28281 + atomic_set_unchecked(&epoch->epoch_size, 0);
28282 /* atomic_set(&epoch->active, 0); is already zero */
28283 if (rv == FE_STILL_LIVE)
28284 rv = FE_RECYCLED;
28285 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28286 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28287 drbd_flush(mdev);
28288
28289 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28290 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28291 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28292 if (epoch)
28293 break;
28294 }
28295
28296 epoch = mdev->current_epoch;
28297 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28298 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28299
28300 D_ASSERT(atomic_read(&epoch->active) == 0);
28301 D_ASSERT(epoch->flags == 0);
28302 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28303 }
28304
28305 epoch->flags = 0;
28306 - atomic_set(&epoch->epoch_size, 0);
28307 + atomic_set_unchecked(&epoch->epoch_size, 0);
28308 atomic_set(&epoch->active, 0);
28309
28310 spin_lock(&mdev->epoch_lock);
28311 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28312 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28313 list_add(&epoch->list, &mdev->current_epoch->list);
28314 mdev->current_epoch = epoch;
28315 mdev->epochs++;
28316 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28317 spin_unlock(&mdev->peer_seq_lock);
28318
28319 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28320 - atomic_inc(&mdev->current_epoch->epoch_size);
28321 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28322 return drbd_drain_block(mdev, data_size);
28323 }
28324
28325 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28326
28327 spin_lock(&mdev->epoch_lock);
28328 e->epoch = mdev->current_epoch;
28329 - atomic_inc(&e->epoch->epoch_size);
28330 + atomic_inc_unchecked(&e->epoch->epoch_size);
28331 atomic_inc(&e->epoch->active);
28332 spin_unlock(&mdev->epoch_lock);
28333
28334 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28335 D_ASSERT(list_empty(&mdev->done_ee));
28336
28337 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28338 - atomic_set(&mdev->current_epoch->epoch_size, 0);
28339 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28340 D_ASSERT(list_empty(&mdev->current_epoch->list));
28341 }
28342
28343 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28344 index 1e888c9..05cf1b0 100644
28345 --- a/drivers/block/loop.c
28346 +++ b/drivers/block/loop.c
28347 @@ -227,7 +227,7 @@ static int __do_lo_send_write(struct file *file,
28348 mm_segment_t old_fs = get_fs();
28349
28350 set_fs(get_ds());
28351 - bw = file->f_op->write(file, buf, len, &pos);
28352 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28353 set_fs(old_fs);
28354 if (likely(bw == len))
28355 return 0;
28356 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
28357 index 4364303..9adf4ee 100644
28358 --- a/drivers/char/Kconfig
28359 +++ b/drivers/char/Kconfig
28360 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28361
28362 config DEVKMEM
28363 bool "/dev/kmem virtual device support"
28364 - default y
28365 + default n
28366 + depends on !GRKERNSEC_KMEM
28367 help
28368 Say Y here if you want to support the /dev/kmem device. The
28369 /dev/kmem device is rarely used, but can be used for certain
28370 @@ -596,6 +597,7 @@ config DEVPORT
28371 bool
28372 depends on !M68K
28373 depends on ISA || PCI
28374 + depends on !GRKERNSEC_KMEM
28375 default y
28376
28377 source "drivers/s390/char/Kconfig"
28378 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
28379 index 2e04433..22afc64 100644
28380 --- a/drivers/char/agp/frontend.c
28381 +++ b/drivers/char/agp/frontend.c
28382 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
28383 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
28384 return -EFAULT;
28385
28386 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
28387 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
28388 return -EFAULT;
28389
28390 client = agp_find_client_by_pid(reserve.pid);
28391 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
28392 index 095ab90..afad0a4 100644
28393 --- a/drivers/char/briq_panel.c
28394 +++ b/drivers/char/briq_panel.c
28395 @@ -9,6 +9,7 @@
28396 #include <linux/types.h>
28397 #include <linux/errno.h>
28398 #include <linux/tty.h>
28399 +#include <linux/mutex.h>
28400 #include <linux/timer.h>
28401 #include <linux/kernel.h>
28402 #include <linux/wait.h>
28403 @@ -34,6 +35,7 @@ static int vfd_is_open;
28404 static unsigned char vfd[40];
28405 static int vfd_cursor;
28406 static unsigned char ledpb, led;
28407 +static DEFINE_MUTEX(vfd_mutex);
28408
28409 static void update_vfd(void)
28410 {
28411 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28412 if (!vfd_is_open)
28413 return -EBUSY;
28414
28415 + mutex_lock(&vfd_mutex);
28416 for (;;) {
28417 char c;
28418 if (!indx)
28419 break;
28420 - if (get_user(c, buf))
28421 + if (get_user(c, buf)) {
28422 + mutex_unlock(&vfd_mutex);
28423 return -EFAULT;
28424 + }
28425 if (esc) {
28426 set_led(c);
28427 esc = 0;
28428 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28429 buf++;
28430 }
28431 update_vfd();
28432 + mutex_unlock(&vfd_mutex);
28433
28434 return len;
28435 }
28436 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
28437 index f773a9d..65cd683 100644
28438 --- a/drivers/char/genrtc.c
28439 +++ b/drivers/char/genrtc.c
28440 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
28441 switch (cmd) {
28442
28443 case RTC_PLL_GET:
28444 + memset(&pll, 0, sizeof(pll));
28445 if (get_rtc_pll(&pll))
28446 return -EINVAL;
28447 else
28448 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
28449 index 0833896..cccce52 100644
28450 --- a/drivers/char/hpet.c
28451 +++ b/drivers/char/hpet.c
28452 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
28453 }
28454
28455 static int
28456 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
28457 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
28458 struct hpet_info *info)
28459 {
28460 struct hpet_timer __iomem *timer;
28461 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
28462 index 58c0e63..46c16bf 100644
28463 --- a/drivers/char/ipmi/ipmi_msghandler.c
28464 +++ b/drivers/char/ipmi/ipmi_msghandler.c
28465 @@ -415,7 +415,7 @@ struct ipmi_smi {
28466 struct proc_dir_entry *proc_dir;
28467 char proc_dir_name[10];
28468
28469 - atomic_t stats[IPMI_NUM_STATS];
28470 + atomic_unchecked_t stats[IPMI_NUM_STATS];
28471
28472 /*
28473 * run_to_completion duplicate of smb_info, smi_info
28474 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
28475
28476
28477 #define ipmi_inc_stat(intf, stat) \
28478 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
28479 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
28480 #define ipmi_get_stat(intf, stat) \
28481 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
28482 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
28483
28484 static int is_lan_addr(struct ipmi_addr *addr)
28485 {
28486 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
28487 INIT_LIST_HEAD(&intf->cmd_rcvrs);
28488 init_waitqueue_head(&intf->waitq);
28489 for (i = 0; i < IPMI_NUM_STATS; i++)
28490 - atomic_set(&intf->stats[i], 0);
28491 + atomic_set_unchecked(&intf->stats[i], 0);
28492
28493 intf->proc_dir = NULL;
28494
28495 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
28496 index 9397ab4..d01bee1 100644
28497 --- a/drivers/char/ipmi/ipmi_si_intf.c
28498 +++ b/drivers/char/ipmi/ipmi_si_intf.c
28499 @@ -277,7 +277,7 @@ struct smi_info {
28500 unsigned char slave_addr;
28501
28502 /* Counters and things for the proc filesystem. */
28503 - atomic_t stats[SI_NUM_STATS];
28504 + atomic_unchecked_t stats[SI_NUM_STATS];
28505
28506 struct task_struct *thread;
28507
28508 @@ -286,9 +286,9 @@ struct smi_info {
28509 };
28510
28511 #define smi_inc_stat(smi, stat) \
28512 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28513 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28514 #define smi_get_stat(smi, stat) \
28515 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28516 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28517
28518 #define SI_MAX_PARMS 4
28519
28520 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
28521 atomic_set(&new_smi->req_events, 0);
28522 new_smi->run_to_completion = 0;
28523 for (i = 0; i < SI_NUM_STATS; i++)
28524 - atomic_set(&new_smi->stats[i], 0);
28525 + atomic_set_unchecked(&new_smi->stats[i], 0);
28526
28527 new_smi->interrupt_disabled = 1;
28528 atomic_set(&new_smi->stop_operation, 0);
28529 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
28530 index 1aeaaba..e018570 100644
28531 --- a/drivers/char/mbcs.c
28532 +++ b/drivers/char/mbcs.c
28533 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
28534 return 0;
28535 }
28536
28537 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
28538 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
28539 {
28540 .part_num = MBCS_PART_NUM,
28541 .mfg_num = MBCS_MFG_NUM,
28542 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
28543 index 1451790..f705c30 100644
28544 --- a/drivers/char/mem.c
28545 +++ b/drivers/char/mem.c
28546 @@ -18,6 +18,7 @@
28547 #include <linux/raw.h>
28548 #include <linux/tty.h>
28549 #include <linux/capability.h>
28550 +#include <linux/security.h>
28551 #include <linux/ptrace.h>
28552 #include <linux/device.h>
28553 #include <linux/highmem.h>
28554 @@ -35,6 +36,10 @@
28555 # include <linux/efi.h>
28556 #endif
28557
28558 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28559 +extern const struct file_operations grsec_fops;
28560 +#endif
28561 +
28562 static inline unsigned long size_inside_page(unsigned long start,
28563 unsigned long size)
28564 {
28565 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28566
28567 while (cursor < to) {
28568 if (!devmem_is_allowed(pfn)) {
28569 +#ifdef CONFIG_GRKERNSEC_KMEM
28570 + gr_handle_mem_readwrite(from, to);
28571 +#else
28572 printk(KERN_INFO
28573 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28574 current->comm, from, to);
28575 +#endif
28576 return 0;
28577 }
28578 cursor += PAGE_SIZE;
28579 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28580 }
28581 return 1;
28582 }
28583 +#elif defined(CONFIG_GRKERNSEC_KMEM)
28584 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28585 +{
28586 + return 0;
28587 +}
28588 #else
28589 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28590 {
28591 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28592
28593 while (count > 0) {
28594 unsigned long remaining;
28595 + char *temp;
28596
28597 sz = size_inside_page(p, count);
28598
28599 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28600 if (!ptr)
28601 return -EFAULT;
28602
28603 - remaining = copy_to_user(buf, ptr, sz);
28604 +#ifdef CONFIG_PAX_USERCOPY
28605 + temp = kmalloc(sz, GFP_KERNEL);
28606 + if (!temp) {
28607 + unxlate_dev_mem_ptr(p, ptr);
28608 + return -ENOMEM;
28609 + }
28610 + memcpy(temp, ptr, sz);
28611 +#else
28612 + temp = ptr;
28613 +#endif
28614 +
28615 + remaining = copy_to_user(buf, temp, sz);
28616 +
28617 +#ifdef CONFIG_PAX_USERCOPY
28618 + kfree(temp);
28619 +#endif
28620 +
28621 unxlate_dev_mem_ptr(p, ptr);
28622 if (remaining)
28623 return -EFAULT;
28624 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28625 size_t count, loff_t *ppos)
28626 {
28627 unsigned long p = *ppos;
28628 - ssize_t low_count, read, sz;
28629 + ssize_t low_count, read, sz, err = 0;
28630 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28631 - int err = 0;
28632
28633 read = 0;
28634 if (p < (unsigned long) high_memory) {
28635 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28636 }
28637 #endif
28638 while (low_count > 0) {
28639 + char *temp;
28640 +
28641 sz = size_inside_page(p, low_count);
28642
28643 /*
28644 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28645 */
28646 kbuf = xlate_dev_kmem_ptr((char *)p);
28647
28648 - if (copy_to_user(buf, kbuf, sz))
28649 +#ifdef CONFIG_PAX_USERCOPY
28650 + temp = kmalloc(sz, GFP_KERNEL);
28651 + if (!temp)
28652 + return -ENOMEM;
28653 + memcpy(temp, kbuf, sz);
28654 +#else
28655 + temp = kbuf;
28656 +#endif
28657 +
28658 + err = copy_to_user(buf, temp, sz);
28659 +
28660 +#ifdef CONFIG_PAX_USERCOPY
28661 + kfree(temp);
28662 +#endif
28663 +
28664 + if (err)
28665 return -EFAULT;
28666 buf += sz;
28667 p += sz;
28668 @@ -867,6 +914,9 @@ static const struct memdev {
28669 #ifdef CONFIG_CRASH_DUMP
28670 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28671 #endif
28672 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28673 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28674 +#endif
28675 };
28676
28677 static int memory_open(struct inode *inode, struct file *filp)
28678 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
28679 index da3cfee..a5a6606 100644
28680 --- a/drivers/char/nvram.c
28681 +++ b/drivers/char/nvram.c
28682 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
28683
28684 spin_unlock_irq(&rtc_lock);
28685
28686 - if (copy_to_user(buf, contents, tmp - contents))
28687 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28688 return -EFAULT;
28689
28690 *ppos = i;
28691 diff --git a/drivers/char/random.c b/drivers/char/random.c
28692 index 6035ab8..bdfe4fd 100644
28693 --- a/drivers/char/random.c
28694 +++ b/drivers/char/random.c
28695 @@ -261,8 +261,13 @@
28696 /*
28697 * Configuration information
28698 */
28699 +#ifdef CONFIG_GRKERNSEC_RANDNET
28700 +#define INPUT_POOL_WORDS 512
28701 +#define OUTPUT_POOL_WORDS 128
28702 +#else
28703 #define INPUT_POOL_WORDS 128
28704 #define OUTPUT_POOL_WORDS 32
28705 +#endif
28706 #define SEC_XFER_SIZE 512
28707 #define EXTRACT_SIZE 10
28708
28709 @@ -300,10 +305,17 @@ static struct poolinfo {
28710 int poolwords;
28711 int tap1, tap2, tap3, tap4, tap5;
28712 } poolinfo_table[] = {
28713 +#ifdef CONFIG_GRKERNSEC_RANDNET
28714 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28715 + { 512, 411, 308, 208, 104, 1 },
28716 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28717 + { 128, 103, 76, 51, 25, 1 },
28718 +#else
28719 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28720 { 128, 103, 76, 51, 25, 1 },
28721 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28722 { 32, 26, 20, 14, 7, 1 },
28723 +#endif
28724 #if 0
28725 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28726 { 2048, 1638, 1231, 819, 411, 1 },
28727 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
28728
28729 extract_buf(r, tmp);
28730 i = min_t(int, nbytes, EXTRACT_SIZE);
28731 - if (copy_to_user(buf, tmp, i)) {
28732 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28733 ret = -EFAULT;
28734 break;
28735 }
28736 @@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28737 #include <linux/sysctl.h>
28738
28739 static int min_read_thresh = 8, min_write_thresh;
28740 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
28741 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28742 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28743 static char sysctl_bootid[16];
28744
28745 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
28746 index 1ee8ce7..b778bef 100644
28747 --- a/drivers/char/sonypi.c
28748 +++ b/drivers/char/sonypi.c
28749 @@ -55,6 +55,7 @@
28750 #include <asm/uaccess.h>
28751 #include <asm/io.h>
28752 #include <asm/system.h>
28753 +#include <asm/local.h>
28754
28755 #include <linux/sonypi.h>
28756
28757 @@ -491,7 +492,7 @@ static struct sonypi_device {
28758 spinlock_t fifo_lock;
28759 wait_queue_head_t fifo_proc_list;
28760 struct fasync_struct *fifo_async;
28761 - int open_count;
28762 + local_t open_count;
28763 int model;
28764 struct input_dev *input_jog_dev;
28765 struct input_dev *input_key_dev;
28766 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
28767 static int sonypi_misc_release(struct inode *inode, struct file *file)
28768 {
28769 mutex_lock(&sonypi_device.lock);
28770 - sonypi_device.open_count--;
28771 + local_dec(&sonypi_device.open_count);
28772 mutex_unlock(&sonypi_device.lock);
28773 return 0;
28774 }
28775 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
28776 {
28777 mutex_lock(&sonypi_device.lock);
28778 /* Flush input queue on first open */
28779 - if (!sonypi_device.open_count)
28780 + if (!local_read(&sonypi_device.open_count))
28781 kfifo_reset(&sonypi_device.fifo);
28782 - sonypi_device.open_count++;
28783 + local_inc(&sonypi_device.open_count);
28784 mutex_unlock(&sonypi_device.lock);
28785
28786 return 0;
28787 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
28788 index 361a1df..2471eee 100644
28789 --- a/drivers/char/tpm/tpm.c
28790 +++ b/drivers/char/tpm/tpm.c
28791 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
28792 chip->vendor.req_complete_val)
28793 goto out_recv;
28794
28795 - if ((status == chip->vendor.req_canceled)) {
28796 + if (status == chip->vendor.req_canceled) {
28797 dev_err(chip->dev, "Operation Canceled\n");
28798 rc = -ECANCELED;
28799 goto out;
28800 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
28801 index 0636520..169c1d0 100644
28802 --- a/drivers/char/tpm/tpm_bios.c
28803 +++ b/drivers/char/tpm/tpm_bios.c
28804 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
28805 event = addr;
28806
28807 if ((event->event_type == 0 && event->event_size == 0) ||
28808 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28809 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28810 return NULL;
28811
28812 return addr;
28813 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
28814 return NULL;
28815
28816 if ((event->event_type == 0 && event->event_size == 0) ||
28817 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28818 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28819 return NULL;
28820
28821 (*pos)++;
28822 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
28823 int i;
28824
28825 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28826 - seq_putc(m, data[i]);
28827 + if (!seq_putc(m, data[i]))
28828 + return -EFAULT;
28829
28830 return 0;
28831 }
28832 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
28833 log->bios_event_log_end = log->bios_event_log + len;
28834
28835 virt = acpi_os_map_memory(start, len);
28836 + if (!virt) {
28837 + kfree(log->bios_event_log);
28838 + log->bios_event_log = NULL;
28839 + return -EFAULT;
28840 + }
28841
28842 - memcpy(log->bios_event_log, virt, len);
28843 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
28844
28845 acpi_os_unmap_memory(virt, len);
28846 return 0;
28847 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
28848 index 8e3c46d..c139b99 100644
28849 --- a/drivers/char/virtio_console.c
28850 +++ b/drivers/char/virtio_console.c
28851 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
28852 if (to_user) {
28853 ssize_t ret;
28854
28855 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
28856 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
28857 if (ret)
28858 return -EFAULT;
28859 } else {
28860 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
28861 if (!port_has_data(port) && !port->host_connected)
28862 return 0;
28863
28864 - return fill_readbuf(port, ubuf, count, true);
28865 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
28866 }
28867
28868 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
28869 diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
28870 index eb1d864..39ee5a7 100644
28871 --- a/drivers/dma/dmatest.c
28872 +++ b/drivers/dma/dmatest.c
28873 @@ -591,7 +591,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
28874 }
28875 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
28876 cnt = dmatest_add_threads(dtc, DMA_PQ);
28877 - thread_count += cnt > 0 ?: 0;
28878 + thread_count += cnt > 0 ? cnt : 0;
28879 }
28880
28881 pr_info("dmatest: Started %u threads using %s\n",
28882 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
28883 index c9eee6d..f9d5280 100644
28884 --- a/drivers/edac/amd64_edac.c
28885 +++ b/drivers/edac/amd64_edac.c
28886 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
28887 * PCI core identifies what devices are on a system during boot, and then
28888 * inquiry this table to see if this driver is for a given device found.
28889 */
28890 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
28891 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
28892 {
28893 .vendor = PCI_VENDOR_ID_AMD,
28894 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
28895 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
28896 index e47e73b..348e0bd 100644
28897 --- a/drivers/edac/amd76x_edac.c
28898 +++ b/drivers/edac/amd76x_edac.c
28899 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
28900 edac_mc_free(mci);
28901 }
28902
28903 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
28904 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
28905 {
28906 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28907 AMD762},
28908 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
28909 index 1af531a..3a8ff27 100644
28910 --- a/drivers/edac/e752x_edac.c
28911 +++ b/drivers/edac/e752x_edac.c
28912 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
28913 edac_mc_free(mci);
28914 }
28915
28916 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
28917 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
28918 {
28919 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28920 E7520},
28921 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
28922 index 6ffb6d2..383d8d7 100644
28923 --- a/drivers/edac/e7xxx_edac.c
28924 +++ b/drivers/edac/e7xxx_edac.c
28925 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
28926 edac_mc_free(mci);
28927 }
28928
28929 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
28930 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
28931 {
28932 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28933 E7205},
28934 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
28935 index 495198a..ac08c85 100644
28936 --- a/drivers/edac/edac_pci_sysfs.c
28937 +++ b/drivers/edac/edac_pci_sysfs.c
28938 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
28939 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28940 static int edac_pci_poll_msec = 1000; /* one second workq period */
28941
28942 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
28943 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28944 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28945 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28946
28947 static struct kobject *edac_pci_top_main_kobj;
28948 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28949 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28950 edac_printk(KERN_CRIT, EDAC_PCI,
28951 "Signaled System Error on %s\n",
28952 pci_name(dev));
28953 - atomic_inc(&pci_nonparity_count);
28954 + atomic_inc_unchecked(&pci_nonparity_count);
28955 }
28956
28957 if (status & (PCI_STATUS_PARITY)) {
28958 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28959 "Master Data Parity Error on %s\n",
28960 pci_name(dev));
28961
28962 - atomic_inc(&pci_parity_count);
28963 + atomic_inc_unchecked(&pci_parity_count);
28964 }
28965
28966 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28967 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28968 "Detected Parity Error on %s\n",
28969 pci_name(dev));
28970
28971 - atomic_inc(&pci_parity_count);
28972 + atomic_inc_unchecked(&pci_parity_count);
28973 }
28974 }
28975
28976 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28977 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28978 "Signaled System Error on %s\n",
28979 pci_name(dev));
28980 - atomic_inc(&pci_nonparity_count);
28981 + atomic_inc_unchecked(&pci_nonparity_count);
28982 }
28983
28984 if (status & (PCI_STATUS_PARITY)) {
28985 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28986 "Master Data Parity Error on "
28987 "%s\n", pci_name(dev));
28988
28989 - atomic_inc(&pci_parity_count);
28990 + atomic_inc_unchecked(&pci_parity_count);
28991 }
28992
28993 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28994 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28995 "Detected Parity Error on %s\n",
28996 pci_name(dev));
28997
28998 - atomic_inc(&pci_parity_count);
28999 + atomic_inc_unchecked(&pci_parity_count);
29000 }
29001 }
29002 }
29003 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29004 if (!check_pci_errors)
29005 return;
29006
29007 - before_count = atomic_read(&pci_parity_count);
29008 + before_count = atomic_read_unchecked(&pci_parity_count);
29009
29010 /* scan all PCI devices looking for a Parity Error on devices and
29011 * bridges.
29012 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29013 /* Only if operator has selected panic on PCI Error */
29014 if (edac_pci_get_panic_on_pe()) {
29015 /* If the count is different 'after' from 'before' */
29016 - if (before_count != atomic_read(&pci_parity_count))
29017 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29018 panic("EDAC: PCI Parity Error");
29019 }
29020 }
29021 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29022 index c0510b3..6e2a954 100644
29023 --- a/drivers/edac/i3000_edac.c
29024 +++ b/drivers/edac/i3000_edac.c
29025 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29026 edac_mc_free(mci);
29027 }
29028
29029 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29030 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29031 {
29032 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29033 I3000},
29034 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29035 index aa08497..7e6822a 100644
29036 --- a/drivers/edac/i3200_edac.c
29037 +++ b/drivers/edac/i3200_edac.c
29038 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29039 edac_mc_free(mci);
29040 }
29041
29042 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29043 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29044 {
29045 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29046 I3200},
29047 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29048 index 4dc3ac2..67d05a6 100644
29049 --- a/drivers/edac/i5000_edac.c
29050 +++ b/drivers/edac/i5000_edac.c
29051 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29052 *
29053 * The "E500P" device is the first device supported.
29054 */
29055 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29056 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29057 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29058 .driver_data = I5000P},
29059
29060 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29061 index bcbdeec..9886d16 100644
29062 --- a/drivers/edac/i5100_edac.c
29063 +++ b/drivers/edac/i5100_edac.c
29064 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29065 edac_mc_free(mci);
29066 }
29067
29068 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29069 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29070 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29071 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29072 { 0, }
29073 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29074 index 74d6ec34..baff517 100644
29075 --- a/drivers/edac/i5400_edac.c
29076 +++ b/drivers/edac/i5400_edac.c
29077 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29078 *
29079 * The "E500P" device is the first device supported.
29080 */
29081 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29082 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29083 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29084 {0,} /* 0 terminated list. */
29085 };
29086 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29087 index 6104dba..e7ea8e1 100644
29088 --- a/drivers/edac/i7300_edac.c
29089 +++ b/drivers/edac/i7300_edac.c
29090 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29091 *
29092 * Has only 8086:360c PCI ID
29093 */
29094 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29095 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29096 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29097 {0,} /* 0 terminated list. */
29098 };
29099 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29100 index 70ad892..178943c 100644
29101 --- a/drivers/edac/i7core_edac.c
29102 +++ b/drivers/edac/i7core_edac.c
29103 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29104 /*
29105 * pci_device_id table for which devices we are looking for
29106 */
29107 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29108 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29109 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29110 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29111 {0,} /* 0 terminated list. */
29112 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29113 index 4329d39..f3022ef 100644
29114 --- a/drivers/edac/i82443bxgx_edac.c
29115 +++ b/drivers/edac/i82443bxgx_edac.c
29116 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29117
29118 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29119
29120 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29121 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29122 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29123 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29124 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29125 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29126 index 931a057..fd28340 100644
29127 --- a/drivers/edac/i82860_edac.c
29128 +++ b/drivers/edac/i82860_edac.c
29129 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29130 edac_mc_free(mci);
29131 }
29132
29133 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29134 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29135 {
29136 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29137 I82860},
29138 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29139 index 33864c6..01edc61 100644
29140 --- a/drivers/edac/i82875p_edac.c
29141 +++ b/drivers/edac/i82875p_edac.c
29142 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29143 edac_mc_free(mci);
29144 }
29145
29146 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29147 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29148 {
29149 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29150 I82875P},
29151 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29152 index a5da732..983363b 100644
29153 --- a/drivers/edac/i82975x_edac.c
29154 +++ b/drivers/edac/i82975x_edac.c
29155 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29156 edac_mc_free(mci);
29157 }
29158
29159 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29160 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29161 {
29162 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29163 I82975X
29164 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29165 index 0106747..0b40417 100644
29166 --- a/drivers/edac/mce_amd.h
29167 +++ b/drivers/edac/mce_amd.h
29168 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
29169 bool (*dc_mce)(u16, u8);
29170 bool (*ic_mce)(u16, u8);
29171 bool (*nb_mce)(u16, u8);
29172 -};
29173 +} __no_const;
29174
29175 void amd_report_gart_errors(bool);
29176 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29177 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29178 index b153674..ad2ba9b 100644
29179 --- a/drivers/edac/r82600_edac.c
29180 +++ b/drivers/edac/r82600_edac.c
29181 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29182 edac_mc_free(mci);
29183 }
29184
29185 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29186 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29187 {
29188 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29189 },
29190 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29191 index 7a402bf..af0b211 100644
29192 --- a/drivers/edac/sb_edac.c
29193 +++ b/drivers/edac/sb_edac.c
29194 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29195 /*
29196 * pci_device_id table for which devices we are looking for
29197 */
29198 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29199 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29200 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29201 {0,} /* 0 terminated list. */
29202 };
29203 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29204 index b6f47de..c5acf3a 100644
29205 --- a/drivers/edac/x38_edac.c
29206 +++ b/drivers/edac/x38_edac.c
29207 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29208 edac_mc_free(mci);
29209 }
29210
29211 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29212 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29213 {
29214 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29215 X38},
29216 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29217 index 85661b0..c784559a 100644
29218 --- a/drivers/firewire/core-card.c
29219 +++ b/drivers/firewire/core-card.c
29220 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29221
29222 void fw_core_remove_card(struct fw_card *card)
29223 {
29224 - struct fw_card_driver dummy_driver = dummy_driver_template;
29225 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29226
29227 card->driver->update_phy_reg(card, 4,
29228 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29229 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29230 index 4799393..37bd3ab 100644
29231 --- a/drivers/firewire/core-cdev.c
29232 +++ b/drivers/firewire/core-cdev.c
29233 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29234 int ret;
29235
29236 if ((request->channels == 0 && request->bandwidth == 0) ||
29237 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29238 - request->bandwidth < 0)
29239 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29240 return -EINVAL;
29241
29242 r = kmalloc(sizeof(*r), GFP_KERNEL);
29243 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29244 index 855ab3f..11f4bbd 100644
29245 --- a/drivers/firewire/core-transaction.c
29246 +++ b/drivers/firewire/core-transaction.c
29247 @@ -37,6 +37,7 @@
29248 #include <linux/timer.h>
29249 #include <linux/types.h>
29250 #include <linux/workqueue.h>
29251 +#include <linux/sched.h>
29252
29253 #include <asm/byteorder.h>
29254
29255 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29256 index b45be57..5fad18b 100644
29257 --- a/drivers/firewire/core.h
29258 +++ b/drivers/firewire/core.h
29259 @@ -101,6 +101,7 @@ struct fw_card_driver {
29260
29261 int (*stop_iso)(struct fw_iso_context *ctx);
29262 };
29263 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29264
29265 void fw_card_initialize(struct fw_card *card,
29266 const struct fw_card_driver *driver, struct device *device);
29267 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29268 index 153980b..4b4d046 100644
29269 --- a/drivers/firmware/dmi_scan.c
29270 +++ b/drivers/firmware/dmi_scan.c
29271 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29272 }
29273 }
29274 else {
29275 - /*
29276 - * no iounmap() for that ioremap(); it would be a no-op, but
29277 - * it's so early in setup that sucker gets confused into doing
29278 - * what it shouldn't if we actually call it.
29279 - */
29280 p = dmi_ioremap(0xF0000, 0x10000);
29281 if (p == NULL)
29282 goto error;
29283 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29284 if (buf == NULL)
29285 return -1;
29286
29287 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29288 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29289
29290 iounmap(buf);
29291 return 0;
29292 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29293 index 98723cb..10ca85b 100644
29294 --- a/drivers/gpio/gpio-vr41xx.c
29295 +++ b/drivers/gpio/gpio-vr41xx.c
29296 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29297 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29298 maskl, pendl, maskh, pendh);
29299
29300 - atomic_inc(&irq_err_count);
29301 + atomic_inc_unchecked(&irq_err_count);
29302
29303 return -EINVAL;
29304 }
29305 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
29306 index 8323fc3..5c1d755 100644
29307 --- a/drivers/gpu/drm/drm_crtc.c
29308 +++ b/drivers/gpu/drm/drm_crtc.c
29309 @@ -1379,7 +1379,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29310 */
29311 if ((out_resp->count_modes >= mode_count) && mode_count) {
29312 copied = 0;
29313 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
29314 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
29315 list_for_each_entry(mode, &connector->modes, head) {
29316 drm_crtc_convert_to_umode(&u_mode, mode);
29317 if (copy_to_user(mode_ptr + copied,
29318 @@ -1394,8 +1394,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29319
29320 if ((out_resp->count_props >= props_count) && props_count) {
29321 copied = 0;
29322 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
29323 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
29324 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
29325 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
29326 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
29327 if (connector->property_ids[i] != 0) {
29328 if (put_user(connector->property_ids[i],
29329 @@ -1417,7 +1417,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29330
29331 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
29332 copied = 0;
29333 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
29334 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
29335 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
29336 if (connector->encoder_ids[i] != 0) {
29337 if (put_user(connector->encoder_ids[i],
29338 @@ -1576,7 +1576,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
29339 }
29340
29341 for (i = 0; i < crtc_req->count_connectors; i++) {
29342 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
29343 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
29344 if (get_user(out_id, &set_connectors_ptr[i])) {
29345 ret = -EFAULT;
29346 goto out;
29347 @@ -1857,7 +1857,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
29348 fb = obj_to_fb(obj);
29349
29350 num_clips = r->num_clips;
29351 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
29352 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
29353
29354 if (!num_clips != !clips_ptr) {
29355 ret = -EINVAL;
29356 @@ -2283,7 +2283,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29357 out_resp->flags = property->flags;
29358
29359 if ((out_resp->count_values >= value_count) && value_count) {
29360 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
29361 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
29362 for (i = 0; i < value_count; i++) {
29363 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
29364 ret = -EFAULT;
29365 @@ -2296,7 +2296,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29366 if (property->flags & DRM_MODE_PROP_ENUM) {
29367 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
29368 copied = 0;
29369 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
29370 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
29371 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
29372
29373 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
29374 @@ -2319,7 +2319,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29375 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
29376 copied = 0;
29377 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
29378 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
29379 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
29380
29381 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
29382 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
29383 @@ -2380,7 +2380,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
29384 struct drm_mode_get_blob *out_resp = data;
29385 struct drm_property_blob *blob;
29386 int ret = 0;
29387 - void *blob_ptr;
29388 + void __user *blob_ptr;
29389
29390 if (!drm_core_check_feature(dev, DRIVER_MODESET))
29391 return -EINVAL;
29392 @@ -2394,7 +2394,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
29393 blob = obj_to_blob(obj);
29394
29395 if (out_resp->length == blob->length) {
29396 - blob_ptr = (void *)(unsigned long)out_resp->data;
29397 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
29398 if (copy_to_user(blob_ptr, blob->data, blob->length)){
29399 ret = -EFAULT;
29400 goto done;
29401 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29402 index d2619d7..bd6bd00 100644
29403 --- a/drivers/gpu/drm/drm_crtc_helper.c
29404 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29405 @@ -279,7 +279,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29406 struct drm_crtc *tmp;
29407 int crtc_mask = 1;
29408
29409 - WARN(!crtc, "checking null crtc?\n");
29410 + BUG_ON(!crtc);
29411
29412 dev = crtc->dev;
29413
29414 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29415 index 40c187c..5746164 100644
29416 --- a/drivers/gpu/drm/drm_drv.c
29417 +++ b/drivers/gpu/drm/drm_drv.c
29418 @@ -308,7 +308,7 @@ module_exit(drm_core_exit);
29419 /**
29420 * Copy and IOCTL return string to user space
29421 */
29422 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29423 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29424 {
29425 int len;
29426
29427 @@ -387,7 +387,7 @@ long drm_ioctl(struct file *filp,
29428
29429 dev = file_priv->minor->dev;
29430 atomic_inc(&dev->ioctl_count);
29431 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29432 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29433 ++file_priv->ioctl_count;
29434
29435 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29436 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29437 index 828bf65..cdaa0e9 100644
29438 --- a/drivers/gpu/drm/drm_fops.c
29439 +++ b/drivers/gpu/drm/drm_fops.c
29440 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29441 }
29442
29443 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29444 - atomic_set(&dev->counts[i], 0);
29445 + atomic_set_unchecked(&dev->counts[i], 0);
29446
29447 dev->sigdata.lock = NULL;
29448
29449 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
29450
29451 retcode = drm_open_helper(inode, filp, dev);
29452 if (!retcode) {
29453 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29454 - if (!dev->open_count++)
29455 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29456 + if (local_inc_return(&dev->open_count) == 1)
29457 retcode = drm_setup(dev);
29458 }
29459 if (!retcode) {
29460 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
29461
29462 mutex_lock(&drm_global_mutex);
29463
29464 - DRM_DEBUG("open_count = %d\n", dev->open_count);
29465 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
29466
29467 if (dev->driver->preclose)
29468 dev->driver->preclose(dev, file_priv);
29469 @@ -485,7 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)
29470 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29471 task_pid_nr(current),
29472 (long)old_encode_dev(file_priv->minor->device),
29473 - dev->open_count);
29474 + local_read(&dev->open_count));
29475
29476 /* Release any auth tokens that might point to this file_priv,
29477 (do that under the drm_global_mutex) */
29478 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
29479 * End inline drm_release
29480 */
29481
29482 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
29483 - if (!--dev->open_count) {
29484 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
29485 + if (local_dec_and_test(&dev->open_count)) {
29486 if (atomic_read(&dev->ioctl_count)) {
29487 DRM_ERROR("Device busy: %d\n",
29488 atomic_read(&dev->ioctl_count));
29489 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
29490 index c87dc96..326055d 100644
29491 --- a/drivers/gpu/drm/drm_global.c
29492 +++ b/drivers/gpu/drm/drm_global.c
29493 @@ -36,7 +36,7 @@
29494 struct drm_global_item {
29495 struct mutex mutex;
29496 void *object;
29497 - int refcount;
29498 + atomic_t refcount;
29499 };
29500
29501 static struct drm_global_item glob[DRM_GLOBAL_NUM];
29502 @@ -49,7 +49,7 @@ void drm_global_init(void)
29503 struct drm_global_item *item = &glob[i];
29504 mutex_init(&item->mutex);
29505 item->object = NULL;
29506 - item->refcount = 0;
29507 + atomic_set(&item->refcount, 0);
29508 }
29509 }
29510
29511 @@ -59,7 +59,7 @@ void drm_global_release(void)
29512 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
29513 struct drm_global_item *item = &glob[i];
29514 BUG_ON(item->object != NULL);
29515 - BUG_ON(item->refcount != 0);
29516 + BUG_ON(atomic_read(&item->refcount) != 0);
29517 }
29518 }
29519
29520 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29521 void *object;
29522
29523 mutex_lock(&item->mutex);
29524 - if (item->refcount == 0) {
29525 + if (atomic_read(&item->refcount) == 0) {
29526 item->object = kzalloc(ref->size, GFP_KERNEL);
29527 if (unlikely(item->object == NULL)) {
29528 ret = -ENOMEM;
29529 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29530 goto out_err;
29531
29532 }
29533 - ++item->refcount;
29534 + atomic_inc(&item->refcount);
29535 ref->object = item->object;
29536 object = item->object;
29537 mutex_unlock(&item->mutex);
29538 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
29539 struct drm_global_item *item = &glob[ref->global_type];
29540
29541 mutex_lock(&item->mutex);
29542 - BUG_ON(item->refcount == 0);
29543 + BUG_ON(atomic_read(&item->refcount) == 0);
29544 BUG_ON(ref->object != item->object);
29545 - if (--item->refcount == 0) {
29546 + if (atomic_dec_and_test(&item->refcount)) {
29547 ref->release(ref);
29548 item->object = NULL;
29549 }
29550 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
29551 index ab1162d..42587b2 100644
29552 --- a/drivers/gpu/drm/drm_info.c
29553 +++ b/drivers/gpu/drm/drm_info.c
29554 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
29555 struct drm_local_map *map;
29556 struct drm_map_list *r_list;
29557
29558 - /* Hardcoded from _DRM_FRAME_BUFFER,
29559 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
29560 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
29561 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
29562 + static const char * const types[] = {
29563 + [_DRM_FRAME_BUFFER] = "FB",
29564 + [_DRM_REGISTERS] = "REG",
29565 + [_DRM_SHM] = "SHM",
29566 + [_DRM_AGP] = "AGP",
29567 + [_DRM_SCATTER_GATHER] = "SG",
29568 + [_DRM_CONSISTENT] = "PCI",
29569 + [_DRM_GEM] = "GEM" };
29570 const char *type;
29571 int i;
29572
29573 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
29574 map = r_list->map;
29575 if (!map)
29576 continue;
29577 - if (map->type < 0 || map->type > 5)
29578 + if (map->type >= ARRAY_SIZE(types))
29579 type = "??";
29580 else
29581 type = types[map->type];
29582 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
29583 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29584 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29585 vma->vm_flags & VM_IO ? 'i' : '-',
29586 +#ifdef CONFIG_GRKERNSEC_HIDESYM
29587 + 0);
29588 +#else
29589 vma->vm_pgoff);
29590 +#endif
29591
29592 #if defined(__i386__)
29593 pgprot = pgprot_val(vma->vm_page_prot);
29594 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
29595 index ddd70db..40321e6 100644
29596 --- a/drivers/gpu/drm/drm_ioc32.c
29597 +++ b/drivers/gpu/drm/drm_ioc32.c
29598 @@ -456,7 +456,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
29599 request = compat_alloc_user_space(nbytes);
29600 if (!access_ok(VERIFY_WRITE, request, nbytes))
29601 return -EFAULT;
29602 - list = (struct drm_buf_desc *) (request + 1);
29603 + list = (struct drm_buf_desc __user *) (request + 1);
29604
29605 if (__put_user(count, &request->count)
29606 || __put_user(list, &request->list))
29607 @@ -517,7 +517,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
29608 request = compat_alloc_user_space(nbytes);
29609 if (!access_ok(VERIFY_WRITE, request, nbytes))
29610 return -EFAULT;
29611 - list = (struct drm_buf_pub *) (request + 1);
29612 + list = (struct drm_buf_pub __user *) (request + 1);
29613
29614 if (__put_user(count, &request->count)
29615 || __put_user(list, &request->list))
29616 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
29617 index 904d7e9..ab88581 100644
29618 --- a/drivers/gpu/drm/drm_ioctl.c
29619 +++ b/drivers/gpu/drm/drm_ioctl.c
29620 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
29621 stats->data[i].value =
29622 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29623 else
29624 - stats->data[i].value = atomic_read(&dev->counts[i]);
29625 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29626 stats->data[i].type = dev->types[i];
29627 }
29628
29629 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
29630 index 632ae24..244cf4a 100644
29631 --- a/drivers/gpu/drm/drm_lock.c
29632 +++ b/drivers/gpu/drm/drm_lock.c
29633 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29634 if (drm_lock_take(&master->lock, lock->context)) {
29635 master->lock.file_priv = file_priv;
29636 master->lock.lock_time = jiffies;
29637 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29638 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29639 break; /* Got lock */
29640 }
29641
29642 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29643 return -EINVAL;
29644 }
29645
29646 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29647 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29648
29649 if (drm_lock_free(&master->lock, lock->context)) {
29650 /* FIXME: Should really bail out here. */
29651 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
29652 index 8f371e8..9f85d52 100644
29653 --- a/drivers/gpu/drm/i810/i810_dma.c
29654 +++ b/drivers/gpu/drm/i810/i810_dma.c
29655 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
29656 dma->buflist[vertex->idx],
29657 vertex->discard, vertex->used);
29658
29659 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29660 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29661 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29662 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29663 sarea_priv->last_enqueue = dev_priv->counter - 1;
29664 sarea_priv->last_dispatch = (int)hw_status[5];
29665
29666 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
29667 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29668 mc->last_render);
29669
29670 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29671 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29672 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29673 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29674 sarea_priv->last_enqueue = dev_priv->counter - 1;
29675 sarea_priv->last_dispatch = (int)hw_status[5];
29676
29677 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
29678 index c9339f4..f5e1b9d 100644
29679 --- a/drivers/gpu/drm/i810/i810_drv.h
29680 +++ b/drivers/gpu/drm/i810/i810_drv.h
29681 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29682 int page_flipping;
29683
29684 wait_queue_head_t irq_queue;
29685 - atomic_t irq_received;
29686 - atomic_t irq_emitted;
29687 + atomic_unchecked_t irq_received;
29688 + atomic_unchecked_t irq_emitted;
29689
29690 int front_offset;
29691 } drm_i810_private_t;
29692 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
29693 index b2e3c97..58cf079 100644
29694 --- a/drivers/gpu/drm/i915/i915_debugfs.c
29695 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
29696 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
29697 I915_READ(GTIMR));
29698 }
29699 seq_printf(m, "Interrupts received: %d\n",
29700 - atomic_read(&dev_priv->irq_received));
29701 + atomic_read_unchecked(&dev_priv->irq_received));
29702 for (i = 0; i < I915_NUM_RINGS; i++) {
29703 if (IS_GEN6(dev) || IS_GEN7(dev)) {
29704 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29705 @@ -1232,7 +1232,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
29706 return ret;
29707
29708 if (opregion->header)
29709 - seq_write(m, opregion->header, OPREGION_SIZE);
29710 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
29711
29712 mutex_unlock(&dev->struct_mutex);
29713
29714 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
29715 index c4da951..3c59c5c 100644
29716 --- a/drivers/gpu/drm/i915/i915_dma.c
29717 +++ b/drivers/gpu/drm/i915/i915_dma.c
29718 @@ -1172,7 +1172,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
29719 bool can_switch;
29720
29721 spin_lock(&dev->count_lock);
29722 - can_switch = (dev->open_count == 0);
29723 + can_switch = (local_read(&dev->open_count) == 0);
29724 spin_unlock(&dev->count_lock);
29725 return can_switch;
29726 }
29727 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
29728 index ae294a0..1755461 100644
29729 --- a/drivers/gpu/drm/i915/i915_drv.h
29730 +++ b/drivers/gpu/drm/i915/i915_drv.h
29731 @@ -229,7 +229,7 @@ struct drm_i915_display_funcs {
29732 /* render clock increase/decrease */
29733 /* display clock increase/decrease */
29734 /* pll clock increase/decrease */
29735 -};
29736 +} __no_const;
29737
29738 struct intel_device_info {
29739 u8 gen;
29740 @@ -318,7 +318,7 @@ typedef struct drm_i915_private {
29741 int current_page;
29742 int page_flipping;
29743
29744 - atomic_t irq_received;
29745 + atomic_unchecked_t irq_received;
29746
29747 /* protects the irq masks */
29748 spinlock_t irq_lock;
29749 @@ -893,7 +893,7 @@ struct drm_i915_gem_object {
29750 * will be page flipped away on the next vblank. When it
29751 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29752 */
29753 - atomic_t pending_flip;
29754 + atomic_unchecked_t pending_flip;
29755 };
29756
29757 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29758 @@ -1273,7 +1273,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
29759 extern void intel_teardown_gmbus(struct drm_device *dev);
29760 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29761 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29762 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29763 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29764 {
29765 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29766 }
29767 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29768 index b9da890..cad1d98 100644
29769 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29770 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29771 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
29772 i915_gem_clflush_object(obj);
29773
29774 if (obj->base.pending_write_domain)
29775 - cd->flips |= atomic_read(&obj->pending_flip);
29776 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29777
29778 /* The actual obj->write_domain will be updated with
29779 * pending_write_domain after we emit the accumulated flush for all
29780 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
29781
29782 static int
29783 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
29784 - int count)
29785 + unsigned int count)
29786 {
29787 - int i;
29788 + unsigned int i;
29789
29790 for (i = 0; i < count; i++) {
29791 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
29792 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
29793 index d47a53b..61154c2 100644
29794 --- a/drivers/gpu/drm/i915/i915_irq.c
29795 +++ b/drivers/gpu/drm/i915/i915_irq.c
29796 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
29797 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
29798 struct drm_i915_master_private *master_priv;
29799
29800 - atomic_inc(&dev_priv->irq_received);
29801 + atomic_inc_unchecked(&dev_priv->irq_received);
29802
29803 /* disable master interrupt before clearing iir */
29804 de_ier = I915_READ(DEIER);
29805 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
29806 struct drm_i915_master_private *master_priv;
29807 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
29808
29809 - atomic_inc(&dev_priv->irq_received);
29810 + atomic_inc_unchecked(&dev_priv->irq_received);
29811
29812 if (IS_GEN6(dev))
29813 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
29814 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
29815 int ret = IRQ_NONE, pipe;
29816 bool blc_event = false;
29817
29818 - atomic_inc(&dev_priv->irq_received);
29819 + atomic_inc_unchecked(&dev_priv->irq_received);
29820
29821 iir = I915_READ(IIR);
29822
29823 @@ -1750,7 +1750,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
29824 {
29825 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29826
29827 - atomic_set(&dev_priv->irq_received, 0);
29828 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29829
29830 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29831 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29832 @@ -1938,7 +1938,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
29833 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29834 int pipe;
29835
29836 - atomic_set(&dev_priv->irq_received, 0);
29837 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29838
29839 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29840 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29841 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
29842 index 9ec9755..6d1cf2d 100644
29843 --- a/drivers/gpu/drm/i915/intel_display.c
29844 +++ b/drivers/gpu/drm/i915/intel_display.c
29845 @@ -2230,7 +2230,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
29846
29847 wait_event(dev_priv->pending_flip_queue,
29848 atomic_read(&dev_priv->mm.wedged) ||
29849 - atomic_read(&obj->pending_flip) == 0);
29850 + atomic_read_unchecked(&obj->pending_flip) == 0);
29851
29852 /* Big Hammer, we also need to ensure that any pending
29853 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29854 @@ -2851,7 +2851,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
29855 obj = to_intel_framebuffer(crtc->fb)->obj;
29856 dev_priv = crtc->dev->dev_private;
29857 wait_event(dev_priv->pending_flip_queue,
29858 - atomic_read(&obj->pending_flip) == 0);
29859 + atomic_read_unchecked(&obj->pending_flip) == 0);
29860 }
29861
29862 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29863 @@ -6952,7 +6952,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
29864
29865 atomic_clear_mask(1 << intel_crtc->plane,
29866 &obj->pending_flip.counter);
29867 - if (atomic_read(&obj->pending_flip) == 0)
29868 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
29869 wake_up(&dev_priv->pending_flip_queue);
29870
29871 schedule_work(&work->work);
29872 @@ -7242,7 +7242,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29873 /* Block clients from rendering to the new back buffer until
29874 * the flip occurs and the object is no longer visible.
29875 */
29876 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29877 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29878
29879 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
29880 if (ret)
29881 @@ -7256,7 +7256,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29882 return 0;
29883
29884 cleanup_pending:
29885 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29886 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29887 drm_gem_object_unreference(&work->old_fb_obj->base);
29888 drm_gem_object_unreference(&obj->base);
29889 mutex_unlock(&dev->struct_mutex);
29890 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
29891 index 54558a0..2d97005 100644
29892 --- a/drivers/gpu/drm/mga/mga_drv.h
29893 +++ b/drivers/gpu/drm/mga/mga_drv.h
29894 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29895 u32 clear_cmd;
29896 u32 maccess;
29897
29898 - atomic_t vbl_received; /**< Number of vblanks received. */
29899 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29900 wait_queue_head_t fence_queue;
29901 - atomic_t last_fence_retired;
29902 + atomic_unchecked_t last_fence_retired;
29903 u32 next_fence_to_post;
29904
29905 unsigned int fb_cpp;
29906 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
29907 index 2581202..f230a8d9 100644
29908 --- a/drivers/gpu/drm/mga/mga_irq.c
29909 +++ b/drivers/gpu/drm/mga/mga_irq.c
29910 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
29911 if (crtc != 0)
29912 return 0;
29913
29914 - return atomic_read(&dev_priv->vbl_received);
29915 + return atomic_read_unchecked(&dev_priv->vbl_received);
29916 }
29917
29918
29919 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29920 /* VBLANK interrupt */
29921 if (status & MGA_VLINEPEN) {
29922 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29923 - atomic_inc(&dev_priv->vbl_received);
29924 + atomic_inc_unchecked(&dev_priv->vbl_received);
29925 drm_handle_vblank(dev, 0);
29926 handled = 1;
29927 }
29928 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29929 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29930 MGA_WRITE(MGA_PRIMEND, prim_end);
29931
29932 - atomic_inc(&dev_priv->last_fence_retired);
29933 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
29934 DRM_WAKEUP(&dev_priv->fence_queue);
29935 handled = 1;
29936 }
29937 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
29938 * using fences.
29939 */
29940 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29941 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29942 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29943 - *sequence) <= (1 << 23)));
29944
29945 *sequence = cur_fence;
29946 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
29947 index 5fc201b..7b032b9 100644
29948 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
29949 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
29950 @@ -201,7 +201,7 @@ struct methods {
29951 const char desc[8];
29952 void (*loadbios)(struct drm_device *, uint8_t *);
29953 const bool rw;
29954 -};
29955 +} __do_const;
29956
29957 static struct methods shadow_methods[] = {
29958 { "PRAMIN", load_vbios_pramin, true },
29959 @@ -5474,7 +5474,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
29960 struct bit_table {
29961 const char id;
29962 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
29963 -};
29964 +} __no_const;
29965
29966 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
29967
29968 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
29969 index 4c0be3a..5757582 100644
29970 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
29971 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
29972 @@ -238,7 +238,7 @@ struct nouveau_channel {
29973 struct list_head pending;
29974 uint32_t sequence;
29975 uint32_t sequence_ack;
29976 - atomic_t last_sequence_irq;
29977 + atomic_unchecked_t last_sequence_irq;
29978 struct nouveau_vma vma;
29979 } fence;
29980
29981 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
29982 u32 handle, u16 class);
29983 void (*set_tile_region)(struct drm_device *dev, int i);
29984 void (*tlb_flush)(struct drm_device *, int engine);
29985 -};
29986 +} __no_const;
29987
29988 struct nouveau_instmem_engine {
29989 void *priv;
29990 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
29991 struct nouveau_mc_engine {
29992 int (*init)(struct drm_device *dev);
29993 void (*takedown)(struct drm_device *dev);
29994 -};
29995 +} __no_const;
29996
29997 struct nouveau_timer_engine {
29998 int (*init)(struct drm_device *dev);
29999 void (*takedown)(struct drm_device *dev);
30000 uint64_t (*read)(struct drm_device *dev);
30001 -};
30002 +} __no_const;
30003
30004 struct nouveau_fb_engine {
30005 int num_tiles;
30006 @@ -558,7 +558,7 @@ struct nouveau_vram_engine {
30007 void (*put)(struct drm_device *, struct nouveau_mem **);
30008
30009 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30010 -};
30011 +} __no_const;
30012
30013 struct nouveau_engine {
30014 struct nouveau_instmem_engine instmem;
30015 @@ -706,7 +706,7 @@ struct drm_nouveau_private {
30016 struct drm_global_reference mem_global_ref;
30017 struct ttm_bo_global_ref bo_global_ref;
30018 struct ttm_bo_device bdev;
30019 - atomic_t validate_sequence;
30020 + atomic_unchecked_t validate_sequence;
30021 } ttm;
30022
30023 struct {
30024 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30025 index 2f6daae..c9d7b9e 100644
30026 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30027 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30028 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30029 if (USE_REFCNT(dev))
30030 sequence = nvchan_rd32(chan, 0x48);
30031 else
30032 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30033 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30034
30035 if (chan->fence.sequence_ack == sequence)
30036 goto out;
30037 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30038 return ret;
30039 }
30040
30041 - atomic_set(&chan->fence.last_sequence_irq, 0);
30042 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30043 return 0;
30044 }
30045
30046 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30047 index 7ce3fde..cb3ea04 100644
30048 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30049 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30050 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30051 int trycnt = 0;
30052 int ret, i;
30053
30054 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30055 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30056 retry:
30057 if (++trycnt > 100000) {
30058 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30059 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30060 index d8831ab..0ba8356 100644
30061 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30062 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30063 @@ -542,7 +542,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30064 bool can_switch;
30065
30066 spin_lock(&dev->count_lock);
30067 - can_switch = (dev->open_count == 0);
30068 + can_switch = (local_read(&dev->open_count) == 0);
30069 spin_unlock(&dev->count_lock);
30070 return can_switch;
30071 }
30072 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30073 index dbdea8e..cd6eeeb 100644
30074 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30075 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30076 @@ -554,7 +554,7 @@ static int
30077 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30078 u32 class, u32 mthd, u32 data)
30079 {
30080 - atomic_set(&chan->fence.last_sequence_irq, data);
30081 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30082 return 0;
30083 }
30084
30085 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30086 index bcac90b..53bfc76 100644
30087 --- a/drivers/gpu/drm/r128/r128_cce.c
30088 +++ b/drivers/gpu/drm/r128/r128_cce.c
30089 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30090
30091 /* GH: Simple idle check.
30092 */
30093 - atomic_set(&dev_priv->idle_count, 0);
30094 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30095
30096 /* We don't support anything other than bus-mastering ring mode,
30097 * but the ring can be in either AGP or PCI space for the ring
30098 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30099 index 930c71b..499aded 100644
30100 --- a/drivers/gpu/drm/r128/r128_drv.h
30101 +++ b/drivers/gpu/drm/r128/r128_drv.h
30102 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30103 int is_pci;
30104 unsigned long cce_buffers_offset;
30105
30106 - atomic_t idle_count;
30107 + atomic_unchecked_t idle_count;
30108
30109 int page_flipping;
30110 int current_page;
30111 u32 crtc_offset;
30112 u32 crtc_offset_cntl;
30113
30114 - atomic_t vbl_received;
30115 + atomic_unchecked_t vbl_received;
30116
30117 u32 color_fmt;
30118 unsigned int front_offset;
30119 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30120 index 429d5a0..7e899ed 100644
30121 --- a/drivers/gpu/drm/r128/r128_irq.c
30122 +++ b/drivers/gpu/drm/r128/r128_irq.c
30123 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30124 if (crtc != 0)
30125 return 0;
30126
30127 - return atomic_read(&dev_priv->vbl_received);
30128 + return atomic_read_unchecked(&dev_priv->vbl_received);
30129 }
30130
30131 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30132 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30133 /* VBLANK interrupt */
30134 if (status & R128_CRTC_VBLANK_INT) {
30135 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30136 - atomic_inc(&dev_priv->vbl_received);
30137 + atomic_inc_unchecked(&dev_priv->vbl_received);
30138 drm_handle_vblank(dev, 0);
30139 return IRQ_HANDLED;
30140 }
30141 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30142 index a9e33ce..09edd4b 100644
30143 --- a/drivers/gpu/drm/r128/r128_state.c
30144 +++ b/drivers/gpu/drm/r128/r128_state.c
30145 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30146
30147 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30148 {
30149 - if (atomic_read(&dev_priv->idle_count) == 0)
30150 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30151 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30152 else
30153 - atomic_set(&dev_priv->idle_count, 0);
30154 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30155 }
30156
30157 #endif
30158 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30159 index 5a82b6b..9e69c73 100644
30160 --- a/drivers/gpu/drm/radeon/mkregtable.c
30161 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30162 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30163 regex_t mask_rex;
30164 regmatch_t match[4];
30165 char buf[1024];
30166 - size_t end;
30167 + long end;
30168 int len;
30169 int done = 0;
30170 int r;
30171 unsigned o;
30172 struct offset *offset;
30173 char last_reg_s[10];
30174 - int last_reg;
30175 + unsigned long last_reg;
30176
30177 if (regcomp
30178 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30179 diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
30180 index cb1acff..8861bc5 100644
30181 --- a/drivers/gpu/drm/radeon/r600_cs.c
30182 +++ b/drivers/gpu/drm/radeon/r600_cs.c
30183 @@ -1304,6 +1304,7 @@ static int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
30184 h0 = G_038004_TEX_HEIGHT(word1) + 1;
30185 d0 = G_038004_TEX_DEPTH(word1);
30186 nfaces = 1;
30187 + array = 0;
30188 switch (G_038000_DIM(word0)) {
30189 case V_038000_SQ_TEX_DIM_1D:
30190 case V_038000_SQ_TEX_DIM_2D:
30191 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30192 index 8227e76..ce0b195 100644
30193 --- a/drivers/gpu/drm/radeon/radeon.h
30194 +++ b/drivers/gpu/drm/radeon/radeon.h
30195 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
30196 */
30197 struct radeon_fence_driver {
30198 uint32_t scratch_reg;
30199 - atomic_t seq;
30200 + atomic_unchecked_t seq;
30201 uint32_t last_seq;
30202 unsigned long last_jiffies;
30203 unsigned long last_timeout;
30204 @@ -530,7 +530,7 @@ struct r600_blit_cp_primitives {
30205 int x2, int y2);
30206 void (*draw_auto)(struct radeon_device *rdev);
30207 void (*set_default_state)(struct radeon_device *rdev);
30208 -};
30209 +} __no_const;
30210
30211 struct r600_blit {
30212 struct mutex mutex;
30213 @@ -954,7 +954,7 @@ struct radeon_asic {
30214 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30215 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30216 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30217 -};
30218 +} __no_const;
30219
30220 /*
30221 * Asic structures
30222 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30223 index 9231564..78b00fd 100644
30224 --- a/drivers/gpu/drm/radeon/radeon_device.c
30225 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30226 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30227 bool can_switch;
30228
30229 spin_lock(&dev->count_lock);
30230 - can_switch = (dev->open_count == 0);
30231 + can_switch = (local_read(&dev->open_count) == 0);
30232 spin_unlock(&dev->count_lock);
30233 return can_switch;
30234 }
30235 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30236 index a1b59ca..86f2d44 100644
30237 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30238 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30239 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30240
30241 /* SW interrupt */
30242 wait_queue_head_t swi_queue;
30243 - atomic_t swi_emitted;
30244 + atomic_unchecked_t swi_emitted;
30245 int vblank_crtc;
30246 uint32_t irq_enable_reg;
30247 uint32_t r500_disp_irq_reg;
30248 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30249 index 76ec0e9..6feb1a3 100644
30250 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30251 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30252 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30253 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
30254 return 0;
30255 }
30256 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
30257 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
30258 if (!rdev->cp.ready)
30259 /* FIXME: cp is not running assume everythings is done right
30260 * away
30261 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
30262 return r;
30263 }
30264 radeon_fence_write(rdev, 0);
30265 - atomic_set(&rdev->fence_drv.seq, 0);
30266 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
30267 INIT_LIST_HEAD(&rdev->fence_drv.created);
30268 INIT_LIST_HEAD(&rdev->fence_drv.emited);
30269 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
30270 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30271 index 48b7cea..342236f 100644
30272 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30273 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30274 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30275 request = compat_alloc_user_space(sizeof(*request));
30276 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30277 || __put_user(req32.param, &request->param)
30278 - || __put_user((void __user *)(unsigned long)req32.value,
30279 + || __put_user((unsigned long)req32.value,
30280 &request->value))
30281 return -EFAULT;
30282
30283 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30284 index 00da384..32f972d 100644
30285 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30286 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30287 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30288 unsigned int ret;
30289 RING_LOCALS;
30290
30291 - atomic_inc(&dev_priv->swi_emitted);
30292 - ret = atomic_read(&dev_priv->swi_emitted);
30293 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30294 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30295
30296 BEGIN_RING(4);
30297 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30298 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30299 drm_radeon_private_t *dev_priv =
30300 (drm_radeon_private_t *) dev->dev_private;
30301
30302 - atomic_set(&dev_priv->swi_emitted, 0);
30303 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30304 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30305
30306 dev->max_vblank_count = 0x001fffff;
30307 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30308 index e8422ae..d22d4a8 100644
30309 --- a/drivers/gpu/drm/radeon/radeon_state.c
30310 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30311 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30312 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30313 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30314
30315 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30316 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30317 sarea_priv->nbox * sizeof(depth_boxes[0])))
30318 return -EFAULT;
30319
30320 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30321 {
30322 drm_radeon_private_t *dev_priv = dev->dev_private;
30323 drm_radeon_getparam_t *param = data;
30324 - int value;
30325 + int value = 0;
30326
30327 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30328
30329 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30330 index 0b5468b..9c4b308 100644
30331 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30332 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30333 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30334 }
30335 if (unlikely(ttm_vm_ops == NULL)) {
30336 ttm_vm_ops = vma->vm_ops;
30337 - radeon_ttm_vm_ops = *ttm_vm_ops;
30338 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30339 + pax_open_kernel();
30340 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30341 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30342 + pax_close_kernel();
30343 }
30344 vma->vm_ops = &radeon_ttm_vm_ops;
30345 return 0;
30346 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30347 index a9049ed..501f284 100644
30348 --- a/drivers/gpu/drm/radeon/rs690.c
30349 +++ b/drivers/gpu/drm/radeon/rs690.c
30350 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30351 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30352 rdev->pm.sideport_bandwidth.full)
30353 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30354 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30355 + read_delay_latency.full = dfixed_const(800 * 1000);
30356 read_delay_latency.full = dfixed_div(read_delay_latency,
30357 rdev->pm.igp_sideport_mclk);
30358 + a.full = dfixed_const(370);
30359 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30360 } else {
30361 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30362 rdev->pm.k8_bandwidth.full)
30363 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30364 index 727e93d..1565650 100644
30365 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30366 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30367 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30368 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30369 struct shrink_control *sc)
30370 {
30371 - static atomic_t start_pool = ATOMIC_INIT(0);
30372 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30373 unsigned i;
30374 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30375 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30376 struct ttm_page_pool *pool;
30377 int shrink_pages = sc->nr_to_scan;
30378
30379 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30380 index 9cf87d9..2000b7d 100644
30381 --- a/drivers/gpu/drm/via/via_drv.h
30382 +++ b/drivers/gpu/drm/via/via_drv.h
30383 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30384 typedef uint32_t maskarray_t[5];
30385
30386 typedef struct drm_via_irq {
30387 - atomic_t irq_received;
30388 + atomic_unchecked_t irq_received;
30389 uint32_t pending_mask;
30390 uint32_t enable_mask;
30391 wait_queue_head_t irq_queue;
30392 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30393 struct timeval last_vblank;
30394 int last_vblank_valid;
30395 unsigned usec_per_vblank;
30396 - atomic_t vbl_received;
30397 + atomic_unchecked_t vbl_received;
30398 drm_via_state_t hc_state;
30399 char pci_buf[VIA_PCI_BUF_SIZE];
30400 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30401 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30402 index d391f48..10c8ca3 100644
30403 --- a/drivers/gpu/drm/via/via_irq.c
30404 +++ b/drivers/gpu/drm/via/via_irq.c
30405 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30406 if (crtc != 0)
30407 return 0;
30408
30409 - return atomic_read(&dev_priv->vbl_received);
30410 + return atomic_read_unchecked(&dev_priv->vbl_received);
30411 }
30412
30413 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30414 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30415
30416 status = VIA_READ(VIA_REG_INTERRUPT);
30417 if (status & VIA_IRQ_VBLANK_PENDING) {
30418 - atomic_inc(&dev_priv->vbl_received);
30419 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30420 + atomic_inc_unchecked(&dev_priv->vbl_received);
30421 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30422 do_gettimeofday(&cur_vblank);
30423 if (dev_priv->last_vblank_valid) {
30424 dev_priv->usec_per_vblank =
30425 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30426 dev_priv->last_vblank = cur_vblank;
30427 dev_priv->last_vblank_valid = 1;
30428 }
30429 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30430 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30431 DRM_DEBUG("US per vblank is: %u\n",
30432 dev_priv->usec_per_vblank);
30433 }
30434 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30435
30436 for (i = 0; i < dev_priv->num_irqs; ++i) {
30437 if (status & cur_irq->pending_mask) {
30438 - atomic_inc(&cur_irq->irq_received);
30439 + atomic_inc_unchecked(&cur_irq->irq_received);
30440 DRM_WAKEUP(&cur_irq->irq_queue);
30441 handled = 1;
30442 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
30443 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
30444 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30445 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30446 masks[irq][4]));
30447 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30448 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30449 } else {
30450 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30451 (((cur_irq_sequence =
30452 - atomic_read(&cur_irq->irq_received)) -
30453 + atomic_read_unchecked(&cur_irq->irq_received)) -
30454 *sequence) <= (1 << 23)));
30455 }
30456 *sequence = cur_irq_sequence;
30457 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
30458 }
30459
30460 for (i = 0; i < dev_priv->num_irqs; ++i) {
30461 - atomic_set(&cur_irq->irq_received, 0);
30462 + atomic_set_unchecked(&cur_irq->irq_received, 0);
30463 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30464 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30465 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30466 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
30467 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30468 case VIA_IRQ_RELATIVE:
30469 irqwait->request.sequence +=
30470 - atomic_read(&cur_irq->irq_received);
30471 + atomic_read_unchecked(&cur_irq->irq_received);
30472 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30473 case VIA_IRQ_ABSOLUTE:
30474 break;
30475 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30476 index dc27970..f18b008 100644
30477 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30478 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30479 @@ -260,7 +260,7 @@ struct vmw_private {
30480 * Fencing and IRQs.
30481 */
30482
30483 - atomic_t marker_seq;
30484 + atomic_unchecked_t marker_seq;
30485 wait_queue_head_t fence_queue;
30486 wait_queue_head_t fifo_queue;
30487 int fence_queue_waiters; /* Protected by hw_mutex */
30488 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30489 index a0c2f12..68ae6cb 100644
30490 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30491 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30492 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
30493 (unsigned int) min,
30494 (unsigned int) fifo->capabilities);
30495
30496 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30497 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30498 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
30499 vmw_marker_queue_init(&fifo->marker_queue);
30500 return vmw_fifo_send_fence(dev_priv, &dummy);
30501 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
30502 if (reserveable)
30503 iowrite32(bytes, fifo_mem +
30504 SVGA_FIFO_RESERVED);
30505 - return fifo_mem + (next_cmd >> 2);
30506 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
30507 } else {
30508 need_bounce = true;
30509 }
30510 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30511
30512 fm = vmw_fifo_reserve(dev_priv, bytes);
30513 if (unlikely(fm == NULL)) {
30514 - *seqno = atomic_read(&dev_priv->marker_seq);
30515 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30516 ret = -ENOMEM;
30517 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
30518 false, 3*HZ);
30519 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30520 }
30521
30522 do {
30523 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
30524 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
30525 } while (*seqno == 0);
30526
30527 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
30528 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30529 index cabc95f..14b3d77 100644
30530 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30531 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30532 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
30533 * emitted. Then the fence is stale and signaled.
30534 */
30535
30536 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
30537 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
30538 > VMW_FENCE_WRAP);
30539
30540 return ret;
30541 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
30542
30543 if (fifo_idle)
30544 down_read(&fifo_state->rwsem);
30545 - signal_seq = atomic_read(&dev_priv->marker_seq);
30546 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
30547 ret = 0;
30548
30549 for (;;) {
30550 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30551 index 8a8725c..afed796 100644
30552 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30553 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30554 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
30555 while (!vmw_lag_lt(queue, us)) {
30556 spin_lock(&queue->lock);
30557 if (list_empty(&queue->head))
30558 - seqno = atomic_read(&dev_priv->marker_seq);
30559 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30560 else {
30561 marker = list_first_entry(&queue->head,
30562 struct vmw_marker, head);
30563 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
30564 index bb656d8..4169fca 100644
30565 --- a/drivers/hid/hid-core.c
30566 +++ b/drivers/hid/hid-core.c
30567 @@ -2012,7 +2012,7 @@ static bool hid_ignore(struct hid_device *hdev)
30568
30569 int hid_add_device(struct hid_device *hdev)
30570 {
30571 - static atomic_t id = ATOMIC_INIT(0);
30572 + static atomic_unchecked_t id = ATOMIC_INIT(0);
30573 int ret;
30574
30575 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30576 @@ -2027,7 +2027,7 @@ int hid_add_device(struct hid_device *hdev)
30577 /* XXX hack, any other cleaner solution after the driver core
30578 * is converted to allow more than 20 bytes as the device name? */
30579 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30580 - hdev->vendor, hdev->product, atomic_inc_return(&id));
30581 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30582
30583 hid_debug_register(hdev, dev_name(&hdev->dev));
30584 ret = device_add(&hdev->dev);
30585 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
30586 index 4ef02b2..8a96831 100644
30587 --- a/drivers/hid/usbhid/hiddev.c
30588 +++ b/drivers/hid/usbhid/hiddev.c
30589 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
30590 break;
30591
30592 case HIDIOCAPPLICATION:
30593 - if (arg < 0 || arg >= hid->maxapplication)
30594 + if (arg >= hid->maxapplication)
30595 break;
30596
30597 for (i = 0; i < hid->maxcollection; i++)
30598 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
30599 index 4065374..10ed7dc 100644
30600 --- a/drivers/hv/channel.c
30601 +++ b/drivers/hv/channel.c
30602 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
30603 int ret = 0;
30604 int t;
30605
30606 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
30607 - atomic_inc(&vmbus_connection.next_gpadl_handle);
30608 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
30609 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
30610
30611 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
30612 if (ret)
30613 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
30614 index 0fb100e..baf87e5 100644
30615 --- a/drivers/hv/hv.c
30616 +++ b/drivers/hv/hv.c
30617 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
30618 u64 output_address = (output) ? virt_to_phys(output) : 0;
30619 u32 output_address_hi = output_address >> 32;
30620 u32 output_address_lo = output_address & 0xFFFFFFFF;
30621 - void *hypercall_page = hv_context.hypercall_page;
30622 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
30623
30624 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
30625 "=a"(hv_status_lo) : "d" (control_hi),
30626 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
30627 index 0aee112..b72d21f 100644
30628 --- a/drivers/hv/hyperv_vmbus.h
30629 +++ b/drivers/hv/hyperv_vmbus.h
30630 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
30631 struct vmbus_connection {
30632 enum vmbus_connect_state conn_state;
30633
30634 - atomic_t next_gpadl_handle;
30635 + atomic_unchecked_t next_gpadl_handle;
30636
30637 /*
30638 * Represents channel interrupts. Each bit position represents a
30639 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
30640 index d2d0a2a..90b8f4d 100644
30641 --- a/drivers/hv/vmbus_drv.c
30642 +++ b/drivers/hv/vmbus_drv.c
30643 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
30644 {
30645 int ret = 0;
30646
30647 - static atomic_t device_num = ATOMIC_INIT(0);
30648 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
30649
30650 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
30651 - atomic_inc_return(&device_num));
30652 + atomic_inc_return_unchecked(&device_num));
30653
30654 child_device_obj->device.bus = &hv_bus;
30655 child_device_obj->device.parent = &hv_acpi_dev->dev;
30656 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
30657 index 66f6729..2d6de0a 100644
30658 --- a/drivers/hwmon/acpi_power_meter.c
30659 +++ b/drivers/hwmon/acpi_power_meter.c
30660 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
30661 return res;
30662
30663 temp /= 1000;
30664 - if (temp < 0)
30665 - return -EINVAL;
30666
30667 mutex_lock(&resource->lock);
30668 resource->trip[attr->index - 7] = temp;
30669 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
30670 index 5357925..6cf0418 100644
30671 --- a/drivers/hwmon/sht15.c
30672 +++ b/drivers/hwmon/sht15.c
30673 @@ -166,7 +166,7 @@ struct sht15_data {
30674 int supply_uV;
30675 bool supply_uV_valid;
30676 struct work_struct update_supply_work;
30677 - atomic_t interrupt_handled;
30678 + atomic_unchecked_t interrupt_handled;
30679 };
30680
30681 /**
30682 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
30683 return ret;
30684
30685 gpio_direction_input(data->pdata->gpio_data);
30686 - atomic_set(&data->interrupt_handled, 0);
30687 + atomic_set_unchecked(&data->interrupt_handled, 0);
30688
30689 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30690 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30691 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30692 /* Only relevant if the interrupt hasn't occurred. */
30693 - if (!atomic_read(&data->interrupt_handled))
30694 + if (!atomic_read_unchecked(&data->interrupt_handled))
30695 schedule_work(&data->read_work);
30696 }
30697 ret = wait_event_timeout(data->wait_queue,
30698 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
30699
30700 /* First disable the interrupt */
30701 disable_irq_nosync(irq);
30702 - atomic_inc(&data->interrupt_handled);
30703 + atomic_inc_unchecked(&data->interrupt_handled);
30704 /* Then schedule a reading work struct */
30705 if (data->state != SHT15_READING_NOTHING)
30706 schedule_work(&data->read_work);
30707 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
30708 * If not, then start the interrupt again - care here as could
30709 * have gone low in meantime so verify it hasn't!
30710 */
30711 - atomic_set(&data->interrupt_handled, 0);
30712 + atomic_set_unchecked(&data->interrupt_handled, 0);
30713 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30714 /* If still not occurred or another handler has been scheduled */
30715 if (gpio_get_value(data->pdata->gpio_data)
30716 - || atomic_read(&data->interrupt_handled))
30717 + || atomic_read_unchecked(&data->interrupt_handled))
30718 return;
30719 }
30720
30721 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
30722 index 378fcb5..5e91fa8 100644
30723 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
30724 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
30725 @@ -43,7 +43,7 @@
30726 extern struct i2c_adapter amd756_smbus;
30727
30728 static struct i2c_adapter *s4882_adapter;
30729 -static struct i2c_algorithm *s4882_algo;
30730 +static i2c_algorithm_no_const *s4882_algo;
30731
30732 /* Wrapper access functions for multiplexed SMBus */
30733 static DEFINE_MUTEX(amd756_lock);
30734 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
30735 index 29015eb..af2d8e9 100644
30736 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
30737 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
30738 @@ -41,7 +41,7 @@
30739 extern struct i2c_adapter *nforce2_smbus;
30740
30741 static struct i2c_adapter *s4985_adapter;
30742 -static struct i2c_algorithm *s4985_algo;
30743 +static i2c_algorithm_no_const *s4985_algo;
30744
30745 /* Wrapper access functions for multiplexed SMBus */
30746 static DEFINE_MUTEX(nforce2_lock);
30747 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
30748 index d7a4833..7fae376 100644
30749 --- a/drivers/i2c/i2c-mux.c
30750 +++ b/drivers/i2c/i2c-mux.c
30751 @@ -28,7 +28,7 @@
30752 /* multiplexer per channel data */
30753 struct i2c_mux_priv {
30754 struct i2c_adapter adap;
30755 - struct i2c_algorithm algo;
30756 + i2c_algorithm_no_const algo;
30757
30758 struct i2c_adapter *parent;
30759 void *mux_dev; /* the mux chip/device */
30760 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
30761 index 57d00ca..0145194 100644
30762 --- a/drivers/ide/aec62xx.c
30763 +++ b/drivers/ide/aec62xx.c
30764 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
30765 .cable_detect = atp86x_cable_detect,
30766 };
30767
30768 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
30769 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
30770 { /* 0: AEC6210 */
30771 .name = DRV_NAME,
30772 .init_chipset = init_chipset_aec62xx,
30773 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
30774 index 2c8016a..911a27c 100644
30775 --- a/drivers/ide/alim15x3.c
30776 +++ b/drivers/ide/alim15x3.c
30777 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
30778 .dma_sff_read_status = ide_dma_sff_read_status,
30779 };
30780
30781 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
30782 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
30783 .name = DRV_NAME,
30784 .init_chipset = init_chipset_ali15x3,
30785 .init_hwif = init_hwif_ali15x3,
30786 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
30787 index 3747b25..56fc995 100644
30788 --- a/drivers/ide/amd74xx.c
30789 +++ b/drivers/ide/amd74xx.c
30790 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
30791 .udma_mask = udma, \
30792 }
30793
30794 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
30795 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
30796 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
30797 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
30798 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
30799 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
30800 index 15f0ead..cb43480 100644
30801 --- a/drivers/ide/atiixp.c
30802 +++ b/drivers/ide/atiixp.c
30803 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
30804 .cable_detect = atiixp_cable_detect,
30805 };
30806
30807 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
30808 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
30809 { /* 0: IXP200/300/400/700 */
30810 .name = DRV_NAME,
30811 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
30812 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
30813 index 5f80312..d1fc438 100644
30814 --- a/drivers/ide/cmd64x.c
30815 +++ b/drivers/ide/cmd64x.c
30816 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
30817 .dma_sff_read_status = ide_dma_sff_read_status,
30818 };
30819
30820 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
30821 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
30822 { /* 0: CMD643 */
30823 .name = DRV_NAME,
30824 .init_chipset = init_chipset_cmd64x,
30825 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
30826 index 2c1e5f7..1444762 100644
30827 --- a/drivers/ide/cs5520.c
30828 +++ b/drivers/ide/cs5520.c
30829 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
30830 .set_dma_mode = cs5520_set_dma_mode,
30831 };
30832
30833 -static const struct ide_port_info cyrix_chipset __devinitdata = {
30834 +static const struct ide_port_info cyrix_chipset __devinitconst = {
30835 .name = DRV_NAME,
30836 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
30837 .port_ops = &cs5520_port_ops,
30838 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
30839 index 4dc4eb9..49b40ad 100644
30840 --- a/drivers/ide/cs5530.c
30841 +++ b/drivers/ide/cs5530.c
30842 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
30843 .udma_filter = cs5530_udma_filter,
30844 };
30845
30846 -static const struct ide_port_info cs5530_chipset __devinitdata = {
30847 +static const struct ide_port_info cs5530_chipset __devinitconst = {
30848 .name = DRV_NAME,
30849 .init_chipset = init_chipset_cs5530,
30850 .init_hwif = init_hwif_cs5530,
30851 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
30852 index 5059faf..18d4c85 100644
30853 --- a/drivers/ide/cs5535.c
30854 +++ b/drivers/ide/cs5535.c
30855 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
30856 .cable_detect = cs5535_cable_detect,
30857 };
30858
30859 -static const struct ide_port_info cs5535_chipset __devinitdata = {
30860 +static const struct ide_port_info cs5535_chipset __devinitconst = {
30861 .name = DRV_NAME,
30862 .port_ops = &cs5535_port_ops,
30863 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
30864 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
30865 index 847553f..3ffb49d 100644
30866 --- a/drivers/ide/cy82c693.c
30867 +++ b/drivers/ide/cy82c693.c
30868 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
30869 .set_dma_mode = cy82c693_set_dma_mode,
30870 };
30871
30872 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
30873 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
30874 .name = DRV_NAME,
30875 .init_iops = init_iops_cy82c693,
30876 .port_ops = &cy82c693_port_ops,
30877 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
30878 index 58c51cd..4aec3b8 100644
30879 --- a/drivers/ide/hpt366.c
30880 +++ b/drivers/ide/hpt366.c
30881 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
30882 }
30883 };
30884
30885 -static const struct hpt_info hpt36x __devinitdata = {
30886 +static const struct hpt_info hpt36x __devinitconst = {
30887 .chip_name = "HPT36x",
30888 .chip_type = HPT36x,
30889 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
30890 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
30891 .timings = &hpt36x_timings
30892 };
30893
30894 -static const struct hpt_info hpt370 __devinitdata = {
30895 +static const struct hpt_info hpt370 __devinitconst = {
30896 .chip_name = "HPT370",
30897 .chip_type = HPT370,
30898 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30899 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
30900 .timings = &hpt37x_timings
30901 };
30902
30903 -static const struct hpt_info hpt370a __devinitdata = {
30904 +static const struct hpt_info hpt370a __devinitconst = {
30905 .chip_name = "HPT370A",
30906 .chip_type = HPT370A,
30907 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30908 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
30909 .timings = &hpt37x_timings
30910 };
30911
30912 -static const struct hpt_info hpt374 __devinitdata = {
30913 +static const struct hpt_info hpt374 __devinitconst = {
30914 .chip_name = "HPT374",
30915 .chip_type = HPT374,
30916 .udma_mask = ATA_UDMA5,
30917 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
30918 .timings = &hpt37x_timings
30919 };
30920
30921 -static const struct hpt_info hpt372 __devinitdata = {
30922 +static const struct hpt_info hpt372 __devinitconst = {
30923 .chip_name = "HPT372",
30924 .chip_type = HPT372,
30925 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30926 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
30927 .timings = &hpt37x_timings
30928 };
30929
30930 -static const struct hpt_info hpt372a __devinitdata = {
30931 +static const struct hpt_info hpt372a __devinitconst = {
30932 .chip_name = "HPT372A",
30933 .chip_type = HPT372A,
30934 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30935 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
30936 .timings = &hpt37x_timings
30937 };
30938
30939 -static const struct hpt_info hpt302 __devinitdata = {
30940 +static const struct hpt_info hpt302 __devinitconst = {
30941 .chip_name = "HPT302",
30942 .chip_type = HPT302,
30943 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30944 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
30945 .timings = &hpt37x_timings
30946 };
30947
30948 -static const struct hpt_info hpt371 __devinitdata = {
30949 +static const struct hpt_info hpt371 __devinitconst = {
30950 .chip_name = "HPT371",
30951 .chip_type = HPT371,
30952 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30953 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
30954 .timings = &hpt37x_timings
30955 };
30956
30957 -static const struct hpt_info hpt372n __devinitdata = {
30958 +static const struct hpt_info hpt372n __devinitconst = {
30959 .chip_name = "HPT372N",
30960 .chip_type = HPT372N,
30961 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30962 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
30963 .timings = &hpt37x_timings
30964 };
30965
30966 -static const struct hpt_info hpt302n __devinitdata = {
30967 +static const struct hpt_info hpt302n __devinitconst = {
30968 .chip_name = "HPT302N",
30969 .chip_type = HPT302N,
30970 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30971 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
30972 .timings = &hpt37x_timings
30973 };
30974
30975 -static const struct hpt_info hpt371n __devinitdata = {
30976 +static const struct hpt_info hpt371n __devinitconst = {
30977 .chip_name = "HPT371N",
30978 .chip_type = HPT371N,
30979 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30980 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
30981 .dma_sff_read_status = ide_dma_sff_read_status,
30982 };
30983
30984 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
30985 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
30986 { /* 0: HPT36x */
30987 .name = DRV_NAME,
30988 .init_chipset = init_chipset_hpt366,
30989 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
30990 index 8126824..55a2798 100644
30991 --- a/drivers/ide/ide-cd.c
30992 +++ b/drivers/ide/ide-cd.c
30993 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
30994 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30995 if ((unsigned long)buf & alignment
30996 || blk_rq_bytes(rq) & q->dma_pad_mask
30997 - || object_is_on_stack(buf))
30998 + || object_starts_on_stack(buf))
30999 drive->dma = 0;
31000 }
31001 }
31002 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31003 index a743e68..1cfd674 100644
31004 --- a/drivers/ide/ide-pci-generic.c
31005 +++ b/drivers/ide/ide-pci-generic.c
31006 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31007 .udma_mask = ATA_UDMA6, \
31008 }
31009
31010 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31011 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31012 /* 0: Unknown */
31013 DECLARE_GENERIC_PCI_DEV(0),
31014
31015 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31016 index 560e66d..d5dd180 100644
31017 --- a/drivers/ide/it8172.c
31018 +++ b/drivers/ide/it8172.c
31019 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31020 .set_dma_mode = it8172_set_dma_mode,
31021 };
31022
31023 -static const struct ide_port_info it8172_port_info __devinitdata = {
31024 +static const struct ide_port_info it8172_port_info __devinitconst = {
31025 .name = DRV_NAME,
31026 .port_ops = &it8172_port_ops,
31027 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31028 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31029 index 46816ba..1847aeb 100644
31030 --- a/drivers/ide/it8213.c
31031 +++ b/drivers/ide/it8213.c
31032 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31033 .cable_detect = it8213_cable_detect,
31034 };
31035
31036 -static const struct ide_port_info it8213_chipset __devinitdata = {
31037 +static const struct ide_port_info it8213_chipset __devinitconst = {
31038 .name = DRV_NAME,
31039 .enablebits = { {0x41, 0x80, 0x80} },
31040 .port_ops = &it8213_port_ops,
31041 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31042 index 2e3169f..c5611db 100644
31043 --- a/drivers/ide/it821x.c
31044 +++ b/drivers/ide/it821x.c
31045 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31046 .cable_detect = it821x_cable_detect,
31047 };
31048
31049 -static const struct ide_port_info it821x_chipset __devinitdata = {
31050 +static const struct ide_port_info it821x_chipset __devinitconst = {
31051 .name = DRV_NAME,
31052 .init_chipset = init_chipset_it821x,
31053 .init_hwif = init_hwif_it821x,
31054 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31055 index 74c2c4a..efddd7d 100644
31056 --- a/drivers/ide/jmicron.c
31057 +++ b/drivers/ide/jmicron.c
31058 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31059 .cable_detect = jmicron_cable_detect,
31060 };
31061
31062 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31063 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31064 .name = DRV_NAME,
31065 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31066 .port_ops = &jmicron_port_ops,
31067 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31068 index 95327a2..73f78d8 100644
31069 --- a/drivers/ide/ns87415.c
31070 +++ b/drivers/ide/ns87415.c
31071 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31072 .dma_sff_read_status = superio_dma_sff_read_status,
31073 };
31074
31075 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31076 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31077 .name = DRV_NAME,
31078 .init_hwif = init_hwif_ns87415,
31079 .tp_ops = &ns87415_tp_ops,
31080 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31081 index 1a53a4c..39edc66 100644
31082 --- a/drivers/ide/opti621.c
31083 +++ b/drivers/ide/opti621.c
31084 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31085 .set_pio_mode = opti621_set_pio_mode,
31086 };
31087
31088 -static const struct ide_port_info opti621_chipset __devinitdata = {
31089 +static const struct ide_port_info opti621_chipset __devinitconst = {
31090 .name = DRV_NAME,
31091 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31092 .port_ops = &opti621_port_ops,
31093 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31094 index 9546fe2..2e5ceb6 100644
31095 --- a/drivers/ide/pdc202xx_new.c
31096 +++ b/drivers/ide/pdc202xx_new.c
31097 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31098 .udma_mask = udma, \
31099 }
31100
31101 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31102 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31103 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31104 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31105 };
31106 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31107 index 3a35ec6..5634510 100644
31108 --- a/drivers/ide/pdc202xx_old.c
31109 +++ b/drivers/ide/pdc202xx_old.c
31110 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31111 .max_sectors = sectors, \
31112 }
31113
31114 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31115 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31116 { /* 0: PDC20246 */
31117 .name = DRV_NAME,
31118 .init_chipset = init_chipset_pdc202xx,
31119 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31120 index 1892e81..fe0fd60 100644
31121 --- a/drivers/ide/piix.c
31122 +++ b/drivers/ide/piix.c
31123 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31124 .udma_mask = udma, \
31125 }
31126
31127 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31128 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31129 /* 0: MPIIX */
31130 { /*
31131 * MPIIX actually has only a single IDE channel mapped to
31132 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31133 index a6414a8..c04173e 100644
31134 --- a/drivers/ide/rz1000.c
31135 +++ b/drivers/ide/rz1000.c
31136 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31137 }
31138 }
31139
31140 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31141 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31142 .name = DRV_NAME,
31143 .host_flags = IDE_HFLAG_NO_DMA,
31144 };
31145 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31146 index 356b9b5..d4758eb 100644
31147 --- a/drivers/ide/sc1200.c
31148 +++ b/drivers/ide/sc1200.c
31149 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31150 .dma_sff_read_status = ide_dma_sff_read_status,
31151 };
31152
31153 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31154 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31155 .name = DRV_NAME,
31156 .port_ops = &sc1200_port_ops,
31157 .dma_ops = &sc1200_dma_ops,
31158 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31159 index b7f5b0c..9701038 100644
31160 --- a/drivers/ide/scc_pata.c
31161 +++ b/drivers/ide/scc_pata.c
31162 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31163 .dma_sff_read_status = scc_dma_sff_read_status,
31164 };
31165
31166 -static const struct ide_port_info scc_chipset __devinitdata = {
31167 +static const struct ide_port_info scc_chipset __devinitconst = {
31168 .name = "sccIDE",
31169 .init_iops = init_iops_scc,
31170 .init_dma = scc_init_dma,
31171 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31172 index 35fb8da..24d72ef 100644
31173 --- a/drivers/ide/serverworks.c
31174 +++ b/drivers/ide/serverworks.c
31175 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31176 .cable_detect = svwks_cable_detect,
31177 };
31178
31179 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31180 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31181 { /* 0: OSB4 */
31182 .name = DRV_NAME,
31183 .init_chipset = init_chipset_svwks,
31184 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31185 index ddeda44..46f7e30 100644
31186 --- a/drivers/ide/siimage.c
31187 +++ b/drivers/ide/siimage.c
31188 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31189 .udma_mask = ATA_UDMA6, \
31190 }
31191
31192 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31193 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31194 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31195 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31196 };
31197 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31198 index 4a00225..09e61b4 100644
31199 --- a/drivers/ide/sis5513.c
31200 +++ b/drivers/ide/sis5513.c
31201 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31202 .cable_detect = sis_cable_detect,
31203 };
31204
31205 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31206 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31207 .name = DRV_NAME,
31208 .init_chipset = init_chipset_sis5513,
31209 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31210 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31211 index f21dc2a..d051cd2 100644
31212 --- a/drivers/ide/sl82c105.c
31213 +++ b/drivers/ide/sl82c105.c
31214 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31215 .dma_sff_read_status = ide_dma_sff_read_status,
31216 };
31217
31218 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31219 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31220 .name = DRV_NAME,
31221 .init_chipset = init_chipset_sl82c105,
31222 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31223 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31224 index 864ffe0..863a5e9 100644
31225 --- a/drivers/ide/slc90e66.c
31226 +++ b/drivers/ide/slc90e66.c
31227 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31228 .cable_detect = slc90e66_cable_detect,
31229 };
31230
31231 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31232 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31233 .name = DRV_NAME,
31234 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31235 .port_ops = &slc90e66_port_ops,
31236 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31237 index 4799d5c..1794678 100644
31238 --- a/drivers/ide/tc86c001.c
31239 +++ b/drivers/ide/tc86c001.c
31240 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31241 .dma_sff_read_status = ide_dma_sff_read_status,
31242 };
31243
31244 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31245 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31246 .name = DRV_NAME,
31247 .init_hwif = init_hwif_tc86c001,
31248 .port_ops = &tc86c001_port_ops,
31249 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31250 index 281c914..55ce1b8 100644
31251 --- a/drivers/ide/triflex.c
31252 +++ b/drivers/ide/triflex.c
31253 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31254 .set_dma_mode = triflex_set_mode,
31255 };
31256
31257 -static const struct ide_port_info triflex_device __devinitdata = {
31258 +static const struct ide_port_info triflex_device __devinitconst = {
31259 .name = DRV_NAME,
31260 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31261 .port_ops = &triflex_port_ops,
31262 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31263 index 4b42ca0..e494a98 100644
31264 --- a/drivers/ide/trm290.c
31265 +++ b/drivers/ide/trm290.c
31266 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31267 .dma_check = trm290_dma_check,
31268 };
31269
31270 -static const struct ide_port_info trm290_chipset __devinitdata = {
31271 +static const struct ide_port_info trm290_chipset __devinitconst = {
31272 .name = DRV_NAME,
31273 .init_hwif = init_hwif_trm290,
31274 .tp_ops = &trm290_tp_ops,
31275 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31276 index f46f49c..eb77678 100644
31277 --- a/drivers/ide/via82cxxx.c
31278 +++ b/drivers/ide/via82cxxx.c
31279 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31280 .cable_detect = via82cxxx_cable_detect,
31281 };
31282
31283 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31284 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31285 .name = DRV_NAME,
31286 .init_chipset = init_chipset_via82cxxx,
31287 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31288 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31289 index eb0e2cc..14241c7 100644
31290 --- a/drivers/ieee802154/fakehard.c
31291 +++ b/drivers/ieee802154/fakehard.c
31292 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31293 phy->transmit_power = 0xbf;
31294
31295 dev->netdev_ops = &fake_ops;
31296 - dev->ml_priv = &fake_mlme;
31297 + dev->ml_priv = (void *)&fake_mlme;
31298
31299 priv = netdev_priv(dev);
31300 priv->phy = phy;
31301 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31302 index 8b72f39..55df4c8 100644
31303 --- a/drivers/infiniband/core/cm.c
31304 +++ b/drivers/infiniband/core/cm.c
31305 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31306
31307 struct cm_counter_group {
31308 struct kobject obj;
31309 - atomic_long_t counter[CM_ATTR_COUNT];
31310 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31311 };
31312
31313 struct cm_counter_attribute {
31314 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31315 struct ib_mad_send_buf *msg = NULL;
31316 int ret;
31317
31318 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31319 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31320 counter[CM_REQ_COUNTER]);
31321
31322 /* Quick state check to discard duplicate REQs. */
31323 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31324 if (!cm_id_priv)
31325 return;
31326
31327 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31328 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31329 counter[CM_REP_COUNTER]);
31330 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31331 if (ret)
31332 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31333 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31334 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31335 spin_unlock_irq(&cm_id_priv->lock);
31336 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31337 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31338 counter[CM_RTU_COUNTER]);
31339 goto out;
31340 }
31341 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31342 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31343 dreq_msg->local_comm_id);
31344 if (!cm_id_priv) {
31345 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31346 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31347 counter[CM_DREQ_COUNTER]);
31348 cm_issue_drep(work->port, work->mad_recv_wc);
31349 return -EINVAL;
31350 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31351 case IB_CM_MRA_REP_RCVD:
31352 break;
31353 case IB_CM_TIMEWAIT:
31354 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31355 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31356 counter[CM_DREQ_COUNTER]);
31357 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31358 goto unlock;
31359 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31360 cm_free_msg(msg);
31361 goto deref;
31362 case IB_CM_DREQ_RCVD:
31363 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31364 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31365 counter[CM_DREQ_COUNTER]);
31366 goto unlock;
31367 default:
31368 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31369 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31370 cm_id_priv->msg, timeout)) {
31371 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31372 - atomic_long_inc(&work->port->
31373 + atomic_long_inc_unchecked(&work->port->
31374 counter_group[CM_RECV_DUPLICATES].
31375 counter[CM_MRA_COUNTER]);
31376 goto out;
31377 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31378 break;
31379 case IB_CM_MRA_REQ_RCVD:
31380 case IB_CM_MRA_REP_RCVD:
31381 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31382 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31383 counter[CM_MRA_COUNTER]);
31384 /* fall through */
31385 default:
31386 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31387 case IB_CM_LAP_IDLE:
31388 break;
31389 case IB_CM_MRA_LAP_SENT:
31390 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31391 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31392 counter[CM_LAP_COUNTER]);
31393 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31394 goto unlock;
31395 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31396 cm_free_msg(msg);
31397 goto deref;
31398 case IB_CM_LAP_RCVD:
31399 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31400 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31401 counter[CM_LAP_COUNTER]);
31402 goto unlock;
31403 default:
31404 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31405 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31406 if (cur_cm_id_priv) {
31407 spin_unlock_irq(&cm.lock);
31408 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31409 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31410 counter[CM_SIDR_REQ_COUNTER]);
31411 goto out; /* Duplicate message. */
31412 }
31413 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31414 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31415 msg->retries = 1;
31416
31417 - atomic_long_add(1 + msg->retries,
31418 + atomic_long_add_unchecked(1 + msg->retries,
31419 &port->counter_group[CM_XMIT].counter[attr_index]);
31420 if (msg->retries)
31421 - atomic_long_add(msg->retries,
31422 + atomic_long_add_unchecked(msg->retries,
31423 &port->counter_group[CM_XMIT_RETRIES].
31424 counter[attr_index]);
31425
31426 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31427 }
31428
31429 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31430 - atomic_long_inc(&port->counter_group[CM_RECV].
31431 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31432 counter[attr_id - CM_ATTR_ID_OFFSET]);
31433
31434 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31435 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31436 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31437
31438 return sprintf(buf, "%ld\n",
31439 - atomic_long_read(&group->counter[cm_attr->index]));
31440 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31441 }
31442
31443 static const struct sysfs_ops cm_counter_ops = {
31444 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
31445 index 176c8f9..2627b62 100644
31446 --- a/drivers/infiniband/core/fmr_pool.c
31447 +++ b/drivers/infiniband/core/fmr_pool.c
31448 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
31449
31450 struct task_struct *thread;
31451
31452 - atomic_t req_ser;
31453 - atomic_t flush_ser;
31454 + atomic_unchecked_t req_ser;
31455 + atomic_unchecked_t flush_ser;
31456
31457 wait_queue_head_t force_wait;
31458 };
31459 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31460 struct ib_fmr_pool *pool = pool_ptr;
31461
31462 do {
31463 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31464 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31465 ib_fmr_batch_release(pool);
31466
31467 - atomic_inc(&pool->flush_ser);
31468 + atomic_inc_unchecked(&pool->flush_ser);
31469 wake_up_interruptible(&pool->force_wait);
31470
31471 if (pool->flush_function)
31472 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31473 }
31474
31475 set_current_state(TASK_INTERRUPTIBLE);
31476 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
31477 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
31478 !kthread_should_stop())
31479 schedule();
31480 __set_current_state(TASK_RUNNING);
31481 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
31482 pool->dirty_watermark = params->dirty_watermark;
31483 pool->dirty_len = 0;
31484 spin_lock_init(&pool->pool_lock);
31485 - atomic_set(&pool->req_ser, 0);
31486 - atomic_set(&pool->flush_ser, 0);
31487 + atomic_set_unchecked(&pool->req_ser, 0);
31488 + atomic_set_unchecked(&pool->flush_ser, 0);
31489 init_waitqueue_head(&pool->force_wait);
31490
31491 pool->thread = kthread_run(ib_fmr_cleanup_thread,
31492 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
31493 }
31494 spin_unlock_irq(&pool->pool_lock);
31495
31496 - serial = atomic_inc_return(&pool->req_ser);
31497 + serial = atomic_inc_return_unchecked(&pool->req_ser);
31498 wake_up_process(pool->thread);
31499
31500 if (wait_event_interruptible(pool->force_wait,
31501 - atomic_read(&pool->flush_ser) - serial >= 0))
31502 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
31503 return -EINTR;
31504
31505 return 0;
31506 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
31507 } else {
31508 list_add_tail(&fmr->list, &pool->dirty_list);
31509 if (++pool->dirty_len >= pool->dirty_watermark) {
31510 - atomic_inc(&pool->req_ser);
31511 + atomic_inc_unchecked(&pool->req_ser);
31512 wake_up_process(pool->thread);
31513 }
31514 }
31515 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
31516 index 40c8353..946b0e4 100644
31517 --- a/drivers/infiniband/hw/cxgb4/mem.c
31518 +++ b/drivers/infiniband/hw/cxgb4/mem.c
31519 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31520 int err;
31521 struct fw_ri_tpte tpt;
31522 u32 stag_idx;
31523 - static atomic_t key;
31524 + static atomic_unchecked_t key;
31525
31526 if (c4iw_fatal_error(rdev))
31527 return -EIO;
31528 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31529 &rdev->resource.tpt_fifo_lock);
31530 if (!stag_idx)
31531 return -ENOMEM;
31532 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
31533 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
31534 }
31535 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
31536 __func__, stag_state, type, pdid, stag_idx);
31537 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
31538 index 79b3dbc..96e5fcc 100644
31539 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
31540 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
31541 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31542 struct ib_atomic_eth *ateth;
31543 struct ipath_ack_entry *e;
31544 u64 vaddr;
31545 - atomic64_t *maddr;
31546 + atomic64_unchecked_t *maddr;
31547 u64 sdata;
31548 u32 rkey;
31549 u8 next;
31550 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31551 IB_ACCESS_REMOTE_ATOMIC)))
31552 goto nack_acc_unlck;
31553 /* Perform atomic OP and save result. */
31554 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31555 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31556 sdata = be64_to_cpu(ateth->swap_data);
31557 e = &qp->s_ack_queue[qp->r_head_ack_queue];
31558 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
31559 - (u64) atomic64_add_return(sdata, maddr) - sdata :
31560 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31561 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31562 be64_to_cpu(ateth->compare_data),
31563 sdata);
31564 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
31565 index 1f95bba..9530f87 100644
31566 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
31567 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
31568 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
31569 unsigned long flags;
31570 struct ib_wc wc;
31571 u64 sdata;
31572 - atomic64_t *maddr;
31573 + atomic64_unchecked_t *maddr;
31574 enum ib_wc_status send_status;
31575
31576 /*
31577 @@ -382,11 +382,11 @@ again:
31578 IB_ACCESS_REMOTE_ATOMIC)))
31579 goto acc_err;
31580 /* Perform atomic OP and save result. */
31581 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31582 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31583 sdata = wqe->wr.wr.atomic.compare_add;
31584 *(u64 *) sqp->s_sge.sge.vaddr =
31585 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
31586 - (u64) atomic64_add_return(sdata, maddr) - sdata :
31587 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31588 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31589 sdata, wqe->wr.wr.atomic.swap);
31590 goto send_comp;
31591 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
31592 index 5965b3d..16817fb 100644
31593 --- a/drivers/infiniband/hw/nes/nes.c
31594 +++ b/drivers/infiniband/hw/nes/nes.c
31595 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
31596 LIST_HEAD(nes_adapter_list);
31597 static LIST_HEAD(nes_dev_list);
31598
31599 -atomic_t qps_destroyed;
31600 +atomic_unchecked_t qps_destroyed;
31601
31602 static unsigned int ee_flsh_adapter;
31603 static unsigned int sysfs_nonidx_addr;
31604 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
31605 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
31606 struct nes_adapter *nesadapter = nesdev->nesadapter;
31607
31608 - atomic_inc(&qps_destroyed);
31609 + atomic_inc_unchecked(&qps_destroyed);
31610
31611 /* Free the control structures */
31612
31613 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
31614 index 568b4f1..5ea3eff 100644
31615 --- a/drivers/infiniband/hw/nes/nes.h
31616 +++ b/drivers/infiniband/hw/nes/nes.h
31617 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
31618 extern unsigned int wqm_quanta;
31619 extern struct list_head nes_adapter_list;
31620
31621 -extern atomic_t cm_connects;
31622 -extern atomic_t cm_accepts;
31623 -extern atomic_t cm_disconnects;
31624 -extern atomic_t cm_closes;
31625 -extern atomic_t cm_connecteds;
31626 -extern atomic_t cm_connect_reqs;
31627 -extern atomic_t cm_rejects;
31628 -extern atomic_t mod_qp_timouts;
31629 -extern atomic_t qps_created;
31630 -extern atomic_t qps_destroyed;
31631 -extern atomic_t sw_qps_destroyed;
31632 +extern atomic_unchecked_t cm_connects;
31633 +extern atomic_unchecked_t cm_accepts;
31634 +extern atomic_unchecked_t cm_disconnects;
31635 +extern atomic_unchecked_t cm_closes;
31636 +extern atomic_unchecked_t cm_connecteds;
31637 +extern atomic_unchecked_t cm_connect_reqs;
31638 +extern atomic_unchecked_t cm_rejects;
31639 +extern atomic_unchecked_t mod_qp_timouts;
31640 +extern atomic_unchecked_t qps_created;
31641 +extern atomic_unchecked_t qps_destroyed;
31642 +extern atomic_unchecked_t sw_qps_destroyed;
31643 extern u32 mh_detected;
31644 extern u32 mh_pauses_sent;
31645 extern u32 cm_packets_sent;
31646 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
31647 extern u32 cm_packets_received;
31648 extern u32 cm_packets_dropped;
31649 extern u32 cm_packets_retrans;
31650 -extern atomic_t cm_listens_created;
31651 -extern atomic_t cm_listens_destroyed;
31652 +extern atomic_unchecked_t cm_listens_created;
31653 +extern atomic_unchecked_t cm_listens_destroyed;
31654 extern u32 cm_backlog_drops;
31655 -extern atomic_t cm_loopbacks;
31656 -extern atomic_t cm_nodes_created;
31657 -extern atomic_t cm_nodes_destroyed;
31658 -extern atomic_t cm_accel_dropped_pkts;
31659 -extern atomic_t cm_resets_recvd;
31660 -extern atomic_t pau_qps_created;
31661 -extern atomic_t pau_qps_destroyed;
31662 +extern atomic_unchecked_t cm_loopbacks;
31663 +extern atomic_unchecked_t cm_nodes_created;
31664 +extern atomic_unchecked_t cm_nodes_destroyed;
31665 +extern atomic_unchecked_t cm_accel_dropped_pkts;
31666 +extern atomic_unchecked_t cm_resets_recvd;
31667 +extern atomic_unchecked_t pau_qps_created;
31668 +extern atomic_unchecked_t pau_qps_destroyed;
31669
31670 extern u32 int_mod_timer_init;
31671 extern u32 int_mod_cq_depth_256;
31672 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
31673 index 0a52d72..0642f36 100644
31674 --- a/drivers/infiniband/hw/nes/nes_cm.c
31675 +++ b/drivers/infiniband/hw/nes/nes_cm.c
31676 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
31677 u32 cm_packets_retrans;
31678 u32 cm_packets_created;
31679 u32 cm_packets_received;
31680 -atomic_t cm_listens_created;
31681 -atomic_t cm_listens_destroyed;
31682 +atomic_unchecked_t cm_listens_created;
31683 +atomic_unchecked_t cm_listens_destroyed;
31684 u32 cm_backlog_drops;
31685 -atomic_t cm_loopbacks;
31686 -atomic_t cm_nodes_created;
31687 -atomic_t cm_nodes_destroyed;
31688 -atomic_t cm_accel_dropped_pkts;
31689 -atomic_t cm_resets_recvd;
31690 +atomic_unchecked_t cm_loopbacks;
31691 +atomic_unchecked_t cm_nodes_created;
31692 +atomic_unchecked_t cm_nodes_destroyed;
31693 +atomic_unchecked_t cm_accel_dropped_pkts;
31694 +atomic_unchecked_t cm_resets_recvd;
31695
31696 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
31697 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
31698 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
31699
31700 static struct nes_cm_core *g_cm_core;
31701
31702 -atomic_t cm_connects;
31703 -atomic_t cm_accepts;
31704 -atomic_t cm_disconnects;
31705 -atomic_t cm_closes;
31706 -atomic_t cm_connecteds;
31707 -atomic_t cm_connect_reqs;
31708 -atomic_t cm_rejects;
31709 +atomic_unchecked_t cm_connects;
31710 +atomic_unchecked_t cm_accepts;
31711 +atomic_unchecked_t cm_disconnects;
31712 +atomic_unchecked_t cm_closes;
31713 +atomic_unchecked_t cm_connecteds;
31714 +atomic_unchecked_t cm_connect_reqs;
31715 +atomic_unchecked_t cm_rejects;
31716
31717 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
31718 {
31719 @@ -1271,7 +1271,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
31720 kfree(listener);
31721 listener = NULL;
31722 ret = 0;
31723 - atomic_inc(&cm_listens_destroyed);
31724 + atomic_inc_unchecked(&cm_listens_destroyed);
31725 } else {
31726 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
31727 }
31728 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
31729 cm_node->rem_mac);
31730
31731 add_hte_node(cm_core, cm_node);
31732 - atomic_inc(&cm_nodes_created);
31733 + atomic_inc_unchecked(&cm_nodes_created);
31734
31735 return cm_node;
31736 }
31737 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
31738 }
31739
31740 atomic_dec(&cm_core->node_cnt);
31741 - atomic_inc(&cm_nodes_destroyed);
31742 + atomic_inc_unchecked(&cm_nodes_destroyed);
31743 nesqp = cm_node->nesqp;
31744 if (nesqp) {
31745 nesqp->cm_node = NULL;
31746 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
31747
31748 static void drop_packet(struct sk_buff *skb)
31749 {
31750 - atomic_inc(&cm_accel_dropped_pkts);
31751 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
31752 dev_kfree_skb_any(skb);
31753 }
31754
31755 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
31756 {
31757
31758 int reset = 0; /* whether to send reset in case of err.. */
31759 - atomic_inc(&cm_resets_recvd);
31760 + atomic_inc_unchecked(&cm_resets_recvd);
31761 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
31762 " refcnt=%d\n", cm_node, cm_node->state,
31763 atomic_read(&cm_node->ref_count));
31764 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
31765 rem_ref_cm_node(cm_node->cm_core, cm_node);
31766 return NULL;
31767 }
31768 - atomic_inc(&cm_loopbacks);
31769 + atomic_inc_unchecked(&cm_loopbacks);
31770 loopbackremotenode->loopbackpartner = cm_node;
31771 loopbackremotenode->tcp_cntxt.rcv_wscale =
31772 NES_CM_DEFAULT_RCV_WND_SCALE;
31773 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
31774 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
31775 else {
31776 rem_ref_cm_node(cm_core, cm_node);
31777 - atomic_inc(&cm_accel_dropped_pkts);
31778 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
31779 dev_kfree_skb_any(skb);
31780 }
31781 break;
31782 @@ -2880,7 +2880,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31783
31784 if ((cm_id) && (cm_id->event_handler)) {
31785 if (issue_disconn) {
31786 - atomic_inc(&cm_disconnects);
31787 + atomic_inc_unchecked(&cm_disconnects);
31788 cm_event.event = IW_CM_EVENT_DISCONNECT;
31789 cm_event.status = disconn_status;
31790 cm_event.local_addr = cm_id->local_addr;
31791 @@ -2902,7 +2902,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31792 }
31793
31794 if (issue_close) {
31795 - atomic_inc(&cm_closes);
31796 + atomic_inc_unchecked(&cm_closes);
31797 nes_disconnect(nesqp, 1);
31798
31799 cm_id->provider_data = nesqp;
31800 @@ -3038,7 +3038,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31801
31802 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
31803 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
31804 - atomic_inc(&cm_accepts);
31805 + atomic_inc_unchecked(&cm_accepts);
31806
31807 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
31808 netdev_refcnt_read(nesvnic->netdev));
31809 @@ -3240,7 +3240,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
31810 struct nes_cm_core *cm_core;
31811 u8 *start_buff;
31812
31813 - atomic_inc(&cm_rejects);
31814 + atomic_inc_unchecked(&cm_rejects);
31815 cm_node = (struct nes_cm_node *)cm_id->provider_data;
31816 loopback = cm_node->loopbackpartner;
31817 cm_core = cm_node->cm_core;
31818 @@ -3300,7 +3300,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31819 ntohl(cm_id->local_addr.sin_addr.s_addr),
31820 ntohs(cm_id->local_addr.sin_port));
31821
31822 - atomic_inc(&cm_connects);
31823 + atomic_inc_unchecked(&cm_connects);
31824 nesqp->active_conn = 1;
31825
31826 /* cache the cm_id in the qp */
31827 @@ -3406,7 +3406,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
31828 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
31829 return err;
31830 }
31831 - atomic_inc(&cm_listens_created);
31832 + atomic_inc_unchecked(&cm_listens_created);
31833 }
31834
31835 cm_id->add_ref(cm_id);
31836 @@ -3507,7 +3507,7 @@ static void cm_event_connected(struct nes_cm_event *event)
31837
31838 if (nesqp->destroyed)
31839 return;
31840 - atomic_inc(&cm_connecteds);
31841 + atomic_inc_unchecked(&cm_connecteds);
31842 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
31843 " local port 0x%04X. jiffies = %lu.\n",
31844 nesqp->hwqp.qp_id,
31845 @@ -3694,7 +3694,7 @@ static void cm_event_reset(struct nes_cm_event *event)
31846
31847 cm_id->add_ref(cm_id);
31848 ret = cm_id->event_handler(cm_id, &cm_event);
31849 - atomic_inc(&cm_closes);
31850 + atomic_inc_unchecked(&cm_closes);
31851 cm_event.event = IW_CM_EVENT_CLOSE;
31852 cm_event.status = 0;
31853 cm_event.provider_data = cm_id->provider_data;
31854 @@ -3730,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
31855 return;
31856 cm_id = cm_node->cm_id;
31857
31858 - atomic_inc(&cm_connect_reqs);
31859 + atomic_inc_unchecked(&cm_connect_reqs);
31860 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31861 cm_node, cm_id, jiffies);
31862
31863 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
31864 return;
31865 cm_id = cm_node->cm_id;
31866
31867 - atomic_inc(&cm_connect_reqs);
31868 + atomic_inc_unchecked(&cm_connect_reqs);
31869 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31870 cm_node, cm_id, jiffies);
31871
31872 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
31873 index b3b2a24..7bfaf1e 100644
31874 --- a/drivers/infiniband/hw/nes/nes_mgt.c
31875 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
31876 @@ -40,8 +40,8 @@
31877 #include "nes.h"
31878 #include "nes_mgt.h"
31879
31880 -atomic_t pau_qps_created;
31881 -atomic_t pau_qps_destroyed;
31882 +atomic_unchecked_t pau_qps_created;
31883 +atomic_unchecked_t pau_qps_destroyed;
31884
31885 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
31886 {
31887 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
31888 {
31889 struct sk_buff *skb;
31890 unsigned long flags;
31891 - atomic_inc(&pau_qps_destroyed);
31892 + atomic_inc_unchecked(&pau_qps_destroyed);
31893
31894 /* Free packets that have not yet been forwarded */
31895 /* Lock is acquired by skb_dequeue when removing the skb */
31896 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
31897 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
31898 skb_queue_head_init(&nesqp->pau_list);
31899 spin_lock_init(&nesqp->pau_lock);
31900 - atomic_inc(&pau_qps_created);
31901 + atomic_inc_unchecked(&pau_qps_created);
31902 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
31903 }
31904
31905 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
31906 index c00d2f3..8834298 100644
31907 --- a/drivers/infiniband/hw/nes/nes_nic.c
31908 +++ b/drivers/infiniband/hw/nes/nes_nic.c
31909 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
31910 target_stat_values[++index] = mh_detected;
31911 target_stat_values[++index] = mh_pauses_sent;
31912 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
31913 - target_stat_values[++index] = atomic_read(&cm_connects);
31914 - target_stat_values[++index] = atomic_read(&cm_accepts);
31915 - target_stat_values[++index] = atomic_read(&cm_disconnects);
31916 - target_stat_values[++index] = atomic_read(&cm_connecteds);
31917 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
31918 - target_stat_values[++index] = atomic_read(&cm_rejects);
31919 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
31920 - target_stat_values[++index] = atomic_read(&qps_created);
31921 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
31922 - target_stat_values[++index] = atomic_read(&qps_destroyed);
31923 - target_stat_values[++index] = atomic_read(&cm_closes);
31924 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
31925 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
31926 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
31927 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
31928 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
31929 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
31930 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
31931 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
31932 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
31933 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
31934 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
31935 target_stat_values[++index] = cm_packets_sent;
31936 target_stat_values[++index] = cm_packets_bounced;
31937 target_stat_values[++index] = cm_packets_created;
31938 target_stat_values[++index] = cm_packets_received;
31939 target_stat_values[++index] = cm_packets_dropped;
31940 target_stat_values[++index] = cm_packets_retrans;
31941 - target_stat_values[++index] = atomic_read(&cm_listens_created);
31942 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
31943 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
31944 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
31945 target_stat_values[++index] = cm_backlog_drops;
31946 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
31947 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
31948 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
31949 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
31950 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
31951 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
31952 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
31953 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
31954 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
31955 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
31956 target_stat_values[++index] = nesadapter->free_4kpbl;
31957 target_stat_values[++index] = nesadapter->free_256pbl;
31958 target_stat_values[++index] = int_mod_timer_init;
31959 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
31960 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
31961 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
31962 - target_stat_values[++index] = atomic_read(&pau_qps_created);
31963 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
31964 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
31965 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
31966 }
31967
31968 /**
31969 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
31970 index 5095bc4..41e8fff 100644
31971 --- a/drivers/infiniband/hw/nes/nes_verbs.c
31972 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
31973 @@ -46,9 +46,9 @@
31974
31975 #include <rdma/ib_umem.h>
31976
31977 -atomic_t mod_qp_timouts;
31978 -atomic_t qps_created;
31979 -atomic_t sw_qps_destroyed;
31980 +atomic_unchecked_t mod_qp_timouts;
31981 +atomic_unchecked_t qps_created;
31982 +atomic_unchecked_t sw_qps_destroyed;
31983
31984 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
31985
31986 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
31987 if (init_attr->create_flags)
31988 return ERR_PTR(-EINVAL);
31989
31990 - atomic_inc(&qps_created);
31991 + atomic_inc_unchecked(&qps_created);
31992 switch (init_attr->qp_type) {
31993 case IB_QPT_RC:
31994 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
31995 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
31996 struct iw_cm_event cm_event;
31997 int ret = 0;
31998
31999 - atomic_inc(&sw_qps_destroyed);
32000 + atomic_inc_unchecked(&sw_qps_destroyed);
32001 nesqp->destroyed = 1;
32002
32003 /* Blow away the connection if it exists. */
32004 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32005 index b881bdc..c2e360c 100644
32006 --- a/drivers/infiniband/hw/qib/qib.h
32007 +++ b/drivers/infiniband/hw/qib/qib.h
32008 @@ -51,6 +51,7 @@
32009 #include <linux/completion.h>
32010 #include <linux/kref.h>
32011 #include <linux/sched.h>
32012 +#include <linux/slab.h>
32013
32014 #include "qib_common.h"
32015 #include "qib_verbs.h"
32016 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32017 index c351aa4..e6967c2 100644
32018 --- a/drivers/input/gameport/gameport.c
32019 +++ b/drivers/input/gameport/gameport.c
32020 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32021 */
32022 static void gameport_init_port(struct gameport *gameport)
32023 {
32024 - static atomic_t gameport_no = ATOMIC_INIT(0);
32025 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32026
32027 __module_get(THIS_MODULE);
32028
32029 mutex_init(&gameport->drv_mutex);
32030 device_initialize(&gameport->dev);
32031 dev_set_name(&gameport->dev, "gameport%lu",
32032 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32033 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32034 gameport->dev.bus = &gameport_bus;
32035 gameport->dev.release = gameport_release_port;
32036 if (gameport->parent)
32037 diff --git a/drivers/input/input.c b/drivers/input/input.c
32038 index da38d97..2aa0b79 100644
32039 --- a/drivers/input/input.c
32040 +++ b/drivers/input/input.c
32041 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32042 */
32043 int input_register_device(struct input_dev *dev)
32044 {
32045 - static atomic_t input_no = ATOMIC_INIT(0);
32046 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32047 struct input_handler *handler;
32048 const char *path;
32049 int error;
32050 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32051 dev->setkeycode = input_default_setkeycode;
32052
32053 dev_set_name(&dev->dev, "input%ld",
32054 - (unsigned long) atomic_inc_return(&input_no) - 1);
32055 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32056
32057 error = device_add(&dev->dev);
32058 if (error)
32059 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32060 index b8d8611..7a4a04b 100644
32061 --- a/drivers/input/joystick/sidewinder.c
32062 +++ b/drivers/input/joystick/sidewinder.c
32063 @@ -30,6 +30,7 @@
32064 #include <linux/kernel.h>
32065 #include <linux/module.h>
32066 #include <linux/slab.h>
32067 +#include <linux/sched.h>
32068 #include <linux/init.h>
32069 #include <linux/input.h>
32070 #include <linux/gameport.h>
32071 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32072 index d728875..844c89b 100644
32073 --- a/drivers/input/joystick/xpad.c
32074 +++ b/drivers/input/joystick/xpad.c
32075 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32076
32077 static int xpad_led_probe(struct usb_xpad *xpad)
32078 {
32079 - static atomic_t led_seq = ATOMIC_INIT(0);
32080 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32081 long led_no;
32082 struct xpad_led *led;
32083 struct led_classdev *led_cdev;
32084 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32085 if (!led)
32086 return -ENOMEM;
32087
32088 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32089 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32090
32091 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32092 led->xpad = xpad;
32093 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32094 index 0110b5a..d3ad144 100644
32095 --- a/drivers/input/mousedev.c
32096 +++ b/drivers/input/mousedev.c
32097 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32098
32099 spin_unlock_irq(&client->packet_lock);
32100
32101 - if (copy_to_user(buffer, data, count))
32102 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32103 return -EFAULT;
32104
32105 return count;
32106 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32107 index ba70058..571d25d 100644
32108 --- a/drivers/input/serio/serio.c
32109 +++ b/drivers/input/serio/serio.c
32110 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32111 */
32112 static void serio_init_port(struct serio *serio)
32113 {
32114 - static atomic_t serio_no = ATOMIC_INIT(0);
32115 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32116
32117 __module_get(THIS_MODULE);
32118
32119 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32120 mutex_init(&serio->drv_mutex);
32121 device_initialize(&serio->dev);
32122 dev_set_name(&serio->dev, "serio%ld",
32123 - (long)atomic_inc_return(&serio_no) - 1);
32124 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32125 serio->dev.bus = &serio_bus;
32126 serio->dev.release = serio_release_port;
32127 serio->dev.groups = serio_device_attr_groups;
32128 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32129 index e44933d..9ba484a 100644
32130 --- a/drivers/isdn/capi/capi.c
32131 +++ b/drivers/isdn/capi/capi.c
32132 @@ -83,8 +83,8 @@ struct capiminor {
32133
32134 struct capi20_appl *ap;
32135 u32 ncci;
32136 - atomic_t datahandle;
32137 - atomic_t msgid;
32138 + atomic_unchecked_t datahandle;
32139 + atomic_unchecked_t msgid;
32140
32141 struct tty_port port;
32142 int ttyinstop;
32143 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32144 capimsg_setu16(s, 2, mp->ap->applid);
32145 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32146 capimsg_setu8 (s, 5, CAPI_RESP);
32147 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32148 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32149 capimsg_setu32(s, 8, mp->ncci);
32150 capimsg_setu16(s, 12, datahandle);
32151 }
32152 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32153 mp->outbytes -= len;
32154 spin_unlock_bh(&mp->outlock);
32155
32156 - datahandle = atomic_inc_return(&mp->datahandle);
32157 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32158 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32159 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32160 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32161 capimsg_setu16(skb->data, 2, mp->ap->applid);
32162 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32163 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32164 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32165 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32166 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32167 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32168 capimsg_setu16(skb->data, 16, len); /* Data length */
32169 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32170 index db621db..825ea1a 100644
32171 --- a/drivers/isdn/gigaset/common.c
32172 +++ b/drivers/isdn/gigaset/common.c
32173 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32174 cs->commands_pending = 0;
32175 cs->cur_at_seq = 0;
32176 cs->gotfwver = -1;
32177 - cs->open_count = 0;
32178 + local_set(&cs->open_count, 0);
32179 cs->dev = NULL;
32180 cs->tty = NULL;
32181 cs->tty_dev = NULL;
32182 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32183 index 212efaf..f187c6b 100644
32184 --- a/drivers/isdn/gigaset/gigaset.h
32185 +++ b/drivers/isdn/gigaset/gigaset.h
32186 @@ -35,6 +35,7 @@
32187 #include <linux/tty_driver.h>
32188 #include <linux/list.h>
32189 #include <linux/atomic.h>
32190 +#include <asm/local.h>
32191
32192 #define GIG_VERSION {0, 5, 0, 0}
32193 #define GIG_COMPAT {0, 4, 0, 0}
32194 @@ -433,7 +434,7 @@ struct cardstate {
32195 spinlock_t cmdlock;
32196 unsigned curlen, cmdbytes;
32197
32198 - unsigned open_count;
32199 + local_t open_count;
32200 struct tty_struct *tty;
32201 struct tasklet_struct if_wake_tasklet;
32202 unsigned control_state;
32203 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32204 index ee0a549..a7c9798 100644
32205 --- a/drivers/isdn/gigaset/interface.c
32206 +++ b/drivers/isdn/gigaset/interface.c
32207 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32208 }
32209 tty->driver_data = cs;
32210
32211 - ++cs->open_count;
32212 -
32213 - if (cs->open_count == 1) {
32214 + if (local_inc_return(&cs->open_count) == 1) {
32215 spin_lock_irqsave(&cs->lock, flags);
32216 cs->tty = tty;
32217 spin_unlock_irqrestore(&cs->lock, flags);
32218 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32219
32220 if (!cs->connected)
32221 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32222 - else if (!cs->open_count)
32223 + else if (!local_read(&cs->open_count))
32224 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32225 else {
32226 - if (!--cs->open_count) {
32227 + if (!local_dec_return(&cs->open_count)) {
32228 spin_lock_irqsave(&cs->lock, flags);
32229 cs->tty = NULL;
32230 spin_unlock_irqrestore(&cs->lock, flags);
32231 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32232 if (!cs->connected) {
32233 gig_dbg(DEBUG_IF, "not connected");
32234 retval = -ENODEV;
32235 - } else if (!cs->open_count)
32236 + } else if (!local_read(&cs->open_count))
32237 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32238 else {
32239 retval = 0;
32240 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32241 retval = -ENODEV;
32242 goto done;
32243 }
32244 - if (!cs->open_count) {
32245 + if (!local_read(&cs->open_count)) {
32246 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32247 retval = -ENODEV;
32248 goto done;
32249 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32250 if (!cs->connected) {
32251 gig_dbg(DEBUG_IF, "not connected");
32252 retval = -ENODEV;
32253 - } else if (!cs->open_count)
32254 + } else if (!local_read(&cs->open_count))
32255 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32256 else if (cs->mstate != MS_LOCKED) {
32257 dev_warn(cs->dev, "can't write to unlocked device\n");
32258 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32259
32260 if (!cs->connected)
32261 gig_dbg(DEBUG_IF, "not connected");
32262 - else if (!cs->open_count)
32263 + else if (!local_read(&cs->open_count))
32264 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32265 else if (cs->mstate != MS_LOCKED)
32266 dev_warn(cs->dev, "can't write to unlocked device\n");
32267 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32268
32269 if (!cs->connected)
32270 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32271 - else if (!cs->open_count)
32272 + else if (!local_read(&cs->open_count))
32273 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32274 else
32275 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32276 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32277
32278 if (!cs->connected)
32279 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32280 - else if (!cs->open_count)
32281 + else if (!local_read(&cs->open_count))
32282 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32283 else
32284 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32285 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32286 goto out;
32287 }
32288
32289 - if (!cs->open_count) {
32290 + if (!local_read(&cs->open_count)) {
32291 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32292 goto out;
32293 }
32294 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32295 index 2a57da59..e7a12ed 100644
32296 --- a/drivers/isdn/hardware/avm/b1.c
32297 +++ b/drivers/isdn/hardware/avm/b1.c
32298 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32299 }
32300 if (left) {
32301 if (t4file->user) {
32302 - if (copy_from_user(buf, dp, left))
32303 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32304 return -EFAULT;
32305 } else {
32306 memcpy(buf, dp, left);
32307 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32308 }
32309 if (left) {
32310 if (config->user) {
32311 - if (copy_from_user(buf, dp, left))
32312 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32313 return -EFAULT;
32314 } else {
32315 memcpy(buf, dp, left);
32316 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32317 index 85784a7..a19ca98 100644
32318 --- a/drivers/isdn/hardware/eicon/divasync.h
32319 +++ b/drivers/isdn/hardware/eicon/divasync.h
32320 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32321 } diva_didd_add_adapter_t;
32322 typedef struct _diva_didd_remove_adapter {
32323 IDI_CALL p_request;
32324 -} diva_didd_remove_adapter_t;
32325 +} __no_const diva_didd_remove_adapter_t;
32326 typedef struct _diva_didd_read_adapter_array {
32327 void * buffer;
32328 dword length;
32329 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32330 index a3bd163..8956575 100644
32331 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32332 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32333 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32334 typedef struct _diva_os_idi_adapter_interface {
32335 diva_init_card_proc_t cleanup_adapter_proc;
32336 diva_cmd_card_proc_t cmd_proc;
32337 -} diva_os_idi_adapter_interface_t;
32338 +} __no_const diva_os_idi_adapter_interface_t;
32339
32340 typedef struct _diva_os_xdi_adapter {
32341 struct list_head link;
32342 diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
32343 index 2339d73..802ab87 100644
32344 --- a/drivers/isdn/i4l/isdn_net.c
32345 +++ b/drivers/isdn/i4l/isdn_net.c
32346 @@ -1901,7 +1901,7 @@ static int isdn_net_header(struct sk_buff *skb, struct net_device *dev,
32347 {
32348 isdn_net_local *lp = netdev_priv(dev);
32349 unsigned char *p;
32350 - ushort len = 0;
32351 + int len = 0;
32352
32353 switch (lp->p_encap) {
32354 case ISDN_NET_ENCAP_ETHER:
32355 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32356 index 1f355bb..43f1fea 100644
32357 --- a/drivers/isdn/icn/icn.c
32358 +++ b/drivers/isdn/icn/icn.c
32359 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32360 if (count > len)
32361 count = len;
32362 if (user) {
32363 - if (copy_from_user(msg, buf, count))
32364 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32365 return -EFAULT;
32366 } else
32367 memcpy(msg, buf, count);
32368 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32369 index b5fdcb7..5b6c59f 100644
32370 --- a/drivers/lguest/core.c
32371 +++ b/drivers/lguest/core.c
32372 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32373 * it's worked so far. The end address needs +1 because __get_vm_area
32374 * allocates an extra guard page, so we need space for that.
32375 */
32376 +
32377 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32378 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32379 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32380 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32381 +#else
32382 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32383 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32384 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32385 +#endif
32386 +
32387 if (!switcher_vma) {
32388 err = -ENOMEM;
32389 printk("lguest: could not map switcher pages high\n");
32390 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32391 * Now the Switcher is mapped at the right address, we can't fail!
32392 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32393 */
32394 - memcpy(switcher_vma->addr, start_switcher_text,
32395 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32396 end_switcher_text - start_switcher_text);
32397
32398 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32399 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32400 index 65af42f..530c87a 100644
32401 --- a/drivers/lguest/x86/core.c
32402 +++ b/drivers/lguest/x86/core.c
32403 @@ -59,7 +59,7 @@ static struct {
32404 /* Offset from where switcher.S was compiled to where we've copied it */
32405 static unsigned long switcher_offset(void)
32406 {
32407 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32408 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32409 }
32410
32411 /* This cpu's struct lguest_pages. */
32412 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32413 * These copies are pretty cheap, so we do them unconditionally: */
32414 /* Save the current Host top-level page directory.
32415 */
32416 +
32417 +#ifdef CONFIG_PAX_PER_CPU_PGD
32418 + pages->state.host_cr3 = read_cr3();
32419 +#else
32420 pages->state.host_cr3 = __pa(current->mm->pgd);
32421 +#endif
32422 +
32423 /*
32424 * Set up the Guest's page tables to see this CPU's pages (and no
32425 * other CPU's pages).
32426 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32427 * compiled-in switcher code and the high-mapped copy we just made.
32428 */
32429 for (i = 0; i < IDT_ENTRIES; i++)
32430 - default_idt_entries[i] += switcher_offset();
32431 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32432
32433 /*
32434 * Set up the Switcher's per-cpu areas.
32435 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32436 * it will be undisturbed when we switch. To change %cs and jump we
32437 * need this structure to feed to Intel's "lcall" instruction.
32438 */
32439 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32440 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32441 lguest_entry.segment = LGUEST_CS;
32442
32443 /*
32444 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32445 index 40634b0..4f5855e 100644
32446 --- a/drivers/lguest/x86/switcher_32.S
32447 +++ b/drivers/lguest/x86/switcher_32.S
32448 @@ -87,6 +87,7 @@
32449 #include <asm/page.h>
32450 #include <asm/segment.h>
32451 #include <asm/lguest.h>
32452 +#include <asm/processor-flags.h>
32453
32454 // We mark the start of the code to copy
32455 // It's placed in .text tho it's never run here
32456 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32457 // Changes type when we load it: damn Intel!
32458 // For after we switch over our page tables
32459 // That entry will be read-only: we'd crash.
32460 +
32461 +#ifdef CONFIG_PAX_KERNEXEC
32462 + mov %cr0, %edx
32463 + xor $X86_CR0_WP, %edx
32464 + mov %edx, %cr0
32465 +#endif
32466 +
32467 movl $(GDT_ENTRY_TSS*8), %edx
32468 ltr %dx
32469
32470 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32471 // Let's clear it again for our return.
32472 // The GDT descriptor of the Host
32473 // Points to the table after two "size" bytes
32474 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
32475 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
32476 // Clear "used" from type field (byte 5, bit 2)
32477 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
32478 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
32479 +
32480 +#ifdef CONFIG_PAX_KERNEXEC
32481 + mov %cr0, %eax
32482 + xor $X86_CR0_WP, %eax
32483 + mov %eax, %cr0
32484 +#endif
32485
32486 // Once our page table's switched, the Guest is live!
32487 // The Host fades as we run this final step.
32488 @@ -295,13 +309,12 @@ deliver_to_host:
32489 // I consulted gcc, and it gave
32490 // These instructions, which I gladly credit:
32491 leal (%edx,%ebx,8), %eax
32492 - movzwl (%eax),%edx
32493 - movl 4(%eax), %eax
32494 - xorw %ax, %ax
32495 - orl %eax, %edx
32496 + movl 4(%eax), %edx
32497 + movw (%eax), %dx
32498 // Now the address of the handler's in %edx
32499 // We call it now: its "iret" drops us home.
32500 - jmp *%edx
32501 + ljmp $__KERNEL_CS, $1f
32502 +1: jmp *%edx
32503
32504 // Every interrupt can come to us here
32505 // But we must truly tell each apart.
32506 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
32507 index 4daf9e5..b8d1d0f 100644
32508 --- a/drivers/macintosh/macio_asic.c
32509 +++ b/drivers/macintosh/macio_asic.c
32510 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
32511 * MacIO is matched against any Apple ID, it's probe() function
32512 * will then decide wether it applies or not
32513 */
32514 -static const struct pci_device_id __devinitdata pci_ids [] = { {
32515 +static const struct pci_device_id __devinitconst pci_ids [] = { {
32516 .vendor = PCI_VENDOR_ID_APPLE,
32517 .device = PCI_ANY_ID,
32518 .subvendor = PCI_ANY_ID,
32519 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
32520 index 1ce84ed..0fdd40a 100644
32521 --- a/drivers/md/dm-ioctl.c
32522 +++ b/drivers/md/dm-ioctl.c
32523 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
32524 cmd == DM_LIST_VERSIONS_CMD)
32525 return 0;
32526
32527 - if ((cmd == DM_DEV_CREATE_CMD)) {
32528 + if (cmd == DM_DEV_CREATE_CMD) {
32529 if (!*param->name) {
32530 DMWARN("name not supplied when creating device");
32531 return -EINVAL;
32532 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
32533 index 9bfd057..01180bc 100644
32534 --- a/drivers/md/dm-raid1.c
32535 +++ b/drivers/md/dm-raid1.c
32536 @@ -40,7 +40,7 @@ enum dm_raid1_error {
32537
32538 struct mirror {
32539 struct mirror_set *ms;
32540 - atomic_t error_count;
32541 + atomic_unchecked_t error_count;
32542 unsigned long error_type;
32543 struct dm_dev *dev;
32544 sector_t offset;
32545 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
32546 struct mirror *m;
32547
32548 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
32549 - if (!atomic_read(&m->error_count))
32550 + if (!atomic_read_unchecked(&m->error_count))
32551 return m;
32552
32553 return NULL;
32554 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
32555 * simple way to tell if a device has encountered
32556 * errors.
32557 */
32558 - atomic_inc(&m->error_count);
32559 + atomic_inc_unchecked(&m->error_count);
32560
32561 if (test_and_set_bit(error_type, &m->error_type))
32562 return;
32563 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
32564 struct mirror *m = get_default_mirror(ms);
32565
32566 do {
32567 - if (likely(!atomic_read(&m->error_count)))
32568 + if (likely(!atomic_read_unchecked(&m->error_count)))
32569 return m;
32570
32571 if (m-- == ms->mirror)
32572 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
32573 {
32574 struct mirror *default_mirror = get_default_mirror(m->ms);
32575
32576 - return !atomic_read(&default_mirror->error_count);
32577 + return !atomic_read_unchecked(&default_mirror->error_count);
32578 }
32579
32580 static int mirror_available(struct mirror_set *ms, struct bio *bio)
32581 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
32582 */
32583 if (likely(region_in_sync(ms, region, 1)))
32584 m = choose_mirror(ms, bio->bi_sector);
32585 - else if (m && atomic_read(&m->error_count))
32586 + else if (m && atomic_read_unchecked(&m->error_count))
32587 m = NULL;
32588
32589 if (likely(m))
32590 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
32591 }
32592
32593 ms->mirror[mirror].ms = ms;
32594 - atomic_set(&(ms->mirror[mirror].error_count), 0);
32595 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
32596 ms->mirror[mirror].error_type = 0;
32597 ms->mirror[mirror].offset = offset;
32598
32599 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
32600 */
32601 static char device_status_char(struct mirror *m)
32602 {
32603 - if (!atomic_read(&(m->error_count)))
32604 + if (!atomic_read_unchecked(&(m->error_count)))
32605 return 'A';
32606
32607 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
32608 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
32609 index 3d80cf0..b77cc47 100644
32610 --- a/drivers/md/dm-stripe.c
32611 +++ b/drivers/md/dm-stripe.c
32612 @@ -20,7 +20,7 @@ struct stripe {
32613 struct dm_dev *dev;
32614 sector_t physical_start;
32615
32616 - atomic_t error_count;
32617 + atomic_unchecked_t error_count;
32618 };
32619
32620 struct stripe_c {
32621 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32622 kfree(sc);
32623 return r;
32624 }
32625 - atomic_set(&(sc->stripe[i].error_count), 0);
32626 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
32627 }
32628
32629 ti->private = sc;
32630 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
32631 DMEMIT("%d ", sc->stripes);
32632 for (i = 0; i < sc->stripes; i++) {
32633 DMEMIT("%s ", sc->stripe[i].dev->name);
32634 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
32635 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
32636 'D' : 'A';
32637 }
32638 buffer[i] = '\0';
32639 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
32640 */
32641 for (i = 0; i < sc->stripes; i++)
32642 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
32643 - atomic_inc(&(sc->stripe[i].error_count));
32644 - if (atomic_read(&(sc->stripe[i].error_count)) <
32645 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
32646 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
32647 DM_IO_ERROR_THRESHOLD)
32648 schedule_work(&sc->trigger_event);
32649 }
32650 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
32651 index 8e91321..fd17aef 100644
32652 --- a/drivers/md/dm-table.c
32653 +++ b/drivers/md/dm-table.c
32654 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
32655 if (!dev_size)
32656 return 0;
32657
32658 - if ((start >= dev_size) || (start + len > dev_size)) {
32659 + if ((start >= dev_size) || (len > dev_size - start)) {
32660 DMWARN("%s: %s too small for target: "
32661 "start=%llu, len=%llu, dev_size=%llu",
32662 dm_device_name(ti->table->md), bdevname(bdev, b),
32663 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
32664 index 237571a..fb6d19b 100644
32665 --- a/drivers/md/dm-thin-metadata.c
32666 +++ b/drivers/md/dm-thin-metadata.c
32667 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32668
32669 pmd->info.tm = tm;
32670 pmd->info.levels = 2;
32671 - pmd->info.value_type.context = pmd->data_sm;
32672 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32673 pmd->info.value_type.size = sizeof(__le64);
32674 pmd->info.value_type.inc = data_block_inc;
32675 pmd->info.value_type.dec = data_block_dec;
32676 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32677
32678 pmd->bl_info.tm = tm;
32679 pmd->bl_info.levels = 1;
32680 - pmd->bl_info.value_type.context = pmd->data_sm;
32681 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32682 pmd->bl_info.value_type.size = sizeof(__le64);
32683 pmd->bl_info.value_type.inc = data_block_inc;
32684 pmd->bl_info.value_type.dec = data_block_dec;
32685 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
32686 index 4720f68..78d1df7 100644
32687 --- a/drivers/md/dm.c
32688 +++ b/drivers/md/dm.c
32689 @@ -177,9 +177,9 @@ struct mapped_device {
32690 /*
32691 * Event handling.
32692 */
32693 - atomic_t event_nr;
32694 + atomic_unchecked_t event_nr;
32695 wait_queue_head_t eventq;
32696 - atomic_t uevent_seq;
32697 + atomic_unchecked_t uevent_seq;
32698 struct list_head uevent_list;
32699 spinlock_t uevent_lock; /* Protect access to uevent_list */
32700
32701 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
32702 rwlock_init(&md->map_lock);
32703 atomic_set(&md->holders, 1);
32704 atomic_set(&md->open_count, 0);
32705 - atomic_set(&md->event_nr, 0);
32706 - atomic_set(&md->uevent_seq, 0);
32707 + atomic_set_unchecked(&md->event_nr, 0);
32708 + atomic_set_unchecked(&md->uevent_seq, 0);
32709 INIT_LIST_HEAD(&md->uevent_list);
32710 spin_lock_init(&md->uevent_lock);
32711
32712 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
32713
32714 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
32715
32716 - atomic_inc(&md->event_nr);
32717 + atomic_inc_unchecked(&md->event_nr);
32718 wake_up(&md->eventq);
32719 }
32720
32721 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
32722
32723 uint32_t dm_next_uevent_seq(struct mapped_device *md)
32724 {
32725 - return atomic_add_return(1, &md->uevent_seq);
32726 + return atomic_add_return_unchecked(1, &md->uevent_seq);
32727 }
32728
32729 uint32_t dm_get_event_nr(struct mapped_device *md)
32730 {
32731 - return atomic_read(&md->event_nr);
32732 + return atomic_read_unchecked(&md->event_nr);
32733 }
32734
32735 int dm_wait_event(struct mapped_device *md, int event_nr)
32736 {
32737 return wait_event_interruptible(md->eventq,
32738 - (event_nr != atomic_read(&md->event_nr)));
32739 + (event_nr != atomic_read_unchecked(&md->event_nr)));
32740 }
32741
32742 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
32743 diff --git a/drivers/md/md.c b/drivers/md/md.c
32744 index f47f1f8..b7f559e 100644
32745 --- a/drivers/md/md.c
32746 +++ b/drivers/md/md.c
32747 @@ -278,10 +278,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
32748 * start build, activate spare
32749 */
32750 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
32751 -static atomic_t md_event_count;
32752 +static atomic_unchecked_t md_event_count;
32753 void md_new_event(struct mddev *mddev)
32754 {
32755 - atomic_inc(&md_event_count);
32756 + atomic_inc_unchecked(&md_event_count);
32757 wake_up(&md_event_waiters);
32758 }
32759 EXPORT_SYMBOL_GPL(md_new_event);
32760 @@ -291,7 +291,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
32761 */
32762 static void md_new_event_inintr(struct mddev *mddev)
32763 {
32764 - atomic_inc(&md_event_count);
32765 + atomic_inc_unchecked(&md_event_count);
32766 wake_up(&md_event_waiters);
32767 }
32768
32769 @@ -1525,7 +1525,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
32770
32771 rdev->preferred_minor = 0xffff;
32772 rdev->data_offset = le64_to_cpu(sb->data_offset);
32773 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32774 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32775
32776 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
32777 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
32778 @@ -1742,7 +1742,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
32779 else
32780 sb->resync_offset = cpu_to_le64(0);
32781
32782 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
32783 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
32784
32785 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
32786 sb->size = cpu_to_le64(mddev->dev_sectors);
32787 @@ -2639,7 +2639,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
32788 static ssize_t
32789 errors_show(struct md_rdev *rdev, char *page)
32790 {
32791 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
32792 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
32793 }
32794
32795 static ssize_t
32796 @@ -2648,7 +2648,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
32797 char *e;
32798 unsigned long n = simple_strtoul(buf, &e, 10);
32799 if (*buf && (*e == 0 || *e == '\n')) {
32800 - atomic_set(&rdev->corrected_errors, n);
32801 + atomic_set_unchecked(&rdev->corrected_errors, n);
32802 return len;
32803 }
32804 return -EINVAL;
32805 @@ -3039,8 +3039,8 @@ int md_rdev_init(struct md_rdev *rdev)
32806 rdev->sb_loaded = 0;
32807 rdev->bb_page = NULL;
32808 atomic_set(&rdev->nr_pending, 0);
32809 - atomic_set(&rdev->read_errors, 0);
32810 - atomic_set(&rdev->corrected_errors, 0);
32811 + atomic_set_unchecked(&rdev->read_errors, 0);
32812 + atomic_set_unchecked(&rdev->corrected_errors, 0);
32813
32814 INIT_LIST_HEAD(&rdev->same_set);
32815 init_waitqueue_head(&rdev->blocked_wait);
32816 @@ -6683,7 +6683,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32817
32818 spin_unlock(&pers_lock);
32819 seq_printf(seq, "\n");
32820 - seq->poll_event = atomic_read(&md_event_count);
32821 + seq->poll_event = atomic_read_unchecked(&md_event_count);
32822 return 0;
32823 }
32824 if (v == (void*)2) {
32825 @@ -6772,7 +6772,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32826 chunk_kb ? "KB" : "B");
32827 if (bitmap->file) {
32828 seq_printf(seq, ", file: ");
32829 - seq_path(seq, &bitmap->file->f_path, " \t\n");
32830 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
32831 }
32832
32833 seq_printf(seq, "\n");
32834 @@ -6803,7 +6803,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
32835 return error;
32836
32837 seq = file->private_data;
32838 - seq->poll_event = atomic_read(&md_event_count);
32839 + seq->poll_event = atomic_read_unchecked(&md_event_count);
32840 return error;
32841 }
32842
32843 @@ -6817,7 +6817,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
32844 /* always allow read */
32845 mask = POLLIN | POLLRDNORM;
32846
32847 - if (seq->poll_event != atomic_read(&md_event_count))
32848 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
32849 mask |= POLLERR | POLLPRI;
32850 return mask;
32851 }
32852 @@ -6861,7 +6861,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
32853 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32854 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32855 (int)part_stat_read(&disk->part0, sectors[1]) -
32856 - atomic_read(&disk->sync_io);
32857 + atomic_read_unchecked(&disk->sync_io);
32858 /* sync IO will cause sync_io to increase before the disk_stats
32859 * as sync_io is counted when a request starts, and
32860 * disk_stats is counted when it completes.
32861 diff --git a/drivers/md/md.h b/drivers/md/md.h
32862 index cf742d9..7c7c745 100644
32863 --- a/drivers/md/md.h
32864 +++ b/drivers/md/md.h
32865 @@ -120,13 +120,13 @@ struct md_rdev {
32866 * only maintained for arrays that
32867 * support hot removal
32868 */
32869 - atomic_t read_errors; /* number of consecutive read errors that
32870 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
32871 * we have tried to ignore.
32872 */
32873 struct timespec last_read_error; /* monotonic time since our
32874 * last read error
32875 */
32876 - atomic_t corrected_errors; /* number of corrected read errors,
32877 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32878 * for reporting to userspace and storing
32879 * in superblock.
32880 */
32881 @@ -410,7 +410,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
32882
32883 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32884 {
32885 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32886 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32887 }
32888
32889 struct md_personality
32890 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
32891 index 50ed53b..4f29d7d 100644
32892 --- a/drivers/md/persistent-data/dm-space-map-checker.c
32893 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
32894 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
32895 /*----------------------------------------------------------------*/
32896
32897 struct sm_checker {
32898 - struct dm_space_map sm;
32899 + dm_space_map_no_const sm;
32900
32901 struct count_array old_counts;
32902 struct count_array counts;
32903 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
32904 index fc469ba..2d91555 100644
32905 --- a/drivers/md/persistent-data/dm-space-map-disk.c
32906 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
32907 @@ -23,7 +23,7 @@
32908 * Space map interface.
32909 */
32910 struct sm_disk {
32911 - struct dm_space_map sm;
32912 + dm_space_map_no_const sm;
32913
32914 struct ll_disk ll;
32915 struct ll_disk old_ll;
32916 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
32917 index e89ae5e..062e4c2 100644
32918 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
32919 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
32920 @@ -43,7 +43,7 @@ struct block_op {
32921 };
32922
32923 struct sm_metadata {
32924 - struct dm_space_map sm;
32925 + dm_space_map_no_const sm;
32926
32927 struct ll_disk ll;
32928 struct ll_disk old_ll;
32929 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
32930 index 1cbfc6b..56e1dbb 100644
32931 --- a/drivers/md/persistent-data/dm-space-map.h
32932 +++ b/drivers/md/persistent-data/dm-space-map.h
32933 @@ -60,6 +60,7 @@ struct dm_space_map {
32934 int (*root_size)(struct dm_space_map *sm, size_t *result);
32935 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
32936 };
32937 +typedef struct dm_space_map __no_const dm_space_map_no_const;
32938
32939 /*----------------------------------------------------------------*/
32940
32941 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
32942 index 7d9e071..015b1d5 100644
32943 --- a/drivers/md/raid1.c
32944 +++ b/drivers/md/raid1.c
32945 @@ -1568,7 +1568,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
32946 if (r1_sync_page_io(rdev, sect, s,
32947 bio->bi_io_vec[idx].bv_page,
32948 READ) != 0)
32949 - atomic_add(s, &rdev->corrected_errors);
32950 + atomic_add_unchecked(s, &rdev->corrected_errors);
32951 }
32952 sectors -= s;
32953 sect += s;
32954 @@ -1781,7 +1781,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
32955 test_bit(In_sync, &rdev->flags)) {
32956 if (r1_sync_page_io(rdev, sect, s,
32957 conf->tmppage, READ)) {
32958 - atomic_add(s, &rdev->corrected_errors);
32959 + atomic_add_unchecked(s, &rdev->corrected_errors);
32960 printk(KERN_INFO
32961 "md/raid1:%s: read error corrected "
32962 "(%d sectors at %llu on %s)\n",
32963 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
32964 index 685ddf3..955b087 100644
32965 --- a/drivers/md/raid10.c
32966 +++ b/drivers/md/raid10.c
32967 @@ -1440,7 +1440,7 @@ static void end_sync_read(struct bio *bio, int error)
32968 /* The write handler will notice the lack of
32969 * R10BIO_Uptodate and record any errors etc
32970 */
32971 - atomic_add(r10_bio->sectors,
32972 + atomic_add_unchecked(r10_bio->sectors,
32973 &conf->mirrors[d].rdev->corrected_errors);
32974
32975 /* for reconstruct, we always reschedule after a read.
32976 @@ -1740,7 +1740,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32977 {
32978 struct timespec cur_time_mon;
32979 unsigned long hours_since_last;
32980 - unsigned int read_errors = atomic_read(&rdev->read_errors);
32981 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32982
32983 ktime_get_ts(&cur_time_mon);
32984
32985 @@ -1762,9 +1762,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32986 * overflowing the shift of read_errors by hours_since_last.
32987 */
32988 if (hours_since_last >= 8 * sizeof(read_errors))
32989 - atomic_set(&rdev->read_errors, 0);
32990 + atomic_set_unchecked(&rdev->read_errors, 0);
32991 else
32992 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32993 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32994 }
32995
32996 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
32997 @@ -1814,8 +1814,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32998 return;
32999
33000 check_decay_read_errors(mddev, rdev);
33001 - atomic_inc(&rdev->read_errors);
33002 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33003 + atomic_inc_unchecked(&rdev->read_errors);
33004 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33005 char b[BDEVNAME_SIZE];
33006 bdevname(rdev->bdev, b);
33007
33008 @@ -1823,7 +1823,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33009 "md/raid10:%s: %s: Raid device exceeded "
33010 "read_error threshold [cur %d:max %d]\n",
33011 mdname(mddev), b,
33012 - atomic_read(&rdev->read_errors), max_read_errors);
33013 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33014 printk(KERN_NOTICE
33015 "md/raid10:%s: %s: Failing raid device\n",
33016 mdname(mddev), b);
33017 @@ -1968,7 +1968,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33018 (unsigned long long)(
33019 sect + rdev->data_offset),
33020 bdevname(rdev->bdev, b));
33021 - atomic_add(s, &rdev->corrected_errors);
33022 + atomic_add_unchecked(s, &rdev->corrected_errors);
33023 }
33024
33025 rdev_dec_pending(rdev, mddev);
33026 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33027 index 858fdbb..b2dac95 100644
33028 --- a/drivers/md/raid5.c
33029 +++ b/drivers/md/raid5.c
33030 @@ -1610,19 +1610,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33031 (unsigned long long)(sh->sector
33032 + rdev->data_offset),
33033 bdevname(rdev->bdev, b));
33034 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33035 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33036 clear_bit(R5_ReadError, &sh->dev[i].flags);
33037 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33038 }
33039 - if (atomic_read(&conf->disks[i].rdev->read_errors))
33040 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
33041 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
33042 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
33043 } else {
33044 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
33045 int retry = 0;
33046 rdev = conf->disks[i].rdev;
33047
33048 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33049 - atomic_inc(&rdev->read_errors);
33050 + atomic_inc_unchecked(&rdev->read_errors);
33051 if (conf->mddev->degraded >= conf->max_degraded)
33052 printk_ratelimited(
33053 KERN_WARNING
33054 @@ -1642,7 +1642,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33055 (unsigned long long)(sh->sector
33056 + rdev->data_offset),
33057 bdn);
33058 - else if (atomic_read(&rdev->read_errors)
33059 + else if (atomic_read_unchecked(&rdev->read_errors)
33060 > conf->max_nr_stripes)
33061 printk(KERN_WARNING
33062 "md/raid:%s: Too many read errors, failing device %s.\n",
33063 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33064 index ba9a643..e474ab5 100644
33065 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33066 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33067 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33068 .subvendor = _subvend, .subdevice = _subdev, \
33069 .driver_data = (unsigned long)&_driverdata }
33070
33071 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33072 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33073 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33074 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33075 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33076 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33077 index a7d876f..8c21b61 100644
33078 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33079 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33080 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33081 union {
33082 dmx_ts_cb ts;
33083 dmx_section_cb sec;
33084 - } cb;
33085 + } __no_const cb;
33086
33087 struct dvb_demux *demux;
33088 void *priv;
33089 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33090 index f732877..d38c35a 100644
33091 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33092 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33093 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33094 const struct dvb_device *template, void *priv, int type)
33095 {
33096 struct dvb_device *dvbdev;
33097 - struct file_operations *dvbdevfops;
33098 + file_operations_no_const *dvbdevfops;
33099 struct device *clsdev;
33100 int minor;
33101 int id;
33102 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33103 index 9f2a02c..5920f88 100644
33104 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33105 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33106 @@ -1069,7 +1069,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33107 struct dib0700_adapter_state {
33108 int (*set_param_save) (struct dvb_frontend *,
33109 struct dvb_frontend_parameters *);
33110 -};
33111 +} __no_const;
33112
33113 static int dib7070_set_param_override(struct dvb_frontend *fe,
33114 struct dvb_frontend_parameters *fep)
33115 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33116 index f103ec1..5e8968b 100644
33117 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33118 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33119 @@ -95,7 +95,7 @@ struct su3000_state {
33120
33121 struct s6x0_state {
33122 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33123 -};
33124 +} __no_const;
33125
33126 /* debug */
33127 static int dvb_usb_dw2102_debug;
33128 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33129 index 404f63a..4796533 100644
33130 --- a/drivers/media/dvb/frontends/dib3000.h
33131 +++ b/drivers/media/dvb/frontends/dib3000.h
33132 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33133 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33134 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33135 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33136 -};
33137 +} __no_const;
33138
33139 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33140 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33141 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
33142 index 90bf573..e8463da 100644
33143 --- a/drivers/media/dvb/frontends/ds3000.c
33144 +++ b/drivers/media/dvb/frontends/ds3000.c
33145 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
33146
33147 for (i = 0; i < 30 ; i++) {
33148 ds3000_read_status(fe, &status);
33149 - if (status && FE_HAS_LOCK)
33150 + if (status & FE_HAS_LOCK)
33151 break;
33152
33153 msleep(10);
33154 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33155 index 0564192..75b16f5 100644
33156 --- a/drivers/media/dvb/ngene/ngene-cards.c
33157 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33158 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33159
33160 /****************************************************************************/
33161
33162 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33163 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33164 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33165 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33166 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33167 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33168 index 16a089f..ab1667d 100644
33169 --- a/drivers/media/radio/radio-cadet.c
33170 +++ b/drivers/media/radio/radio-cadet.c
33171 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33172 unsigned char readbuf[RDS_BUFFER];
33173 int i = 0;
33174
33175 + if (count > RDS_BUFFER)
33176 + return -EFAULT;
33177 mutex_lock(&dev->lock);
33178 if (dev->rdsstat == 0) {
33179 dev->rdsstat = 1;
33180 diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
33181 index 61287fc..8b08712 100644
33182 --- a/drivers/media/rc/redrat3.c
33183 +++ b/drivers/media/rc/redrat3.c
33184 @@ -905,7 +905,7 @@ static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier)
33185 return carrier;
33186 }
33187
33188 -static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
33189 +static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, u32 n)
33190 {
33191 struct redrat3_dev *rr3 = rcdev->priv;
33192 struct device *dev = rr3->dev;
33193 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33194 index 9cde353..8c6a1c3 100644
33195 --- a/drivers/media/video/au0828/au0828.h
33196 +++ b/drivers/media/video/au0828/au0828.h
33197 @@ -191,7 +191,7 @@ struct au0828_dev {
33198
33199 /* I2C */
33200 struct i2c_adapter i2c_adap;
33201 - struct i2c_algorithm i2c_algo;
33202 + i2c_algorithm_no_const i2c_algo;
33203 struct i2c_client i2c_client;
33204 u32 i2c_rc;
33205
33206 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33207 index 68d1240..46b32eb 100644
33208 --- a/drivers/media/video/cx88/cx88-alsa.c
33209 +++ b/drivers/media/video/cx88/cx88-alsa.c
33210 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33211 * Only boards with eeprom and byte 1 at eeprom=1 have it
33212 */
33213
33214 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33215 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33216 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33217 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33218 {0, }
33219 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33220 index ee0d0b3..20ab61e 100644
33221 --- a/drivers/media/video/omap/omap_vout.c
33222 +++ b/drivers/media/video/omap/omap_vout.c
33223 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33224 OMAP_VIDEO2,
33225 };
33226
33227 -static struct videobuf_queue_ops video_vbq_ops;
33228 /* Variables configurable through module params*/
33229 static u32 video1_numbuffers = 3;
33230 static u32 video2_numbuffers = 3;
33231 @@ -995,6 +994,13 @@ static int omap_vout_release(struct file *file)
33232 return ret;
33233 }
33234
33235 +static struct videobuf_queue_ops video_vbq_ops = {
33236 + .buf_setup = omap_vout_buffer_setup,
33237 + .buf_prepare = omap_vout_buffer_prepare,
33238 + .buf_release = omap_vout_buffer_release,
33239 + .buf_queue = omap_vout_buffer_queue,
33240 +};
33241 +
33242 static int omap_vout_open(struct file *file)
33243 {
33244 struct videobuf_queue *q;
33245 @@ -1016,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33246 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33247
33248 q = &vout->vbq;
33249 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33250 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33251 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33252 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33253 spin_lock_init(&vout->vbq_lock);
33254
33255 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33256 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33257 index 305e6aa..0143317 100644
33258 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33259 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33260 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33261
33262 /* I2C stuff */
33263 struct i2c_adapter i2c_adap;
33264 - struct i2c_algorithm i2c_algo;
33265 + i2c_algorithm_no_const i2c_algo;
33266 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33267 int i2c_cx25840_hack_state;
33268 int i2c_linked;
33269 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33270 index a0895bf..b7ebb1b 100644
33271 --- a/drivers/media/video/timblogiw.c
33272 +++ b/drivers/media/video/timblogiw.c
33273 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33274
33275 /* Platform device functions */
33276
33277 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33278 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33279 .vidioc_querycap = timblogiw_querycap,
33280 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33281 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33282 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33283 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33284 };
33285
33286 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33287 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33288 .owner = THIS_MODULE,
33289 .open = timblogiw_open,
33290 .release = timblogiw_close,
33291 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33292 index e9c6a60..daf6a33 100644
33293 --- a/drivers/message/fusion/mptbase.c
33294 +++ b/drivers/message/fusion/mptbase.c
33295 @@ -6753,8 +6753,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33296 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33297 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33298
33299 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33300 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33301 +#else
33302 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33303 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33304 +#endif
33305 +
33306 /*
33307 * Rounding UP to nearest 4-kB boundary here...
33308 */
33309 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33310 index 9d95042..b808101 100644
33311 --- a/drivers/message/fusion/mptsas.c
33312 +++ b/drivers/message/fusion/mptsas.c
33313 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33314 return 0;
33315 }
33316
33317 +static inline void
33318 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33319 +{
33320 + if (phy_info->port_details) {
33321 + phy_info->port_details->rphy = rphy;
33322 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33323 + ioc->name, rphy));
33324 + }
33325 +
33326 + if (rphy) {
33327 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33328 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33329 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33330 + ioc->name, rphy, rphy->dev.release));
33331 + }
33332 +}
33333 +
33334 /* no mutex */
33335 static void
33336 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33337 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33338 return NULL;
33339 }
33340
33341 -static inline void
33342 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33343 -{
33344 - if (phy_info->port_details) {
33345 - phy_info->port_details->rphy = rphy;
33346 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33347 - ioc->name, rphy));
33348 - }
33349 -
33350 - if (rphy) {
33351 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33352 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33353 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33354 - ioc->name, rphy, rphy->dev.release));
33355 - }
33356 -}
33357 -
33358 static inline struct sas_port *
33359 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33360 {
33361 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33362 index 0c3ced7..1fe34ec 100644
33363 --- a/drivers/message/fusion/mptscsih.c
33364 +++ b/drivers/message/fusion/mptscsih.c
33365 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33366
33367 h = shost_priv(SChost);
33368
33369 - if (h) {
33370 - if (h->info_kbuf == NULL)
33371 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33372 - return h->info_kbuf;
33373 - h->info_kbuf[0] = '\0';
33374 + if (!h)
33375 + return NULL;
33376
33377 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33378 - h->info_kbuf[size-1] = '\0';
33379 - }
33380 + if (h->info_kbuf == NULL)
33381 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33382 + return h->info_kbuf;
33383 + h->info_kbuf[0] = '\0';
33384 +
33385 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33386 + h->info_kbuf[size-1] = '\0';
33387
33388 return h->info_kbuf;
33389 }
33390 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33391 index 07dbeaf..5533142 100644
33392 --- a/drivers/message/i2o/i2o_proc.c
33393 +++ b/drivers/message/i2o/i2o_proc.c
33394 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33395 "Array Controller Device"
33396 };
33397
33398 -static char *chtostr(u8 * chars, int n)
33399 -{
33400 - char tmp[256];
33401 - tmp[0] = 0;
33402 - return strncat(tmp, (char *)chars, n);
33403 -}
33404 -
33405 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33406 char *group)
33407 {
33408 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33409
33410 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33411 seq_printf(seq, "%-#8x", ddm_table.module_id);
33412 - seq_printf(seq, "%-29s",
33413 - chtostr(ddm_table.module_name_version, 28));
33414 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33415 seq_printf(seq, "%9d ", ddm_table.data_size);
33416 seq_printf(seq, "%8d", ddm_table.code_size);
33417
33418 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33419
33420 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33421 seq_printf(seq, "%-#8x", dst->module_id);
33422 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33423 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33424 + seq_printf(seq, "%-.28s", dst->module_name_version);
33425 + seq_printf(seq, "%-.8s", dst->date);
33426 seq_printf(seq, "%8d ", dst->module_size);
33427 seq_printf(seq, "%8d ", dst->mpb_size);
33428 seq_printf(seq, "0x%04x", dst->module_flags);
33429 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33430 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33431 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33432 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33433 - seq_printf(seq, "Vendor info : %s\n",
33434 - chtostr((u8 *) (work32 + 2), 16));
33435 - seq_printf(seq, "Product info : %s\n",
33436 - chtostr((u8 *) (work32 + 6), 16));
33437 - seq_printf(seq, "Description : %s\n",
33438 - chtostr((u8 *) (work32 + 10), 16));
33439 - seq_printf(seq, "Product rev. : %s\n",
33440 - chtostr((u8 *) (work32 + 14), 8));
33441 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33442 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33443 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33444 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33445
33446 seq_printf(seq, "Serial number : ");
33447 print_serial_number(seq, (u8 *) (work32 + 16),
33448 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33449 }
33450
33451 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33452 - seq_printf(seq, "Module name : %s\n",
33453 - chtostr(result.module_name, 24));
33454 - seq_printf(seq, "Module revision : %s\n",
33455 - chtostr(result.module_rev, 8));
33456 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33457 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33458
33459 seq_printf(seq, "Serial number : ");
33460 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33461 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33462 return 0;
33463 }
33464
33465 - seq_printf(seq, "Device name : %s\n",
33466 - chtostr(result.device_name, 64));
33467 - seq_printf(seq, "Service name : %s\n",
33468 - chtostr(result.service_name, 64));
33469 - seq_printf(seq, "Physical name : %s\n",
33470 - chtostr(result.physical_location, 64));
33471 - seq_printf(seq, "Instance number : %s\n",
33472 - chtostr(result.instance_number, 4));
33473 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33474 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33475 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33476 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33477
33478 return 0;
33479 }
33480 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
33481 index a8c08f3..155fe3d 100644
33482 --- a/drivers/message/i2o/iop.c
33483 +++ b/drivers/message/i2o/iop.c
33484 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
33485
33486 spin_lock_irqsave(&c->context_list_lock, flags);
33487
33488 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33489 - atomic_inc(&c->context_list_counter);
33490 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33491 + atomic_inc_unchecked(&c->context_list_counter);
33492
33493 - entry->context = atomic_read(&c->context_list_counter);
33494 + entry->context = atomic_read_unchecked(&c->context_list_counter);
33495
33496 list_add(&entry->list, &c->context_list);
33497
33498 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
33499
33500 #if BITS_PER_LONG == 64
33501 spin_lock_init(&c->context_list_lock);
33502 - atomic_set(&c->context_list_counter, 0);
33503 + atomic_set_unchecked(&c->context_list_counter, 0);
33504 INIT_LIST_HEAD(&c->context_list);
33505 #endif
33506
33507 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
33508 index 7ce65f4..e66e9bc 100644
33509 --- a/drivers/mfd/abx500-core.c
33510 +++ b/drivers/mfd/abx500-core.c
33511 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
33512
33513 struct abx500_device_entry {
33514 struct list_head list;
33515 - struct abx500_ops ops;
33516 + abx500_ops_no_const ops;
33517 struct device *dev;
33518 };
33519
33520 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
33521 index 5c2a06a..8fa077c 100644
33522 --- a/drivers/mfd/janz-cmodio.c
33523 +++ b/drivers/mfd/janz-cmodio.c
33524 @@ -13,6 +13,7 @@
33525
33526 #include <linux/kernel.h>
33527 #include <linux/module.h>
33528 +#include <linux/slab.h>
33529 #include <linux/init.h>
33530 #include <linux/pci.h>
33531 #include <linux/interrupt.h>
33532 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
33533 index 29d12a7..f900ba4 100644
33534 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
33535 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
33536 @@ -464,7 +464,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
33537 * the lid is closed. This leads to interrupts as soon as a little move
33538 * is done.
33539 */
33540 - atomic_inc(&lis3->count);
33541 + atomic_inc_unchecked(&lis3->count);
33542
33543 wake_up_interruptible(&lis3->misc_wait);
33544 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
33545 @@ -550,7 +550,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33546 if (lis3->pm_dev)
33547 pm_runtime_get_sync(lis3->pm_dev);
33548
33549 - atomic_set(&lis3->count, 0);
33550 + atomic_set_unchecked(&lis3->count, 0);
33551 return 0;
33552 }
33553
33554 @@ -583,7 +583,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33555 add_wait_queue(&lis3->misc_wait, &wait);
33556 while (true) {
33557 set_current_state(TASK_INTERRUPTIBLE);
33558 - data = atomic_xchg(&lis3->count, 0);
33559 + data = atomic_xchg_unchecked(&lis3->count, 0);
33560 if (data)
33561 break;
33562
33563 @@ -624,7 +624,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33564 struct lis3lv02d, miscdev);
33565
33566 poll_wait(file, &lis3->misc_wait, wait);
33567 - if (atomic_read(&lis3->count))
33568 + if (atomic_read_unchecked(&lis3->count))
33569 return POLLIN | POLLRDNORM;
33570 return 0;
33571 }
33572 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
33573 index 2b1482a..5d33616 100644
33574 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
33575 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
33576 @@ -266,7 +266,7 @@ struct lis3lv02d {
33577 struct input_polled_dev *idev; /* input device */
33578 struct platform_device *pdev; /* platform device */
33579 struct regulator_bulk_data regulators[2];
33580 - atomic_t count; /* interrupt count after last read */
33581 + atomic_unchecked_t count; /* interrupt count after last read */
33582 union axis_conversion ac; /* hw -> logical axis */
33583 int mapped_btns[3];
33584
33585 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
33586 index 2f30bad..c4c13d0 100644
33587 --- a/drivers/misc/sgi-gru/gruhandles.c
33588 +++ b/drivers/misc/sgi-gru/gruhandles.c
33589 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
33590 unsigned long nsec;
33591
33592 nsec = CLKS2NSEC(clks);
33593 - atomic_long_inc(&mcs_op_statistics[op].count);
33594 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
33595 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33596 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33597 if (mcs_op_statistics[op].max < nsec)
33598 mcs_op_statistics[op].max = nsec;
33599 }
33600 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
33601 index 7768b87..f8aac38 100644
33602 --- a/drivers/misc/sgi-gru/gruprocfs.c
33603 +++ b/drivers/misc/sgi-gru/gruprocfs.c
33604 @@ -32,9 +32,9 @@
33605
33606 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33607
33608 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33609 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33610 {
33611 - unsigned long val = atomic_long_read(v);
33612 + unsigned long val = atomic_long_read_unchecked(v);
33613
33614 seq_printf(s, "%16lu %s\n", val, id);
33615 }
33616 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
33617
33618 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33619 for (op = 0; op < mcsop_last; op++) {
33620 - count = atomic_long_read(&mcs_op_statistics[op].count);
33621 - total = atomic_long_read(&mcs_op_statistics[op].total);
33622 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33623 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33624 max = mcs_op_statistics[op].max;
33625 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33626 count ? total / count : 0, max);
33627 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
33628 index 5c3ce24..4915ccb 100644
33629 --- a/drivers/misc/sgi-gru/grutables.h
33630 +++ b/drivers/misc/sgi-gru/grutables.h
33631 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33632 * GRU statistics.
33633 */
33634 struct gru_stats_s {
33635 - atomic_long_t vdata_alloc;
33636 - atomic_long_t vdata_free;
33637 - atomic_long_t gts_alloc;
33638 - atomic_long_t gts_free;
33639 - atomic_long_t gms_alloc;
33640 - atomic_long_t gms_free;
33641 - atomic_long_t gts_double_allocate;
33642 - atomic_long_t assign_context;
33643 - atomic_long_t assign_context_failed;
33644 - atomic_long_t free_context;
33645 - atomic_long_t load_user_context;
33646 - atomic_long_t load_kernel_context;
33647 - atomic_long_t lock_kernel_context;
33648 - atomic_long_t unlock_kernel_context;
33649 - atomic_long_t steal_user_context;
33650 - atomic_long_t steal_kernel_context;
33651 - atomic_long_t steal_context_failed;
33652 - atomic_long_t nopfn;
33653 - atomic_long_t asid_new;
33654 - atomic_long_t asid_next;
33655 - atomic_long_t asid_wrap;
33656 - atomic_long_t asid_reuse;
33657 - atomic_long_t intr;
33658 - atomic_long_t intr_cbr;
33659 - atomic_long_t intr_tfh;
33660 - atomic_long_t intr_spurious;
33661 - atomic_long_t intr_mm_lock_failed;
33662 - atomic_long_t call_os;
33663 - atomic_long_t call_os_wait_queue;
33664 - atomic_long_t user_flush_tlb;
33665 - atomic_long_t user_unload_context;
33666 - atomic_long_t user_exception;
33667 - atomic_long_t set_context_option;
33668 - atomic_long_t check_context_retarget_intr;
33669 - atomic_long_t check_context_unload;
33670 - atomic_long_t tlb_dropin;
33671 - atomic_long_t tlb_preload_page;
33672 - atomic_long_t tlb_dropin_fail_no_asid;
33673 - atomic_long_t tlb_dropin_fail_upm;
33674 - atomic_long_t tlb_dropin_fail_invalid;
33675 - atomic_long_t tlb_dropin_fail_range_active;
33676 - atomic_long_t tlb_dropin_fail_idle;
33677 - atomic_long_t tlb_dropin_fail_fmm;
33678 - atomic_long_t tlb_dropin_fail_no_exception;
33679 - atomic_long_t tfh_stale_on_fault;
33680 - atomic_long_t mmu_invalidate_range;
33681 - atomic_long_t mmu_invalidate_page;
33682 - atomic_long_t flush_tlb;
33683 - atomic_long_t flush_tlb_gru;
33684 - atomic_long_t flush_tlb_gru_tgh;
33685 - atomic_long_t flush_tlb_gru_zero_asid;
33686 + atomic_long_unchecked_t vdata_alloc;
33687 + atomic_long_unchecked_t vdata_free;
33688 + atomic_long_unchecked_t gts_alloc;
33689 + atomic_long_unchecked_t gts_free;
33690 + atomic_long_unchecked_t gms_alloc;
33691 + atomic_long_unchecked_t gms_free;
33692 + atomic_long_unchecked_t gts_double_allocate;
33693 + atomic_long_unchecked_t assign_context;
33694 + atomic_long_unchecked_t assign_context_failed;
33695 + atomic_long_unchecked_t free_context;
33696 + atomic_long_unchecked_t load_user_context;
33697 + atomic_long_unchecked_t load_kernel_context;
33698 + atomic_long_unchecked_t lock_kernel_context;
33699 + atomic_long_unchecked_t unlock_kernel_context;
33700 + atomic_long_unchecked_t steal_user_context;
33701 + atomic_long_unchecked_t steal_kernel_context;
33702 + atomic_long_unchecked_t steal_context_failed;
33703 + atomic_long_unchecked_t nopfn;
33704 + atomic_long_unchecked_t asid_new;
33705 + atomic_long_unchecked_t asid_next;
33706 + atomic_long_unchecked_t asid_wrap;
33707 + atomic_long_unchecked_t asid_reuse;
33708 + atomic_long_unchecked_t intr;
33709 + atomic_long_unchecked_t intr_cbr;
33710 + atomic_long_unchecked_t intr_tfh;
33711 + atomic_long_unchecked_t intr_spurious;
33712 + atomic_long_unchecked_t intr_mm_lock_failed;
33713 + atomic_long_unchecked_t call_os;
33714 + atomic_long_unchecked_t call_os_wait_queue;
33715 + atomic_long_unchecked_t user_flush_tlb;
33716 + atomic_long_unchecked_t user_unload_context;
33717 + atomic_long_unchecked_t user_exception;
33718 + atomic_long_unchecked_t set_context_option;
33719 + atomic_long_unchecked_t check_context_retarget_intr;
33720 + atomic_long_unchecked_t check_context_unload;
33721 + atomic_long_unchecked_t tlb_dropin;
33722 + atomic_long_unchecked_t tlb_preload_page;
33723 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33724 + atomic_long_unchecked_t tlb_dropin_fail_upm;
33725 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
33726 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
33727 + atomic_long_unchecked_t tlb_dropin_fail_idle;
33728 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
33729 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33730 + atomic_long_unchecked_t tfh_stale_on_fault;
33731 + atomic_long_unchecked_t mmu_invalidate_range;
33732 + atomic_long_unchecked_t mmu_invalidate_page;
33733 + atomic_long_unchecked_t flush_tlb;
33734 + atomic_long_unchecked_t flush_tlb_gru;
33735 + atomic_long_unchecked_t flush_tlb_gru_tgh;
33736 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33737
33738 - atomic_long_t copy_gpa;
33739 - atomic_long_t read_gpa;
33740 + atomic_long_unchecked_t copy_gpa;
33741 + atomic_long_unchecked_t read_gpa;
33742
33743 - atomic_long_t mesq_receive;
33744 - atomic_long_t mesq_receive_none;
33745 - atomic_long_t mesq_send;
33746 - atomic_long_t mesq_send_failed;
33747 - atomic_long_t mesq_noop;
33748 - atomic_long_t mesq_send_unexpected_error;
33749 - atomic_long_t mesq_send_lb_overflow;
33750 - atomic_long_t mesq_send_qlimit_reached;
33751 - atomic_long_t mesq_send_amo_nacked;
33752 - atomic_long_t mesq_send_put_nacked;
33753 - atomic_long_t mesq_page_overflow;
33754 - atomic_long_t mesq_qf_locked;
33755 - atomic_long_t mesq_qf_noop_not_full;
33756 - atomic_long_t mesq_qf_switch_head_failed;
33757 - atomic_long_t mesq_qf_unexpected_error;
33758 - atomic_long_t mesq_noop_unexpected_error;
33759 - atomic_long_t mesq_noop_lb_overflow;
33760 - atomic_long_t mesq_noop_qlimit_reached;
33761 - atomic_long_t mesq_noop_amo_nacked;
33762 - atomic_long_t mesq_noop_put_nacked;
33763 - atomic_long_t mesq_noop_page_overflow;
33764 + atomic_long_unchecked_t mesq_receive;
33765 + atomic_long_unchecked_t mesq_receive_none;
33766 + atomic_long_unchecked_t mesq_send;
33767 + atomic_long_unchecked_t mesq_send_failed;
33768 + atomic_long_unchecked_t mesq_noop;
33769 + atomic_long_unchecked_t mesq_send_unexpected_error;
33770 + atomic_long_unchecked_t mesq_send_lb_overflow;
33771 + atomic_long_unchecked_t mesq_send_qlimit_reached;
33772 + atomic_long_unchecked_t mesq_send_amo_nacked;
33773 + atomic_long_unchecked_t mesq_send_put_nacked;
33774 + atomic_long_unchecked_t mesq_page_overflow;
33775 + atomic_long_unchecked_t mesq_qf_locked;
33776 + atomic_long_unchecked_t mesq_qf_noop_not_full;
33777 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
33778 + atomic_long_unchecked_t mesq_qf_unexpected_error;
33779 + atomic_long_unchecked_t mesq_noop_unexpected_error;
33780 + atomic_long_unchecked_t mesq_noop_lb_overflow;
33781 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
33782 + atomic_long_unchecked_t mesq_noop_amo_nacked;
33783 + atomic_long_unchecked_t mesq_noop_put_nacked;
33784 + atomic_long_unchecked_t mesq_noop_page_overflow;
33785
33786 };
33787
33788 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
33789 tghop_invalidate, mcsop_last};
33790
33791 struct mcs_op_statistic {
33792 - atomic_long_t count;
33793 - atomic_long_t total;
33794 + atomic_long_unchecked_t count;
33795 + atomic_long_unchecked_t total;
33796 unsigned long max;
33797 };
33798
33799 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
33800
33801 #define STAT(id) do { \
33802 if (gru_options & OPT_STATS) \
33803 - atomic_long_inc(&gru_stats.id); \
33804 + atomic_long_inc_unchecked(&gru_stats.id); \
33805 } while (0)
33806
33807 #ifdef CONFIG_SGI_GRU_DEBUG
33808 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
33809 index 851b2f2..a4ec097 100644
33810 --- a/drivers/misc/sgi-xp/xp.h
33811 +++ b/drivers/misc/sgi-xp/xp.h
33812 @@ -289,7 +289,7 @@ struct xpc_interface {
33813 xpc_notify_func, void *);
33814 void (*received) (short, int, void *);
33815 enum xp_retval (*partid_to_nasids) (short, void *);
33816 -};
33817 +} __no_const;
33818
33819 extern struct xpc_interface xpc_interface;
33820
33821 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
33822 index b94d5f7..7f494c5 100644
33823 --- a/drivers/misc/sgi-xp/xpc.h
33824 +++ b/drivers/misc/sgi-xp/xpc.h
33825 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
33826 void (*received_payload) (struct xpc_channel *, void *);
33827 void (*notify_senders_of_disconnect) (struct xpc_channel *);
33828 };
33829 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
33830
33831 /* struct xpc_partition act_state values (for XPC HB) */
33832
33833 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
33834 /* found in xpc_main.c */
33835 extern struct device *xpc_part;
33836 extern struct device *xpc_chan;
33837 -extern struct xpc_arch_operations xpc_arch_ops;
33838 +extern xpc_arch_operations_no_const xpc_arch_ops;
33839 extern int xpc_disengage_timelimit;
33840 extern int xpc_disengage_timedout;
33841 extern int xpc_activate_IRQ_rcvd;
33842 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
33843 index 8d082b4..aa749ae 100644
33844 --- a/drivers/misc/sgi-xp/xpc_main.c
33845 +++ b/drivers/misc/sgi-xp/xpc_main.c
33846 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
33847 .notifier_call = xpc_system_die,
33848 };
33849
33850 -struct xpc_arch_operations xpc_arch_ops;
33851 +xpc_arch_operations_no_const xpc_arch_ops;
33852
33853 /*
33854 * Timer function to enforce the timelimit on the partition disengage.
33855 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
33856 index 6878a94..fe5c5f1 100644
33857 --- a/drivers/mmc/host/sdhci-pci.c
33858 +++ b/drivers/mmc/host/sdhci-pci.c
33859 @@ -673,7 +673,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
33860 .probe = via_probe,
33861 };
33862
33863 -static const struct pci_device_id pci_ids[] __devinitdata = {
33864 +static const struct pci_device_id pci_ids[] __devinitconst = {
33865 {
33866 .vendor = PCI_VENDOR_ID_RICOH,
33867 .device = PCI_DEVICE_ID_RICOH_R5C822,
33868 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
33869 index e9fad91..0a7a16a 100644
33870 --- a/drivers/mtd/devices/doc2000.c
33871 +++ b/drivers/mtd/devices/doc2000.c
33872 @@ -773,7 +773,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
33873
33874 /* The ECC will not be calculated correctly if less than 512 is written */
33875 /* DBB-
33876 - if (len != 0x200 && eccbuf)
33877 + if (len != 0x200)
33878 printk(KERN_WARNING
33879 "ECC needs a full sector write (adr: %lx size %lx)\n",
33880 (long) to, (long) len);
33881 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
33882 index a3f7a27..234016e 100644
33883 --- a/drivers/mtd/devices/doc2001.c
33884 +++ b/drivers/mtd/devices/doc2001.c
33885 @@ -392,7 +392,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
33886 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
33887
33888 /* Don't allow read past end of device */
33889 - if (from >= this->totlen)
33890 + if (from >= this->totlen || !len)
33891 return -EINVAL;
33892
33893 /* Don't allow a single read to cross a 512-byte block boundary */
33894 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
33895 index 3984d48..28aa897 100644
33896 --- a/drivers/mtd/nand/denali.c
33897 +++ b/drivers/mtd/nand/denali.c
33898 @@ -26,6 +26,7 @@
33899 #include <linux/pci.h>
33900 #include <linux/mtd/mtd.h>
33901 #include <linux/module.h>
33902 +#include <linux/slab.h>
33903
33904 #include "denali.h"
33905
33906 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
33907 index ac40925..483b753 100644
33908 --- a/drivers/mtd/nftlmount.c
33909 +++ b/drivers/mtd/nftlmount.c
33910 @@ -24,6 +24,7 @@
33911 #include <asm/errno.h>
33912 #include <linux/delay.h>
33913 #include <linux/slab.h>
33914 +#include <linux/sched.h>
33915 #include <linux/mtd/mtd.h>
33916 #include <linux/mtd/nand.h>
33917 #include <linux/mtd/nftl.h>
33918 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
33919 index 6c3fb5a..c542a81 100644
33920 --- a/drivers/mtd/ubi/build.c
33921 +++ b/drivers/mtd/ubi/build.c
33922 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
33923 static int __init bytes_str_to_int(const char *str)
33924 {
33925 char *endp;
33926 - unsigned long result;
33927 + unsigned long result, scale = 1;
33928
33929 result = simple_strtoul(str, &endp, 0);
33930 if (str == endp || result >= INT_MAX) {
33931 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
33932
33933 switch (*endp) {
33934 case 'G':
33935 - result *= 1024;
33936 + scale *= 1024;
33937 case 'M':
33938 - result *= 1024;
33939 + scale *= 1024;
33940 case 'K':
33941 - result *= 1024;
33942 + scale *= 1024;
33943 if (endp[1] == 'i' && endp[2] == 'B')
33944 endp += 2;
33945 case '\0':
33946 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
33947 return -EINVAL;
33948 }
33949
33950 - return result;
33951 + if ((intoverflow_t)result*scale >= INT_MAX) {
33952 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
33953 + str);
33954 + return -EINVAL;
33955 + }
33956 +
33957 + return result*scale;
33958 }
33959
33960 /**
33961 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
33962 index 1feae59..c2a61d2 100644
33963 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
33964 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
33965 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
33966 */
33967
33968 #define ATL2_PARAM(X, desc) \
33969 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33970 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33971 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
33972 MODULE_PARM_DESC(X, desc);
33973 #else
33974 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33975 index 9a517c2..a50cfcb 100644
33976 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33977 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33978 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
33979
33980 int (*wait_comp)(struct bnx2x *bp,
33981 struct bnx2x_rx_mode_ramrod_params *p);
33982 -};
33983 +} __no_const;
33984
33985 /********************** Set multicast group ***********************************/
33986
33987 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
33988 index 94b4bd0..73c02de 100644
33989 --- a/drivers/net/ethernet/broadcom/tg3.h
33990 +++ b/drivers/net/ethernet/broadcom/tg3.h
33991 @@ -134,6 +134,7 @@
33992 #define CHIPREV_ID_5750_A0 0x4000
33993 #define CHIPREV_ID_5750_A1 0x4001
33994 #define CHIPREV_ID_5750_A3 0x4003
33995 +#define CHIPREV_ID_5750_C1 0x4201
33996 #define CHIPREV_ID_5750_C2 0x4202
33997 #define CHIPREV_ID_5752_A0_HW 0x5000
33998 #define CHIPREV_ID_5752_A0 0x6000
33999 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34000 index c5f5479..2e8c260 100644
34001 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34002 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34003 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34004 */
34005 struct l2t_skb_cb {
34006 arp_failure_handler_func arp_failure_handler;
34007 -};
34008 +} __no_const;
34009
34010 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34011
34012 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34013 index 871bcaa..4043505 100644
34014 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34015 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34016 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34017 for (i=0; i<ETH_ALEN; i++) {
34018 tmp.addr[i] = dev->dev_addr[i];
34019 }
34020 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34021 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34022 break;
34023
34024 case DE4X5_SET_HWADDR: /* Set the hardware address */
34025 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34026 spin_lock_irqsave(&lp->lock, flags);
34027 memcpy(&statbuf, &lp->pktStats, ioc->len);
34028 spin_unlock_irqrestore(&lp->lock, flags);
34029 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34030 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34031 return -EFAULT;
34032 break;
34033 }
34034 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34035 index 14d5b61..1398636 100644
34036 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34037 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34038 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34039 {NULL}};
34040
34041
34042 -static const char *block_name[] __devinitdata = {
34043 +static const char *block_name[] __devinitconst = {
34044 "21140 non-MII",
34045 "21140 MII PHY",
34046 "21142 Serial PHY",
34047 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34048 index 4d01219..b58d26d 100644
34049 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34050 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34051 @@ -236,7 +236,7 @@ struct pci_id_info {
34052 int drv_flags; /* Driver use, intended as capability flags. */
34053 };
34054
34055 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34056 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34057 { /* Sometime a Level-One switch card. */
34058 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34059 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34060 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34061 index dcd7f7a..ecb7fb3 100644
34062 --- a/drivers/net/ethernet/dlink/sundance.c
34063 +++ b/drivers/net/ethernet/dlink/sundance.c
34064 @@ -218,7 +218,7 @@ enum {
34065 struct pci_id_info {
34066 const char *name;
34067 };
34068 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34069 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34070 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34071 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34072 {"D-Link DFE-580TX 4 port Server Adapter"},
34073 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34074 index bf266a0..e024af7 100644
34075 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34076 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34077 @@ -397,7 +397,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34078
34079 if (wrapped)
34080 newacc += 65536;
34081 - ACCESS_ONCE(*acc) = newacc;
34082 + ACCESS_ONCE_RW(*acc) = newacc;
34083 }
34084
34085 void be_parse_stats(struct be_adapter *adapter)
34086 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34087 index fb5579a..debdffa 100644
34088 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34089 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34090 @@ -30,6 +30,8 @@
34091 #include <linux/netdevice.h>
34092 #include <linux/phy.h>
34093 #include <linux/platform_device.h>
34094 +#include <linux/interrupt.h>
34095 +#include <linux/irqreturn.h>
34096 #include <net/ip.h>
34097
34098 #include "ftgmac100.h"
34099 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34100 index a127cb2..0d043cd 100644
34101 --- a/drivers/net/ethernet/faraday/ftmac100.c
34102 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34103 @@ -30,6 +30,8 @@
34104 #include <linux/module.h>
34105 #include <linux/netdevice.h>
34106 #include <linux/platform_device.h>
34107 +#include <linux/interrupt.h>
34108 +#include <linux/irqreturn.h>
34109
34110 #include "ftmac100.h"
34111
34112 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34113 index 61d2bdd..7f1154a 100644
34114 --- a/drivers/net/ethernet/fealnx.c
34115 +++ b/drivers/net/ethernet/fealnx.c
34116 @@ -150,7 +150,7 @@ struct chip_info {
34117 int flags;
34118 };
34119
34120 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34121 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34122 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34123 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34124 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34125 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34126 index e1159e5..e18684d 100644
34127 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34128 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34129 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34130 {
34131 struct e1000_hw *hw = &adapter->hw;
34132 struct e1000_mac_info *mac = &hw->mac;
34133 - struct e1000_mac_operations *func = &mac->ops;
34134 + e1000_mac_operations_no_const *func = &mac->ops;
34135
34136 /* Set media type */
34137 switch (adapter->pdev->device) {
34138 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34139 index a3e65fd..f451444 100644
34140 --- a/drivers/net/ethernet/intel/e1000e/82571.c
34141 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
34142 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34143 {
34144 struct e1000_hw *hw = &adapter->hw;
34145 struct e1000_mac_info *mac = &hw->mac;
34146 - struct e1000_mac_operations *func = &mac->ops;
34147 + e1000_mac_operations_no_const *func = &mac->ops;
34148 u32 swsm = 0;
34149 u32 swsm2 = 0;
34150 bool force_clear_smbi = false;
34151 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34152 index 2967039..ca8c40c 100644
34153 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34154 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34155 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34156 void (*write_vfta)(struct e1000_hw *, u32, u32);
34157 s32 (*read_mac_addr)(struct e1000_hw *);
34158 };
34159 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34160
34161 /*
34162 * When to use various PHY register access functions:
34163 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
34164 void (*power_up)(struct e1000_hw *);
34165 void (*power_down)(struct e1000_hw *);
34166 };
34167 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34168
34169 /* Function pointers for the NVM. */
34170 struct e1000_nvm_operations {
34171 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34172 s32 (*validate)(struct e1000_hw *);
34173 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34174 };
34175 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34176
34177 struct e1000_mac_info {
34178 - struct e1000_mac_operations ops;
34179 + e1000_mac_operations_no_const ops;
34180 u8 addr[ETH_ALEN];
34181 u8 perm_addr[ETH_ALEN];
34182
34183 @@ -872,7 +875,7 @@ struct e1000_mac_info {
34184 };
34185
34186 struct e1000_phy_info {
34187 - struct e1000_phy_operations ops;
34188 + e1000_phy_operations_no_const ops;
34189
34190 enum e1000_phy_type type;
34191
34192 @@ -906,7 +909,7 @@ struct e1000_phy_info {
34193 };
34194
34195 struct e1000_nvm_info {
34196 - struct e1000_nvm_operations ops;
34197 + e1000_nvm_operations_no_const ops;
34198
34199 enum e1000_nvm_type type;
34200 enum e1000_nvm_override override;
34201 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34202 index 4519a13..f97fcd0 100644
34203 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34204 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34205 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34206 s32 (*read_mac_addr)(struct e1000_hw *);
34207 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34208 };
34209 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34210
34211 struct e1000_phy_operations {
34212 s32 (*acquire)(struct e1000_hw *);
34213 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34214 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34215 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34216 };
34217 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34218
34219 struct e1000_nvm_operations {
34220 s32 (*acquire)(struct e1000_hw *);
34221 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34222 s32 (*update)(struct e1000_hw *);
34223 s32 (*validate)(struct e1000_hw *);
34224 };
34225 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34226
34227 struct e1000_info {
34228 s32 (*get_invariants)(struct e1000_hw *);
34229 @@ -350,7 +353,7 @@ struct e1000_info {
34230 extern const struct e1000_info e1000_82575_info;
34231
34232 struct e1000_mac_info {
34233 - struct e1000_mac_operations ops;
34234 + e1000_mac_operations_no_const ops;
34235
34236 u8 addr[6];
34237 u8 perm_addr[6];
34238 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34239 };
34240
34241 struct e1000_phy_info {
34242 - struct e1000_phy_operations ops;
34243 + e1000_phy_operations_no_const ops;
34244
34245 enum e1000_phy_type type;
34246
34247 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34248 };
34249
34250 struct e1000_nvm_info {
34251 - struct e1000_nvm_operations ops;
34252 + e1000_nvm_operations_no_const ops;
34253 enum e1000_nvm_type type;
34254 enum e1000_nvm_override override;
34255
34256 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34257 s32 (*check_for_ack)(struct e1000_hw *, u16);
34258 s32 (*check_for_rst)(struct e1000_hw *, u16);
34259 };
34260 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34261
34262 struct e1000_mbx_stats {
34263 u32 msgs_tx;
34264 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34265 };
34266
34267 struct e1000_mbx_info {
34268 - struct e1000_mbx_operations ops;
34269 + e1000_mbx_operations_no_const ops;
34270 struct e1000_mbx_stats stats;
34271 u32 timeout;
34272 u32 usec_delay;
34273 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34274 index d7ed58f..64cde36 100644
34275 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34276 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34277 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34278 s32 (*read_mac_addr)(struct e1000_hw *);
34279 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34280 };
34281 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34282
34283 struct e1000_mac_info {
34284 - struct e1000_mac_operations ops;
34285 + e1000_mac_operations_no_const ops;
34286 u8 addr[6];
34287 u8 perm_addr[6];
34288
34289 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34290 s32 (*check_for_ack)(struct e1000_hw *);
34291 s32 (*check_for_rst)(struct e1000_hw *);
34292 };
34293 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34294
34295 struct e1000_mbx_stats {
34296 u32 msgs_tx;
34297 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34298 };
34299
34300 struct e1000_mbx_info {
34301 - struct e1000_mbx_operations ops;
34302 + e1000_mbx_operations_no_const ops;
34303 struct e1000_mbx_stats stats;
34304 u32 timeout;
34305 u32 usec_delay;
34306 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34307 index 6c5cca8..de8ef63 100644
34308 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34309 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34310 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
34311 s32 (*update_checksum)(struct ixgbe_hw *);
34312 u16 (*calc_checksum)(struct ixgbe_hw *);
34313 };
34314 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34315
34316 struct ixgbe_mac_operations {
34317 s32 (*init_hw)(struct ixgbe_hw *);
34318 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
34319 /* Manageability interface */
34320 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34321 };
34322 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34323
34324 struct ixgbe_phy_operations {
34325 s32 (*identify)(struct ixgbe_hw *);
34326 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
34327 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34328 s32 (*check_overtemp)(struct ixgbe_hw *);
34329 };
34330 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34331
34332 struct ixgbe_eeprom_info {
34333 - struct ixgbe_eeprom_operations ops;
34334 + ixgbe_eeprom_operations_no_const ops;
34335 enum ixgbe_eeprom_type type;
34336 u32 semaphore_delay;
34337 u16 word_size;
34338 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
34339
34340 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34341 struct ixgbe_mac_info {
34342 - struct ixgbe_mac_operations ops;
34343 + ixgbe_mac_operations_no_const ops;
34344 enum ixgbe_mac_type type;
34345 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34346 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34347 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
34348 };
34349
34350 struct ixgbe_phy_info {
34351 - struct ixgbe_phy_operations ops;
34352 + ixgbe_phy_operations_no_const ops;
34353 struct mdio_if_info mdio;
34354 enum ixgbe_phy_type type;
34355 u32 id;
34356 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
34357 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34358 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34359 };
34360 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34361
34362 struct ixgbe_mbx_stats {
34363 u32 msgs_tx;
34364 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
34365 };
34366
34367 struct ixgbe_mbx_info {
34368 - struct ixgbe_mbx_operations ops;
34369 + ixgbe_mbx_operations_no_const ops;
34370 struct ixgbe_mbx_stats stats;
34371 u32 timeout;
34372 u32 usec_delay;
34373 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34374 index 10306b4..28df758 100644
34375 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34376 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34377 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34378 s32 (*clear_vfta)(struct ixgbe_hw *);
34379 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34380 };
34381 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34382
34383 enum ixgbe_mac_type {
34384 ixgbe_mac_unknown = 0,
34385 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34386 };
34387
34388 struct ixgbe_mac_info {
34389 - struct ixgbe_mac_operations ops;
34390 + ixgbe_mac_operations_no_const ops;
34391 u8 addr[6];
34392 u8 perm_addr[6];
34393
34394 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34395 s32 (*check_for_ack)(struct ixgbe_hw *);
34396 s32 (*check_for_rst)(struct ixgbe_hw *);
34397 };
34398 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34399
34400 struct ixgbe_mbx_stats {
34401 u32 msgs_tx;
34402 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34403 };
34404
34405 struct ixgbe_mbx_info {
34406 - struct ixgbe_mbx_operations ops;
34407 + ixgbe_mbx_operations_no_const ops;
34408 struct ixgbe_mbx_stats stats;
34409 u32 timeout;
34410 u32 udelay;
34411 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34412 index 94bbc85..78c12e6 100644
34413 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34414 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34415 @@ -40,6 +40,7 @@
34416 #include <linux/dma-mapping.h>
34417 #include <linux/slab.h>
34418 #include <linux/io-mapping.h>
34419 +#include <linux/sched.h>
34420
34421 #include <linux/mlx4/device.h>
34422 #include <linux/mlx4/doorbell.h>
34423 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34424 index 5046a64..71ca936 100644
34425 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34426 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34427 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34428 void (*link_down)(struct __vxge_hw_device *devh);
34429 void (*crit_err)(struct __vxge_hw_device *devh,
34430 enum vxge_hw_event type, u64 ext_data);
34431 -};
34432 +} __no_const;
34433
34434 /*
34435 * struct __vxge_hw_blockpool_entry - Block private data structure
34436 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34437 index 4a518a3..936b334 100644
34438 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34439 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34440 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34441 struct vxge_hw_mempool_dma *dma_object,
34442 u32 index,
34443 u32 is_last);
34444 -};
34445 +} __no_const;
34446
34447 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34448 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34449 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34450 index c8f47f1..5da9840 100644
34451 --- a/drivers/net/ethernet/realtek/r8169.c
34452 +++ b/drivers/net/ethernet/realtek/r8169.c
34453 @@ -698,17 +698,17 @@ struct rtl8169_private {
34454 struct mdio_ops {
34455 void (*write)(void __iomem *, int, int);
34456 int (*read)(void __iomem *, int);
34457 - } mdio_ops;
34458 + } __no_const mdio_ops;
34459
34460 struct pll_power_ops {
34461 void (*down)(struct rtl8169_private *);
34462 void (*up)(struct rtl8169_private *);
34463 - } pll_power_ops;
34464 + } __no_const pll_power_ops;
34465
34466 struct jumbo_ops {
34467 void (*enable)(struct rtl8169_private *);
34468 void (*disable)(struct rtl8169_private *);
34469 - } jumbo_ops;
34470 + } __no_const jumbo_ops;
34471
34472 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34473 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34474 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34475 index 1b4658c..a30dabb 100644
34476 --- a/drivers/net/ethernet/sis/sis190.c
34477 +++ b/drivers/net/ethernet/sis/sis190.c
34478 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34479 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34480 struct net_device *dev)
34481 {
34482 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34483 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34484 struct sis190_private *tp = netdev_priv(dev);
34485 struct pci_dev *isa_bridge;
34486 u8 reg, tmp8;
34487 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34488 index 41e6b33..8e89b0f 100644
34489 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34490 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34491 @@ -139,8 +139,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
34492
34493 writel(value, ioaddr + MMC_CNTRL);
34494
34495 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34496 - MMC_CNTRL, value);
34497 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34498 +// MMC_CNTRL, value);
34499 }
34500
34501 /* To mask all all interrupts.*/
34502 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
34503 index edfa15d..002bfa9 100644
34504 --- a/drivers/net/ppp/ppp_generic.c
34505 +++ b/drivers/net/ppp/ppp_generic.c
34506 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34507 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
34508 struct ppp_stats stats;
34509 struct ppp_comp_stats cstats;
34510 - char *vers;
34511
34512 switch (cmd) {
34513 case SIOCGPPPSTATS:
34514 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34515 break;
34516
34517 case SIOCGPPPVER:
34518 - vers = PPP_VERSION;
34519 - if (copy_to_user(addr, vers, strlen(vers) + 1))
34520 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
34521 break;
34522 err = 0;
34523 break;
34524 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
34525 index 515f122..41dd273 100644
34526 --- a/drivers/net/tokenring/abyss.c
34527 +++ b/drivers/net/tokenring/abyss.c
34528 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
34529
34530 static int __init abyss_init (void)
34531 {
34532 - abyss_netdev_ops = tms380tr_netdev_ops;
34533 + pax_open_kernel();
34534 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34535
34536 - abyss_netdev_ops.ndo_open = abyss_open;
34537 - abyss_netdev_ops.ndo_stop = abyss_close;
34538 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
34539 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
34540 + pax_close_kernel();
34541
34542 return pci_register_driver(&abyss_driver);
34543 }
34544 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
34545 index 6153cfd..cf69c1c 100644
34546 --- a/drivers/net/tokenring/madgemc.c
34547 +++ b/drivers/net/tokenring/madgemc.c
34548 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
34549
34550 static int __init madgemc_init (void)
34551 {
34552 - madgemc_netdev_ops = tms380tr_netdev_ops;
34553 - madgemc_netdev_ops.ndo_open = madgemc_open;
34554 - madgemc_netdev_ops.ndo_stop = madgemc_close;
34555 + pax_open_kernel();
34556 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34557 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
34558 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
34559 + pax_close_kernel();
34560
34561 return mca_register_driver (&madgemc_driver);
34562 }
34563 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
34564 index 8d362e6..f91cc52 100644
34565 --- a/drivers/net/tokenring/proteon.c
34566 +++ b/drivers/net/tokenring/proteon.c
34567 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
34568 struct platform_device *pdev;
34569 int i, num = 0, err = 0;
34570
34571 - proteon_netdev_ops = tms380tr_netdev_ops;
34572 - proteon_netdev_ops.ndo_open = proteon_open;
34573 - proteon_netdev_ops.ndo_stop = tms380tr_close;
34574 + pax_open_kernel();
34575 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34576 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
34577 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
34578 + pax_close_kernel();
34579
34580 err = platform_driver_register(&proteon_driver);
34581 if (err)
34582 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
34583 index 46db5c5..37c1536 100644
34584 --- a/drivers/net/tokenring/skisa.c
34585 +++ b/drivers/net/tokenring/skisa.c
34586 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
34587 struct platform_device *pdev;
34588 int i, num = 0, err = 0;
34589
34590 - sk_isa_netdev_ops = tms380tr_netdev_ops;
34591 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
34592 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34593 + pax_open_kernel();
34594 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34595 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
34596 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34597 + pax_close_kernel();
34598
34599 err = platform_driver_register(&sk_isa_driver);
34600 if (err)
34601 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
34602 index 304fe78..db112fa 100644
34603 --- a/drivers/net/usb/hso.c
34604 +++ b/drivers/net/usb/hso.c
34605 @@ -71,7 +71,7 @@
34606 #include <asm/byteorder.h>
34607 #include <linux/serial_core.h>
34608 #include <linux/serial.h>
34609 -
34610 +#include <asm/local.h>
34611
34612 #define MOD_AUTHOR "Option Wireless"
34613 #define MOD_DESCRIPTION "USB High Speed Option driver"
34614 @@ -257,7 +257,7 @@ struct hso_serial {
34615
34616 /* from usb_serial_port */
34617 struct tty_struct *tty;
34618 - int open_count;
34619 + local_t open_count;
34620 spinlock_t serial_lock;
34621
34622 int (*write_data) (struct hso_serial *serial);
34623 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
34624 struct urb *urb;
34625
34626 urb = serial->rx_urb[0];
34627 - if (serial->open_count > 0) {
34628 + if (local_read(&serial->open_count) > 0) {
34629 count = put_rxbuf_data(urb, serial);
34630 if (count == -1)
34631 return;
34632 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
34633 DUMP1(urb->transfer_buffer, urb->actual_length);
34634
34635 /* Anyone listening? */
34636 - if (serial->open_count == 0)
34637 + if (local_read(&serial->open_count) == 0)
34638 return;
34639
34640 if (status == 0) {
34641 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34642 spin_unlock_irq(&serial->serial_lock);
34643
34644 /* check for port already opened, if not set the termios */
34645 - serial->open_count++;
34646 - if (serial->open_count == 1) {
34647 + if (local_inc_return(&serial->open_count) == 1) {
34648 serial->rx_state = RX_IDLE;
34649 /* Force default termio settings */
34650 _hso_serial_set_termios(tty, NULL);
34651 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34652 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
34653 if (result) {
34654 hso_stop_serial_device(serial->parent);
34655 - serial->open_count--;
34656 + local_dec(&serial->open_count);
34657 kref_put(&serial->parent->ref, hso_serial_ref_free);
34658 }
34659 } else {
34660 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
34661
34662 /* reset the rts and dtr */
34663 /* do the actual close */
34664 - serial->open_count--;
34665 + local_dec(&serial->open_count);
34666
34667 - if (serial->open_count <= 0) {
34668 - serial->open_count = 0;
34669 + if (local_read(&serial->open_count) <= 0) {
34670 + local_set(&serial->open_count, 0);
34671 spin_lock_irq(&serial->serial_lock);
34672 if (serial->tty == tty) {
34673 serial->tty->driver_data = NULL;
34674 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
34675
34676 /* the actual setup */
34677 spin_lock_irqsave(&serial->serial_lock, flags);
34678 - if (serial->open_count)
34679 + if (local_read(&serial->open_count))
34680 _hso_serial_set_termios(tty, old);
34681 else
34682 tty->termios = old;
34683 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
34684 D1("Pending read interrupt on port %d\n", i);
34685 spin_lock(&serial->serial_lock);
34686 if (serial->rx_state == RX_IDLE &&
34687 - serial->open_count > 0) {
34688 + local_read(&serial->open_count) > 0) {
34689 /* Setup and send a ctrl req read on
34690 * port i */
34691 if (!serial->rx_urb_filled[0]) {
34692 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
34693 /* Start all serial ports */
34694 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
34695 if (serial_table[i] && (serial_table[i]->interface == iface)) {
34696 - if (dev2ser(serial_table[i])->open_count) {
34697 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
34698 result =
34699 hso_start_serial_device(serial_table[i], GFP_NOIO);
34700 hso_kick_transmit(dev2ser(serial_table[i]));
34701 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34702 index e662cbc..8d4a102 100644
34703 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
34704 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34705 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
34706 * Return with error code if any of the queue indices
34707 * is out of range
34708 */
34709 - if (p->ring_index[i] < 0 ||
34710 - p->ring_index[i] >= adapter->num_rx_queues)
34711 + if (p->ring_index[i] >= adapter->num_rx_queues)
34712 return -EINVAL;
34713 }
34714
34715 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
34716 index 0f9ee46..e2d6e65 100644
34717 --- a/drivers/net/wireless/ath/ath.h
34718 +++ b/drivers/net/wireless/ath/ath.h
34719 @@ -119,6 +119,7 @@ struct ath_ops {
34720 void (*write_flush) (void *);
34721 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
34722 };
34723 +typedef struct ath_ops __no_const ath_ops_no_const;
34724
34725 struct ath_common;
34726 struct ath_bus_ops;
34727 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34728 index b592016..fe47870 100644
34729 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34730 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34731 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34732 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
34733 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
34734
34735 - ACCESS_ONCE(ads->ds_link) = i->link;
34736 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
34737 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
34738 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
34739
34740 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
34741 ctl6 = SM(i->keytype, AR_EncrType);
34742 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34743
34744 if ((i->is_first || i->is_last) &&
34745 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
34746 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
34747 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
34748 | set11nTries(i->rates, 1)
34749 | set11nTries(i->rates, 2)
34750 | set11nTries(i->rates, 3)
34751 | (i->dur_update ? AR_DurUpdateEna : 0)
34752 | SM(0, AR_BurstDur);
34753
34754 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
34755 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
34756 | set11nRate(i->rates, 1)
34757 | set11nRate(i->rates, 2)
34758 | set11nRate(i->rates, 3);
34759 } else {
34760 - ACCESS_ONCE(ads->ds_ctl2) = 0;
34761 - ACCESS_ONCE(ads->ds_ctl3) = 0;
34762 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
34763 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
34764 }
34765
34766 if (!i->is_first) {
34767 - ACCESS_ONCE(ads->ds_ctl0) = 0;
34768 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34769 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34770 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
34771 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34772 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34773 return;
34774 }
34775
34776 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34777 break;
34778 }
34779
34780 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34781 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34782 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34783 | SM(i->txpower, AR_XmitPower)
34784 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34785 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34786 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
34787 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
34788
34789 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34790 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34791 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34792 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34793
34794 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
34795 return;
34796
34797 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34798 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34799 | set11nPktDurRTSCTS(i->rates, 1);
34800
34801 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34802 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34803 | set11nPktDurRTSCTS(i->rates, 3);
34804
34805 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34806 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34807 | set11nRateFlags(i->rates, 1)
34808 | set11nRateFlags(i->rates, 2)
34809 | set11nRateFlags(i->rates, 3)
34810 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34811 index f5ae3c6..7936af3 100644
34812 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34813 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34814 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34815 (i->qcu << AR_TxQcuNum_S) | 0x17;
34816
34817 checksum += val;
34818 - ACCESS_ONCE(ads->info) = val;
34819 + ACCESS_ONCE_RW(ads->info) = val;
34820
34821 checksum += i->link;
34822 - ACCESS_ONCE(ads->link) = i->link;
34823 + ACCESS_ONCE_RW(ads->link) = i->link;
34824
34825 checksum += i->buf_addr[0];
34826 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
34827 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
34828 checksum += i->buf_addr[1];
34829 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
34830 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
34831 checksum += i->buf_addr[2];
34832 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
34833 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
34834 checksum += i->buf_addr[3];
34835 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
34836 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
34837
34838 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
34839 - ACCESS_ONCE(ads->ctl3) = val;
34840 + ACCESS_ONCE_RW(ads->ctl3) = val;
34841 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
34842 - ACCESS_ONCE(ads->ctl5) = val;
34843 + ACCESS_ONCE_RW(ads->ctl5) = val;
34844 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
34845 - ACCESS_ONCE(ads->ctl7) = val;
34846 + ACCESS_ONCE_RW(ads->ctl7) = val;
34847 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
34848 - ACCESS_ONCE(ads->ctl9) = val;
34849 + ACCESS_ONCE_RW(ads->ctl9) = val;
34850
34851 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
34852 - ACCESS_ONCE(ads->ctl10) = checksum;
34853 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
34854
34855 if (i->is_first || i->is_last) {
34856 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
34857 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
34858 | set11nTries(i->rates, 1)
34859 | set11nTries(i->rates, 2)
34860 | set11nTries(i->rates, 3)
34861 | (i->dur_update ? AR_DurUpdateEna : 0)
34862 | SM(0, AR_BurstDur);
34863
34864 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
34865 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
34866 | set11nRate(i->rates, 1)
34867 | set11nRate(i->rates, 2)
34868 | set11nRate(i->rates, 3);
34869 } else {
34870 - ACCESS_ONCE(ads->ctl13) = 0;
34871 - ACCESS_ONCE(ads->ctl14) = 0;
34872 + ACCESS_ONCE_RW(ads->ctl13) = 0;
34873 + ACCESS_ONCE_RW(ads->ctl14) = 0;
34874 }
34875
34876 ads->ctl20 = 0;
34877 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34878
34879 ctl17 = SM(i->keytype, AR_EncrType);
34880 if (!i->is_first) {
34881 - ACCESS_ONCE(ads->ctl11) = 0;
34882 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34883 - ACCESS_ONCE(ads->ctl15) = 0;
34884 - ACCESS_ONCE(ads->ctl16) = 0;
34885 - ACCESS_ONCE(ads->ctl17) = ctl17;
34886 - ACCESS_ONCE(ads->ctl18) = 0;
34887 - ACCESS_ONCE(ads->ctl19) = 0;
34888 + ACCESS_ONCE_RW(ads->ctl11) = 0;
34889 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34890 + ACCESS_ONCE_RW(ads->ctl15) = 0;
34891 + ACCESS_ONCE_RW(ads->ctl16) = 0;
34892 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34893 + ACCESS_ONCE_RW(ads->ctl18) = 0;
34894 + ACCESS_ONCE_RW(ads->ctl19) = 0;
34895 return;
34896 }
34897
34898 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34899 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34900 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34901 | SM(i->txpower, AR_XmitPower)
34902 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34903 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34904 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
34905 ctl12 |= SM(val, AR_PAPRDChainMask);
34906
34907 - ACCESS_ONCE(ads->ctl12) = ctl12;
34908 - ACCESS_ONCE(ads->ctl17) = ctl17;
34909 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
34910 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34911
34912 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34913 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34914 | set11nPktDurRTSCTS(i->rates, 1);
34915
34916 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34917 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34918 | set11nPktDurRTSCTS(i->rates, 3);
34919
34920 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
34921 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
34922 | set11nRateFlags(i->rates, 1)
34923 | set11nRateFlags(i->rates, 2)
34924 | set11nRateFlags(i->rates, 3)
34925 | SM(i->rtscts_rate, AR_RTSCTSRate);
34926
34927 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
34928 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
34929 }
34930
34931 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
34932 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
34933 index 1bd8edf..10c6d30 100644
34934 --- a/drivers/net/wireless/ath/ath9k/hw.h
34935 +++ b/drivers/net/wireless/ath/ath9k/hw.h
34936 @@ -605,7 +605,7 @@ struct ath_hw_private_ops {
34937
34938 /* ANI */
34939 void (*ani_cache_ini_regs)(struct ath_hw *ah);
34940 -};
34941 +} __no_const;
34942
34943 /**
34944 * struct ath_hw_ops - callbacks used by hardware code and driver code
34945 @@ -635,7 +635,7 @@ struct ath_hw_ops {
34946 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
34947 struct ath_hw_antcomb_conf *antconf);
34948
34949 -};
34950 +} __no_const;
34951
34952 struct ath_nf_limits {
34953 s16 max;
34954 @@ -655,7 +655,7 @@ enum ath_cal_list {
34955 #define AH_FASTCC 0x4
34956
34957 struct ath_hw {
34958 - struct ath_ops reg_ops;
34959 + ath_ops_no_const reg_ops;
34960
34961 struct ieee80211_hw *hw;
34962 struct ath_common common;
34963 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34964 index bea8524..c677c06 100644
34965 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34966 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34967 @@ -547,7 +547,7 @@ struct phy_func_ptr {
34968 void (*carrsuppr)(struct brcms_phy *);
34969 s32 (*rxsigpwr)(struct brcms_phy *, s32);
34970 void (*detach)(struct brcms_phy *);
34971 -};
34972 +} __no_const;
34973
34974 struct brcms_phy {
34975 struct brcms_phy_pub pubpi_ro;
34976 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
34977 index 05f2ad1..ae00eea 100644
34978 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
34979 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
34980 @@ -3685,7 +3685,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
34981 */
34982 if (iwl3945_mod_params.disable_hw_scan) {
34983 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
34984 - iwl3945_hw_ops.hw_scan = NULL;
34985 + pax_open_kernel();
34986 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
34987 + pax_close_kernel();
34988 }
34989
34990 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
34991 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
34992 index 69a77e2..552b42c 100644
34993 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
34994 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
34995 @@ -71,8 +71,8 @@ do { \
34996 } while (0)
34997
34998 #else
34999 -#define IWL_DEBUG(m, level, fmt, args...)
35000 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35001 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35002 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35003 #define iwl_print_hex_dump(m, level, p, len)
35004 #endif /* CONFIG_IWLWIFI_DEBUG */
35005
35006 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35007 index 523ad55..f8c5dc5 100644
35008 --- a/drivers/net/wireless/mac80211_hwsim.c
35009 +++ b/drivers/net/wireless/mac80211_hwsim.c
35010 @@ -1678,9 +1678,11 @@ static int __init init_mac80211_hwsim(void)
35011 return -EINVAL;
35012
35013 if (fake_hw_scan) {
35014 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35015 - mac80211_hwsim_ops.sw_scan_start = NULL;
35016 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35017 + pax_open_kernel();
35018 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35019 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35020 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35021 + pax_close_kernel();
35022 }
35023
35024 spin_lock_init(&hwsim_radio_lock);
35025 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35026 index 30f138b..c904585 100644
35027 --- a/drivers/net/wireless/mwifiex/main.h
35028 +++ b/drivers/net/wireless/mwifiex/main.h
35029 @@ -543,7 +543,7 @@ struct mwifiex_if_ops {
35030 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35031 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35032 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35033 -};
35034 +} __no_const;
35035
35036 struct mwifiex_adapter {
35037 u8 iface_type;
35038 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35039 index 0c13840..a5c3ed6 100644
35040 --- a/drivers/net/wireless/rndis_wlan.c
35041 +++ b/drivers/net/wireless/rndis_wlan.c
35042 @@ -1275,7 +1275,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35043
35044 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35045
35046 - if (rts_threshold < 0 || rts_threshold > 2347)
35047 + if (rts_threshold > 2347)
35048 rts_threshold = 2347;
35049
35050 tmp = cpu_to_le32(rts_threshold);
35051 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35052 index a77f1bb..c608b2b 100644
35053 --- a/drivers/net/wireless/wl1251/wl1251.h
35054 +++ b/drivers/net/wireless/wl1251/wl1251.h
35055 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35056 void (*reset)(struct wl1251 *wl);
35057 void (*enable_irq)(struct wl1251 *wl);
35058 void (*disable_irq)(struct wl1251 *wl);
35059 -};
35060 +} __no_const;
35061
35062 struct wl1251 {
35063 struct ieee80211_hw *hw;
35064 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35065 index f34b5b2..b5abb9f 100644
35066 --- a/drivers/oprofile/buffer_sync.c
35067 +++ b/drivers/oprofile/buffer_sync.c
35068 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35069 if (cookie == NO_COOKIE)
35070 offset = pc;
35071 if (cookie == INVALID_COOKIE) {
35072 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35073 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35074 offset = pc;
35075 }
35076 if (cookie != last_cookie) {
35077 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35078 /* add userspace sample */
35079
35080 if (!mm) {
35081 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35082 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35083 return 0;
35084 }
35085
35086 cookie = lookup_dcookie(mm, s->eip, &offset);
35087
35088 if (cookie == INVALID_COOKIE) {
35089 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35090 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35091 return 0;
35092 }
35093
35094 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35095 /* ignore backtraces if failed to add a sample */
35096 if (state == sb_bt_start) {
35097 state = sb_bt_ignore;
35098 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35099 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35100 }
35101 }
35102 release_mm(mm);
35103 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35104 index c0cc4e7..44d4e54 100644
35105 --- a/drivers/oprofile/event_buffer.c
35106 +++ b/drivers/oprofile/event_buffer.c
35107 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35108 }
35109
35110 if (buffer_pos == buffer_size) {
35111 - atomic_inc(&oprofile_stats.event_lost_overflow);
35112 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35113 return;
35114 }
35115
35116 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35117 index f8c752e..28bf4fc 100644
35118 --- a/drivers/oprofile/oprof.c
35119 +++ b/drivers/oprofile/oprof.c
35120 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35121 if (oprofile_ops.switch_events())
35122 return;
35123
35124 - atomic_inc(&oprofile_stats.multiplex_counter);
35125 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35126 start_switch_worker();
35127 }
35128
35129 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35130 index 917d28e..d62d981 100644
35131 --- a/drivers/oprofile/oprofile_stats.c
35132 +++ b/drivers/oprofile/oprofile_stats.c
35133 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35134 cpu_buf->sample_invalid_eip = 0;
35135 }
35136
35137 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35138 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35139 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35140 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35141 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35142 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35143 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35144 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35145 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35146 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35147 }
35148
35149
35150 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35151 index 38b6fc0..b5cbfce 100644
35152 --- a/drivers/oprofile/oprofile_stats.h
35153 +++ b/drivers/oprofile/oprofile_stats.h
35154 @@ -13,11 +13,11 @@
35155 #include <linux/atomic.h>
35156
35157 struct oprofile_stat_struct {
35158 - atomic_t sample_lost_no_mm;
35159 - atomic_t sample_lost_no_mapping;
35160 - atomic_t bt_lost_no_mapping;
35161 - atomic_t event_lost_overflow;
35162 - atomic_t multiplex_counter;
35163 + atomic_unchecked_t sample_lost_no_mm;
35164 + atomic_unchecked_t sample_lost_no_mapping;
35165 + atomic_unchecked_t bt_lost_no_mapping;
35166 + atomic_unchecked_t event_lost_overflow;
35167 + atomic_unchecked_t multiplex_counter;
35168 };
35169
35170 extern struct oprofile_stat_struct oprofile_stats;
35171 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35172 index 2f0aa0f..90fab02 100644
35173 --- a/drivers/oprofile/oprofilefs.c
35174 +++ b/drivers/oprofile/oprofilefs.c
35175 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
35176
35177
35178 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35179 - char const *name, atomic_t *val)
35180 + char const *name, atomic_unchecked_t *val)
35181 {
35182 return __oprofilefs_create_file(sb, root, name,
35183 &atomic_ro_fops, 0444, val);
35184 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35185 index 3f56bc0..707d642 100644
35186 --- a/drivers/parport/procfs.c
35187 +++ b/drivers/parport/procfs.c
35188 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35189
35190 *ppos += len;
35191
35192 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35193 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35194 }
35195
35196 #ifdef CONFIG_PARPORT_1284
35197 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35198
35199 *ppos += len;
35200
35201 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35202 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35203 }
35204 #endif /* IEEE1284.3 support. */
35205
35206 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35207 index 9fff878..ad0ad53 100644
35208 --- a/drivers/pci/hotplug/cpci_hotplug.h
35209 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35210 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35211 int (*hardware_test) (struct slot* slot, u32 value);
35212 u8 (*get_power) (struct slot* slot);
35213 int (*set_power) (struct slot* slot, int value);
35214 -};
35215 +} __no_const;
35216
35217 struct cpci_hp_controller {
35218 unsigned int irq;
35219 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35220 index 76ba8a1..20ca857 100644
35221 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35222 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35223 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35224
35225 void compaq_nvram_init (void __iomem *rom_start)
35226 {
35227 +
35228 +#ifndef CONFIG_PAX_KERNEXEC
35229 if (rom_start) {
35230 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35231 }
35232 +#endif
35233 +
35234 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35235
35236 /* initialize our int15 lock */
35237 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35238 index 1cfbf22..be96487 100644
35239 --- a/drivers/pci/pcie/aspm.c
35240 +++ b/drivers/pci/pcie/aspm.c
35241 @@ -27,9 +27,9 @@
35242 #define MODULE_PARAM_PREFIX "pcie_aspm."
35243
35244 /* Note: those are not register definitions */
35245 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35246 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35247 -#define ASPM_STATE_L1 (4) /* L1 state */
35248 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35249 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35250 +#define ASPM_STATE_L1 (4U) /* L1 state */
35251 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35252 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35253
35254 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35255 index dfee1b3..a454fb6 100644
35256 --- a/drivers/pci/probe.c
35257 +++ b/drivers/pci/probe.c
35258 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35259 u32 l, sz, mask;
35260 u16 orig_cmd;
35261
35262 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35263 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35264
35265 if (!dev->mmio_always_on) {
35266 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35267 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35268 index 27911b5..5b6db88 100644
35269 --- a/drivers/pci/proc.c
35270 +++ b/drivers/pci/proc.c
35271 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35272 static int __init pci_proc_init(void)
35273 {
35274 struct pci_dev *dev = NULL;
35275 +
35276 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35277 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35278 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35279 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35280 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35281 +#endif
35282 +#else
35283 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35284 +#endif
35285 proc_create("devices", 0, proc_bus_pci_dir,
35286 &proc_bus_pci_dev_operations);
35287 proc_initialized = 1;
35288 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35289 index 7b82868..b9344c9 100644
35290 --- a/drivers/platform/x86/thinkpad_acpi.c
35291 +++ b/drivers/platform/x86/thinkpad_acpi.c
35292 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35293 return 0;
35294 }
35295
35296 -void static hotkey_mask_warn_incomplete_mask(void)
35297 +static void hotkey_mask_warn_incomplete_mask(void)
35298 {
35299 /* log only what the user can fix... */
35300 const u32 wantedmask = hotkey_driver_mask &
35301 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35302 }
35303 }
35304
35305 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35306 - struct tp_nvram_state *newn,
35307 - const u32 event_mask)
35308 -{
35309 -
35310 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35311 do { \
35312 if ((event_mask & (1 << __scancode)) && \
35313 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35314 tpacpi_hotkey_send_key(__scancode); \
35315 } while (0)
35316
35317 - void issue_volchange(const unsigned int oldvol,
35318 - const unsigned int newvol)
35319 - {
35320 - unsigned int i = oldvol;
35321 +static void issue_volchange(const unsigned int oldvol,
35322 + const unsigned int newvol,
35323 + const u32 event_mask)
35324 +{
35325 + unsigned int i = oldvol;
35326
35327 - while (i > newvol) {
35328 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35329 - i--;
35330 - }
35331 - while (i < newvol) {
35332 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35333 - i++;
35334 - }
35335 + while (i > newvol) {
35336 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35337 + i--;
35338 }
35339 + while (i < newvol) {
35340 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35341 + i++;
35342 + }
35343 +}
35344
35345 - void issue_brightnesschange(const unsigned int oldbrt,
35346 - const unsigned int newbrt)
35347 - {
35348 - unsigned int i = oldbrt;
35349 +static void issue_brightnesschange(const unsigned int oldbrt,
35350 + const unsigned int newbrt,
35351 + const u32 event_mask)
35352 +{
35353 + unsigned int i = oldbrt;
35354
35355 - while (i > newbrt) {
35356 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35357 - i--;
35358 - }
35359 - while (i < newbrt) {
35360 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35361 - i++;
35362 - }
35363 + while (i > newbrt) {
35364 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35365 + i--;
35366 + }
35367 + while (i < newbrt) {
35368 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35369 + i++;
35370 }
35371 +}
35372
35373 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35374 + struct tp_nvram_state *newn,
35375 + const u32 event_mask)
35376 +{
35377 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35378 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35379 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35380 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35381 oldn->volume_level != newn->volume_level) {
35382 /* recently muted, or repeated mute keypress, or
35383 * multiple presses ending in mute */
35384 - issue_volchange(oldn->volume_level, newn->volume_level);
35385 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35386 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35387 }
35388 } else {
35389 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35390 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35391 }
35392 if (oldn->volume_level != newn->volume_level) {
35393 - issue_volchange(oldn->volume_level, newn->volume_level);
35394 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35395 } else if (oldn->volume_toggle != newn->volume_toggle) {
35396 /* repeated vol up/down keypress at end of scale ? */
35397 if (newn->volume_level == 0)
35398 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35399 /* handle brightness */
35400 if (oldn->brightness_level != newn->brightness_level) {
35401 issue_brightnesschange(oldn->brightness_level,
35402 - newn->brightness_level);
35403 + newn->brightness_level,
35404 + event_mask);
35405 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35406 /* repeated key presses that didn't change state */
35407 if (newn->brightness_level == 0)
35408 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35409 && !tp_features.bright_unkfw)
35410 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35411 }
35412 +}
35413
35414 #undef TPACPI_COMPARE_KEY
35415 #undef TPACPI_MAY_SEND_KEY
35416 -}
35417
35418 /*
35419 * Polling driver
35420 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35421 index b859d16..5cc6b1a 100644
35422 --- a/drivers/pnp/pnpbios/bioscalls.c
35423 +++ b/drivers/pnp/pnpbios/bioscalls.c
35424 @@ -59,7 +59,7 @@ do { \
35425 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35426 } while(0)
35427
35428 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35429 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35430 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35431
35432 /*
35433 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35434
35435 cpu = get_cpu();
35436 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35437 +
35438 + pax_open_kernel();
35439 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35440 + pax_close_kernel();
35441
35442 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35443 spin_lock_irqsave(&pnp_bios_lock, flags);
35444 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35445 :"memory");
35446 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35447
35448 + pax_open_kernel();
35449 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35450 + pax_close_kernel();
35451 +
35452 put_cpu();
35453
35454 /* If we get here and this is set then the PnP BIOS faulted on us. */
35455 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35456 return status;
35457 }
35458
35459 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35460 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35461 {
35462 int i;
35463
35464 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35465 pnp_bios_callpoint.offset = header->fields.pm16offset;
35466 pnp_bios_callpoint.segment = PNP_CS16;
35467
35468 + pax_open_kernel();
35469 +
35470 for_each_possible_cpu(i) {
35471 struct desc_struct *gdt = get_cpu_gdt_table(i);
35472 if (!gdt)
35473 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35474 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35475 (unsigned long)__va(header->fields.pm16dseg));
35476 }
35477 +
35478 + pax_close_kernel();
35479 }
35480 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35481 index b0ecacb..7c9da2e 100644
35482 --- a/drivers/pnp/resource.c
35483 +++ b/drivers/pnp/resource.c
35484 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35485 return 1;
35486
35487 /* check if the resource is valid */
35488 - if (*irq < 0 || *irq > 15)
35489 + if (*irq > 15)
35490 return 0;
35491
35492 /* check if the resource is reserved */
35493 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35494 return 1;
35495
35496 /* check if the resource is valid */
35497 - if (*dma < 0 || *dma == 4 || *dma > 7)
35498 + if (*dma == 4 || *dma > 7)
35499 return 0;
35500
35501 /* check if the resource is reserved */
35502 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35503 index bb16f5b..c751eef 100644
35504 --- a/drivers/power/bq27x00_battery.c
35505 +++ b/drivers/power/bq27x00_battery.c
35506 @@ -67,7 +67,7 @@
35507 struct bq27x00_device_info;
35508 struct bq27x00_access_methods {
35509 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35510 -};
35511 +} __no_const;
35512
35513 enum bq27x00_chip { BQ27000, BQ27500 };
35514
35515 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35516 index 33f5d9a..d957d3f 100644
35517 --- a/drivers/regulator/max8660.c
35518 +++ b/drivers/regulator/max8660.c
35519 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35520 max8660->shadow_regs[MAX8660_OVER1] = 5;
35521 } else {
35522 /* Otherwise devices can be toggled via software */
35523 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
35524 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
35525 + pax_open_kernel();
35526 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
35527 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
35528 + pax_close_kernel();
35529 }
35530
35531 /*
35532 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
35533 index 023d17d..74ef35b 100644
35534 --- a/drivers/regulator/mc13892-regulator.c
35535 +++ b/drivers/regulator/mc13892-regulator.c
35536 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
35537 }
35538 mc13xxx_unlock(mc13892);
35539
35540 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35541 + pax_open_kernel();
35542 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35543 = mc13892_vcam_set_mode;
35544 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35545 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35546 = mc13892_vcam_get_mode;
35547 + pax_close_kernel();
35548 for (i = 0; i < pdata->num_regulators; i++) {
35549 init_data = &pdata->regulators[i];
35550 priv->regulators[i] = regulator_register(
35551 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
35552 index cace6d3..f623fda 100644
35553 --- a/drivers/rtc/rtc-dev.c
35554 +++ b/drivers/rtc/rtc-dev.c
35555 @@ -14,6 +14,7 @@
35556 #include <linux/module.h>
35557 #include <linux/rtc.h>
35558 #include <linux/sched.h>
35559 +#include <linux/grsecurity.h>
35560 #include "rtc-core.h"
35561
35562 static dev_t rtc_devt;
35563 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
35564 if (copy_from_user(&tm, uarg, sizeof(tm)))
35565 return -EFAULT;
35566
35567 + gr_log_timechange();
35568 +
35569 return rtc_set_time(rtc, &tm);
35570
35571 case RTC_PIE_ON:
35572 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
35573 index ffb5878..e6d785c 100644
35574 --- a/drivers/scsi/aacraid/aacraid.h
35575 +++ b/drivers/scsi/aacraid/aacraid.h
35576 @@ -492,7 +492,7 @@ struct adapter_ops
35577 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
35578 /* Administrative operations */
35579 int (*adapter_comm)(struct aac_dev * dev, int comm);
35580 -};
35581 +} __no_const;
35582
35583 /*
35584 * Define which interrupt handler needs to be installed
35585 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
35586 index 705e13e..91c873c 100644
35587 --- a/drivers/scsi/aacraid/linit.c
35588 +++ b/drivers/scsi/aacraid/linit.c
35589 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
35590 #elif defined(__devinitconst)
35591 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35592 #else
35593 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
35594 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35595 #endif
35596 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
35597 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
35598 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
35599 index d5ff142..49c0ebb 100644
35600 --- a/drivers/scsi/aic94xx/aic94xx_init.c
35601 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
35602 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
35603 .lldd_control_phy = asd_control_phy,
35604 };
35605
35606 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
35607 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
35608 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
35609 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
35610 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
35611 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
35612 index a796de9..1ef20e1 100644
35613 --- a/drivers/scsi/bfa/bfa.h
35614 +++ b/drivers/scsi/bfa/bfa.h
35615 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
35616 u32 *end);
35617 int cpe_vec_q0;
35618 int rme_vec_q0;
35619 -};
35620 +} __no_const;
35621 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
35622
35623 struct bfa_faa_cbfn_s {
35624 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
35625 index e07bd47..cd1bbbb 100644
35626 --- a/drivers/scsi/bfa/bfa_fcpim.c
35627 +++ b/drivers/scsi/bfa/bfa_fcpim.c
35628 @@ -4121,7 +4121,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
35629
35630 bfa_iotag_attach(fcp);
35631
35632 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
35633 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
35634 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
35635 (fcp->num_itns * sizeof(struct bfa_itn_s));
35636 memset(fcp->itn_arr, 0,
35637 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35638 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
35639 {
35640 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
35641 - struct bfa_itn_s *itn;
35642 + bfa_itn_s_no_const *itn;
35643
35644 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
35645 itn->isr = isr;
35646 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
35647 index 1080bcb..a3b39e3 100644
35648 --- a/drivers/scsi/bfa/bfa_fcpim.h
35649 +++ b/drivers/scsi/bfa/bfa_fcpim.h
35650 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
35651 struct bfa_itn_s {
35652 bfa_isr_func_t isr;
35653 };
35654 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
35655
35656 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35657 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
35658 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
35659 struct list_head iotag_tio_free_q; /* free IO resources */
35660 struct list_head iotag_unused_q; /* unused IO resources*/
35661 struct bfa_iotag_s *iotag_arr;
35662 - struct bfa_itn_s *itn_arr;
35663 + bfa_itn_s_no_const *itn_arr;
35664 int num_ioim_reqs;
35665 int num_fwtio_reqs;
35666 int num_itns;
35667 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
35668 index 546d46b..642fa5b 100644
35669 --- a/drivers/scsi/bfa/bfa_ioc.h
35670 +++ b/drivers/scsi/bfa/bfa_ioc.h
35671 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
35672 bfa_ioc_disable_cbfn_t disable_cbfn;
35673 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
35674 bfa_ioc_reset_cbfn_t reset_cbfn;
35675 -};
35676 +} __no_const;
35677
35678 /*
35679 * IOC event notification mechanism.
35680 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
35681 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
35682 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
35683 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
35684 -};
35685 +} __no_const;
35686
35687 /*
35688 * Queue element to wait for room in request queue. FIFO order is
35689 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
35690 index 351dc0b..951dc32 100644
35691 --- a/drivers/scsi/hosts.c
35692 +++ b/drivers/scsi/hosts.c
35693 @@ -42,7 +42,7 @@
35694 #include "scsi_logging.h"
35695
35696
35697 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
35698 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
35699
35700
35701 static void scsi_host_cls_release(struct device *dev)
35702 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
35703 * subtract one because we increment first then return, but we need to
35704 * know what the next host number was before increment
35705 */
35706 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
35707 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
35708 shost->dma_channel = 0xff;
35709
35710 /* These three are default values which can be overridden */
35711 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
35712 index 865d452..e9b7fa7 100644
35713 --- a/drivers/scsi/hpsa.c
35714 +++ b/drivers/scsi/hpsa.c
35715 @@ -505,7 +505,7 @@ static inline u32 next_command(struct ctlr_info *h)
35716 u32 a;
35717
35718 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35719 - return h->access.command_completed(h);
35720 + return h->access->command_completed(h);
35721
35722 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35723 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35724 @@ -2989,7 +2989,7 @@ static void start_io(struct ctlr_info *h)
35725 while (!list_empty(&h->reqQ)) {
35726 c = list_entry(h->reqQ.next, struct CommandList, list);
35727 /* can't do anything if fifo is full */
35728 - if ((h->access.fifo_full(h))) {
35729 + if ((h->access->fifo_full(h))) {
35730 dev_warn(&h->pdev->dev, "fifo full\n");
35731 break;
35732 }
35733 @@ -2999,7 +2999,7 @@ static void start_io(struct ctlr_info *h)
35734 h->Qdepth--;
35735
35736 /* Tell the controller execute command */
35737 - h->access.submit_command(h, c);
35738 + h->access->submit_command(h, c);
35739
35740 /* Put job onto the completed Q */
35741 addQ(&h->cmpQ, c);
35742 @@ -3008,17 +3008,17 @@ static void start_io(struct ctlr_info *h)
35743
35744 static inline unsigned long get_next_completion(struct ctlr_info *h)
35745 {
35746 - return h->access.command_completed(h);
35747 + return h->access->command_completed(h);
35748 }
35749
35750 static inline bool interrupt_pending(struct ctlr_info *h)
35751 {
35752 - return h->access.intr_pending(h);
35753 + return h->access->intr_pending(h);
35754 }
35755
35756 static inline long interrupt_not_for_us(struct ctlr_info *h)
35757 {
35758 - return (h->access.intr_pending(h) == 0) ||
35759 + return (h->access->intr_pending(h) == 0) ||
35760 (h->interrupts_enabled == 0);
35761 }
35762
35763 @@ -3917,7 +3917,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
35764 if (prod_index < 0)
35765 return -ENODEV;
35766 h->product_name = products[prod_index].product_name;
35767 - h->access = *(products[prod_index].access);
35768 + h->access = products[prod_index].access;
35769
35770 if (hpsa_board_disabled(h->pdev)) {
35771 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35772 @@ -4162,7 +4162,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
35773
35774 assert_spin_locked(&lockup_detector_lock);
35775 remove_ctlr_from_lockup_detector_list(h);
35776 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35777 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35778 spin_lock_irqsave(&h->lock, flags);
35779 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
35780 spin_unlock_irqrestore(&h->lock, flags);
35781 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
35782 }
35783
35784 /* make sure the board interrupts are off */
35785 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35786 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35787
35788 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
35789 goto clean2;
35790 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
35791 * fake ones to scoop up any residual completions.
35792 */
35793 spin_lock_irqsave(&h->lock, flags);
35794 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35795 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35796 spin_unlock_irqrestore(&h->lock, flags);
35797 free_irq(h->intr[h->intr_mode], h);
35798 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
35799 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
35800 dev_info(&h->pdev->dev, "Board READY.\n");
35801 dev_info(&h->pdev->dev,
35802 "Waiting for stale completions to drain.\n");
35803 - h->access.set_intr_mask(h, HPSA_INTR_ON);
35804 + h->access->set_intr_mask(h, HPSA_INTR_ON);
35805 msleep(10000);
35806 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35807 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35808
35809 rc = controller_reset_failed(h->cfgtable);
35810 if (rc)
35811 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
35812 }
35813
35814 /* Turn the interrupts on so we can service requests */
35815 - h->access.set_intr_mask(h, HPSA_INTR_ON);
35816 + h->access->set_intr_mask(h, HPSA_INTR_ON);
35817
35818 hpsa_hba_inquiry(h);
35819 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
35820 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
35821 * To write all data in the battery backed cache to disks
35822 */
35823 hpsa_flush_cache(h);
35824 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35825 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35826 free_irq(h->intr[h->intr_mode], h);
35827 #ifdef CONFIG_PCI_MSI
35828 if (h->msix_vector)
35829 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
35830 return;
35831 }
35832 /* Change the access methods to the performant access methods */
35833 - h->access = SA5_performant_access;
35834 + h->access = &SA5_performant_access;
35835 h->transMethod = CFGTBL_Trans_Performant;
35836 }
35837
35838 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
35839 index 91edafb..a9b88ec 100644
35840 --- a/drivers/scsi/hpsa.h
35841 +++ b/drivers/scsi/hpsa.h
35842 @@ -73,7 +73,7 @@ struct ctlr_info {
35843 unsigned int msix_vector;
35844 unsigned int msi_vector;
35845 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
35846 - struct access_method access;
35847 + struct access_method *access;
35848
35849 /* queue and queue Info */
35850 struct list_head reqQ;
35851 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
35852 index f2df059..a3a9930 100644
35853 --- a/drivers/scsi/ips.h
35854 +++ b/drivers/scsi/ips.h
35855 @@ -1027,7 +1027,7 @@ typedef struct {
35856 int (*intr)(struct ips_ha *);
35857 void (*enableint)(struct ips_ha *);
35858 uint32_t (*statupd)(struct ips_ha *);
35859 -} ips_hw_func_t;
35860 +} __no_const ips_hw_func_t;
35861
35862 typedef struct ips_ha {
35863 uint8_t ha_id[IPS_MAX_CHANNELS+1];
35864 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
35865 index 9de9db2..1e09660 100644
35866 --- a/drivers/scsi/libfc/fc_exch.c
35867 +++ b/drivers/scsi/libfc/fc_exch.c
35868 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
35869 * all together if not used XXX
35870 */
35871 struct {
35872 - atomic_t no_free_exch;
35873 - atomic_t no_free_exch_xid;
35874 - atomic_t xid_not_found;
35875 - atomic_t xid_busy;
35876 - atomic_t seq_not_found;
35877 - atomic_t non_bls_resp;
35878 + atomic_unchecked_t no_free_exch;
35879 + atomic_unchecked_t no_free_exch_xid;
35880 + atomic_unchecked_t xid_not_found;
35881 + atomic_unchecked_t xid_busy;
35882 + atomic_unchecked_t seq_not_found;
35883 + atomic_unchecked_t non_bls_resp;
35884 } stats;
35885 };
35886
35887 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
35888 /* allocate memory for exchange */
35889 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
35890 if (!ep) {
35891 - atomic_inc(&mp->stats.no_free_exch);
35892 + atomic_inc_unchecked(&mp->stats.no_free_exch);
35893 goto out;
35894 }
35895 memset(ep, 0, sizeof(*ep));
35896 @@ -780,7 +780,7 @@ out:
35897 return ep;
35898 err:
35899 spin_unlock_bh(&pool->lock);
35900 - atomic_inc(&mp->stats.no_free_exch_xid);
35901 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
35902 mempool_free(ep, mp->ep_pool);
35903 return NULL;
35904 }
35905 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35906 xid = ntohs(fh->fh_ox_id); /* we originated exch */
35907 ep = fc_exch_find(mp, xid);
35908 if (!ep) {
35909 - atomic_inc(&mp->stats.xid_not_found);
35910 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35911 reject = FC_RJT_OX_ID;
35912 goto out;
35913 }
35914 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35915 ep = fc_exch_find(mp, xid);
35916 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
35917 if (ep) {
35918 - atomic_inc(&mp->stats.xid_busy);
35919 + atomic_inc_unchecked(&mp->stats.xid_busy);
35920 reject = FC_RJT_RX_ID;
35921 goto rel;
35922 }
35923 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35924 }
35925 xid = ep->xid; /* get our XID */
35926 } else if (!ep) {
35927 - atomic_inc(&mp->stats.xid_not_found);
35928 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35929 reject = FC_RJT_RX_ID; /* XID not found */
35930 goto out;
35931 }
35932 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35933 } else {
35934 sp = &ep->seq;
35935 if (sp->id != fh->fh_seq_id) {
35936 - atomic_inc(&mp->stats.seq_not_found);
35937 + atomic_inc_unchecked(&mp->stats.seq_not_found);
35938 if (f_ctl & FC_FC_END_SEQ) {
35939 /*
35940 * Update sequence_id based on incoming last
35941 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35942
35943 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
35944 if (!ep) {
35945 - atomic_inc(&mp->stats.xid_not_found);
35946 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35947 goto out;
35948 }
35949 if (ep->esb_stat & ESB_ST_COMPLETE) {
35950 - atomic_inc(&mp->stats.xid_not_found);
35951 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35952 goto rel;
35953 }
35954 if (ep->rxid == FC_XID_UNKNOWN)
35955 ep->rxid = ntohs(fh->fh_rx_id);
35956 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
35957 - atomic_inc(&mp->stats.xid_not_found);
35958 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35959 goto rel;
35960 }
35961 if (ep->did != ntoh24(fh->fh_s_id) &&
35962 ep->did != FC_FID_FLOGI) {
35963 - atomic_inc(&mp->stats.xid_not_found);
35964 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35965 goto rel;
35966 }
35967 sof = fr_sof(fp);
35968 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35969 sp->ssb_stat |= SSB_ST_RESP;
35970 sp->id = fh->fh_seq_id;
35971 } else if (sp->id != fh->fh_seq_id) {
35972 - atomic_inc(&mp->stats.seq_not_found);
35973 + atomic_inc_unchecked(&mp->stats.seq_not_found);
35974 goto rel;
35975 }
35976
35977 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35978 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
35979
35980 if (!sp)
35981 - atomic_inc(&mp->stats.xid_not_found);
35982 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35983 else
35984 - atomic_inc(&mp->stats.non_bls_resp);
35985 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
35986
35987 fc_frame_free(fp);
35988 }
35989 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
35990 index db9238f..4378ed2 100644
35991 --- a/drivers/scsi/libsas/sas_ata.c
35992 +++ b/drivers/scsi/libsas/sas_ata.c
35993 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
35994 .postreset = ata_std_postreset,
35995 .error_handler = ata_std_error_handler,
35996 .post_internal_cmd = sas_ata_post_internal,
35997 - .qc_defer = ata_std_qc_defer,
35998 + .qc_defer = ata_std_qc_defer,
35999 .qc_prep = ata_noop_qc_prep,
36000 .qc_issue = sas_ata_qc_issue,
36001 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36002 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36003 index bb4c8e0..f33d849 100644
36004 --- a/drivers/scsi/lpfc/lpfc.h
36005 +++ b/drivers/scsi/lpfc/lpfc.h
36006 @@ -425,7 +425,7 @@ struct lpfc_vport {
36007 struct dentry *debug_nodelist;
36008 struct dentry *vport_debugfs_root;
36009 struct lpfc_debugfs_trc *disc_trc;
36010 - atomic_t disc_trc_cnt;
36011 + atomic_unchecked_t disc_trc_cnt;
36012 #endif
36013 uint8_t stat_data_enabled;
36014 uint8_t stat_data_blocked;
36015 @@ -835,8 +835,8 @@ struct lpfc_hba {
36016 struct timer_list fabric_block_timer;
36017 unsigned long bit_flags;
36018 #define FABRIC_COMANDS_BLOCKED 0
36019 - atomic_t num_rsrc_err;
36020 - atomic_t num_cmd_success;
36021 + atomic_unchecked_t num_rsrc_err;
36022 + atomic_unchecked_t num_cmd_success;
36023 unsigned long last_rsrc_error_time;
36024 unsigned long last_ramp_down_time;
36025 unsigned long last_ramp_up_time;
36026 @@ -866,7 +866,7 @@ struct lpfc_hba {
36027
36028 struct dentry *debug_slow_ring_trc;
36029 struct lpfc_debugfs_trc *slow_ring_trc;
36030 - atomic_t slow_ring_trc_cnt;
36031 + atomic_unchecked_t slow_ring_trc_cnt;
36032 /* iDiag debugfs sub-directory */
36033 struct dentry *idiag_root;
36034 struct dentry *idiag_pci_cfg;
36035 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36036 index 2838259..a07cfb5 100644
36037 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36038 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36039 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36040
36041 #include <linux/debugfs.h>
36042
36043 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36044 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36045 static unsigned long lpfc_debugfs_start_time = 0L;
36046
36047 /* iDiag */
36048 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36049 lpfc_debugfs_enable = 0;
36050
36051 len = 0;
36052 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36053 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36054 (lpfc_debugfs_max_disc_trc - 1);
36055 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36056 dtp = vport->disc_trc + i;
36057 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36058 lpfc_debugfs_enable = 0;
36059
36060 len = 0;
36061 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36062 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36063 (lpfc_debugfs_max_slow_ring_trc - 1);
36064 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36065 dtp = phba->slow_ring_trc + i;
36066 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36067 !vport || !vport->disc_trc)
36068 return;
36069
36070 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36071 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36072 (lpfc_debugfs_max_disc_trc - 1);
36073 dtp = vport->disc_trc + index;
36074 dtp->fmt = fmt;
36075 dtp->data1 = data1;
36076 dtp->data2 = data2;
36077 dtp->data3 = data3;
36078 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36079 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36080 dtp->jif = jiffies;
36081 #endif
36082 return;
36083 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36084 !phba || !phba->slow_ring_trc)
36085 return;
36086
36087 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36088 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36089 (lpfc_debugfs_max_slow_ring_trc - 1);
36090 dtp = phba->slow_ring_trc + index;
36091 dtp->fmt = fmt;
36092 dtp->data1 = data1;
36093 dtp->data2 = data2;
36094 dtp->data3 = data3;
36095 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36096 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36097 dtp->jif = jiffies;
36098 #endif
36099 return;
36100 @@ -3986,7 +3986,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36101 "slow_ring buffer\n");
36102 goto debug_failed;
36103 }
36104 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36105 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36106 memset(phba->slow_ring_trc, 0,
36107 (sizeof(struct lpfc_debugfs_trc) *
36108 lpfc_debugfs_max_slow_ring_trc));
36109 @@ -4032,7 +4032,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36110 "buffer\n");
36111 goto debug_failed;
36112 }
36113 - atomic_set(&vport->disc_trc_cnt, 0);
36114 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36115
36116 snprintf(name, sizeof(name), "discovery_trace");
36117 vport->debug_disc_trc =
36118 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36119 index 55bc4fc..a2a109c 100644
36120 --- a/drivers/scsi/lpfc/lpfc_init.c
36121 +++ b/drivers/scsi/lpfc/lpfc_init.c
36122 @@ -10027,8 +10027,10 @@ lpfc_init(void)
36123 printk(LPFC_COPYRIGHT "\n");
36124
36125 if (lpfc_enable_npiv) {
36126 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36127 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36128 + pax_open_kernel();
36129 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36130 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36131 + pax_close_kernel();
36132 }
36133 lpfc_transport_template =
36134 fc_attach_transport(&lpfc_transport_functions);
36135 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36136 index 2e1e54e..1af0a0d 100644
36137 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36138 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36139 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36140 uint32_t evt_posted;
36141
36142 spin_lock_irqsave(&phba->hbalock, flags);
36143 - atomic_inc(&phba->num_rsrc_err);
36144 + atomic_inc_unchecked(&phba->num_rsrc_err);
36145 phba->last_rsrc_error_time = jiffies;
36146
36147 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36148 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36149 unsigned long flags;
36150 struct lpfc_hba *phba = vport->phba;
36151 uint32_t evt_posted;
36152 - atomic_inc(&phba->num_cmd_success);
36153 + atomic_inc_unchecked(&phba->num_cmd_success);
36154
36155 if (vport->cfg_lun_queue_depth <= queue_depth)
36156 return;
36157 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36158 unsigned long num_rsrc_err, num_cmd_success;
36159 int i;
36160
36161 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36162 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36163 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36164 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36165
36166 vports = lpfc_create_vport_work_array(phba);
36167 if (vports != NULL)
36168 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36169 }
36170 }
36171 lpfc_destroy_vport_work_array(phba, vports);
36172 - atomic_set(&phba->num_rsrc_err, 0);
36173 - atomic_set(&phba->num_cmd_success, 0);
36174 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36175 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36176 }
36177
36178 /**
36179 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36180 }
36181 }
36182 lpfc_destroy_vport_work_array(phba, vports);
36183 - atomic_set(&phba->num_rsrc_err, 0);
36184 - atomic_set(&phba->num_cmd_success, 0);
36185 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36186 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36187 }
36188
36189 /**
36190 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36191 index 5163edb..7b142bc 100644
36192 --- a/drivers/scsi/pmcraid.c
36193 +++ b/drivers/scsi/pmcraid.c
36194 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36195 res->scsi_dev = scsi_dev;
36196 scsi_dev->hostdata = res;
36197 res->change_detected = 0;
36198 - atomic_set(&res->read_failures, 0);
36199 - atomic_set(&res->write_failures, 0);
36200 + atomic_set_unchecked(&res->read_failures, 0);
36201 + atomic_set_unchecked(&res->write_failures, 0);
36202 rc = 0;
36203 }
36204 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36205 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36206
36207 /* If this was a SCSI read/write command keep count of errors */
36208 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36209 - atomic_inc(&res->read_failures);
36210 + atomic_inc_unchecked(&res->read_failures);
36211 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36212 - atomic_inc(&res->write_failures);
36213 + atomic_inc_unchecked(&res->write_failures);
36214
36215 if (!RES_IS_GSCSI(res->cfg_entry) &&
36216 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36217 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36218 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36219 * hrrq_id assigned here in queuecommand
36220 */
36221 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36222 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36223 pinstance->num_hrrq;
36224 cmd->cmd_done = pmcraid_io_done;
36225
36226 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36227 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36228 * hrrq_id assigned here in queuecommand
36229 */
36230 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36231 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36232 pinstance->num_hrrq;
36233
36234 if (request_size) {
36235 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36236
36237 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36238 /* add resources only after host is added into system */
36239 - if (!atomic_read(&pinstance->expose_resources))
36240 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36241 return;
36242
36243 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36244 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36245 init_waitqueue_head(&pinstance->reset_wait_q);
36246
36247 atomic_set(&pinstance->outstanding_cmds, 0);
36248 - atomic_set(&pinstance->last_message_id, 0);
36249 - atomic_set(&pinstance->expose_resources, 0);
36250 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36251 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36252
36253 INIT_LIST_HEAD(&pinstance->free_res_q);
36254 INIT_LIST_HEAD(&pinstance->used_res_q);
36255 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36256 /* Schedule worker thread to handle CCN and take care of adding and
36257 * removing devices to OS
36258 */
36259 - atomic_set(&pinstance->expose_resources, 1);
36260 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36261 schedule_work(&pinstance->worker_q);
36262 return rc;
36263
36264 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36265 index ca496c7..9c791d5 100644
36266 --- a/drivers/scsi/pmcraid.h
36267 +++ b/drivers/scsi/pmcraid.h
36268 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36269 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36270
36271 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36272 - atomic_t last_message_id;
36273 + atomic_unchecked_t last_message_id;
36274
36275 /* configuration table */
36276 struct pmcraid_config_table *cfg_table;
36277 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36278 atomic_t outstanding_cmds;
36279
36280 /* should add/delete resources to mid-layer now ?*/
36281 - atomic_t expose_resources;
36282 + atomic_unchecked_t expose_resources;
36283
36284
36285
36286 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36287 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36288 };
36289 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36290 - atomic_t read_failures; /* count of failed READ commands */
36291 - atomic_t write_failures; /* count of failed WRITE commands */
36292 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36293 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36294
36295 /* To indicate add/delete/modify during CCN */
36296 u8 change_detected;
36297 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36298 index fcf052c..a8025a4 100644
36299 --- a/drivers/scsi/qla2xxx/qla_def.h
36300 +++ b/drivers/scsi/qla2xxx/qla_def.h
36301 @@ -2244,7 +2244,7 @@ struct isp_operations {
36302 int (*get_flash_version) (struct scsi_qla_host *, void *);
36303 int (*start_scsi) (srb_t *);
36304 int (*abort_isp) (struct scsi_qla_host *);
36305 -};
36306 +} __no_const;
36307
36308 /* MSI-X Support *************************************************************/
36309
36310 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36311 index fd5edc6..4906148 100644
36312 --- a/drivers/scsi/qla4xxx/ql4_def.h
36313 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36314 @@ -258,7 +258,7 @@ struct ddb_entry {
36315 * (4000 only) */
36316 atomic_t relogin_timer; /* Max Time to wait for
36317 * relogin to complete */
36318 - atomic_t relogin_retry_count; /* Num of times relogin has been
36319 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36320 * retried */
36321 uint32_t default_time2wait; /* Default Min time between
36322 * relogins (+aens) */
36323 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36324 index 4169c8b..a8b896b 100644
36325 --- a/drivers/scsi/qla4xxx/ql4_os.c
36326 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36327 @@ -2104,12 +2104,12 @@ void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36328 */
36329 if (!iscsi_is_session_online(cls_sess)) {
36330 /* Reset retry relogin timer */
36331 - atomic_inc(&ddb_entry->relogin_retry_count);
36332 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36333 DEBUG2(ql4_printk(KERN_INFO, ha,
36334 "%s: index[%d] relogin timed out-retrying"
36335 " relogin (%d), retry (%d)\n", __func__,
36336 ddb_entry->fw_ddb_index,
36337 - atomic_read(&ddb_entry->relogin_retry_count),
36338 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36339 ddb_entry->default_time2wait + 4));
36340 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36341 atomic_set(&ddb_entry->retry_relogin_timer,
36342 @@ -3835,7 +3835,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36343
36344 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36345 atomic_set(&ddb_entry->relogin_timer, 0);
36346 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36347 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36348
36349 ddb_entry->default_relogin_timeout =
36350 le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36351 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36352 index 2aeb2e9..46e3925 100644
36353 --- a/drivers/scsi/scsi.c
36354 +++ b/drivers/scsi/scsi.c
36355 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36356 unsigned long timeout;
36357 int rtn = 0;
36358
36359 - atomic_inc(&cmd->device->iorequest_cnt);
36360 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36361
36362 /* check if the device is still usable */
36363 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36364 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36365 index f85cfa6..a57c9e8 100644
36366 --- a/drivers/scsi/scsi_lib.c
36367 +++ b/drivers/scsi/scsi_lib.c
36368 @@ -1416,7 +1416,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36369 shost = sdev->host;
36370 scsi_init_cmd_errh(cmd);
36371 cmd->result = DID_NO_CONNECT << 16;
36372 - atomic_inc(&cmd->device->iorequest_cnt);
36373 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36374
36375 /*
36376 * SCSI request completion path will do scsi_device_unbusy(),
36377 @@ -1442,9 +1442,9 @@ static void scsi_softirq_done(struct request *rq)
36378
36379 INIT_LIST_HEAD(&cmd->eh_entry);
36380
36381 - atomic_inc(&cmd->device->iodone_cnt);
36382 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36383 if (cmd->result)
36384 - atomic_inc(&cmd->device->ioerr_cnt);
36385 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36386
36387 disposition = scsi_decide_disposition(cmd);
36388 if (disposition != SUCCESS &&
36389 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36390 index 04c2a27..9d8bd66 100644
36391 --- a/drivers/scsi/scsi_sysfs.c
36392 +++ b/drivers/scsi/scsi_sysfs.c
36393 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36394 char *buf) \
36395 { \
36396 struct scsi_device *sdev = to_scsi_device(dev); \
36397 - unsigned long long count = atomic_read(&sdev->field); \
36398 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36399 return snprintf(buf, 20, "0x%llx\n", count); \
36400 } \
36401 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36402 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36403 index 84a1fdf..693b0d6 100644
36404 --- a/drivers/scsi/scsi_tgt_lib.c
36405 +++ b/drivers/scsi/scsi_tgt_lib.c
36406 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36407 int err;
36408
36409 dprintk("%lx %u\n", uaddr, len);
36410 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36411 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36412 if (err) {
36413 /*
36414 * TODO: need to fixup sg_tablesize, max_segment_size,
36415 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36416 index 1b21491..1b7f60e 100644
36417 --- a/drivers/scsi/scsi_transport_fc.c
36418 +++ b/drivers/scsi/scsi_transport_fc.c
36419 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36420 * Netlink Infrastructure
36421 */
36422
36423 -static atomic_t fc_event_seq;
36424 +static atomic_unchecked_t fc_event_seq;
36425
36426 /**
36427 * fc_get_event_number - Obtain the next sequential FC event number
36428 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
36429 u32
36430 fc_get_event_number(void)
36431 {
36432 - return atomic_add_return(1, &fc_event_seq);
36433 + return atomic_add_return_unchecked(1, &fc_event_seq);
36434 }
36435 EXPORT_SYMBOL(fc_get_event_number);
36436
36437 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
36438 {
36439 int error;
36440
36441 - atomic_set(&fc_event_seq, 0);
36442 + atomic_set_unchecked(&fc_event_seq, 0);
36443
36444 error = transport_class_register(&fc_host_class);
36445 if (error)
36446 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36447 char *cp;
36448
36449 *val = simple_strtoul(buf, &cp, 0);
36450 - if ((*cp && (*cp != '\n')) || (*val < 0))
36451 + if (*cp && (*cp != '\n'))
36452 return -EINVAL;
36453 /*
36454 * Check for overflow; dev_loss_tmo is u32
36455 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36456 index 96029e6..4d77fa0 100644
36457 --- a/drivers/scsi/scsi_transport_iscsi.c
36458 +++ b/drivers/scsi/scsi_transport_iscsi.c
36459 @@ -79,7 +79,7 @@ struct iscsi_internal {
36460 struct transport_container session_cont;
36461 };
36462
36463 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36464 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36465 static struct workqueue_struct *iscsi_eh_timer_workq;
36466
36467 static DEFINE_IDA(iscsi_sess_ida);
36468 @@ -1062,7 +1062,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36469 int err;
36470
36471 ihost = shost->shost_data;
36472 - session->sid = atomic_add_return(1, &iscsi_session_nr);
36473 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
36474
36475 if (target_id == ISCSI_MAX_TARGET) {
36476 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
36477 @@ -2663,7 +2663,7 @@ static __init int iscsi_transport_init(void)
36478 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
36479 ISCSI_TRANSPORT_VERSION);
36480
36481 - atomic_set(&iscsi_session_nr, 0);
36482 + atomic_set_unchecked(&iscsi_session_nr, 0);
36483
36484 err = class_register(&iscsi_transport_class);
36485 if (err)
36486 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
36487 index 21a045e..ec89e03 100644
36488 --- a/drivers/scsi/scsi_transport_srp.c
36489 +++ b/drivers/scsi/scsi_transport_srp.c
36490 @@ -33,7 +33,7 @@
36491 #include "scsi_transport_srp_internal.h"
36492
36493 struct srp_host_attrs {
36494 - atomic_t next_port_id;
36495 + atomic_unchecked_t next_port_id;
36496 };
36497 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
36498
36499 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
36500 struct Scsi_Host *shost = dev_to_shost(dev);
36501 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
36502
36503 - atomic_set(&srp_host->next_port_id, 0);
36504 + atomic_set_unchecked(&srp_host->next_port_id, 0);
36505 return 0;
36506 }
36507
36508 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
36509 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
36510 rport->roles = ids->roles;
36511
36512 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
36513 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
36514 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
36515
36516 transport_setup_device(&rport->dev);
36517 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
36518 index 441a1c5..07cece7 100644
36519 --- a/drivers/scsi/sg.c
36520 +++ b/drivers/scsi/sg.c
36521 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
36522 sdp->disk->disk_name,
36523 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
36524 NULL,
36525 - (char *)arg);
36526 + (char __user *)arg);
36527 case BLKTRACESTART:
36528 return blk_trace_startstop(sdp->device->request_queue, 1);
36529 case BLKTRACESTOP:
36530 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
36531 const struct file_operations * fops;
36532 };
36533
36534 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
36535 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
36536 {"allow_dio", &adio_fops},
36537 {"debug", &debug_fops},
36538 {"def_reserved_size", &dressz_fops},
36539 @@ -2327,7 +2327,7 @@ sg_proc_init(void)
36540 {
36541 int k, mask;
36542 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
36543 - struct sg_proc_leaf * leaf;
36544 + const struct sg_proc_leaf * leaf;
36545
36546 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
36547 if (!sg_proc_sgp)
36548 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
36549 index f64250e..1ee3049 100644
36550 --- a/drivers/spi/spi-dw-pci.c
36551 +++ b/drivers/spi/spi-dw-pci.c
36552 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
36553 #define spi_resume NULL
36554 #endif
36555
36556 -static const struct pci_device_id pci_ids[] __devinitdata = {
36557 +static const struct pci_device_id pci_ids[] __devinitconst = {
36558 /* Intel MID platform SPI controller 0 */
36559 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
36560 {},
36561 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
36562 index 77eae99..b7cdcc9 100644
36563 --- a/drivers/spi/spi.c
36564 +++ b/drivers/spi/spi.c
36565 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
36566 EXPORT_SYMBOL_GPL(spi_bus_unlock);
36567
36568 /* portable code must never pass more than 32 bytes */
36569 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
36570 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
36571
36572 static u8 *buf;
36573
36574 diff --git a/drivers/staging/gma500/power.c b/drivers/staging/gma500/power.c
36575 index 436fe97..4082570 100644
36576 --- a/drivers/staging/gma500/power.c
36577 +++ b/drivers/staging/gma500/power.c
36578 @@ -266,7 +266,7 @@ bool gma_power_begin(struct drm_device *dev, bool force_on)
36579 ret = gma_resume_pci(dev->pdev);
36580 if (ret == 0) {
36581 /* FIXME: we want to defer this for Medfield/Oaktrail */
36582 - gma_resume_display(dev);
36583 + gma_resume_display(dev->pdev);
36584 psb_irq_preinstall(dev);
36585 psb_irq_postinstall(dev);
36586 pm_runtime_get(&dev->pdev->dev);
36587 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
36588 index bafccb3..e3ac78d 100644
36589 --- a/drivers/staging/hv/rndis_filter.c
36590 +++ b/drivers/staging/hv/rndis_filter.c
36591 @@ -42,7 +42,7 @@ struct rndis_device {
36592
36593 enum rndis_device_state state;
36594 bool link_state;
36595 - atomic_t new_req_id;
36596 + atomic_unchecked_t new_req_id;
36597
36598 spinlock_t request_lock;
36599 struct list_head req_list;
36600 @@ -116,7 +116,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36601 * template
36602 */
36603 set = &rndis_msg->msg.set_req;
36604 - set->req_id = atomic_inc_return(&dev->new_req_id);
36605 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36606
36607 /* Add to the request list */
36608 spin_lock_irqsave(&dev->request_lock, flags);
36609 @@ -646,7 +646,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36610
36611 /* Setup the rndis set */
36612 halt = &request->request_msg.msg.halt_req;
36613 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36614 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36615
36616 /* Ignore return since this msg is optional. */
36617 rndis_filter_send_request(dev, request);
36618 diff --git a/drivers/staging/iio/buffer_generic.h b/drivers/staging/iio/buffer_generic.h
36619 index 9e8f010..af9efb56 100644
36620 --- a/drivers/staging/iio/buffer_generic.h
36621 +++ b/drivers/staging/iio/buffer_generic.h
36622 @@ -64,7 +64,7 @@ struct iio_buffer_access_funcs {
36623
36624 int (*is_enabled)(struct iio_buffer *buffer);
36625 int (*enable)(struct iio_buffer *buffer);
36626 -};
36627 +} __no_const;
36628
36629 /**
36630 * struct iio_buffer_setup_ops - buffer setup related callbacks
36631 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
36632 index 8b307b4..a97ac91 100644
36633 --- a/drivers/staging/octeon/ethernet-rx.c
36634 +++ b/drivers/staging/octeon/ethernet-rx.c
36635 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36636 /* Increment RX stats for virtual ports */
36637 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
36638 #ifdef CONFIG_64BIT
36639 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
36640 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
36641 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
36642 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
36643 #else
36644 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
36645 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
36646 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
36647 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
36648 #endif
36649 }
36650 netif_receive_skb(skb);
36651 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36652 dev->name);
36653 */
36654 #ifdef CONFIG_64BIT
36655 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
36656 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36657 #else
36658 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
36659 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
36660 #endif
36661 dev_kfree_skb_irq(skb);
36662 }
36663 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
36664 index 076f866..2308070 100644
36665 --- a/drivers/staging/octeon/ethernet.c
36666 +++ b/drivers/staging/octeon/ethernet.c
36667 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
36668 * since the RX tasklet also increments it.
36669 */
36670 #ifdef CONFIG_64BIT
36671 - atomic64_add(rx_status.dropped_packets,
36672 - (atomic64_t *)&priv->stats.rx_dropped);
36673 + atomic64_add_unchecked(rx_status.dropped_packets,
36674 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36675 #else
36676 - atomic_add(rx_status.dropped_packets,
36677 - (atomic_t *)&priv->stats.rx_dropped);
36678 + atomic_add_unchecked(rx_status.dropped_packets,
36679 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
36680 #endif
36681 }
36682
36683 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
36684 index 7a19555..466456d 100644
36685 --- a/drivers/staging/pohmelfs/inode.c
36686 +++ b/drivers/staging/pohmelfs/inode.c
36687 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
36688 mutex_init(&psb->mcache_lock);
36689 psb->mcache_root = RB_ROOT;
36690 psb->mcache_timeout = msecs_to_jiffies(5000);
36691 - atomic_long_set(&psb->mcache_gen, 0);
36692 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
36693
36694 psb->trans_max_pages = 100;
36695
36696 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
36697 INIT_LIST_HEAD(&psb->crypto_ready_list);
36698 INIT_LIST_HEAD(&psb->crypto_active_list);
36699
36700 - atomic_set(&psb->trans_gen, 1);
36701 + atomic_set_unchecked(&psb->trans_gen, 1);
36702 atomic_long_set(&psb->total_inodes, 0);
36703
36704 mutex_init(&psb->state_lock);
36705 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
36706 index e22665c..a2a9390 100644
36707 --- a/drivers/staging/pohmelfs/mcache.c
36708 +++ b/drivers/staging/pohmelfs/mcache.c
36709 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
36710 m->data = data;
36711 m->start = start;
36712 m->size = size;
36713 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
36714 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
36715
36716 mutex_lock(&psb->mcache_lock);
36717 err = pohmelfs_mcache_insert(psb, m);
36718 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
36719 index 985b6b7..7699e05 100644
36720 --- a/drivers/staging/pohmelfs/netfs.h
36721 +++ b/drivers/staging/pohmelfs/netfs.h
36722 @@ -571,14 +571,14 @@ struct pohmelfs_config;
36723 struct pohmelfs_sb {
36724 struct rb_root mcache_root;
36725 struct mutex mcache_lock;
36726 - atomic_long_t mcache_gen;
36727 + atomic_long_unchecked_t mcache_gen;
36728 unsigned long mcache_timeout;
36729
36730 unsigned int idx;
36731
36732 unsigned int trans_retries;
36733
36734 - atomic_t trans_gen;
36735 + atomic_unchecked_t trans_gen;
36736
36737 unsigned int crypto_attached_size;
36738 unsigned int crypto_align_size;
36739 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
36740 index 06c1a74..866eebc 100644
36741 --- a/drivers/staging/pohmelfs/trans.c
36742 +++ b/drivers/staging/pohmelfs/trans.c
36743 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
36744 int err;
36745 struct netfs_cmd *cmd = t->iovec.iov_base;
36746
36747 - t->gen = atomic_inc_return(&psb->trans_gen);
36748 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
36749
36750 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
36751 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
36752 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
36753 index 86308a0..feaa925 100644
36754 --- a/drivers/staging/rtl8712/rtl871x_io.h
36755 +++ b/drivers/staging/rtl8712/rtl871x_io.h
36756 @@ -108,7 +108,7 @@ struct _io_ops {
36757 u8 *pmem);
36758 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
36759 u8 *pmem);
36760 -};
36761 +} __no_const;
36762
36763 struct io_req {
36764 struct list_head list;
36765 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
36766 index c7b5e8b..783d6cb 100644
36767 --- a/drivers/staging/sbe-2t3e3/netdev.c
36768 +++ b/drivers/staging/sbe-2t3e3/netdev.c
36769 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36770 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
36771
36772 if (rlen)
36773 - if (copy_to_user(data, &resp, rlen))
36774 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
36775 return -EFAULT;
36776
36777 return 0;
36778 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
36779 index be21617..0954e45 100644
36780 --- a/drivers/staging/usbip/usbip_common.h
36781 +++ b/drivers/staging/usbip/usbip_common.h
36782 @@ -289,7 +289,7 @@ struct usbip_device {
36783 void (*shutdown)(struct usbip_device *);
36784 void (*reset)(struct usbip_device *);
36785 void (*unusable)(struct usbip_device *);
36786 - } eh_ops;
36787 + } __no_const eh_ops;
36788 };
36789
36790 #if 0
36791 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
36792 index 88b3298..3783eee 100644
36793 --- a/drivers/staging/usbip/vhci.h
36794 +++ b/drivers/staging/usbip/vhci.h
36795 @@ -88,7 +88,7 @@ struct vhci_hcd {
36796 unsigned resuming:1;
36797 unsigned long re_timeout;
36798
36799 - atomic_t seqnum;
36800 + atomic_unchecked_t seqnum;
36801
36802 /*
36803 * NOTE:
36804 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
36805 index 2ee97e2..0420b86 100644
36806 --- a/drivers/staging/usbip/vhci_hcd.c
36807 +++ b/drivers/staging/usbip/vhci_hcd.c
36808 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
36809 return;
36810 }
36811
36812 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
36813 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36814 if (priv->seqnum == 0xffff)
36815 dev_info(&urb->dev->dev, "seqnum max\n");
36816
36817 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
36818 return -ENOMEM;
36819 }
36820
36821 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
36822 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36823 if (unlink->seqnum == 0xffff)
36824 pr_info("seqnum max\n");
36825
36826 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
36827 vdev->rhport = rhport;
36828 }
36829
36830 - atomic_set(&vhci->seqnum, 0);
36831 + atomic_set_unchecked(&vhci->seqnum, 0);
36832 spin_lock_init(&vhci->lock);
36833
36834 hcd->power_budget = 0; /* no limit */
36835 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
36836 index 3872b8c..fe6d2f4 100644
36837 --- a/drivers/staging/usbip/vhci_rx.c
36838 +++ b/drivers/staging/usbip/vhci_rx.c
36839 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
36840 if (!urb) {
36841 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
36842 pr_info("max seqnum %d\n",
36843 - atomic_read(&the_controller->seqnum));
36844 + atomic_read_unchecked(&the_controller->seqnum));
36845 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
36846 return;
36847 }
36848 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
36849 index 7735027..30eed13 100644
36850 --- a/drivers/staging/vt6655/hostap.c
36851 +++ b/drivers/staging/vt6655/hostap.c
36852 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
36853 *
36854 */
36855
36856 +static net_device_ops_no_const apdev_netdev_ops;
36857 +
36858 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36859 {
36860 PSDevice apdev_priv;
36861 struct net_device *dev = pDevice->dev;
36862 int ret;
36863 - const struct net_device_ops apdev_netdev_ops = {
36864 - .ndo_start_xmit = pDevice->tx_80211,
36865 - };
36866
36867 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36868
36869 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36870 *apdev_priv = *pDevice;
36871 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36872
36873 + /* only half broken now */
36874 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36875 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36876
36877 pDevice->apdev->type = ARPHRD_IEEE80211;
36878 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
36879 index 51b5adf..098e320 100644
36880 --- a/drivers/staging/vt6656/hostap.c
36881 +++ b/drivers/staging/vt6656/hostap.c
36882 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
36883 *
36884 */
36885
36886 +static net_device_ops_no_const apdev_netdev_ops;
36887 +
36888 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36889 {
36890 PSDevice apdev_priv;
36891 struct net_device *dev = pDevice->dev;
36892 int ret;
36893 - const struct net_device_ops apdev_netdev_ops = {
36894 - .ndo_start_xmit = pDevice->tx_80211,
36895 - };
36896
36897 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36898
36899 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36900 *apdev_priv = *pDevice;
36901 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36902
36903 + /* only half broken now */
36904 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36905 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36906
36907 pDevice->apdev->type = ARPHRD_IEEE80211;
36908 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
36909 index 7843dfd..3db105f 100644
36910 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
36911 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
36912 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
36913
36914 struct usbctlx_completor {
36915 int (*complete) (struct usbctlx_completor *);
36916 -};
36917 +} __no_const;
36918
36919 static int
36920 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
36921 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
36922 index 1ca66ea..76f1343 100644
36923 --- a/drivers/staging/zcache/tmem.c
36924 +++ b/drivers/staging/zcache/tmem.c
36925 @@ -39,7 +39,7 @@
36926 * A tmem host implementation must use this function to register callbacks
36927 * for memory allocation.
36928 */
36929 -static struct tmem_hostops tmem_hostops;
36930 +static tmem_hostops_no_const tmem_hostops;
36931
36932 static void tmem_objnode_tree_init(void);
36933
36934 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
36935 * A tmem host implementation must use this function to register
36936 * callbacks for a page-accessible memory (PAM) implementation
36937 */
36938 -static struct tmem_pamops tmem_pamops;
36939 +static tmem_pamops_no_const tmem_pamops;
36940
36941 void tmem_register_pamops(struct tmem_pamops *m)
36942 {
36943 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
36944 index ed147c4..94fc3c6 100644
36945 --- a/drivers/staging/zcache/tmem.h
36946 +++ b/drivers/staging/zcache/tmem.h
36947 @@ -180,6 +180,7 @@ struct tmem_pamops {
36948 void (*new_obj)(struct tmem_obj *);
36949 int (*replace_in_obj)(void *, struct tmem_obj *);
36950 };
36951 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
36952 extern void tmem_register_pamops(struct tmem_pamops *m);
36953
36954 /* memory allocation methods provided by the host implementation */
36955 @@ -189,6 +190,7 @@ struct tmem_hostops {
36956 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
36957 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
36958 };
36959 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
36960 extern void tmem_register_hostops(struct tmem_hostops *m);
36961
36962 /* core tmem accessor functions */
36963 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
36964 index 0c1d5c73..88e90a8 100644
36965 --- a/drivers/target/iscsi/iscsi_target.c
36966 +++ b/drivers/target/iscsi/iscsi_target.c
36967 @@ -1364,7 +1364,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
36968 * outstanding_r2ts reaches zero, go ahead and send the delayed
36969 * TASK_ABORTED status.
36970 */
36971 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
36972 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
36973 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
36974 if (--cmd->outstanding_r2ts < 1) {
36975 iscsit_stop_dataout_timer(cmd);
36976 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
36977 index 6845228..df77141 100644
36978 --- a/drivers/target/target_core_tmr.c
36979 +++ b/drivers/target/target_core_tmr.c
36980 @@ -250,7 +250,7 @@ static void core_tmr_drain_task_list(
36981 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
36982 cmd->t_task_list_num,
36983 atomic_read(&cmd->t_task_cdbs_left),
36984 - atomic_read(&cmd->t_task_cdbs_sent),
36985 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
36986 atomic_read(&cmd->t_transport_active),
36987 atomic_read(&cmd->t_transport_stop),
36988 atomic_read(&cmd->t_transport_sent));
36989 @@ -281,7 +281,7 @@ static void core_tmr_drain_task_list(
36990 pr_debug("LUN_RESET: got t_transport_active = 1 for"
36991 " task: %p, t_fe_count: %d dev: %p\n", task,
36992 fe_count, dev);
36993 - atomic_set(&cmd->t_transport_aborted, 1);
36994 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
36995 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36996
36997 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
36998 @@ -289,7 +289,7 @@ static void core_tmr_drain_task_list(
36999 }
37000 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37001 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37002 - atomic_set(&cmd->t_transport_aborted, 1);
37003 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37004 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37005
37006 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37007 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37008 index e4ddb93..2fc6e0f 100644
37009 --- a/drivers/target/target_core_transport.c
37010 +++ b/drivers/target/target_core_transport.c
37011 @@ -1343,7 +1343,7 @@ struct se_device *transport_add_device_to_core_hba(
37012
37013 dev->queue_depth = dev_limits->queue_depth;
37014 atomic_set(&dev->depth_left, dev->queue_depth);
37015 - atomic_set(&dev->dev_ordered_id, 0);
37016 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37017
37018 se_dev_set_default_attribs(dev, dev_limits);
37019
37020 @@ -1530,7 +1530,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37021 * Used to determine when ORDERED commands should go from
37022 * Dormant to Active status.
37023 */
37024 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37025 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37026 smp_mb__after_atomic_inc();
37027 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37028 cmd->se_ordered_id, cmd->sam_task_attr,
37029 @@ -1800,7 +1800,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37030 " t_transport_active: %d t_transport_stop: %d"
37031 " t_transport_sent: %d\n", cmd->t_task_list_num,
37032 atomic_read(&cmd->t_task_cdbs_left),
37033 - atomic_read(&cmd->t_task_cdbs_sent),
37034 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37035 atomic_read(&cmd->t_task_cdbs_ex_left),
37036 atomic_read(&cmd->t_transport_active),
37037 atomic_read(&cmd->t_transport_stop),
37038 @@ -2089,9 +2089,9 @@ check_depth:
37039
37040 spin_lock_irqsave(&cmd->t_state_lock, flags);
37041 task->task_flags |= (TF_ACTIVE | TF_SENT);
37042 - atomic_inc(&cmd->t_task_cdbs_sent);
37043 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37044
37045 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37046 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37047 cmd->t_task_list_num)
37048 atomic_set(&cmd->t_transport_sent, 1);
37049
37050 @@ -4296,7 +4296,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37051 atomic_set(&cmd->transport_lun_stop, 0);
37052 }
37053 if (!atomic_read(&cmd->t_transport_active) ||
37054 - atomic_read(&cmd->t_transport_aborted)) {
37055 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
37056 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37057 return false;
37058 }
37059 @@ -4545,7 +4545,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37060 {
37061 int ret = 0;
37062
37063 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37064 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37065 if (!send_status ||
37066 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37067 return 1;
37068 @@ -4582,7 +4582,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37069 */
37070 if (cmd->data_direction == DMA_TO_DEVICE) {
37071 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37072 - atomic_inc(&cmd->t_transport_aborted);
37073 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37074 smp_mb__after_atomic_inc();
37075 }
37076 }
37077 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37078 index b9040be..e3f5aab 100644
37079 --- a/drivers/tty/hvc/hvcs.c
37080 +++ b/drivers/tty/hvc/hvcs.c
37081 @@ -83,6 +83,7 @@
37082 #include <asm/hvcserver.h>
37083 #include <asm/uaccess.h>
37084 #include <asm/vio.h>
37085 +#include <asm/local.h>
37086
37087 /*
37088 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37089 @@ -270,7 +271,7 @@ struct hvcs_struct {
37090 unsigned int index;
37091
37092 struct tty_struct *tty;
37093 - int open_count;
37094 + local_t open_count;
37095
37096 /*
37097 * Used to tell the driver kernel_thread what operations need to take
37098 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37099
37100 spin_lock_irqsave(&hvcsd->lock, flags);
37101
37102 - if (hvcsd->open_count > 0) {
37103 + if (local_read(&hvcsd->open_count) > 0) {
37104 spin_unlock_irqrestore(&hvcsd->lock, flags);
37105 printk(KERN_INFO "HVCS: vterm state unchanged. "
37106 "The hvcs device node is still in use.\n");
37107 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37108 if ((retval = hvcs_partner_connect(hvcsd)))
37109 goto error_release;
37110
37111 - hvcsd->open_count = 1;
37112 + local_set(&hvcsd->open_count, 1);
37113 hvcsd->tty = tty;
37114 tty->driver_data = hvcsd;
37115
37116 @@ -1179,7 +1180,7 @@ fast_open:
37117
37118 spin_lock_irqsave(&hvcsd->lock, flags);
37119 kref_get(&hvcsd->kref);
37120 - hvcsd->open_count++;
37121 + local_inc(&hvcsd->open_count);
37122 hvcsd->todo_mask |= HVCS_SCHED_READ;
37123 spin_unlock_irqrestore(&hvcsd->lock, flags);
37124
37125 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37126 hvcsd = tty->driver_data;
37127
37128 spin_lock_irqsave(&hvcsd->lock, flags);
37129 - if (--hvcsd->open_count == 0) {
37130 + if (local_dec_and_test(&hvcsd->open_count)) {
37131
37132 vio_disable_interrupts(hvcsd->vdev);
37133
37134 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37135 free_irq(irq, hvcsd);
37136 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37137 return;
37138 - } else if (hvcsd->open_count < 0) {
37139 + } else if (local_read(&hvcsd->open_count) < 0) {
37140 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37141 " is missmanaged.\n",
37142 - hvcsd->vdev->unit_address, hvcsd->open_count);
37143 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37144 }
37145
37146 spin_unlock_irqrestore(&hvcsd->lock, flags);
37147 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37148
37149 spin_lock_irqsave(&hvcsd->lock, flags);
37150 /* Preserve this so that we know how many kref refs to put */
37151 - temp_open_count = hvcsd->open_count;
37152 + temp_open_count = local_read(&hvcsd->open_count);
37153
37154 /*
37155 * Don't kref put inside the spinlock because the destruction
37156 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37157 hvcsd->tty->driver_data = NULL;
37158 hvcsd->tty = NULL;
37159
37160 - hvcsd->open_count = 0;
37161 + local_set(&hvcsd->open_count, 0);
37162
37163 /* This will drop any buffered data on the floor which is OK in a hangup
37164 * scenario. */
37165 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37166 * the middle of a write operation? This is a crummy place to do this
37167 * but we want to keep it all in the spinlock.
37168 */
37169 - if (hvcsd->open_count <= 0) {
37170 + if (local_read(&hvcsd->open_count) <= 0) {
37171 spin_unlock_irqrestore(&hvcsd->lock, flags);
37172 return -ENODEV;
37173 }
37174 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37175 {
37176 struct hvcs_struct *hvcsd = tty->driver_data;
37177
37178 - if (!hvcsd || hvcsd->open_count <= 0)
37179 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37180 return 0;
37181
37182 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37183 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37184 index ef92869..f4ebd88 100644
37185 --- a/drivers/tty/ipwireless/tty.c
37186 +++ b/drivers/tty/ipwireless/tty.c
37187 @@ -29,6 +29,7 @@
37188 #include <linux/tty_driver.h>
37189 #include <linux/tty_flip.h>
37190 #include <linux/uaccess.h>
37191 +#include <asm/local.h>
37192
37193 #include "tty.h"
37194 #include "network.h"
37195 @@ -51,7 +52,7 @@ struct ipw_tty {
37196 int tty_type;
37197 struct ipw_network *network;
37198 struct tty_struct *linux_tty;
37199 - int open_count;
37200 + local_t open_count;
37201 unsigned int control_lines;
37202 struct mutex ipw_tty_mutex;
37203 int tx_bytes_queued;
37204 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37205 mutex_unlock(&tty->ipw_tty_mutex);
37206 return -ENODEV;
37207 }
37208 - if (tty->open_count == 0)
37209 + if (local_read(&tty->open_count) == 0)
37210 tty->tx_bytes_queued = 0;
37211
37212 - tty->open_count++;
37213 + local_inc(&tty->open_count);
37214
37215 tty->linux_tty = linux_tty;
37216 linux_tty->driver_data = tty;
37217 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37218
37219 static void do_ipw_close(struct ipw_tty *tty)
37220 {
37221 - tty->open_count--;
37222 -
37223 - if (tty->open_count == 0) {
37224 + if (local_dec_return(&tty->open_count) == 0) {
37225 struct tty_struct *linux_tty = tty->linux_tty;
37226
37227 if (linux_tty != NULL) {
37228 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37229 return;
37230
37231 mutex_lock(&tty->ipw_tty_mutex);
37232 - if (tty->open_count == 0) {
37233 + if (local_read(&tty->open_count) == 0) {
37234 mutex_unlock(&tty->ipw_tty_mutex);
37235 return;
37236 }
37237 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37238 return;
37239 }
37240
37241 - if (!tty->open_count) {
37242 + if (!local_read(&tty->open_count)) {
37243 mutex_unlock(&tty->ipw_tty_mutex);
37244 return;
37245 }
37246 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37247 return -ENODEV;
37248
37249 mutex_lock(&tty->ipw_tty_mutex);
37250 - if (!tty->open_count) {
37251 + if (!local_read(&tty->open_count)) {
37252 mutex_unlock(&tty->ipw_tty_mutex);
37253 return -EINVAL;
37254 }
37255 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37256 if (!tty)
37257 return -ENODEV;
37258
37259 - if (!tty->open_count)
37260 + if (!local_read(&tty->open_count))
37261 return -EINVAL;
37262
37263 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37264 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37265 if (!tty)
37266 return 0;
37267
37268 - if (!tty->open_count)
37269 + if (!local_read(&tty->open_count))
37270 return 0;
37271
37272 return tty->tx_bytes_queued;
37273 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37274 if (!tty)
37275 return -ENODEV;
37276
37277 - if (!tty->open_count)
37278 + if (!local_read(&tty->open_count))
37279 return -EINVAL;
37280
37281 return get_control_lines(tty);
37282 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37283 if (!tty)
37284 return -ENODEV;
37285
37286 - if (!tty->open_count)
37287 + if (!local_read(&tty->open_count))
37288 return -EINVAL;
37289
37290 return set_control_lines(tty, set, clear);
37291 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37292 if (!tty)
37293 return -ENODEV;
37294
37295 - if (!tty->open_count)
37296 + if (!local_read(&tty->open_count))
37297 return -EINVAL;
37298
37299 /* FIXME: Exactly how is the tty object locked here .. */
37300 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37301 against a parallel ioctl etc */
37302 mutex_lock(&ttyj->ipw_tty_mutex);
37303 }
37304 - while (ttyj->open_count)
37305 + while (local_read(&ttyj->open_count))
37306 do_ipw_close(ttyj);
37307 ipwireless_disassociate_network_ttys(network,
37308 ttyj->channel_idx);
37309 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37310 index fc7bbba..9527e93 100644
37311 --- a/drivers/tty/n_gsm.c
37312 +++ b/drivers/tty/n_gsm.c
37313 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37314 kref_init(&dlci->ref);
37315 mutex_init(&dlci->mutex);
37316 dlci->fifo = &dlci->_fifo;
37317 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37318 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37319 kfree(dlci);
37320 return NULL;
37321 }
37322 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37323 index 39d6ab6..eb97f41 100644
37324 --- a/drivers/tty/n_tty.c
37325 +++ b/drivers/tty/n_tty.c
37326 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37327 {
37328 *ops = tty_ldisc_N_TTY;
37329 ops->owner = NULL;
37330 - ops->refcount = ops->flags = 0;
37331 + atomic_set(&ops->refcount, 0);
37332 + ops->flags = 0;
37333 }
37334 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37335 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37336 index e18604b..a7d5a11 100644
37337 --- a/drivers/tty/pty.c
37338 +++ b/drivers/tty/pty.c
37339 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
37340 register_sysctl_table(pty_root_table);
37341
37342 /* Now create the /dev/ptmx special device */
37343 + pax_open_kernel();
37344 tty_default_fops(&ptmx_fops);
37345 - ptmx_fops.open = ptmx_open;
37346 + *(void **)&ptmx_fops.open = ptmx_open;
37347 + pax_close_kernel();
37348
37349 cdev_init(&ptmx_cdev, &ptmx_fops);
37350 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37351 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37352 index 2b42a01..32a2ed3 100644
37353 --- a/drivers/tty/serial/kgdboc.c
37354 +++ b/drivers/tty/serial/kgdboc.c
37355 @@ -24,8 +24,9 @@
37356 #define MAX_CONFIG_LEN 40
37357
37358 static struct kgdb_io kgdboc_io_ops;
37359 +static struct kgdb_io kgdboc_io_ops_console;
37360
37361 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37362 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37363 static int configured = -1;
37364
37365 static char config[MAX_CONFIG_LEN];
37366 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37367 kgdboc_unregister_kbd();
37368 if (configured == 1)
37369 kgdb_unregister_io_module(&kgdboc_io_ops);
37370 + else if (configured == 2)
37371 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37372 }
37373
37374 static int configure_kgdboc(void)
37375 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37376 int err;
37377 char *cptr = config;
37378 struct console *cons;
37379 + int is_console = 0;
37380
37381 err = kgdboc_option_setup(config);
37382 if (err || !strlen(config) || isspace(config[0]))
37383 goto noconfig;
37384
37385 err = -ENODEV;
37386 - kgdboc_io_ops.is_console = 0;
37387 kgdb_tty_driver = NULL;
37388
37389 kgdboc_use_kms = 0;
37390 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37391 int idx;
37392 if (cons->device && cons->device(cons, &idx) == p &&
37393 idx == tty_line) {
37394 - kgdboc_io_ops.is_console = 1;
37395 + is_console = 1;
37396 break;
37397 }
37398 cons = cons->next;
37399 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37400 kgdb_tty_line = tty_line;
37401
37402 do_register:
37403 - err = kgdb_register_io_module(&kgdboc_io_ops);
37404 + if (is_console) {
37405 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37406 + configured = 2;
37407 + } else {
37408 + err = kgdb_register_io_module(&kgdboc_io_ops);
37409 + configured = 1;
37410 + }
37411 if (err)
37412 goto noconfig;
37413
37414 - configured = 1;
37415 -
37416 return 0;
37417
37418 noconfig:
37419 @@ -213,7 +220,7 @@ noconfig:
37420 static int __init init_kgdboc(void)
37421 {
37422 /* Already configured? */
37423 - if (configured == 1)
37424 + if (configured >= 1)
37425 return 0;
37426
37427 return configure_kgdboc();
37428 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37429 if (config[len - 1] == '\n')
37430 config[len - 1] = '\0';
37431
37432 - if (configured == 1)
37433 + if (configured >= 1)
37434 cleanup_kgdboc();
37435
37436 /* Go and configure with the new params. */
37437 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37438 .post_exception = kgdboc_post_exp_handler,
37439 };
37440
37441 +static struct kgdb_io kgdboc_io_ops_console = {
37442 + .name = "kgdboc",
37443 + .read_char = kgdboc_get_char,
37444 + .write_char = kgdboc_put_char,
37445 + .pre_exception = kgdboc_pre_exp_handler,
37446 + .post_exception = kgdboc_post_exp_handler,
37447 + .is_console = 1
37448 +};
37449 +
37450 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37451 /* This is only available if kgdboc is a built in for early debugging */
37452 static int __init kgdboc_early_init(char *opt)
37453 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37454 index 05085be..67eadb0 100644
37455 --- a/drivers/tty/tty_io.c
37456 +++ b/drivers/tty/tty_io.c
37457 @@ -3240,7 +3240,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37458
37459 void tty_default_fops(struct file_operations *fops)
37460 {
37461 - *fops = tty_fops;
37462 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37463 }
37464
37465 /*
37466 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37467 index 8e0924f..4204eb4 100644
37468 --- a/drivers/tty/tty_ldisc.c
37469 +++ b/drivers/tty/tty_ldisc.c
37470 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37471 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37472 struct tty_ldisc_ops *ldo = ld->ops;
37473
37474 - ldo->refcount--;
37475 + atomic_dec(&ldo->refcount);
37476 module_put(ldo->owner);
37477 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37478
37479 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37480 spin_lock_irqsave(&tty_ldisc_lock, flags);
37481 tty_ldiscs[disc] = new_ldisc;
37482 new_ldisc->num = disc;
37483 - new_ldisc->refcount = 0;
37484 + atomic_set(&new_ldisc->refcount, 0);
37485 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37486
37487 return ret;
37488 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
37489 return -EINVAL;
37490
37491 spin_lock_irqsave(&tty_ldisc_lock, flags);
37492 - if (tty_ldiscs[disc]->refcount)
37493 + if (atomic_read(&tty_ldiscs[disc]->refcount))
37494 ret = -EBUSY;
37495 else
37496 tty_ldiscs[disc] = NULL;
37497 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37498 if (ldops) {
37499 ret = ERR_PTR(-EAGAIN);
37500 if (try_module_get(ldops->owner)) {
37501 - ldops->refcount++;
37502 + atomic_inc(&ldops->refcount);
37503 ret = ldops;
37504 }
37505 }
37506 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37507 unsigned long flags;
37508
37509 spin_lock_irqsave(&tty_ldisc_lock, flags);
37510 - ldops->refcount--;
37511 + atomic_dec(&ldops->refcount);
37512 module_put(ldops->owner);
37513 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37514 }
37515 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37516 index a605549..6bd3c96 100644
37517 --- a/drivers/tty/vt/keyboard.c
37518 +++ b/drivers/tty/vt/keyboard.c
37519 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37520 kbd->kbdmode == VC_OFF) &&
37521 value != KVAL(K_SAK))
37522 return; /* SAK is allowed even in raw mode */
37523 +
37524 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37525 + {
37526 + void *func = fn_handler[value];
37527 + if (func == fn_show_state || func == fn_show_ptregs ||
37528 + func == fn_show_mem)
37529 + return;
37530 + }
37531 +#endif
37532 +
37533 fn_handler[value](vc);
37534 }
37535
37536 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
37537 index 65447c5..0526f0a 100644
37538 --- a/drivers/tty/vt/vt_ioctl.c
37539 +++ b/drivers/tty/vt/vt_ioctl.c
37540 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37541 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37542 return -EFAULT;
37543
37544 - if (!capable(CAP_SYS_TTY_CONFIG))
37545 - perm = 0;
37546 -
37547 switch (cmd) {
37548 case KDGKBENT:
37549 key_map = key_maps[s];
37550 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37551 val = (i ? K_HOLE : K_NOSUCHMAP);
37552 return put_user(val, &user_kbe->kb_value);
37553 case KDSKBENT:
37554 + if (!capable(CAP_SYS_TTY_CONFIG))
37555 + perm = 0;
37556 +
37557 if (!perm)
37558 return -EPERM;
37559 if (!i && v == K_NOSUCHMAP) {
37560 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37561 int i, j, k;
37562 int ret;
37563
37564 - if (!capable(CAP_SYS_TTY_CONFIG))
37565 - perm = 0;
37566 -
37567 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37568 if (!kbs) {
37569 ret = -ENOMEM;
37570 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37571 kfree(kbs);
37572 return ((p && *p) ? -EOVERFLOW : 0);
37573 case KDSKBSENT:
37574 + if (!capable(CAP_SYS_TTY_CONFIG))
37575 + perm = 0;
37576 +
37577 if (!perm) {
37578 ret = -EPERM;
37579 goto reterr;
37580 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37581 index a783d53..cb30d94 100644
37582 --- a/drivers/uio/uio.c
37583 +++ b/drivers/uio/uio.c
37584 @@ -25,6 +25,7 @@
37585 #include <linux/kobject.h>
37586 #include <linux/cdev.h>
37587 #include <linux/uio_driver.h>
37588 +#include <asm/local.h>
37589
37590 #define UIO_MAX_DEVICES (1U << MINORBITS)
37591
37592 @@ -32,10 +33,10 @@ struct uio_device {
37593 struct module *owner;
37594 struct device *dev;
37595 int minor;
37596 - atomic_t event;
37597 + atomic_unchecked_t event;
37598 struct fasync_struct *async_queue;
37599 wait_queue_head_t wait;
37600 - int vma_count;
37601 + local_t vma_count;
37602 struct uio_info *info;
37603 struct kobject *map_dir;
37604 struct kobject *portio_dir;
37605 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37606 struct device_attribute *attr, char *buf)
37607 {
37608 struct uio_device *idev = dev_get_drvdata(dev);
37609 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37610 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37611 }
37612
37613 static struct device_attribute uio_class_attributes[] = {
37614 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37615 {
37616 struct uio_device *idev = info->uio_dev;
37617
37618 - atomic_inc(&idev->event);
37619 + atomic_inc_unchecked(&idev->event);
37620 wake_up_interruptible(&idev->wait);
37621 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37622 }
37623 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
37624 }
37625
37626 listener->dev = idev;
37627 - listener->event_count = atomic_read(&idev->event);
37628 + listener->event_count = atomic_read_unchecked(&idev->event);
37629 filep->private_data = listener;
37630
37631 if (idev->info->open) {
37632 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
37633 return -EIO;
37634
37635 poll_wait(filep, &idev->wait, wait);
37636 - if (listener->event_count != atomic_read(&idev->event))
37637 + if (listener->event_count != atomic_read_unchecked(&idev->event))
37638 return POLLIN | POLLRDNORM;
37639 return 0;
37640 }
37641 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
37642 do {
37643 set_current_state(TASK_INTERRUPTIBLE);
37644
37645 - event_count = atomic_read(&idev->event);
37646 + event_count = atomic_read_unchecked(&idev->event);
37647 if (event_count != listener->event_count) {
37648 if (copy_to_user(buf, &event_count, count))
37649 retval = -EFAULT;
37650 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
37651 static void uio_vma_open(struct vm_area_struct *vma)
37652 {
37653 struct uio_device *idev = vma->vm_private_data;
37654 - idev->vma_count++;
37655 + local_inc(&idev->vma_count);
37656 }
37657
37658 static void uio_vma_close(struct vm_area_struct *vma)
37659 {
37660 struct uio_device *idev = vma->vm_private_data;
37661 - idev->vma_count--;
37662 + local_dec(&idev->vma_count);
37663 }
37664
37665 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
37666 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
37667 idev->owner = owner;
37668 idev->info = info;
37669 init_waitqueue_head(&idev->wait);
37670 - atomic_set(&idev->event, 0);
37671 + atomic_set_unchecked(&idev->event, 0);
37672
37673 ret = uio_get_minor(idev);
37674 if (ret)
37675 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
37676 index a845f8b..4f54072 100644
37677 --- a/drivers/usb/atm/cxacru.c
37678 +++ b/drivers/usb/atm/cxacru.c
37679 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
37680 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
37681 if (ret < 2)
37682 return -EINVAL;
37683 - if (index < 0 || index > 0x7f)
37684 + if (index > 0x7f)
37685 return -EINVAL;
37686 pos += tmp;
37687
37688 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
37689 index d3448ca..d2864ca 100644
37690 --- a/drivers/usb/atm/usbatm.c
37691 +++ b/drivers/usb/atm/usbatm.c
37692 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37693 if (printk_ratelimit())
37694 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
37695 __func__, vpi, vci);
37696 - atomic_inc(&vcc->stats->rx_err);
37697 + atomic_inc_unchecked(&vcc->stats->rx_err);
37698 return;
37699 }
37700
37701 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37702 if (length > ATM_MAX_AAL5_PDU) {
37703 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
37704 __func__, length, vcc);
37705 - atomic_inc(&vcc->stats->rx_err);
37706 + atomic_inc_unchecked(&vcc->stats->rx_err);
37707 goto out;
37708 }
37709
37710 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37711 if (sarb->len < pdu_length) {
37712 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
37713 __func__, pdu_length, sarb->len, vcc);
37714 - atomic_inc(&vcc->stats->rx_err);
37715 + atomic_inc_unchecked(&vcc->stats->rx_err);
37716 goto out;
37717 }
37718
37719 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
37720 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
37721 __func__, vcc);
37722 - atomic_inc(&vcc->stats->rx_err);
37723 + atomic_inc_unchecked(&vcc->stats->rx_err);
37724 goto out;
37725 }
37726
37727 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37728 if (printk_ratelimit())
37729 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
37730 __func__, length);
37731 - atomic_inc(&vcc->stats->rx_drop);
37732 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37733 goto out;
37734 }
37735
37736 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37737
37738 vcc->push(vcc, skb);
37739
37740 - atomic_inc(&vcc->stats->rx);
37741 + atomic_inc_unchecked(&vcc->stats->rx);
37742 out:
37743 skb_trim(sarb, 0);
37744 }
37745 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
37746 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
37747
37748 usbatm_pop(vcc, skb);
37749 - atomic_inc(&vcc->stats->tx);
37750 + atomic_inc_unchecked(&vcc->stats->tx);
37751
37752 skb = skb_dequeue(&instance->sndqueue);
37753 }
37754 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
37755 if (!left--)
37756 return sprintf(page,
37757 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
37758 - atomic_read(&atm_dev->stats.aal5.tx),
37759 - atomic_read(&atm_dev->stats.aal5.tx_err),
37760 - atomic_read(&atm_dev->stats.aal5.rx),
37761 - atomic_read(&atm_dev->stats.aal5.rx_err),
37762 - atomic_read(&atm_dev->stats.aal5.rx_drop));
37763 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
37764 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
37765 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
37766 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
37767 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
37768
37769 if (!left--) {
37770 if (instance->disconnected)
37771 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
37772 index d956965..4179a77 100644
37773 --- a/drivers/usb/core/devices.c
37774 +++ b/drivers/usb/core/devices.c
37775 @@ -126,7 +126,7 @@ static const char format_endpt[] =
37776 * time it gets called.
37777 */
37778 static struct device_connect_event {
37779 - atomic_t count;
37780 + atomic_unchecked_t count;
37781 wait_queue_head_t wait;
37782 } device_event = {
37783 .count = ATOMIC_INIT(1),
37784 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
37785
37786 void usbfs_conn_disc_event(void)
37787 {
37788 - atomic_add(2, &device_event.count);
37789 + atomic_add_unchecked(2, &device_event.count);
37790 wake_up(&device_event.wait);
37791 }
37792
37793 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
37794
37795 poll_wait(file, &device_event.wait, wait);
37796
37797 - event_count = atomic_read(&device_event.count);
37798 + event_count = atomic_read_unchecked(&device_event.count);
37799 if (file->f_version != event_count) {
37800 file->f_version = event_count;
37801 return POLLIN | POLLRDNORM;
37802 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
37803 index b3bdfed..a9460e0 100644
37804 --- a/drivers/usb/core/message.c
37805 +++ b/drivers/usb/core/message.c
37806 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
37807 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
37808 if (buf) {
37809 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
37810 - if (len > 0) {
37811 - smallbuf = kmalloc(++len, GFP_NOIO);
37812 + if (len++ > 0) {
37813 + smallbuf = kmalloc(len, GFP_NOIO);
37814 if (!smallbuf)
37815 return buf;
37816 memcpy(smallbuf, buf, len);
37817 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
37818 index 1fc8f12..20647c1 100644
37819 --- a/drivers/usb/early/ehci-dbgp.c
37820 +++ b/drivers/usb/early/ehci-dbgp.c
37821 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
37822
37823 #ifdef CONFIG_KGDB
37824 static struct kgdb_io kgdbdbgp_io_ops;
37825 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
37826 +static struct kgdb_io kgdbdbgp_io_ops_console;
37827 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
37828 #else
37829 #define dbgp_kgdb_mode (0)
37830 #endif
37831 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
37832 .write_char = kgdbdbgp_write_char,
37833 };
37834
37835 +static struct kgdb_io kgdbdbgp_io_ops_console = {
37836 + .name = "kgdbdbgp",
37837 + .read_char = kgdbdbgp_read_char,
37838 + .write_char = kgdbdbgp_write_char,
37839 + .is_console = 1
37840 +};
37841 +
37842 static int kgdbdbgp_wait_time;
37843
37844 static int __init kgdbdbgp_parse_config(char *str)
37845 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
37846 ptr++;
37847 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
37848 }
37849 - kgdb_register_io_module(&kgdbdbgp_io_ops);
37850 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
37851 + if (early_dbgp_console.index != -1)
37852 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
37853 + else
37854 + kgdb_register_io_module(&kgdbdbgp_io_ops);
37855
37856 return 0;
37857 }
37858 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
37859 index d6bea3e..60b250e 100644
37860 --- a/drivers/usb/wusbcore/wa-hc.h
37861 +++ b/drivers/usb/wusbcore/wa-hc.h
37862 @@ -192,7 +192,7 @@ struct wahc {
37863 struct list_head xfer_delayed_list;
37864 spinlock_t xfer_list_lock;
37865 struct work_struct xfer_work;
37866 - atomic_t xfer_id_count;
37867 + atomic_unchecked_t xfer_id_count;
37868 };
37869
37870
37871 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
37872 INIT_LIST_HEAD(&wa->xfer_delayed_list);
37873 spin_lock_init(&wa->xfer_list_lock);
37874 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
37875 - atomic_set(&wa->xfer_id_count, 1);
37876 + atomic_set_unchecked(&wa->xfer_id_count, 1);
37877 }
37878
37879 /**
37880 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
37881 index 57c01ab..8a05959 100644
37882 --- a/drivers/usb/wusbcore/wa-xfer.c
37883 +++ b/drivers/usb/wusbcore/wa-xfer.c
37884 @@ -296,7 +296,7 @@ out:
37885 */
37886 static void wa_xfer_id_init(struct wa_xfer *xfer)
37887 {
37888 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
37889 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
37890 }
37891
37892 /*
37893 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
37894 index c14c42b..f955cc2 100644
37895 --- a/drivers/vhost/vhost.c
37896 +++ b/drivers/vhost/vhost.c
37897 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
37898 return 0;
37899 }
37900
37901 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
37902 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
37903 {
37904 struct file *eventfp, *filep = NULL,
37905 *pollstart = NULL, *pollstop = NULL;
37906 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
37907 index b0b2ac3..89a4399 100644
37908 --- a/drivers/video/aty/aty128fb.c
37909 +++ b/drivers/video/aty/aty128fb.c
37910 @@ -148,7 +148,7 @@ enum {
37911 };
37912
37913 /* Must match above enum */
37914 -static const char *r128_family[] __devinitdata = {
37915 +static const char *r128_family[] __devinitconst = {
37916 "AGP",
37917 "PCI",
37918 "PRO AGP",
37919 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
37920 index 5c3960d..15cf8fc 100644
37921 --- a/drivers/video/fbcmap.c
37922 +++ b/drivers/video/fbcmap.c
37923 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
37924 rc = -ENODEV;
37925 goto out;
37926 }
37927 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
37928 - !info->fbops->fb_setcmap)) {
37929 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
37930 rc = -EINVAL;
37931 goto out1;
37932 }
37933 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
37934 index ad93629..e020fc3 100644
37935 --- a/drivers/video/fbmem.c
37936 +++ b/drivers/video/fbmem.c
37937 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37938 image->dx += image->width + 8;
37939 }
37940 } else if (rotate == FB_ROTATE_UD) {
37941 - for (x = 0; x < num && image->dx >= 0; x++) {
37942 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
37943 info->fbops->fb_imageblit(info, image);
37944 image->dx -= image->width + 8;
37945 }
37946 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37947 image->dy += image->height + 8;
37948 }
37949 } else if (rotate == FB_ROTATE_CCW) {
37950 - for (x = 0; x < num && image->dy >= 0; x++) {
37951 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
37952 info->fbops->fb_imageblit(info, image);
37953 image->dy -= image->height + 8;
37954 }
37955 @@ -1143,7 +1143,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
37956 return -EFAULT;
37957 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
37958 return -EINVAL;
37959 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
37960 + if (con2fb.framebuffer >= FB_MAX)
37961 return -EINVAL;
37962 if (!registered_fb[con2fb.framebuffer])
37963 request_module("fb%d", con2fb.framebuffer);
37964 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
37965 index 5a5d092..265c5ed 100644
37966 --- a/drivers/video/geode/gx1fb_core.c
37967 +++ b/drivers/video/geode/gx1fb_core.c
37968 @@ -29,7 +29,7 @@ static int crt_option = 1;
37969 static char panel_option[32] = "";
37970
37971 /* Modes relevant to the GX1 (taken from modedb.c) */
37972 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
37973 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
37974 /* 640x480-60 VESA */
37975 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
37976 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
37977 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
37978 index 0fad23f..0e9afa4 100644
37979 --- a/drivers/video/gxt4500.c
37980 +++ b/drivers/video/gxt4500.c
37981 @@ -156,7 +156,7 @@ struct gxt4500_par {
37982 static char *mode_option;
37983
37984 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
37985 -static const struct fb_videomode defaultmode __devinitdata = {
37986 +static const struct fb_videomode defaultmode __devinitconst = {
37987 .refresh = 60,
37988 .xres = 1280,
37989 .yres = 1024,
37990 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
37991 return 0;
37992 }
37993
37994 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
37995 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
37996 .id = "IBM GXT4500P",
37997 .type = FB_TYPE_PACKED_PIXELS,
37998 .visual = FB_VISUAL_PSEUDOCOLOR,
37999 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38000 index 7672d2e..b56437f 100644
38001 --- a/drivers/video/i810/i810_accel.c
38002 +++ b/drivers/video/i810/i810_accel.c
38003 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38004 }
38005 }
38006 printk("ringbuffer lockup!!!\n");
38007 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38008 i810_report_error(mmio);
38009 par->dev_flags |= LOCKUP;
38010 info->pixmap.scan_align = 1;
38011 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38012 index 318f6fb..9a389c1 100644
38013 --- a/drivers/video/i810/i810_main.c
38014 +++ b/drivers/video/i810/i810_main.c
38015 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38016 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38017
38018 /* PCI */
38019 -static const char *i810_pci_list[] __devinitdata = {
38020 +static const char *i810_pci_list[] __devinitconst = {
38021 "Intel(R) 810 Framebuffer Device" ,
38022 "Intel(R) 810-DC100 Framebuffer Device" ,
38023 "Intel(R) 810E Framebuffer Device" ,
38024 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38025 index de36693..3c63fc2 100644
38026 --- a/drivers/video/jz4740_fb.c
38027 +++ b/drivers/video/jz4740_fb.c
38028 @@ -136,7 +136,7 @@ struct jzfb {
38029 uint32_t pseudo_palette[16];
38030 };
38031
38032 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38033 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38034 .id = "JZ4740 FB",
38035 .type = FB_TYPE_PACKED_PIXELS,
38036 .visual = FB_VISUAL_TRUECOLOR,
38037 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38038 index 3c14e43..eafa544 100644
38039 --- a/drivers/video/logo/logo_linux_clut224.ppm
38040 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38041 @@ -1,1604 +1,1123 @@
38042 P3
38043 -# Standard 224-color Linux logo
38044 80 80
38045 255
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 0 0 0
38054 - 0 0 0 0 0 0 0 0 0 0 0 0
38055 - 6 6 6 6 6 6 10 10 10 10 10 10
38056 - 10 10 10 6 6 6 6 6 6 6 6 6
38057 - 0 0 0 0 0 0 0 0 0 0 0 0
38058 - 0 0 0 0 0 0 0 0 0 0 0 0
38059 - 0 0 0 0 0 0 0 0 0 0 0 0
38060 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
38068 - 0 0 0 0 0 0 0 0 0 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 0 0 0
38074 - 0 0 0 6 6 6 10 10 10 14 14 14
38075 - 22 22 22 26 26 26 30 30 30 34 34 34
38076 - 30 30 30 30 30 30 26 26 26 18 18 18
38077 - 14 14 14 10 10 10 6 6 6 0 0 0
38078 - 0 0 0 0 0 0 0 0 0 0 0 0
38079 - 0 0 0 0 0 0 0 0 0 0 0 0
38080 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 0
38088 - 0 0 0 0 0 0 0 0 0 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 0 0 0
38094 - 6 6 6 14 14 14 26 26 26 42 42 42
38095 - 54 54 54 66 66 66 78 78 78 78 78 78
38096 - 78 78 78 74 74 74 66 66 66 54 54 54
38097 - 42 42 42 26 26 26 18 18 18 10 10 10
38098 - 6 6 6 0 0 0 0 0 0 0 0 0
38099 - 0 0 0 0 0 0 0 0 0 0 0 0
38100 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0 0 0 0 0 0 0
38108 - 0 0 0 0 0 0 0 0 0 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 - 22 22 22 42 42 42 66 66 66 86 86 86
38115 - 66 66 66 38 38 38 38 38 38 22 22 22
38116 - 26 26 26 34 34 34 54 54 54 66 66 66
38117 - 86 86 86 70 70 70 46 46 46 26 26 26
38118 - 14 14 14 6 6 6 0 0 0 0 0 0
38119 - 0 0 0 0 0 0 0 0 0 0 0 0
38120 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 10 10 10 26 26 26
38134 - 50 50 50 82 82 82 58 58 58 6 6 6
38135 - 2 2 6 2 2 6 2 2 6 2 2 6
38136 - 2 2 6 2 2 6 2 2 6 2 2 6
38137 - 6 6 6 54 54 54 86 86 86 66 66 66
38138 - 38 38 38 18 18 18 6 6 6 0 0 0
38139 - 0 0 0 0 0 0 0 0 0 0 0 0
38140 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
38154 - 78 78 78 34 34 34 2 2 6 2 2 6
38155 - 2 2 6 2 2 6 2 2 6 2 2 6
38156 - 2 2 6 2 2 6 2 2 6 2 2 6
38157 - 2 2 6 2 2 6 6 6 6 70 70 70
38158 - 78 78 78 46 46 46 22 22 22 6 6 6
38159 - 0 0 0 0 0 0 0 0 0 0 0 0
38160 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
38174 - 26 26 26 2 2 6 2 2 6 2 2 6
38175 - 2 2 6 2 2 6 2 2 6 2 2 6
38176 - 2 2 6 2 2 6 2 2 6 14 14 14
38177 - 46 46 46 34 34 34 6 6 6 2 2 6
38178 - 42 42 42 78 78 78 42 42 42 18 18 18
38179 - 6 6 6 0 0 0 0 0 0 0 0 0
38180 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
38194 - 2 2 6 2 2 6 2 2 6 2 2 6
38195 - 2 2 6 2 2 6 2 2 6 2 2 6
38196 - 2 2 6 2 2 6 2 2 6 26 26 26
38197 - 86 86 86 101 101 101 46 46 46 10 10 10
38198 - 2 2 6 58 58 58 70 70 70 34 34 34
38199 - 10 10 10 0 0 0 0 0 0 0 0 0
38200 - 0 0 0 0 0 0 0 0 0 0 0 0
38201 - 0 0 0 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 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
38214 - 2 2 6 2 2 6 2 2 6 2 2 6
38215 - 2 2 6 2 2 6 2 2 6 2 2 6
38216 - 2 2 6 2 2 6 2 2 6 30 30 30
38217 - 94 94 94 94 94 94 58 58 58 26 26 26
38218 - 2 2 6 6 6 6 78 78 78 54 54 54
38219 - 22 22 22 6 6 6 0 0 0 0 0 0
38220 - 0 0 0 0 0 0 0 0 0 0 0 0
38221 - 0 0 0 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 6 6 6
38233 - 22 22 22 62 62 62 62 62 62 2 2 6
38234 - 2 2 6 2 2 6 2 2 6 2 2 6
38235 - 2 2 6 2 2 6 2 2 6 2 2 6
38236 - 2 2 6 2 2 6 2 2 6 26 26 26
38237 - 54 54 54 38 38 38 18 18 18 10 10 10
38238 - 2 2 6 2 2 6 34 34 34 82 82 82
38239 - 38 38 38 14 14 14 0 0 0 0 0 0
38240 - 0 0 0 0 0 0 0 0 0 0 0 0
38241 - 0 0 0 0 0 0 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 1 0 0 1 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 6 6 6
38253 - 30 30 30 78 78 78 30 30 30 2 2 6
38254 - 2 2 6 2 2 6 2 2 6 2 2 6
38255 - 2 2 6 2 2 6 2 2 6 2 2 6
38256 - 2 2 6 2 2 6 2 2 6 10 10 10
38257 - 10 10 10 2 2 6 2 2 6 2 2 6
38258 - 2 2 6 2 2 6 2 2 6 78 78 78
38259 - 50 50 50 18 18 18 6 6 6 0 0 0
38260 - 0 0 0 0 0 0 0 0 0 0 0 0
38261 - 0 0 0 0 0 0 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 1 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 10 10 10
38273 - 38 38 38 86 86 86 14 14 14 2 2 6
38274 - 2 2 6 2 2 6 2 2 6 2 2 6
38275 - 2 2 6 2 2 6 2 2 6 2 2 6
38276 - 2 2 6 2 2 6 2 2 6 2 2 6
38277 - 2 2 6 2 2 6 2 2 6 2 2 6
38278 - 2 2 6 2 2 6 2 2 6 54 54 54
38279 - 66 66 66 26 26 26 6 6 6 0 0 0
38280 - 0 0 0 0 0 0 0 0 0 0 0 0
38281 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 14 14 14
38293 - 42 42 42 82 82 82 2 2 6 2 2 6
38294 - 2 2 6 6 6 6 10 10 10 2 2 6
38295 - 2 2 6 2 2 6 2 2 6 2 2 6
38296 - 2 2 6 2 2 6 2 2 6 6 6 6
38297 - 14 14 14 10 10 10 2 2 6 2 2 6
38298 - 2 2 6 2 2 6 2 2 6 18 18 18
38299 - 82 82 82 34 34 34 10 10 10 0 0 0
38300 - 0 0 0 0 0 0 0 0 0 0 0 0
38301 - 0 0 0 0 0 0 0 0 0 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 1 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 14 14 14
38313 - 46 46 46 86 86 86 2 2 6 2 2 6
38314 - 6 6 6 6 6 6 22 22 22 34 34 34
38315 - 6 6 6 2 2 6 2 2 6 2 2 6
38316 - 2 2 6 2 2 6 18 18 18 34 34 34
38317 - 10 10 10 50 50 50 22 22 22 2 2 6
38318 - 2 2 6 2 2 6 2 2 6 10 10 10
38319 - 86 86 86 42 42 42 14 14 14 0 0 0
38320 - 0 0 0 0 0 0 0 0 0 0 0 0
38321 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 14 14 14
38333 - 46 46 46 86 86 86 2 2 6 2 2 6
38334 - 38 38 38 116 116 116 94 94 94 22 22 22
38335 - 22 22 22 2 2 6 2 2 6 2 2 6
38336 - 14 14 14 86 86 86 138 138 138 162 162 162
38337 -154 154 154 38 38 38 26 26 26 6 6 6
38338 - 2 2 6 2 2 6 2 2 6 2 2 6
38339 - 86 86 86 46 46 46 14 14 14 0 0 0
38340 - 0 0 0 0 0 0 0 0 0 0 0 0
38341 - 0 0 0 0 0 0 0 0 0 0 0 0
38342 - 0 0 0 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 14 14 14
38353 - 46 46 46 86 86 86 2 2 6 14 14 14
38354 -134 134 134 198 198 198 195 195 195 116 116 116
38355 - 10 10 10 2 2 6 2 2 6 6 6 6
38356 -101 98 89 187 187 187 210 210 210 218 218 218
38357 -214 214 214 134 134 134 14 14 14 6 6 6
38358 - 2 2 6 2 2 6 2 2 6 2 2 6
38359 - 86 86 86 50 50 50 18 18 18 6 6 6
38360 - 0 0 0 0 0 0 0 0 0 0 0 0
38361 - 0 0 0 0 0 0 0 0 0 0 0 0
38362 - 0 0 0 0 0 0 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 1 0 0 0
38367 - 0 0 1 0 0 1 0 0 1 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 - 46 46 46 86 86 86 2 2 6 54 54 54
38374 -218 218 218 195 195 195 226 226 226 246 246 246
38375 - 58 58 58 2 2 6 2 2 6 30 30 30
38376 -210 210 210 253 253 253 174 174 174 123 123 123
38377 -221 221 221 234 234 234 74 74 74 2 2 6
38378 - 2 2 6 2 2 6 2 2 6 2 2 6
38379 - 70 70 70 58 58 58 22 22 22 6 6 6
38380 - 0 0 0 0 0 0 0 0 0 0 0 0
38381 - 0 0 0 0 0 0 0 0 0 0 0 0
38382 - 0 0 0 0 0 0 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 0 0 0 14 14 14
38393 - 46 46 46 82 82 82 2 2 6 106 106 106
38394 -170 170 170 26 26 26 86 86 86 226 226 226
38395 -123 123 123 10 10 10 14 14 14 46 46 46
38396 -231 231 231 190 190 190 6 6 6 70 70 70
38397 - 90 90 90 238 238 238 158 158 158 2 2 6
38398 - 2 2 6 2 2 6 2 2 6 2 2 6
38399 - 70 70 70 58 58 58 22 22 22 6 6 6
38400 - 0 0 0 0 0 0 0 0 0 0 0 0
38401 - 0 0 0 0 0 0 0 0 0 0 0 0
38402 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
38407 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 14 14 14
38413 - 42 42 42 86 86 86 6 6 6 116 116 116
38414 -106 106 106 6 6 6 70 70 70 149 149 149
38415 -128 128 128 18 18 18 38 38 38 54 54 54
38416 -221 221 221 106 106 106 2 2 6 14 14 14
38417 - 46 46 46 190 190 190 198 198 198 2 2 6
38418 - 2 2 6 2 2 6 2 2 6 2 2 6
38419 - 74 74 74 62 62 62 22 22 22 6 6 6
38420 - 0 0 0 0 0 0 0 0 0 0 0 0
38421 - 0 0 0 0 0 0 0 0 0 0 0 0
38422 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
38427 - 0 0 1 0 0 0 0 0 1 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 - 0 0 0 0 0 0 0 0 0 14 14 14
38433 - 42 42 42 94 94 94 14 14 14 101 101 101
38434 -128 128 128 2 2 6 18 18 18 116 116 116
38435 -118 98 46 121 92 8 121 92 8 98 78 10
38436 -162 162 162 106 106 106 2 2 6 2 2 6
38437 - 2 2 6 195 195 195 195 195 195 6 6 6
38438 - 2 2 6 2 2 6 2 2 6 2 2 6
38439 - 74 74 74 62 62 62 22 22 22 6 6 6
38440 - 0 0 0 0 0 0 0 0 0 0 0 0
38441 - 0 0 0 0 0 0 0 0 0 0 0 0
38442 - 0 0 0 0 0 0 0 0 0 0 0 0
38443 - 0 0 0 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 1 0 0 1
38447 - 0 0 1 0 0 0 0 0 1 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 - 0 0 0 0 0 0 0 0 0 10 10 10
38453 - 38 38 38 90 90 90 14 14 14 58 58 58
38454 -210 210 210 26 26 26 54 38 6 154 114 10
38455 -226 170 11 236 186 11 225 175 15 184 144 12
38456 -215 174 15 175 146 61 37 26 9 2 2 6
38457 - 70 70 70 246 246 246 138 138 138 2 2 6
38458 - 2 2 6 2 2 6 2 2 6 2 2 6
38459 - 70 70 70 66 66 66 26 26 26 6 6 6
38460 - 0 0 0 0 0 0 0 0 0 0 0 0
38461 - 0 0 0 0 0 0 0 0 0 0 0 0
38462 - 0 0 0 0 0 0 0 0 0 0 0 0
38463 - 0 0 0 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 - 0 0 0 0 0 0 0 0 0 10 10 10
38473 - 38 38 38 86 86 86 14 14 14 10 10 10
38474 -195 195 195 188 164 115 192 133 9 225 175 15
38475 -239 182 13 234 190 10 232 195 16 232 200 30
38476 -245 207 45 241 208 19 232 195 16 184 144 12
38477 -218 194 134 211 206 186 42 42 42 2 2 6
38478 - 2 2 6 2 2 6 2 2 6 2 2 6
38479 - 50 50 50 74 74 74 30 30 30 6 6 6
38480 - 0 0 0 0 0 0 0 0 0 0 0 0
38481 - 0 0 0 0 0 0 0 0 0 0 0 0
38482 - 0 0 0 0 0 0 0 0 0 0 0 0
38483 - 0 0 0 0 0 0 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 0 0 0
38492 - 0 0 0 0 0 0 0 0 0 10 10 10
38493 - 34 34 34 86 86 86 14 14 14 2 2 6
38494 -121 87 25 192 133 9 219 162 10 239 182 13
38495 -236 186 11 232 195 16 241 208 19 244 214 54
38496 -246 218 60 246 218 38 246 215 20 241 208 19
38497 -241 208 19 226 184 13 121 87 25 2 2 6
38498 - 2 2 6 2 2 6 2 2 6 2 2 6
38499 - 50 50 50 82 82 82 34 34 34 10 10 10
38500 - 0 0 0 0 0 0 0 0 0 0 0 0
38501 - 0 0 0 0 0 0 0 0 0 0 0 0
38502 - 0 0 0 0 0 0 0 0 0 0 0 0
38503 - 0 0 0 0 0 0 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 0 0 0
38512 - 0 0 0 0 0 0 0 0 0 10 10 10
38513 - 34 34 34 82 82 82 30 30 30 61 42 6
38514 -180 123 7 206 145 10 230 174 11 239 182 13
38515 -234 190 10 238 202 15 241 208 19 246 218 74
38516 -246 218 38 246 215 20 246 215 20 246 215 20
38517 -226 184 13 215 174 15 184 144 12 6 6 6
38518 - 2 2 6 2 2 6 2 2 6 2 2 6
38519 - 26 26 26 94 94 94 42 42 42 14 14 14
38520 - 0 0 0 0 0 0 0 0 0 0 0 0
38521 - 0 0 0 0 0 0 0 0 0 0 0 0
38522 - 0 0 0 0 0 0 0 0 0 0 0 0
38523 - 0 0 0 0 0 0 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 0 0 0
38532 - 0 0 0 0 0 0 0 0 0 10 10 10
38533 - 30 30 30 78 78 78 50 50 50 104 69 6
38534 -192 133 9 216 158 10 236 178 12 236 186 11
38535 -232 195 16 241 208 19 244 214 54 245 215 43
38536 -246 215 20 246 215 20 241 208 19 198 155 10
38537 -200 144 11 216 158 10 156 118 10 2 2 6
38538 - 2 2 6 2 2 6 2 2 6 2 2 6
38539 - 6 6 6 90 90 90 54 54 54 18 18 18
38540 - 6 6 6 0 0 0 0 0 0 0 0 0
38541 - 0 0 0 0 0 0 0 0 0 0 0 0
38542 - 0 0 0 0 0 0 0 0 0 0 0 0
38543 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
38552 - 0 0 0 0 0 0 0 0 0 10 10 10
38553 - 30 30 30 78 78 78 46 46 46 22 22 22
38554 -137 92 6 210 162 10 239 182 13 238 190 10
38555 -238 202 15 241 208 19 246 215 20 246 215 20
38556 -241 208 19 203 166 17 185 133 11 210 150 10
38557 -216 158 10 210 150 10 102 78 10 2 2 6
38558 - 6 6 6 54 54 54 14 14 14 2 2 6
38559 - 2 2 6 62 62 62 74 74 74 30 30 30
38560 - 10 10 10 0 0 0 0 0 0 0 0 0
38561 - 0 0 0 0 0 0 0 0 0 0 0 0
38562 - 0 0 0 0 0 0 0 0 0 0 0 0
38563 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
38572 - 0 0 0 0 0 0 0 0 0 10 10 10
38573 - 34 34 34 78 78 78 50 50 50 6 6 6
38574 - 94 70 30 139 102 15 190 146 13 226 184 13
38575 -232 200 30 232 195 16 215 174 15 190 146 13
38576 -168 122 10 192 133 9 210 150 10 213 154 11
38577 -202 150 34 182 157 106 101 98 89 2 2 6
38578 - 2 2 6 78 78 78 116 116 116 58 58 58
38579 - 2 2 6 22 22 22 90 90 90 46 46 46
38580 - 18 18 18 6 6 6 0 0 0 0 0 0
38581 - 0 0 0 0 0 0 0 0 0 0 0 0
38582 - 0 0 0 0 0 0 0 0 0 0 0 0
38583 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0
38592 - 0 0 0 0 0 0 0 0 0 10 10 10
38593 - 38 38 38 86 86 86 50 50 50 6 6 6
38594 -128 128 128 174 154 114 156 107 11 168 122 10
38595 -198 155 10 184 144 12 197 138 11 200 144 11
38596 -206 145 10 206 145 10 197 138 11 188 164 115
38597 -195 195 195 198 198 198 174 174 174 14 14 14
38598 - 2 2 6 22 22 22 116 116 116 116 116 116
38599 - 22 22 22 2 2 6 74 74 74 70 70 70
38600 - 30 30 30 10 10 10 0 0 0 0 0 0
38601 - 0 0 0 0 0 0 0 0 0 0 0 0
38602 - 0 0 0 0 0 0 0 0 0 0 0 0
38603 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0 0 0 0 0 0
38612 - 0 0 0 0 0 0 6 6 6 18 18 18
38613 - 50 50 50 101 101 101 26 26 26 10 10 10
38614 -138 138 138 190 190 190 174 154 114 156 107 11
38615 -197 138 11 200 144 11 197 138 11 192 133 9
38616 -180 123 7 190 142 34 190 178 144 187 187 187
38617 -202 202 202 221 221 221 214 214 214 66 66 66
38618 - 2 2 6 2 2 6 50 50 50 62 62 62
38619 - 6 6 6 2 2 6 10 10 10 90 90 90
38620 - 50 50 50 18 18 18 6 6 6 0 0 0
38621 - 0 0 0 0 0 0 0 0 0 0 0 0
38622 - 0 0 0 0 0 0 0 0 0 0 0 0
38623 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 0 0 0
38632 - 0 0 0 0 0 0 10 10 10 34 34 34
38633 - 74 74 74 74 74 74 2 2 6 6 6 6
38634 -144 144 144 198 198 198 190 190 190 178 166 146
38635 -154 121 60 156 107 11 156 107 11 168 124 44
38636 -174 154 114 187 187 187 190 190 190 210 210 210
38637 -246 246 246 253 253 253 253 253 253 182 182 182
38638 - 6 6 6 2 2 6 2 2 6 2 2 6
38639 - 2 2 6 2 2 6 2 2 6 62 62 62
38640 - 74 74 74 34 34 34 14 14 14 0 0 0
38641 - 0 0 0 0 0 0 0 0 0 0 0 0
38642 - 0 0 0 0 0 0 0 0 0 0 0 0
38643 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 0 0 0
38652 - 0 0 0 10 10 10 22 22 22 54 54 54
38653 - 94 94 94 18 18 18 2 2 6 46 46 46
38654 -234 234 234 221 221 221 190 190 190 190 190 190
38655 -190 190 190 187 187 187 187 187 187 190 190 190
38656 -190 190 190 195 195 195 214 214 214 242 242 242
38657 -253 253 253 253 253 253 253 253 253 253 253 253
38658 - 82 82 82 2 2 6 2 2 6 2 2 6
38659 - 2 2 6 2 2 6 2 2 6 14 14 14
38660 - 86 86 86 54 54 54 22 22 22 6 6 6
38661 - 0 0 0 0 0 0 0 0 0 0 0 0
38662 - 0 0 0 0 0 0 0 0 0 0 0 0
38663 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
38671 - 0 0 0 0 0 0 0 0 0 0 0 0
38672 - 6 6 6 18 18 18 46 46 46 90 90 90
38673 - 46 46 46 18 18 18 6 6 6 182 182 182
38674 -253 253 253 246 246 246 206 206 206 190 190 190
38675 -190 190 190 190 190 190 190 190 190 190 190 190
38676 -206 206 206 231 231 231 250 250 250 253 253 253
38677 -253 253 253 253 253 253 253 253 253 253 253 253
38678 -202 202 202 14 14 14 2 2 6 2 2 6
38679 - 2 2 6 2 2 6 2 2 6 2 2 6
38680 - 42 42 42 86 86 86 42 42 42 18 18 18
38681 - 6 6 6 0 0 0 0 0 0 0 0 0
38682 - 0 0 0 0 0 0 0 0 0 0 0 0
38683 - 0 0 0 0 0 0 0 0 0 0 0 0
38684 - 0 0 0 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 0 0 0
38691 - 0 0 0 0 0 0 0 0 0 6 6 6
38692 - 14 14 14 38 38 38 74 74 74 66 66 66
38693 - 2 2 6 6 6 6 90 90 90 250 250 250
38694 -253 253 253 253 253 253 238 238 238 198 198 198
38695 -190 190 190 190 190 190 195 195 195 221 221 221
38696 -246 246 246 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 82 82 82 2 2 6 2 2 6
38699 - 2 2 6 2 2 6 2 2 6 2 2 6
38700 - 2 2 6 78 78 78 70 70 70 34 34 34
38701 - 14 14 14 6 6 6 0 0 0 0 0 0
38702 - 0 0 0 0 0 0 0 0 0 0 0 0
38703 - 0 0 0 0 0 0 0 0 0 0 0 0
38704 - 0 0 0 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 0 0 0
38711 - 0 0 0 0 0 0 0 0 0 14 14 14
38712 - 34 34 34 66 66 66 78 78 78 6 6 6
38713 - 2 2 6 18 18 18 218 218 218 253 253 253
38714 -253 253 253 253 253 253 253 253 253 246 246 246
38715 -226 226 226 231 231 231 246 246 246 253 253 253
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 178 178 178 2 2 6 2 2 6
38719 - 2 2 6 2 2 6 2 2 6 2 2 6
38720 - 2 2 6 18 18 18 90 90 90 62 62 62
38721 - 30 30 30 10 10 10 0 0 0 0 0 0
38722 - 0 0 0 0 0 0 0 0 0 0 0 0
38723 - 0 0 0 0 0 0 0 0 0 0 0 0
38724 - 0 0 0 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 0 0 0 0 0 0
38731 - 0 0 0 0 0 0 10 10 10 26 26 26
38732 - 58 58 58 90 90 90 18 18 18 2 2 6
38733 - 2 2 6 110 110 110 253 253 253 253 253 253
38734 -253 253 253 253 253 253 253 253 253 253 253 253
38735 -250 250 250 253 253 253 253 253 253 253 253 253
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 231 231 231 18 18 18 2 2 6
38739 - 2 2 6 2 2 6 2 2 6 2 2 6
38740 - 2 2 6 2 2 6 18 18 18 94 94 94
38741 - 54 54 54 26 26 26 10 10 10 0 0 0
38742 - 0 0 0 0 0 0 0 0 0 0 0 0
38743 - 0 0 0 0 0 0 0 0 0 0 0 0
38744 - 0 0 0 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 0 0 0 0 0 0
38751 - 0 0 0 6 6 6 22 22 22 50 50 50
38752 - 90 90 90 26 26 26 2 2 6 2 2 6
38753 - 14 14 14 195 195 195 250 250 250 253 253 253
38754 -253 253 253 253 253 253 253 253 253 253 253 253
38755 -253 253 253 253 253 253 253 253 253 253 253 253
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 -250 250 250 242 242 242 54 54 54 2 2 6
38759 - 2 2 6 2 2 6 2 2 6 2 2 6
38760 - 2 2 6 2 2 6 2 2 6 38 38 38
38761 - 86 86 86 50 50 50 22 22 22 6 6 6
38762 - 0 0 0 0 0 0 0 0 0 0 0 0
38763 - 0 0 0 0 0 0 0 0 0 0 0 0
38764 - 0 0 0 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 0 0 0 0 0 0
38771 - 6 6 6 14 14 14 38 38 38 82 82 82
38772 - 34 34 34 2 2 6 2 2 6 2 2 6
38773 - 42 42 42 195 195 195 246 246 246 253 253 253
38774 -253 253 253 253 253 253 253 253 253 250 250 250
38775 -242 242 242 242 242 242 250 250 250 253 253 253
38776 -253 253 253 253 253 253 253 253 253 253 253 253
38777 -253 253 253 250 250 250 246 246 246 238 238 238
38778 -226 226 226 231 231 231 101 101 101 6 6 6
38779 - 2 2 6 2 2 6 2 2 6 2 2 6
38780 - 2 2 6 2 2 6 2 2 6 2 2 6
38781 - 38 38 38 82 82 82 42 42 42 14 14 14
38782 - 6 6 6 0 0 0 0 0 0 0 0 0
38783 - 0 0 0 0 0 0 0 0 0 0 0 0
38784 - 0 0 0 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 0 0 0 0 0 0
38791 - 10 10 10 26 26 26 62 62 62 66 66 66
38792 - 2 2 6 2 2 6 2 2 6 6 6 6
38793 - 70 70 70 170 170 170 206 206 206 234 234 234
38794 -246 246 246 250 250 250 250 250 250 238 238 238
38795 -226 226 226 231 231 231 238 238 238 250 250 250
38796 -250 250 250 250 250 250 246 246 246 231 231 231
38797 -214 214 214 206 206 206 202 202 202 202 202 202
38798 -198 198 198 202 202 202 182 182 182 18 18 18
38799 - 2 2 6 2 2 6 2 2 6 2 2 6
38800 - 2 2 6 2 2 6 2 2 6 2 2 6
38801 - 2 2 6 62 62 62 66 66 66 30 30 30
38802 - 10 10 10 0 0 0 0 0 0 0 0 0
38803 - 0 0 0 0 0 0 0 0 0 0 0 0
38804 - 0 0 0 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 0 0 0
38810 - 0 0 0 0 0 0 0 0 0 0 0 0
38811 - 14 14 14 42 42 42 82 82 82 18 18 18
38812 - 2 2 6 2 2 6 2 2 6 10 10 10
38813 - 94 94 94 182 182 182 218 218 218 242 242 242
38814 -250 250 250 253 253 253 253 253 253 250 250 250
38815 -234 234 234 253 253 253 253 253 253 253 253 253
38816 -253 253 253 253 253 253 253 253 253 246 246 246
38817 -238 238 238 226 226 226 210 210 210 202 202 202
38818 -195 195 195 195 195 195 210 210 210 158 158 158
38819 - 6 6 6 14 14 14 50 50 50 14 14 14
38820 - 2 2 6 2 2 6 2 2 6 2 2 6
38821 - 2 2 6 6 6 6 86 86 86 46 46 46
38822 - 18 18 18 6 6 6 0 0 0 0 0 0
38823 - 0 0 0 0 0 0 0 0 0 0 0 0
38824 - 0 0 0 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 0 0 0 0 0 0 0 0 0
38830 - 0 0 0 0 0 0 0 0 0 6 6 6
38831 - 22 22 22 54 54 54 70 70 70 2 2 6
38832 - 2 2 6 10 10 10 2 2 6 22 22 22
38833 -166 166 166 231 231 231 250 250 250 253 253 253
38834 -253 253 253 253 253 253 253 253 253 250 250 250
38835 -242 242 242 253 253 253 253 253 253 253 253 253
38836 -253 253 253 253 253 253 253 253 253 253 253 253
38837 -253 253 253 253 253 253 253 253 253 246 246 246
38838 -231 231 231 206 206 206 198 198 198 226 226 226
38839 - 94 94 94 2 2 6 6 6 6 38 38 38
38840 - 30 30 30 2 2 6 2 2 6 2 2 6
38841 - 2 2 6 2 2 6 62 62 62 66 66 66
38842 - 26 26 26 10 10 10 0 0 0 0 0 0
38843 - 0 0 0 0 0 0 0 0 0 0 0 0
38844 - 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38850 - 0 0 0 0 0 0 0 0 0 10 10 10
38851 - 30 30 30 74 74 74 50 50 50 2 2 6
38852 - 26 26 26 26 26 26 2 2 6 106 106 106
38853 -238 238 238 253 253 253 253 253 253 253 253 253
38854 -253 253 253 253 253 253 253 253 253 253 253 253
38855 -253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 218 218 218 202 202 202
38859 -210 210 210 14 14 14 2 2 6 2 2 6
38860 - 30 30 30 22 22 22 2 2 6 2 2 6
38861 - 2 2 6 2 2 6 18 18 18 86 86 86
38862 - 42 42 42 14 14 14 0 0 0 0 0 0
38863 - 0 0 0 0 0 0 0 0 0 0 0 0
38864 - 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38870 - 0 0 0 0 0 0 0 0 0 14 14 14
38871 - 42 42 42 90 90 90 22 22 22 2 2 6
38872 - 42 42 42 2 2 6 18 18 18 218 218 218
38873 -253 253 253 253 253 253 253 253 253 253 253 253
38874 -253 253 253 253 253 253 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 250 250 250 221 221 221
38879 -218 218 218 101 101 101 2 2 6 14 14 14
38880 - 18 18 18 38 38 38 10 10 10 2 2 6
38881 - 2 2 6 2 2 6 2 2 6 78 78 78
38882 - 58 58 58 22 22 22 6 6 6 0 0 0
38883 - 0 0 0 0 0 0 0 0 0 0 0 0
38884 - 0 0 0 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 0 0 0
38889 - 0 0 0 0 0 0 0 0 0 0 0 0
38890 - 0 0 0 0 0 0 6 6 6 18 18 18
38891 - 54 54 54 82 82 82 2 2 6 26 26 26
38892 - 22 22 22 2 2 6 123 123 123 253 253 253
38893 -253 253 253 253 253 253 253 253 253 253 253 253
38894 -253 253 253 253 253 253 253 253 253 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 250 250 250
38899 -238 238 238 198 198 198 6 6 6 38 38 38
38900 - 58 58 58 26 26 26 38 38 38 2 2 6
38901 - 2 2 6 2 2 6 2 2 6 46 46 46
38902 - 78 78 78 30 30 30 10 10 10 0 0 0
38903 - 0 0 0 0 0 0 0 0 0 0 0 0
38904 - 0 0 0 0 0 0 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 0 0 0
38909 - 0 0 0 0 0 0 0 0 0 0 0 0
38910 - 0 0 0 0 0 0 10 10 10 30 30 30
38911 - 74 74 74 58 58 58 2 2 6 42 42 42
38912 - 2 2 6 22 22 22 231 231 231 253 253 253
38913 -253 253 253 253 253 253 253 253 253 253 253 253
38914 -253 253 253 253 253 253 253 253 253 250 250 250
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 246 246 246 46 46 46 38 38 38
38920 - 42 42 42 14 14 14 38 38 38 14 14 14
38921 - 2 2 6 2 2 6 2 2 6 6 6 6
38922 - 86 86 86 46 46 46 14 14 14 0 0 0
38923 - 0 0 0 0 0 0 0 0 0 0 0 0
38924 - 0 0 0 0 0 0 0 0 0 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 0 0 0
38929 - 0 0 0 0 0 0 0 0 0 0 0 0
38930 - 0 0 0 6 6 6 14 14 14 42 42 42
38931 - 90 90 90 18 18 18 18 18 18 26 26 26
38932 - 2 2 6 116 116 116 253 253 253 253 253 253
38933 -253 253 253 253 253 253 253 253 253 253 253 253
38934 -253 253 253 253 253 253 250 250 250 238 238 238
38935 -253 253 253 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 -253 253 253 253 253 253 94 94 94 6 6 6
38940 - 2 2 6 2 2 6 10 10 10 34 34 34
38941 - 2 2 6 2 2 6 2 2 6 2 2 6
38942 - 74 74 74 58 58 58 22 22 22 6 6 6
38943 - 0 0 0 0 0 0 0 0 0 0 0 0
38944 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
38949 - 0 0 0 0 0 0 0 0 0 0 0 0
38950 - 0 0 0 10 10 10 26 26 26 66 66 66
38951 - 82 82 82 2 2 6 38 38 38 6 6 6
38952 - 14 14 14 210 210 210 253 253 253 253 253 253
38953 -253 253 253 253 253 253 253 253 253 253 253 253
38954 -253 253 253 253 253 253 246 246 246 242 242 242
38955 -253 253 253 253 253 253 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 -253 253 253 253 253 253 144 144 144 2 2 6
38960 - 2 2 6 2 2 6 2 2 6 46 46 46
38961 - 2 2 6 2 2 6 2 2 6 2 2 6
38962 - 42 42 42 74 74 74 30 30 30 10 10 10
38963 - 0 0 0 0 0 0 0 0 0 0 0 0
38964 - 0 0 0 0 0 0 0 0 0 0 0 0
38965 - 0 0 0 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 0 0 0
38969 - 0 0 0 0 0 0 0 0 0 0 0 0
38970 - 6 6 6 14 14 14 42 42 42 90 90 90
38971 - 26 26 26 6 6 6 42 42 42 2 2 6
38972 - 74 74 74 250 250 250 253 253 253 253 253 253
38973 -253 253 253 253 253 253 253 253 253 253 253 253
38974 -253 253 253 253 253 253 242 242 242 242 242 242
38975 -253 253 253 253 253 253 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 253 253 253 182 182 182 2 2 6
38980 - 2 2 6 2 2 6 2 2 6 46 46 46
38981 - 2 2 6 2 2 6 2 2 6 2 2 6
38982 - 10 10 10 86 86 86 38 38 38 10 10 10
38983 - 0 0 0 0 0 0 0 0 0 0 0 0
38984 - 0 0 0 0 0 0 0 0 0 0 0 0
38985 - 0 0 0 0 0 0 0 0 0 0 0 0
38986 - 0 0 0 0 0 0 0 0 0 0 0 0
38987 - 0 0 0 0 0 0 0 0 0 0 0 0
38988 - 0 0 0 0 0 0 0 0 0 0 0 0
38989 - 0 0 0 0 0 0 0 0 0 0 0 0
38990 - 10 10 10 26 26 26 66 66 66 82 82 82
38991 - 2 2 6 22 22 22 18 18 18 2 2 6
38992 -149 149 149 253 253 253 253 253 253 253 253 253
38993 -253 253 253 253 253 253 253 253 253 253 253 253
38994 -253 253 253 253 253 253 234 234 234 242 242 242
38995 -253 253 253 253 253 253 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 253 253 253 206 206 206 2 2 6
39000 - 2 2 6 2 2 6 2 2 6 38 38 38
39001 - 2 2 6 2 2 6 2 2 6 2 2 6
39002 - 6 6 6 86 86 86 46 46 46 14 14 14
39003 - 0 0 0 0 0 0 0 0 0 0 0 0
39004 - 0 0 0 0 0 0 0 0 0 0 0 0
39005 - 0 0 0 0 0 0 0 0 0 0 0 0
39006 - 0 0 0 0 0 0 0 0 0 0 0 0
39007 - 0 0 0 0 0 0 0 0 0 0 0 0
39008 - 0 0 0 0 0 0 0 0 0 0 0 0
39009 - 0 0 0 0 0 0 0 0 0 6 6 6
39010 - 18 18 18 46 46 46 86 86 86 18 18 18
39011 - 2 2 6 34 34 34 10 10 10 6 6 6
39012 -210 210 210 253 253 253 253 253 253 253 253 253
39013 -253 253 253 253 253 253 253 253 253 253 253 253
39014 -253 253 253 253 253 253 234 234 234 242 242 242
39015 -253 253 253 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 -253 253 253 253 253 253 221 221 221 6 6 6
39020 - 2 2 6 2 2 6 6 6 6 30 30 30
39021 - 2 2 6 2 2 6 2 2 6 2 2 6
39022 - 2 2 6 82 82 82 54 54 54 18 18 18
39023 - 6 6 6 0 0 0 0 0 0 0 0 0
39024 - 0 0 0 0 0 0 0 0 0 0 0 0
39025 - 0 0 0 0 0 0 0 0 0 0 0 0
39026 - 0 0 0 0 0 0 0 0 0 0 0 0
39027 - 0 0 0 0 0 0 0 0 0 0 0 0
39028 - 0 0 0 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 0 0 0 0 10 10 10
39030 - 26 26 26 66 66 66 62 62 62 2 2 6
39031 - 2 2 6 38 38 38 10 10 10 26 26 26
39032 -238 238 238 253 253 253 253 253 253 253 253 253
39033 -253 253 253 253 253 253 253 253 253 253 253 253
39034 -253 253 253 253 253 253 231 231 231 238 238 238
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 253 253 253
39039 -253 253 253 253 253 253 231 231 231 6 6 6
39040 - 2 2 6 2 2 6 10 10 10 30 30 30
39041 - 2 2 6 2 2 6 2 2 6 2 2 6
39042 - 2 2 6 66 66 66 58 58 58 22 22 22
39043 - 6 6 6 0 0 0 0 0 0 0 0 0
39044 - 0 0 0 0 0 0 0 0 0 0 0 0
39045 - 0 0 0 0 0 0 0 0 0 0 0 0
39046 - 0 0 0 0 0 0 0 0 0 0 0 0
39047 - 0 0 0 0 0 0 0 0 0 0 0 0
39048 - 0 0 0 0 0 0 0 0 0 0 0 0
39049 - 0 0 0 0 0 0 0 0 0 10 10 10
39050 - 38 38 38 78 78 78 6 6 6 2 2 6
39051 - 2 2 6 46 46 46 14 14 14 42 42 42
39052 -246 246 246 253 253 253 253 253 253 253 253 253
39053 -253 253 253 253 253 253 253 253 253 253 253 253
39054 -253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253 253 253 253 253 253 253
39059 -253 253 253 253 253 253 234 234 234 10 10 10
39060 - 2 2 6 2 2 6 22 22 22 14 14 14
39061 - 2 2 6 2 2 6 2 2 6 2 2 6
39062 - 2 2 6 66 66 66 62 62 62 22 22 22
39063 - 6 6 6 0 0 0 0 0 0 0 0 0
39064 - 0 0 0 0 0 0 0 0 0 0 0 0
39065 - 0 0 0 0 0 0 0 0 0 0 0 0
39066 - 0 0 0 0 0 0 0 0 0 0 0 0
39067 - 0 0 0 0 0 0 0 0 0 0 0 0
39068 - 0 0 0 0 0 0 0 0 0 0 0 0
39069 - 0 0 0 0 0 0 6 6 6 18 18 18
39070 - 50 50 50 74 74 74 2 2 6 2 2 6
39071 - 14 14 14 70 70 70 34 34 34 62 62 62
39072 -250 250 250 253 253 253 253 253 253 253 253 253
39073 -253 253 253 253 253 253 253 253 253 253 253 253
39074 -253 253 253 253 253 253 231 231 231 246 246 246
39075 -253 253 253 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 -253 253 253 253 253 253 253 253 253 253 253 253
39079 -253 253 253 253 253 253 234 234 234 14 14 14
39080 - 2 2 6 2 2 6 30 30 30 2 2 6
39081 - 2 2 6 2 2 6 2 2 6 2 2 6
39082 - 2 2 6 66 66 66 62 62 62 22 22 22
39083 - 6 6 6 0 0 0 0 0 0 0 0 0
39084 - 0 0 0 0 0 0 0 0 0 0 0 0
39085 - 0 0 0 0 0 0 0 0 0 0 0 0
39086 - 0 0 0 0 0 0 0 0 0 0 0 0
39087 - 0 0 0 0 0 0 0 0 0 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 0 0 0 6 6 6 18 18 18
39090 - 54 54 54 62 62 62 2 2 6 2 2 6
39091 - 2 2 6 30 30 30 46 46 46 70 70 70
39092 -250 250 250 253 253 253 253 253 253 253 253 253
39093 -253 253 253 253 253 253 253 253 253 253 253 253
39094 -253 253 253 253 253 253 231 231 231 246 246 246
39095 -253 253 253 253 253 253 253 253 253 253 253 253
39096 -253 253 253 253 253 253 253 253 253 253 253 253
39097 -253 253 253 253 253 253 253 253 253 253 253 253
39098 -253 253 253 253 253 253 253 253 253 253 253 253
39099 -253 253 253 253 253 253 226 226 226 10 10 10
39100 - 2 2 6 6 6 6 30 30 30 2 2 6
39101 - 2 2 6 2 2 6 2 2 6 2 2 6
39102 - 2 2 6 66 66 66 58 58 58 22 22 22
39103 - 6 6 6 0 0 0 0 0 0 0 0 0
39104 - 0 0 0 0 0 0 0 0 0 0 0 0
39105 - 0 0 0 0 0 0 0 0 0 0 0 0
39106 - 0 0 0 0 0 0 0 0 0 0 0 0
39107 - 0 0 0 0 0 0 0 0 0 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 6 6 6 22 22 22
39110 - 58 58 58 62 62 62 2 2 6 2 2 6
39111 - 2 2 6 2 2 6 30 30 30 78 78 78
39112 -250 250 250 253 253 253 253 253 253 253 253 253
39113 -253 253 253 253 253 253 253 253 253 253 253 253
39114 -253 253 253 253 253 253 231 231 231 246 246 246
39115 -253 253 253 253 253 253 253 253 253 253 253 253
39116 -253 253 253 253 253 253 253 253 253 253 253 253
39117 -253 253 253 253 253 253 253 253 253 253 253 253
39118 -253 253 253 253 253 253 253 253 253 253 253 253
39119 -253 253 253 253 253 253 206 206 206 2 2 6
39120 - 22 22 22 34 34 34 18 14 6 22 22 22
39121 - 26 26 26 18 18 18 6 6 6 2 2 6
39122 - 2 2 6 82 82 82 54 54 54 18 18 18
39123 - 6 6 6 0 0 0 0 0 0 0 0 0
39124 - 0 0 0 0 0 0 0 0 0 0 0 0
39125 - 0 0 0 0 0 0 0 0 0 0 0 0
39126 - 0 0 0 0 0 0 0 0 0 0 0 0
39127 - 0 0 0 0 0 0 0 0 0 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 6 6 6 26 26 26
39130 - 62 62 62 106 106 106 74 54 14 185 133 11
39131 -210 162 10 121 92 8 6 6 6 62 62 62
39132 -238 238 238 253 253 253 253 253 253 253 253 253
39133 -253 253 253 253 253 253 253 253 253 253 253 253
39134 -253 253 253 253 253 253 231 231 231 246 246 246
39135 -253 253 253 253 253 253 253 253 253 253 253 253
39136 -253 253 253 253 253 253 253 253 253 253 253 253
39137 -253 253 253 253 253 253 253 253 253 253 253 253
39138 -253 253 253 253 253 253 253 253 253 253 253 253
39139 -253 253 253 253 253 253 158 158 158 18 18 18
39140 - 14 14 14 2 2 6 2 2 6 2 2 6
39141 - 6 6 6 18 18 18 66 66 66 38 38 38
39142 - 6 6 6 94 94 94 50 50 50 18 18 18
39143 - 6 6 6 0 0 0 0 0 0 0 0 0
39144 - 0 0 0 0 0 0 0 0 0 0 0 0
39145 - 0 0 0 0 0 0 0 0 0 0 0 0
39146 - 0 0 0 0 0 0 0 0 0 0 0 0
39147 - 0 0 0 0 0 0 0 0 0 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 6 6 6
39149 - 10 10 10 10 10 10 18 18 18 38 38 38
39150 - 78 78 78 142 134 106 216 158 10 242 186 14
39151 -246 190 14 246 190 14 156 118 10 10 10 10
39152 - 90 90 90 238 238 238 253 253 253 253 253 253
39153 -253 253 253 253 253 253 253 253 253 253 253 253
39154 -253 253 253 253 253 253 231 231 231 250 250 250
39155 -253 253 253 253 253 253 253 253 253 253 253 253
39156 -253 253 253 253 253 253 253 253 253 253 253 253
39157 -253 253 253 253 253 253 253 253 253 253 253 253
39158 -253 253 253 253 253 253 253 253 253 246 230 190
39159 -238 204 91 238 204 91 181 142 44 37 26 9
39160 - 2 2 6 2 2 6 2 2 6 2 2 6
39161 - 2 2 6 2 2 6 38 38 38 46 46 46
39162 - 26 26 26 106 106 106 54 54 54 18 18 18
39163 - 6 6 6 0 0 0 0 0 0 0 0 0
39164 - 0 0 0 0 0 0 0 0 0 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 6 6 6 14 14 14 22 22 22
39169 - 30 30 30 38 38 38 50 50 50 70 70 70
39170 -106 106 106 190 142 34 226 170 11 242 186 14
39171 -246 190 14 246 190 14 246 190 14 154 114 10
39172 - 6 6 6 74 74 74 226 226 226 253 253 253
39173 -253 253 253 253 253 253 253 253 253 253 253 253
39174 -253 253 253 253 253 253 231 231 231 250 250 250
39175 -253 253 253 253 253 253 253 253 253 253 253 253
39176 -253 253 253 253 253 253 253 253 253 253 253 253
39177 -253 253 253 253 253 253 253 253 253 253 253 253
39178 -253 253 253 253 253 253 253 253 253 228 184 62
39179 -241 196 14 241 208 19 232 195 16 38 30 10
39180 - 2 2 6 2 2 6 2 2 6 2 2 6
39181 - 2 2 6 6 6 6 30 30 30 26 26 26
39182 -203 166 17 154 142 90 66 66 66 26 26 26
39183 - 6 6 6 0 0 0 0 0 0 0 0 0
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 6 6 6 18 18 18 38 38 38 58 58 58
39189 - 78 78 78 86 86 86 101 101 101 123 123 123
39190 -175 146 61 210 150 10 234 174 13 246 186 14
39191 -246 190 14 246 190 14 246 190 14 238 190 10
39192 -102 78 10 2 2 6 46 46 46 198 198 198
39193 -253 253 253 253 253 253 253 253 253 253 253 253
39194 -253 253 253 253 253 253 234 234 234 242 242 242
39195 -253 253 253 253 253 253 253 253 253 253 253 253
39196 -253 253 253 253 253 253 253 253 253 253 253 253
39197 -253 253 253 253 253 253 253 253 253 253 253 253
39198 -253 253 253 253 253 253 253 253 253 224 178 62
39199 -242 186 14 241 196 14 210 166 10 22 18 6
39200 - 2 2 6 2 2 6 2 2 6 2 2 6
39201 - 2 2 6 2 2 6 6 6 6 121 92 8
39202 -238 202 15 232 195 16 82 82 82 34 34 34
39203 - 10 10 10 0 0 0 0 0 0 0 0 0
39204 - 0 0 0 0 0 0 0 0 0 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 14 14 14 38 38 38 70 70 70 154 122 46
39209 -190 142 34 200 144 11 197 138 11 197 138 11
39210 -213 154 11 226 170 11 242 186 14 246 190 14
39211 -246 190 14 246 190 14 246 190 14 246 190 14
39212 -225 175 15 46 32 6 2 2 6 22 22 22
39213 -158 158 158 250 250 250 253 253 253 253 253 253
39214 -253 253 253 253 253 253 253 253 253 253 253 253
39215 -253 253 253 253 253 253 253 253 253 253 253 253
39216 -253 253 253 253 253 253 253 253 253 253 253 253
39217 -253 253 253 253 253 253 253 253 253 253 253 253
39218 -253 253 253 250 250 250 242 242 242 224 178 62
39219 -239 182 13 236 186 11 213 154 11 46 32 6
39220 - 2 2 6 2 2 6 2 2 6 2 2 6
39221 - 2 2 6 2 2 6 61 42 6 225 175 15
39222 -238 190 10 236 186 11 112 100 78 42 42 42
39223 - 14 14 14 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 6 6 6
39228 - 22 22 22 54 54 54 154 122 46 213 154 11
39229 -226 170 11 230 174 11 226 170 11 226 170 11
39230 -236 178 12 242 186 14 246 190 14 246 190 14
39231 -246 190 14 246 190 14 246 190 14 246 190 14
39232 -241 196 14 184 144 12 10 10 10 2 2 6
39233 - 6 6 6 116 116 116 242 242 242 253 253 253
39234 -253 253 253 253 253 253 253 253 253 253 253 253
39235 -253 253 253 253 253 253 253 253 253 253 253 253
39236 -253 253 253 253 253 253 253 253 253 253 253 253
39237 -253 253 253 253 253 253 253 253 253 253 253 253
39238 -253 253 253 231 231 231 198 198 198 214 170 54
39239 -236 178 12 236 178 12 210 150 10 137 92 6
39240 - 18 14 6 2 2 6 2 2 6 2 2 6
39241 - 6 6 6 70 47 6 200 144 11 236 178 12
39242 -239 182 13 239 182 13 124 112 88 58 58 58
39243 - 22 22 22 6 6 6 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 10 10 10
39248 - 30 30 30 70 70 70 180 133 36 226 170 11
39249 -239 182 13 242 186 14 242 186 14 246 186 14
39250 -246 190 14 246 190 14 246 190 14 246 190 14
39251 -246 190 14 246 190 14 246 190 14 246 190 14
39252 -246 190 14 232 195 16 98 70 6 2 2 6
39253 - 2 2 6 2 2 6 66 66 66 221 221 221
39254 -253 253 253 253 253 253 253 253 253 253 253 253
39255 -253 253 253 253 253 253 253 253 253 253 253 253
39256 -253 253 253 253 253 253 253 253 253 253 253 253
39257 -253 253 253 253 253 253 253 253 253 253 253 253
39258 -253 253 253 206 206 206 198 198 198 214 166 58
39259 -230 174 11 230 174 11 216 158 10 192 133 9
39260 -163 110 8 116 81 8 102 78 10 116 81 8
39261 -167 114 7 197 138 11 226 170 11 239 182 13
39262 -242 186 14 242 186 14 162 146 94 78 78 78
39263 - 34 34 34 14 14 14 6 6 6 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 6 6 6
39268 - 30 30 30 78 78 78 190 142 34 226 170 11
39269 -239 182 13 246 190 14 246 190 14 246 190 14
39270 -246 190 14 246 190 14 246 190 14 246 190 14
39271 -246 190 14 246 190 14 246 190 14 246 190 14
39272 -246 190 14 241 196 14 203 166 17 22 18 6
39273 - 2 2 6 2 2 6 2 2 6 38 38 38
39274 -218 218 218 253 253 253 253 253 253 253 253 253
39275 -253 253 253 253 253 253 253 253 253 253 253 253
39276 -253 253 253 253 253 253 253 253 253 253 253 253
39277 -253 253 253 253 253 253 253 253 253 253 253 253
39278 -250 250 250 206 206 206 198 198 198 202 162 69
39279 -226 170 11 236 178 12 224 166 10 210 150 10
39280 -200 144 11 197 138 11 192 133 9 197 138 11
39281 -210 150 10 226 170 11 242 186 14 246 190 14
39282 -246 190 14 246 186 14 225 175 15 124 112 88
39283 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
39288 - 30 30 30 78 78 78 174 135 50 224 166 10
39289 -239 182 13 246 190 14 246 190 14 246 190 14
39290 -246 190 14 246 190 14 246 190 14 246 190 14
39291 -246 190 14 246 190 14 246 190 14 246 190 14
39292 -246 190 14 246 190 14 241 196 14 139 102 15
39293 - 2 2 6 2 2 6 2 2 6 2 2 6
39294 - 78 78 78 250 250 250 253 253 253 253 253 253
39295 -253 253 253 253 253 253 253 253 253 253 253 253
39296 -253 253 253 253 253 253 253 253 253 253 253 253
39297 -253 253 253 253 253 253 253 253 253 253 253 253
39298 -250 250 250 214 214 214 198 198 198 190 150 46
39299 -219 162 10 236 178 12 234 174 13 224 166 10
39300 -216 158 10 213 154 11 213 154 11 216 158 10
39301 -226 170 11 239 182 13 246 190 14 246 190 14
39302 -246 190 14 246 190 14 242 186 14 206 162 42
39303 -101 101 101 58 58 58 30 30 30 14 14 14
39304 - 6 6 6 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 10 10 10
39308 - 30 30 30 74 74 74 174 135 50 216 158 10
39309 -236 178 12 246 190 14 246 190 14 246 190 14
39310 -246 190 14 246 190 14 246 190 14 246 190 14
39311 -246 190 14 246 190 14 246 190 14 246 190 14
39312 -246 190 14 246 190 14 241 196 14 226 184 13
39313 - 61 42 6 2 2 6 2 2 6 2 2 6
39314 - 22 22 22 238 238 238 253 253 253 253 253 253
39315 -253 253 253 253 253 253 253 253 253 253 253 253
39316 -253 253 253 253 253 253 253 253 253 253 253 253
39317 -253 253 253 253 253 253 253 253 253 253 253 253
39318 -253 253 253 226 226 226 187 187 187 180 133 36
39319 -216 158 10 236 178 12 239 182 13 236 178 12
39320 -230 174 11 226 170 11 226 170 11 230 174 11
39321 -236 178 12 242 186 14 246 190 14 246 190 14
39322 -246 190 14 246 190 14 246 186 14 239 182 13
39323 -206 162 42 106 106 106 66 66 66 34 34 34
39324 - 14 14 14 6 6 6 0 0 0 0 0 0
39325 - 0 0 0 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 6 6 6
39328 - 26 26 26 70 70 70 163 133 67 213 154 11
39329 -236 178 12 246 190 14 246 190 14 246 190 14
39330 -246 190 14 246 190 14 246 190 14 246 190 14
39331 -246 190 14 246 190 14 246 190 14 246 190 14
39332 -246 190 14 246 190 14 246 190 14 241 196 14
39333 -190 146 13 18 14 6 2 2 6 2 2 6
39334 - 46 46 46 246 246 246 253 253 253 253 253 253
39335 -253 253 253 253 253 253 253 253 253 253 253 253
39336 -253 253 253 253 253 253 253 253 253 253 253 253
39337 -253 253 253 253 253 253 253 253 253 253 253 253
39338 -253 253 253 221 221 221 86 86 86 156 107 11
39339 -216 158 10 236 178 12 242 186 14 246 186 14
39340 -242 186 14 239 182 13 239 182 13 242 186 14
39341 -242 186 14 246 186 14 246 190 14 246 190 14
39342 -246 190 14 246 190 14 246 190 14 246 190 14
39343 -242 186 14 225 175 15 142 122 72 66 66 66
39344 - 30 30 30 10 10 10 0 0 0 0 0 0
39345 - 0 0 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 6 6 6
39348 - 26 26 26 70 70 70 163 133 67 210 150 10
39349 -236 178 12 246 190 14 246 190 14 246 190 14
39350 -246 190 14 246 190 14 246 190 14 246 190 14
39351 -246 190 14 246 190 14 246 190 14 246 190 14
39352 -246 190 14 246 190 14 246 190 14 246 190 14
39353 -232 195 16 121 92 8 34 34 34 106 106 106
39354 -221 221 221 253 253 253 253 253 253 253 253 253
39355 -253 253 253 253 253 253 253 253 253 253 253 253
39356 -253 253 253 253 253 253 253 253 253 253 253 253
39357 -253 253 253 253 253 253 253 253 253 253 253 253
39358 -242 242 242 82 82 82 18 14 6 163 110 8
39359 -216 158 10 236 178 12 242 186 14 246 190 14
39360 -246 190 14 246 190 14 246 190 14 246 190 14
39361 -246 190 14 246 190 14 246 190 14 246 190 14
39362 -246 190 14 246 190 14 246 190 14 246 190 14
39363 -246 190 14 246 190 14 242 186 14 163 133 67
39364 - 46 46 46 18 18 18 6 6 6 0 0 0
39365 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 10 10 10
39368 - 30 30 30 78 78 78 163 133 67 210 150 10
39369 -236 178 12 246 186 14 246 190 14 246 190 14
39370 -246 190 14 246 190 14 246 190 14 246 190 14
39371 -246 190 14 246 190 14 246 190 14 246 190 14
39372 -246 190 14 246 190 14 246 190 14 246 190 14
39373 -241 196 14 215 174 15 190 178 144 253 253 253
39374 -253 253 253 253 253 253 253 253 253 253 253 253
39375 -253 253 253 253 253 253 253 253 253 253 253 253
39376 -253 253 253 253 253 253 253 253 253 253 253 253
39377 -253 253 253 253 253 253 253 253 253 218 218 218
39378 - 58 58 58 2 2 6 22 18 6 167 114 7
39379 -216 158 10 236 178 12 246 186 14 246 190 14
39380 -246 190 14 246 190 14 246 190 14 246 190 14
39381 -246 190 14 246 190 14 246 190 14 246 190 14
39382 -246 190 14 246 190 14 246 190 14 246 190 14
39383 -246 190 14 246 186 14 242 186 14 190 150 46
39384 - 54 54 54 22 22 22 6 6 6 0 0 0
39385 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 14 14 14
39388 - 38 38 38 86 86 86 180 133 36 213 154 11
39389 -236 178 12 246 186 14 246 190 14 246 190 14
39390 -246 190 14 246 190 14 246 190 14 246 190 14
39391 -246 190 14 246 190 14 246 190 14 246 190 14
39392 -246 190 14 246 190 14 246 190 14 246 190 14
39393 -246 190 14 232 195 16 190 146 13 214 214 214
39394 -253 253 253 253 253 253 253 253 253 253 253 253
39395 -253 253 253 253 253 253 253 253 253 253 253 253
39396 -253 253 253 253 253 253 253 253 253 253 253 253
39397 -253 253 253 250 250 250 170 170 170 26 26 26
39398 - 2 2 6 2 2 6 37 26 9 163 110 8
39399 -219 162 10 239 182 13 246 186 14 246 190 14
39400 -246 190 14 246 190 14 246 190 14 246 190 14
39401 -246 190 14 246 190 14 246 190 14 246 190 14
39402 -246 190 14 246 190 14 246 190 14 246 190 14
39403 -246 186 14 236 178 12 224 166 10 142 122 72
39404 - 46 46 46 18 18 18 6 6 6 0 0 0
39405 - 0 0 0 0 0 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 6 6 6 18 18 18
39408 - 50 50 50 109 106 95 192 133 9 224 166 10
39409 -242 186 14 246 190 14 246 190 14 246 190 14
39410 -246 190 14 246 190 14 246 190 14 246 190 14
39411 -246 190 14 246 190 14 246 190 14 246 190 14
39412 -246 190 14 246 190 14 246 190 14 246 190 14
39413 -242 186 14 226 184 13 210 162 10 142 110 46
39414 -226 226 226 253 253 253 253 253 253 253 253 253
39415 -253 253 253 253 253 253 253 253 253 253 253 253
39416 -253 253 253 253 253 253 253 253 253 253 253 253
39417 -198 198 198 66 66 66 2 2 6 2 2 6
39418 - 2 2 6 2 2 6 50 34 6 156 107 11
39419 -219 162 10 239 182 13 246 186 14 246 190 14
39420 -246 190 14 246 190 14 246 190 14 246 190 14
39421 -246 190 14 246 190 14 246 190 14 246 190 14
39422 -246 190 14 246 190 14 246 190 14 242 186 14
39423 -234 174 13 213 154 11 154 122 46 66 66 66
39424 - 30 30 30 10 10 10 0 0 0 0 0 0
39425 - 0 0 0 0 0 0 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 0 0 0
39427 - 0 0 0 0 0 0 6 6 6 22 22 22
39428 - 58 58 58 154 121 60 206 145 10 234 174 13
39429 -242 186 14 246 186 14 246 190 14 246 190 14
39430 -246 190 14 246 190 14 246 190 14 246 190 14
39431 -246 190 14 246 190 14 246 190 14 246 190 14
39432 -246 190 14 246 190 14 246 190 14 246 190 14
39433 -246 186 14 236 178 12 210 162 10 163 110 8
39434 - 61 42 6 138 138 138 218 218 218 250 250 250
39435 -253 253 253 253 253 253 253 253 253 250 250 250
39436 -242 242 242 210 210 210 144 144 144 66 66 66
39437 - 6 6 6 2 2 6 2 2 6 2 2 6
39438 - 2 2 6 2 2 6 61 42 6 163 110 8
39439 -216 158 10 236 178 12 246 190 14 246 190 14
39440 -246 190 14 246 190 14 246 190 14 246 190 14
39441 -246 190 14 246 190 14 246 190 14 246 190 14
39442 -246 190 14 239 182 13 230 174 11 216 158 10
39443 -190 142 34 124 112 88 70 70 70 38 38 38
39444 - 18 18 18 6 6 6 0 0 0 0 0 0
39445 - 0 0 0 0 0 0 0 0 0 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 0 0 0
39447 - 0 0 0 0 0 0 6 6 6 22 22 22
39448 - 62 62 62 168 124 44 206 145 10 224 166 10
39449 -236 178 12 239 182 13 242 186 14 242 186 14
39450 -246 186 14 246 190 14 246 190 14 246 190 14
39451 -246 190 14 246 190 14 246 190 14 246 190 14
39452 -246 190 14 246 190 14 246 190 14 246 190 14
39453 -246 190 14 236 178 12 216 158 10 175 118 6
39454 - 80 54 7 2 2 6 6 6 6 30 30 30
39455 - 54 54 54 62 62 62 50 50 50 38 38 38
39456 - 14 14 14 2 2 6 2 2 6 2 2 6
39457 - 2 2 6 2 2 6 2 2 6 2 2 6
39458 - 2 2 6 6 6 6 80 54 7 167 114 7
39459 -213 154 11 236 178 12 246 190 14 246 190 14
39460 -246 190 14 246 190 14 246 190 14 246 190 14
39461 -246 190 14 242 186 14 239 182 13 239 182 13
39462 -230 174 11 210 150 10 174 135 50 124 112 88
39463 - 82 82 82 54 54 54 34 34 34 18 18 18
39464 - 6 6 6 0 0 0 0 0 0 0 0 0
39465 - 0 0 0 0 0 0 0 0 0 0 0 0
39466 - 0 0 0 0 0 0 0 0 0 0 0 0
39467 - 0 0 0 0 0 0 6 6 6 18 18 18
39468 - 50 50 50 158 118 36 192 133 9 200 144 11
39469 -216 158 10 219 162 10 224 166 10 226 170 11
39470 -230 174 11 236 178 12 239 182 13 239 182 13
39471 -242 186 14 246 186 14 246 190 14 246 190 14
39472 -246 190 14 246 190 14 246 190 14 246 190 14
39473 -246 186 14 230 174 11 210 150 10 163 110 8
39474 -104 69 6 10 10 10 2 2 6 2 2 6
39475 - 2 2 6 2 2 6 2 2 6 2 2 6
39476 - 2 2 6 2 2 6 2 2 6 2 2 6
39477 - 2 2 6 2 2 6 2 2 6 2 2 6
39478 - 2 2 6 6 6 6 91 60 6 167 114 7
39479 -206 145 10 230 174 11 242 186 14 246 190 14
39480 -246 190 14 246 190 14 246 186 14 242 186 14
39481 -239 182 13 230 174 11 224 166 10 213 154 11
39482 -180 133 36 124 112 88 86 86 86 58 58 58
39483 - 38 38 38 22 22 22 10 10 10 6 6 6
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 14 14 14
39488 - 34 34 34 70 70 70 138 110 50 158 118 36
39489 -167 114 7 180 123 7 192 133 9 197 138 11
39490 -200 144 11 206 145 10 213 154 11 219 162 10
39491 -224 166 10 230 174 11 239 182 13 242 186 14
39492 -246 186 14 246 186 14 246 186 14 246 186 14
39493 -239 182 13 216 158 10 185 133 11 152 99 6
39494 -104 69 6 18 14 6 2 2 6 2 2 6
39495 - 2 2 6 2 2 6 2 2 6 2 2 6
39496 - 2 2 6 2 2 6 2 2 6 2 2 6
39497 - 2 2 6 2 2 6 2 2 6 2 2 6
39498 - 2 2 6 6 6 6 80 54 7 152 99 6
39499 -192 133 9 219 162 10 236 178 12 239 182 13
39500 -246 186 14 242 186 14 239 182 13 236 178 12
39501 -224 166 10 206 145 10 192 133 9 154 121 60
39502 - 94 94 94 62 62 62 42 42 42 22 22 22
39503 - 14 14 14 6 6 6 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 0 6 6 6
39508 - 18 18 18 34 34 34 58 58 58 78 78 78
39509 -101 98 89 124 112 88 142 110 46 156 107 11
39510 -163 110 8 167 114 7 175 118 6 180 123 7
39511 -185 133 11 197 138 11 210 150 10 219 162 10
39512 -226 170 11 236 178 12 236 178 12 234 174 13
39513 -219 162 10 197 138 11 163 110 8 130 83 6
39514 - 91 60 6 10 10 10 2 2 6 2 2 6
39515 - 18 18 18 38 38 38 38 38 38 38 38 38
39516 - 38 38 38 38 38 38 38 38 38 38 38 38
39517 - 38 38 38 38 38 38 26 26 26 2 2 6
39518 - 2 2 6 6 6 6 70 47 6 137 92 6
39519 -175 118 6 200 144 11 219 162 10 230 174 11
39520 -234 174 13 230 174 11 219 162 10 210 150 10
39521 -192 133 9 163 110 8 124 112 88 82 82 82
39522 - 50 50 50 30 30 30 14 14 14 6 6 6
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 0 0 0
39525 - 0 0 0 0 0 0 0 0 0 0 0 0
39526 - 0 0 0 0 0 0 0 0 0 0 0 0
39527 - 0 0 0 0 0 0 0 0 0 0 0 0
39528 - 6 6 6 14 14 14 22 22 22 34 34 34
39529 - 42 42 42 58 58 58 74 74 74 86 86 86
39530 -101 98 89 122 102 70 130 98 46 121 87 25
39531 -137 92 6 152 99 6 163 110 8 180 123 7
39532 -185 133 11 197 138 11 206 145 10 200 144 11
39533 -180 123 7 156 107 11 130 83 6 104 69 6
39534 - 50 34 6 54 54 54 110 110 110 101 98 89
39535 - 86 86 86 82 82 82 78 78 78 78 78 78
39536 - 78 78 78 78 78 78 78 78 78 78 78 78
39537 - 78 78 78 82 82 82 86 86 86 94 94 94
39538 -106 106 106 101 101 101 86 66 34 124 80 6
39539 -156 107 11 180 123 7 192 133 9 200 144 11
39540 -206 145 10 200 144 11 192 133 9 175 118 6
39541 -139 102 15 109 106 95 70 70 70 42 42 42
39542 - 22 22 22 10 10 10 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 6 6 6 10 10 10
39549 - 14 14 14 22 22 22 30 30 30 38 38 38
39550 - 50 50 50 62 62 62 74 74 74 90 90 90
39551 -101 98 89 112 100 78 121 87 25 124 80 6
39552 -137 92 6 152 99 6 152 99 6 152 99 6
39553 -138 86 6 124 80 6 98 70 6 86 66 30
39554 -101 98 89 82 82 82 58 58 58 46 46 46
39555 - 38 38 38 34 34 34 34 34 34 34 34 34
39556 - 34 34 34 34 34 34 34 34 34 34 34 34
39557 - 34 34 34 34 34 34 38 38 38 42 42 42
39558 - 54 54 54 82 82 82 94 86 76 91 60 6
39559 -134 86 6 156 107 11 167 114 7 175 118 6
39560 -175 118 6 167 114 7 152 99 6 121 87 25
39561 -101 98 89 62 62 62 34 34 34 18 18 18
39562 - 6 6 6 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 6 6 6 6 6 6 10 10 10
39570 - 18 18 18 22 22 22 30 30 30 42 42 42
39571 - 50 50 50 66 66 66 86 86 86 101 98 89
39572 -106 86 58 98 70 6 104 69 6 104 69 6
39573 -104 69 6 91 60 6 82 62 34 90 90 90
39574 - 62 62 62 38 38 38 22 22 22 14 14 14
39575 - 10 10 10 10 10 10 10 10 10 10 10 10
39576 - 10 10 10 10 10 10 6 6 6 10 10 10
39577 - 10 10 10 10 10 10 10 10 10 14 14 14
39578 - 22 22 22 42 42 42 70 70 70 89 81 66
39579 - 80 54 7 104 69 6 124 80 6 137 92 6
39580 -134 86 6 116 81 8 100 82 52 86 86 86
39581 - 58 58 58 30 30 30 14 14 14 6 6 6
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 6 6 6 10 10 10 14 14 14
39591 - 18 18 18 26 26 26 38 38 38 54 54 54
39592 - 70 70 70 86 86 86 94 86 76 89 81 66
39593 - 89 81 66 86 86 86 74 74 74 50 50 50
39594 - 30 30 30 14 14 14 6 6 6 0 0 0
39595 - 0 0 0 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 6 6 6 18 18 18 34 34 34 58 58 58
39599 - 82 82 82 89 81 66 89 81 66 89 81 66
39600 - 94 86 66 94 86 76 74 74 74 50 50 50
39601 - 26 26 26 14 14 14 6 6 6 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 6 6 6 6 6 6 14 14 14 18 18 18
39612 - 30 30 30 38 38 38 46 46 46 54 54 54
39613 - 50 50 50 42 42 42 30 30 30 18 18 18
39614 - 10 10 10 0 0 0 0 0 0 0 0 0
39615 - 0 0 0 0 0 0 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 6 6 6 14 14 14 26 26 26
39619 - 38 38 38 50 50 50 58 58 58 58 58 58
39620 - 54 54 54 42 42 42 30 30 30 18 18 18
39621 - 10 10 10 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 6 6 6
39632 - 6 6 6 10 10 10 14 14 14 18 18 18
39633 - 18 18 18 14 14 14 10 10 10 6 6 6
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 6 6 6
39639 - 14 14 14 18 18 18 22 22 22 22 22 22
39640 - 18 18 18 14 14 14 10 10 10 6 6 6
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39659 +4 4 4 4 4 4
39660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39673 +4 4 4 4 4 4
39674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39687 +4 4 4 4 4 4
39688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39701 +4 4 4 4 4 4
39702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39715 +4 4 4 4 4 4
39716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39724 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
39727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39729 +4 4 4 4 4 4
39730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39734 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
39735 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
39736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39739 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
39740 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39741 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
39742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39743 +4 4 4 4 4 4
39744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39748 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
39749 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
39750 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 1 1 1 6 6 6
39754 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
39755 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
39756 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39757 +4 4 4 4 4 4
39758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39762 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
39763 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
39764 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39765 +4 4 4 4 4 4 4 4 4 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 0 0 0 4 4 4 41 54 63 125 124 125
39768 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
39769 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
39770 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
39771 +4 4 4 4 4 4
39772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39775 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
39776 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
39777 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
39778 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
39779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39780 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39781 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
39782 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
39783 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
39784 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
39785 +4 4 4 4 4 4
39786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39789 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
39790 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
39791 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
39792 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
39793 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39794 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
39795 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
39796 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
39797 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
39798 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
39799 +4 4 4 4 4 4
39800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39803 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
39804 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
39805 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
39806 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
39807 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
39808 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
39809 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
39810 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
39811 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
39812 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
39813 +4 4 4 4 4 4
39814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39816 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
39817 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
39818 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
39819 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
39820 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
39821 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
39822 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
39823 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
39824 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
39825 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
39826 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
39827 +4 4 4 4 4 4
39828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39830 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
39831 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
39832 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
39833 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
39834 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
39835 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
39836 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
39837 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
39838 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
39839 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
39840 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
39841 +4 4 4 4 4 4
39842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39844 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
39845 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
39846 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
39847 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
39848 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
39849 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
39850 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
39851 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
39852 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
39853 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
39854 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39855 +4 4 4 4 4 4
39856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39858 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
39859 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
39860 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
39861 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
39862 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
39863 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
39864 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
39865 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
39866 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
39867 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
39868 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
39869 +4 4 4 4 4 4
39870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39871 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
39872 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
39873 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
39874 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
39875 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
39876 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
39877 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
39878 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
39879 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
39880 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
39881 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
39882 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
39883 +4 4 4 4 4 4
39884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39885 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
39886 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
39887 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
39888 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
39889 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
39890 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
39891 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
39892 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
39893 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
39894 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
39895 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
39896 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
39897 +0 0 0 4 4 4
39898 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39899 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
39900 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
39901 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
39902 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
39903 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
39904 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
39905 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
39906 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
39907 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
39908 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
39909 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
39910 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
39911 +2 0 0 0 0 0
39912 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
39913 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
39914 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
39915 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
39916 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
39917 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
39918 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
39919 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
39920 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
39921 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
39922 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
39923 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
39924 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
39925 +37 38 37 0 0 0
39926 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
39927 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
39928 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
39929 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
39930 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
39931 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
39932 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
39933 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
39934 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
39935 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
39936 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
39937 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
39938 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
39939 +85 115 134 4 0 0
39940 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
39941 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
39942 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
39943 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
39944 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
39945 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
39946 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
39947 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
39948 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
39949 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
39950 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
39951 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
39952 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
39953 +60 73 81 4 0 0
39954 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
39955 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
39956 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
39957 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
39958 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
39959 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
39960 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
39961 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
39962 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
39963 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
39964 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
39965 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
39966 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
39967 +16 19 21 4 0 0
39968 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
39969 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
39970 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
39971 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
39972 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
39973 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
39974 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
39975 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
39976 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
39977 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
39978 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
39979 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
39980 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
39981 +4 0 0 4 3 3
39982 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
39983 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
39984 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
39985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
39986 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
39987 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
39988 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
39989 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
39990 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
39991 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
39992 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
39993 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
39994 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
39995 +3 2 2 4 4 4
39996 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
39997 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
39998 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
39999 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40000 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40001 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40002 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40003 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40004 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40005 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40006 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40007 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40008 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40009 +4 4 4 4 4 4
40010 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40011 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40012 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40013 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40014 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40015 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40016 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40017 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40018 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40019 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40020 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40021 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40022 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40023 +4 4 4 4 4 4
40024 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40025 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40026 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40027 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40028 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40029 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40030 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40031 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40032 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40033 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40034 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40035 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40036 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40037 +5 5 5 5 5 5
40038 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40039 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40040 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40041 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40042 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40043 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40044 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40045 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40046 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40047 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40048 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40049 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40050 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40051 +5 5 5 4 4 4
40052 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40053 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40054 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40055 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40056 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40057 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40058 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40059 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40060 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40061 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40062 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40063 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40065 +4 4 4 4 4 4
40066 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40067 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40068 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40069 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40070 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40071 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40072 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40073 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40074 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40075 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40076 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40077 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40079 +4 4 4 4 4 4
40080 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40081 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40082 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40083 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40084 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40085 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40086 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40087 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40088 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40089 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40090 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40093 +4 4 4 4 4 4
40094 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40095 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40096 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40097 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40098 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40099 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40100 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40101 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40102 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40103 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40104 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40107 +4 4 4 4 4 4
40108 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40109 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40110 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40111 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40112 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40113 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40114 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40115 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40116 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40117 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40118 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40121 +4 4 4 4 4 4
40122 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40123 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40124 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40125 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40126 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40127 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40128 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40129 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40130 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40131 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40132 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40135 +4 4 4 4 4 4
40136 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40137 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40138 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40139 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40140 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40141 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40142 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40143 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40144 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40145 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40146 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40149 +4 4 4 4 4 4
40150 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40151 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40152 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40153 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40154 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40155 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40156 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40157 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40158 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40159 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40160 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40163 +4 4 4 4 4 4
40164 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40165 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40166 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40167 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40168 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40169 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40170 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40171 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40172 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40173 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40174 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40177 +4 4 4 4 4 4
40178 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40179 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40180 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40181 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40182 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40183 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40184 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40185 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40186 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40187 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40188 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40191 +4 4 4 4 4 4
40192 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40193 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40194 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40195 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40196 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40197 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40198 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40199 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40200 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40201 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40202 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40205 +4 4 4 4 4 4
40206 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40207 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40208 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40209 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40210 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40211 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40212 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40213 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40214 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40215 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40216 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40219 +4 4 4 4 4 4
40220 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40221 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40222 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40223 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40224 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40225 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40226 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40227 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40228 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40229 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40230 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40233 +4 4 4 4 4 4
40234 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40235 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40236 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40237 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40238 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40239 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40240 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40241 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40242 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40243 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40244 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40247 +4 4 4 4 4 4
40248 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40249 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40250 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40251 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40252 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40253 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40254 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40255 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40256 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40257 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40258 +0 0 0 3 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40261 +4 4 4 4 4 4
40262 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40263 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40264 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40265 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40266 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40267 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40268 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40269 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40270 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40271 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40272 +0 0 0 3 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4
40275 +4 4 4 4 4 4
40276 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40277 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40278 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40279 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40280 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40281 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40282 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40283 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40284 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40285 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40286 +0 0 0 3 3 3 5 5 5 4 4 4 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 4 4 4
40290 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40291 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40292 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40293 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40294 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40295 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40296 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40297 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40298 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40299 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40300 +0 0 0 3 3 3 5 5 5 4 4 4 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
40304 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40305 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40306 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40307 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40308 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40309 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40310 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40311 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40312 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40313 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40314 +0 0 0 3 3 3 5 5 5 4 4 4 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
40318 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40319 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40320 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40321 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40322 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40323 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40324 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40325 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40326 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40327 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40328 +0 0 0 3 3 3 5 5 5 4 4 4 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
40332 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40333 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40334 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40335 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40336 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40337 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40338 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40339 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40340 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40341 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40342 +0 0 0 3 3 3 5 5 5 4 4 4 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
40346 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40347 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40348 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40349 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40350 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40351 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40352 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40353 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40354 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40355 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40356 +0 0 0 3 3 3 5 5 5 4 4 4 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
40360 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40361 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40362 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40363 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40364 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40365 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40366 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40367 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40368 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40369 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40370 +0 0 0 3 3 3 5 5 5 4 4 4 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
40374 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40375 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40376 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40377 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40378 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40379 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40380 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40381 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40382 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40383 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40384 +0 0 0 3 3 3 5 5 5 4 4 4 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
40388 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40389 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40390 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40391 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40392 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40393 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40394 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40395 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40396 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40397 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40398 +0 0 0 3 3 3 5 5 5 4 4 4 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
40402 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40403 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40404 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40405 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40406 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40407 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40408 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40409 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40410 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40411 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40412 +0 0 0 3 3 3 5 5 5 4 4 4 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
40416 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40417 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40418 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40419 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40420 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40421 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40422 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40423 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40424 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40425 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40426 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40429 +4 4 4 4 4 4
40430 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40431 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40432 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40433 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40434 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40435 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40436 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40437 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40438 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40439 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40440 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40443 +4 4 4 4 4 4
40444 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40445 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40446 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40447 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40448 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40449 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40450 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40451 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40452 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40453 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40454 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40457 +4 4 4 4 4 4
40458 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40459 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40460 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40461 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40462 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40463 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40464 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40465 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40466 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40467 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40471 +4 4 4 4 4 4
40472 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40473 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40474 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40475 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40476 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40477 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40478 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40479 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40480 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40481 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40485 +4 4 4 4 4 4
40486 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40487 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40488 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40489 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40490 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40491 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40492 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40493 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40494 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40495 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40499 +4 4 4 4 4 4
40500 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40501 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40502 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40503 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40504 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40505 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40506 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40507 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40508 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40509 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40513 +4 4 4 4 4 4
40514 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40515 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40516 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40517 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40518 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40519 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40520 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40521 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40522 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
40523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40527 +4 4 4 4 4 4
40528 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40529 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40530 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40531 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40532 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40533 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40534 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40535 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40536 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
40537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40541 +4 4 4 4 4 4
40542 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40543 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40544 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40545 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40546 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40547 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40548 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40549 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40550 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40555 +4 4 4 4 4 4
40556 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
40557 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40558 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40559 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40560 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40561 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40562 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40563 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
40564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40569 +4 4 4 4 4 4
40570 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40571 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40572 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40573 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40574 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40575 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40576 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40577 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40583 +4 4 4 4 4 4
40584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40585 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40586 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40587 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40588 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40589 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40590 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40591 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
40592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40597 +4 4 4 4 4 4
40598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40599 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40600 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40601 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40602 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40603 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40604 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40605 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
40606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40611 +4 4 4 4 4 4
40612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40613 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40614 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40615 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40616 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40617 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40618 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40619 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40625 +4 4 4 4 4 4
40626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40628 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40629 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40630 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40631 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40632 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40633 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40639 +4 4 4 4 4 4
40640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40643 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40644 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
40645 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
40646 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
40647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40653 +4 4 4 4 4 4
40654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40657 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40658 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40659 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
40660 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
40661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40667 +4 4 4 4 4 4
40668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40671 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40672 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40673 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40674 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
40675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40681 +4 4 4 4 4 4
40682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40685 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
40686 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
40687 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
40688 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
40689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40695 +4 4 4 4 4 4
40696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40700 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
40701 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40702 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40709 +4 4 4 4 4 4
40710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40714 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
40715 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
40716 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40723 +4 4 4 4 4 4
40724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40728 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
40729 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
40730 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40737 +4 4 4 4 4 4
40738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40742 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
40743 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
40744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40751 +4 4 4 4 4 4
40752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40756 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40757 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
40758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40765 +4 4 4 4 4 4
40766 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
40767 index 3473e75..c930142 100644
40768 --- a/drivers/video/udlfb.c
40769 +++ b/drivers/video/udlfb.c
40770 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
40771 dlfb_urb_completion(urb);
40772
40773 error:
40774 - atomic_add(bytes_sent, &dev->bytes_sent);
40775 - atomic_add(bytes_identical, &dev->bytes_identical);
40776 - atomic_add(width*height*2, &dev->bytes_rendered);
40777 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40778 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40779 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
40780 end_cycles = get_cycles();
40781 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
40782 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40783 >> 10)), /* Kcycles */
40784 &dev->cpu_kcycles_used);
40785
40786 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
40787 dlfb_urb_completion(urb);
40788
40789 error:
40790 - atomic_add(bytes_sent, &dev->bytes_sent);
40791 - atomic_add(bytes_identical, &dev->bytes_identical);
40792 - atomic_add(bytes_rendered, &dev->bytes_rendered);
40793 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40794 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40795 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
40796 end_cycles = get_cycles();
40797 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
40798 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40799 >> 10)), /* Kcycles */
40800 &dev->cpu_kcycles_used);
40801 }
40802 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
40803 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40804 struct dlfb_data *dev = fb_info->par;
40805 return snprintf(buf, PAGE_SIZE, "%u\n",
40806 - atomic_read(&dev->bytes_rendered));
40807 + atomic_read_unchecked(&dev->bytes_rendered));
40808 }
40809
40810 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40811 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40812 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40813 struct dlfb_data *dev = fb_info->par;
40814 return snprintf(buf, PAGE_SIZE, "%u\n",
40815 - atomic_read(&dev->bytes_identical));
40816 + atomic_read_unchecked(&dev->bytes_identical));
40817 }
40818
40819 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40820 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40821 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40822 struct dlfb_data *dev = fb_info->par;
40823 return snprintf(buf, PAGE_SIZE, "%u\n",
40824 - atomic_read(&dev->bytes_sent));
40825 + atomic_read_unchecked(&dev->bytes_sent));
40826 }
40827
40828 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40829 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40830 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40831 struct dlfb_data *dev = fb_info->par;
40832 return snprintf(buf, PAGE_SIZE, "%u\n",
40833 - atomic_read(&dev->cpu_kcycles_used));
40834 + atomic_read_unchecked(&dev->cpu_kcycles_used));
40835 }
40836
40837 static ssize_t edid_show(
40838 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
40839 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40840 struct dlfb_data *dev = fb_info->par;
40841
40842 - atomic_set(&dev->bytes_rendered, 0);
40843 - atomic_set(&dev->bytes_identical, 0);
40844 - atomic_set(&dev->bytes_sent, 0);
40845 - atomic_set(&dev->cpu_kcycles_used, 0);
40846 + atomic_set_unchecked(&dev->bytes_rendered, 0);
40847 + atomic_set_unchecked(&dev->bytes_identical, 0);
40848 + atomic_set_unchecked(&dev->bytes_sent, 0);
40849 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
40850
40851 return count;
40852 }
40853 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
40854 index 7f8472c..9842e87 100644
40855 --- a/drivers/video/uvesafb.c
40856 +++ b/drivers/video/uvesafb.c
40857 @@ -19,6 +19,7 @@
40858 #include <linux/io.h>
40859 #include <linux/mutex.h>
40860 #include <linux/slab.h>
40861 +#include <linux/moduleloader.h>
40862 #include <video/edid.h>
40863 #include <video/uvesafb.h>
40864 #ifdef CONFIG_X86
40865 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
40866 NULL,
40867 };
40868
40869 - return call_usermodehelper(v86d_path, argv, envp, 1);
40870 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
40871 }
40872
40873 /*
40874 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
40875 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
40876 par->pmi_setpal = par->ypan = 0;
40877 } else {
40878 +
40879 +#ifdef CONFIG_PAX_KERNEXEC
40880 +#ifdef CONFIG_MODULES
40881 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
40882 +#endif
40883 + if (!par->pmi_code) {
40884 + par->pmi_setpal = par->ypan = 0;
40885 + return 0;
40886 + }
40887 +#endif
40888 +
40889 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
40890 + task->t.regs.edi);
40891 +
40892 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40893 + pax_open_kernel();
40894 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
40895 + pax_close_kernel();
40896 +
40897 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
40898 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
40899 +#else
40900 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
40901 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
40902 +#endif
40903 +
40904 printk(KERN_INFO "uvesafb: protected mode interface info at "
40905 "%04x:%04x\n",
40906 (u16)task->t.regs.es, (u16)task->t.regs.edi);
40907 @@ -1821,6 +1844,11 @@ out:
40908 if (par->vbe_modes)
40909 kfree(par->vbe_modes);
40910
40911 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40912 + if (par->pmi_code)
40913 + module_free_exec(NULL, par->pmi_code);
40914 +#endif
40915 +
40916 framebuffer_release(info);
40917 return err;
40918 }
40919 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
40920 kfree(par->vbe_state_orig);
40921 if (par->vbe_state_saved)
40922 kfree(par->vbe_state_saved);
40923 +
40924 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40925 + if (par->pmi_code)
40926 + module_free_exec(NULL, par->pmi_code);
40927 +#endif
40928 +
40929 }
40930
40931 framebuffer_release(info);
40932 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
40933 index 501b340..86bd4cf 100644
40934 --- a/drivers/video/vesafb.c
40935 +++ b/drivers/video/vesafb.c
40936 @@ -9,6 +9,7 @@
40937 */
40938
40939 #include <linux/module.h>
40940 +#include <linux/moduleloader.h>
40941 #include <linux/kernel.h>
40942 #include <linux/errno.h>
40943 #include <linux/string.h>
40944 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
40945 static int vram_total __initdata; /* Set total amount of memory */
40946 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
40947 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
40948 -static void (*pmi_start)(void) __read_mostly;
40949 -static void (*pmi_pal) (void) __read_mostly;
40950 +static void (*pmi_start)(void) __read_only;
40951 +static void (*pmi_pal) (void) __read_only;
40952 static int depth __read_mostly;
40953 static int vga_compat __read_mostly;
40954 /* --------------------------------------------------------------------- */
40955 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
40956 unsigned int size_vmode;
40957 unsigned int size_remap;
40958 unsigned int size_total;
40959 + void *pmi_code = NULL;
40960
40961 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
40962 return -ENODEV;
40963 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
40964 size_remap = size_total;
40965 vesafb_fix.smem_len = size_remap;
40966
40967 -#ifndef __i386__
40968 - screen_info.vesapm_seg = 0;
40969 -#endif
40970 -
40971 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
40972 printk(KERN_WARNING
40973 "vesafb: cannot reserve video memory at 0x%lx\n",
40974 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
40975 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
40976 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
40977
40978 +#ifdef __i386__
40979 +
40980 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40981 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
40982 + if (!pmi_code)
40983 +#elif !defined(CONFIG_PAX_KERNEXEC)
40984 + if (0)
40985 +#endif
40986 +
40987 +#endif
40988 + screen_info.vesapm_seg = 0;
40989 +
40990 if (screen_info.vesapm_seg) {
40991 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
40992 - screen_info.vesapm_seg,screen_info.vesapm_off);
40993 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
40994 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
40995 }
40996
40997 if (screen_info.vesapm_seg < 0xc000)
40998 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
40999
41000 if (ypan || pmi_setpal) {
41001 unsigned short *pmi_base;
41002 +
41003 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41004 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41005 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41006 +
41007 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41008 + pax_open_kernel();
41009 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41010 +#else
41011 + pmi_code = pmi_base;
41012 +#endif
41013 +
41014 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41015 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41016 +
41017 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41018 + pmi_start = ktva_ktla(pmi_start);
41019 + pmi_pal = ktva_ktla(pmi_pal);
41020 + pax_close_kernel();
41021 +#endif
41022 +
41023 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41024 if (pmi_base[3]) {
41025 printk(KERN_INFO "vesafb: pmi: ports = ");
41026 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41027 info->node, info->fix.id);
41028 return 0;
41029 err:
41030 +
41031 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41032 + module_free_exec(NULL, pmi_code);
41033 +#endif
41034 +
41035 if (info->screen_base)
41036 iounmap(info->screen_base);
41037 framebuffer_release(info);
41038 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41039 index 88714ae..16c2e11 100644
41040 --- a/drivers/video/via/via_clock.h
41041 +++ b/drivers/video/via/via_clock.h
41042 @@ -56,7 +56,7 @@ struct via_clock {
41043
41044 void (*set_engine_pll_state)(u8 state);
41045 void (*set_engine_pll)(struct via_pll_config config);
41046 -};
41047 +} __no_const;
41048
41049
41050 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41051 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41052 index e56c934..fc22f4b 100644
41053 --- a/drivers/xen/xen-pciback/conf_space.h
41054 +++ b/drivers/xen/xen-pciback/conf_space.h
41055 @@ -44,15 +44,15 @@ struct config_field {
41056 struct {
41057 conf_dword_write write;
41058 conf_dword_read read;
41059 - } dw;
41060 + } __no_const dw;
41061 struct {
41062 conf_word_write write;
41063 conf_word_read read;
41064 - } w;
41065 + } __no_const w;
41066 struct {
41067 conf_byte_write write;
41068 conf_byte_read read;
41069 - } b;
41070 + } __no_const b;
41071 } u;
41072 struct list_head list;
41073 };
41074 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41075 index 879ed88..bc03a01 100644
41076 --- a/fs/9p/vfs_inode.c
41077 +++ b/fs/9p/vfs_inode.c
41078 @@ -1286,7 +1286,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41079 void
41080 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41081 {
41082 - char *s = nd_get_link(nd);
41083 + const char *s = nd_get_link(nd);
41084
41085 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
41086 IS_ERR(s) ? "<error>" : s);
41087 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41088 index 79e2ca7..5828ad1 100644
41089 --- a/fs/Kconfig.binfmt
41090 +++ b/fs/Kconfig.binfmt
41091 @@ -86,7 +86,7 @@ config HAVE_AOUT
41092
41093 config BINFMT_AOUT
41094 tristate "Kernel support for a.out and ECOFF binaries"
41095 - depends on HAVE_AOUT
41096 + depends on HAVE_AOUT && BROKEN
41097 ---help---
41098 A.out (Assembler.OUTput) is a set of formats for libraries and
41099 executables used in the earliest versions of UNIX. Linux used
41100 diff --git a/fs/aio.c b/fs/aio.c
41101 index 67e4b90..fbb09dc 100644
41102 --- a/fs/aio.c
41103 +++ b/fs/aio.c
41104 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41105 size += sizeof(struct io_event) * nr_events;
41106 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41107
41108 - if (nr_pages < 0)
41109 + if (nr_pages <= 0)
41110 return -EINVAL;
41111
41112 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41113 @@ -1463,22 +1463,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41114 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41115 {
41116 ssize_t ret;
41117 + struct iovec iovstack;
41118
41119 #ifdef CONFIG_COMPAT
41120 if (compat)
41121 ret = compat_rw_copy_check_uvector(type,
41122 (struct compat_iovec __user *)kiocb->ki_buf,
41123 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41124 + kiocb->ki_nbytes, 1, &iovstack,
41125 &kiocb->ki_iovec, 1);
41126 else
41127 #endif
41128 ret = rw_copy_check_uvector(type,
41129 (struct iovec __user *)kiocb->ki_buf,
41130 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41131 + kiocb->ki_nbytes, 1, &iovstack,
41132 &kiocb->ki_iovec, 1);
41133 if (ret < 0)
41134 goto out;
41135
41136 + if (kiocb->ki_iovec == &iovstack) {
41137 + kiocb->ki_inline_vec = iovstack;
41138 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41139 + }
41140 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41141 kiocb->ki_cur_seg = 0;
41142 /* ki_nbytes/left now reflect bytes instead of segs */
41143 diff --git a/fs/attr.c b/fs/attr.c
41144 index 7ee7ba4..0c61a60 100644
41145 --- a/fs/attr.c
41146 +++ b/fs/attr.c
41147 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41148 unsigned long limit;
41149
41150 limit = rlimit(RLIMIT_FSIZE);
41151 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41152 if (limit != RLIM_INFINITY && offset > limit)
41153 goto out_sig;
41154 if (offset > inode->i_sb->s_maxbytes)
41155 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41156 index 6861f61..a25f010 100644
41157 --- a/fs/autofs4/waitq.c
41158 +++ b/fs/autofs4/waitq.c
41159 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
41160 {
41161 unsigned long sigpipe, flags;
41162 mm_segment_t fs;
41163 - const char *data = (const char *)addr;
41164 + const char __user *data = (const char __force_user *)addr;
41165 ssize_t wr = 0;
41166
41167 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
41168 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41169 index 8342ca6..82fd192 100644
41170 --- a/fs/befs/linuxvfs.c
41171 +++ b/fs/befs/linuxvfs.c
41172 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41173 {
41174 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41175 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41176 - char *link = nd_get_link(nd);
41177 + const char *link = nd_get_link(nd);
41178 if (!IS_ERR(link))
41179 kfree(link);
41180 }
41181 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41182 index a6395bd..f1e376a 100644
41183 --- a/fs/binfmt_aout.c
41184 +++ b/fs/binfmt_aout.c
41185 @@ -16,6 +16,7 @@
41186 #include <linux/string.h>
41187 #include <linux/fs.h>
41188 #include <linux/file.h>
41189 +#include <linux/security.h>
41190 #include <linux/stat.h>
41191 #include <linux/fcntl.h>
41192 #include <linux/ptrace.h>
41193 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41194 #endif
41195 # define START_STACK(u) ((void __user *)u.start_stack)
41196
41197 + memset(&dump, 0, sizeof(dump));
41198 +
41199 fs = get_fs();
41200 set_fs(KERNEL_DS);
41201 has_dumped = 1;
41202 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41203
41204 /* If the size of the dump file exceeds the rlimit, then see what would happen
41205 if we wrote the stack, but not the data area. */
41206 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41207 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41208 dump.u_dsize = 0;
41209
41210 /* Make sure we have enough room to write the stack and data areas. */
41211 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41212 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41213 dump.u_ssize = 0;
41214
41215 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41216 rlim = rlimit(RLIMIT_DATA);
41217 if (rlim >= RLIM_INFINITY)
41218 rlim = ~0;
41219 +
41220 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41221 if (ex.a_data + ex.a_bss > rlim)
41222 return -ENOMEM;
41223
41224 @@ -259,9 +266,37 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41225 current->mm->free_area_cache = current->mm->mmap_base;
41226 current->mm->cached_hole_size = 0;
41227
41228 + retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
41229 + if (retval < 0) {
41230 + /* Someone check-me: is this error path enough? */
41231 + send_sig(SIGKILL, current, 0);
41232 + return retval;
41233 + }
41234 +
41235 install_exec_creds(bprm);
41236 current->flags &= ~PF_FORKNOEXEC;
41237
41238 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41239 + current->mm->pax_flags = 0UL;
41240 +#endif
41241 +
41242 +#ifdef CONFIG_PAX_PAGEEXEC
41243 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41244 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41245 +
41246 +#ifdef CONFIG_PAX_EMUTRAMP
41247 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41248 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41249 +#endif
41250 +
41251 +#ifdef CONFIG_PAX_MPROTECT
41252 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41253 + current->mm->pax_flags |= MF_PAX_MPROTECT;
41254 +#endif
41255 +
41256 + }
41257 +#endif
41258 +
41259 if (N_MAGIC(ex) == OMAGIC) {
41260 unsigned long text_addr, map_size;
41261 loff_t pos;
41262 @@ -334,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41263
41264 down_write(&current->mm->mmap_sem);
41265 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41266 - PROT_READ | PROT_WRITE | PROT_EXEC,
41267 + PROT_READ | PROT_WRITE,
41268 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41269 fd_offset + ex.a_text);
41270 up_write(&current->mm->mmap_sem);
41271 @@ -352,13 +387,6 @@ beyond_if:
41272 return retval;
41273 }
41274
41275 - retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
41276 - if (retval < 0) {
41277 - /* Someone check-me: is this error path enough? */
41278 - send_sig(SIGKILL, current, 0);
41279 - return retval;
41280 - }
41281 -
41282 current->mm->start_stack =
41283 (unsigned long) create_aout_tables((char __user *) bprm->p, bprm);
41284 #ifdef __alpha__
41285 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41286 index 6ff96c6..dbf63ee 100644
41287 --- a/fs/binfmt_elf.c
41288 +++ b/fs/binfmt_elf.c
41289 @@ -32,6 +32,7 @@
41290 #include <linux/elf.h>
41291 #include <linux/utsname.h>
41292 #include <linux/coredump.h>
41293 +#include <linux/xattr.h>
41294 #include <asm/uaccess.h>
41295 #include <asm/param.h>
41296 #include <asm/page.h>
41297 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41298 #define elf_core_dump NULL
41299 #endif
41300
41301 +#ifdef CONFIG_PAX_MPROTECT
41302 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41303 +#endif
41304 +
41305 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41306 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41307 #else
41308 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
41309 .load_binary = load_elf_binary,
41310 .load_shlib = load_elf_library,
41311 .core_dump = elf_core_dump,
41312 +
41313 +#ifdef CONFIG_PAX_MPROTECT
41314 + .handle_mprotect= elf_handle_mprotect,
41315 +#endif
41316 +
41317 .min_coredump = ELF_EXEC_PAGESIZE,
41318 };
41319
41320 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
41321
41322 static int set_brk(unsigned long start, unsigned long end)
41323 {
41324 + unsigned long e = end;
41325 +
41326 start = ELF_PAGEALIGN(start);
41327 end = ELF_PAGEALIGN(end);
41328 if (end > start) {
41329 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
41330 if (BAD_ADDR(addr))
41331 return addr;
41332 }
41333 - current->mm->start_brk = current->mm->brk = end;
41334 + current->mm->start_brk = current->mm->brk = e;
41335 return 0;
41336 }
41337
41338 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41339 elf_addr_t __user *u_rand_bytes;
41340 const char *k_platform = ELF_PLATFORM;
41341 const char *k_base_platform = ELF_BASE_PLATFORM;
41342 - unsigned char k_rand_bytes[16];
41343 + u32 k_rand_bytes[4];
41344 int items;
41345 elf_addr_t *elf_info;
41346 int ei_index = 0;
41347 const struct cred *cred = current_cred();
41348 struct vm_area_struct *vma;
41349 + unsigned long saved_auxv[AT_VECTOR_SIZE];
41350
41351 /*
41352 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41353 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41354 * Generate 16 random bytes for userspace PRNG seeding.
41355 */
41356 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41357 - u_rand_bytes = (elf_addr_t __user *)
41358 - STACK_ALLOC(p, sizeof(k_rand_bytes));
41359 + srandom32(k_rand_bytes[0] ^ random32());
41360 + srandom32(k_rand_bytes[1] ^ random32());
41361 + srandom32(k_rand_bytes[2] ^ random32());
41362 + srandom32(k_rand_bytes[3] ^ random32());
41363 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
41364 + u_rand_bytes = (elf_addr_t __user *) p;
41365 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41366 return -EFAULT;
41367
41368 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41369 return -EFAULT;
41370 current->mm->env_end = p;
41371
41372 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41373 +
41374 /* Put the elf_info on the stack in the right place. */
41375 sp = (elf_addr_t __user *)envp + 1;
41376 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41377 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41378 return -EFAULT;
41379 return 0;
41380 }
41381 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41382 {
41383 struct elf_phdr *elf_phdata;
41384 struct elf_phdr *eppnt;
41385 - unsigned long load_addr = 0;
41386 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41387 int load_addr_set = 0;
41388 unsigned long last_bss = 0, elf_bss = 0;
41389 - unsigned long error = ~0UL;
41390 + unsigned long error = -EINVAL;
41391 unsigned long total_size;
41392 int retval, i, size;
41393
41394 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41395 goto out_close;
41396 }
41397
41398 +#ifdef CONFIG_PAX_SEGMEXEC
41399 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41400 + pax_task_size = SEGMEXEC_TASK_SIZE;
41401 +#endif
41402 +
41403 eppnt = elf_phdata;
41404 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41405 if (eppnt->p_type == PT_LOAD) {
41406 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41407 k = load_addr + eppnt->p_vaddr;
41408 if (BAD_ADDR(k) ||
41409 eppnt->p_filesz > eppnt->p_memsz ||
41410 - eppnt->p_memsz > TASK_SIZE ||
41411 - TASK_SIZE - eppnt->p_memsz < k) {
41412 + eppnt->p_memsz > pax_task_size ||
41413 + pax_task_size - eppnt->p_memsz < k) {
41414 error = -ENOMEM;
41415 goto out_close;
41416 }
41417 @@ -528,6 +552,351 @@ out:
41418 return error;
41419 }
41420
41421 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41422 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41423 +{
41424 + unsigned long pax_flags = 0UL;
41425 +
41426 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41427 +
41428 +#ifdef CONFIG_PAX_PAGEEXEC
41429 + if (elf_phdata->p_flags & PF_PAGEEXEC)
41430 + pax_flags |= MF_PAX_PAGEEXEC;
41431 +#endif
41432 +
41433 +#ifdef CONFIG_PAX_SEGMEXEC
41434 + if (elf_phdata->p_flags & PF_SEGMEXEC)
41435 + pax_flags |= MF_PAX_SEGMEXEC;
41436 +#endif
41437 +
41438 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41439 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41440 + if ((__supported_pte_mask & _PAGE_NX))
41441 + pax_flags &= ~MF_PAX_SEGMEXEC;
41442 + else
41443 + pax_flags &= ~MF_PAX_PAGEEXEC;
41444 + }
41445 +#endif
41446 +
41447 +#ifdef CONFIG_PAX_EMUTRAMP
41448 + if (elf_phdata->p_flags & PF_EMUTRAMP)
41449 + pax_flags |= MF_PAX_EMUTRAMP;
41450 +#endif
41451 +
41452 +#ifdef CONFIG_PAX_MPROTECT
41453 + if (elf_phdata->p_flags & PF_MPROTECT)
41454 + pax_flags |= MF_PAX_MPROTECT;
41455 +#endif
41456 +
41457 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41458 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41459 + pax_flags |= MF_PAX_RANDMMAP;
41460 +#endif
41461 +
41462 +#endif
41463 +
41464 + return pax_flags;
41465 +}
41466 +
41467 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41468 +{
41469 + unsigned long pax_flags = 0UL;
41470 +
41471 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41472 +
41473 +#ifdef CONFIG_PAX_PAGEEXEC
41474 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41475 + pax_flags |= MF_PAX_PAGEEXEC;
41476 +#endif
41477 +
41478 +#ifdef CONFIG_PAX_SEGMEXEC
41479 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41480 + pax_flags |= MF_PAX_SEGMEXEC;
41481 +#endif
41482 +
41483 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41484 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41485 + if ((__supported_pte_mask & _PAGE_NX))
41486 + pax_flags &= ~MF_PAX_SEGMEXEC;
41487 + else
41488 + pax_flags &= ~MF_PAX_PAGEEXEC;
41489 + }
41490 +#endif
41491 +
41492 +#ifdef CONFIG_PAX_EMUTRAMP
41493 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41494 + pax_flags |= MF_PAX_EMUTRAMP;
41495 +#endif
41496 +
41497 +#ifdef CONFIG_PAX_MPROTECT
41498 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41499 + pax_flags |= MF_PAX_MPROTECT;
41500 +#endif
41501 +
41502 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41503 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41504 + pax_flags |= MF_PAX_RANDMMAP;
41505 +#endif
41506 +
41507 +#endif
41508 +
41509 + return pax_flags;
41510 +}
41511 +
41512 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41513 +{
41514 + unsigned long pax_flags = 0UL;
41515 +
41516 +#ifdef CONFIG_PAX_EI_PAX
41517 +
41518 +#ifdef CONFIG_PAX_PAGEEXEC
41519 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41520 + pax_flags |= MF_PAX_PAGEEXEC;
41521 +#endif
41522 +
41523 +#ifdef CONFIG_PAX_SEGMEXEC
41524 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41525 + pax_flags |= MF_PAX_SEGMEXEC;
41526 +#endif
41527 +
41528 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41529 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41530 + if ((__supported_pte_mask & _PAGE_NX))
41531 + pax_flags &= ~MF_PAX_SEGMEXEC;
41532 + else
41533 + pax_flags &= ~MF_PAX_PAGEEXEC;
41534 + }
41535 +#endif
41536 +
41537 +#ifdef CONFIG_PAX_EMUTRAMP
41538 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41539 + pax_flags |= MF_PAX_EMUTRAMP;
41540 +#endif
41541 +
41542 +#ifdef CONFIG_PAX_MPROTECT
41543 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41544 + pax_flags |= MF_PAX_MPROTECT;
41545 +#endif
41546 +
41547 +#ifdef CONFIG_PAX_ASLR
41548 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41549 + pax_flags |= MF_PAX_RANDMMAP;
41550 +#endif
41551 +
41552 +#else
41553 +
41554 +#ifdef CONFIG_PAX_PAGEEXEC
41555 + pax_flags |= MF_PAX_PAGEEXEC;
41556 +#endif
41557 +
41558 +#ifdef CONFIG_PAX_MPROTECT
41559 + pax_flags |= MF_PAX_MPROTECT;
41560 +#endif
41561 +
41562 +#ifdef CONFIG_PAX_RANDMMAP
41563 + pax_flags |= MF_PAX_RANDMMAP;
41564 +#endif
41565 +
41566 +#ifdef CONFIG_PAX_SEGMEXEC
41567 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41568 + pax_flags &= ~MF_PAX_PAGEEXEC;
41569 + pax_flags |= MF_PAX_SEGMEXEC;
41570 + }
41571 +#endif
41572 +
41573 +#endif
41574 +
41575 + return pax_flags;
41576 +}
41577 +
41578 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
41579 +{
41580 +
41581 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41582 + unsigned long i;
41583 +
41584 + for (i = 0UL; i < elf_ex->e_phnum; i++)
41585 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
41586 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
41587 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
41588 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
41589 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
41590 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
41591 + return ~0UL;
41592 +
41593 +#ifdef CONFIG_PAX_SOFTMODE
41594 + if (pax_softmode)
41595 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
41596 + else
41597 +#endif
41598 +
41599 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
41600 + break;
41601 + }
41602 +#endif
41603 +
41604 + return ~0UL;
41605 +}
41606 +
41607 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41608 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41609 +{
41610 + unsigned long pax_flags = 0UL;
41611 +
41612 +#ifdef CONFIG_PAX_PAGEEXEC
41613 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41614 + pax_flags |= MF_PAX_PAGEEXEC;
41615 +#endif
41616 +
41617 +#ifdef CONFIG_PAX_SEGMEXEC
41618 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41619 + pax_flags |= MF_PAX_SEGMEXEC;
41620 +#endif
41621 +
41622 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41623 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41624 + if ((__supported_pte_mask & _PAGE_NX))
41625 + pax_flags &= ~MF_PAX_SEGMEXEC;
41626 + else
41627 + pax_flags &= ~MF_PAX_PAGEEXEC;
41628 + }
41629 +#endif
41630 +
41631 +#ifdef CONFIG_PAX_EMUTRAMP
41632 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41633 + pax_flags |= MF_PAX_EMUTRAMP;
41634 +#endif
41635 +
41636 +#ifdef CONFIG_PAX_MPROTECT
41637 + if (pax_flags_softmode & MF_PAX_MPROTECT)
41638 + pax_flags |= MF_PAX_MPROTECT;
41639 +#endif
41640 +
41641 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41642 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41643 + pax_flags |= MF_PAX_RANDMMAP;
41644 +#endif
41645 +
41646 + return pax_flags;
41647 +}
41648 +
41649 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41650 +{
41651 + unsigned long pax_flags = 0UL;
41652 +
41653 +#ifdef CONFIG_PAX_PAGEEXEC
41654 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41655 + pax_flags |= MF_PAX_PAGEEXEC;
41656 +#endif
41657 +
41658 +#ifdef CONFIG_PAX_SEGMEXEC
41659 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41660 + pax_flags |= MF_PAX_SEGMEXEC;
41661 +#endif
41662 +
41663 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41664 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41665 + if ((__supported_pte_mask & _PAGE_NX))
41666 + pax_flags &= ~MF_PAX_SEGMEXEC;
41667 + else
41668 + pax_flags &= ~MF_PAX_PAGEEXEC;
41669 + }
41670 +#endif
41671 +
41672 +#ifdef CONFIG_PAX_EMUTRAMP
41673 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
41674 + pax_flags |= MF_PAX_EMUTRAMP;
41675 +#endif
41676 +
41677 +#ifdef CONFIG_PAX_MPROTECT
41678 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
41679 + pax_flags |= MF_PAX_MPROTECT;
41680 +#endif
41681 +
41682 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41683 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
41684 + pax_flags |= MF_PAX_RANDMMAP;
41685 +#endif
41686 +
41687 + return pax_flags;
41688 +}
41689 +#endif
41690 +
41691 +static unsigned long pax_parse_xattr_pax(struct file * const file)
41692 +{
41693 +
41694 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41695 + ssize_t xattr_size, i;
41696 + unsigned char xattr_value[5];
41697 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
41698 +
41699 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
41700 + if (xattr_size <= 0)
41701 + return ~0UL;
41702 +
41703 + for (i = 0; i < xattr_size; i++)
41704 + switch (xattr_value[i]) {
41705 + default:
41706 + return ~0UL;
41707 +
41708 +#define parse_flag(option1, option2, flag) \
41709 + case option1: \
41710 + pax_flags_hardmode |= MF_PAX_##flag; \
41711 + break; \
41712 + case option2: \
41713 + pax_flags_softmode |= MF_PAX_##flag; \
41714 + break;
41715 +
41716 + parse_flag('p', 'P', PAGEEXEC);
41717 + parse_flag('e', 'E', EMUTRAMP);
41718 + parse_flag('m', 'M', MPROTECT);
41719 + parse_flag('r', 'R', RANDMMAP);
41720 + parse_flag('s', 'S', SEGMEXEC);
41721 +
41722 +#undef parse_flag
41723 + }
41724 +
41725 + if (pax_flags_hardmode & pax_flags_softmode)
41726 + return ~0UL;
41727 +
41728 +#ifdef CONFIG_PAX_SOFTMODE
41729 + if (pax_softmode)
41730 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
41731 + else
41732 +#endif
41733 +
41734 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
41735 +#else
41736 + return ~0UL;
41737 +#endif
41738 +
41739 +}
41740 +
41741 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
41742 +{
41743 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
41744 +
41745 + pax_flags = pax_parse_ei_pax(elf_ex);
41746 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
41747 + xattr_pax_flags = pax_parse_xattr_pax(file);
41748 +
41749 + if (pt_pax_flags == ~0UL)
41750 + pt_pax_flags = xattr_pax_flags;
41751 + else if (xattr_pax_flags == ~0UL)
41752 + xattr_pax_flags = pt_pax_flags;
41753 + if (pt_pax_flags != xattr_pax_flags)
41754 + return -EINVAL;
41755 + if (pt_pax_flags != ~0UL)
41756 + pax_flags = pt_pax_flags;
41757 +
41758 + if (0 > pax_check_flags(&pax_flags))
41759 + return -EINVAL;
41760 +
41761 + current->mm->pax_flags = pax_flags;
41762 + return 0;
41763 +}
41764 +#endif
41765 +
41766 /*
41767 * These are the functions used to load ELF style executables and shared
41768 * libraries. There is no binary dependent code anywhere else.
41769 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
41770 {
41771 unsigned int random_variable = 0;
41772
41773 +#ifdef CONFIG_PAX_RANDUSTACK
41774 + if (randomize_va_space)
41775 + return stack_top - current->mm->delta_stack;
41776 +#endif
41777 +
41778 if ((current->flags & PF_RANDOMIZE) &&
41779 !(current->personality & ADDR_NO_RANDOMIZE)) {
41780 random_variable = get_random_int() & STACK_RND_MASK;
41781 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41782 unsigned long load_addr = 0, load_bias = 0;
41783 int load_addr_set = 0;
41784 char * elf_interpreter = NULL;
41785 - unsigned long error;
41786 + unsigned long error = 0;
41787 struct elf_phdr *elf_ppnt, *elf_phdata;
41788 unsigned long elf_bss, elf_brk;
41789 int retval, i;
41790 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41791 unsigned long start_code, end_code, start_data, end_data;
41792 unsigned long reloc_func_desc __maybe_unused = 0;
41793 int executable_stack = EXSTACK_DEFAULT;
41794 - unsigned long def_flags = 0;
41795 struct {
41796 struct elfhdr elf_ex;
41797 struct elfhdr interp_elf_ex;
41798 } *loc;
41799 + unsigned long pax_task_size = TASK_SIZE;
41800
41801 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
41802 if (!loc) {
41803 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41804
41805 /* OK, This is the point of no return */
41806 current->flags &= ~PF_FORKNOEXEC;
41807 - current->mm->def_flags = def_flags;
41808 +
41809 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41810 + current->mm->pax_flags = 0UL;
41811 +#endif
41812 +
41813 +#ifdef CONFIG_PAX_DLRESOLVE
41814 + current->mm->call_dl_resolve = 0UL;
41815 +#endif
41816 +
41817 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
41818 + current->mm->call_syscall = 0UL;
41819 +#endif
41820 +
41821 +#ifdef CONFIG_PAX_ASLR
41822 + current->mm->delta_mmap = 0UL;
41823 + current->mm->delta_stack = 0UL;
41824 +#endif
41825 +
41826 + current->mm->def_flags = 0;
41827 +
41828 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41829 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
41830 + send_sig(SIGKILL, current, 0);
41831 + goto out_free_dentry;
41832 + }
41833 +#endif
41834 +
41835 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
41836 + pax_set_initial_flags(bprm);
41837 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
41838 + if (pax_set_initial_flags_func)
41839 + (pax_set_initial_flags_func)(bprm);
41840 +#endif
41841 +
41842 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
41843 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
41844 + current->mm->context.user_cs_limit = PAGE_SIZE;
41845 + current->mm->def_flags |= VM_PAGEEXEC;
41846 + }
41847 +#endif
41848 +
41849 +#ifdef CONFIG_PAX_SEGMEXEC
41850 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
41851 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
41852 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
41853 + pax_task_size = SEGMEXEC_TASK_SIZE;
41854 + current->mm->def_flags |= VM_NOHUGEPAGE;
41855 + }
41856 +#endif
41857 +
41858 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
41859 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41860 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
41861 + put_cpu();
41862 + }
41863 +#endif
41864
41865 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
41866 may depend on the personality. */
41867 SET_PERSONALITY(loc->elf_ex);
41868 +
41869 +#ifdef CONFIG_PAX_ASLR
41870 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
41871 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
41872 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
41873 + }
41874 +#endif
41875 +
41876 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41877 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41878 + executable_stack = EXSTACK_DISABLE_X;
41879 + current->personality &= ~READ_IMPLIES_EXEC;
41880 + } else
41881 +#endif
41882 +
41883 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
41884 current->personality |= READ_IMPLIES_EXEC;
41885
41886 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41887 #else
41888 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
41889 #endif
41890 +
41891 +#ifdef CONFIG_PAX_RANDMMAP
41892 + /* PaX: randomize base address at the default exe base if requested */
41893 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
41894 +#ifdef CONFIG_SPARC64
41895 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
41896 +#else
41897 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
41898 +#endif
41899 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
41900 + elf_flags |= MAP_FIXED;
41901 + }
41902 +#endif
41903 +
41904 }
41905
41906 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
41907 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41908 * allowed task size. Note that p_filesz must always be
41909 * <= p_memsz so it is only necessary to check p_memsz.
41910 */
41911 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41912 - elf_ppnt->p_memsz > TASK_SIZE ||
41913 - TASK_SIZE - elf_ppnt->p_memsz < k) {
41914 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41915 + elf_ppnt->p_memsz > pax_task_size ||
41916 + pax_task_size - elf_ppnt->p_memsz < k) {
41917 /* set_brk can never work. Avoid overflows. */
41918 send_sig(SIGKILL, current, 0);
41919 retval = -EINVAL;
41920 @@ -870,6 +1328,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41921 start_data += load_bias;
41922 end_data += load_bias;
41923
41924 +#ifdef CONFIG_PAX_RANDMMAP
41925 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
41926 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
41927 +#endif
41928 +
41929 /* Calling set_brk effectively mmaps the pages that we need
41930 * for the bss and break sections. We must do this before
41931 * mapping in the interpreter, to make sure it doesn't wind
41932 @@ -881,9 +1344,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41933 goto out_free_dentry;
41934 }
41935 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
41936 - send_sig(SIGSEGV, current, 0);
41937 - retval = -EFAULT; /* Nobody gets to see this, but.. */
41938 - goto out_free_dentry;
41939 + /*
41940 + * This bss-zeroing can fail if the ELF
41941 + * file specifies odd protections. So
41942 + * we don't check the return value
41943 + */
41944 }
41945
41946 if (elf_interpreter) {
41947 @@ -1098,7 +1563,7 @@ out:
41948 * Decide what to dump of a segment, part, all or none.
41949 */
41950 static unsigned long vma_dump_size(struct vm_area_struct *vma,
41951 - unsigned long mm_flags)
41952 + unsigned long mm_flags, long signr)
41953 {
41954 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
41955
41956 @@ -1132,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
41957 if (vma->vm_file == NULL)
41958 return 0;
41959
41960 - if (FILTER(MAPPED_PRIVATE))
41961 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
41962 goto whole;
41963
41964 /*
41965 @@ -1354,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
41966 {
41967 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
41968 int i = 0;
41969 - do
41970 + do {
41971 i += 2;
41972 - while (auxv[i - 2] != AT_NULL);
41973 + } while (auxv[i - 2] != AT_NULL);
41974 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
41975 }
41976
41977 @@ -1862,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
41978 }
41979
41980 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
41981 - unsigned long mm_flags)
41982 + struct coredump_params *cprm)
41983 {
41984 struct vm_area_struct *vma;
41985 size_t size = 0;
41986
41987 for (vma = first_vma(current, gate_vma); vma != NULL;
41988 vma = next_vma(vma, gate_vma))
41989 - size += vma_dump_size(vma, mm_flags);
41990 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41991 return size;
41992 }
41993
41994 @@ -1963,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41995
41996 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
41997
41998 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
41999 + offset += elf_core_vma_data_size(gate_vma, cprm);
42000 offset += elf_core_extra_data_size();
42001 e_shoff = offset;
42002
42003 @@ -1977,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42004 offset = dataoff;
42005
42006 size += sizeof(*elf);
42007 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42008 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42009 goto end_coredump;
42010
42011 size += sizeof(*phdr4note);
42012 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42013 if (size > cprm->limit
42014 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42015 goto end_coredump;
42016 @@ -1994,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42017 phdr.p_offset = offset;
42018 phdr.p_vaddr = vma->vm_start;
42019 phdr.p_paddr = 0;
42020 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42021 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42022 phdr.p_memsz = vma->vm_end - vma->vm_start;
42023 offset += phdr.p_filesz;
42024 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42025 @@ -2005,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42026 phdr.p_align = ELF_EXEC_PAGESIZE;
42027
42028 size += sizeof(phdr);
42029 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42030 if (size > cprm->limit
42031 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42032 goto end_coredump;
42033 @@ -2029,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42034 unsigned long addr;
42035 unsigned long end;
42036
42037 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42038 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42039
42040 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42041 struct page *page;
42042 @@ -2038,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42043 page = get_dump_page(addr);
42044 if (page) {
42045 void *kaddr = kmap(page);
42046 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42047 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42048 !dump_write(cprm->file, kaddr,
42049 PAGE_SIZE);
42050 @@ -2055,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42051
42052 if (e_phnum == PN_XNUM) {
42053 size += sizeof(*shdr4extnum);
42054 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42055 if (size > cprm->limit
42056 || !dump_write(cprm->file, shdr4extnum,
42057 sizeof(*shdr4extnum)))
42058 @@ -2075,6 +2545,97 @@ out:
42059
42060 #endif /* CONFIG_ELF_CORE */
42061
42062 +#ifdef CONFIG_PAX_MPROTECT
42063 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42064 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42065 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42066 + *
42067 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42068 + * basis because we want to allow the common case and not the special ones.
42069 + */
42070 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42071 +{
42072 + struct elfhdr elf_h;
42073 + struct elf_phdr elf_p;
42074 + unsigned long i;
42075 + unsigned long oldflags;
42076 + bool is_textrel_rw, is_textrel_rx, is_relro;
42077 +
42078 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42079 + return;
42080 +
42081 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42082 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42083 +
42084 +#ifdef CONFIG_PAX_ELFRELOCS
42085 + /* possible TEXTREL */
42086 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42087 + 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);
42088 +#else
42089 + is_textrel_rw = false;
42090 + is_textrel_rx = false;
42091 +#endif
42092 +
42093 + /* possible RELRO */
42094 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42095 +
42096 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42097 + return;
42098 +
42099 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42100 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42101 +
42102 +#ifdef CONFIG_PAX_ETEXECRELOCS
42103 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42104 +#else
42105 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42106 +#endif
42107 +
42108 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42109 + !elf_check_arch(&elf_h) ||
42110 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42111 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42112 + return;
42113 +
42114 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42115 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42116 + return;
42117 + switch (elf_p.p_type) {
42118 + case PT_DYNAMIC:
42119 + if (!is_textrel_rw && !is_textrel_rx)
42120 + continue;
42121 + i = 0UL;
42122 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42123 + elf_dyn dyn;
42124 +
42125 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42126 + return;
42127 + if (dyn.d_tag == DT_NULL)
42128 + return;
42129 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42130 + gr_log_textrel(vma);
42131 + if (is_textrel_rw)
42132 + vma->vm_flags |= VM_MAYWRITE;
42133 + else
42134 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42135 + vma->vm_flags &= ~VM_MAYWRITE;
42136 + return;
42137 + }
42138 + i++;
42139 + }
42140 + return;
42141 +
42142 + case PT_GNU_RELRO:
42143 + if (!is_relro)
42144 + continue;
42145 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42146 + vma->vm_flags &= ~VM_MAYWRITE;
42147 + return;
42148 + }
42149 + }
42150 +}
42151 +#endif
42152 +
42153 static int __init init_elf_binfmt(void)
42154 {
42155 return register_binfmt(&elf_format);
42156 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42157 index 1bffbe0..c8c283e 100644
42158 --- a/fs/binfmt_flat.c
42159 +++ b/fs/binfmt_flat.c
42160 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42161 realdatastart = (unsigned long) -ENOMEM;
42162 printk("Unable to allocate RAM for process data, errno %d\n",
42163 (int)-realdatastart);
42164 + down_write(&current->mm->mmap_sem);
42165 do_munmap(current->mm, textpos, text_len);
42166 + up_write(&current->mm->mmap_sem);
42167 ret = realdatastart;
42168 goto err;
42169 }
42170 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42171 }
42172 if (IS_ERR_VALUE(result)) {
42173 printk("Unable to read data+bss, errno %d\n", (int)-result);
42174 + down_write(&current->mm->mmap_sem);
42175 do_munmap(current->mm, textpos, text_len);
42176 do_munmap(current->mm, realdatastart, len);
42177 + up_write(&current->mm->mmap_sem);
42178 ret = result;
42179 goto err;
42180 }
42181 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42182 }
42183 if (IS_ERR_VALUE(result)) {
42184 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42185 + down_write(&current->mm->mmap_sem);
42186 do_munmap(current->mm, textpos, text_len + data_len + extra +
42187 MAX_SHARED_LIBS * sizeof(unsigned long));
42188 + up_write(&current->mm->mmap_sem);
42189 ret = result;
42190 goto err;
42191 }
42192 diff --git a/fs/bio.c b/fs/bio.c
42193 index b1fe82c..84da0a9 100644
42194 --- a/fs/bio.c
42195 +++ b/fs/bio.c
42196 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42197 const int read = bio_data_dir(bio) == READ;
42198 struct bio_map_data *bmd = bio->bi_private;
42199 int i;
42200 - char *p = bmd->sgvecs[0].iov_base;
42201 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42202
42203 __bio_for_each_segment(bvec, bio, i, 0) {
42204 char *addr = page_address(bvec->bv_page);
42205 diff --git a/fs/block_dev.c b/fs/block_dev.c
42206 index b07f1da..9efcb92 100644
42207 --- a/fs/block_dev.c
42208 +++ b/fs/block_dev.c
42209 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42210 else if (bdev->bd_contains == bdev)
42211 return true; /* is a whole device which isn't held */
42212
42213 - else if (whole->bd_holder == bd_may_claim)
42214 + else if (whole->bd_holder == (void *)bd_may_claim)
42215 return true; /* is a partition of a device that is being partitioned */
42216 else if (whole->bd_holder != NULL)
42217 return false; /* is a partition of a held device */
42218 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42219 index dede441..f2a2507 100644
42220 --- a/fs/btrfs/ctree.c
42221 +++ b/fs/btrfs/ctree.c
42222 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42223 free_extent_buffer(buf);
42224 add_root_to_dirty_list(root);
42225 } else {
42226 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42227 - parent_start = parent->start;
42228 - else
42229 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42230 + if (parent)
42231 + parent_start = parent->start;
42232 + else
42233 + parent_start = 0;
42234 + } else
42235 parent_start = 0;
42236
42237 WARN_ON(trans->transid != btrfs_header_generation(parent));
42238 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42239 index fd1a06d..6e9033d 100644
42240 --- a/fs/btrfs/inode.c
42241 +++ b/fs/btrfs/inode.c
42242 @@ -6895,7 +6895,7 @@ fail:
42243 return -ENOMEM;
42244 }
42245
42246 -static int btrfs_getattr(struct vfsmount *mnt,
42247 +int btrfs_getattr(struct vfsmount *mnt,
42248 struct dentry *dentry, struct kstat *stat)
42249 {
42250 struct inode *inode = dentry->d_inode;
42251 @@ -6909,6 +6909,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42252 return 0;
42253 }
42254
42255 +EXPORT_SYMBOL(btrfs_getattr);
42256 +
42257 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
42258 +{
42259 + return BTRFS_I(inode)->root->anon_dev;
42260 +}
42261 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42262 +
42263 /*
42264 * If a file is moved, it will inherit the cow and compression flags of the new
42265 * directory.
42266 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42267 index c04f02c..f5c9e2e 100644
42268 --- a/fs/btrfs/ioctl.c
42269 +++ b/fs/btrfs/ioctl.c
42270 @@ -2733,9 +2733,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42271 for (i = 0; i < num_types; i++) {
42272 struct btrfs_space_info *tmp;
42273
42274 + /* Don't copy in more than we allocated */
42275 if (!slot_count)
42276 break;
42277
42278 + slot_count--;
42279 +
42280 info = NULL;
42281 rcu_read_lock();
42282 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42283 @@ -2757,15 +2760,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42284 memcpy(dest, &space, sizeof(space));
42285 dest++;
42286 space_args.total_spaces++;
42287 - slot_count--;
42288 }
42289 - if (!slot_count)
42290 - break;
42291 }
42292 up_read(&info->groups_sem);
42293 }
42294
42295 - user_dest = (struct btrfs_ioctl_space_info *)
42296 + user_dest = (struct btrfs_ioctl_space_info __user *)
42297 (arg + sizeof(struct btrfs_ioctl_space_args));
42298
42299 if (copy_to_user(user_dest, dest_orig, alloc_size))
42300 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42301 index cfb5543..1ae7347 100644
42302 --- a/fs/btrfs/relocation.c
42303 +++ b/fs/btrfs/relocation.c
42304 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42305 }
42306 spin_unlock(&rc->reloc_root_tree.lock);
42307
42308 - BUG_ON((struct btrfs_root *)node->data != root);
42309 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
42310
42311 if (!del) {
42312 spin_lock(&rc->reloc_root_tree.lock);
42313 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42314 index 622f469..e8d2d55 100644
42315 --- a/fs/cachefiles/bind.c
42316 +++ b/fs/cachefiles/bind.c
42317 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42318 args);
42319
42320 /* start by checking things over */
42321 - ASSERT(cache->fstop_percent >= 0 &&
42322 - cache->fstop_percent < cache->fcull_percent &&
42323 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
42324 cache->fcull_percent < cache->frun_percent &&
42325 cache->frun_percent < 100);
42326
42327 - ASSERT(cache->bstop_percent >= 0 &&
42328 - cache->bstop_percent < cache->bcull_percent &&
42329 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
42330 cache->bcull_percent < cache->brun_percent &&
42331 cache->brun_percent < 100);
42332
42333 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42334 index 0a1467b..6a53245 100644
42335 --- a/fs/cachefiles/daemon.c
42336 +++ b/fs/cachefiles/daemon.c
42337 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42338 if (n > buflen)
42339 return -EMSGSIZE;
42340
42341 - if (copy_to_user(_buffer, buffer, n) != 0)
42342 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42343 return -EFAULT;
42344
42345 return n;
42346 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42347 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42348 return -EIO;
42349
42350 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
42351 + if (datalen > PAGE_SIZE - 1)
42352 return -EOPNOTSUPP;
42353
42354 /* drag the command string into the kernel so we can parse it */
42355 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42356 if (args[0] != '%' || args[1] != '\0')
42357 return -EINVAL;
42358
42359 - if (fstop < 0 || fstop >= cache->fcull_percent)
42360 + if (fstop >= cache->fcull_percent)
42361 return cachefiles_daemon_range_error(cache, args);
42362
42363 cache->fstop_percent = fstop;
42364 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42365 if (args[0] != '%' || args[1] != '\0')
42366 return -EINVAL;
42367
42368 - if (bstop < 0 || bstop >= cache->bcull_percent)
42369 + if (bstop >= cache->bcull_percent)
42370 return cachefiles_daemon_range_error(cache, args);
42371
42372 cache->bstop_percent = bstop;
42373 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42374 index bd6bc1b..b627b53 100644
42375 --- a/fs/cachefiles/internal.h
42376 +++ b/fs/cachefiles/internal.h
42377 @@ -57,7 +57,7 @@ struct cachefiles_cache {
42378 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42379 struct rb_root active_nodes; /* active nodes (can't be culled) */
42380 rwlock_t active_lock; /* lock for active_nodes */
42381 - atomic_t gravecounter; /* graveyard uniquifier */
42382 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42383 unsigned frun_percent; /* when to stop culling (% files) */
42384 unsigned fcull_percent; /* when to start culling (% files) */
42385 unsigned fstop_percent; /* when to stop allocating (% files) */
42386 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42387 * proc.c
42388 */
42389 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42390 -extern atomic_t cachefiles_lookup_histogram[HZ];
42391 -extern atomic_t cachefiles_mkdir_histogram[HZ];
42392 -extern atomic_t cachefiles_create_histogram[HZ];
42393 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42394 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42395 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42396
42397 extern int __init cachefiles_proc_init(void);
42398 extern void cachefiles_proc_cleanup(void);
42399 static inline
42400 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42401 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42402 {
42403 unsigned long jif = jiffies - start_jif;
42404 if (jif >= HZ)
42405 jif = HZ - 1;
42406 - atomic_inc(&histogram[jif]);
42407 + atomic_inc_unchecked(&histogram[jif]);
42408 }
42409
42410 #else
42411 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42412 index a0358c2..d6137f2 100644
42413 --- a/fs/cachefiles/namei.c
42414 +++ b/fs/cachefiles/namei.c
42415 @@ -318,7 +318,7 @@ try_again:
42416 /* first step is to make up a grave dentry in the graveyard */
42417 sprintf(nbuffer, "%08x%08x",
42418 (uint32_t) get_seconds(),
42419 - (uint32_t) atomic_inc_return(&cache->gravecounter));
42420 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42421
42422 /* do the multiway lock magic */
42423 trap = lock_rename(cache->graveyard, dir);
42424 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42425 index eccd339..4c1d995 100644
42426 --- a/fs/cachefiles/proc.c
42427 +++ b/fs/cachefiles/proc.c
42428 @@ -14,9 +14,9 @@
42429 #include <linux/seq_file.h>
42430 #include "internal.h"
42431
42432 -atomic_t cachefiles_lookup_histogram[HZ];
42433 -atomic_t cachefiles_mkdir_histogram[HZ];
42434 -atomic_t cachefiles_create_histogram[HZ];
42435 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42436 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42437 +atomic_unchecked_t cachefiles_create_histogram[HZ];
42438
42439 /*
42440 * display the latency histogram
42441 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42442 return 0;
42443 default:
42444 index = (unsigned long) v - 3;
42445 - x = atomic_read(&cachefiles_lookup_histogram[index]);
42446 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
42447 - z = atomic_read(&cachefiles_create_histogram[index]);
42448 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42449 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42450 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42451 if (x == 0 && y == 0 && z == 0)
42452 return 0;
42453
42454 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42455 index 0e3c092..818480e 100644
42456 --- a/fs/cachefiles/rdwr.c
42457 +++ b/fs/cachefiles/rdwr.c
42458 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42459 old_fs = get_fs();
42460 set_fs(KERNEL_DS);
42461 ret = file->f_op->write(
42462 - file, (const void __user *) data, len, &pos);
42463 + file, (const void __force_user *) data, len, &pos);
42464 set_fs(old_fs);
42465 kunmap(page);
42466 if (ret != len)
42467 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42468 index 9895400..fa40a7d 100644
42469 --- a/fs/ceph/dir.c
42470 +++ b/fs/ceph/dir.c
42471 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42472 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42473 struct ceph_mds_client *mdsc = fsc->mdsc;
42474 unsigned frag = fpos_frag(filp->f_pos);
42475 - int off = fpos_off(filp->f_pos);
42476 + unsigned int off = fpos_off(filp->f_pos);
42477 int err;
42478 u32 ftype;
42479 struct ceph_mds_reply_info_parsed *rinfo;
42480 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42481 index 84e8c07..6170d31 100644
42482 --- a/fs/cifs/cifs_debug.c
42483 +++ b/fs/cifs/cifs_debug.c
42484 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42485
42486 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42487 #ifdef CONFIG_CIFS_STATS2
42488 - atomic_set(&totBufAllocCount, 0);
42489 - atomic_set(&totSmBufAllocCount, 0);
42490 + atomic_set_unchecked(&totBufAllocCount, 0);
42491 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42492 #endif /* CONFIG_CIFS_STATS2 */
42493 spin_lock(&cifs_tcp_ses_lock);
42494 list_for_each(tmp1, &cifs_tcp_ses_list) {
42495 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42496 tcon = list_entry(tmp3,
42497 struct cifs_tcon,
42498 tcon_list);
42499 - atomic_set(&tcon->num_smbs_sent, 0);
42500 - atomic_set(&tcon->num_writes, 0);
42501 - atomic_set(&tcon->num_reads, 0);
42502 - atomic_set(&tcon->num_oplock_brks, 0);
42503 - atomic_set(&tcon->num_opens, 0);
42504 - atomic_set(&tcon->num_posixopens, 0);
42505 - atomic_set(&tcon->num_posixmkdirs, 0);
42506 - atomic_set(&tcon->num_closes, 0);
42507 - atomic_set(&tcon->num_deletes, 0);
42508 - atomic_set(&tcon->num_mkdirs, 0);
42509 - atomic_set(&tcon->num_rmdirs, 0);
42510 - atomic_set(&tcon->num_renames, 0);
42511 - atomic_set(&tcon->num_t2renames, 0);
42512 - atomic_set(&tcon->num_ffirst, 0);
42513 - atomic_set(&tcon->num_fnext, 0);
42514 - atomic_set(&tcon->num_fclose, 0);
42515 - atomic_set(&tcon->num_hardlinks, 0);
42516 - atomic_set(&tcon->num_symlinks, 0);
42517 - atomic_set(&tcon->num_locks, 0);
42518 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42519 + atomic_set_unchecked(&tcon->num_writes, 0);
42520 + atomic_set_unchecked(&tcon->num_reads, 0);
42521 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42522 + atomic_set_unchecked(&tcon->num_opens, 0);
42523 + atomic_set_unchecked(&tcon->num_posixopens, 0);
42524 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42525 + atomic_set_unchecked(&tcon->num_closes, 0);
42526 + atomic_set_unchecked(&tcon->num_deletes, 0);
42527 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
42528 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
42529 + atomic_set_unchecked(&tcon->num_renames, 0);
42530 + atomic_set_unchecked(&tcon->num_t2renames, 0);
42531 + atomic_set_unchecked(&tcon->num_ffirst, 0);
42532 + atomic_set_unchecked(&tcon->num_fnext, 0);
42533 + atomic_set_unchecked(&tcon->num_fclose, 0);
42534 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
42535 + atomic_set_unchecked(&tcon->num_symlinks, 0);
42536 + atomic_set_unchecked(&tcon->num_locks, 0);
42537 }
42538 }
42539 }
42540 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42541 smBufAllocCount.counter, cifs_min_small);
42542 #ifdef CONFIG_CIFS_STATS2
42543 seq_printf(m, "Total Large %d Small %d Allocations\n",
42544 - atomic_read(&totBufAllocCount),
42545 - atomic_read(&totSmBufAllocCount));
42546 + atomic_read_unchecked(&totBufAllocCount),
42547 + atomic_read_unchecked(&totSmBufAllocCount));
42548 #endif /* CONFIG_CIFS_STATS2 */
42549
42550 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42551 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42552 if (tcon->need_reconnect)
42553 seq_puts(m, "\tDISCONNECTED ");
42554 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42555 - atomic_read(&tcon->num_smbs_sent),
42556 - atomic_read(&tcon->num_oplock_brks));
42557 + atomic_read_unchecked(&tcon->num_smbs_sent),
42558 + atomic_read_unchecked(&tcon->num_oplock_brks));
42559 seq_printf(m, "\nReads: %d Bytes: %lld",
42560 - atomic_read(&tcon->num_reads),
42561 + atomic_read_unchecked(&tcon->num_reads),
42562 (long long)(tcon->bytes_read));
42563 seq_printf(m, "\nWrites: %d Bytes: %lld",
42564 - atomic_read(&tcon->num_writes),
42565 + atomic_read_unchecked(&tcon->num_writes),
42566 (long long)(tcon->bytes_written));
42567 seq_printf(m, "\nFlushes: %d",
42568 - atomic_read(&tcon->num_flushes));
42569 + atomic_read_unchecked(&tcon->num_flushes));
42570 seq_printf(m, "\nLocks: %d HardLinks: %d "
42571 "Symlinks: %d",
42572 - atomic_read(&tcon->num_locks),
42573 - atomic_read(&tcon->num_hardlinks),
42574 - atomic_read(&tcon->num_symlinks));
42575 + atomic_read_unchecked(&tcon->num_locks),
42576 + atomic_read_unchecked(&tcon->num_hardlinks),
42577 + atomic_read_unchecked(&tcon->num_symlinks));
42578 seq_printf(m, "\nOpens: %d Closes: %d "
42579 "Deletes: %d",
42580 - atomic_read(&tcon->num_opens),
42581 - atomic_read(&tcon->num_closes),
42582 - atomic_read(&tcon->num_deletes));
42583 + atomic_read_unchecked(&tcon->num_opens),
42584 + atomic_read_unchecked(&tcon->num_closes),
42585 + atomic_read_unchecked(&tcon->num_deletes));
42586 seq_printf(m, "\nPosix Opens: %d "
42587 "Posix Mkdirs: %d",
42588 - atomic_read(&tcon->num_posixopens),
42589 - atomic_read(&tcon->num_posixmkdirs));
42590 + atomic_read_unchecked(&tcon->num_posixopens),
42591 + atomic_read_unchecked(&tcon->num_posixmkdirs));
42592 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42593 - atomic_read(&tcon->num_mkdirs),
42594 - atomic_read(&tcon->num_rmdirs));
42595 + atomic_read_unchecked(&tcon->num_mkdirs),
42596 + atomic_read_unchecked(&tcon->num_rmdirs));
42597 seq_printf(m, "\nRenames: %d T2 Renames %d",
42598 - atomic_read(&tcon->num_renames),
42599 - atomic_read(&tcon->num_t2renames));
42600 + atomic_read_unchecked(&tcon->num_renames),
42601 + atomic_read_unchecked(&tcon->num_t2renames));
42602 seq_printf(m, "\nFindFirst: %d FNext %d "
42603 "FClose %d",
42604 - atomic_read(&tcon->num_ffirst),
42605 - atomic_read(&tcon->num_fnext),
42606 - atomic_read(&tcon->num_fclose));
42607 + atomic_read_unchecked(&tcon->num_ffirst),
42608 + atomic_read_unchecked(&tcon->num_fnext),
42609 + atomic_read_unchecked(&tcon->num_fclose));
42610 }
42611 }
42612 }
42613 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
42614 index 8f1fe32..38f9e27 100644
42615 --- a/fs/cifs/cifsfs.c
42616 +++ b/fs/cifs/cifsfs.c
42617 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
42618 cifs_req_cachep = kmem_cache_create("cifs_request",
42619 CIFSMaxBufSize +
42620 MAX_CIFS_HDR_SIZE, 0,
42621 - SLAB_HWCACHE_ALIGN, NULL);
42622 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
42623 if (cifs_req_cachep == NULL)
42624 return -ENOMEM;
42625
42626 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
42627 efficient to alloc 1 per page off the slab compared to 17K (5page)
42628 alloc of large cifs buffers even when page debugging is on */
42629 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
42630 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
42631 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
42632 NULL);
42633 if (cifs_sm_req_cachep == NULL) {
42634 mempool_destroy(cifs_req_poolp);
42635 @@ -1101,8 +1101,8 @@ init_cifs(void)
42636 atomic_set(&bufAllocCount, 0);
42637 atomic_set(&smBufAllocCount, 0);
42638 #ifdef CONFIG_CIFS_STATS2
42639 - atomic_set(&totBufAllocCount, 0);
42640 - atomic_set(&totSmBufAllocCount, 0);
42641 + atomic_set_unchecked(&totBufAllocCount, 0);
42642 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42643 #endif /* CONFIG_CIFS_STATS2 */
42644
42645 atomic_set(&midCount, 0);
42646 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
42647 index 8238aa1..0347196 100644
42648 --- a/fs/cifs/cifsglob.h
42649 +++ b/fs/cifs/cifsglob.h
42650 @@ -392,28 +392,28 @@ struct cifs_tcon {
42651 __u16 Flags; /* optional support bits */
42652 enum statusEnum tidStatus;
42653 #ifdef CONFIG_CIFS_STATS
42654 - atomic_t num_smbs_sent;
42655 - atomic_t num_writes;
42656 - atomic_t num_reads;
42657 - atomic_t num_flushes;
42658 - atomic_t num_oplock_brks;
42659 - atomic_t num_opens;
42660 - atomic_t num_closes;
42661 - atomic_t num_deletes;
42662 - atomic_t num_mkdirs;
42663 - atomic_t num_posixopens;
42664 - atomic_t num_posixmkdirs;
42665 - atomic_t num_rmdirs;
42666 - atomic_t num_renames;
42667 - atomic_t num_t2renames;
42668 - atomic_t num_ffirst;
42669 - atomic_t num_fnext;
42670 - atomic_t num_fclose;
42671 - atomic_t num_hardlinks;
42672 - atomic_t num_symlinks;
42673 - atomic_t num_locks;
42674 - atomic_t num_acl_get;
42675 - atomic_t num_acl_set;
42676 + atomic_unchecked_t num_smbs_sent;
42677 + atomic_unchecked_t num_writes;
42678 + atomic_unchecked_t num_reads;
42679 + atomic_unchecked_t num_flushes;
42680 + atomic_unchecked_t num_oplock_brks;
42681 + atomic_unchecked_t num_opens;
42682 + atomic_unchecked_t num_closes;
42683 + atomic_unchecked_t num_deletes;
42684 + atomic_unchecked_t num_mkdirs;
42685 + atomic_unchecked_t num_posixopens;
42686 + atomic_unchecked_t num_posixmkdirs;
42687 + atomic_unchecked_t num_rmdirs;
42688 + atomic_unchecked_t num_renames;
42689 + atomic_unchecked_t num_t2renames;
42690 + atomic_unchecked_t num_ffirst;
42691 + atomic_unchecked_t num_fnext;
42692 + atomic_unchecked_t num_fclose;
42693 + atomic_unchecked_t num_hardlinks;
42694 + atomic_unchecked_t num_symlinks;
42695 + atomic_unchecked_t num_locks;
42696 + atomic_unchecked_t num_acl_get;
42697 + atomic_unchecked_t num_acl_set;
42698 #ifdef CONFIG_CIFS_STATS2
42699 unsigned long long time_writes;
42700 unsigned long long time_reads;
42701 @@ -628,7 +628,7 @@ convert_delimiter(char *path, char delim)
42702 }
42703
42704 #ifdef CONFIG_CIFS_STATS
42705 -#define cifs_stats_inc atomic_inc
42706 +#define cifs_stats_inc atomic_inc_unchecked
42707
42708 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
42709 unsigned int bytes)
42710 @@ -985,8 +985,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
42711 /* Various Debug counters */
42712 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
42713 #ifdef CONFIG_CIFS_STATS2
42714 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
42715 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
42716 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
42717 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
42718 #endif
42719 GLOBAL_EXTERN atomic_t smBufAllocCount;
42720 GLOBAL_EXTERN atomic_t midCount;
42721 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
42722 index 6b0e064..94e6c3c 100644
42723 --- a/fs/cifs/link.c
42724 +++ b/fs/cifs/link.c
42725 @@ -600,7 +600,7 @@ symlink_exit:
42726
42727 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
42728 {
42729 - char *p = nd_get_link(nd);
42730 + const char *p = nd_get_link(nd);
42731 if (!IS_ERR(p))
42732 kfree(p);
42733 }
42734 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
42735 index 703ef5c..2a44ed5 100644
42736 --- a/fs/cifs/misc.c
42737 +++ b/fs/cifs/misc.c
42738 @@ -156,7 +156,7 @@ cifs_buf_get(void)
42739 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
42740 atomic_inc(&bufAllocCount);
42741 #ifdef CONFIG_CIFS_STATS2
42742 - atomic_inc(&totBufAllocCount);
42743 + atomic_inc_unchecked(&totBufAllocCount);
42744 #endif /* CONFIG_CIFS_STATS2 */
42745 }
42746
42747 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
42748 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
42749 atomic_inc(&smBufAllocCount);
42750 #ifdef CONFIG_CIFS_STATS2
42751 - atomic_inc(&totSmBufAllocCount);
42752 + atomic_inc_unchecked(&totSmBufAllocCount);
42753 #endif /* CONFIG_CIFS_STATS2 */
42754
42755 }
42756 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
42757 index 6901578..d402eb5 100644
42758 --- a/fs/coda/cache.c
42759 +++ b/fs/coda/cache.c
42760 @@ -24,7 +24,7 @@
42761 #include "coda_linux.h"
42762 #include "coda_cache.h"
42763
42764 -static atomic_t permission_epoch = ATOMIC_INIT(0);
42765 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
42766
42767 /* replace or extend an acl cache hit */
42768 void coda_cache_enter(struct inode *inode, int mask)
42769 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
42770 struct coda_inode_info *cii = ITOC(inode);
42771
42772 spin_lock(&cii->c_lock);
42773 - cii->c_cached_epoch = atomic_read(&permission_epoch);
42774 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
42775 if (cii->c_uid != current_fsuid()) {
42776 cii->c_uid = current_fsuid();
42777 cii->c_cached_perm = mask;
42778 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
42779 {
42780 struct coda_inode_info *cii = ITOC(inode);
42781 spin_lock(&cii->c_lock);
42782 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
42783 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
42784 spin_unlock(&cii->c_lock);
42785 }
42786
42787 /* remove all acl caches */
42788 void coda_cache_clear_all(struct super_block *sb)
42789 {
42790 - atomic_inc(&permission_epoch);
42791 + atomic_inc_unchecked(&permission_epoch);
42792 }
42793
42794
42795 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
42796 spin_lock(&cii->c_lock);
42797 hit = (mask & cii->c_cached_perm) == mask &&
42798 cii->c_uid == current_fsuid() &&
42799 - cii->c_cached_epoch == atomic_read(&permission_epoch);
42800 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
42801 spin_unlock(&cii->c_lock);
42802
42803 return hit;
42804 diff --git a/fs/compat.c b/fs/compat.c
42805 index c987875..08771ca 100644
42806 --- a/fs/compat.c
42807 +++ b/fs/compat.c
42808 @@ -132,8 +132,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
42809 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
42810 {
42811 compat_ino_t ino = stat->ino;
42812 - typeof(ubuf->st_uid) uid = 0;
42813 - typeof(ubuf->st_gid) gid = 0;
42814 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
42815 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
42816 int err;
42817
42818 SET_UID(uid, stat->uid);
42819 @@ -504,7 +504,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
42820
42821 set_fs(KERNEL_DS);
42822 /* The __user pointer cast is valid because of the set_fs() */
42823 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
42824 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
42825 set_fs(oldfs);
42826 /* truncating is ok because it's a user address */
42827 if (!ret)
42828 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
42829 goto out;
42830
42831 ret = -EINVAL;
42832 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
42833 + if (nr_segs > UIO_MAXIOV)
42834 goto out;
42835 if (nr_segs > fast_segs) {
42836 ret = -ENOMEM;
42837 @@ -845,6 +845,7 @@ struct compat_old_linux_dirent {
42838
42839 struct compat_readdir_callback {
42840 struct compat_old_linux_dirent __user *dirent;
42841 + struct file * file;
42842 int result;
42843 };
42844
42845 @@ -862,6 +863,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
42846 buf->result = -EOVERFLOW;
42847 return -EOVERFLOW;
42848 }
42849 +
42850 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42851 + return 0;
42852 +
42853 buf->result++;
42854 dirent = buf->dirent;
42855 if (!access_ok(VERIFY_WRITE, dirent,
42856 @@ -894,6 +899,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
42857
42858 buf.result = 0;
42859 buf.dirent = dirent;
42860 + buf.file = file;
42861
42862 error = vfs_readdir(file, compat_fillonedir, &buf);
42863 if (buf.result)
42864 @@ -914,6 +920,7 @@ struct compat_linux_dirent {
42865 struct compat_getdents_callback {
42866 struct compat_linux_dirent __user *current_dir;
42867 struct compat_linux_dirent __user *previous;
42868 + struct file * file;
42869 int count;
42870 int error;
42871 };
42872 @@ -935,6 +942,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
42873 buf->error = -EOVERFLOW;
42874 return -EOVERFLOW;
42875 }
42876 +
42877 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42878 + return 0;
42879 +
42880 dirent = buf->previous;
42881 if (dirent) {
42882 if (__put_user(offset, &dirent->d_off))
42883 @@ -982,6 +993,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
42884 buf.previous = NULL;
42885 buf.count = count;
42886 buf.error = 0;
42887 + buf.file = file;
42888
42889 error = vfs_readdir(file, compat_filldir, &buf);
42890 if (error >= 0)
42891 @@ -1003,6 +1015,7 @@ out:
42892 struct compat_getdents_callback64 {
42893 struct linux_dirent64 __user *current_dir;
42894 struct linux_dirent64 __user *previous;
42895 + struct file * file;
42896 int count;
42897 int error;
42898 };
42899 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
42900 buf->error = -EINVAL; /* only used if we fail.. */
42901 if (reclen > buf->count)
42902 return -EINVAL;
42903 +
42904 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42905 + return 0;
42906 +
42907 dirent = buf->previous;
42908
42909 if (dirent) {
42910 @@ -1070,13 +1087,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
42911 buf.previous = NULL;
42912 buf.count = count;
42913 buf.error = 0;
42914 + buf.file = file;
42915
42916 error = vfs_readdir(file, compat_filldir64, &buf);
42917 if (error >= 0)
42918 error = buf.error;
42919 lastdirent = buf.previous;
42920 if (lastdirent) {
42921 - typeof(lastdirent->d_off) d_off = file->f_pos;
42922 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
42923 if (__put_user_unaligned(d_off, &lastdirent->d_off))
42924 error = -EFAULT;
42925 else
42926 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
42927 index 112e45a..b59845b 100644
42928 --- a/fs/compat_binfmt_elf.c
42929 +++ b/fs/compat_binfmt_elf.c
42930 @@ -30,11 +30,13 @@
42931 #undef elf_phdr
42932 #undef elf_shdr
42933 #undef elf_note
42934 +#undef elf_dyn
42935 #undef elf_addr_t
42936 #define elfhdr elf32_hdr
42937 #define elf_phdr elf32_phdr
42938 #define elf_shdr elf32_shdr
42939 #define elf_note elf32_note
42940 +#define elf_dyn Elf32_Dyn
42941 #define elf_addr_t Elf32_Addr
42942
42943 /*
42944 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
42945 index 51352de..93292ff 100644
42946 --- a/fs/compat_ioctl.c
42947 +++ b/fs/compat_ioctl.c
42948 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
42949
42950 err = get_user(palp, &up->palette);
42951 err |= get_user(length, &up->length);
42952 + if (err)
42953 + return -EFAULT;
42954
42955 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
42956 err = put_user(compat_ptr(palp), &up_native->palette);
42957 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
42958 return -EFAULT;
42959 if (__get_user(udata, &ss32->iomem_base))
42960 return -EFAULT;
42961 - ss.iomem_base = compat_ptr(udata);
42962 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
42963 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
42964 __get_user(ss.port_high, &ss32->port_high))
42965 return -EFAULT;
42966 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
42967 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
42968 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
42969 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
42970 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42971 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42972 return -EFAULT;
42973
42974 return ioctl_preallocate(file, p);
42975 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
42976 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
42977 {
42978 unsigned int a, b;
42979 - a = *(unsigned int *)p;
42980 - b = *(unsigned int *)q;
42981 + a = *(const unsigned int *)p;
42982 + b = *(const unsigned int *)q;
42983 if (a > b)
42984 return 1;
42985 if (a < b)
42986 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
42987 index 9a37a9b..35792b6 100644
42988 --- a/fs/configfs/dir.c
42989 +++ b/fs/configfs/dir.c
42990 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
42991 }
42992 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
42993 struct configfs_dirent *next;
42994 - const char * name;
42995 + const unsigned char * name;
42996 + char d_name[sizeof(next->s_dentry->d_iname)];
42997 int len;
42998 struct inode *inode = NULL;
42999
43000 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43001 continue;
43002
43003 name = configfs_get_name(next);
43004 - len = strlen(name);
43005 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43006 + len = next->s_dentry->d_name.len;
43007 + memcpy(d_name, name, len);
43008 + name = d_name;
43009 + } else
43010 + len = strlen(name);
43011
43012 /*
43013 * We'll have a dentry and an inode for
43014 diff --git a/fs/dcache.c b/fs/dcache.c
43015 index f7908ae..920a680 100644
43016 --- a/fs/dcache.c
43017 +++ b/fs/dcache.c
43018 @@ -3042,7 +3042,7 @@ void __init vfs_caches_init(unsigned long mempages)
43019 mempages -= reserve;
43020
43021 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43022 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43023 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43024
43025 dcache_init();
43026 inode_init();
43027 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43028 index f3a257d..715ac0f 100644
43029 --- a/fs/debugfs/inode.c
43030 +++ b/fs/debugfs/inode.c
43031 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43032 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43033 {
43034 return debugfs_create_file(name,
43035 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43036 + S_IFDIR | S_IRWXU,
43037 +#else
43038 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43039 +#endif
43040 parent, NULL, NULL);
43041 }
43042 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43043 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43044 index af11098..81e3bbe 100644
43045 --- a/fs/ecryptfs/inode.c
43046 +++ b/fs/ecryptfs/inode.c
43047 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43048 old_fs = get_fs();
43049 set_fs(get_ds());
43050 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43051 - (char __user *)lower_buf,
43052 + (char __force_user *)lower_buf,
43053 lower_bufsiz);
43054 set_fs(old_fs);
43055 if (rc < 0)
43056 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43057 }
43058 old_fs = get_fs();
43059 set_fs(get_ds());
43060 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43061 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43062 set_fs(old_fs);
43063 if (rc < 0) {
43064 kfree(buf);
43065 @@ -752,7 +752,7 @@ out:
43066 static void
43067 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43068 {
43069 - char *buf = nd_get_link(nd);
43070 + const char *buf = nd_get_link(nd);
43071 if (!IS_ERR(buf)) {
43072 /* Free the char* */
43073 kfree(buf);
43074 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43075 index 0dc5a3d..d3cdeea 100644
43076 --- a/fs/ecryptfs/miscdev.c
43077 +++ b/fs/ecryptfs/miscdev.c
43078 @@ -328,7 +328,7 @@ check_list:
43079 goto out_unlock_msg_ctx;
43080 i = 5;
43081 if (msg_ctx->msg) {
43082 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43083 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43084 goto out_unlock_msg_ctx;
43085 i += packet_length_size;
43086 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43087 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43088 index 608c1c3..7d040a8 100644
43089 --- a/fs/ecryptfs/read_write.c
43090 +++ b/fs/ecryptfs/read_write.c
43091 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43092 return -EIO;
43093 fs_save = get_fs();
43094 set_fs(get_ds());
43095 - rc = vfs_write(lower_file, data, size, &offset);
43096 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43097 set_fs(fs_save);
43098 mark_inode_dirty_sync(ecryptfs_inode);
43099 return rc;
43100 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43101 return -EIO;
43102 fs_save = get_fs();
43103 set_fs(get_ds());
43104 - rc = vfs_read(lower_file, data, size, &offset);
43105 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43106 set_fs(fs_save);
43107 return rc;
43108 }
43109 diff --git a/fs/exec.c b/fs/exec.c
43110 index 3625464..cdeecdb 100644
43111 --- a/fs/exec.c
43112 +++ b/fs/exec.c
43113 @@ -55,12 +55,28 @@
43114 #include <linux/pipe_fs_i.h>
43115 #include <linux/oom.h>
43116 #include <linux/compat.h>
43117 +#include <linux/random.h>
43118 +#include <linux/seq_file.h>
43119 +
43120 +#ifdef CONFIG_PAX_REFCOUNT
43121 +#include <linux/kallsyms.h>
43122 +#include <linux/kdebug.h>
43123 +#endif
43124
43125 #include <asm/uaccess.h>
43126 #include <asm/mmu_context.h>
43127 #include <asm/tlb.h>
43128 #include "internal.h"
43129
43130 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43131 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43132 +#endif
43133 +
43134 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43135 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43136 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43137 +#endif
43138 +
43139 int core_uses_pid;
43140 char core_pattern[CORENAME_MAX_SIZE] = "core";
43141 unsigned int core_pipe_limit;
43142 @@ -70,7 +86,7 @@ struct core_name {
43143 char *corename;
43144 int used, size;
43145 };
43146 -static atomic_t call_count = ATOMIC_INIT(1);
43147 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43148
43149 /* The maximal length of core_pattern is also specified in sysctl.c */
43150
43151 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43152 int write)
43153 {
43154 struct page *page;
43155 - int ret;
43156
43157 -#ifdef CONFIG_STACK_GROWSUP
43158 - if (write) {
43159 - ret = expand_downwards(bprm->vma, pos);
43160 - if (ret < 0)
43161 - return NULL;
43162 - }
43163 -#endif
43164 - ret = get_user_pages(current, bprm->mm, pos,
43165 - 1, write, 1, &page, NULL);
43166 - if (ret <= 0)
43167 + if (0 > expand_downwards(bprm->vma, pos))
43168 + return NULL;
43169 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43170 return NULL;
43171
43172 if (write) {
43173 @@ -215,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43174 if (size <= ARG_MAX)
43175 return page;
43176
43177 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43178 + // only allow 512KB for argv+env on suid/sgid binaries
43179 + // to prevent easy ASLR exhaustion
43180 + if (((bprm->cred->euid != current_euid()) ||
43181 + (bprm->cred->egid != current_egid())) &&
43182 + (size > (512 * 1024))) {
43183 + put_page(page);
43184 + return NULL;
43185 + }
43186 +#endif
43187 +
43188 /*
43189 * Limit to 1/4-th the stack size for the argv+env strings.
43190 * This ensures that:
43191 @@ -274,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43192 vma->vm_end = STACK_TOP_MAX;
43193 vma->vm_start = vma->vm_end - PAGE_SIZE;
43194 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43195 +
43196 +#ifdef CONFIG_PAX_SEGMEXEC
43197 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43198 +#endif
43199 +
43200 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43201 INIT_LIST_HEAD(&vma->anon_vma_chain);
43202
43203 @@ -288,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43204 mm->stack_vm = mm->total_vm = 1;
43205 up_write(&mm->mmap_sem);
43206 bprm->p = vma->vm_end - sizeof(void *);
43207 +
43208 +#ifdef CONFIG_PAX_RANDUSTACK
43209 + if (randomize_va_space)
43210 + bprm->p ^= random32() & ~PAGE_MASK;
43211 +#endif
43212 +
43213 return 0;
43214 err:
43215 up_write(&mm->mmap_sem);
43216 @@ -396,19 +426,7 @@ err:
43217 return err;
43218 }
43219
43220 -struct user_arg_ptr {
43221 -#ifdef CONFIG_COMPAT
43222 - bool is_compat;
43223 -#endif
43224 - union {
43225 - const char __user *const __user *native;
43226 -#ifdef CONFIG_COMPAT
43227 - compat_uptr_t __user *compat;
43228 -#endif
43229 - } ptr;
43230 -};
43231 -
43232 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43233 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43234 {
43235 const char __user *native;
43236
43237 @@ -417,14 +435,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43238 compat_uptr_t compat;
43239
43240 if (get_user(compat, argv.ptr.compat + nr))
43241 - return ERR_PTR(-EFAULT);
43242 + return (const char __force_user *)ERR_PTR(-EFAULT);
43243
43244 return compat_ptr(compat);
43245 }
43246 #endif
43247
43248 if (get_user(native, argv.ptr.native + nr))
43249 - return ERR_PTR(-EFAULT);
43250 + return (const char __force_user *)ERR_PTR(-EFAULT);
43251
43252 return native;
43253 }
43254 @@ -443,7 +461,7 @@ static int count(struct user_arg_ptr argv, int max)
43255 if (!p)
43256 break;
43257
43258 - if (IS_ERR(p))
43259 + if (IS_ERR((const char __force_kernel *)p))
43260 return -EFAULT;
43261
43262 if (i++ >= max)
43263 @@ -477,7 +495,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43264
43265 ret = -EFAULT;
43266 str = get_user_arg_ptr(argv, argc);
43267 - if (IS_ERR(str))
43268 + if (IS_ERR((const char __force_kernel *)str))
43269 goto out;
43270
43271 len = strnlen_user(str, MAX_ARG_STRLEN);
43272 @@ -559,7 +577,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43273 int r;
43274 mm_segment_t oldfs = get_fs();
43275 struct user_arg_ptr argv = {
43276 - .ptr.native = (const char __user *const __user *)__argv,
43277 + .ptr.native = (const char __force_user *const __force_user *)__argv,
43278 };
43279
43280 set_fs(KERNEL_DS);
43281 @@ -594,7 +612,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43282 unsigned long new_end = old_end - shift;
43283 struct mmu_gather tlb;
43284
43285 - BUG_ON(new_start > new_end);
43286 + if (new_start >= new_end || new_start < mmap_min_addr)
43287 + return -ENOMEM;
43288
43289 /*
43290 * ensure there are no vmas between where we want to go
43291 @@ -603,6 +622,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43292 if (vma != find_vma(mm, new_start))
43293 return -EFAULT;
43294
43295 +#ifdef CONFIG_PAX_SEGMEXEC
43296 + BUG_ON(pax_find_mirror_vma(vma));
43297 +#endif
43298 +
43299 /*
43300 * cover the whole range: [new_start, old_end)
43301 */
43302 @@ -683,10 +706,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43303 stack_top = arch_align_stack(stack_top);
43304 stack_top = PAGE_ALIGN(stack_top);
43305
43306 - if (unlikely(stack_top < mmap_min_addr) ||
43307 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43308 - return -ENOMEM;
43309 -
43310 stack_shift = vma->vm_end - stack_top;
43311
43312 bprm->p -= stack_shift;
43313 @@ -698,8 +717,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43314 bprm->exec -= stack_shift;
43315
43316 down_write(&mm->mmap_sem);
43317 +
43318 + /* Move stack pages down in memory. */
43319 + if (stack_shift) {
43320 + ret = shift_arg_pages(vma, stack_shift);
43321 + if (ret)
43322 + goto out_unlock;
43323 + }
43324 +
43325 vm_flags = VM_STACK_FLAGS;
43326
43327 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43328 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43329 + vm_flags &= ~VM_EXEC;
43330 +
43331 +#ifdef CONFIG_PAX_MPROTECT
43332 + if (mm->pax_flags & MF_PAX_MPROTECT)
43333 + vm_flags &= ~VM_MAYEXEC;
43334 +#endif
43335 +
43336 + }
43337 +#endif
43338 +
43339 /*
43340 * Adjust stack execute permissions; explicitly enable for
43341 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43342 @@ -718,13 +757,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43343 goto out_unlock;
43344 BUG_ON(prev != vma);
43345
43346 - /* Move stack pages down in memory. */
43347 - if (stack_shift) {
43348 - ret = shift_arg_pages(vma, stack_shift);
43349 - if (ret)
43350 - goto out_unlock;
43351 - }
43352 -
43353 /* mprotect_fixup is overkill to remove the temporary stack flags */
43354 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43355
43356 @@ -805,7 +837,7 @@ int kernel_read(struct file *file, loff_t offset,
43357 old_fs = get_fs();
43358 set_fs(get_ds());
43359 /* The cast to a user pointer is valid due to the set_fs() */
43360 - result = vfs_read(file, (void __user *)addr, count, &pos);
43361 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
43362 set_fs(old_fs);
43363 return result;
43364 }
43365 @@ -1067,6 +1099,21 @@ void set_task_comm(struct task_struct *tsk, char *buf)
43366 perf_event_comm(tsk);
43367 }
43368
43369 +static void filename_to_taskname(char *tcomm, const char *fn, unsigned int len)
43370 +{
43371 + int i, ch;
43372 +
43373 + /* Copies the binary name from after last slash */
43374 + for (i = 0; (ch = *(fn++)) != '\0';) {
43375 + if (ch == '/')
43376 + i = 0; /* overwrite what we wrote */
43377 + else
43378 + if (i < len - 1)
43379 + tcomm[i++] = ch;
43380 + }
43381 + tcomm[i] = '\0';
43382 +}
43383 +
43384 int flush_old_exec(struct linux_binprm * bprm)
43385 {
43386 int retval;
43387 @@ -1081,6 +1128,7 @@ int flush_old_exec(struct linux_binprm * bprm)
43388
43389 set_mm_exe_file(bprm->mm, bprm->file);
43390
43391 + filename_to_taskname(bprm->tcomm, bprm->filename, sizeof(bprm->tcomm));
43392 /*
43393 * Release all of the old mmap stuff
43394 */
43395 @@ -1112,10 +1160,6 @@ EXPORT_SYMBOL(would_dump);
43396
43397 void setup_new_exec(struct linux_binprm * bprm)
43398 {
43399 - int i, ch;
43400 - const char *name;
43401 - char tcomm[sizeof(current->comm)];
43402 -
43403 arch_pick_mmap_layout(current->mm);
43404
43405 /* This is the point of no return */
43406 @@ -1126,18 +1170,7 @@ void setup_new_exec(struct linux_binprm * bprm)
43407 else
43408 set_dumpable(current->mm, suid_dumpable);
43409
43410 - name = bprm->filename;
43411 -
43412 - /* Copies the binary name from after last slash */
43413 - for (i=0; (ch = *(name++)) != '\0';) {
43414 - if (ch == '/')
43415 - i = 0; /* overwrite what we wrote */
43416 - else
43417 - if (i < (sizeof(tcomm) - 1))
43418 - tcomm[i++] = ch;
43419 - }
43420 - tcomm[i] = '\0';
43421 - set_task_comm(current, tcomm);
43422 + set_task_comm(current, bprm->tcomm);
43423
43424 /* Set the new mm task size. We have to do that late because it may
43425 * depend on TIF_32BIT which is only updated in flush_thread() on
43426 @@ -1247,7 +1280,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
43427 }
43428 rcu_read_unlock();
43429
43430 - if (p->fs->users > n_fs) {
43431 + if (atomic_read(&p->fs->users) > n_fs) {
43432 bprm->unsafe |= LSM_UNSAFE_SHARE;
43433 } else {
43434 res = -EAGAIN;
43435 @@ -1442,6 +1475,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43436
43437 EXPORT_SYMBOL(search_binary_handler);
43438
43439 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43440 +static DEFINE_PER_CPU(u64, exec_counter);
43441 +static int __init init_exec_counters(void)
43442 +{
43443 + unsigned int cpu;
43444 +
43445 + for_each_possible_cpu(cpu) {
43446 + per_cpu(exec_counter, cpu) = (u64)cpu;
43447 + }
43448 +
43449 + return 0;
43450 +}
43451 +early_initcall(init_exec_counters);
43452 +static inline void increment_exec_counter(void)
43453 +{
43454 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
43455 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43456 +}
43457 +#else
43458 +static inline void increment_exec_counter(void) {}
43459 +#endif
43460 +
43461 /*
43462 * sys_execve() executes a new program.
43463 */
43464 @@ -1450,6 +1505,11 @@ static int do_execve_common(const char *filename,
43465 struct user_arg_ptr envp,
43466 struct pt_regs *regs)
43467 {
43468 +#ifdef CONFIG_GRKERNSEC
43469 + struct file *old_exec_file;
43470 + struct acl_subject_label *old_acl;
43471 + struct rlimit old_rlim[RLIM_NLIMITS];
43472 +#endif
43473 struct linux_binprm *bprm;
43474 struct file *file;
43475 struct files_struct *displaced;
43476 @@ -1457,6 +1517,8 @@ static int do_execve_common(const char *filename,
43477 int retval;
43478 const struct cred *cred = current_cred();
43479
43480 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43481 +
43482 /*
43483 * We move the actual failure in case of RLIMIT_NPROC excess from
43484 * set*uid() to execve() because too many poorly written programs
43485 @@ -1497,12 +1559,27 @@ static int do_execve_common(const char *filename,
43486 if (IS_ERR(file))
43487 goto out_unmark;
43488
43489 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
43490 + retval = -EPERM;
43491 + goto out_file;
43492 + }
43493 +
43494 sched_exec();
43495
43496 bprm->file = file;
43497 bprm->filename = filename;
43498 bprm->interp = filename;
43499
43500 + if (gr_process_user_ban()) {
43501 + retval = -EPERM;
43502 + goto out_file;
43503 + }
43504 +
43505 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43506 + retval = -EACCES;
43507 + goto out_file;
43508 + }
43509 +
43510 retval = bprm_mm_init(bprm);
43511 if (retval)
43512 goto out_file;
43513 @@ -1519,24 +1596,65 @@ static int do_execve_common(const char *filename,
43514 if (retval < 0)
43515 goto out;
43516
43517 +#ifdef CONFIG_GRKERNSEC
43518 + old_acl = current->acl;
43519 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43520 + old_exec_file = current->exec_file;
43521 + get_file(file);
43522 + current->exec_file = file;
43523 +#endif
43524 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43525 + /* limit suid stack to 8MB
43526 + we saved the old limits above and will restore them if this exec fails
43527 + */
43528 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43529 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43530 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43531 +#endif
43532 +
43533 + if (!gr_tpe_allow(file)) {
43534 + retval = -EACCES;
43535 + goto out_fail;
43536 + }
43537 +
43538 + if (gr_check_crash_exec(file)) {
43539 + retval = -EACCES;
43540 + goto out_fail;
43541 + }
43542 +
43543 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43544 + bprm->unsafe);
43545 + if (retval < 0)
43546 + goto out_fail;
43547 +
43548 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43549 if (retval < 0)
43550 - goto out;
43551 + goto out_fail;
43552
43553 bprm->exec = bprm->p;
43554 retval = copy_strings(bprm->envc, envp, bprm);
43555 if (retval < 0)
43556 - goto out;
43557 + goto out_fail;
43558
43559 retval = copy_strings(bprm->argc, argv, bprm);
43560 if (retval < 0)
43561 - goto out;
43562 + goto out_fail;
43563 +
43564 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43565 +
43566 + gr_handle_exec_args(bprm, argv);
43567
43568 retval = search_binary_handler(bprm,regs);
43569 if (retval < 0)
43570 - goto out;
43571 + goto out_fail;
43572 +#ifdef CONFIG_GRKERNSEC
43573 + if (old_exec_file)
43574 + fput(old_exec_file);
43575 +#endif
43576
43577 /* execve succeeded */
43578 +
43579 + increment_exec_counter();
43580 current->fs->in_exec = 0;
43581 current->in_execve = 0;
43582 acct_update_integrals(current);
43583 @@ -1545,6 +1663,14 @@ static int do_execve_common(const char *filename,
43584 put_files_struct(displaced);
43585 return retval;
43586
43587 +out_fail:
43588 +#ifdef CONFIG_GRKERNSEC
43589 + current->acl = old_acl;
43590 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43591 + fput(current->exec_file);
43592 + current->exec_file = old_exec_file;
43593 +#endif
43594 +
43595 out:
43596 if (bprm->mm) {
43597 acct_arg_size(bprm, 0);
43598 @@ -1618,7 +1744,7 @@ static int expand_corename(struct core_name *cn)
43599 {
43600 char *old_corename = cn->corename;
43601
43602 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43603 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43604 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43605
43606 if (!cn->corename) {
43607 @@ -1715,7 +1841,7 @@ static int format_corename(struct core_name *cn, long signr)
43608 int pid_in_pattern = 0;
43609 int err = 0;
43610
43611 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43612 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43613 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43614 cn->used = 0;
43615
43616 @@ -1812,6 +1938,218 @@ out:
43617 return ispipe;
43618 }
43619
43620 +int pax_check_flags(unsigned long *flags)
43621 +{
43622 + int retval = 0;
43623 +
43624 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43625 + if (*flags & MF_PAX_SEGMEXEC)
43626 + {
43627 + *flags &= ~MF_PAX_SEGMEXEC;
43628 + retval = -EINVAL;
43629 + }
43630 +#endif
43631 +
43632 + if ((*flags & MF_PAX_PAGEEXEC)
43633 +
43634 +#ifdef CONFIG_PAX_PAGEEXEC
43635 + && (*flags & MF_PAX_SEGMEXEC)
43636 +#endif
43637 +
43638 + )
43639 + {
43640 + *flags &= ~MF_PAX_PAGEEXEC;
43641 + retval = -EINVAL;
43642 + }
43643 +
43644 + if ((*flags & MF_PAX_MPROTECT)
43645 +
43646 +#ifdef CONFIG_PAX_MPROTECT
43647 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43648 +#endif
43649 +
43650 + )
43651 + {
43652 + *flags &= ~MF_PAX_MPROTECT;
43653 + retval = -EINVAL;
43654 + }
43655 +
43656 + if ((*flags & MF_PAX_EMUTRAMP)
43657 +
43658 +#ifdef CONFIG_PAX_EMUTRAMP
43659 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43660 +#endif
43661 +
43662 + )
43663 + {
43664 + *flags &= ~MF_PAX_EMUTRAMP;
43665 + retval = -EINVAL;
43666 + }
43667 +
43668 + return retval;
43669 +}
43670 +
43671 +EXPORT_SYMBOL(pax_check_flags);
43672 +
43673 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43674 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
43675 +{
43676 + struct task_struct *tsk = current;
43677 + struct mm_struct *mm = current->mm;
43678 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
43679 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
43680 + char *path_exec = NULL;
43681 + char *path_fault = NULL;
43682 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
43683 +
43684 + if (buffer_exec && buffer_fault) {
43685 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
43686 +
43687 + down_read(&mm->mmap_sem);
43688 + vma = mm->mmap;
43689 + while (vma && (!vma_exec || !vma_fault)) {
43690 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
43691 + vma_exec = vma;
43692 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
43693 + vma_fault = vma;
43694 + vma = vma->vm_next;
43695 + }
43696 + if (vma_exec) {
43697 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
43698 + if (IS_ERR(path_exec))
43699 + path_exec = "<path too long>";
43700 + else {
43701 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
43702 + if (path_exec) {
43703 + *path_exec = 0;
43704 + path_exec = buffer_exec;
43705 + } else
43706 + path_exec = "<path too long>";
43707 + }
43708 + }
43709 + if (vma_fault) {
43710 + start = vma_fault->vm_start;
43711 + end = vma_fault->vm_end;
43712 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
43713 + if (vma_fault->vm_file) {
43714 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
43715 + if (IS_ERR(path_fault))
43716 + path_fault = "<path too long>";
43717 + else {
43718 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
43719 + if (path_fault) {
43720 + *path_fault = 0;
43721 + path_fault = buffer_fault;
43722 + } else
43723 + path_fault = "<path too long>";
43724 + }
43725 + } else
43726 + path_fault = "<anonymous mapping>";
43727 + }
43728 + up_read(&mm->mmap_sem);
43729 + }
43730 + if (tsk->signal->curr_ip)
43731 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
43732 + else
43733 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
43734 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
43735 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
43736 + task_uid(tsk), task_euid(tsk), pc, sp);
43737 + free_page((unsigned long)buffer_exec);
43738 + free_page((unsigned long)buffer_fault);
43739 + pax_report_insns(regs, pc, sp);
43740 + do_coredump(SIGKILL, SIGKILL, regs);
43741 +}
43742 +#endif
43743 +
43744 +#ifdef CONFIG_PAX_REFCOUNT
43745 +void pax_report_refcount_overflow(struct pt_regs *regs)
43746 +{
43747 + if (current->signal->curr_ip)
43748 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43749 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
43750 + else
43751 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43752 + current->comm, task_pid_nr(current), current_uid(), current_euid());
43753 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
43754 + show_regs(regs);
43755 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
43756 +}
43757 +#endif
43758 +
43759 +#ifdef CONFIG_PAX_USERCOPY
43760 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
43761 +int object_is_on_stack(const void *obj, unsigned long len)
43762 +{
43763 + const void * const stack = task_stack_page(current);
43764 + const void * const stackend = stack + THREAD_SIZE;
43765 +
43766 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43767 + const void *frame = NULL;
43768 + const void *oldframe;
43769 +#endif
43770 +
43771 + if (obj + len < obj)
43772 + return -1;
43773 +
43774 + if (obj + len <= stack || stackend <= obj)
43775 + return 0;
43776 +
43777 + if (obj < stack || stackend < obj + len)
43778 + return -1;
43779 +
43780 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43781 + oldframe = __builtin_frame_address(1);
43782 + if (oldframe)
43783 + frame = __builtin_frame_address(2);
43784 + /*
43785 + low ----------------------------------------------> high
43786 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
43787 + ^----------------^
43788 + allow copies only within here
43789 + */
43790 + while (stack <= frame && frame < stackend) {
43791 + /* if obj + len extends past the last frame, this
43792 + check won't pass and the next frame will be 0,
43793 + causing us to bail out and correctly report
43794 + the copy as invalid
43795 + */
43796 + if (obj + len <= frame)
43797 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
43798 + oldframe = frame;
43799 + frame = *(const void * const *)frame;
43800 + }
43801 + return -1;
43802 +#else
43803 + return 1;
43804 +#endif
43805 +}
43806 +
43807 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
43808 +{
43809 + if (current->signal->curr_ip)
43810 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43811 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43812 + else
43813 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43814 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43815 + dump_stack();
43816 + gr_handle_kernel_exploit();
43817 + do_group_exit(SIGKILL);
43818 +}
43819 +#endif
43820 +
43821 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
43822 +void pax_track_stack(void)
43823 +{
43824 + unsigned long sp = (unsigned long)&sp;
43825 + if (sp < current_thread_info()->lowest_stack &&
43826 + sp > (unsigned long)task_stack_page(current))
43827 + current_thread_info()->lowest_stack = sp;
43828 +}
43829 +EXPORT_SYMBOL(pax_track_stack);
43830 +#endif
43831 +
43832 static int zap_process(struct task_struct *start, int exit_code)
43833 {
43834 struct task_struct *t;
43835 @@ -2023,17 +2361,17 @@ static void wait_for_dump_helpers(struct file *file)
43836 pipe = file->f_path.dentry->d_inode->i_pipe;
43837
43838 pipe_lock(pipe);
43839 - pipe->readers++;
43840 - pipe->writers--;
43841 + atomic_inc(&pipe->readers);
43842 + atomic_dec(&pipe->writers);
43843
43844 - while ((pipe->readers > 1) && (!signal_pending(current))) {
43845 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
43846 wake_up_interruptible_sync(&pipe->wait);
43847 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
43848 pipe_wait(pipe);
43849 }
43850
43851 - pipe->readers--;
43852 - pipe->writers++;
43853 + atomic_dec(&pipe->readers);
43854 + atomic_inc(&pipe->writers);
43855 pipe_unlock(pipe);
43856
43857 }
43858 @@ -2094,7 +2432,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43859 int retval = 0;
43860 int flag = 0;
43861 int ispipe;
43862 - static atomic_t core_dump_count = ATOMIC_INIT(0);
43863 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
43864 struct coredump_params cprm = {
43865 .signr = signr,
43866 .regs = regs,
43867 @@ -2109,6 +2447,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43868
43869 audit_core_dumps(signr);
43870
43871 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
43872 + gr_handle_brute_attach(current, cprm.mm_flags);
43873 +
43874 binfmt = mm->binfmt;
43875 if (!binfmt || !binfmt->core_dump)
43876 goto fail;
43877 @@ -2176,7 +2517,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43878 }
43879 cprm.limit = RLIM_INFINITY;
43880
43881 - dump_count = atomic_inc_return(&core_dump_count);
43882 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
43883 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
43884 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
43885 task_tgid_vnr(current), current->comm);
43886 @@ -2203,6 +2544,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43887 } else {
43888 struct inode *inode;
43889
43890 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
43891 +
43892 if (cprm.limit < binfmt->min_coredump)
43893 goto fail_unlock;
43894
43895 @@ -2246,7 +2589,7 @@ close_fail:
43896 filp_close(cprm.file, NULL);
43897 fail_dropcount:
43898 if (ispipe)
43899 - atomic_dec(&core_dump_count);
43900 + atomic_dec_unchecked(&core_dump_count);
43901 fail_unlock:
43902 kfree(cn.corename);
43903 fail_corename:
43904 @@ -2265,7 +2608,7 @@ fail:
43905 */
43906 int dump_write(struct file *file, const void *addr, int nr)
43907 {
43908 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
43909 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
43910 }
43911 EXPORT_SYMBOL(dump_write);
43912
43913 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
43914 index a8cbe1b..fed04cb 100644
43915 --- a/fs/ext2/balloc.c
43916 +++ b/fs/ext2/balloc.c
43917 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
43918
43919 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43920 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43921 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43922 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
43923 sbi->s_resuid != current_fsuid() &&
43924 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43925 return 0;
43926 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
43927 index a203892..4e64db5 100644
43928 --- a/fs/ext3/balloc.c
43929 +++ b/fs/ext3/balloc.c
43930 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
43931
43932 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43933 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43934 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43935 + if (free_blocks < root_blocks + 1 &&
43936 !use_reservation && sbi->s_resuid != current_fsuid() &&
43937 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43938 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
43939 + !capable_nolog(CAP_SYS_RESOURCE)) {
43940 return 0;
43941 }
43942 return 1;
43943 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
43944 index 12ccacd..a6035fce0 100644
43945 --- a/fs/ext4/balloc.c
43946 +++ b/fs/ext4/balloc.c
43947 @@ -436,8 +436,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
43948 /* Hm, nope. Are (enough) root reserved clusters available? */
43949 if (sbi->s_resuid == current_fsuid() ||
43950 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
43951 - capable(CAP_SYS_RESOURCE) ||
43952 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
43953 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
43954 + capable_nolog(CAP_SYS_RESOURCE)) {
43955
43956 if (free_clusters >= (nclusters + dirty_clusters))
43957 return 1;
43958 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
43959 index 5b0e26a..0aa002d 100644
43960 --- a/fs/ext4/ext4.h
43961 +++ b/fs/ext4/ext4.h
43962 @@ -1208,19 +1208,19 @@ struct ext4_sb_info {
43963 unsigned long s_mb_last_start;
43964
43965 /* stats for buddy allocator */
43966 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
43967 - atomic_t s_bal_success; /* we found long enough chunks */
43968 - atomic_t s_bal_allocated; /* in blocks */
43969 - atomic_t s_bal_ex_scanned; /* total extents scanned */
43970 - atomic_t s_bal_goals; /* goal hits */
43971 - atomic_t s_bal_breaks; /* too long searches */
43972 - atomic_t s_bal_2orders; /* 2^order hits */
43973 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
43974 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
43975 + atomic_unchecked_t s_bal_allocated; /* in blocks */
43976 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
43977 + atomic_unchecked_t s_bal_goals; /* goal hits */
43978 + atomic_unchecked_t s_bal_breaks; /* too long searches */
43979 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
43980 spinlock_t s_bal_lock;
43981 unsigned long s_mb_buddies_generated;
43982 unsigned long long s_mb_generation_time;
43983 - atomic_t s_mb_lost_chunks;
43984 - atomic_t s_mb_preallocated;
43985 - atomic_t s_mb_discarded;
43986 + atomic_unchecked_t s_mb_lost_chunks;
43987 + atomic_unchecked_t s_mb_preallocated;
43988 + atomic_unchecked_t s_mb_discarded;
43989 atomic_t s_lock_busy;
43990
43991 /* locality groups */
43992 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
43993 index e2d8be8..c7f0ce9 100644
43994 --- a/fs/ext4/mballoc.c
43995 +++ b/fs/ext4/mballoc.c
43996 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
43997 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
43998
43999 if (EXT4_SB(sb)->s_mb_stats)
44000 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44001 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44002
44003 break;
44004 }
44005 @@ -2088,7 +2088,7 @@ repeat:
44006 ac->ac_status = AC_STATUS_CONTINUE;
44007 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44008 cr = 3;
44009 - atomic_inc(&sbi->s_mb_lost_chunks);
44010 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44011 goto repeat;
44012 }
44013 }
44014 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44015 if (sbi->s_mb_stats) {
44016 ext4_msg(sb, KERN_INFO,
44017 "mballoc: %u blocks %u reqs (%u success)",
44018 - atomic_read(&sbi->s_bal_allocated),
44019 - atomic_read(&sbi->s_bal_reqs),
44020 - atomic_read(&sbi->s_bal_success));
44021 + atomic_read_unchecked(&sbi->s_bal_allocated),
44022 + atomic_read_unchecked(&sbi->s_bal_reqs),
44023 + atomic_read_unchecked(&sbi->s_bal_success));
44024 ext4_msg(sb, KERN_INFO,
44025 "mballoc: %u extents scanned, %u goal hits, "
44026 "%u 2^N hits, %u breaks, %u lost",
44027 - atomic_read(&sbi->s_bal_ex_scanned),
44028 - atomic_read(&sbi->s_bal_goals),
44029 - atomic_read(&sbi->s_bal_2orders),
44030 - atomic_read(&sbi->s_bal_breaks),
44031 - atomic_read(&sbi->s_mb_lost_chunks));
44032 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44033 + atomic_read_unchecked(&sbi->s_bal_goals),
44034 + atomic_read_unchecked(&sbi->s_bal_2orders),
44035 + atomic_read_unchecked(&sbi->s_bal_breaks),
44036 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44037 ext4_msg(sb, KERN_INFO,
44038 "mballoc: %lu generated and it took %Lu",
44039 sbi->s_mb_buddies_generated,
44040 sbi->s_mb_generation_time);
44041 ext4_msg(sb, KERN_INFO,
44042 "mballoc: %u preallocated, %u discarded",
44043 - atomic_read(&sbi->s_mb_preallocated),
44044 - atomic_read(&sbi->s_mb_discarded));
44045 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44046 + atomic_read_unchecked(&sbi->s_mb_discarded));
44047 }
44048
44049 free_percpu(sbi->s_locality_groups);
44050 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44051 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44052
44053 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44054 - atomic_inc(&sbi->s_bal_reqs);
44055 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44056 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44057 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44058 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44059 - atomic_inc(&sbi->s_bal_success);
44060 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44061 + atomic_inc_unchecked(&sbi->s_bal_success);
44062 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44063 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44064 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44065 - atomic_inc(&sbi->s_bal_goals);
44066 + atomic_inc_unchecked(&sbi->s_bal_goals);
44067 if (ac->ac_found > sbi->s_mb_max_to_scan)
44068 - atomic_inc(&sbi->s_bal_breaks);
44069 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44070 }
44071
44072 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44073 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44074 trace_ext4_mb_new_inode_pa(ac, pa);
44075
44076 ext4_mb_use_inode_pa(ac, pa);
44077 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44078 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44079
44080 ei = EXT4_I(ac->ac_inode);
44081 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44082 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44083 trace_ext4_mb_new_group_pa(ac, pa);
44084
44085 ext4_mb_use_group_pa(ac, pa);
44086 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44087 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44088
44089 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44090 lg = ac->ac_lg;
44091 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44092 * from the bitmap and continue.
44093 */
44094 }
44095 - atomic_add(free, &sbi->s_mb_discarded);
44096 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44097
44098 return err;
44099 }
44100 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44101 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44102 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44103 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44104 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44105 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44106 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44107
44108 return 0;
44109 diff --git a/fs/fcntl.c b/fs/fcntl.c
44110 index 22764c7..86372c9 100644
44111 --- a/fs/fcntl.c
44112 +++ b/fs/fcntl.c
44113 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44114 if (err)
44115 return err;
44116
44117 + if (gr_handle_chroot_fowner(pid, type))
44118 + return -ENOENT;
44119 + if (gr_check_protected_task_fowner(pid, type))
44120 + return -EACCES;
44121 +
44122 f_modown(filp, pid, type, force);
44123 return 0;
44124 }
44125 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44126
44127 static int f_setown_ex(struct file *filp, unsigned long arg)
44128 {
44129 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44130 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44131 struct f_owner_ex owner;
44132 struct pid *pid;
44133 int type;
44134 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44135
44136 static int f_getown_ex(struct file *filp, unsigned long arg)
44137 {
44138 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44139 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44140 struct f_owner_ex owner;
44141 int ret = 0;
44142
44143 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44144 switch (cmd) {
44145 case F_DUPFD:
44146 case F_DUPFD_CLOEXEC:
44147 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44148 if (arg >= rlimit(RLIMIT_NOFILE))
44149 break;
44150 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44151 diff --git a/fs/fifo.c b/fs/fifo.c
44152 index b1a524d..4ee270e 100644
44153 --- a/fs/fifo.c
44154 +++ b/fs/fifo.c
44155 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44156 */
44157 filp->f_op = &read_pipefifo_fops;
44158 pipe->r_counter++;
44159 - if (pipe->readers++ == 0)
44160 + if (atomic_inc_return(&pipe->readers) == 1)
44161 wake_up_partner(inode);
44162
44163 - if (!pipe->writers) {
44164 + if (!atomic_read(&pipe->writers)) {
44165 if ((filp->f_flags & O_NONBLOCK)) {
44166 /* suppress POLLHUP until we have
44167 * seen a writer */
44168 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44169 * errno=ENXIO when there is no process reading the FIFO.
44170 */
44171 ret = -ENXIO;
44172 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44173 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44174 goto err;
44175
44176 filp->f_op = &write_pipefifo_fops;
44177 pipe->w_counter++;
44178 - if (!pipe->writers++)
44179 + if (atomic_inc_return(&pipe->writers) == 1)
44180 wake_up_partner(inode);
44181
44182 - if (!pipe->readers) {
44183 + if (!atomic_read(&pipe->readers)) {
44184 wait_for_partner(inode, &pipe->r_counter);
44185 if (signal_pending(current))
44186 goto err_wr;
44187 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44188 */
44189 filp->f_op = &rdwr_pipefifo_fops;
44190
44191 - pipe->readers++;
44192 - pipe->writers++;
44193 + atomic_inc(&pipe->readers);
44194 + atomic_inc(&pipe->writers);
44195 pipe->r_counter++;
44196 pipe->w_counter++;
44197 - if (pipe->readers == 1 || pipe->writers == 1)
44198 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44199 wake_up_partner(inode);
44200 break;
44201
44202 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44203 return 0;
44204
44205 err_rd:
44206 - if (!--pipe->readers)
44207 + if (atomic_dec_and_test(&pipe->readers))
44208 wake_up_interruptible(&pipe->wait);
44209 ret = -ERESTARTSYS;
44210 goto err;
44211
44212 err_wr:
44213 - if (!--pipe->writers)
44214 + if (atomic_dec_and_test(&pipe->writers))
44215 wake_up_interruptible(&pipe->wait);
44216 ret = -ERESTARTSYS;
44217 goto err;
44218
44219 err:
44220 - if (!pipe->readers && !pipe->writers)
44221 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44222 free_pipe_info(inode);
44223
44224 err_nocleanup:
44225 diff --git a/fs/file.c b/fs/file.c
44226 index 4c6992d..104cdea 100644
44227 --- a/fs/file.c
44228 +++ b/fs/file.c
44229 @@ -15,6 +15,7 @@
44230 #include <linux/slab.h>
44231 #include <linux/vmalloc.h>
44232 #include <linux/file.h>
44233 +#include <linux/security.h>
44234 #include <linux/fdtable.h>
44235 #include <linux/bitops.h>
44236 #include <linux/interrupt.h>
44237 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
44238 * N.B. For clone tasks sharing a files structure, this test
44239 * will limit the total number of files that can be opened.
44240 */
44241 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44242 if (nr >= rlimit(RLIMIT_NOFILE))
44243 return -EMFILE;
44244
44245 diff --git a/fs/filesystems.c b/fs/filesystems.c
44246 index 0845f84..7b4ebef 100644
44247 --- a/fs/filesystems.c
44248 +++ b/fs/filesystems.c
44249 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
44250 int len = dot ? dot - name : strlen(name);
44251
44252 fs = __get_fs_type(name, len);
44253 +
44254 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
44255 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44256 +#else
44257 if (!fs && (request_module("%.*s", len, name) == 0))
44258 +#endif
44259 fs = __get_fs_type(name, len);
44260
44261 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44262 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44263 index 78b519c..a8b4979 100644
44264 --- a/fs/fs_struct.c
44265 +++ b/fs/fs_struct.c
44266 @@ -4,6 +4,7 @@
44267 #include <linux/path.h>
44268 #include <linux/slab.h>
44269 #include <linux/fs_struct.h>
44270 +#include <linux/grsecurity.h>
44271 #include "internal.h"
44272
44273 static inline void path_get_longterm(struct path *path)
44274 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44275 old_root = fs->root;
44276 fs->root = *path;
44277 path_get_longterm(path);
44278 + gr_set_chroot_entries(current, path);
44279 write_seqcount_end(&fs->seq);
44280 spin_unlock(&fs->lock);
44281 if (old_root.dentry)
44282 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44283 && fs->root.mnt == old_root->mnt) {
44284 path_get_longterm(new_root);
44285 fs->root = *new_root;
44286 + gr_set_chroot_entries(p, new_root);
44287 count++;
44288 }
44289 if (fs->pwd.dentry == old_root->dentry
44290 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
44291 spin_lock(&fs->lock);
44292 write_seqcount_begin(&fs->seq);
44293 tsk->fs = NULL;
44294 - kill = !--fs->users;
44295 + gr_clear_chroot_entries(tsk);
44296 + kill = !atomic_dec_return(&fs->users);
44297 write_seqcount_end(&fs->seq);
44298 spin_unlock(&fs->lock);
44299 task_unlock(tsk);
44300 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44301 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44302 /* We don't need to lock fs - think why ;-) */
44303 if (fs) {
44304 - fs->users = 1;
44305 + atomic_set(&fs->users, 1);
44306 fs->in_exec = 0;
44307 spin_lock_init(&fs->lock);
44308 seqcount_init(&fs->seq);
44309 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44310 spin_lock(&old->lock);
44311 fs->root = old->root;
44312 path_get_longterm(&fs->root);
44313 + /* instead of calling gr_set_chroot_entries here,
44314 + we call it from every caller of this function
44315 + */
44316 fs->pwd = old->pwd;
44317 path_get_longterm(&fs->pwd);
44318 spin_unlock(&old->lock);
44319 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
44320
44321 task_lock(current);
44322 spin_lock(&fs->lock);
44323 - kill = !--fs->users;
44324 + kill = !atomic_dec_return(&fs->users);
44325 current->fs = new_fs;
44326 + gr_set_chroot_entries(current, &new_fs->root);
44327 spin_unlock(&fs->lock);
44328 task_unlock(current);
44329
44330 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44331
44332 int current_umask(void)
44333 {
44334 - return current->fs->umask;
44335 + return current->fs->umask | gr_acl_umask();
44336 }
44337 EXPORT_SYMBOL(current_umask);
44338
44339 /* to be mentioned only in INIT_TASK */
44340 struct fs_struct init_fs = {
44341 - .users = 1,
44342 + .users = ATOMIC_INIT(1),
44343 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44344 .seq = SEQCNT_ZERO,
44345 .umask = 0022,
44346 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
44347 task_lock(current);
44348
44349 spin_lock(&init_fs.lock);
44350 - init_fs.users++;
44351 + atomic_inc(&init_fs.users);
44352 spin_unlock(&init_fs.lock);
44353
44354 spin_lock(&fs->lock);
44355 current->fs = &init_fs;
44356 - kill = !--fs->users;
44357 + gr_set_chroot_entries(current, &current->fs->root);
44358 + kill = !atomic_dec_return(&fs->users);
44359 spin_unlock(&fs->lock);
44360
44361 task_unlock(current);
44362 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44363 index 9905350..02eaec4 100644
44364 --- a/fs/fscache/cookie.c
44365 +++ b/fs/fscache/cookie.c
44366 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44367 parent ? (char *) parent->def->name : "<no-parent>",
44368 def->name, netfs_data);
44369
44370 - fscache_stat(&fscache_n_acquires);
44371 + fscache_stat_unchecked(&fscache_n_acquires);
44372
44373 /* if there's no parent cookie, then we don't create one here either */
44374 if (!parent) {
44375 - fscache_stat(&fscache_n_acquires_null);
44376 + fscache_stat_unchecked(&fscache_n_acquires_null);
44377 _leave(" [no parent]");
44378 return NULL;
44379 }
44380 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44381 /* allocate and initialise a cookie */
44382 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44383 if (!cookie) {
44384 - fscache_stat(&fscache_n_acquires_oom);
44385 + fscache_stat_unchecked(&fscache_n_acquires_oom);
44386 _leave(" [ENOMEM]");
44387 return NULL;
44388 }
44389 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44390
44391 switch (cookie->def->type) {
44392 case FSCACHE_COOKIE_TYPE_INDEX:
44393 - fscache_stat(&fscache_n_cookie_index);
44394 + fscache_stat_unchecked(&fscache_n_cookie_index);
44395 break;
44396 case FSCACHE_COOKIE_TYPE_DATAFILE:
44397 - fscache_stat(&fscache_n_cookie_data);
44398 + fscache_stat_unchecked(&fscache_n_cookie_data);
44399 break;
44400 default:
44401 - fscache_stat(&fscache_n_cookie_special);
44402 + fscache_stat_unchecked(&fscache_n_cookie_special);
44403 break;
44404 }
44405
44406 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44407 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44408 atomic_dec(&parent->n_children);
44409 __fscache_cookie_put(cookie);
44410 - fscache_stat(&fscache_n_acquires_nobufs);
44411 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44412 _leave(" = NULL");
44413 return NULL;
44414 }
44415 }
44416
44417 - fscache_stat(&fscache_n_acquires_ok);
44418 + fscache_stat_unchecked(&fscache_n_acquires_ok);
44419 _leave(" = %p", cookie);
44420 return cookie;
44421 }
44422 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44423 cache = fscache_select_cache_for_object(cookie->parent);
44424 if (!cache) {
44425 up_read(&fscache_addremove_sem);
44426 - fscache_stat(&fscache_n_acquires_no_cache);
44427 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44428 _leave(" = -ENOMEDIUM [no cache]");
44429 return -ENOMEDIUM;
44430 }
44431 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44432 object = cache->ops->alloc_object(cache, cookie);
44433 fscache_stat_d(&fscache_n_cop_alloc_object);
44434 if (IS_ERR(object)) {
44435 - fscache_stat(&fscache_n_object_no_alloc);
44436 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
44437 ret = PTR_ERR(object);
44438 goto error;
44439 }
44440
44441 - fscache_stat(&fscache_n_object_alloc);
44442 + fscache_stat_unchecked(&fscache_n_object_alloc);
44443
44444 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44445
44446 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44447 struct fscache_object *object;
44448 struct hlist_node *_p;
44449
44450 - fscache_stat(&fscache_n_updates);
44451 + fscache_stat_unchecked(&fscache_n_updates);
44452
44453 if (!cookie) {
44454 - fscache_stat(&fscache_n_updates_null);
44455 + fscache_stat_unchecked(&fscache_n_updates_null);
44456 _leave(" [no cookie]");
44457 return;
44458 }
44459 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44460 struct fscache_object *object;
44461 unsigned long event;
44462
44463 - fscache_stat(&fscache_n_relinquishes);
44464 + fscache_stat_unchecked(&fscache_n_relinquishes);
44465 if (retire)
44466 - fscache_stat(&fscache_n_relinquishes_retire);
44467 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44468
44469 if (!cookie) {
44470 - fscache_stat(&fscache_n_relinquishes_null);
44471 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
44472 _leave(" [no cookie]");
44473 return;
44474 }
44475 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44476
44477 /* wait for the cookie to finish being instantiated (or to fail) */
44478 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44479 - fscache_stat(&fscache_n_relinquishes_waitcrt);
44480 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44481 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44482 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44483 }
44484 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44485 index f6aad48..88dcf26 100644
44486 --- a/fs/fscache/internal.h
44487 +++ b/fs/fscache/internal.h
44488 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44489 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44490 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44491
44492 -extern atomic_t fscache_n_op_pend;
44493 -extern atomic_t fscache_n_op_run;
44494 -extern atomic_t fscache_n_op_enqueue;
44495 -extern atomic_t fscache_n_op_deferred_release;
44496 -extern atomic_t fscache_n_op_release;
44497 -extern atomic_t fscache_n_op_gc;
44498 -extern atomic_t fscache_n_op_cancelled;
44499 -extern atomic_t fscache_n_op_rejected;
44500 +extern atomic_unchecked_t fscache_n_op_pend;
44501 +extern atomic_unchecked_t fscache_n_op_run;
44502 +extern atomic_unchecked_t fscache_n_op_enqueue;
44503 +extern atomic_unchecked_t fscache_n_op_deferred_release;
44504 +extern atomic_unchecked_t fscache_n_op_release;
44505 +extern atomic_unchecked_t fscache_n_op_gc;
44506 +extern atomic_unchecked_t fscache_n_op_cancelled;
44507 +extern atomic_unchecked_t fscache_n_op_rejected;
44508
44509 -extern atomic_t fscache_n_attr_changed;
44510 -extern atomic_t fscache_n_attr_changed_ok;
44511 -extern atomic_t fscache_n_attr_changed_nobufs;
44512 -extern atomic_t fscache_n_attr_changed_nomem;
44513 -extern atomic_t fscache_n_attr_changed_calls;
44514 +extern atomic_unchecked_t fscache_n_attr_changed;
44515 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
44516 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44517 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44518 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
44519
44520 -extern atomic_t fscache_n_allocs;
44521 -extern atomic_t fscache_n_allocs_ok;
44522 -extern atomic_t fscache_n_allocs_wait;
44523 -extern atomic_t fscache_n_allocs_nobufs;
44524 -extern atomic_t fscache_n_allocs_intr;
44525 -extern atomic_t fscache_n_allocs_object_dead;
44526 -extern atomic_t fscache_n_alloc_ops;
44527 -extern atomic_t fscache_n_alloc_op_waits;
44528 +extern atomic_unchecked_t fscache_n_allocs;
44529 +extern atomic_unchecked_t fscache_n_allocs_ok;
44530 +extern atomic_unchecked_t fscache_n_allocs_wait;
44531 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
44532 +extern atomic_unchecked_t fscache_n_allocs_intr;
44533 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
44534 +extern atomic_unchecked_t fscache_n_alloc_ops;
44535 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
44536
44537 -extern atomic_t fscache_n_retrievals;
44538 -extern atomic_t fscache_n_retrievals_ok;
44539 -extern atomic_t fscache_n_retrievals_wait;
44540 -extern atomic_t fscache_n_retrievals_nodata;
44541 -extern atomic_t fscache_n_retrievals_nobufs;
44542 -extern atomic_t fscache_n_retrievals_intr;
44543 -extern atomic_t fscache_n_retrievals_nomem;
44544 -extern atomic_t fscache_n_retrievals_object_dead;
44545 -extern atomic_t fscache_n_retrieval_ops;
44546 -extern atomic_t fscache_n_retrieval_op_waits;
44547 +extern atomic_unchecked_t fscache_n_retrievals;
44548 +extern atomic_unchecked_t fscache_n_retrievals_ok;
44549 +extern atomic_unchecked_t fscache_n_retrievals_wait;
44550 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
44551 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44552 +extern atomic_unchecked_t fscache_n_retrievals_intr;
44553 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
44554 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44555 +extern atomic_unchecked_t fscache_n_retrieval_ops;
44556 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44557
44558 -extern atomic_t fscache_n_stores;
44559 -extern atomic_t fscache_n_stores_ok;
44560 -extern atomic_t fscache_n_stores_again;
44561 -extern atomic_t fscache_n_stores_nobufs;
44562 -extern atomic_t fscache_n_stores_oom;
44563 -extern atomic_t fscache_n_store_ops;
44564 -extern atomic_t fscache_n_store_calls;
44565 -extern atomic_t fscache_n_store_pages;
44566 -extern atomic_t fscache_n_store_radix_deletes;
44567 -extern atomic_t fscache_n_store_pages_over_limit;
44568 +extern atomic_unchecked_t fscache_n_stores;
44569 +extern atomic_unchecked_t fscache_n_stores_ok;
44570 +extern atomic_unchecked_t fscache_n_stores_again;
44571 +extern atomic_unchecked_t fscache_n_stores_nobufs;
44572 +extern atomic_unchecked_t fscache_n_stores_oom;
44573 +extern atomic_unchecked_t fscache_n_store_ops;
44574 +extern atomic_unchecked_t fscache_n_store_calls;
44575 +extern atomic_unchecked_t fscache_n_store_pages;
44576 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
44577 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44578
44579 -extern atomic_t fscache_n_store_vmscan_not_storing;
44580 -extern atomic_t fscache_n_store_vmscan_gone;
44581 -extern atomic_t fscache_n_store_vmscan_busy;
44582 -extern atomic_t fscache_n_store_vmscan_cancelled;
44583 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44584 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44585 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44586 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44587
44588 -extern atomic_t fscache_n_marks;
44589 -extern atomic_t fscache_n_uncaches;
44590 +extern atomic_unchecked_t fscache_n_marks;
44591 +extern atomic_unchecked_t fscache_n_uncaches;
44592
44593 -extern atomic_t fscache_n_acquires;
44594 -extern atomic_t fscache_n_acquires_null;
44595 -extern atomic_t fscache_n_acquires_no_cache;
44596 -extern atomic_t fscache_n_acquires_ok;
44597 -extern atomic_t fscache_n_acquires_nobufs;
44598 -extern atomic_t fscache_n_acquires_oom;
44599 +extern atomic_unchecked_t fscache_n_acquires;
44600 +extern atomic_unchecked_t fscache_n_acquires_null;
44601 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
44602 +extern atomic_unchecked_t fscache_n_acquires_ok;
44603 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
44604 +extern atomic_unchecked_t fscache_n_acquires_oom;
44605
44606 -extern atomic_t fscache_n_updates;
44607 -extern atomic_t fscache_n_updates_null;
44608 -extern atomic_t fscache_n_updates_run;
44609 +extern atomic_unchecked_t fscache_n_updates;
44610 +extern atomic_unchecked_t fscache_n_updates_null;
44611 +extern atomic_unchecked_t fscache_n_updates_run;
44612
44613 -extern atomic_t fscache_n_relinquishes;
44614 -extern atomic_t fscache_n_relinquishes_null;
44615 -extern atomic_t fscache_n_relinquishes_waitcrt;
44616 -extern atomic_t fscache_n_relinquishes_retire;
44617 +extern atomic_unchecked_t fscache_n_relinquishes;
44618 +extern atomic_unchecked_t fscache_n_relinquishes_null;
44619 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44620 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
44621
44622 -extern atomic_t fscache_n_cookie_index;
44623 -extern atomic_t fscache_n_cookie_data;
44624 -extern atomic_t fscache_n_cookie_special;
44625 +extern atomic_unchecked_t fscache_n_cookie_index;
44626 +extern atomic_unchecked_t fscache_n_cookie_data;
44627 +extern atomic_unchecked_t fscache_n_cookie_special;
44628
44629 -extern atomic_t fscache_n_object_alloc;
44630 -extern atomic_t fscache_n_object_no_alloc;
44631 -extern atomic_t fscache_n_object_lookups;
44632 -extern atomic_t fscache_n_object_lookups_negative;
44633 -extern atomic_t fscache_n_object_lookups_positive;
44634 -extern atomic_t fscache_n_object_lookups_timed_out;
44635 -extern atomic_t fscache_n_object_created;
44636 -extern atomic_t fscache_n_object_avail;
44637 -extern atomic_t fscache_n_object_dead;
44638 +extern atomic_unchecked_t fscache_n_object_alloc;
44639 +extern atomic_unchecked_t fscache_n_object_no_alloc;
44640 +extern atomic_unchecked_t fscache_n_object_lookups;
44641 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
44642 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
44643 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
44644 +extern atomic_unchecked_t fscache_n_object_created;
44645 +extern atomic_unchecked_t fscache_n_object_avail;
44646 +extern atomic_unchecked_t fscache_n_object_dead;
44647
44648 -extern atomic_t fscache_n_checkaux_none;
44649 -extern atomic_t fscache_n_checkaux_okay;
44650 -extern atomic_t fscache_n_checkaux_update;
44651 -extern atomic_t fscache_n_checkaux_obsolete;
44652 +extern atomic_unchecked_t fscache_n_checkaux_none;
44653 +extern atomic_unchecked_t fscache_n_checkaux_okay;
44654 +extern atomic_unchecked_t fscache_n_checkaux_update;
44655 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
44656
44657 extern atomic_t fscache_n_cop_alloc_object;
44658 extern atomic_t fscache_n_cop_lookup_object;
44659 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
44660 atomic_inc(stat);
44661 }
44662
44663 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
44664 +{
44665 + atomic_inc_unchecked(stat);
44666 +}
44667 +
44668 static inline void fscache_stat_d(atomic_t *stat)
44669 {
44670 atomic_dec(stat);
44671 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
44672
44673 #define __fscache_stat(stat) (NULL)
44674 #define fscache_stat(stat) do {} while (0)
44675 +#define fscache_stat_unchecked(stat) do {} while (0)
44676 #define fscache_stat_d(stat) do {} while (0)
44677 #endif
44678
44679 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
44680 index b6b897c..0ffff9c 100644
44681 --- a/fs/fscache/object.c
44682 +++ b/fs/fscache/object.c
44683 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44684 /* update the object metadata on disk */
44685 case FSCACHE_OBJECT_UPDATING:
44686 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
44687 - fscache_stat(&fscache_n_updates_run);
44688 + fscache_stat_unchecked(&fscache_n_updates_run);
44689 fscache_stat(&fscache_n_cop_update_object);
44690 object->cache->ops->update_object(object);
44691 fscache_stat_d(&fscache_n_cop_update_object);
44692 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44693 spin_lock(&object->lock);
44694 object->state = FSCACHE_OBJECT_DEAD;
44695 spin_unlock(&object->lock);
44696 - fscache_stat(&fscache_n_object_dead);
44697 + fscache_stat_unchecked(&fscache_n_object_dead);
44698 goto terminal_transit;
44699
44700 /* handle the parent cache of this object being withdrawn from
44701 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44702 spin_lock(&object->lock);
44703 object->state = FSCACHE_OBJECT_DEAD;
44704 spin_unlock(&object->lock);
44705 - fscache_stat(&fscache_n_object_dead);
44706 + fscache_stat_unchecked(&fscache_n_object_dead);
44707 goto terminal_transit;
44708
44709 /* complain about the object being woken up once it is
44710 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44711 parent->cookie->def->name, cookie->def->name,
44712 object->cache->tag->name);
44713
44714 - fscache_stat(&fscache_n_object_lookups);
44715 + fscache_stat_unchecked(&fscache_n_object_lookups);
44716 fscache_stat(&fscache_n_cop_lookup_object);
44717 ret = object->cache->ops->lookup_object(object);
44718 fscache_stat_d(&fscache_n_cop_lookup_object);
44719 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44720 if (ret == -ETIMEDOUT) {
44721 /* probably stuck behind another object, so move this one to
44722 * the back of the queue */
44723 - fscache_stat(&fscache_n_object_lookups_timed_out);
44724 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
44725 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44726 }
44727
44728 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
44729
44730 spin_lock(&object->lock);
44731 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44732 - fscache_stat(&fscache_n_object_lookups_negative);
44733 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
44734
44735 /* transit here to allow write requests to begin stacking up
44736 * and read requests to begin returning ENODATA */
44737 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
44738 * result, in which case there may be data available */
44739 spin_lock(&object->lock);
44740 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44741 - fscache_stat(&fscache_n_object_lookups_positive);
44742 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
44743
44744 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
44745
44746 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
44747 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44748 } else {
44749 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
44750 - fscache_stat(&fscache_n_object_created);
44751 + fscache_stat_unchecked(&fscache_n_object_created);
44752
44753 object->state = FSCACHE_OBJECT_AVAILABLE;
44754 spin_unlock(&object->lock);
44755 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
44756 fscache_enqueue_dependents(object);
44757
44758 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
44759 - fscache_stat(&fscache_n_object_avail);
44760 + fscache_stat_unchecked(&fscache_n_object_avail);
44761
44762 _leave("");
44763 }
44764 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44765 enum fscache_checkaux result;
44766
44767 if (!object->cookie->def->check_aux) {
44768 - fscache_stat(&fscache_n_checkaux_none);
44769 + fscache_stat_unchecked(&fscache_n_checkaux_none);
44770 return FSCACHE_CHECKAUX_OKAY;
44771 }
44772
44773 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44774 switch (result) {
44775 /* entry okay as is */
44776 case FSCACHE_CHECKAUX_OKAY:
44777 - fscache_stat(&fscache_n_checkaux_okay);
44778 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
44779 break;
44780
44781 /* entry requires update */
44782 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
44783 - fscache_stat(&fscache_n_checkaux_update);
44784 + fscache_stat_unchecked(&fscache_n_checkaux_update);
44785 break;
44786
44787 /* entry requires deletion */
44788 case FSCACHE_CHECKAUX_OBSOLETE:
44789 - fscache_stat(&fscache_n_checkaux_obsolete);
44790 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
44791 break;
44792
44793 default:
44794 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
44795 index 30afdfa..2256596 100644
44796 --- a/fs/fscache/operation.c
44797 +++ b/fs/fscache/operation.c
44798 @@ -17,7 +17,7 @@
44799 #include <linux/slab.h>
44800 #include "internal.h"
44801
44802 -atomic_t fscache_op_debug_id;
44803 +atomic_unchecked_t fscache_op_debug_id;
44804 EXPORT_SYMBOL(fscache_op_debug_id);
44805
44806 /**
44807 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
44808 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
44809 ASSERTCMP(atomic_read(&op->usage), >, 0);
44810
44811 - fscache_stat(&fscache_n_op_enqueue);
44812 + fscache_stat_unchecked(&fscache_n_op_enqueue);
44813 switch (op->flags & FSCACHE_OP_TYPE) {
44814 case FSCACHE_OP_ASYNC:
44815 _debug("queue async");
44816 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
44817 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
44818 if (op->processor)
44819 fscache_enqueue_operation(op);
44820 - fscache_stat(&fscache_n_op_run);
44821 + fscache_stat_unchecked(&fscache_n_op_run);
44822 }
44823
44824 /*
44825 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44826 if (object->n_ops > 1) {
44827 atomic_inc(&op->usage);
44828 list_add_tail(&op->pend_link, &object->pending_ops);
44829 - fscache_stat(&fscache_n_op_pend);
44830 + fscache_stat_unchecked(&fscache_n_op_pend);
44831 } else if (!list_empty(&object->pending_ops)) {
44832 atomic_inc(&op->usage);
44833 list_add_tail(&op->pend_link, &object->pending_ops);
44834 - fscache_stat(&fscache_n_op_pend);
44835 + fscache_stat_unchecked(&fscache_n_op_pend);
44836 fscache_start_operations(object);
44837 } else {
44838 ASSERTCMP(object->n_in_progress, ==, 0);
44839 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44840 object->n_exclusive++; /* reads and writes must wait */
44841 atomic_inc(&op->usage);
44842 list_add_tail(&op->pend_link, &object->pending_ops);
44843 - fscache_stat(&fscache_n_op_pend);
44844 + fscache_stat_unchecked(&fscache_n_op_pend);
44845 ret = 0;
44846 } else {
44847 /* not allowed to submit ops in any other state */
44848 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
44849 if (object->n_exclusive > 0) {
44850 atomic_inc(&op->usage);
44851 list_add_tail(&op->pend_link, &object->pending_ops);
44852 - fscache_stat(&fscache_n_op_pend);
44853 + fscache_stat_unchecked(&fscache_n_op_pend);
44854 } else if (!list_empty(&object->pending_ops)) {
44855 atomic_inc(&op->usage);
44856 list_add_tail(&op->pend_link, &object->pending_ops);
44857 - fscache_stat(&fscache_n_op_pend);
44858 + fscache_stat_unchecked(&fscache_n_op_pend);
44859 fscache_start_operations(object);
44860 } else {
44861 ASSERTCMP(object->n_exclusive, ==, 0);
44862 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
44863 object->n_ops++;
44864 atomic_inc(&op->usage);
44865 list_add_tail(&op->pend_link, &object->pending_ops);
44866 - fscache_stat(&fscache_n_op_pend);
44867 + fscache_stat_unchecked(&fscache_n_op_pend);
44868 ret = 0;
44869 } else if (object->state == FSCACHE_OBJECT_DYING ||
44870 object->state == FSCACHE_OBJECT_LC_DYING ||
44871 object->state == FSCACHE_OBJECT_WITHDRAWING) {
44872 - fscache_stat(&fscache_n_op_rejected);
44873 + fscache_stat_unchecked(&fscache_n_op_rejected);
44874 ret = -ENOBUFS;
44875 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
44876 fscache_report_unexpected_submission(object, op, ostate);
44877 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
44878
44879 ret = -EBUSY;
44880 if (!list_empty(&op->pend_link)) {
44881 - fscache_stat(&fscache_n_op_cancelled);
44882 + fscache_stat_unchecked(&fscache_n_op_cancelled);
44883 list_del_init(&op->pend_link);
44884 object->n_ops--;
44885 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
44886 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
44887 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
44888 BUG();
44889
44890 - fscache_stat(&fscache_n_op_release);
44891 + fscache_stat_unchecked(&fscache_n_op_release);
44892
44893 if (op->release) {
44894 op->release(op);
44895 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
44896 * lock, and defer it otherwise */
44897 if (!spin_trylock(&object->lock)) {
44898 _debug("defer put");
44899 - fscache_stat(&fscache_n_op_deferred_release);
44900 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
44901
44902 cache = object->cache;
44903 spin_lock(&cache->op_gc_list_lock);
44904 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
44905
44906 _debug("GC DEFERRED REL OBJ%x OP%x",
44907 object->debug_id, op->debug_id);
44908 - fscache_stat(&fscache_n_op_gc);
44909 + fscache_stat_unchecked(&fscache_n_op_gc);
44910
44911 ASSERTCMP(atomic_read(&op->usage), ==, 0);
44912
44913 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
44914 index 3f7a59b..cf196cc 100644
44915 --- a/fs/fscache/page.c
44916 +++ b/fs/fscache/page.c
44917 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44918 val = radix_tree_lookup(&cookie->stores, page->index);
44919 if (!val) {
44920 rcu_read_unlock();
44921 - fscache_stat(&fscache_n_store_vmscan_not_storing);
44922 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
44923 __fscache_uncache_page(cookie, page);
44924 return true;
44925 }
44926 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44927 spin_unlock(&cookie->stores_lock);
44928
44929 if (xpage) {
44930 - fscache_stat(&fscache_n_store_vmscan_cancelled);
44931 - fscache_stat(&fscache_n_store_radix_deletes);
44932 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
44933 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44934 ASSERTCMP(xpage, ==, page);
44935 } else {
44936 - fscache_stat(&fscache_n_store_vmscan_gone);
44937 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
44938 }
44939
44940 wake_up_bit(&cookie->flags, 0);
44941 @@ -107,7 +107,7 @@ page_busy:
44942 /* we might want to wait here, but that could deadlock the allocator as
44943 * the work threads writing to the cache may all end up sleeping
44944 * on memory allocation */
44945 - fscache_stat(&fscache_n_store_vmscan_busy);
44946 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
44947 return false;
44948 }
44949 EXPORT_SYMBOL(__fscache_maybe_release_page);
44950 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
44951 FSCACHE_COOKIE_STORING_TAG);
44952 if (!radix_tree_tag_get(&cookie->stores, page->index,
44953 FSCACHE_COOKIE_PENDING_TAG)) {
44954 - fscache_stat(&fscache_n_store_radix_deletes);
44955 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44956 xpage = radix_tree_delete(&cookie->stores, page->index);
44957 }
44958 spin_unlock(&cookie->stores_lock);
44959 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
44960
44961 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
44962
44963 - fscache_stat(&fscache_n_attr_changed_calls);
44964 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
44965
44966 if (fscache_object_is_active(object)) {
44967 fscache_stat(&fscache_n_cop_attr_changed);
44968 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44969
44970 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44971
44972 - fscache_stat(&fscache_n_attr_changed);
44973 + fscache_stat_unchecked(&fscache_n_attr_changed);
44974
44975 op = kzalloc(sizeof(*op), GFP_KERNEL);
44976 if (!op) {
44977 - fscache_stat(&fscache_n_attr_changed_nomem);
44978 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
44979 _leave(" = -ENOMEM");
44980 return -ENOMEM;
44981 }
44982 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44983 if (fscache_submit_exclusive_op(object, op) < 0)
44984 goto nobufs;
44985 spin_unlock(&cookie->lock);
44986 - fscache_stat(&fscache_n_attr_changed_ok);
44987 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
44988 fscache_put_operation(op);
44989 _leave(" = 0");
44990 return 0;
44991 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44992 nobufs:
44993 spin_unlock(&cookie->lock);
44994 kfree(op);
44995 - fscache_stat(&fscache_n_attr_changed_nobufs);
44996 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
44997 _leave(" = %d", -ENOBUFS);
44998 return -ENOBUFS;
44999 }
45000 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45001 /* allocate a retrieval operation and attempt to submit it */
45002 op = kzalloc(sizeof(*op), GFP_NOIO);
45003 if (!op) {
45004 - fscache_stat(&fscache_n_retrievals_nomem);
45005 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45006 return NULL;
45007 }
45008
45009 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45010 return 0;
45011 }
45012
45013 - fscache_stat(&fscache_n_retrievals_wait);
45014 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45015
45016 jif = jiffies;
45017 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45018 fscache_wait_bit_interruptible,
45019 TASK_INTERRUPTIBLE) != 0) {
45020 - fscache_stat(&fscache_n_retrievals_intr);
45021 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45022 _leave(" = -ERESTARTSYS");
45023 return -ERESTARTSYS;
45024 }
45025 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45026 */
45027 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45028 struct fscache_retrieval *op,
45029 - atomic_t *stat_op_waits,
45030 - atomic_t *stat_object_dead)
45031 + atomic_unchecked_t *stat_op_waits,
45032 + atomic_unchecked_t *stat_object_dead)
45033 {
45034 int ret;
45035
45036 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45037 goto check_if_dead;
45038
45039 _debug(">>> WT");
45040 - fscache_stat(stat_op_waits);
45041 + fscache_stat_unchecked(stat_op_waits);
45042 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45043 fscache_wait_bit_interruptible,
45044 TASK_INTERRUPTIBLE) < 0) {
45045 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45046
45047 check_if_dead:
45048 if (unlikely(fscache_object_is_dead(object))) {
45049 - fscache_stat(stat_object_dead);
45050 + fscache_stat_unchecked(stat_object_dead);
45051 return -ENOBUFS;
45052 }
45053 return 0;
45054 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45055
45056 _enter("%p,%p,,,", cookie, page);
45057
45058 - fscache_stat(&fscache_n_retrievals);
45059 + fscache_stat_unchecked(&fscache_n_retrievals);
45060
45061 if (hlist_empty(&cookie->backing_objects))
45062 goto nobufs;
45063 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45064 goto nobufs_unlock;
45065 spin_unlock(&cookie->lock);
45066
45067 - fscache_stat(&fscache_n_retrieval_ops);
45068 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45069
45070 /* pin the netfs read context in case we need to do the actual netfs
45071 * read because we've encountered a cache read failure */
45072 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45073
45074 error:
45075 if (ret == -ENOMEM)
45076 - fscache_stat(&fscache_n_retrievals_nomem);
45077 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45078 else if (ret == -ERESTARTSYS)
45079 - fscache_stat(&fscache_n_retrievals_intr);
45080 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45081 else if (ret == -ENODATA)
45082 - fscache_stat(&fscache_n_retrievals_nodata);
45083 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45084 else if (ret < 0)
45085 - fscache_stat(&fscache_n_retrievals_nobufs);
45086 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45087 else
45088 - fscache_stat(&fscache_n_retrievals_ok);
45089 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45090
45091 fscache_put_retrieval(op);
45092 _leave(" = %d", ret);
45093 @@ -429,7 +429,7 @@ nobufs_unlock:
45094 spin_unlock(&cookie->lock);
45095 kfree(op);
45096 nobufs:
45097 - fscache_stat(&fscache_n_retrievals_nobufs);
45098 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45099 _leave(" = -ENOBUFS");
45100 return -ENOBUFS;
45101 }
45102 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45103
45104 _enter("%p,,%d,,,", cookie, *nr_pages);
45105
45106 - fscache_stat(&fscache_n_retrievals);
45107 + fscache_stat_unchecked(&fscache_n_retrievals);
45108
45109 if (hlist_empty(&cookie->backing_objects))
45110 goto nobufs;
45111 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45112 goto nobufs_unlock;
45113 spin_unlock(&cookie->lock);
45114
45115 - fscache_stat(&fscache_n_retrieval_ops);
45116 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45117
45118 /* pin the netfs read context in case we need to do the actual netfs
45119 * read because we've encountered a cache read failure */
45120 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45121
45122 error:
45123 if (ret == -ENOMEM)
45124 - fscache_stat(&fscache_n_retrievals_nomem);
45125 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45126 else if (ret == -ERESTARTSYS)
45127 - fscache_stat(&fscache_n_retrievals_intr);
45128 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45129 else if (ret == -ENODATA)
45130 - fscache_stat(&fscache_n_retrievals_nodata);
45131 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45132 else if (ret < 0)
45133 - fscache_stat(&fscache_n_retrievals_nobufs);
45134 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45135 else
45136 - fscache_stat(&fscache_n_retrievals_ok);
45137 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45138
45139 fscache_put_retrieval(op);
45140 _leave(" = %d", ret);
45141 @@ -545,7 +545,7 @@ nobufs_unlock:
45142 spin_unlock(&cookie->lock);
45143 kfree(op);
45144 nobufs:
45145 - fscache_stat(&fscache_n_retrievals_nobufs);
45146 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45147 _leave(" = -ENOBUFS");
45148 return -ENOBUFS;
45149 }
45150 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45151
45152 _enter("%p,%p,,,", cookie, page);
45153
45154 - fscache_stat(&fscache_n_allocs);
45155 + fscache_stat_unchecked(&fscache_n_allocs);
45156
45157 if (hlist_empty(&cookie->backing_objects))
45158 goto nobufs;
45159 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45160 goto nobufs_unlock;
45161 spin_unlock(&cookie->lock);
45162
45163 - fscache_stat(&fscache_n_alloc_ops);
45164 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45165
45166 ret = fscache_wait_for_retrieval_activation(
45167 object, op,
45168 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45169
45170 error:
45171 if (ret == -ERESTARTSYS)
45172 - fscache_stat(&fscache_n_allocs_intr);
45173 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45174 else if (ret < 0)
45175 - fscache_stat(&fscache_n_allocs_nobufs);
45176 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45177 else
45178 - fscache_stat(&fscache_n_allocs_ok);
45179 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45180
45181 fscache_put_retrieval(op);
45182 _leave(" = %d", ret);
45183 @@ -625,7 +625,7 @@ nobufs_unlock:
45184 spin_unlock(&cookie->lock);
45185 kfree(op);
45186 nobufs:
45187 - fscache_stat(&fscache_n_allocs_nobufs);
45188 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45189 _leave(" = -ENOBUFS");
45190 return -ENOBUFS;
45191 }
45192 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45193
45194 spin_lock(&cookie->stores_lock);
45195
45196 - fscache_stat(&fscache_n_store_calls);
45197 + fscache_stat_unchecked(&fscache_n_store_calls);
45198
45199 /* find a page to store */
45200 page = NULL;
45201 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45202 page = results[0];
45203 _debug("gang %d [%lx]", n, page->index);
45204 if (page->index > op->store_limit) {
45205 - fscache_stat(&fscache_n_store_pages_over_limit);
45206 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45207 goto superseded;
45208 }
45209
45210 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45211 spin_unlock(&cookie->stores_lock);
45212 spin_unlock(&object->lock);
45213
45214 - fscache_stat(&fscache_n_store_pages);
45215 + fscache_stat_unchecked(&fscache_n_store_pages);
45216 fscache_stat(&fscache_n_cop_write_page);
45217 ret = object->cache->ops->write_page(op, page);
45218 fscache_stat_d(&fscache_n_cop_write_page);
45219 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45220 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45221 ASSERT(PageFsCache(page));
45222
45223 - fscache_stat(&fscache_n_stores);
45224 + fscache_stat_unchecked(&fscache_n_stores);
45225
45226 op = kzalloc(sizeof(*op), GFP_NOIO);
45227 if (!op)
45228 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45229 spin_unlock(&cookie->stores_lock);
45230 spin_unlock(&object->lock);
45231
45232 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45233 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45234 op->store_limit = object->store_limit;
45235
45236 if (fscache_submit_op(object, &op->op) < 0)
45237 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45238
45239 spin_unlock(&cookie->lock);
45240 radix_tree_preload_end();
45241 - fscache_stat(&fscache_n_store_ops);
45242 - fscache_stat(&fscache_n_stores_ok);
45243 + fscache_stat_unchecked(&fscache_n_store_ops);
45244 + fscache_stat_unchecked(&fscache_n_stores_ok);
45245
45246 /* the work queue now carries its own ref on the object */
45247 fscache_put_operation(&op->op);
45248 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45249 return 0;
45250
45251 already_queued:
45252 - fscache_stat(&fscache_n_stores_again);
45253 + fscache_stat_unchecked(&fscache_n_stores_again);
45254 already_pending:
45255 spin_unlock(&cookie->stores_lock);
45256 spin_unlock(&object->lock);
45257 spin_unlock(&cookie->lock);
45258 radix_tree_preload_end();
45259 kfree(op);
45260 - fscache_stat(&fscache_n_stores_ok);
45261 + fscache_stat_unchecked(&fscache_n_stores_ok);
45262 _leave(" = 0");
45263 return 0;
45264
45265 @@ -851,14 +851,14 @@ nobufs:
45266 spin_unlock(&cookie->lock);
45267 radix_tree_preload_end();
45268 kfree(op);
45269 - fscache_stat(&fscache_n_stores_nobufs);
45270 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
45271 _leave(" = -ENOBUFS");
45272 return -ENOBUFS;
45273
45274 nomem_free:
45275 kfree(op);
45276 nomem:
45277 - fscache_stat(&fscache_n_stores_oom);
45278 + fscache_stat_unchecked(&fscache_n_stores_oom);
45279 _leave(" = -ENOMEM");
45280 return -ENOMEM;
45281 }
45282 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45283 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45284 ASSERTCMP(page, !=, NULL);
45285
45286 - fscache_stat(&fscache_n_uncaches);
45287 + fscache_stat_unchecked(&fscache_n_uncaches);
45288
45289 /* cache withdrawal may beat us to it */
45290 if (!PageFsCache(page))
45291 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45292 unsigned long loop;
45293
45294 #ifdef CONFIG_FSCACHE_STATS
45295 - atomic_add(pagevec->nr, &fscache_n_marks);
45296 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45297 #endif
45298
45299 for (loop = 0; loop < pagevec->nr; loop++) {
45300 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45301 index 4765190..2a067f2 100644
45302 --- a/fs/fscache/stats.c
45303 +++ b/fs/fscache/stats.c
45304 @@ -18,95 +18,95 @@
45305 /*
45306 * operation counters
45307 */
45308 -atomic_t fscache_n_op_pend;
45309 -atomic_t fscache_n_op_run;
45310 -atomic_t fscache_n_op_enqueue;
45311 -atomic_t fscache_n_op_requeue;
45312 -atomic_t fscache_n_op_deferred_release;
45313 -atomic_t fscache_n_op_release;
45314 -atomic_t fscache_n_op_gc;
45315 -atomic_t fscache_n_op_cancelled;
45316 -atomic_t fscache_n_op_rejected;
45317 +atomic_unchecked_t fscache_n_op_pend;
45318 +atomic_unchecked_t fscache_n_op_run;
45319 +atomic_unchecked_t fscache_n_op_enqueue;
45320 +atomic_unchecked_t fscache_n_op_requeue;
45321 +atomic_unchecked_t fscache_n_op_deferred_release;
45322 +atomic_unchecked_t fscache_n_op_release;
45323 +atomic_unchecked_t fscache_n_op_gc;
45324 +atomic_unchecked_t fscache_n_op_cancelled;
45325 +atomic_unchecked_t fscache_n_op_rejected;
45326
45327 -atomic_t fscache_n_attr_changed;
45328 -atomic_t fscache_n_attr_changed_ok;
45329 -atomic_t fscache_n_attr_changed_nobufs;
45330 -atomic_t fscache_n_attr_changed_nomem;
45331 -atomic_t fscache_n_attr_changed_calls;
45332 +atomic_unchecked_t fscache_n_attr_changed;
45333 +atomic_unchecked_t fscache_n_attr_changed_ok;
45334 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
45335 +atomic_unchecked_t fscache_n_attr_changed_nomem;
45336 +atomic_unchecked_t fscache_n_attr_changed_calls;
45337
45338 -atomic_t fscache_n_allocs;
45339 -atomic_t fscache_n_allocs_ok;
45340 -atomic_t fscache_n_allocs_wait;
45341 -atomic_t fscache_n_allocs_nobufs;
45342 -atomic_t fscache_n_allocs_intr;
45343 -atomic_t fscache_n_allocs_object_dead;
45344 -atomic_t fscache_n_alloc_ops;
45345 -atomic_t fscache_n_alloc_op_waits;
45346 +atomic_unchecked_t fscache_n_allocs;
45347 +atomic_unchecked_t fscache_n_allocs_ok;
45348 +atomic_unchecked_t fscache_n_allocs_wait;
45349 +atomic_unchecked_t fscache_n_allocs_nobufs;
45350 +atomic_unchecked_t fscache_n_allocs_intr;
45351 +atomic_unchecked_t fscache_n_allocs_object_dead;
45352 +atomic_unchecked_t fscache_n_alloc_ops;
45353 +atomic_unchecked_t fscache_n_alloc_op_waits;
45354
45355 -atomic_t fscache_n_retrievals;
45356 -atomic_t fscache_n_retrievals_ok;
45357 -atomic_t fscache_n_retrievals_wait;
45358 -atomic_t fscache_n_retrievals_nodata;
45359 -atomic_t fscache_n_retrievals_nobufs;
45360 -atomic_t fscache_n_retrievals_intr;
45361 -atomic_t fscache_n_retrievals_nomem;
45362 -atomic_t fscache_n_retrievals_object_dead;
45363 -atomic_t fscache_n_retrieval_ops;
45364 -atomic_t fscache_n_retrieval_op_waits;
45365 +atomic_unchecked_t fscache_n_retrievals;
45366 +atomic_unchecked_t fscache_n_retrievals_ok;
45367 +atomic_unchecked_t fscache_n_retrievals_wait;
45368 +atomic_unchecked_t fscache_n_retrievals_nodata;
45369 +atomic_unchecked_t fscache_n_retrievals_nobufs;
45370 +atomic_unchecked_t fscache_n_retrievals_intr;
45371 +atomic_unchecked_t fscache_n_retrievals_nomem;
45372 +atomic_unchecked_t fscache_n_retrievals_object_dead;
45373 +atomic_unchecked_t fscache_n_retrieval_ops;
45374 +atomic_unchecked_t fscache_n_retrieval_op_waits;
45375
45376 -atomic_t fscache_n_stores;
45377 -atomic_t fscache_n_stores_ok;
45378 -atomic_t fscache_n_stores_again;
45379 -atomic_t fscache_n_stores_nobufs;
45380 -atomic_t fscache_n_stores_oom;
45381 -atomic_t fscache_n_store_ops;
45382 -atomic_t fscache_n_store_calls;
45383 -atomic_t fscache_n_store_pages;
45384 -atomic_t fscache_n_store_radix_deletes;
45385 -atomic_t fscache_n_store_pages_over_limit;
45386 +atomic_unchecked_t fscache_n_stores;
45387 +atomic_unchecked_t fscache_n_stores_ok;
45388 +atomic_unchecked_t fscache_n_stores_again;
45389 +atomic_unchecked_t fscache_n_stores_nobufs;
45390 +atomic_unchecked_t fscache_n_stores_oom;
45391 +atomic_unchecked_t fscache_n_store_ops;
45392 +atomic_unchecked_t fscache_n_store_calls;
45393 +atomic_unchecked_t fscache_n_store_pages;
45394 +atomic_unchecked_t fscache_n_store_radix_deletes;
45395 +atomic_unchecked_t fscache_n_store_pages_over_limit;
45396
45397 -atomic_t fscache_n_store_vmscan_not_storing;
45398 -atomic_t fscache_n_store_vmscan_gone;
45399 -atomic_t fscache_n_store_vmscan_busy;
45400 -atomic_t fscache_n_store_vmscan_cancelled;
45401 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45402 +atomic_unchecked_t fscache_n_store_vmscan_gone;
45403 +atomic_unchecked_t fscache_n_store_vmscan_busy;
45404 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45405
45406 -atomic_t fscache_n_marks;
45407 -atomic_t fscache_n_uncaches;
45408 +atomic_unchecked_t fscache_n_marks;
45409 +atomic_unchecked_t fscache_n_uncaches;
45410
45411 -atomic_t fscache_n_acquires;
45412 -atomic_t fscache_n_acquires_null;
45413 -atomic_t fscache_n_acquires_no_cache;
45414 -atomic_t fscache_n_acquires_ok;
45415 -atomic_t fscache_n_acquires_nobufs;
45416 -atomic_t fscache_n_acquires_oom;
45417 +atomic_unchecked_t fscache_n_acquires;
45418 +atomic_unchecked_t fscache_n_acquires_null;
45419 +atomic_unchecked_t fscache_n_acquires_no_cache;
45420 +atomic_unchecked_t fscache_n_acquires_ok;
45421 +atomic_unchecked_t fscache_n_acquires_nobufs;
45422 +atomic_unchecked_t fscache_n_acquires_oom;
45423
45424 -atomic_t fscache_n_updates;
45425 -atomic_t fscache_n_updates_null;
45426 -atomic_t fscache_n_updates_run;
45427 +atomic_unchecked_t fscache_n_updates;
45428 +atomic_unchecked_t fscache_n_updates_null;
45429 +atomic_unchecked_t fscache_n_updates_run;
45430
45431 -atomic_t fscache_n_relinquishes;
45432 -atomic_t fscache_n_relinquishes_null;
45433 -atomic_t fscache_n_relinquishes_waitcrt;
45434 -atomic_t fscache_n_relinquishes_retire;
45435 +atomic_unchecked_t fscache_n_relinquishes;
45436 +atomic_unchecked_t fscache_n_relinquishes_null;
45437 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45438 +atomic_unchecked_t fscache_n_relinquishes_retire;
45439
45440 -atomic_t fscache_n_cookie_index;
45441 -atomic_t fscache_n_cookie_data;
45442 -atomic_t fscache_n_cookie_special;
45443 +atomic_unchecked_t fscache_n_cookie_index;
45444 +atomic_unchecked_t fscache_n_cookie_data;
45445 +atomic_unchecked_t fscache_n_cookie_special;
45446
45447 -atomic_t fscache_n_object_alloc;
45448 -atomic_t fscache_n_object_no_alloc;
45449 -atomic_t fscache_n_object_lookups;
45450 -atomic_t fscache_n_object_lookups_negative;
45451 -atomic_t fscache_n_object_lookups_positive;
45452 -atomic_t fscache_n_object_lookups_timed_out;
45453 -atomic_t fscache_n_object_created;
45454 -atomic_t fscache_n_object_avail;
45455 -atomic_t fscache_n_object_dead;
45456 +atomic_unchecked_t fscache_n_object_alloc;
45457 +atomic_unchecked_t fscache_n_object_no_alloc;
45458 +atomic_unchecked_t fscache_n_object_lookups;
45459 +atomic_unchecked_t fscache_n_object_lookups_negative;
45460 +atomic_unchecked_t fscache_n_object_lookups_positive;
45461 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
45462 +atomic_unchecked_t fscache_n_object_created;
45463 +atomic_unchecked_t fscache_n_object_avail;
45464 +atomic_unchecked_t fscache_n_object_dead;
45465
45466 -atomic_t fscache_n_checkaux_none;
45467 -atomic_t fscache_n_checkaux_okay;
45468 -atomic_t fscache_n_checkaux_update;
45469 -atomic_t fscache_n_checkaux_obsolete;
45470 +atomic_unchecked_t fscache_n_checkaux_none;
45471 +atomic_unchecked_t fscache_n_checkaux_okay;
45472 +atomic_unchecked_t fscache_n_checkaux_update;
45473 +atomic_unchecked_t fscache_n_checkaux_obsolete;
45474
45475 atomic_t fscache_n_cop_alloc_object;
45476 atomic_t fscache_n_cop_lookup_object;
45477 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45478 seq_puts(m, "FS-Cache statistics\n");
45479
45480 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45481 - atomic_read(&fscache_n_cookie_index),
45482 - atomic_read(&fscache_n_cookie_data),
45483 - atomic_read(&fscache_n_cookie_special));
45484 + atomic_read_unchecked(&fscache_n_cookie_index),
45485 + atomic_read_unchecked(&fscache_n_cookie_data),
45486 + atomic_read_unchecked(&fscache_n_cookie_special));
45487
45488 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45489 - atomic_read(&fscache_n_object_alloc),
45490 - atomic_read(&fscache_n_object_no_alloc),
45491 - atomic_read(&fscache_n_object_avail),
45492 - atomic_read(&fscache_n_object_dead));
45493 + atomic_read_unchecked(&fscache_n_object_alloc),
45494 + atomic_read_unchecked(&fscache_n_object_no_alloc),
45495 + atomic_read_unchecked(&fscache_n_object_avail),
45496 + atomic_read_unchecked(&fscache_n_object_dead));
45497 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45498 - atomic_read(&fscache_n_checkaux_none),
45499 - atomic_read(&fscache_n_checkaux_okay),
45500 - atomic_read(&fscache_n_checkaux_update),
45501 - atomic_read(&fscache_n_checkaux_obsolete));
45502 + atomic_read_unchecked(&fscache_n_checkaux_none),
45503 + atomic_read_unchecked(&fscache_n_checkaux_okay),
45504 + atomic_read_unchecked(&fscache_n_checkaux_update),
45505 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45506
45507 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45508 - atomic_read(&fscache_n_marks),
45509 - atomic_read(&fscache_n_uncaches));
45510 + atomic_read_unchecked(&fscache_n_marks),
45511 + atomic_read_unchecked(&fscache_n_uncaches));
45512
45513 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45514 " oom=%u\n",
45515 - atomic_read(&fscache_n_acquires),
45516 - atomic_read(&fscache_n_acquires_null),
45517 - atomic_read(&fscache_n_acquires_no_cache),
45518 - atomic_read(&fscache_n_acquires_ok),
45519 - atomic_read(&fscache_n_acquires_nobufs),
45520 - atomic_read(&fscache_n_acquires_oom));
45521 + atomic_read_unchecked(&fscache_n_acquires),
45522 + atomic_read_unchecked(&fscache_n_acquires_null),
45523 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
45524 + atomic_read_unchecked(&fscache_n_acquires_ok),
45525 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
45526 + atomic_read_unchecked(&fscache_n_acquires_oom));
45527
45528 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45529 - atomic_read(&fscache_n_object_lookups),
45530 - atomic_read(&fscache_n_object_lookups_negative),
45531 - atomic_read(&fscache_n_object_lookups_positive),
45532 - atomic_read(&fscache_n_object_created),
45533 - atomic_read(&fscache_n_object_lookups_timed_out));
45534 + atomic_read_unchecked(&fscache_n_object_lookups),
45535 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
45536 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
45537 + atomic_read_unchecked(&fscache_n_object_created),
45538 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45539
45540 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45541 - atomic_read(&fscache_n_updates),
45542 - atomic_read(&fscache_n_updates_null),
45543 - atomic_read(&fscache_n_updates_run));
45544 + atomic_read_unchecked(&fscache_n_updates),
45545 + atomic_read_unchecked(&fscache_n_updates_null),
45546 + atomic_read_unchecked(&fscache_n_updates_run));
45547
45548 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45549 - atomic_read(&fscache_n_relinquishes),
45550 - atomic_read(&fscache_n_relinquishes_null),
45551 - atomic_read(&fscache_n_relinquishes_waitcrt),
45552 - atomic_read(&fscache_n_relinquishes_retire));
45553 + atomic_read_unchecked(&fscache_n_relinquishes),
45554 + atomic_read_unchecked(&fscache_n_relinquishes_null),
45555 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45556 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
45557
45558 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45559 - atomic_read(&fscache_n_attr_changed),
45560 - atomic_read(&fscache_n_attr_changed_ok),
45561 - atomic_read(&fscache_n_attr_changed_nobufs),
45562 - atomic_read(&fscache_n_attr_changed_nomem),
45563 - atomic_read(&fscache_n_attr_changed_calls));
45564 + atomic_read_unchecked(&fscache_n_attr_changed),
45565 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
45566 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45567 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45568 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
45569
45570 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45571 - atomic_read(&fscache_n_allocs),
45572 - atomic_read(&fscache_n_allocs_ok),
45573 - atomic_read(&fscache_n_allocs_wait),
45574 - atomic_read(&fscache_n_allocs_nobufs),
45575 - atomic_read(&fscache_n_allocs_intr));
45576 + atomic_read_unchecked(&fscache_n_allocs),
45577 + atomic_read_unchecked(&fscache_n_allocs_ok),
45578 + atomic_read_unchecked(&fscache_n_allocs_wait),
45579 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
45580 + atomic_read_unchecked(&fscache_n_allocs_intr));
45581 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45582 - atomic_read(&fscache_n_alloc_ops),
45583 - atomic_read(&fscache_n_alloc_op_waits),
45584 - atomic_read(&fscache_n_allocs_object_dead));
45585 + atomic_read_unchecked(&fscache_n_alloc_ops),
45586 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
45587 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
45588
45589 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45590 " int=%u oom=%u\n",
45591 - atomic_read(&fscache_n_retrievals),
45592 - atomic_read(&fscache_n_retrievals_ok),
45593 - atomic_read(&fscache_n_retrievals_wait),
45594 - atomic_read(&fscache_n_retrievals_nodata),
45595 - atomic_read(&fscache_n_retrievals_nobufs),
45596 - atomic_read(&fscache_n_retrievals_intr),
45597 - atomic_read(&fscache_n_retrievals_nomem));
45598 + atomic_read_unchecked(&fscache_n_retrievals),
45599 + atomic_read_unchecked(&fscache_n_retrievals_ok),
45600 + atomic_read_unchecked(&fscache_n_retrievals_wait),
45601 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
45602 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45603 + atomic_read_unchecked(&fscache_n_retrievals_intr),
45604 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
45605 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45606 - atomic_read(&fscache_n_retrieval_ops),
45607 - atomic_read(&fscache_n_retrieval_op_waits),
45608 - atomic_read(&fscache_n_retrievals_object_dead));
45609 + atomic_read_unchecked(&fscache_n_retrieval_ops),
45610 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45611 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45612
45613 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45614 - atomic_read(&fscache_n_stores),
45615 - atomic_read(&fscache_n_stores_ok),
45616 - atomic_read(&fscache_n_stores_again),
45617 - atomic_read(&fscache_n_stores_nobufs),
45618 - atomic_read(&fscache_n_stores_oom));
45619 + atomic_read_unchecked(&fscache_n_stores),
45620 + atomic_read_unchecked(&fscache_n_stores_ok),
45621 + atomic_read_unchecked(&fscache_n_stores_again),
45622 + atomic_read_unchecked(&fscache_n_stores_nobufs),
45623 + atomic_read_unchecked(&fscache_n_stores_oom));
45624 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45625 - atomic_read(&fscache_n_store_ops),
45626 - atomic_read(&fscache_n_store_calls),
45627 - atomic_read(&fscache_n_store_pages),
45628 - atomic_read(&fscache_n_store_radix_deletes),
45629 - atomic_read(&fscache_n_store_pages_over_limit));
45630 + atomic_read_unchecked(&fscache_n_store_ops),
45631 + atomic_read_unchecked(&fscache_n_store_calls),
45632 + atomic_read_unchecked(&fscache_n_store_pages),
45633 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
45634 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
45635
45636 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
45637 - atomic_read(&fscache_n_store_vmscan_not_storing),
45638 - atomic_read(&fscache_n_store_vmscan_gone),
45639 - atomic_read(&fscache_n_store_vmscan_busy),
45640 - atomic_read(&fscache_n_store_vmscan_cancelled));
45641 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
45642 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
45643 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
45644 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
45645
45646 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
45647 - atomic_read(&fscache_n_op_pend),
45648 - atomic_read(&fscache_n_op_run),
45649 - atomic_read(&fscache_n_op_enqueue),
45650 - atomic_read(&fscache_n_op_cancelled),
45651 - atomic_read(&fscache_n_op_rejected));
45652 + atomic_read_unchecked(&fscache_n_op_pend),
45653 + atomic_read_unchecked(&fscache_n_op_run),
45654 + atomic_read_unchecked(&fscache_n_op_enqueue),
45655 + atomic_read_unchecked(&fscache_n_op_cancelled),
45656 + atomic_read_unchecked(&fscache_n_op_rejected));
45657 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
45658 - atomic_read(&fscache_n_op_deferred_release),
45659 - atomic_read(&fscache_n_op_release),
45660 - atomic_read(&fscache_n_op_gc));
45661 + atomic_read_unchecked(&fscache_n_op_deferred_release),
45662 + atomic_read_unchecked(&fscache_n_op_release),
45663 + atomic_read_unchecked(&fscache_n_op_gc));
45664
45665 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
45666 atomic_read(&fscache_n_cop_alloc_object),
45667 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
45668 index 3426521..3b75162 100644
45669 --- a/fs/fuse/cuse.c
45670 +++ b/fs/fuse/cuse.c
45671 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
45672 INIT_LIST_HEAD(&cuse_conntbl[i]);
45673
45674 /* inherit and extend fuse_dev_operations */
45675 - cuse_channel_fops = fuse_dev_operations;
45676 - cuse_channel_fops.owner = THIS_MODULE;
45677 - cuse_channel_fops.open = cuse_channel_open;
45678 - cuse_channel_fops.release = cuse_channel_release;
45679 + pax_open_kernel();
45680 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
45681 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
45682 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
45683 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
45684 + pax_close_kernel();
45685
45686 cuse_class = class_create(THIS_MODULE, "cuse");
45687 if (IS_ERR(cuse_class))
45688 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
45689 index 2aaf3ea..8e50863 100644
45690 --- a/fs/fuse/dev.c
45691 +++ b/fs/fuse/dev.c
45692 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
45693 ret = 0;
45694 pipe_lock(pipe);
45695
45696 - if (!pipe->readers) {
45697 + if (!atomic_read(&pipe->readers)) {
45698 send_sig(SIGPIPE, current, 0);
45699 if (!ret)
45700 ret = -EPIPE;
45701 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
45702 index 9f63e49..d8a64c0 100644
45703 --- a/fs/fuse/dir.c
45704 +++ b/fs/fuse/dir.c
45705 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
45706 return link;
45707 }
45708
45709 -static void free_link(char *link)
45710 +static void free_link(const char *link)
45711 {
45712 if (!IS_ERR(link))
45713 free_page((unsigned long) link);
45714 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
45715 index cfd4959..a780959 100644
45716 --- a/fs/gfs2/inode.c
45717 +++ b/fs/gfs2/inode.c
45718 @@ -1490,7 +1490,7 @@ out:
45719
45720 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45721 {
45722 - char *s = nd_get_link(nd);
45723 + const char *s = nd_get_link(nd);
45724 if (!IS_ERR(s))
45725 kfree(s);
45726 }
45727 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
45728 index 0be5a78..9cfb853 100644
45729 --- a/fs/hugetlbfs/inode.c
45730 +++ b/fs/hugetlbfs/inode.c
45731 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
45732 .kill_sb = kill_litter_super,
45733 };
45734
45735 -static struct vfsmount *hugetlbfs_vfsmount;
45736 +struct vfsmount *hugetlbfs_vfsmount;
45737
45738 static int can_do_hugetlb_shm(void)
45739 {
45740 diff --git a/fs/inode.c b/fs/inode.c
45741 index ee4e66b..0451521 100644
45742 --- a/fs/inode.c
45743 +++ b/fs/inode.c
45744 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
45745
45746 #ifdef CONFIG_SMP
45747 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
45748 - static atomic_t shared_last_ino;
45749 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
45750 + static atomic_unchecked_t shared_last_ino;
45751 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
45752
45753 res = next - LAST_INO_BATCH;
45754 }
45755 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
45756 index e513f19..2ab1351 100644
45757 --- a/fs/jffs2/erase.c
45758 +++ b/fs/jffs2/erase.c
45759 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
45760 struct jffs2_unknown_node marker = {
45761 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
45762 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45763 - .totlen = cpu_to_je32(c->cleanmarker_size)
45764 + .totlen = cpu_to_je32(c->cleanmarker_size),
45765 + .hdr_crc = cpu_to_je32(0)
45766 };
45767
45768 jffs2_prealloc_raw_node_refs(c, jeb, 1);
45769 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
45770 index b09e51d..e482afa 100644
45771 --- a/fs/jffs2/wbuf.c
45772 +++ b/fs/jffs2/wbuf.c
45773 @@ -1011,7 +1011,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
45774 {
45775 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
45776 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45777 - .totlen = constant_cpu_to_je32(8)
45778 + .totlen = constant_cpu_to_je32(8),
45779 + .hdr_crc = constant_cpu_to_je32(0)
45780 };
45781
45782 /*
45783 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
45784 index a44eff0..462e07d 100644
45785 --- a/fs/jfs/super.c
45786 +++ b/fs/jfs/super.c
45787 @@ -802,7 +802,7 @@ static int __init init_jfs_fs(void)
45788
45789 jfs_inode_cachep =
45790 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
45791 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
45792 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
45793 init_once);
45794 if (jfs_inode_cachep == NULL)
45795 return -ENOMEM;
45796 diff --git a/fs/libfs.c b/fs/libfs.c
45797 index f6d411e..e82a08d 100644
45798 --- a/fs/libfs.c
45799 +++ b/fs/libfs.c
45800 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45801
45802 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
45803 struct dentry *next;
45804 + char d_name[sizeof(next->d_iname)];
45805 + const unsigned char *name;
45806 +
45807 next = list_entry(p, struct dentry, d_u.d_child);
45808 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
45809 if (!simple_positive(next)) {
45810 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45811
45812 spin_unlock(&next->d_lock);
45813 spin_unlock(&dentry->d_lock);
45814 - if (filldir(dirent, next->d_name.name,
45815 + name = next->d_name.name;
45816 + if (name == next->d_iname) {
45817 + memcpy(d_name, name, next->d_name.len);
45818 + name = d_name;
45819 + }
45820 + if (filldir(dirent, name,
45821 next->d_name.len, filp->f_pos,
45822 next->d_inode->i_ino,
45823 dt_type(next->d_inode)) < 0)
45824 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
45825 index 8392cb8..80d6193 100644
45826 --- a/fs/lockd/clntproc.c
45827 +++ b/fs/lockd/clntproc.c
45828 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
45829 /*
45830 * Cookie counter for NLM requests
45831 */
45832 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
45833 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
45834
45835 void nlmclnt_next_cookie(struct nlm_cookie *c)
45836 {
45837 - u32 cookie = atomic_inc_return(&nlm_cookie);
45838 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
45839
45840 memcpy(c->data, &cookie, 4);
45841 c->len=4;
45842 diff --git a/fs/locks.c b/fs/locks.c
45843 index 637694b..f84a121 100644
45844 --- a/fs/locks.c
45845 +++ b/fs/locks.c
45846 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
45847 return;
45848
45849 if (filp->f_op && filp->f_op->flock) {
45850 - struct file_lock fl = {
45851 + struct file_lock flock = {
45852 .fl_pid = current->tgid,
45853 .fl_file = filp,
45854 .fl_flags = FL_FLOCK,
45855 .fl_type = F_UNLCK,
45856 .fl_end = OFFSET_MAX,
45857 };
45858 - filp->f_op->flock(filp, F_SETLKW, &fl);
45859 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
45860 - fl.fl_ops->fl_release_private(&fl);
45861 + filp->f_op->flock(filp, F_SETLKW, &flock);
45862 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
45863 + flock.fl_ops->fl_release_private(&flock);
45864 }
45865
45866 lock_flocks();
45867 diff --git a/fs/namei.c b/fs/namei.c
45868 index 744e942..24ef47f 100644
45869 --- a/fs/namei.c
45870 +++ b/fs/namei.c
45871 @@ -279,16 +279,32 @@ int generic_permission(struct inode *inode, int mask)
45872 if (ret != -EACCES)
45873 return ret;
45874
45875 +#ifdef CONFIG_GRKERNSEC
45876 + /* we'll block if we have to log due to a denied capability use */
45877 + if (mask & MAY_NOT_BLOCK)
45878 + return -ECHILD;
45879 +#endif
45880 +
45881 if (S_ISDIR(inode->i_mode)) {
45882 /* DACs are overridable for directories */
45883 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45884 - return 0;
45885 if (!(mask & MAY_WRITE))
45886 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45887 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45888 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45889 return 0;
45890 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45891 + return 0;
45892 return -EACCES;
45893 }
45894 /*
45895 + * Searching includes executable on directories, else just read.
45896 + */
45897 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45898 + if (mask == MAY_READ)
45899 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45900 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45901 + return 0;
45902 +
45903 + /*
45904 * Read/write DACs are always overridable.
45905 * Executable DACs are overridable when there is
45906 * at least one exec bit set.
45907 @@ -297,14 +313,6 @@ int generic_permission(struct inode *inode, int mask)
45908 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45909 return 0;
45910
45911 - /*
45912 - * Searching includes executable on directories, else just read.
45913 - */
45914 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45915 - if (mask == MAY_READ)
45916 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45917 - return 0;
45918 -
45919 return -EACCES;
45920 }
45921
45922 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
45923 return error;
45924 }
45925
45926 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
45927 + dentry->d_inode, dentry, nd->path.mnt)) {
45928 + error = -EACCES;
45929 + *p = ERR_PTR(error); /* no ->put_link(), please */
45930 + path_put(&nd->path);
45931 + return error;
45932 + }
45933 +
45934 nd->last_type = LAST_BIND;
45935 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
45936 error = PTR_ERR(*p);
45937 if (!IS_ERR(*p)) {
45938 - char *s = nd_get_link(nd);
45939 + const char *s = nd_get_link(nd);
45940 error = 0;
45941 if (s)
45942 error = __vfs_follow_link(nd, s);
45943 @@ -1624,6 +1640,21 @@ static int path_lookupat(int dfd, const char *name,
45944 if (!err)
45945 err = complete_walk(nd);
45946
45947 + if (!(nd->flags & LOOKUP_PARENT)) {
45948 +#ifdef CONFIG_GRKERNSEC
45949 + if (flags & LOOKUP_RCU) {
45950 + if (!err)
45951 + path_put(&nd->path);
45952 + err = -ECHILD;
45953 + } else
45954 +#endif
45955 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45956 + if (!err)
45957 + path_put(&nd->path);
45958 + err = -ENOENT;
45959 + }
45960 + }
45961 +
45962 if (!err && nd->flags & LOOKUP_DIRECTORY) {
45963 if (!nd->inode->i_op->lookup) {
45964 path_put(&nd->path);
45965 @@ -1651,6 +1682,15 @@ static int do_path_lookup(int dfd, const char *name,
45966 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
45967
45968 if (likely(!retval)) {
45969 + if (*name != '/' && nd->path.dentry && nd->inode) {
45970 +#ifdef CONFIG_GRKERNSEC
45971 + if (flags & LOOKUP_RCU)
45972 + return -ECHILD;
45973 +#endif
45974 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
45975 + return -ENOENT;
45976 + }
45977 +
45978 if (unlikely(!audit_dummy_context())) {
45979 if (nd->path.dentry && nd->inode)
45980 audit_inode(name, nd->path.dentry);
45981 @@ -2048,6 +2088,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
45982 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
45983 return -EPERM;
45984
45985 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
45986 + return -EPERM;
45987 + if (gr_handle_rawio(inode))
45988 + return -EPERM;
45989 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
45990 + return -EACCES;
45991 +
45992 return 0;
45993 }
45994
45995 @@ -2109,6 +2156,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45996 error = complete_walk(nd);
45997 if (error)
45998 return ERR_PTR(error);
45999 +#ifdef CONFIG_GRKERNSEC
46000 + if (nd->flags & LOOKUP_RCU) {
46001 + error = -ECHILD;
46002 + goto exit;
46003 + }
46004 +#endif
46005 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46006 + error = -ENOENT;
46007 + goto exit;
46008 + }
46009 audit_inode(pathname, nd->path.dentry);
46010 if (open_flag & O_CREAT) {
46011 error = -EISDIR;
46012 @@ -2119,6 +2176,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46013 error = complete_walk(nd);
46014 if (error)
46015 return ERR_PTR(error);
46016 +#ifdef CONFIG_GRKERNSEC
46017 + if (nd->flags & LOOKUP_RCU) {
46018 + error = -ECHILD;
46019 + goto exit;
46020 + }
46021 +#endif
46022 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46023 + error = -ENOENT;
46024 + goto exit;
46025 + }
46026 audit_inode(pathname, dir);
46027 goto ok;
46028 }
46029 @@ -2140,6 +2207,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46030 error = complete_walk(nd);
46031 if (error)
46032 return ERR_PTR(-ECHILD);
46033 +#ifdef CONFIG_GRKERNSEC
46034 + if (nd->flags & LOOKUP_RCU) {
46035 + error = -ECHILD;
46036 + goto exit;
46037 + }
46038 +#endif
46039 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46040 + error = -ENOENT;
46041 + goto exit;
46042 + }
46043
46044 error = -ENOTDIR;
46045 if (nd->flags & LOOKUP_DIRECTORY) {
46046 @@ -2180,6 +2257,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46047 /* Negative dentry, just create the file */
46048 if (!dentry->d_inode) {
46049 int mode = op->mode;
46050 +
46051 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46052 + error = -EACCES;
46053 + goto exit_mutex_unlock;
46054 + }
46055 +
46056 if (!IS_POSIXACL(dir->d_inode))
46057 mode &= ~current_umask();
46058 /*
46059 @@ -2203,6 +2286,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46060 error = vfs_create(dir->d_inode, dentry, mode, nd);
46061 if (error)
46062 goto exit_mutex_unlock;
46063 + else
46064 + gr_handle_create(path->dentry, path->mnt);
46065 mutex_unlock(&dir->d_inode->i_mutex);
46066 dput(nd->path.dentry);
46067 nd->path.dentry = dentry;
46068 @@ -2212,6 +2297,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46069 /*
46070 * It already exists.
46071 */
46072 +
46073 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46074 + error = -ENOENT;
46075 + goto exit_mutex_unlock;
46076 + }
46077 +
46078 + /* only check if O_CREAT is specified, all other checks need to go
46079 + into may_open */
46080 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46081 + error = -EACCES;
46082 + goto exit_mutex_unlock;
46083 + }
46084 +
46085 mutex_unlock(&dir->d_inode->i_mutex);
46086 audit_inode(pathname, path->dentry);
46087
46088 @@ -2424,6 +2522,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46089 *path = nd.path;
46090 return dentry;
46091 eexist:
46092 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46093 + dput(dentry);
46094 + dentry = ERR_PTR(-ENOENT);
46095 + goto fail;
46096 + }
46097 dput(dentry);
46098 dentry = ERR_PTR(-EEXIST);
46099 fail:
46100 @@ -2446,6 +2549,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46101 }
46102 EXPORT_SYMBOL(user_path_create);
46103
46104 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46105 +{
46106 + char *tmp = getname(pathname);
46107 + struct dentry *res;
46108 + if (IS_ERR(tmp))
46109 + return ERR_CAST(tmp);
46110 + res = kern_path_create(dfd, tmp, path, is_dir);
46111 + if (IS_ERR(res))
46112 + putname(tmp);
46113 + else
46114 + *to = tmp;
46115 + return res;
46116 +}
46117 +
46118 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
46119 {
46120 int error = may_create(dir, dentry);
46121 @@ -2513,6 +2630,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
46122 error = mnt_want_write(path.mnt);
46123 if (error)
46124 goto out_dput;
46125 +
46126 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46127 + error = -EPERM;
46128 + goto out_drop_write;
46129 + }
46130 +
46131 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46132 + error = -EACCES;
46133 + goto out_drop_write;
46134 + }
46135 +
46136 error = security_path_mknod(&path, dentry, mode, dev);
46137 if (error)
46138 goto out_drop_write;
46139 @@ -2530,6 +2658,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
46140 }
46141 out_drop_write:
46142 mnt_drop_write(path.mnt);
46143 +
46144 + if (!error)
46145 + gr_handle_create(dentry, path.mnt);
46146 out_dput:
46147 dput(dentry);
46148 mutex_unlock(&path.dentry->d_inode->i_mutex);
46149 @@ -2579,12 +2710,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
46150 error = mnt_want_write(path.mnt);
46151 if (error)
46152 goto out_dput;
46153 +
46154 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46155 + error = -EACCES;
46156 + goto out_drop_write;
46157 + }
46158 +
46159 error = security_path_mkdir(&path, dentry, mode);
46160 if (error)
46161 goto out_drop_write;
46162 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46163 out_drop_write:
46164 mnt_drop_write(path.mnt);
46165 +
46166 + if (!error)
46167 + gr_handle_create(dentry, path.mnt);
46168 out_dput:
46169 dput(dentry);
46170 mutex_unlock(&path.dentry->d_inode->i_mutex);
46171 @@ -2664,6 +2804,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46172 char * name;
46173 struct dentry *dentry;
46174 struct nameidata nd;
46175 + ino_t saved_ino = 0;
46176 + dev_t saved_dev = 0;
46177
46178 error = user_path_parent(dfd, pathname, &nd, &name);
46179 if (error)
46180 @@ -2692,6 +2834,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46181 error = -ENOENT;
46182 goto exit3;
46183 }
46184 +
46185 + saved_ino = dentry->d_inode->i_ino;
46186 + saved_dev = gr_get_dev_from_dentry(dentry);
46187 +
46188 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46189 + error = -EACCES;
46190 + goto exit3;
46191 + }
46192 +
46193 error = mnt_want_write(nd.path.mnt);
46194 if (error)
46195 goto exit3;
46196 @@ -2699,6 +2850,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46197 if (error)
46198 goto exit4;
46199 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46200 + if (!error && (saved_dev || saved_ino))
46201 + gr_handle_delete(saved_ino, saved_dev);
46202 exit4:
46203 mnt_drop_write(nd.path.mnt);
46204 exit3:
46205 @@ -2761,6 +2914,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46206 struct dentry *dentry;
46207 struct nameidata nd;
46208 struct inode *inode = NULL;
46209 + ino_t saved_ino = 0;
46210 + dev_t saved_dev = 0;
46211
46212 error = user_path_parent(dfd, pathname, &nd, &name);
46213 if (error)
46214 @@ -2783,6 +2938,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46215 if (!inode)
46216 goto slashes;
46217 ihold(inode);
46218 +
46219 + if (inode->i_nlink <= 1) {
46220 + saved_ino = inode->i_ino;
46221 + saved_dev = gr_get_dev_from_dentry(dentry);
46222 + }
46223 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46224 + error = -EACCES;
46225 + goto exit2;
46226 + }
46227 +
46228 error = mnt_want_write(nd.path.mnt);
46229 if (error)
46230 goto exit2;
46231 @@ -2790,6 +2955,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46232 if (error)
46233 goto exit3;
46234 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46235 + if (!error && (saved_ino || saved_dev))
46236 + gr_handle_delete(saved_ino, saved_dev);
46237 exit3:
46238 mnt_drop_write(nd.path.mnt);
46239 exit2:
46240 @@ -2865,10 +3032,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46241 error = mnt_want_write(path.mnt);
46242 if (error)
46243 goto out_dput;
46244 +
46245 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46246 + error = -EACCES;
46247 + goto out_drop_write;
46248 + }
46249 +
46250 error = security_path_symlink(&path, dentry, from);
46251 if (error)
46252 goto out_drop_write;
46253 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46254 + if (!error)
46255 + gr_handle_create(dentry, path.mnt);
46256 out_drop_write:
46257 mnt_drop_write(path.mnt);
46258 out_dput:
46259 @@ -2940,6 +3115,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46260 {
46261 struct dentry *new_dentry;
46262 struct path old_path, new_path;
46263 + char *to = NULL;
46264 int how = 0;
46265 int error;
46266
46267 @@ -2963,7 +3139,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46268 if (error)
46269 return error;
46270
46271 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
46272 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46273 error = PTR_ERR(new_dentry);
46274 if (IS_ERR(new_dentry))
46275 goto out;
46276 @@ -2974,13 +3150,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46277 error = mnt_want_write(new_path.mnt);
46278 if (error)
46279 goto out_dput;
46280 +
46281 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46282 + old_path.dentry->d_inode,
46283 + old_path.dentry->d_inode->i_mode, to)) {
46284 + error = -EACCES;
46285 + goto out_drop_write;
46286 + }
46287 +
46288 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46289 + old_path.dentry, old_path.mnt, to)) {
46290 + error = -EACCES;
46291 + goto out_drop_write;
46292 + }
46293 +
46294 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46295 if (error)
46296 goto out_drop_write;
46297 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46298 + if (!error)
46299 + gr_handle_create(new_dentry, new_path.mnt);
46300 out_drop_write:
46301 mnt_drop_write(new_path.mnt);
46302 out_dput:
46303 + putname(to);
46304 dput(new_dentry);
46305 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46306 path_put(&new_path);
46307 @@ -3208,6 +3401,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46308 if (new_dentry == trap)
46309 goto exit5;
46310
46311 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46312 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
46313 + to);
46314 + if (error)
46315 + goto exit5;
46316 +
46317 error = mnt_want_write(oldnd.path.mnt);
46318 if (error)
46319 goto exit5;
46320 @@ -3217,6 +3416,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46321 goto exit6;
46322 error = vfs_rename(old_dir->d_inode, old_dentry,
46323 new_dir->d_inode, new_dentry);
46324 + if (!error)
46325 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46326 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46327 exit6:
46328 mnt_drop_write(oldnd.path.mnt);
46329 exit5:
46330 @@ -3242,6 +3444,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46331
46332 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46333 {
46334 + char tmpbuf[64];
46335 + const char *newlink;
46336 int len;
46337
46338 len = PTR_ERR(link);
46339 @@ -3251,7 +3455,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46340 len = strlen(link);
46341 if (len > (unsigned) buflen)
46342 len = buflen;
46343 - if (copy_to_user(buffer, link, len))
46344 +
46345 + if (len < sizeof(tmpbuf)) {
46346 + memcpy(tmpbuf, link, len);
46347 + newlink = tmpbuf;
46348 + } else
46349 + newlink = link;
46350 +
46351 + if (copy_to_user(buffer, newlink, len))
46352 len = -EFAULT;
46353 out:
46354 return len;
46355 diff --git a/fs/namespace.c b/fs/namespace.c
46356 index cfc6d44..b4632a5 100644
46357 --- a/fs/namespace.c
46358 +++ b/fs/namespace.c
46359 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
46360 if (!(sb->s_flags & MS_RDONLY))
46361 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46362 up_write(&sb->s_umount);
46363 +
46364 + gr_log_remount(mnt->mnt_devname, retval);
46365 +
46366 return retval;
46367 }
46368
46369 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
46370 br_write_unlock(vfsmount_lock);
46371 up_write(&namespace_sem);
46372 release_mounts(&umount_list);
46373 +
46374 + gr_log_unmount(mnt->mnt_devname, retval);
46375 +
46376 return retval;
46377 }
46378
46379 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46380 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46381 MS_STRICTATIME);
46382
46383 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46384 + retval = -EPERM;
46385 + goto dput_out;
46386 + }
46387 +
46388 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46389 + retval = -EPERM;
46390 + goto dput_out;
46391 + }
46392 +
46393 if (flags & MS_REMOUNT)
46394 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46395 data_page);
46396 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46397 dev_name, data_page);
46398 dput_out:
46399 path_put(&path);
46400 +
46401 + gr_log_mount(dev_name, dir_name, retval);
46402 +
46403 return retval;
46404 }
46405
46406 @@ -2605,6 +2624,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46407 if (error)
46408 goto out2;
46409
46410 + if (gr_handle_chroot_pivot()) {
46411 + error = -EPERM;
46412 + goto out2;
46413 + }
46414 +
46415 get_fs_root(current->fs, &root);
46416 error = lock_mount(&old);
46417 if (error)
46418 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
46419 index 3db6b82..a57597e 100644
46420 --- a/fs/nfs/blocklayout/blocklayout.c
46421 +++ b/fs/nfs/blocklayout/blocklayout.c
46422 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
46423 */
46424 struct parallel_io {
46425 struct kref refcnt;
46426 - struct rpc_call_ops call_ops;
46427 + rpc_call_ops_no_const call_ops;
46428 void (*pnfs_callback) (void *data);
46429 void *data;
46430 };
46431 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46432 index 50a15fa..ca113f9 100644
46433 --- a/fs/nfs/inode.c
46434 +++ b/fs/nfs/inode.c
46435 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46436 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46437 nfsi->attrtimeo_timestamp = jiffies;
46438
46439 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46440 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46441 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46442 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46443 else
46444 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46445 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46446 }
46447
46448 -static atomic_long_t nfs_attr_generation_counter;
46449 +static atomic_long_unchecked_t nfs_attr_generation_counter;
46450
46451 static unsigned long nfs_read_attr_generation_counter(void)
46452 {
46453 - return atomic_long_read(&nfs_attr_generation_counter);
46454 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46455 }
46456
46457 unsigned long nfs_inc_attr_generation_counter(void)
46458 {
46459 - return atomic_long_inc_return(&nfs_attr_generation_counter);
46460 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46461 }
46462
46463 void nfs_fattr_init(struct nfs_fattr *fattr)
46464 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46465 index 7a2e442..8e544cc 100644
46466 --- a/fs/nfsd/vfs.c
46467 +++ b/fs/nfsd/vfs.c
46468 @@ -914,7 +914,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46469 } else {
46470 oldfs = get_fs();
46471 set_fs(KERNEL_DS);
46472 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46473 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46474 set_fs(oldfs);
46475 }
46476
46477 @@ -1018,7 +1018,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46478
46479 /* Write the data. */
46480 oldfs = get_fs(); set_fs(KERNEL_DS);
46481 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46482 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46483 set_fs(oldfs);
46484 if (host_err < 0)
46485 goto out_nfserr;
46486 @@ -1553,7 +1553,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46487 */
46488
46489 oldfs = get_fs(); set_fs(KERNEL_DS);
46490 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
46491 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
46492 set_fs(oldfs);
46493
46494 if (host_err < 0)
46495 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46496 index 9fde1c0..14e8827 100644
46497 --- a/fs/notify/fanotify/fanotify_user.c
46498 +++ b/fs/notify/fanotify/fanotify_user.c
46499 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46500 goto out_close_fd;
46501
46502 ret = -EFAULT;
46503 - if (copy_to_user(buf, &fanotify_event_metadata,
46504 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46505 + copy_to_user(buf, &fanotify_event_metadata,
46506 fanotify_event_metadata.event_len))
46507 goto out_kill_access_response;
46508
46509 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46510 index ee18815..7aa5d01 100644
46511 --- a/fs/notify/notification.c
46512 +++ b/fs/notify/notification.c
46513 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46514 * get set to 0 so it will never get 'freed'
46515 */
46516 static struct fsnotify_event *q_overflow_event;
46517 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46518 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46519
46520 /**
46521 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46522 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46523 */
46524 u32 fsnotify_get_cookie(void)
46525 {
46526 - return atomic_inc_return(&fsnotify_sync_cookie);
46527 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46528 }
46529 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46530
46531 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46532 index 99e3610..02c1068 100644
46533 --- a/fs/ntfs/dir.c
46534 +++ b/fs/ntfs/dir.c
46535 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
46536 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46537 ~(s64)(ndir->itype.index.block_size - 1)));
46538 /* Bounds checks. */
46539 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46540 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46541 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46542 "inode 0x%lx or driver bug.", vdir->i_ino);
46543 goto err_out;
46544 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46545 index c587e2d..3641eaa 100644
46546 --- a/fs/ntfs/file.c
46547 +++ b/fs/ntfs/file.c
46548 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46549 #endif /* NTFS_RW */
46550 };
46551
46552 -const struct file_operations ntfs_empty_file_ops = {};
46553 +const struct file_operations ntfs_empty_file_ops __read_only;
46554
46555 -const struct inode_operations ntfs_empty_inode_ops = {};
46556 +const struct inode_operations ntfs_empty_inode_ops __read_only;
46557 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46558 index 210c352..a174f83 100644
46559 --- a/fs/ocfs2/localalloc.c
46560 +++ b/fs/ocfs2/localalloc.c
46561 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46562 goto bail;
46563 }
46564
46565 - atomic_inc(&osb->alloc_stats.moves);
46566 + atomic_inc_unchecked(&osb->alloc_stats.moves);
46567
46568 bail:
46569 if (handle)
46570 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46571 index d355e6e..578d905 100644
46572 --- a/fs/ocfs2/ocfs2.h
46573 +++ b/fs/ocfs2/ocfs2.h
46574 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
46575
46576 struct ocfs2_alloc_stats
46577 {
46578 - atomic_t moves;
46579 - atomic_t local_data;
46580 - atomic_t bitmap_data;
46581 - atomic_t bg_allocs;
46582 - atomic_t bg_extends;
46583 + atomic_unchecked_t moves;
46584 + atomic_unchecked_t local_data;
46585 + atomic_unchecked_t bitmap_data;
46586 + atomic_unchecked_t bg_allocs;
46587 + atomic_unchecked_t bg_extends;
46588 };
46589
46590 enum ocfs2_local_alloc_state
46591 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46592 index ba5d97e..c77db25 100644
46593 --- a/fs/ocfs2/suballoc.c
46594 +++ b/fs/ocfs2/suballoc.c
46595 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46596 mlog_errno(status);
46597 goto bail;
46598 }
46599 - atomic_inc(&osb->alloc_stats.bg_extends);
46600 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46601
46602 /* You should never ask for this much metadata */
46603 BUG_ON(bits_wanted >
46604 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46605 mlog_errno(status);
46606 goto bail;
46607 }
46608 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46609 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46610
46611 *suballoc_loc = res.sr_bg_blkno;
46612 *suballoc_bit_start = res.sr_bit_offset;
46613 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
46614 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
46615 res->sr_bits);
46616
46617 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46618 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46619
46620 BUG_ON(res->sr_bits != 1);
46621
46622 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
46623 mlog_errno(status);
46624 goto bail;
46625 }
46626 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46627 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46628
46629 BUG_ON(res.sr_bits != 1);
46630
46631 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46632 cluster_start,
46633 num_clusters);
46634 if (!status)
46635 - atomic_inc(&osb->alloc_stats.local_data);
46636 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
46637 } else {
46638 if (min_clusters > (osb->bitmap_cpg - 1)) {
46639 /* The only paths asking for contiguousness
46640 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46641 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
46642 res.sr_bg_blkno,
46643 res.sr_bit_offset);
46644 - atomic_inc(&osb->alloc_stats.bitmap_data);
46645 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
46646 *num_clusters = res.sr_bits;
46647 }
46648 }
46649 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
46650 index 4994f8b..eaab8eb 100644
46651 --- a/fs/ocfs2/super.c
46652 +++ b/fs/ocfs2/super.c
46653 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
46654 "%10s => GlobalAllocs: %d LocalAllocs: %d "
46655 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
46656 "Stats",
46657 - atomic_read(&osb->alloc_stats.bitmap_data),
46658 - atomic_read(&osb->alloc_stats.local_data),
46659 - atomic_read(&osb->alloc_stats.bg_allocs),
46660 - atomic_read(&osb->alloc_stats.moves),
46661 - atomic_read(&osb->alloc_stats.bg_extends));
46662 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
46663 + atomic_read_unchecked(&osb->alloc_stats.local_data),
46664 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
46665 + atomic_read_unchecked(&osb->alloc_stats.moves),
46666 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
46667
46668 out += snprintf(buf + out, len - out,
46669 "%10s => State: %u Descriptor: %llu Size: %u bits "
46670 @@ -2119,11 +2119,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
46671 spin_lock_init(&osb->osb_xattr_lock);
46672 ocfs2_init_steal_slots(osb);
46673
46674 - atomic_set(&osb->alloc_stats.moves, 0);
46675 - atomic_set(&osb->alloc_stats.local_data, 0);
46676 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
46677 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
46678 - atomic_set(&osb->alloc_stats.bg_extends, 0);
46679 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
46680 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
46681 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
46682 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
46683 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
46684
46685 /* Copy the blockcheck stats from the superblock probe */
46686 osb->osb_ecc_stats = *stats;
46687 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
46688 index 5d22872..523db20 100644
46689 --- a/fs/ocfs2/symlink.c
46690 +++ b/fs/ocfs2/symlink.c
46691 @@ -142,7 +142,7 @@ bail:
46692
46693 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
46694 {
46695 - char *link = nd_get_link(nd);
46696 + const char *link = nd_get_link(nd);
46697 if (!IS_ERR(link))
46698 kfree(link);
46699 }
46700 diff --git a/fs/open.c b/fs/open.c
46701 index 22c41b5..78894cf 100644
46702 --- a/fs/open.c
46703 +++ b/fs/open.c
46704 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
46705 error = locks_verify_truncate(inode, NULL, length);
46706 if (!error)
46707 error = security_path_truncate(&path);
46708 +
46709 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
46710 + error = -EACCES;
46711 +
46712 if (!error)
46713 error = do_truncate(path.dentry, length, 0, NULL);
46714
46715 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
46716 if (__mnt_is_readonly(path.mnt))
46717 res = -EROFS;
46718
46719 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
46720 + res = -EACCES;
46721 +
46722 out_path_release:
46723 path_put(&path);
46724 out:
46725 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
46726 if (error)
46727 goto dput_and_out;
46728
46729 + gr_log_chdir(path.dentry, path.mnt);
46730 +
46731 set_fs_pwd(current->fs, &path);
46732
46733 dput_and_out:
46734 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
46735 goto out_putf;
46736
46737 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
46738 +
46739 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
46740 + error = -EPERM;
46741 +
46742 + if (!error)
46743 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
46744 +
46745 if (!error)
46746 set_fs_pwd(current->fs, &file->f_path);
46747 out_putf:
46748 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
46749 if (error)
46750 goto dput_and_out;
46751
46752 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
46753 + goto dput_and_out;
46754 +
46755 set_fs_root(current->fs, &path);
46756 +
46757 + gr_handle_chroot_chdir(&path);
46758 +
46759 error = 0;
46760 dput_and_out:
46761 path_put(&path);
46762 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
46763 if (error)
46764 return error;
46765 mutex_lock(&inode->i_mutex);
46766 +
46767 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
46768 + error = -EACCES;
46769 + goto out_unlock;
46770 + }
46771 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
46772 + error = -EACCES;
46773 + goto out_unlock;
46774 + }
46775 +
46776 error = security_path_chmod(path->dentry, path->mnt, mode);
46777 if (error)
46778 goto out_unlock;
46779 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
46780 int error;
46781 struct iattr newattrs;
46782
46783 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
46784 + return -EACCES;
46785 +
46786 newattrs.ia_valid = ATTR_CTIME;
46787 if (user != (uid_t) -1) {
46788 newattrs.ia_valid |= ATTR_UID;
46789 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
46790 index 6296b40..417c00f 100644
46791 --- a/fs/partitions/efi.c
46792 +++ b/fs/partitions/efi.c
46793 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
46794 if (!gpt)
46795 return NULL;
46796
46797 + if (!le32_to_cpu(gpt->num_partition_entries))
46798 + return NULL;
46799 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
46800 + if (!pte)
46801 + return NULL;
46802 +
46803 count = le32_to_cpu(gpt->num_partition_entries) *
46804 le32_to_cpu(gpt->sizeof_partition_entry);
46805 - if (!count)
46806 - return NULL;
46807 - pte = kzalloc(count, GFP_KERNEL);
46808 - if (!pte)
46809 - return NULL;
46810 -
46811 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
46812 (u8 *) pte,
46813 count) < count) {
46814 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
46815 index bd8ae78..539d250 100644
46816 --- a/fs/partitions/ldm.c
46817 +++ b/fs/partitions/ldm.c
46818 @@ -1324,7 +1324,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
46819 goto found;
46820 }
46821
46822 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
46823 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
46824 if (!f) {
46825 ldm_crit ("Out of memory.");
46826 return false;
46827 diff --git a/fs/pipe.c b/fs/pipe.c
46828 index 4065f07..68c0706 100644
46829 --- a/fs/pipe.c
46830 +++ b/fs/pipe.c
46831 @@ -420,9 +420,9 @@ redo:
46832 }
46833 if (bufs) /* More to do? */
46834 continue;
46835 - if (!pipe->writers)
46836 + if (!atomic_read(&pipe->writers))
46837 break;
46838 - if (!pipe->waiting_writers) {
46839 + if (!atomic_read(&pipe->waiting_writers)) {
46840 /* syscall merging: Usually we must not sleep
46841 * if O_NONBLOCK is set, or if we got some data.
46842 * But if a writer sleeps in kernel space, then
46843 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
46844 mutex_lock(&inode->i_mutex);
46845 pipe = inode->i_pipe;
46846
46847 - if (!pipe->readers) {
46848 + if (!atomic_read(&pipe->readers)) {
46849 send_sig(SIGPIPE, current, 0);
46850 ret = -EPIPE;
46851 goto out;
46852 @@ -530,7 +530,7 @@ redo1:
46853 for (;;) {
46854 int bufs;
46855
46856 - if (!pipe->readers) {
46857 + if (!atomic_read(&pipe->readers)) {
46858 send_sig(SIGPIPE, current, 0);
46859 if (!ret)
46860 ret = -EPIPE;
46861 @@ -616,9 +616,9 @@ redo2:
46862 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46863 do_wakeup = 0;
46864 }
46865 - pipe->waiting_writers++;
46866 + atomic_inc(&pipe->waiting_writers);
46867 pipe_wait(pipe);
46868 - pipe->waiting_writers--;
46869 + atomic_dec(&pipe->waiting_writers);
46870 }
46871 out:
46872 mutex_unlock(&inode->i_mutex);
46873 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46874 mask = 0;
46875 if (filp->f_mode & FMODE_READ) {
46876 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
46877 - if (!pipe->writers && filp->f_version != pipe->w_counter)
46878 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
46879 mask |= POLLHUP;
46880 }
46881
46882 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46883 * Most Unices do not set POLLERR for FIFOs but on Linux they
46884 * behave exactly like pipes for poll().
46885 */
46886 - if (!pipe->readers)
46887 + if (!atomic_read(&pipe->readers))
46888 mask |= POLLERR;
46889 }
46890
46891 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
46892
46893 mutex_lock(&inode->i_mutex);
46894 pipe = inode->i_pipe;
46895 - pipe->readers -= decr;
46896 - pipe->writers -= decw;
46897 + atomic_sub(decr, &pipe->readers);
46898 + atomic_sub(decw, &pipe->writers);
46899
46900 - if (!pipe->readers && !pipe->writers) {
46901 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
46902 free_pipe_info(inode);
46903 } else {
46904 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
46905 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
46906
46907 if (inode->i_pipe) {
46908 ret = 0;
46909 - inode->i_pipe->readers++;
46910 + atomic_inc(&inode->i_pipe->readers);
46911 }
46912
46913 mutex_unlock(&inode->i_mutex);
46914 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
46915
46916 if (inode->i_pipe) {
46917 ret = 0;
46918 - inode->i_pipe->writers++;
46919 + atomic_inc(&inode->i_pipe->writers);
46920 }
46921
46922 mutex_unlock(&inode->i_mutex);
46923 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
46924 if (inode->i_pipe) {
46925 ret = 0;
46926 if (filp->f_mode & FMODE_READ)
46927 - inode->i_pipe->readers++;
46928 + atomic_inc(&inode->i_pipe->readers);
46929 if (filp->f_mode & FMODE_WRITE)
46930 - inode->i_pipe->writers++;
46931 + atomic_inc(&inode->i_pipe->writers);
46932 }
46933
46934 mutex_unlock(&inode->i_mutex);
46935 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
46936 inode->i_pipe = NULL;
46937 }
46938
46939 -static struct vfsmount *pipe_mnt __read_mostly;
46940 +struct vfsmount *pipe_mnt __read_mostly;
46941
46942 /*
46943 * pipefs_dname() is called from d_path().
46944 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
46945 goto fail_iput;
46946 inode->i_pipe = pipe;
46947
46948 - pipe->readers = pipe->writers = 1;
46949 + atomic_set(&pipe->readers, 1);
46950 + atomic_set(&pipe->writers, 1);
46951 inode->i_fop = &rdwr_pipefifo_fops;
46952
46953 /*
46954 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
46955 index 15af622..0e9f4467 100644
46956 --- a/fs/proc/Kconfig
46957 +++ b/fs/proc/Kconfig
46958 @@ -30,12 +30,12 @@ config PROC_FS
46959
46960 config PROC_KCORE
46961 bool "/proc/kcore support" if !ARM
46962 - depends on PROC_FS && MMU
46963 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
46964
46965 config PROC_VMCORE
46966 bool "/proc/vmcore support"
46967 - depends on PROC_FS && CRASH_DUMP
46968 - default y
46969 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
46970 + default n
46971 help
46972 Exports the dump image of crashed kernel in ELF format.
46973
46974 @@ -59,8 +59,8 @@ config PROC_SYSCTL
46975 limited in memory.
46976
46977 config PROC_PAGE_MONITOR
46978 - default y
46979 - depends on PROC_FS && MMU
46980 + default n
46981 + depends on PROC_FS && MMU && !GRKERNSEC
46982 bool "Enable /proc page monitoring" if EXPERT
46983 help
46984 Various /proc files exist to monitor process memory utilization:
46985 diff --git a/fs/proc/array.c b/fs/proc/array.c
46986 index 3a1dafd..bf1bd84 100644
46987 --- a/fs/proc/array.c
46988 +++ b/fs/proc/array.c
46989 @@ -60,6 +60,7 @@
46990 #include <linux/tty.h>
46991 #include <linux/string.h>
46992 #include <linux/mman.h>
46993 +#include <linux/grsecurity.h>
46994 #include <linux/proc_fs.h>
46995 #include <linux/ioport.h>
46996 #include <linux/uaccess.h>
46997 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
46998 seq_putc(m, '\n');
46999 }
47000
47001 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47002 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47003 +{
47004 + if (p->mm)
47005 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47006 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47007 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47008 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47009 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47010 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47011 + else
47012 + seq_printf(m, "PaX:\t-----\n");
47013 +}
47014 +#endif
47015 +
47016 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47017 struct pid *pid, struct task_struct *task)
47018 {
47019 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47020 task_cpus_allowed(m, task);
47021 cpuset_task_status_allowed(m, task);
47022 task_context_switch_counts(m, task);
47023 +
47024 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47025 + task_pax(m, task);
47026 +#endif
47027 +
47028 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47029 + task_grsec_rbac(m, task);
47030 +#endif
47031 +
47032 return 0;
47033 }
47034
47035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47036 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47037 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47038 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47039 +#endif
47040 +
47041 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47042 struct pid *pid, struct task_struct *task, int whole)
47043 {
47044 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47045 char tcomm[sizeof(task->comm)];
47046 unsigned long flags;
47047
47048 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47049 + if (current->exec_id != m->exec_id) {
47050 + gr_log_badprocpid("stat");
47051 + return 0;
47052 + }
47053 +#endif
47054 +
47055 state = *get_task_state(task);
47056 vsize = eip = esp = 0;
47057 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
47058 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47059 gtime = task->gtime;
47060 }
47061
47062 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47063 + if (PAX_RAND_FLAGS(mm)) {
47064 + eip = 0;
47065 + esp = 0;
47066 + wchan = 0;
47067 + }
47068 +#endif
47069 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47070 + wchan = 0;
47071 + eip =0;
47072 + esp =0;
47073 +#endif
47074 +
47075 /* scale priority and nice values from timeslices to -20..20 */
47076 /* to make it look like a "normal" Unix priority/nice value */
47077 priority = task_prio(task);
47078 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47079 vsize,
47080 mm ? get_mm_rss(mm) : 0,
47081 rsslim,
47082 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47083 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47084 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47085 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47086 +#else
47087 mm ? (permitted ? mm->start_code : 1) : 0,
47088 mm ? (permitted ? mm->end_code : 1) : 0,
47089 (permitted && mm) ? mm->start_stack : 0,
47090 +#endif
47091 esp,
47092 eip,
47093 /* The signal information here is obsolete.
47094 @@ -533,8 +590,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47095 struct pid *pid, struct task_struct *task)
47096 {
47097 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47098 - struct mm_struct *mm = get_task_mm(task);
47099 + struct mm_struct *mm;
47100
47101 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47102 + if (current->exec_id != m->exec_id) {
47103 + gr_log_badprocpid("statm");
47104 + return 0;
47105 + }
47106 +#endif
47107 + mm = get_task_mm(task);
47108 if (mm) {
47109 size = task_statm(mm, &shared, &text, &data, &resident);
47110 mmput(mm);
47111 @@ -544,3 +608,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47112
47113 return 0;
47114 }
47115 +
47116 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47117 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47118 +{
47119 + u32 curr_ip = 0;
47120 + unsigned long flags;
47121 +
47122 + if (lock_task_sighand(task, &flags)) {
47123 + curr_ip = task->signal->curr_ip;
47124 + unlock_task_sighand(task, &flags);
47125 + }
47126 +
47127 + return sprintf(buffer, "%pI4\n", &curr_ip);
47128 +}
47129 +#endif
47130 diff --git a/fs/proc/base.c b/fs/proc/base.c
47131 index 1ace83d..f5e575d 100644
47132 --- a/fs/proc/base.c
47133 +++ b/fs/proc/base.c
47134 @@ -107,6 +107,22 @@ struct pid_entry {
47135 union proc_op op;
47136 };
47137
47138 +struct getdents_callback {
47139 + struct linux_dirent __user * current_dir;
47140 + struct linux_dirent __user * previous;
47141 + struct file * file;
47142 + int count;
47143 + int error;
47144 +};
47145 +
47146 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
47147 + loff_t offset, u64 ino, unsigned int d_type)
47148 +{
47149 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
47150 + buf->error = -EINVAL;
47151 + return 0;
47152 +}
47153 +
47154 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47155 .name = (NAME), \
47156 .len = sizeof(NAME) - 1, \
47157 @@ -194,26 +210,6 @@ static int proc_root_link(struct inode *inode, struct path *path)
47158 return result;
47159 }
47160
47161 -static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
47162 -{
47163 - struct mm_struct *mm;
47164 - int err;
47165 -
47166 - err = mutex_lock_killable(&task->signal->cred_guard_mutex);
47167 - if (err)
47168 - return ERR_PTR(err);
47169 -
47170 - mm = get_task_mm(task);
47171 - if (mm && mm != current->mm &&
47172 - !ptrace_may_access(task, mode)) {
47173 - mmput(mm);
47174 - mm = ERR_PTR(-EACCES);
47175 - }
47176 - mutex_unlock(&task->signal->cred_guard_mutex);
47177 -
47178 - return mm;
47179 -}
47180 -
47181 struct mm_struct *mm_for_maps(struct task_struct *task)
47182 {
47183 return mm_access(task, PTRACE_MODE_READ);
47184 @@ -229,6 +225,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47185 if (!mm->arg_end)
47186 goto out_mm; /* Shh! No looking before we're done */
47187
47188 + if (gr_acl_handle_procpidmem(task))
47189 + goto out_mm;
47190 +
47191 len = mm->arg_end - mm->arg_start;
47192
47193 if (len > PAGE_SIZE)
47194 @@ -256,12 +255,28 @@ out:
47195 return res;
47196 }
47197
47198 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47199 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47200 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47201 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47202 +#endif
47203 +
47204 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47205 {
47206 struct mm_struct *mm = mm_for_maps(task);
47207 int res = PTR_ERR(mm);
47208 if (mm && !IS_ERR(mm)) {
47209 unsigned int nwords = 0;
47210 +
47211 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47212 + /* allow if we're currently ptracing this task */
47213 + if (PAX_RAND_FLAGS(mm) &&
47214 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47215 + mmput(mm);
47216 + return 0;
47217 + }
47218 +#endif
47219 +
47220 do {
47221 nwords += 2;
47222 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47223 @@ -275,7 +290,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47224 }
47225
47226
47227 -#ifdef CONFIG_KALLSYMS
47228 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47229 /*
47230 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47231 * Returns the resolved symbol. If that fails, simply return the address.
47232 @@ -314,7 +329,7 @@ static void unlock_trace(struct task_struct *task)
47233 mutex_unlock(&task->signal->cred_guard_mutex);
47234 }
47235
47236 -#ifdef CONFIG_STACKTRACE
47237 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47238
47239 #define MAX_STACK_TRACE_DEPTH 64
47240
47241 @@ -505,7 +520,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47242 return count;
47243 }
47244
47245 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47246 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47247 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47248 {
47249 long nr;
47250 @@ -534,7 +549,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47251 /************************************************************************/
47252
47253 /* permission checks */
47254 -static int proc_fd_access_allowed(struct inode *inode)
47255 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47256 {
47257 struct task_struct *task;
47258 int allowed = 0;
47259 @@ -544,7 +559,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47260 */
47261 task = get_proc_task(inode);
47262 if (task) {
47263 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47264 + if (log)
47265 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
47266 + else
47267 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47268 put_task_struct(task);
47269 }
47270 return allowed;
47271 @@ -786,6 +804,10 @@ static int mem_open(struct inode* inode, struct file* file)
47272 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47273 file->private_data = mm;
47274
47275 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47276 + file->f_version = current->exec_id;
47277 +#endif
47278 +
47279 return 0;
47280 }
47281
47282 @@ -797,6 +819,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47283 ssize_t copied;
47284 char *page;
47285
47286 +#ifdef CONFIG_GRKERNSEC
47287 + if (write)
47288 + return -EPERM;
47289 +#endif
47290 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47291 + if (file->f_version != current->exec_id) {
47292 + gr_log_badprocpid("mem");
47293 + return 0;
47294 + }
47295 +#endif
47296 +
47297 if (!mm)
47298 return 0;
47299
47300 @@ -897,6 +930,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
47301 if (!task)
47302 goto out_no_task;
47303
47304 + if (gr_acl_handle_procpidmem(task))
47305 + goto out;
47306 +
47307 ret = -ENOMEM;
47308 page = (char *)__get_free_page(GFP_TEMPORARY);
47309 if (!page)
47310 @@ -1519,7 +1555,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
47311 path_put(&nd->path);
47312
47313 /* Are we allowed to snoop on the tasks file descriptors? */
47314 - if (!proc_fd_access_allowed(inode))
47315 + if (!proc_fd_access_allowed(inode,0))
47316 goto out;
47317
47318 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
47319 @@ -1558,8 +1594,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47320 struct path path;
47321
47322 /* Are we allowed to snoop on the tasks file descriptors? */
47323 - if (!proc_fd_access_allowed(inode))
47324 - goto out;
47325 + /* logging this is needed for learning on chromium to work properly,
47326 + but we don't want to flood the logs from 'ps' which does a readlink
47327 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47328 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
47329 + */
47330 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47331 + if (!proc_fd_access_allowed(inode,0))
47332 + goto out;
47333 + } else {
47334 + if (!proc_fd_access_allowed(inode,1))
47335 + goto out;
47336 + }
47337
47338 error = PROC_I(inode)->op.proc_get_link(inode, &path);
47339 if (error)
47340 @@ -1624,7 +1670,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47341 rcu_read_lock();
47342 cred = __task_cred(task);
47343 inode->i_uid = cred->euid;
47344 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47345 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47346 +#else
47347 inode->i_gid = cred->egid;
47348 +#endif
47349 rcu_read_unlock();
47350 }
47351 security_task_to_inode(task, inode);
47352 @@ -1642,6 +1692,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47353 struct inode *inode = dentry->d_inode;
47354 struct task_struct *task;
47355 const struct cred *cred;
47356 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47357 + const struct cred *tmpcred = current_cred();
47358 +#endif
47359
47360 generic_fillattr(inode, stat);
47361
47362 @@ -1649,13 +1702,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47363 stat->uid = 0;
47364 stat->gid = 0;
47365 task = pid_task(proc_pid(inode), PIDTYPE_PID);
47366 +
47367 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
47368 + rcu_read_unlock();
47369 + return -ENOENT;
47370 + }
47371 +
47372 if (task) {
47373 + cred = __task_cred(task);
47374 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47375 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47376 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47377 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47378 +#endif
47379 + ) {
47380 +#endif
47381 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47382 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47383 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47384 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47385 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47386 +#endif
47387 task_dumpable(task)) {
47388 - cred = __task_cred(task);
47389 stat->uid = cred->euid;
47390 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47391 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47392 +#else
47393 stat->gid = cred->egid;
47394 +#endif
47395 }
47396 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47397 + } else {
47398 + rcu_read_unlock();
47399 + return -ENOENT;
47400 + }
47401 +#endif
47402 }
47403 rcu_read_unlock();
47404 return 0;
47405 @@ -1692,11 +1773,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47406
47407 if (task) {
47408 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47409 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47410 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47411 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47412 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47413 +#endif
47414 task_dumpable(task)) {
47415 rcu_read_lock();
47416 cred = __task_cred(task);
47417 inode->i_uid = cred->euid;
47418 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47419 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47420 +#else
47421 inode->i_gid = cred->egid;
47422 +#endif
47423 rcu_read_unlock();
47424 } else {
47425 inode->i_uid = 0;
47426 @@ -1814,7 +1904,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47427 int fd = proc_fd(inode);
47428
47429 if (task) {
47430 - files = get_files_struct(task);
47431 + if (!gr_acl_handle_procpidmem(task))
47432 + files = get_files_struct(task);
47433 put_task_struct(task);
47434 }
47435 if (files) {
47436 @@ -2082,11 +2173,21 @@ static const struct file_operations proc_fd_operations = {
47437 */
47438 static int proc_fd_permission(struct inode *inode, int mask)
47439 {
47440 + struct task_struct *task;
47441 int rv = generic_permission(inode, mask);
47442 - if (rv == 0)
47443 - return 0;
47444 +
47445 if (task_pid(current) == proc_pid(inode))
47446 rv = 0;
47447 +
47448 + task = get_proc_task(inode);
47449 + if (task == NULL)
47450 + return rv;
47451 +
47452 + if (gr_acl_handle_procpidmem(task))
47453 + rv = -EACCES;
47454 +
47455 + put_task_struct(task);
47456 +
47457 return rv;
47458 }
47459
47460 @@ -2196,6 +2297,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47461 if (!task)
47462 goto out_no_task;
47463
47464 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47465 + goto out;
47466 +
47467 /*
47468 * Yes, it does not scale. And it should not. Don't add
47469 * new entries into /proc/<tgid>/ without very good reasons.
47470 @@ -2240,6 +2344,9 @@ static int proc_pident_readdir(struct file *filp,
47471 if (!task)
47472 goto out_no_task;
47473
47474 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47475 + goto out;
47476 +
47477 ret = 0;
47478 i = filp->f_pos;
47479 switch (i) {
47480 @@ -2510,7 +2617,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47481 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47482 void *cookie)
47483 {
47484 - char *s = nd_get_link(nd);
47485 + const char *s = nd_get_link(nd);
47486 if (!IS_ERR(s))
47487 __putname(s);
47488 }
47489 @@ -2708,7 +2815,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47490 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47491 #endif
47492 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47493 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47494 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47495 INF("syscall", S_IRUGO, proc_pid_syscall),
47496 #endif
47497 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47498 @@ -2733,10 +2840,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47499 #ifdef CONFIG_SECURITY
47500 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47501 #endif
47502 -#ifdef CONFIG_KALLSYMS
47503 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47504 INF("wchan", S_IRUGO, proc_pid_wchan),
47505 #endif
47506 -#ifdef CONFIG_STACKTRACE
47507 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47508 ONE("stack", S_IRUGO, proc_pid_stack),
47509 #endif
47510 #ifdef CONFIG_SCHEDSTATS
47511 @@ -2770,6 +2877,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47512 #ifdef CONFIG_HARDWALL
47513 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47514 #endif
47515 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47516 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47517 +#endif
47518 };
47519
47520 static int proc_tgid_base_readdir(struct file * filp,
47521 @@ -2895,7 +3005,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47522 if (!inode)
47523 goto out;
47524
47525 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47526 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47527 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47528 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47529 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47530 +#else
47531 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47532 +#endif
47533 inode->i_op = &proc_tgid_base_inode_operations;
47534 inode->i_fop = &proc_tgid_base_operations;
47535 inode->i_flags|=S_IMMUTABLE;
47536 @@ -2937,7 +3054,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47537 if (!task)
47538 goto out;
47539
47540 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47541 + goto out_put_task;
47542 +
47543 result = proc_pid_instantiate(dir, dentry, task, NULL);
47544 +out_put_task:
47545 put_task_struct(task);
47546 out:
47547 return result;
47548 @@ -3002,6 +3123,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
47549 {
47550 unsigned int nr;
47551 struct task_struct *reaper;
47552 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47553 + const struct cred *tmpcred = current_cred();
47554 + const struct cred *itercred;
47555 +#endif
47556 + filldir_t __filldir = filldir;
47557 struct tgid_iter iter;
47558 struct pid_namespace *ns;
47559
47560 @@ -3025,8 +3151,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
47561 for (iter = next_tgid(ns, iter);
47562 iter.task;
47563 iter.tgid += 1, iter = next_tgid(ns, iter)) {
47564 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47565 + rcu_read_lock();
47566 + itercred = __task_cred(iter.task);
47567 +#endif
47568 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
47569 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47570 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
47571 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47572 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47573 +#endif
47574 + )
47575 +#endif
47576 + )
47577 + __filldir = &gr_fake_filldir;
47578 + else
47579 + __filldir = filldir;
47580 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47581 + rcu_read_unlock();
47582 +#endif
47583 filp->f_pos = iter.tgid + TGID_OFFSET;
47584 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
47585 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
47586 put_task_struct(iter.task);
47587 goto out;
47588 }
47589 @@ -3054,7 +3199,7 @@ static const struct pid_entry tid_base_stuff[] = {
47590 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47591 #endif
47592 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47593 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47594 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47595 INF("syscall", S_IRUGO, proc_pid_syscall),
47596 #endif
47597 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47598 @@ -3078,10 +3223,10 @@ static const struct pid_entry tid_base_stuff[] = {
47599 #ifdef CONFIG_SECURITY
47600 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47601 #endif
47602 -#ifdef CONFIG_KALLSYMS
47603 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47604 INF("wchan", S_IRUGO, proc_pid_wchan),
47605 #endif
47606 -#ifdef CONFIG_STACKTRACE
47607 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47608 ONE("stack", S_IRUGO, proc_pid_stack),
47609 #endif
47610 #ifdef CONFIG_SCHEDSTATS
47611 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47612 index 82676e3..5f8518a 100644
47613 --- a/fs/proc/cmdline.c
47614 +++ b/fs/proc/cmdline.c
47615 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47616
47617 static int __init proc_cmdline_init(void)
47618 {
47619 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47620 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47621 +#else
47622 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47623 +#endif
47624 return 0;
47625 }
47626 module_init(proc_cmdline_init);
47627 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47628 index b143471..bb105e5 100644
47629 --- a/fs/proc/devices.c
47630 +++ b/fs/proc/devices.c
47631 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47632
47633 static int __init proc_devices_init(void)
47634 {
47635 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47636 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47637 +#else
47638 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47639 +#endif
47640 return 0;
47641 }
47642 module_init(proc_devices_init);
47643 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47644 index 7737c54..7172574 100644
47645 --- a/fs/proc/inode.c
47646 +++ b/fs/proc/inode.c
47647 @@ -18,12 +18,18 @@
47648 #include <linux/module.h>
47649 #include <linux/sysctl.h>
47650 #include <linux/slab.h>
47651 +#include <linux/grsecurity.h>
47652
47653 #include <asm/system.h>
47654 #include <asm/uaccess.h>
47655
47656 #include "internal.h"
47657
47658 +#ifdef CONFIG_PROC_SYSCTL
47659 +extern const struct inode_operations proc_sys_inode_operations;
47660 +extern const struct inode_operations proc_sys_dir_operations;
47661 +#endif
47662 +
47663 static void proc_evict_inode(struct inode *inode)
47664 {
47665 struct proc_dir_entry *de;
47666 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
47667 ns_ops = PROC_I(inode)->ns_ops;
47668 if (ns_ops && ns_ops->put)
47669 ns_ops->put(PROC_I(inode)->ns);
47670 +
47671 +#ifdef CONFIG_PROC_SYSCTL
47672 + if (inode->i_op == &proc_sys_inode_operations ||
47673 + inode->i_op == &proc_sys_dir_operations)
47674 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
47675 +#endif
47676 +
47677 }
47678
47679 static struct kmem_cache * proc_inode_cachep;
47680 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
47681 if (de->mode) {
47682 inode->i_mode = de->mode;
47683 inode->i_uid = de->uid;
47684 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47685 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47686 +#else
47687 inode->i_gid = de->gid;
47688 +#endif
47689 }
47690 if (de->size)
47691 inode->i_size = de->size;
47692 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
47693 index 7838e5c..ff92cbc 100644
47694 --- a/fs/proc/internal.h
47695 +++ b/fs/proc/internal.h
47696 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47697 struct pid *pid, struct task_struct *task);
47698 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47699 struct pid *pid, struct task_struct *task);
47700 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47701 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
47702 +#endif
47703 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
47704
47705 extern const struct file_operations proc_maps_operations;
47706 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
47707 index d245cb2..f4e8498 100644
47708 --- a/fs/proc/kcore.c
47709 +++ b/fs/proc/kcore.c
47710 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47711 * the addresses in the elf_phdr on our list.
47712 */
47713 start = kc_offset_to_vaddr(*fpos - elf_buflen);
47714 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
47715 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
47716 + if (tsz > buflen)
47717 tsz = buflen;
47718 -
47719 +
47720 while (buflen) {
47721 struct kcore_list *m;
47722
47723 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47724 kfree(elf_buf);
47725 } else {
47726 if (kern_addr_valid(start)) {
47727 - unsigned long n;
47728 + char *elf_buf;
47729 + mm_segment_t oldfs;
47730
47731 - n = copy_to_user(buffer, (char *)start, tsz);
47732 - /*
47733 - * We cannot distingush between fault on source
47734 - * and fault on destination. When this happens
47735 - * we clear too and hope it will trigger the
47736 - * EFAULT again.
47737 - */
47738 - if (n) {
47739 - if (clear_user(buffer + tsz - n,
47740 - n))
47741 + elf_buf = kmalloc(tsz, GFP_KERNEL);
47742 + if (!elf_buf)
47743 + return -ENOMEM;
47744 + oldfs = get_fs();
47745 + set_fs(KERNEL_DS);
47746 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
47747 + set_fs(oldfs);
47748 + if (copy_to_user(buffer, elf_buf, tsz)) {
47749 + kfree(elf_buf);
47750 return -EFAULT;
47751 + }
47752 }
47753 + set_fs(oldfs);
47754 + kfree(elf_buf);
47755 } else {
47756 if (clear_user(buffer, tsz))
47757 return -EFAULT;
47758 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47759
47760 static int open_kcore(struct inode *inode, struct file *filp)
47761 {
47762 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
47763 + return -EPERM;
47764 +#endif
47765 if (!capable(CAP_SYS_RAWIO))
47766 return -EPERM;
47767 if (kcore_need_update)
47768 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
47769 index 80e4645..53e5fcf 100644
47770 --- a/fs/proc/meminfo.c
47771 +++ b/fs/proc/meminfo.c
47772 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
47773 vmi.used >> 10,
47774 vmi.largest_chunk >> 10
47775 #ifdef CONFIG_MEMORY_FAILURE
47776 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
47777 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
47778 #endif
47779 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
47780 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
47781 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
47782 index b1822dd..df622cb 100644
47783 --- a/fs/proc/nommu.c
47784 +++ b/fs/proc/nommu.c
47785 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
47786 if (len < 1)
47787 len = 1;
47788 seq_printf(m, "%*c", len, ' ');
47789 - seq_path(m, &file->f_path, "");
47790 + seq_path(m, &file->f_path, "\n\\");
47791 }
47792
47793 seq_putc(m, '\n');
47794 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
47795 index f738024..876984a 100644
47796 --- a/fs/proc/proc_net.c
47797 +++ b/fs/proc/proc_net.c
47798 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
47799 struct task_struct *task;
47800 struct nsproxy *ns;
47801 struct net *net = NULL;
47802 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47803 + const struct cred *cred = current_cred();
47804 +#endif
47805 +
47806 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47807 + if (cred->fsuid)
47808 + return net;
47809 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47810 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
47811 + return net;
47812 +#endif
47813
47814 rcu_read_lock();
47815 task = pid_task(proc_pid(dir), PIDTYPE_PID);
47816 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
47817 index a6b6217..1e0579d 100644
47818 --- a/fs/proc/proc_sysctl.c
47819 +++ b/fs/proc/proc_sysctl.c
47820 @@ -9,11 +9,13 @@
47821 #include <linux/namei.h>
47822 #include "internal.h"
47823
47824 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
47825 +
47826 static const struct dentry_operations proc_sys_dentry_operations;
47827 static const struct file_operations proc_sys_file_operations;
47828 -static const struct inode_operations proc_sys_inode_operations;
47829 +const struct inode_operations proc_sys_inode_operations;
47830 static const struct file_operations proc_sys_dir_file_operations;
47831 -static const struct inode_operations proc_sys_dir_operations;
47832 +const struct inode_operations proc_sys_dir_operations;
47833
47834 void proc_sys_poll_notify(struct ctl_table_poll *poll)
47835 {
47836 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
47837
47838 err = NULL;
47839 d_set_d_op(dentry, &proc_sys_dentry_operations);
47840 +
47841 + gr_handle_proc_create(dentry, inode);
47842 +
47843 d_add(dentry, inode);
47844
47845 + if (gr_handle_sysctl(p, MAY_EXEC))
47846 + err = ERR_PTR(-ENOENT);
47847 +
47848 out:
47849 sysctl_head_finish(head);
47850 return err;
47851 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
47852 if (!table->proc_handler)
47853 goto out;
47854
47855 +#ifdef CONFIG_GRKERNSEC
47856 + error = -EPERM;
47857 + if (write && !capable(CAP_SYS_ADMIN))
47858 + goto out;
47859 +#endif
47860 +
47861 /* careful: calling conventions are nasty here */
47862 res = count;
47863 error = table->proc_handler(table, write, buf, &res, ppos);
47864 @@ -245,6 +259,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
47865 return -ENOMEM;
47866 } else {
47867 d_set_d_op(child, &proc_sys_dentry_operations);
47868 +
47869 + gr_handle_proc_create(child, inode);
47870 +
47871 d_add(child, inode);
47872 }
47873 } else {
47874 @@ -273,6 +290,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
47875 if (*pos < file->f_pos)
47876 continue;
47877
47878 + if (gr_handle_sysctl(table, 0))
47879 + continue;
47880 +
47881 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
47882 if (res)
47883 return res;
47884 @@ -398,6 +418,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
47885 if (IS_ERR(head))
47886 return PTR_ERR(head);
47887
47888 + if (table && gr_handle_sysctl(table, MAY_EXEC))
47889 + return -ENOENT;
47890 +
47891 generic_fillattr(inode, stat);
47892 if (table)
47893 stat->mode = (stat->mode & S_IFMT) | table->mode;
47894 @@ -420,13 +443,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
47895 .llseek = generic_file_llseek,
47896 };
47897
47898 -static const struct inode_operations proc_sys_inode_operations = {
47899 +const struct inode_operations proc_sys_inode_operations = {
47900 .permission = proc_sys_permission,
47901 .setattr = proc_sys_setattr,
47902 .getattr = proc_sys_getattr,
47903 };
47904
47905 -static const struct inode_operations proc_sys_dir_operations = {
47906 +const struct inode_operations proc_sys_dir_operations = {
47907 .lookup = proc_sys_lookup,
47908 .permission = proc_sys_permission,
47909 .setattr = proc_sys_setattr,
47910 diff --git a/fs/proc/root.c b/fs/proc/root.c
47911 index 03102d9..4ae347e 100644
47912 --- a/fs/proc/root.c
47913 +++ b/fs/proc/root.c
47914 @@ -121,7 +121,15 @@ void __init proc_root_init(void)
47915 #ifdef CONFIG_PROC_DEVICETREE
47916 proc_device_tree_init();
47917 #endif
47918 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47919 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47920 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
47921 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47922 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47923 +#endif
47924 +#else
47925 proc_mkdir("bus", NULL);
47926 +#endif
47927 proc_sys_init();
47928 }
47929
47930 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
47931 index 7dcd2a2..b2f410e 100644
47932 --- a/fs/proc/task_mmu.c
47933 +++ b/fs/proc/task_mmu.c
47934 @@ -11,6 +11,7 @@
47935 #include <linux/rmap.h>
47936 #include <linux/swap.h>
47937 #include <linux/swapops.h>
47938 +#include <linux/grsecurity.h>
47939
47940 #include <asm/elf.h>
47941 #include <asm/uaccess.h>
47942 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47943 "VmExe:\t%8lu kB\n"
47944 "VmLib:\t%8lu kB\n"
47945 "VmPTE:\t%8lu kB\n"
47946 - "VmSwap:\t%8lu kB\n",
47947 - hiwater_vm << (PAGE_SHIFT-10),
47948 + "VmSwap:\t%8lu kB\n"
47949 +
47950 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47951 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
47952 +#endif
47953 +
47954 + ,hiwater_vm << (PAGE_SHIFT-10),
47955 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
47956 mm->locked_vm << (PAGE_SHIFT-10),
47957 mm->pinned_vm << (PAGE_SHIFT-10),
47958 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47959 data << (PAGE_SHIFT-10),
47960 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
47961 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
47962 - swap << (PAGE_SHIFT-10));
47963 + swap << (PAGE_SHIFT-10)
47964 +
47965 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47966 + , mm->context.user_cs_base, mm->context.user_cs_limit
47967 +#endif
47968 +
47969 + );
47970 }
47971
47972 unsigned long task_vsize(struct mm_struct *mm)
47973 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
47974 return ret;
47975 }
47976
47977 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47978 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47979 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47980 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47981 +#endif
47982 +
47983 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47984 {
47985 struct mm_struct *mm = vma->vm_mm;
47986 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47987 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
47988 }
47989
47990 - /* We don't show the stack guard page in /proc/maps */
47991 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47992 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
47993 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
47994 +#else
47995 start = vma->vm_start;
47996 - if (stack_guard_page_start(vma, start))
47997 - start += PAGE_SIZE;
47998 end = vma->vm_end;
47999 - if (stack_guard_page_end(vma, end))
48000 - end -= PAGE_SIZE;
48001 +#endif
48002
48003 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48004 start,
48005 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48006 flags & VM_WRITE ? 'w' : '-',
48007 flags & VM_EXEC ? 'x' : '-',
48008 flags & VM_MAYSHARE ? 's' : 'p',
48009 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48010 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48011 +#else
48012 pgoff,
48013 +#endif
48014 MAJOR(dev), MINOR(dev), ino, &len);
48015
48016 /*
48017 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48018 */
48019 if (file) {
48020 pad_len_spaces(m, len);
48021 - seq_path(m, &file->f_path, "\n");
48022 + seq_path(m, &file->f_path, "\n\\");
48023 } else {
48024 const char *name = arch_vma_name(vma);
48025 if (!name) {
48026 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48027 if (vma->vm_start <= mm->brk &&
48028 vma->vm_end >= mm->start_brk) {
48029 name = "[heap]";
48030 - } else if (vma->vm_start <= mm->start_stack &&
48031 - vma->vm_end >= mm->start_stack) {
48032 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48033 + (vma->vm_start <= mm->start_stack &&
48034 + vma->vm_end >= mm->start_stack)) {
48035 name = "[stack]";
48036 }
48037 } else {
48038 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48039 struct proc_maps_private *priv = m->private;
48040 struct task_struct *task = priv->task;
48041
48042 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48043 + if (current->exec_id != m->exec_id) {
48044 + gr_log_badprocpid("maps");
48045 + return 0;
48046 + }
48047 +#endif
48048 +
48049 show_map_vma(m, vma);
48050
48051 if (m->count < m->size) /* vma is copied successfully */
48052 @@ -434,12 +464,23 @@ static int show_smap(struct seq_file *m, void *v)
48053 .private = &mss,
48054 };
48055
48056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48057 + if (current->exec_id != m->exec_id) {
48058 + gr_log_badprocpid("smaps");
48059 + return 0;
48060 + }
48061 +#endif
48062 memset(&mss, 0, sizeof mss);
48063 - mss.vma = vma;
48064 - /* mmap_sem is held in m_start */
48065 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48066 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48067 -
48068 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48069 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48070 +#endif
48071 + mss.vma = vma;
48072 + /* mmap_sem is held in m_start */
48073 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48074 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48075 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48076 + }
48077 +#endif
48078 show_map_vma(m, vma);
48079
48080 seq_printf(m,
48081 @@ -457,7 +498,11 @@ static int show_smap(struct seq_file *m, void *v)
48082 "KernelPageSize: %8lu kB\n"
48083 "MMUPageSize: %8lu kB\n"
48084 "Locked: %8lu kB\n",
48085 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48086 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48087 +#else
48088 (vma->vm_end - vma->vm_start) >> 10,
48089 +#endif
48090 mss.resident >> 10,
48091 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48092 mss.shared_clean >> 10,
48093 @@ -1015,6 +1060,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48094 int n;
48095 char buffer[50];
48096
48097 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48098 + if (current->exec_id != m->exec_id) {
48099 + gr_log_badprocpid("numa_maps");
48100 + return 0;
48101 + }
48102 +#endif
48103 +
48104 if (!mm)
48105 return 0;
48106
48107 @@ -1032,11 +1084,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48108 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48109 mpol_cond_put(pol);
48110
48111 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48112 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48113 +#else
48114 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48115 +#endif
48116
48117 if (file) {
48118 seq_printf(m, " file=");
48119 - seq_path(m, &file->f_path, "\n\t= ");
48120 + seq_path(m, &file->f_path, "\n\t\\= ");
48121 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48122 seq_printf(m, " heap");
48123 } else if (vma->vm_start <= mm->start_stack &&
48124 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48125 index 980de54..2a4db5f 100644
48126 --- a/fs/proc/task_nommu.c
48127 +++ b/fs/proc/task_nommu.c
48128 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48129 else
48130 bytes += kobjsize(mm);
48131
48132 - if (current->fs && current->fs->users > 1)
48133 + if (current->fs && atomic_read(&current->fs->users) > 1)
48134 sbytes += kobjsize(current->fs);
48135 else
48136 bytes += kobjsize(current->fs);
48137 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48138
48139 if (file) {
48140 pad_len_spaces(m, len);
48141 - seq_path(m, &file->f_path, "");
48142 + seq_path(m, &file->f_path, "\n\\");
48143 } else if (mm) {
48144 if (vma->vm_start <= mm->start_stack &&
48145 vma->vm_end >= mm->start_stack) {
48146 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48147 index d67908b..d13f6a6 100644
48148 --- a/fs/quota/netlink.c
48149 +++ b/fs/quota/netlink.c
48150 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48151 void quota_send_warning(short type, unsigned int id, dev_t dev,
48152 const char warntype)
48153 {
48154 - static atomic_t seq;
48155 + static atomic_unchecked_t seq;
48156 struct sk_buff *skb;
48157 void *msg_head;
48158 int ret;
48159 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48160 "VFS: Not enough memory to send quota warning.\n");
48161 return;
48162 }
48163 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48164 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48165 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48166 if (!msg_head) {
48167 printk(KERN_ERR
48168 diff --git a/fs/readdir.c b/fs/readdir.c
48169 index 356f715..c918d38 100644
48170 --- a/fs/readdir.c
48171 +++ b/fs/readdir.c
48172 @@ -17,6 +17,7 @@
48173 #include <linux/security.h>
48174 #include <linux/syscalls.h>
48175 #include <linux/unistd.h>
48176 +#include <linux/namei.h>
48177
48178 #include <asm/uaccess.h>
48179
48180 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48181
48182 struct readdir_callback {
48183 struct old_linux_dirent __user * dirent;
48184 + struct file * file;
48185 int result;
48186 };
48187
48188 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48189 buf->result = -EOVERFLOW;
48190 return -EOVERFLOW;
48191 }
48192 +
48193 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48194 + return 0;
48195 +
48196 buf->result++;
48197 dirent = buf->dirent;
48198 if (!access_ok(VERIFY_WRITE, dirent,
48199 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48200
48201 buf.result = 0;
48202 buf.dirent = dirent;
48203 + buf.file = file;
48204
48205 error = vfs_readdir(file, fillonedir, &buf);
48206 if (buf.result)
48207 @@ -142,6 +149,7 @@ struct linux_dirent {
48208 struct getdents_callback {
48209 struct linux_dirent __user * current_dir;
48210 struct linux_dirent __user * previous;
48211 + struct file * file;
48212 int count;
48213 int error;
48214 };
48215 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48216 buf->error = -EOVERFLOW;
48217 return -EOVERFLOW;
48218 }
48219 +
48220 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48221 + return 0;
48222 +
48223 dirent = buf->previous;
48224 if (dirent) {
48225 if (__put_user(offset, &dirent->d_off))
48226 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48227 buf.previous = NULL;
48228 buf.count = count;
48229 buf.error = 0;
48230 + buf.file = file;
48231
48232 error = vfs_readdir(file, filldir, &buf);
48233 if (error >= 0)
48234 @@ -229,6 +242,7 @@ out:
48235 struct getdents_callback64 {
48236 struct linux_dirent64 __user * current_dir;
48237 struct linux_dirent64 __user * previous;
48238 + struct file *file;
48239 int count;
48240 int error;
48241 };
48242 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48243 buf->error = -EINVAL; /* only used if we fail.. */
48244 if (reclen > buf->count)
48245 return -EINVAL;
48246 +
48247 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48248 + return 0;
48249 +
48250 dirent = buf->previous;
48251 if (dirent) {
48252 if (__put_user(offset, &dirent->d_off))
48253 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48254
48255 buf.current_dir = dirent;
48256 buf.previous = NULL;
48257 + buf.file = file;
48258 buf.count = count;
48259 buf.error = 0;
48260
48261 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48262 error = buf.error;
48263 lastdirent = buf.previous;
48264 if (lastdirent) {
48265 - typeof(lastdirent->d_off) d_off = file->f_pos;
48266 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48267 if (__put_user(d_off, &lastdirent->d_off))
48268 error = -EFAULT;
48269 else
48270 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48271 index 60c0804..d814f98 100644
48272 --- a/fs/reiserfs/do_balan.c
48273 +++ b/fs/reiserfs/do_balan.c
48274 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48275 return;
48276 }
48277
48278 - atomic_inc(&(fs_generation(tb->tb_sb)));
48279 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48280 do_balance_starts(tb);
48281
48282 /* balance leaf returns 0 except if combining L R and S into
48283 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48284 index 7a99811..a7c96c4 100644
48285 --- a/fs/reiserfs/procfs.c
48286 +++ b/fs/reiserfs/procfs.c
48287 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48288 "SMALL_TAILS " : "NO_TAILS ",
48289 replay_only(sb) ? "REPLAY_ONLY " : "",
48290 convert_reiserfs(sb) ? "CONV " : "",
48291 - atomic_read(&r->s_generation_counter),
48292 + atomic_read_unchecked(&r->s_generation_counter),
48293 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48294 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48295 SF(s_good_search_by_key_reada), SF(s_bmaps),
48296 diff --git a/fs/select.c b/fs/select.c
48297 index d33418f..2a5345e 100644
48298 --- a/fs/select.c
48299 +++ b/fs/select.c
48300 @@ -20,6 +20,7 @@
48301 #include <linux/module.h>
48302 #include <linux/slab.h>
48303 #include <linux/poll.h>
48304 +#include <linux/security.h>
48305 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48306 #include <linux/file.h>
48307 #include <linux/fdtable.h>
48308 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48309 struct poll_list *walk = head;
48310 unsigned long todo = nfds;
48311
48312 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48313 if (nfds > rlimit(RLIMIT_NOFILE))
48314 return -EINVAL;
48315
48316 diff --git a/fs/seq_file.c b/fs/seq_file.c
48317 index dba43c3..9fb8511 100644
48318 --- a/fs/seq_file.c
48319 +++ b/fs/seq_file.c
48320 @@ -9,6 +9,7 @@
48321 #include <linux/module.h>
48322 #include <linux/seq_file.h>
48323 #include <linux/slab.h>
48324 +#include <linux/sched.h>
48325
48326 #include <asm/uaccess.h>
48327 #include <asm/page.h>
48328 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48329 memset(p, 0, sizeof(*p));
48330 mutex_init(&p->lock);
48331 p->op = op;
48332 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48333 + p->exec_id = current->exec_id;
48334 +#endif
48335
48336 /*
48337 * Wrappers around seq_open(e.g. swaps_open) need to be
48338 @@ -76,7 +80,8 @@ static int traverse(struct seq_file *m, loff_t offset)
48339 return 0;
48340 }
48341 if (!m->buf) {
48342 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
48343 + m->size = PAGE_SIZE;
48344 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
48345 if (!m->buf)
48346 return -ENOMEM;
48347 }
48348 @@ -116,7 +121,8 @@ static int traverse(struct seq_file *m, loff_t offset)
48349 Eoverflow:
48350 m->op->stop(m, p);
48351 kfree(m->buf);
48352 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
48353 + m->size <<= 1;
48354 + m->buf = kmalloc(m->size, GFP_KERNEL);
48355 return !m->buf ? -ENOMEM : -EAGAIN;
48356 }
48357
48358 @@ -169,7 +175,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
48359 m->version = file->f_version;
48360 /* grab buffer if we didn't have one */
48361 if (!m->buf) {
48362 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
48363 + m->size = PAGE_SIZE;
48364 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
48365 if (!m->buf)
48366 goto Enomem;
48367 }
48368 @@ -210,7 +217,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
48369 goto Fill;
48370 m->op->stop(m, p);
48371 kfree(m->buf);
48372 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
48373 + m->size <<= 1;
48374 + m->buf = kmalloc(m->size, GFP_KERNEL);
48375 if (!m->buf)
48376 goto Enomem;
48377 m->count = 0;
48378 @@ -549,7 +557,7 @@ static void single_stop(struct seq_file *p, void *v)
48379 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48380 void *data)
48381 {
48382 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48383 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48384 int res = -ENOMEM;
48385
48386 if (op) {
48387 diff --git a/fs/splice.c b/fs/splice.c
48388 index fa2defa..8601650 100644
48389 --- a/fs/splice.c
48390 +++ b/fs/splice.c
48391 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48392 pipe_lock(pipe);
48393
48394 for (;;) {
48395 - if (!pipe->readers) {
48396 + if (!atomic_read(&pipe->readers)) {
48397 send_sig(SIGPIPE, current, 0);
48398 if (!ret)
48399 ret = -EPIPE;
48400 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48401 do_wakeup = 0;
48402 }
48403
48404 - pipe->waiting_writers++;
48405 + atomic_inc(&pipe->waiting_writers);
48406 pipe_wait(pipe);
48407 - pipe->waiting_writers--;
48408 + atomic_dec(&pipe->waiting_writers);
48409 }
48410
48411 pipe_unlock(pipe);
48412 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48413 old_fs = get_fs();
48414 set_fs(get_ds());
48415 /* The cast to a user pointer is valid due to the set_fs() */
48416 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48417 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48418 set_fs(old_fs);
48419
48420 return res;
48421 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48422 old_fs = get_fs();
48423 set_fs(get_ds());
48424 /* The cast to a user pointer is valid due to the set_fs() */
48425 - res = vfs_write(file, (const char __user *)buf, count, &pos);
48426 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48427 set_fs(old_fs);
48428
48429 return res;
48430 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48431 goto err;
48432
48433 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48434 - vec[i].iov_base = (void __user *) page_address(page);
48435 + vec[i].iov_base = (void __force_user *) page_address(page);
48436 vec[i].iov_len = this_len;
48437 spd.pages[i] = page;
48438 spd.nr_pages++;
48439 @@ -846,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48440 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48441 {
48442 while (!pipe->nrbufs) {
48443 - if (!pipe->writers)
48444 + if (!atomic_read(&pipe->writers))
48445 return 0;
48446
48447 - if (!pipe->waiting_writers && sd->num_spliced)
48448 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48449 return 0;
48450
48451 if (sd->flags & SPLICE_F_NONBLOCK)
48452 @@ -1182,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48453 * out of the pipe right after the splice_to_pipe(). So set
48454 * PIPE_READERS appropriately.
48455 */
48456 - pipe->readers = 1;
48457 + atomic_set(&pipe->readers, 1);
48458
48459 current->splice_pipe = pipe;
48460 }
48461 @@ -1734,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48462 ret = -ERESTARTSYS;
48463 break;
48464 }
48465 - if (!pipe->writers)
48466 + if (!atomic_read(&pipe->writers))
48467 break;
48468 - if (!pipe->waiting_writers) {
48469 + if (!atomic_read(&pipe->waiting_writers)) {
48470 if (flags & SPLICE_F_NONBLOCK) {
48471 ret = -EAGAIN;
48472 break;
48473 @@ -1768,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48474 pipe_lock(pipe);
48475
48476 while (pipe->nrbufs >= pipe->buffers) {
48477 - if (!pipe->readers) {
48478 + if (!atomic_read(&pipe->readers)) {
48479 send_sig(SIGPIPE, current, 0);
48480 ret = -EPIPE;
48481 break;
48482 @@ -1781,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48483 ret = -ERESTARTSYS;
48484 break;
48485 }
48486 - pipe->waiting_writers++;
48487 + atomic_inc(&pipe->waiting_writers);
48488 pipe_wait(pipe);
48489 - pipe->waiting_writers--;
48490 + atomic_dec(&pipe->waiting_writers);
48491 }
48492
48493 pipe_unlock(pipe);
48494 @@ -1819,14 +1819,14 @@ retry:
48495 pipe_double_lock(ipipe, opipe);
48496
48497 do {
48498 - if (!opipe->readers) {
48499 + if (!atomic_read(&opipe->readers)) {
48500 send_sig(SIGPIPE, current, 0);
48501 if (!ret)
48502 ret = -EPIPE;
48503 break;
48504 }
48505
48506 - if (!ipipe->nrbufs && !ipipe->writers)
48507 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48508 break;
48509
48510 /*
48511 @@ -1923,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48512 pipe_double_lock(ipipe, opipe);
48513
48514 do {
48515 - if (!opipe->readers) {
48516 + if (!atomic_read(&opipe->readers)) {
48517 send_sig(SIGPIPE, current, 0);
48518 if (!ret)
48519 ret = -EPIPE;
48520 @@ -1968,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48521 * return EAGAIN if we have the potential of some data in the
48522 * future, otherwise just return 0
48523 */
48524 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48525 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48526 ret = -EAGAIN;
48527
48528 pipe_unlock(ipipe);
48529 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48530 index 7fdf6a7..e6cd8ad 100644
48531 --- a/fs/sysfs/dir.c
48532 +++ b/fs/sysfs/dir.c
48533 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48534 struct sysfs_dirent *sd;
48535 int rc;
48536
48537 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48538 + const char *parent_name = parent_sd->s_name;
48539 +
48540 + mode = S_IFDIR | S_IRWXU;
48541 +
48542 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48543 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48544 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48545 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48546 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48547 +#endif
48548 +
48549 /* allocate */
48550 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48551 if (!sd)
48552 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48553 index 779789a..f58193c 100644
48554 --- a/fs/sysfs/file.c
48555 +++ b/fs/sysfs/file.c
48556 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48557
48558 struct sysfs_open_dirent {
48559 atomic_t refcnt;
48560 - atomic_t event;
48561 + atomic_unchecked_t event;
48562 wait_queue_head_t poll;
48563 struct list_head buffers; /* goes through sysfs_buffer.list */
48564 };
48565 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48566 if (!sysfs_get_active(attr_sd))
48567 return -ENODEV;
48568
48569 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48570 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48571 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48572
48573 sysfs_put_active(attr_sd);
48574 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48575 return -ENOMEM;
48576
48577 atomic_set(&new_od->refcnt, 0);
48578 - atomic_set(&new_od->event, 1);
48579 + atomic_set_unchecked(&new_od->event, 1);
48580 init_waitqueue_head(&new_od->poll);
48581 INIT_LIST_HEAD(&new_od->buffers);
48582 goto retry;
48583 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48584
48585 sysfs_put_active(attr_sd);
48586
48587 - if (buffer->event != atomic_read(&od->event))
48588 + if (buffer->event != atomic_read_unchecked(&od->event))
48589 goto trigger;
48590
48591 return DEFAULT_POLLMASK;
48592 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48593
48594 od = sd->s_attr.open;
48595 if (od) {
48596 - atomic_inc(&od->event);
48597 + atomic_inc_unchecked(&od->event);
48598 wake_up_interruptible(&od->poll);
48599 }
48600
48601 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48602 index a7ac78f..02158e1 100644
48603 --- a/fs/sysfs/symlink.c
48604 +++ b/fs/sysfs/symlink.c
48605 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48606
48607 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48608 {
48609 - char *page = nd_get_link(nd);
48610 + const char *page = nd_get_link(nd);
48611 if (!IS_ERR(page))
48612 free_page((unsigned long)page);
48613 }
48614 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48615 index c175b4d..8f36a16 100644
48616 --- a/fs/udf/misc.c
48617 +++ b/fs/udf/misc.c
48618 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48619
48620 u8 udf_tag_checksum(const struct tag *t)
48621 {
48622 - u8 *data = (u8 *)t;
48623 + const u8 *data = (const u8 *)t;
48624 u8 checksum = 0;
48625 int i;
48626 for (i = 0; i < sizeof(struct tag); ++i)
48627 diff --git a/fs/utimes.c b/fs/utimes.c
48628 index ba653f3..06ea4b1 100644
48629 --- a/fs/utimes.c
48630 +++ b/fs/utimes.c
48631 @@ -1,6 +1,7 @@
48632 #include <linux/compiler.h>
48633 #include <linux/file.h>
48634 #include <linux/fs.h>
48635 +#include <linux/security.h>
48636 #include <linux/linkage.h>
48637 #include <linux/mount.h>
48638 #include <linux/namei.h>
48639 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48640 goto mnt_drop_write_and_out;
48641 }
48642 }
48643 +
48644 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48645 + error = -EACCES;
48646 + goto mnt_drop_write_and_out;
48647 + }
48648 +
48649 mutex_lock(&inode->i_mutex);
48650 error = notify_change(path->dentry, &newattrs);
48651 mutex_unlock(&inode->i_mutex);
48652 diff --git a/fs/xattr.c b/fs/xattr.c
48653 index 67583de..c5aad14 100644
48654 --- a/fs/xattr.c
48655 +++ b/fs/xattr.c
48656 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
48657 * Extended attribute SET operations
48658 */
48659 static long
48660 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
48661 +setxattr(struct path *path, const char __user *name, const void __user *value,
48662 size_t size, int flags)
48663 {
48664 int error;
48665 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
48666 return PTR_ERR(kvalue);
48667 }
48668
48669 - error = vfs_setxattr(d, kname, kvalue, size, flags);
48670 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
48671 + error = -EACCES;
48672 + goto out;
48673 + }
48674 +
48675 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
48676 +out:
48677 kfree(kvalue);
48678 return error;
48679 }
48680 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
48681 return error;
48682 error = mnt_want_write(path.mnt);
48683 if (!error) {
48684 - error = setxattr(path.dentry, name, value, size, flags);
48685 + error = setxattr(&path, name, value, size, flags);
48686 mnt_drop_write(path.mnt);
48687 }
48688 path_put(&path);
48689 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
48690 return error;
48691 error = mnt_want_write(path.mnt);
48692 if (!error) {
48693 - error = setxattr(path.dentry, name, value, size, flags);
48694 + error = setxattr(&path, name, value, size, flags);
48695 mnt_drop_write(path.mnt);
48696 }
48697 path_put(&path);
48698 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
48699 const void __user *,value, size_t, size, int, flags)
48700 {
48701 struct file *f;
48702 - struct dentry *dentry;
48703 int error = -EBADF;
48704
48705 f = fget(fd);
48706 if (!f)
48707 return error;
48708 - dentry = f->f_path.dentry;
48709 - audit_inode(NULL, dentry);
48710 + audit_inode(NULL, f->f_path.dentry);
48711 error = mnt_want_write_file(f);
48712 if (!error) {
48713 - error = setxattr(dentry, name, value, size, flags);
48714 + error = setxattr(&f->f_path, name, value, size, flags);
48715 mnt_drop_write(f->f_path.mnt);
48716 }
48717 fput(f);
48718 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
48719 index 8d5a506..7f62712 100644
48720 --- a/fs/xattr_acl.c
48721 +++ b/fs/xattr_acl.c
48722 @@ -17,8 +17,8 @@
48723 struct posix_acl *
48724 posix_acl_from_xattr(const void *value, size_t size)
48725 {
48726 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
48727 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
48728 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
48729 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
48730 int count;
48731 struct posix_acl *acl;
48732 struct posix_acl_entry *acl_e;
48733 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
48734 index d0ab788..827999b 100644
48735 --- a/fs/xfs/xfs_bmap.c
48736 +++ b/fs/xfs/xfs_bmap.c
48737 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
48738 int nmap,
48739 int ret_nmap);
48740 #else
48741 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
48742 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
48743 #endif /* DEBUG */
48744
48745 STATIC int
48746 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
48747 index 79d05e8..e3e5861 100644
48748 --- a/fs/xfs/xfs_dir2_sf.c
48749 +++ b/fs/xfs/xfs_dir2_sf.c
48750 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
48751 }
48752
48753 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
48754 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48755 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
48756 + char name[sfep->namelen];
48757 + memcpy(name, sfep->name, sfep->namelen);
48758 + if (filldir(dirent, name, sfep->namelen,
48759 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
48760 + *offset = off & 0x7fffffff;
48761 + return 0;
48762 + }
48763 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48764 off & 0x7fffffff, ino, DT_UNKNOWN)) {
48765 *offset = off & 0x7fffffff;
48766 return 0;
48767 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
48768 index d99a905..9f88202 100644
48769 --- a/fs/xfs/xfs_ioctl.c
48770 +++ b/fs/xfs/xfs_ioctl.c
48771 @@ -128,7 +128,7 @@ xfs_find_handle(
48772 }
48773
48774 error = -EFAULT;
48775 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
48776 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
48777 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
48778 goto out_put;
48779
48780 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
48781 index 23ce927..e274cc1 100644
48782 --- a/fs/xfs/xfs_iops.c
48783 +++ b/fs/xfs/xfs_iops.c
48784 @@ -447,7 +447,7 @@ xfs_vn_put_link(
48785 struct nameidata *nd,
48786 void *p)
48787 {
48788 - char *s = nd_get_link(nd);
48789 + const char *s = nd_get_link(nd);
48790
48791 if (!IS_ERR(s))
48792 kfree(s);
48793 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
48794 new file mode 100644
48795 index 0000000..4089e05
48796 --- /dev/null
48797 +++ b/grsecurity/Kconfig
48798 @@ -0,0 +1,1078 @@
48799 +#
48800 +# grecurity configuration
48801 +#
48802 +
48803 +menu "Grsecurity"
48804 +
48805 +config GRKERNSEC
48806 + bool "Grsecurity"
48807 + select CRYPTO
48808 + select CRYPTO_SHA256
48809 + help
48810 + If you say Y here, you will be able to configure many features
48811 + that will enhance the security of your system. It is highly
48812 + recommended that you say Y here and read through the help
48813 + for each option so that you fully understand the features and
48814 + can evaluate their usefulness for your machine.
48815 +
48816 +choice
48817 + prompt "Security Level"
48818 + depends on GRKERNSEC
48819 + default GRKERNSEC_CUSTOM
48820 +
48821 +config GRKERNSEC_LOW
48822 + bool "Low"
48823 + select GRKERNSEC_LINK
48824 + select GRKERNSEC_FIFO
48825 + select GRKERNSEC_RANDNET
48826 + select GRKERNSEC_DMESG
48827 + select GRKERNSEC_CHROOT
48828 + select GRKERNSEC_CHROOT_CHDIR
48829 +
48830 + help
48831 + If you choose this option, several of the grsecurity options will
48832 + be enabled that will give you greater protection against a number
48833 + of attacks, while assuring that none of your software will have any
48834 + conflicts with the additional security measures. If you run a lot
48835 + of unusual software, or you are having problems with the higher
48836 + security levels, you should say Y here. With this option, the
48837 + following features are enabled:
48838 +
48839 + - Linking restrictions
48840 + - FIFO restrictions
48841 + - Restricted dmesg
48842 + - Enforced chdir("/") on chroot
48843 + - Runtime module disabling
48844 +
48845 +config GRKERNSEC_MEDIUM
48846 + bool "Medium"
48847 + select PAX
48848 + select PAX_EI_PAX
48849 + select PAX_PT_PAX_FLAGS
48850 + select PAX_HAVE_ACL_FLAGS
48851 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48852 + select GRKERNSEC_CHROOT
48853 + select GRKERNSEC_CHROOT_SYSCTL
48854 + select GRKERNSEC_LINK
48855 + select GRKERNSEC_FIFO
48856 + select GRKERNSEC_DMESG
48857 + select GRKERNSEC_RANDNET
48858 + select GRKERNSEC_FORKFAIL
48859 + select GRKERNSEC_TIME
48860 + select GRKERNSEC_SIGNAL
48861 + select GRKERNSEC_CHROOT
48862 + select GRKERNSEC_CHROOT_UNIX
48863 + select GRKERNSEC_CHROOT_MOUNT
48864 + select GRKERNSEC_CHROOT_PIVOT
48865 + select GRKERNSEC_CHROOT_DOUBLE
48866 + select GRKERNSEC_CHROOT_CHDIR
48867 + select GRKERNSEC_CHROOT_MKNOD
48868 + select GRKERNSEC_PROC
48869 + select GRKERNSEC_PROC_USERGROUP
48870 + select PAX_RANDUSTACK
48871 + select PAX_ASLR
48872 + select PAX_RANDMMAP
48873 + select PAX_REFCOUNT if (X86 || SPARC64)
48874 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
48875 +
48876 + help
48877 + If you say Y here, several features in addition to those included
48878 + in the low additional security level will be enabled. These
48879 + features provide even more security to your system, though in rare
48880 + cases they may be incompatible with very old or poorly written
48881 + software. If you enable this option, make sure that your auth
48882 + service (identd) is running as gid 1001. With this option,
48883 + the following features (in addition to those provided in the
48884 + low additional security level) will be enabled:
48885 +
48886 + - Failed fork logging
48887 + - Time change logging
48888 + - Signal logging
48889 + - Deny mounts in chroot
48890 + - Deny double chrooting
48891 + - Deny sysctl writes in chroot
48892 + - Deny mknod in chroot
48893 + - Deny access to abstract AF_UNIX sockets out of chroot
48894 + - Deny pivot_root in chroot
48895 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
48896 + - /proc restrictions with special GID set to 10 (usually wheel)
48897 + - Address Space Layout Randomization (ASLR)
48898 + - Prevent exploitation of most refcount overflows
48899 + - Bounds checking of copying between the kernel and userland
48900 +
48901 +config GRKERNSEC_HIGH
48902 + bool "High"
48903 + select GRKERNSEC_LINK
48904 + select GRKERNSEC_FIFO
48905 + select GRKERNSEC_DMESG
48906 + select GRKERNSEC_FORKFAIL
48907 + select GRKERNSEC_TIME
48908 + select GRKERNSEC_SIGNAL
48909 + select GRKERNSEC_CHROOT
48910 + select GRKERNSEC_CHROOT_SHMAT
48911 + select GRKERNSEC_CHROOT_UNIX
48912 + select GRKERNSEC_CHROOT_MOUNT
48913 + select GRKERNSEC_CHROOT_FCHDIR
48914 + select GRKERNSEC_CHROOT_PIVOT
48915 + select GRKERNSEC_CHROOT_DOUBLE
48916 + select GRKERNSEC_CHROOT_CHDIR
48917 + select GRKERNSEC_CHROOT_MKNOD
48918 + select GRKERNSEC_CHROOT_CAPS
48919 + select GRKERNSEC_CHROOT_SYSCTL
48920 + select GRKERNSEC_CHROOT_FINDTASK
48921 + select GRKERNSEC_SYSFS_RESTRICT
48922 + select GRKERNSEC_PROC
48923 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48924 + select GRKERNSEC_HIDESYM
48925 + select GRKERNSEC_BRUTE
48926 + select GRKERNSEC_PROC_USERGROUP
48927 + select GRKERNSEC_KMEM
48928 + select GRKERNSEC_RESLOG
48929 + select GRKERNSEC_RANDNET
48930 + select GRKERNSEC_PROC_ADD
48931 + select GRKERNSEC_CHROOT_CHMOD
48932 + select GRKERNSEC_CHROOT_NICE
48933 + select GRKERNSEC_SETXID
48934 + select GRKERNSEC_AUDIT_MOUNT
48935 + select GRKERNSEC_MODHARDEN if (MODULES)
48936 + select GRKERNSEC_HARDEN_PTRACE
48937 + select GRKERNSEC_PTRACE_READEXEC
48938 + select GRKERNSEC_VM86 if (X86_32)
48939 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
48940 + select PAX
48941 + select PAX_RANDUSTACK
48942 + select PAX_ASLR
48943 + select PAX_RANDMMAP
48944 + select PAX_NOEXEC
48945 + select PAX_MPROTECT
48946 + select PAX_EI_PAX
48947 + select PAX_PT_PAX_FLAGS
48948 + select PAX_HAVE_ACL_FLAGS
48949 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
48950 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
48951 + select PAX_RANDKSTACK if (X86_TSC && X86)
48952 + select PAX_SEGMEXEC if (X86_32)
48953 + select PAX_PAGEEXEC
48954 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
48955 + select PAX_EMUTRAMP if (PARISC)
48956 + select PAX_EMUSIGRT if (PARISC)
48957 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
48958 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
48959 + select PAX_REFCOUNT if (X86 || SPARC64)
48960 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
48961 + help
48962 + If you say Y here, many of the features of grsecurity will be
48963 + enabled, which will protect you against many kinds of attacks
48964 + against your system. The heightened security comes at a cost
48965 + of an increased chance of incompatibilities with rare software
48966 + on your machine. Since this security level enables PaX, you should
48967 + view <http://pax.grsecurity.net> and read about the PaX
48968 + project. While you are there, download chpax and run it on
48969 + binaries that cause problems with PaX. Also remember that
48970 + since the /proc restrictions are enabled, you must run your
48971 + identd as gid 1001. This security level enables the following
48972 + features in addition to those listed in the low and medium
48973 + security levels:
48974 +
48975 + - Additional /proc restrictions
48976 + - Chmod restrictions in chroot
48977 + - No signals, ptrace, or viewing of processes outside of chroot
48978 + - Capability restrictions in chroot
48979 + - Deny fchdir out of chroot
48980 + - Priority restrictions in chroot
48981 + - Segmentation-based implementation of PaX
48982 + - Mprotect restrictions
48983 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
48984 + - Kernel stack randomization
48985 + - Mount/unmount/remount logging
48986 + - Kernel symbol hiding
48987 + - Hardening of module auto-loading
48988 + - Ptrace restrictions
48989 + - Restricted vm86 mode
48990 + - Restricted sysfs/debugfs
48991 + - Active kernel exploit response
48992 +
48993 +config GRKERNSEC_CUSTOM
48994 + bool "Custom"
48995 + help
48996 + If you say Y here, you will be able to configure every grsecurity
48997 + option, which allows you to enable many more features that aren't
48998 + covered in the basic security levels. These additional features
48999 + include TPE, socket restrictions, and the sysctl system for
49000 + grsecurity. It is advised that you read through the help for
49001 + each option to determine its usefulness in your situation.
49002 +
49003 +endchoice
49004 +
49005 +menu "Memory Protections"
49006 +depends on GRKERNSEC
49007 +
49008 +config GRKERNSEC_KMEM
49009 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49010 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49011 + help
49012 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49013 + be written to or read from to modify or leak the contents of the running
49014 + kernel. /dev/port will also not be allowed to be opened. If you have module
49015 + support disabled, enabling this will close up four ways that are
49016 + currently used to insert malicious code into the running kernel.
49017 + Even with all these features enabled, we still highly recommend that
49018 + you use the RBAC system, as it is still possible for an attacker to
49019 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49020 + If you are not using XFree86, you may be able to stop this additional
49021 + case by enabling the 'Disable privileged I/O' option. Though nothing
49022 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49023 + but only to video memory, which is the only writing we allow in this
49024 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49025 + not be allowed to mprotect it with PROT_WRITE later.
49026 + It is highly recommended that you say Y here if you meet all the
49027 + conditions above.
49028 +
49029 +config GRKERNSEC_VM86
49030 + bool "Restrict VM86 mode"
49031 + depends on X86_32
49032 +
49033 + help
49034 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49035 + make use of a special execution mode on 32bit x86 processors called
49036 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49037 + video cards and will still work with this option enabled. The purpose
49038 + of the option is to prevent exploitation of emulation errors in
49039 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49040 + Nearly all users should be able to enable this option.
49041 +
49042 +config GRKERNSEC_IO
49043 + bool "Disable privileged I/O"
49044 + depends on X86
49045 + select RTC_CLASS
49046 + select RTC_INTF_DEV
49047 + select RTC_DRV_CMOS
49048 +
49049 + help
49050 + If you say Y here, all ioperm and iopl calls will return an error.
49051 + Ioperm and iopl can be used to modify the running kernel.
49052 + Unfortunately, some programs need this access to operate properly,
49053 + the most notable of which are XFree86 and hwclock. hwclock can be
49054 + remedied by having RTC support in the kernel, so real-time
49055 + clock support is enabled if this option is enabled, to ensure
49056 + that hwclock operates correctly. XFree86 still will not
49057 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49058 + IF YOU USE XFree86. If you use XFree86 and you still want to
49059 + protect your kernel against modification, use the RBAC system.
49060 +
49061 +config GRKERNSEC_PROC_MEMMAP
49062 + bool "Harden ASLR against information leaks and entropy reduction"
49063 + default y if (PAX_NOEXEC || PAX_ASLR)
49064 + depends on PAX_NOEXEC || PAX_ASLR
49065 + help
49066 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49067 + give no information about the addresses of its mappings if
49068 + PaX features that rely on random addresses are enabled on the task.
49069 + In addition to sanitizing this information and disabling other
49070 + dangerous sources of information, this option causes reads of sensitive
49071 + /proc/<pid> entries where the file descriptor was opened in a different
49072 + task than the one performing the read. Such attempts are logged.
49073 + This option also limits argv/env strings for suid/sgid binaries
49074 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49075 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49076 + binaries to prevent alternative mmap layouts from being abused.
49077 +
49078 + If you use PaX it is essential that you say Y here as it closes up
49079 + several holes that make full ASLR useless locally.
49080 +
49081 +config GRKERNSEC_BRUTE
49082 + bool "Deter exploit bruteforcing"
49083 + help
49084 + If you say Y here, attempts to bruteforce exploits against forking
49085 + daemons such as apache or sshd, as well as against suid/sgid binaries
49086 + will be deterred. When a child of a forking daemon is killed by PaX
49087 + or crashes due to an illegal instruction or other suspicious signal,
49088 + the parent process will be delayed 30 seconds upon every subsequent
49089 + fork until the administrator is able to assess the situation and
49090 + restart the daemon.
49091 + In the suid/sgid case, the attempt is logged, the user has all their
49092 + processes terminated, and they are prevented from executing any further
49093 + processes for 15 minutes.
49094 + It is recommended that you also enable signal logging in the auditing
49095 + section so that logs are generated when a process triggers a suspicious
49096 + signal.
49097 + If the sysctl option is enabled, a sysctl option with name
49098 + "deter_bruteforce" is created.
49099 +
49100 +
49101 +config GRKERNSEC_MODHARDEN
49102 + bool "Harden module auto-loading"
49103 + depends on MODULES
49104 + help
49105 + If you say Y here, module auto-loading in response to use of some
49106 + feature implemented by an unloaded module will be restricted to
49107 + root users. Enabling this option helps defend against attacks
49108 + by unprivileged users who abuse the auto-loading behavior to
49109 + cause a vulnerable module to load that is then exploited.
49110 +
49111 + If this option prevents a legitimate use of auto-loading for a
49112 + non-root user, the administrator can execute modprobe manually
49113 + with the exact name of the module mentioned in the alert log.
49114 + Alternatively, the administrator can add the module to the list
49115 + of modules loaded at boot by modifying init scripts.
49116 +
49117 + Modification of init scripts will most likely be needed on
49118 + Ubuntu servers with encrypted home directory support enabled,
49119 + as the first non-root user logging in will cause the ecb(aes),
49120 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49121 +
49122 +config GRKERNSEC_HIDESYM
49123 + bool "Hide kernel symbols"
49124 + help
49125 + If you say Y here, getting information on loaded modules, and
49126 + displaying all kernel symbols through a syscall will be restricted
49127 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49128 + /proc/kallsyms will be restricted to the root user. The RBAC
49129 + system can hide that entry even from root.
49130 +
49131 + This option also prevents leaking of kernel addresses through
49132 + several /proc entries.
49133 +
49134 + Note that this option is only effective provided the following
49135 + conditions are met:
49136 + 1) The kernel using grsecurity is not precompiled by some distribution
49137 + 2) You have also enabled GRKERNSEC_DMESG
49138 + 3) You are using the RBAC system and hiding other files such as your
49139 + kernel image and System.map. Alternatively, enabling this option
49140 + causes the permissions on /boot, /lib/modules, and the kernel
49141 + source directory to change at compile time to prevent
49142 + reading by non-root users.
49143 + If the above conditions are met, this option will aid in providing a
49144 + useful protection against local kernel exploitation of overflows
49145 + and arbitrary read/write vulnerabilities.
49146 +
49147 +config GRKERNSEC_KERN_LOCKOUT
49148 + bool "Active kernel exploit response"
49149 + depends on X86 || ARM || PPC || SPARC
49150 + help
49151 + If you say Y here, when a PaX alert is triggered due to suspicious
49152 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49153 + or an OOPs occurs due to bad memory accesses, instead of just
49154 + terminating the offending process (and potentially allowing
49155 + a subsequent exploit from the same user), we will take one of two
49156 + actions:
49157 + If the user was root, we will panic the system
49158 + If the user was non-root, we will log the attempt, terminate
49159 + all processes owned by the user, then prevent them from creating
49160 + any new processes until the system is restarted
49161 + This deters repeated kernel exploitation/bruteforcing attempts
49162 + and is useful for later forensics.
49163 +
49164 +endmenu
49165 +menu "Role Based Access Control Options"
49166 +depends on GRKERNSEC
49167 +
49168 +config GRKERNSEC_RBAC_DEBUG
49169 + bool
49170 +
49171 +config GRKERNSEC_NO_RBAC
49172 + bool "Disable RBAC system"
49173 + help
49174 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49175 + preventing the RBAC system from being enabled. You should only say Y
49176 + here if you have no intention of using the RBAC system, so as to prevent
49177 + an attacker with root access from misusing the RBAC system to hide files
49178 + and processes when loadable module support and /dev/[k]mem have been
49179 + locked down.
49180 +
49181 +config GRKERNSEC_ACL_HIDEKERN
49182 + bool "Hide kernel processes"
49183 + help
49184 + If you say Y here, all kernel threads will be hidden to all
49185 + processes but those whose subject has the "view hidden processes"
49186 + flag.
49187 +
49188 +config GRKERNSEC_ACL_MAXTRIES
49189 + int "Maximum tries before password lockout"
49190 + default 3
49191 + help
49192 + This option enforces the maximum number of times a user can attempt
49193 + to authorize themselves with the grsecurity RBAC system before being
49194 + denied the ability to attempt authorization again for a specified time.
49195 + The lower the number, the harder it will be to brute-force a password.
49196 +
49197 +config GRKERNSEC_ACL_TIMEOUT
49198 + int "Time to wait after max password tries, in seconds"
49199 + default 30
49200 + help
49201 + This option specifies the time the user must wait after attempting to
49202 + authorize to the RBAC system with the maximum number of invalid
49203 + passwords. The higher the number, the harder it will be to brute-force
49204 + a password.
49205 +
49206 +endmenu
49207 +menu "Filesystem Protections"
49208 +depends on GRKERNSEC
49209 +
49210 +config GRKERNSEC_PROC
49211 + bool "Proc restrictions"
49212 + help
49213 + If you say Y here, the permissions of the /proc filesystem
49214 + will be altered to enhance system security and privacy. You MUST
49215 + choose either a user only restriction or a user and group restriction.
49216 + Depending upon the option you choose, you can either restrict users to
49217 + see only the processes they themselves run, or choose a group that can
49218 + view all processes and files normally restricted to root if you choose
49219 + the "restrict to user only" option. NOTE: If you're running identd or
49220 + ntpd as a non-root user, you will have to run it as the group you
49221 + specify here.
49222 +
49223 +config GRKERNSEC_PROC_USER
49224 + bool "Restrict /proc to user only"
49225 + depends on GRKERNSEC_PROC
49226 + help
49227 + If you say Y here, non-root users will only be able to view their own
49228 + processes, and restricts them from viewing network-related information,
49229 + and viewing kernel symbol and module information.
49230 +
49231 +config GRKERNSEC_PROC_USERGROUP
49232 + bool "Allow special group"
49233 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49234 + help
49235 + If you say Y here, you will be able to select a group that will be
49236 + able to view all processes and network-related information. If you've
49237 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49238 + remain hidden. This option is useful if you want to run identd as
49239 + a non-root user.
49240 +
49241 +config GRKERNSEC_PROC_GID
49242 + int "GID for special group"
49243 + depends on GRKERNSEC_PROC_USERGROUP
49244 + default 1001
49245 +
49246 +config GRKERNSEC_PROC_ADD
49247 + bool "Additional restrictions"
49248 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49249 + help
49250 + If you say Y here, additional restrictions will be placed on
49251 + /proc that keep normal users from viewing device information and
49252 + slabinfo information that could be useful for exploits.
49253 +
49254 +config GRKERNSEC_LINK
49255 + bool "Linking restrictions"
49256 + help
49257 + If you say Y here, /tmp race exploits will be prevented, since users
49258 + will no longer be able to follow symlinks owned by other users in
49259 + world-writable +t directories (e.g. /tmp), unless the owner of the
49260 + symlink is the owner of the directory. users will also not be
49261 + able to hardlink to files they do not own. If the sysctl option is
49262 + enabled, a sysctl option with name "linking_restrictions" is created.
49263 +
49264 +config GRKERNSEC_FIFO
49265 + bool "FIFO restrictions"
49266 + help
49267 + If you say Y here, users will not be able to write to FIFOs they don't
49268 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49269 + the FIFO is the same owner of the directory it's held in. If the sysctl
49270 + option is enabled, a sysctl option with name "fifo_restrictions" is
49271 + created.
49272 +
49273 +config GRKERNSEC_SYSFS_RESTRICT
49274 + bool "Sysfs/debugfs restriction"
49275 + depends on SYSFS
49276 + help
49277 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49278 + any filesystem normally mounted under it (e.g. debugfs) will be
49279 + mostly accessible only by root. These filesystems generally provide access
49280 + to hardware and debug information that isn't appropriate for unprivileged
49281 + users of the system. Sysfs and debugfs have also become a large source
49282 + of new vulnerabilities, ranging from infoleaks to local compromise.
49283 + There has been very little oversight with an eye toward security involved
49284 + in adding new exporters of information to these filesystems, so their
49285 + use is discouraged.
49286 + For reasons of compatibility, a few directories have been whitelisted
49287 + for access by non-root users:
49288 + /sys/fs/selinux
49289 + /sys/fs/fuse
49290 + /sys/devices/system/cpu
49291 +
49292 +config GRKERNSEC_ROFS
49293 + bool "Runtime read-only mount protection"
49294 + help
49295 + If you say Y here, a sysctl option with name "romount_protect" will
49296 + be created. By setting this option to 1 at runtime, filesystems
49297 + will be protected in the following ways:
49298 + * No new writable mounts will be allowed
49299 + * Existing read-only mounts won't be able to be remounted read/write
49300 + * Write operations will be denied on all block devices
49301 + This option acts independently of grsec_lock: once it is set to 1,
49302 + it cannot be turned off. Therefore, please be mindful of the resulting
49303 + behavior if this option is enabled in an init script on a read-only
49304 + filesystem. This feature is mainly intended for secure embedded systems.
49305 +
49306 +config GRKERNSEC_CHROOT
49307 + bool "Chroot jail restrictions"
49308 + help
49309 + If you say Y here, you will be able to choose several options that will
49310 + make breaking out of a chrooted jail much more difficult. If you
49311 + encounter no software incompatibilities with the following options, it
49312 + is recommended that you enable each one.
49313 +
49314 +config GRKERNSEC_CHROOT_MOUNT
49315 + bool "Deny mounts"
49316 + depends on GRKERNSEC_CHROOT
49317 + help
49318 + If you say Y here, processes inside a chroot will not be able to
49319 + mount or remount filesystems. If the sysctl option is enabled, a
49320 + sysctl option with name "chroot_deny_mount" is created.
49321 +
49322 +config GRKERNSEC_CHROOT_DOUBLE
49323 + bool "Deny double-chroots"
49324 + depends on GRKERNSEC_CHROOT
49325 + help
49326 + If you say Y here, processes inside a chroot will not be able to chroot
49327 + again outside the chroot. This is a widely used method of breaking
49328 + out of a chroot jail and should not be allowed. If the sysctl
49329 + option is enabled, a sysctl option with name
49330 + "chroot_deny_chroot" is created.
49331 +
49332 +config GRKERNSEC_CHROOT_PIVOT
49333 + bool "Deny pivot_root in chroot"
49334 + depends on GRKERNSEC_CHROOT
49335 + help
49336 + If you say Y here, processes inside a chroot will not be able to use
49337 + a function called pivot_root() that was introduced in Linux 2.3.41. It
49338 + works similar to chroot in that it changes the root filesystem. This
49339 + function could be misused in a chrooted process to attempt to break out
49340 + of the chroot, and therefore should not be allowed. If the sysctl
49341 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
49342 + created.
49343 +
49344 +config GRKERNSEC_CHROOT_CHDIR
49345 + bool "Enforce chdir(\"/\") on all chroots"
49346 + depends on GRKERNSEC_CHROOT
49347 + help
49348 + If you say Y here, the current working directory of all newly-chrooted
49349 + applications will be set to the the root directory of the chroot.
49350 + The man page on chroot(2) states:
49351 + Note that this call does not change the current working
49352 + directory, so that `.' can be outside the tree rooted at
49353 + `/'. In particular, the super-user can escape from a
49354 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49355 +
49356 + It is recommended that you say Y here, since it's not known to break
49357 + any software. If the sysctl option is enabled, a sysctl option with
49358 + name "chroot_enforce_chdir" is created.
49359 +
49360 +config GRKERNSEC_CHROOT_CHMOD
49361 + bool "Deny (f)chmod +s"
49362 + depends on GRKERNSEC_CHROOT
49363 + help
49364 + If you say Y here, processes inside a chroot will not be able to chmod
49365 + or fchmod files to make them have suid or sgid bits. This protects
49366 + against another published method of breaking a chroot. If the sysctl
49367 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
49368 + created.
49369 +
49370 +config GRKERNSEC_CHROOT_FCHDIR
49371 + bool "Deny fchdir out of chroot"
49372 + depends on GRKERNSEC_CHROOT
49373 + help
49374 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
49375 + to a file descriptor of the chrooting process that points to a directory
49376 + outside the filesystem will be stopped. If the sysctl option
49377 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49378 +
49379 +config GRKERNSEC_CHROOT_MKNOD
49380 + bool "Deny mknod"
49381 + depends on GRKERNSEC_CHROOT
49382 + help
49383 + If you say Y here, processes inside a chroot will not be allowed to
49384 + mknod. The problem with using mknod inside a chroot is that it
49385 + would allow an attacker to create a device entry that is the same
49386 + as one on the physical root of your system, which could range from
49387 + anything from the console device to a device for your harddrive (which
49388 + they could then use to wipe the drive or steal data). It is recommended
49389 + that you say Y here, unless you run into software incompatibilities.
49390 + If the sysctl option is enabled, a sysctl option with name
49391 + "chroot_deny_mknod" is created.
49392 +
49393 +config GRKERNSEC_CHROOT_SHMAT
49394 + bool "Deny shmat() out of chroot"
49395 + depends on GRKERNSEC_CHROOT
49396 + help
49397 + If you say Y here, processes inside a chroot will not be able to attach
49398 + to shared memory segments that were created outside of the chroot jail.
49399 + It is recommended that you say Y here. If the sysctl option is enabled,
49400 + a sysctl option with name "chroot_deny_shmat" is created.
49401 +
49402 +config GRKERNSEC_CHROOT_UNIX
49403 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
49404 + depends on GRKERNSEC_CHROOT
49405 + help
49406 + If you say Y here, processes inside a chroot will not be able to
49407 + connect to abstract (meaning not belonging to a filesystem) Unix
49408 + domain sockets that were bound outside of a chroot. It is recommended
49409 + that you say Y here. If the sysctl option is enabled, a sysctl option
49410 + with name "chroot_deny_unix" is created.
49411 +
49412 +config GRKERNSEC_CHROOT_FINDTASK
49413 + bool "Protect outside processes"
49414 + depends on GRKERNSEC_CHROOT
49415 + help
49416 + If you say Y here, processes inside a chroot will not be able to
49417 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49418 + getsid, or view any process outside of the chroot. If the sysctl
49419 + option is enabled, a sysctl option with name "chroot_findtask" is
49420 + created.
49421 +
49422 +config GRKERNSEC_CHROOT_NICE
49423 + bool "Restrict priority changes"
49424 + depends on GRKERNSEC_CHROOT
49425 + help
49426 + If you say Y here, processes inside a chroot will not be able to raise
49427 + the priority of processes in the chroot, or alter the priority of
49428 + processes outside the chroot. This provides more security than simply
49429 + removing CAP_SYS_NICE from the process' capability set. If the
49430 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49431 + is created.
49432 +
49433 +config GRKERNSEC_CHROOT_SYSCTL
49434 + bool "Deny sysctl writes"
49435 + depends on GRKERNSEC_CHROOT
49436 + help
49437 + If you say Y here, an attacker in a chroot will not be able to
49438 + write to sysctl entries, either by sysctl(2) or through a /proc
49439 + interface. It is strongly recommended that you say Y here. If the
49440 + sysctl option is enabled, a sysctl option with name
49441 + "chroot_deny_sysctl" is created.
49442 +
49443 +config GRKERNSEC_CHROOT_CAPS
49444 + bool "Capability restrictions"
49445 + depends on GRKERNSEC_CHROOT
49446 + help
49447 + If you say Y here, the capabilities on all processes within a
49448 + chroot jail will be lowered to stop module insertion, raw i/o,
49449 + system and net admin tasks, rebooting the system, modifying immutable
49450 + files, modifying IPC owned by another, and changing the system time.
49451 + This is left an option because it can break some apps. Disable this
49452 + if your chrooted apps are having problems performing those kinds of
49453 + tasks. If the sysctl option is enabled, a sysctl option with
49454 + name "chroot_caps" is created.
49455 +
49456 +endmenu
49457 +menu "Kernel Auditing"
49458 +depends on GRKERNSEC
49459 +
49460 +config GRKERNSEC_AUDIT_GROUP
49461 + bool "Single group for auditing"
49462 + help
49463 + If you say Y here, the exec, chdir, and (un)mount logging features
49464 + will only operate on a group you specify. This option is recommended
49465 + if you only want to watch certain users instead of having a large
49466 + amount of logs from the entire system. If the sysctl option is enabled,
49467 + a sysctl option with name "audit_group" is created.
49468 +
49469 +config GRKERNSEC_AUDIT_GID
49470 + int "GID for auditing"
49471 + depends on GRKERNSEC_AUDIT_GROUP
49472 + default 1007
49473 +
49474 +config GRKERNSEC_EXECLOG
49475 + bool "Exec logging"
49476 + help
49477 + If you say Y here, all execve() calls will be logged (since the
49478 + other exec*() calls are frontends to execve(), all execution
49479 + will be logged). Useful for shell-servers that like to keep track
49480 + of their users. If the sysctl option is enabled, a sysctl option with
49481 + name "exec_logging" is created.
49482 + WARNING: This option when enabled will produce a LOT of logs, especially
49483 + on an active system.
49484 +
49485 +config GRKERNSEC_RESLOG
49486 + bool "Resource logging"
49487 + help
49488 + If you say Y here, all attempts to overstep resource limits will
49489 + be logged with the resource name, the requested size, and the current
49490 + limit. It is highly recommended that you say Y here. If the sysctl
49491 + option is enabled, a sysctl option with name "resource_logging" is
49492 + created. If the RBAC system is enabled, the sysctl value is ignored.
49493 +
49494 +config GRKERNSEC_CHROOT_EXECLOG
49495 + bool "Log execs within chroot"
49496 + help
49497 + If you say Y here, all executions inside a chroot jail will be logged
49498 + to syslog. This can cause a large amount of logs if certain
49499 + applications (eg. djb's daemontools) are installed on the system, and
49500 + is therefore left as an option. If the sysctl option is enabled, a
49501 + sysctl option with name "chroot_execlog" is created.
49502 +
49503 +config GRKERNSEC_AUDIT_PTRACE
49504 + bool "Ptrace logging"
49505 + help
49506 + If you say Y here, all attempts to attach to a process via ptrace
49507 + will be logged. If the sysctl option is enabled, a sysctl option
49508 + with name "audit_ptrace" is created.
49509 +
49510 +config GRKERNSEC_AUDIT_CHDIR
49511 + bool "Chdir logging"
49512 + help
49513 + If you say Y here, all chdir() calls will be logged. If the sysctl
49514 + option is enabled, a sysctl option with name "audit_chdir" is created.
49515 +
49516 +config GRKERNSEC_AUDIT_MOUNT
49517 + bool "(Un)Mount logging"
49518 + help
49519 + If you say Y here, all mounts and unmounts will be logged. If the
49520 + sysctl option is enabled, a sysctl option with name "audit_mount" is
49521 + created.
49522 +
49523 +config GRKERNSEC_SIGNAL
49524 + bool "Signal logging"
49525 + help
49526 + If you say Y here, certain important signals will be logged, such as
49527 + SIGSEGV, which will as a result inform you of when a error in a program
49528 + occurred, which in some cases could mean a possible exploit attempt.
49529 + If the sysctl option is enabled, a sysctl option with name
49530 + "signal_logging" is created.
49531 +
49532 +config GRKERNSEC_FORKFAIL
49533 + bool "Fork failure logging"
49534 + help
49535 + If you say Y here, all failed fork() attempts will be logged.
49536 + This could suggest a fork bomb, or someone attempting to overstep
49537 + their process limit. If the sysctl option is enabled, a sysctl option
49538 + with name "forkfail_logging" is created.
49539 +
49540 +config GRKERNSEC_TIME
49541 + bool "Time change logging"
49542 + help
49543 + If you say Y here, any changes of the system clock will be logged.
49544 + If the sysctl option is enabled, a sysctl option with name
49545 + "timechange_logging" is created.
49546 +
49547 +config GRKERNSEC_PROC_IPADDR
49548 + bool "/proc/<pid>/ipaddr support"
49549 + help
49550 + If you say Y here, a new entry will be added to each /proc/<pid>
49551 + directory that contains the IP address of the person using the task.
49552 + The IP is carried across local TCP and AF_UNIX stream sockets.
49553 + This information can be useful for IDS/IPSes to perform remote response
49554 + to a local attack. The entry is readable by only the owner of the
49555 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49556 + the RBAC system), and thus does not create privacy concerns.
49557 +
49558 +config GRKERNSEC_RWXMAP_LOG
49559 + bool 'Denied RWX mmap/mprotect logging'
49560 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49561 + help
49562 + If you say Y here, calls to mmap() and mprotect() with explicit
49563 + usage of PROT_WRITE and PROT_EXEC together will be logged when
49564 + denied by the PAX_MPROTECT feature. If the sysctl option is
49565 + enabled, a sysctl option with name "rwxmap_logging" is created.
49566 +
49567 +config GRKERNSEC_AUDIT_TEXTREL
49568 + bool 'ELF text relocations logging (READ HELP)'
49569 + depends on PAX_MPROTECT
49570 + help
49571 + If you say Y here, text relocations will be logged with the filename
49572 + of the offending library or binary. The purpose of the feature is
49573 + to help Linux distribution developers get rid of libraries and
49574 + binaries that need text relocations which hinder the future progress
49575 + of PaX. Only Linux distribution developers should say Y here, and
49576 + never on a production machine, as this option creates an information
49577 + leak that could aid an attacker in defeating the randomization of
49578 + a single memory region. If the sysctl option is enabled, a sysctl
49579 + option with name "audit_textrel" is created.
49580 +
49581 +endmenu
49582 +
49583 +menu "Executable Protections"
49584 +depends on GRKERNSEC
49585 +
49586 +config GRKERNSEC_DMESG
49587 + bool "Dmesg(8) restriction"
49588 + help
49589 + If you say Y here, non-root users will not be able to use dmesg(8)
49590 + to view up to the last 4kb of messages in the kernel's log buffer.
49591 + The kernel's log buffer often contains kernel addresses and other
49592 + identifying information useful to an attacker in fingerprinting a
49593 + system for a targeted exploit.
49594 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
49595 + created.
49596 +
49597 +config GRKERNSEC_HARDEN_PTRACE
49598 + bool "Deter ptrace-based process snooping"
49599 + help
49600 + If you say Y here, TTY sniffers and other malicious monitoring
49601 + programs implemented through ptrace will be defeated. If you
49602 + have been using the RBAC system, this option has already been
49603 + enabled for several years for all users, with the ability to make
49604 + fine-grained exceptions.
49605 +
49606 + This option only affects the ability of non-root users to ptrace
49607 + processes that are not a descendent of the ptracing process.
49608 + This means that strace ./binary and gdb ./binary will still work,
49609 + but attaching to arbitrary processes will not. If the sysctl
49610 + option is enabled, a sysctl option with name "harden_ptrace" is
49611 + created.
49612 +
49613 +config GRKERNSEC_PTRACE_READEXEC
49614 + bool "Require read access to ptrace sensitive binaries"
49615 + help
49616 + If you say Y here, unprivileged users will not be able to ptrace unreadable
49617 + binaries. This option is useful in environments that
49618 + remove the read bits (e.g. file mode 4711) from suid binaries to
49619 + prevent infoleaking of their contents. This option adds
49620 + consistency to the use of that file mode, as the binary could normally
49621 + be read out when run without privileges while ptracing.
49622 +
49623 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49624 + is created.
49625 +
49626 +config GRKERNSEC_SETXID
49627 + bool "Enforce consistent multithreaded privileges"
49628 + help
49629 + If you say Y here, a change from a root uid to a non-root uid
49630 + in a multithreaded application will cause the resulting uids,
49631 + gids, supplementary groups, and capabilities in that thread
49632 + to be propagated to the other threads of the process. In most
49633 + cases this is unnecessary, as glibc will emulate this behavior
49634 + on behalf of the application. Other libcs do not act in the
49635 + same way, allowing the other threads of the process to continue
49636 + running with root privileges. If the sysctl option is enabled,
49637 + a sysctl option with name "consistent_setxid" is created.
49638 +
49639 +config GRKERNSEC_TPE
49640 + bool "Trusted Path Execution (TPE)"
49641 + help
49642 + If you say Y here, you will be able to choose a gid to add to the
49643 + supplementary groups of users you want to mark as "untrusted."
49644 + These users will not be able to execute any files that are not in
49645 + root-owned directories writable only by root. If the sysctl option
49646 + is enabled, a sysctl option with name "tpe" is created.
49647 +
49648 +config GRKERNSEC_TPE_ALL
49649 + bool "Partially restrict all non-root users"
49650 + depends on GRKERNSEC_TPE
49651 + help
49652 + If you say Y here, all non-root users will be covered under
49653 + a weaker TPE restriction. This is separate from, and in addition to,
49654 + the main TPE options that you have selected elsewhere. Thus, if a
49655 + "trusted" GID is chosen, this restriction applies to even that GID.
49656 + Under this restriction, all non-root users will only be allowed to
49657 + execute files in directories they own that are not group or
49658 + world-writable, or in directories owned by root and writable only by
49659 + root. If the sysctl option is enabled, a sysctl option with name
49660 + "tpe_restrict_all" is created.
49661 +
49662 +config GRKERNSEC_TPE_INVERT
49663 + bool "Invert GID option"
49664 + depends on GRKERNSEC_TPE
49665 + help
49666 + If you say Y here, the group you specify in the TPE configuration will
49667 + decide what group TPE restrictions will be *disabled* for. This
49668 + option is useful if you want TPE restrictions to be applied to most
49669 + users on the system. If the sysctl option is enabled, a sysctl option
49670 + with name "tpe_invert" is created. Unlike other sysctl options, this
49671 + entry will default to on for backward-compatibility.
49672 +
49673 +config GRKERNSEC_TPE_GID
49674 + int "GID for untrusted users"
49675 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49676 + default 1005
49677 + help
49678 + Setting this GID determines what group TPE restrictions will be
49679 + *enabled* for. If the sysctl option is enabled, a sysctl option
49680 + with name "tpe_gid" is created.
49681 +
49682 +config GRKERNSEC_TPE_GID
49683 + int "GID for trusted users"
49684 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49685 + default 1005
49686 + help
49687 + Setting this GID determines what group TPE restrictions will be
49688 + *disabled* for. If the sysctl option is enabled, a sysctl option
49689 + with name "tpe_gid" is created.
49690 +
49691 +endmenu
49692 +menu "Network Protections"
49693 +depends on GRKERNSEC
49694 +
49695 +config GRKERNSEC_RANDNET
49696 + bool "Larger entropy pools"
49697 + help
49698 + If you say Y here, the entropy pools used for many features of Linux
49699 + and grsecurity will be doubled in size. Since several grsecurity
49700 + features use additional randomness, it is recommended that you say Y
49701 + here. Saying Y here has a similar effect as modifying
49702 + /proc/sys/kernel/random/poolsize.
49703 +
49704 +config GRKERNSEC_BLACKHOLE
49705 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
49706 + depends on NET
49707 + help
49708 + If you say Y here, neither TCP resets nor ICMP
49709 + destination-unreachable packets will be sent in response to packets
49710 + sent to ports for which no associated listening process exists.
49711 + This feature supports both IPV4 and IPV6 and exempts the
49712 + loopback interface from blackholing. Enabling this feature
49713 + makes a host more resilient to DoS attacks and reduces network
49714 + visibility against scanners.
49715 +
49716 + The blackhole feature as-implemented is equivalent to the FreeBSD
49717 + blackhole feature, as it prevents RST responses to all packets, not
49718 + just SYNs. Under most application behavior this causes no
49719 + problems, but applications (like haproxy) may not close certain
49720 + connections in a way that cleanly terminates them on the remote
49721 + end, leaving the remote host in LAST_ACK state. Because of this
49722 + side-effect and to prevent intentional LAST_ACK DoSes, this
49723 + feature also adds automatic mitigation against such attacks.
49724 + The mitigation drastically reduces the amount of time a socket
49725 + can spend in LAST_ACK state. If you're using haproxy and not
49726 + all servers it connects to have this option enabled, consider
49727 + disabling this feature on the haproxy host.
49728 +
49729 + If the sysctl option is enabled, two sysctl options with names
49730 + "ip_blackhole" and "lastack_retries" will be created.
49731 + While "ip_blackhole" takes the standard zero/non-zero on/off
49732 + toggle, "lastack_retries" uses the same kinds of values as
49733 + "tcp_retries1" and "tcp_retries2". The default value of 4
49734 + prevents a socket from lasting more than 45 seconds in LAST_ACK
49735 + state.
49736 +
49737 +config GRKERNSEC_SOCKET
49738 + bool "Socket restrictions"
49739 + depends on NET
49740 + help
49741 + If you say Y here, you will be able to choose from several options.
49742 + If you assign a GID on your system and add it to the supplementary
49743 + groups of users you want to restrict socket access to, this patch
49744 + will perform up to three things, based on the option(s) you choose.
49745 +
49746 +config GRKERNSEC_SOCKET_ALL
49747 + bool "Deny any sockets to group"
49748 + depends on GRKERNSEC_SOCKET
49749 + help
49750 + If you say Y here, you will be able to choose a GID of whose users will
49751 + be unable to connect to other hosts from your machine or run server
49752 + applications from your machine. If the sysctl option is enabled, a
49753 + sysctl option with name "socket_all" is created.
49754 +
49755 +config GRKERNSEC_SOCKET_ALL_GID
49756 + int "GID to deny all sockets for"
49757 + depends on GRKERNSEC_SOCKET_ALL
49758 + default 1004
49759 + help
49760 + Here you can choose the GID to disable socket access for. Remember to
49761 + add the users you want socket access disabled for to the GID
49762 + specified here. If the sysctl option is enabled, a sysctl option
49763 + with name "socket_all_gid" is created.
49764 +
49765 +config GRKERNSEC_SOCKET_CLIENT
49766 + bool "Deny client sockets to group"
49767 + depends on GRKERNSEC_SOCKET
49768 + help
49769 + If you say Y here, you will be able to choose a GID of whose users will
49770 + be unable to connect to other hosts from your machine, but will be
49771 + able to run servers. If this option is enabled, all users in the group
49772 + you specify will have to use passive mode when initiating ftp transfers
49773 + from the shell on your machine. If the sysctl option is enabled, a
49774 + sysctl option with name "socket_client" is created.
49775 +
49776 +config GRKERNSEC_SOCKET_CLIENT_GID
49777 + int "GID to deny client sockets for"
49778 + depends on GRKERNSEC_SOCKET_CLIENT
49779 + default 1003
49780 + help
49781 + Here you can choose the GID to disable client socket access for.
49782 + Remember to add the users you want client socket access disabled for to
49783 + the GID specified here. If the sysctl option is enabled, a sysctl
49784 + option with name "socket_client_gid" is created.
49785 +
49786 +config GRKERNSEC_SOCKET_SERVER
49787 + bool "Deny server sockets to group"
49788 + depends on GRKERNSEC_SOCKET
49789 + help
49790 + If you say Y here, you will be able to choose a GID of whose users will
49791 + be unable to run server applications from your machine. If the sysctl
49792 + option is enabled, a sysctl option with name "socket_server" is created.
49793 +
49794 +config GRKERNSEC_SOCKET_SERVER_GID
49795 + int "GID to deny server sockets for"
49796 + depends on GRKERNSEC_SOCKET_SERVER
49797 + default 1002
49798 + help
49799 + Here you can choose the GID to disable server socket access for.
49800 + Remember to add the users you want server socket access disabled for to
49801 + the GID specified here. If the sysctl option is enabled, a sysctl
49802 + option with name "socket_server_gid" is created.
49803 +
49804 +endmenu
49805 +menu "Sysctl support"
49806 +depends on GRKERNSEC && SYSCTL
49807 +
49808 +config GRKERNSEC_SYSCTL
49809 + bool "Sysctl support"
49810 + help
49811 + If you say Y here, you will be able to change the options that
49812 + grsecurity runs with at bootup, without having to recompile your
49813 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
49814 + to enable (1) or disable (0) various features. All the sysctl entries
49815 + are mutable until the "grsec_lock" entry is set to a non-zero value.
49816 + All features enabled in the kernel configuration are disabled at boot
49817 + if you do not say Y to the "Turn on features by default" option.
49818 + All options should be set at startup, and the grsec_lock entry should
49819 + be set to a non-zero value after all the options are set.
49820 + *THIS IS EXTREMELY IMPORTANT*
49821 +
49822 +config GRKERNSEC_SYSCTL_DISTRO
49823 + bool "Extra sysctl support for distro makers (READ HELP)"
49824 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
49825 + help
49826 + If you say Y here, additional sysctl options will be created
49827 + for features that affect processes running as root. Therefore,
49828 + it is critical when using this option that the grsec_lock entry be
49829 + enabled after boot. Only distros with prebuilt kernel packages
49830 + with this option enabled that can ensure grsec_lock is enabled
49831 + after boot should use this option.
49832 + *Failure to set grsec_lock after boot makes all grsec features
49833 + this option covers useless*
49834 +
49835 + Currently this option creates the following sysctl entries:
49836 + "Disable Privileged I/O": "disable_priv_io"
49837 +
49838 +config GRKERNSEC_SYSCTL_ON
49839 + bool "Turn on features by default"
49840 + depends on GRKERNSEC_SYSCTL
49841 + help
49842 + If you say Y here, instead of having all features enabled in the
49843 + kernel configuration disabled at boot time, the features will be
49844 + enabled at boot time. It is recommended you say Y here unless
49845 + there is some reason you would want all sysctl-tunable features to
49846 + be disabled by default. As mentioned elsewhere, it is important
49847 + to enable the grsec_lock entry once you have finished modifying
49848 + the sysctl entries.
49849 +
49850 +endmenu
49851 +menu "Logging Options"
49852 +depends on GRKERNSEC
49853 +
49854 +config GRKERNSEC_FLOODTIME
49855 + int "Seconds in between log messages (minimum)"
49856 + default 10
49857 + help
49858 + This option allows you to enforce the number of seconds between
49859 + grsecurity log messages. The default should be suitable for most
49860 + people, however, if you choose to change it, choose a value small enough
49861 + to allow informative logs to be produced, but large enough to
49862 + prevent flooding.
49863 +
49864 +config GRKERNSEC_FLOODBURST
49865 + int "Number of messages in a burst (maximum)"
49866 + default 6
49867 + help
49868 + This option allows you to choose the maximum number of messages allowed
49869 + within the flood time interval you chose in a separate option. The
49870 + default should be suitable for most people, however if you find that
49871 + many of your logs are being interpreted as flooding, you may want to
49872 + raise this value.
49873 +
49874 +endmenu
49875 +
49876 +endmenu
49877 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
49878 new file mode 100644
49879 index 0000000..1b9afa9
49880 --- /dev/null
49881 +++ b/grsecurity/Makefile
49882 @@ -0,0 +1,38 @@
49883 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
49884 +# during 2001-2009 it has been completely redesigned by Brad Spengler
49885 +# into an RBAC system
49886 +#
49887 +# All code in this directory and various hooks inserted throughout the kernel
49888 +# are copyright Brad Spengler - Open Source Security, Inc., and released
49889 +# under the GPL v2 or higher
49890 +
49891 +KBUILD_CFLAGS += -Werror
49892 +
49893 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
49894 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
49895 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
49896 +
49897 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
49898 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
49899 + gracl_learn.o grsec_log.o
49900 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
49901 +
49902 +ifdef CONFIG_NET
49903 +obj-y += grsec_sock.o
49904 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
49905 +endif
49906 +
49907 +ifndef CONFIG_GRKERNSEC
49908 +obj-y += grsec_disabled.o
49909 +endif
49910 +
49911 +ifdef CONFIG_GRKERNSEC_HIDESYM
49912 +extra-y := grsec_hidesym.o
49913 +$(obj)/grsec_hidesym.o:
49914 + @-chmod -f 500 /boot
49915 + @-chmod -f 500 /lib/modules
49916 + @-chmod -f 500 /lib64/modules
49917 + @-chmod -f 500 /lib32/modules
49918 + @-chmod -f 700 .
49919 + @echo ' grsec: protected kernel image paths'
49920 +endif
49921 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
49922 new file mode 100644
49923 index 0000000..2733872
49924 --- /dev/null
49925 +++ b/grsecurity/gracl.c
49926 @@ -0,0 +1,4163 @@
49927 +#include <linux/kernel.h>
49928 +#include <linux/module.h>
49929 +#include <linux/sched.h>
49930 +#include <linux/mm.h>
49931 +#include <linux/file.h>
49932 +#include <linux/fs.h>
49933 +#include <linux/namei.h>
49934 +#include <linux/mount.h>
49935 +#include <linux/tty.h>
49936 +#include <linux/proc_fs.h>
49937 +#include <linux/lglock.h>
49938 +#include <linux/slab.h>
49939 +#include <linux/vmalloc.h>
49940 +#include <linux/types.h>
49941 +#include <linux/sysctl.h>
49942 +#include <linux/netdevice.h>
49943 +#include <linux/ptrace.h>
49944 +#include <linux/gracl.h>
49945 +#include <linux/gralloc.h>
49946 +#include <linux/security.h>
49947 +#include <linux/grinternal.h>
49948 +#include <linux/pid_namespace.h>
49949 +#include <linux/fdtable.h>
49950 +#include <linux/percpu.h>
49951 +
49952 +#include <asm/uaccess.h>
49953 +#include <asm/errno.h>
49954 +#include <asm/mman.h>
49955 +
49956 +static struct acl_role_db acl_role_set;
49957 +static struct name_db name_set;
49958 +static struct inodev_db inodev_set;
49959 +
49960 +/* for keeping track of userspace pointers used for subjects, so we
49961 + can share references in the kernel as well
49962 +*/
49963 +
49964 +static struct path real_root;
49965 +
49966 +static struct acl_subj_map_db subj_map_set;
49967 +
49968 +static struct acl_role_label *default_role;
49969 +
49970 +static struct acl_role_label *role_list;
49971 +
49972 +static u16 acl_sp_role_value;
49973 +
49974 +extern char *gr_shared_page[4];
49975 +static DEFINE_MUTEX(gr_dev_mutex);
49976 +DEFINE_RWLOCK(gr_inode_lock);
49977 +
49978 +struct gr_arg *gr_usermode;
49979 +
49980 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
49981 +
49982 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
49983 +extern void gr_clear_learn_entries(void);
49984 +
49985 +#ifdef CONFIG_GRKERNSEC_RESLOG
49986 +extern void gr_log_resource(const struct task_struct *task,
49987 + const int res, const unsigned long wanted, const int gt);
49988 +#endif
49989 +
49990 +unsigned char *gr_system_salt;
49991 +unsigned char *gr_system_sum;
49992 +
49993 +static struct sprole_pw **acl_special_roles = NULL;
49994 +static __u16 num_sprole_pws = 0;
49995 +
49996 +static struct acl_role_label *kernel_role = NULL;
49997 +
49998 +static unsigned int gr_auth_attempts = 0;
49999 +static unsigned long gr_auth_expires = 0UL;
50000 +
50001 +#ifdef CONFIG_NET
50002 +extern struct vfsmount *sock_mnt;
50003 +#endif
50004 +
50005 +extern struct vfsmount *pipe_mnt;
50006 +extern struct vfsmount *shm_mnt;
50007 +#ifdef CONFIG_HUGETLBFS
50008 +extern struct vfsmount *hugetlbfs_vfsmount;
50009 +#endif
50010 +
50011 +static struct acl_object_label *fakefs_obj_rw;
50012 +static struct acl_object_label *fakefs_obj_rwx;
50013 +
50014 +extern int gr_init_uidset(void);
50015 +extern void gr_free_uidset(void);
50016 +extern void gr_remove_uid(uid_t uid);
50017 +extern int gr_find_uid(uid_t uid);
50018 +
50019 +DECLARE_BRLOCK(vfsmount_lock);
50020 +
50021 +__inline__ int
50022 +gr_acl_is_enabled(void)
50023 +{
50024 + return (gr_status & GR_READY);
50025 +}
50026 +
50027 +#ifdef CONFIG_BTRFS_FS
50028 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50029 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50030 +#endif
50031 +
50032 +static inline dev_t __get_dev(const struct dentry *dentry)
50033 +{
50034 +#ifdef CONFIG_BTRFS_FS
50035 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50036 + return get_btrfs_dev_from_inode(dentry->d_inode);
50037 + else
50038 +#endif
50039 + return dentry->d_inode->i_sb->s_dev;
50040 +}
50041 +
50042 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50043 +{
50044 + return __get_dev(dentry);
50045 +}
50046 +
50047 +static char gr_task_roletype_to_char(struct task_struct *task)
50048 +{
50049 + switch (task->role->roletype &
50050 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50051 + GR_ROLE_SPECIAL)) {
50052 + case GR_ROLE_DEFAULT:
50053 + return 'D';
50054 + case GR_ROLE_USER:
50055 + return 'U';
50056 + case GR_ROLE_GROUP:
50057 + return 'G';
50058 + case GR_ROLE_SPECIAL:
50059 + return 'S';
50060 + }
50061 +
50062 + return 'X';
50063 +}
50064 +
50065 +char gr_roletype_to_char(void)
50066 +{
50067 + return gr_task_roletype_to_char(current);
50068 +}
50069 +
50070 +__inline__ int
50071 +gr_acl_tpe_check(void)
50072 +{
50073 + if (unlikely(!(gr_status & GR_READY)))
50074 + return 0;
50075 + if (current->role->roletype & GR_ROLE_TPE)
50076 + return 1;
50077 + else
50078 + return 0;
50079 +}
50080 +
50081 +int
50082 +gr_handle_rawio(const struct inode *inode)
50083 +{
50084 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50085 + if (inode && S_ISBLK(inode->i_mode) &&
50086 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50087 + !capable(CAP_SYS_RAWIO))
50088 + return 1;
50089 +#endif
50090 + return 0;
50091 +}
50092 +
50093 +static int
50094 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50095 +{
50096 + if (likely(lena != lenb))
50097 + return 0;
50098 +
50099 + return !memcmp(a, b, lena);
50100 +}
50101 +
50102 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50103 +{
50104 + *buflen -= namelen;
50105 + if (*buflen < 0)
50106 + return -ENAMETOOLONG;
50107 + *buffer -= namelen;
50108 + memcpy(*buffer, str, namelen);
50109 + return 0;
50110 +}
50111 +
50112 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50113 +{
50114 + return prepend(buffer, buflen, name->name, name->len);
50115 +}
50116 +
50117 +static int prepend_path(const struct path *path, struct path *root,
50118 + char **buffer, int *buflen)
50119 +{
50120 + struct dentry *dentry = path->dentry;
50121 + struct vfsmount *vfsmnt = path->mnt;
50122 + bool slash = false;
50123 + int error = 0;
50124 +
50125 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50126 + struct dentry * parent;
50127 +
50128 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50129 + /* Global root? */
50130 + if (vfsmnt->mnt_parent == vfsmnt) {
50131 + goto out;
50132 + }
50133 + dentry = vfsmnt->mnt_mountpoint;
50134 + vfsmnt = vfsmnt->mnt_parent;
50135 + continue;
50136 + }
50137 + parent = dentry->d_parent;
50138 + prefetch(parent);
50139 + spin_lock(&dentry->d_lock);
50140 + error = prepend_name(buffer, buflen, &dentry->d_name);
50141 + spin_unlock(&dentry->d_lock);
50142 + if (!error)
50143 + error = prepend(buffer, buflen, "/", 1);
50144 + if (error)
50145 + break;
50146 +
50147 + slash = true;
50148 + dentry = parent;
50149 + }
50150 +
50151 +out:
50152 + if (!error && !slash)
50153 + error = prepend(buffer, buflen, "/", 1);
50154 +
50155 + return error;
50156 +}
50157 +
50158 +/* this must be called with vfsmount_lock and rename_lock held */
50159 +
50160 +static char *__our_d_path(const struct path *path, struct path *root,
50161 + char *buf, int buflen)
50162 +{
50163 + char *res = buf + buflen;
50164 + int error;
50165 +
50166 + prepend(&res, &buflen, "\0", 1);
50167 + error = prepend_path(path, root, &res, &buflen);
50168 + if (error)
50169 + return ERR_PTR(error);
50170 +
50171 + return res;
50172 +}
50173 +
50174 +static char *
50175 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50176 +{
50177 + char *retval;
50178 +
50179 + retval = __our_d_path(path, root, buf, buflen);
50180 + if (unlikely(IS_ERR(retval)))
50181 + retval = strcpy(buf, "<path too long>");
50182 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50183 + retval[1] = '\0';
50184 +
50185 + return retval;
50186 +}
50187 +
50188 +static char *
50189 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50190 + char *buf, int buflen)
50191 +{
50192 + struct path path;
50193 + char *res;
50194 +
50195 + path.dentry = (struct dentry *)dentry;
50196 + path.mnt = (struct vfsmount *)vfsmnt;
50197 +
50198 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50199 + by the RBAC system */
50200 + res = gen_full_path(&path, &real_root, buf, buflen);
50201 +
50202 + return res;
50203 +}
50204 +
50205 +static char *
50206 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50207 + char *buf, int buflen)
50208 +{
50209 + char *res;
50210 + struct path path;
50211 + struct path root;
50212 + struct task_struct *reaper = &init_task;
50213 +
50214 + path.dentry = (struct dentry *)dentry;
50215 + path.mnt = (struct vfsmount *)vfsmnt;
50216 +
50217 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50218 + get_fs_root(reaper->fs, &root);
50219 +
50220 + write_seqlock(&rename_lock);
50221 + br_read_lock(vfsmount_lock);
50222 + res = gen_full_path(&path, &root, buf, buflen);
50223 + br_read_unlock(vfsmount_lock);
50224 + write_sequnlock(&rename_lock);
50225 +
50226 + path_put(&root);
50227 + return res;
50228 +}
50229 +
50230 +static char *
50231 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50232 +{
50233 + char *ret;
50234 + write_seqlock(&rename_lock);
50235 + br_read_lock(vfsmount_lock);
50236 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50237 + PAGE_SIZE);
50238 + br_read_unlock(vfsmount_lock);
50239 + write_sequnlock(&rename_lock);
50240 + return ret;
50241 +}
50242 +
50243 +static char *
50244 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50245 +{
50246 + char *ret;
50247 + char *buf;
50248 + int buflen;
50249 +
50250 + write_seqlock(&rename_lock);
50251 + br_read_lock(vfsmount_lock);
50252 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50253 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50254 + buflen = (int)(ret - buf);
50255 + if (buflen >= 5)
50256 + prepend(&ret, &buflen, "/proc", 5);
50257 + else
50258 + ret = strcpy(buf, "<path too long>");
50259 + br_read_unlock(vfsmount_lock);
50260 + write_sequnlock(&rename_lock);
50261 + return ret;
50262 +}
50263 +
50264 +char *
50265 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50266 +{
50267 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50268 + PAGE_SIZE);
50269 +}
50270 +
50271 +char *
50272 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50273 +{
50274 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50275 + PAGE_SIZE);
50276 +}
50277 +
50278 +char *
50279 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50280 +{
50281 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50282 + PAGE_SIZE);
50283 +}
50284 +
50285 +char *
50286 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50287 +{
50288 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50289 + PAGE_SIZE);
50290 +}
50291 +
50292 +char *
50293 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50294 +{
50295 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50296 + PAGE_SIZE);
50297 +}
50298 +
50299 +__inline__ __u32
50300 +to_gr_audit(const __u32 reqmode)
50301 +{
50302 + /* masks off auditable permission flags, then shifts them to create
50303 + auditing flags, and adds the special case of append auditing if
50304 + we're requesting write */
50305 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50306 +}
50307 +
50308 +struct acl_subject_label *
50309 +lookup_subject_map(const struct acl_subject_label *userp)
50310 +{
50311 + unsigned int index = shash(userp, subj_map_set.s_size);
50312 + struct subject_map *match;
50313 +
50314 + match = subj_map_set.s_hash[index];
50315 +
50316 + while (match && match->user != userp)
50317 + match = match->next;
50318 +
50319 + if (match != NULL)
50320 + return match->kernel;
50321 + else
50322 + return NULL;
50323 +}
50324 +
50325 +static void
50326 +insert_subj_map_entry(struct subject_map *subjmap)
50327 +{
50328 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50329 + struct subject_map **curr;
50330 +
50331 + subjmap->prev = NULL;
50332 +
50333 + curr = &subj_map_set.s_hash[index];
50334 + if (*curr != NULL)
50335 + (*curr)->prev = subjmap;
50336 +
50337 + subjmap->next = *curr;
50338 + *curr = subjmap;
50339 +
50340 + return;
50341 +}
50342 +
50343 +static struct acl_role_label *
50344 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50345 + const gid_t gid)
50346 +{
50347 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50348 + struct acl_role_label *match;
50349 + struct role_allowed_ip *ipp;
50350 + unsigned int x;
50351 + u32 curr_ip = task->signal->curr_ip;
50352 +
50353 + task->signal->saved_ip = curr_ip;
50354 +
50355 + match = acl_role_set.r_hash[index];
50356 +
50357 + while (match) {
50358 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50359 + for (x = 0; x < match->domain_child_num; x++) {
50360 + if (match->domain_children[x] == uid)
50361 + goto found;
50362 + }
50363 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50364 + break;
50365 + match = match->next;
50366 + }
50367 +found:
50368 + if (match == NULL) {
50369 + try_group:
50370 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50371 + match = acl_role_set.r_hash[index];
50372 +
50373 + while (match) {
50374 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50375 + for (x = 0; x < match->domain_child_num; x++) {
50376 + if (match->domain_children[x] == gid)
50377 + goto found2;
50378 + }
50379 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50380 + break;
50381 + match = match->next;
50382 + }
50383 +found2:
50384 + if (match == NULL)
50385 + match = default_role;
50386 + if (match->allowed_ips == NULL)
50387 + return match;
50388 + else {
50389 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50390 + if (likely
50391 + ((ntohl(curr_ip) & ipp->netmask) ==
50392 + (ntohl(ipp->addr) & ipp->netmask)))
50393 + return match;
50394 + }
50395 + match = default_role;
50396 + }
50397 + } else if (match->allowed_ips == NULL) {
50398 + return match;
50399 + } else {
50400 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50401 + if (likely
50402 + ((ntohl(curr_ip) & ipp->netmask) ==
50403 + (ntohl(ipp->addr) & ipp->netmask)))
50404 + return match;
50405 + }
50406 + goto try_group;
50407 + }
50408 +
50409 + return match;
50410 +}
50411 +
50412 +struct acl_subject_label *
50413 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50414 + const struct acl_role_label *role)
50415 +{
50416 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50417 + struct acl_subject_label *match;
50418 +
50419 + match = role->subj_hash[index];
50420 +
50421 + while (match && (match->inode != ino || match->device != dev ||
50422 + (match->mode & GR_DELETED))) {
50423 + match = match->next;
50424 + }
50425 +
50426 + if (match && !(match->mode & GR_DELETED))
50427 + return match;
50428 + else
50429 + return NULL;
50430 +}
50431 +
50432 +struct acl_subject_label *
50433 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50434 + const struct acl_role_label *role)
50435 +{
50436 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50437 + struct acl_subject_label *match;
50438 +
50439 + match = role->subj_hash[index];
50440 +
50441 + while (match && (match->inode != ino || match->device != dev ||
50442 + !(match->mode & GR_DELETED))) {
50443 + match = match->next;
50444 + }
50445 +
50446 + if (match && (match->mode & GR_DELETED))
50447 + return match;
50448 + else
50449 + return NULL;
50450 +}
50451 +
50452 +static struct acl_object_label *
50453 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50454 + const struct acl_subject_label *subj)
50455 +{
50456 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50457 + struct acl_object_label *match;
50458 +
50459 + match = subj->obj_hash[index];
50460 +
50461 + while (match && (match->inode != ino || match->device != dev ||
50462 + (match->mode & GR_DELETED))) {
50463 + match = match->next;
50464 + }
50465 +
50466 + if (match && !(match->mode & GR_DELETED))
50467 + return match;
50468 + else
50469 + return NULL;
50470 +}
50471 +
50472 +static struct acl_object_label *
50473 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50474 + const struct acl_subject_label *subj)
50475 +{
50476 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50477 + struct acl_object_label *match;
50478 +
50479 + match = subj->obj_hash[index];
50480 +
50481 + while (match && (match->inode != ino || match->device != dev ||
50482 + !(match->mode & GR_DELETED))) {
50483 + match = match->next;
50484 + }
50485 +
50486 + if (match && (match->mode & GR_DELETED))
50487 + return match;
50488 +
50489 + match = subj->obj_hash[index];
50490 +
50491 + while (match && (match->inode != ino || match->device != dev ||
50492 + (match->mode & GR_DELETED))) {
50493 + match = match->next;
50494 + }
50495 +
50496 + if (match && !(match->mode & GR_DELETED))
50497 + return match;
50498 + else
50499 + return NULL;
50500 +}
50501 +
50502 +static struct name_entry *
50503 +lookup_name_entry(const char *name)
50504 +{
50505 + unsigned int len = strlen(name);
50506 + unsigned int key = full_name_hash(name, len);
50507 + unsigned int index = key % name_set.n_size;
50508 + struct name_entry *match;
50509 +
50510 + match = name_set.n_hash[index];
50511 +
50512 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50513 + match = match->next;
50514 +
50515 + return match;
50516 +}
50517 +
50518 +static struct name_entry *
50519 +lookup_name_entry_create(const char *name)
50520 +{
50521 + unsigned int len = strlen(name);
50522 + unsigned int key = full_name_hash(name, len);
50523 + unsigned int index = key % name_set.n_size;
50524 + struct name_entry *match;
50525 +
50526 + match = name_set.n_hash[index];
50527 +
50528 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50529 + !match->deleted))
50530 + match = match->next;
50531 +
50532 + if (match && match->deleted)
50533 + return match;
50534 +
50535 + match = name_set.n_hash[index];
50536 +
50537 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50538 + match->deleted))
50539 + match = match->next;
50540 +
50541 + if (match && !match->deleted)
50542 + return match;
50543 + else
50544 + return NULL;
50545 +}
50546 +
50547 +static struct inodev_entry *
50548 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
50549 +{
50550 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
50551 + struct inodev_entry *match;
50552 +
50553 + match = inodev_set.i_hash[index];
50554 +
50555 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50556 + match = match->next;
50557 +
50558 + return match;
50559 +}
50560 +
50561 +static void
50562 +insert_inodev_entry(struct inodev_entry *entry)
50563 +{
50564 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50565 + inodev_set.i_size);
50566 + struct inodev_entry **curr;
50567 +
50568 + entry->prev = NULL;
50569 +
50570 + curr = &inodev_set.i_hash[index];
50571 + if (*curr != NULL)
50572 + (*curr)->prev = entry;
50573 +
50574 + entry->next = *curr;
50575 + *curr = entry;
50576 +
50577 + return;
50578 +}
50579 +
50580 +static void
50581 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50582 +{
50583 + unsigned int index =
50584 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50585 + struct acl_role_label **curr;
50586 + struct acl_role_label *tmp;
50587 +
50588 + curr = &acl_role_set.r_hash[index];
50589 +
50590 + /* if role was already inserted due to domains and already has
50591 + a role in the same bucket as it attached, then we need to
50592 + combine these two buckets
50593 + */
50594 + if (role->next) {
50595 + tmp = role->next;
50596 + while (tmp->next)
50597 + tmp = tmp->next;
50598 + tmp->next = *curr;
50599 + } else
50600 + role->next = *curr;
50601 + *curr = role;
50602 +
50603 + return;
50604 +}
50605 +
50606 +static void
50607 +insert_acl_role_label(struct acl_role_label *role)
50608 +{
50609 + int i;
50610 +
50611 + if (role_list == NULL) {
50612 + role_list = role;
50613 + role->prev = NULL;
50614 + } else {
50615 + role->prev = role_list;
50616 + role_list = role;
50617 + }
50618 +
50619 + /* used for hash chains */
50620 + role->next = NULL;
50621 +
50622 + if (role->roletype & GR_ROLE_DOMAIN) {
50623 + for (i = 0; i < role->domain_child_num; i++)
50624 + __insert_acl_role_label(role, role->domain_children[i]);
50625 + } else
50626 + __insert_acl_role_label(role, role->uidgid);
50627 +}
50628 +
50629 +static int
50630 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50631 +{
50632 + struct name_entry **curr, *nentry;
50633 + struct inodev_entry *ientry;
50634 + unsigned int len = strlen(name);
50635 + unsigned int key = full_name_hash(name, len);
50636 + unsigned int index = key % name_set.n_size;
50637 +
50638 + curr = &name_set.n_hash[index];
50639 +
50640 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50641 + curr = &((*curr)->next);
50642 +
50643 + if (*curr != NULL)
50644 + return 1;
50645 +
50646 + nentry = acl_alloc(sizeof (struct name_entry));
50647 + if (nentry == NULL)
50648 + return 0;
50649 + ientry = acl_alloc(sizeof (struct inodev_entry));
50650 + if (ientry == NULL)
50651 + return 0;
50652 + ientry->nentry = nentry;
50653 +
50654 + nentry->key = key;
50655 + nentry->name = name;
50656 + nentry->inode = inode;
50657 + nentry->device = device;
50658 + nentry->len = len;
50659 + nentry->deleted = deleted;
50660 +
50661 + nentry->prev = NULL;
50662 + curr = &name_set.n_hash[index];
50663 + if (*curr != NULL)
50664 + (*curr)->prev = nentry;
50665 + nentry->next = *curr;
50666 + *curr = nentry;
50667 +
50668 + /* insert us into the table searchable by inode/dev */
50669 + insert_inodev_entry(ientry);
50670 +
50671 + return 1;
50672 +}
50673 +
50674 +static void
50675 +insert_acl_obj_label(struct acl_object_label *obj,
50676 + struct acl_subject_label *subj)
50677 +{
50678 + unsigned int index =
50679 + fhash(obj->inode, obj->device, subj->obj_hash_size);
50680 + struct acl_object_label **curr;
50681 +
50682 +
50683 + obj->prev = NULL;
50684 +
50685 + curr = &subj->obj_hash[index];
50686 + if (*curr != NULL)
50687 + (*curr)->prev = obj;
50688 +
50689 + obj->next = *curr;
50690 + *curr = obj;
50691 +
50692 + return;
50693 +}
50694 +
50695 +static void
50696 +insert_acl_subj_label(struct acl_subject_label *obj,
50697 + struct acl_role_label *role)
50698 +{
50699 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
50700 + struct acl_subject_label **curr;
50701 +
50702 + obj->prev = NULL;
50703 +
50704 + curr = &role->subj_hash[index];
50705 + if (*curr != NULL)
50706 + (*curr)->prev = obj;
50707 +
50708 + obj->next = *curr;
50709 + *curr = obj;
50710 +
50711 + return;
50712 +}
50713 +
50714 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
50715 +
50716 +static void *
50717 +create_table(__u32 * len, int elementsize)
50718 +{
50719 + unsigned int table_sizes[] = {
50720 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
50721 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
50722 + 4194301, 8388593, 16777213, 33554393, 67108859
50723 + };
50724 + void *newtable = NULL;
50725 + unsigned int pwr = 0;
50726 +
50727 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
50728 + table_sizes[pwr] <= *len)
50729 + pwr++;
50730 +
50731 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
50732 + return newtable;
50733 +
50734 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
50735 + newtable =
50736 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
50737 + else
50738 + newtable = vmalloc(table_sizes[pwr] * elementsize);
50739 +
50740 + *len = table_sizes[pwr];
50741 +
50742 + return newtable;
50743 +}
50744 +
50745 +static int
50746 +init_variables(const struct gr_arg *arg)
50747 +{
50748 + struct task_struct *reaper = &init_task;
50749 + unsigned int stacksize;
50750 +
50751 + subj_map_set.s_size = arg->role_db.num_subjects;
50752 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
50753 + name_set.n_size = arg->role_db.num_objects;
50754 + inodev_set.i_size = arg->role_db.num_objects;
50755 +
50756 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
50757 + !name_set.n_size || !inodev_set.i_size)
50758 + return 1;
50759 +
50760 + if (!gr_init_uidset())
50761 + return 1;
50762 +
50763 + /* set up the stack that holds allocation info */
50764 +
50765 + stacksize = arg->role_db.num_pointers + 5;
50766 +
50767 + if (!acl_alloc_stack_init(stacksize))
50768 + return 1;
50769 +
50770 + /* grab reference for the real root dentry and vfsmount */
50771 + get_fs_root(reaper->fs, &real_root);
50772 +
50773 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50774 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
50775 +#endif
50776 +
50777 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
50778 + if (fakefs_obj_rw == NULL)
50779 + return 1;
50780 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
50781 +
50782 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
50783 + if (fakefs_obj_rwx == NULL)
50784 + return 1;
50785 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
50786 +
50787 + subj_map_set.s_hash =
50788 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
50789 + acl_role_set.r_hash =
50790 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
50791 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
50792 + inodev_set.i_hash =
50793 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
50794 +
50795 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
50796 + !name_set.n_hash || !inodev_set.i_hash)
50797 + return 1;
50798 +
50799 + memset(subj_map_set.s_hash, 0,
50800 + sizeof(struct subject_map *) * subj_map_set.s_size);
50801 + memset(acl_role_set.r_hash, 0,
50802 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
50803 + memset(name_set.n_hash, 0,
50804 + sizeof (struct name_entry *) * name_set.n_size);
50805 + memset(inodev_set.i_hash, 0,
50806 + sizeof (struct inodev_entry *) * inodev_set.i_size);
50807 +
50808 + return 0;
50809 +}
50810 +
50811 +/* free information not needed after startup
50812 + currently contains user->kernel pointer mappings for subjects
50813 +*/
50814 +
50815 +static void
50816 +free_init_variables(void)
50817 +{
50818 + __u32 i;
50819 +
50820 + if (subj_map_set.s_hash) {
50821 + for (i = 0; i < subj_map_set.s_size; i++) {
50822 + if (subj_map_set.s_hash[i]) {
50823 + kfree(subj_map_set.s_hash[i]);
50824 + subj_map_set.s_hash[i] = NULL;
50825 + }
50826 + }
50827 +
50828 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
50829 + PAGE_SIZE)
50830 + kfree(subj_map_set.s_hash);
50831 + else
50832 + vfree(subj_map_set.s_hash);
50833 + }
50834 +
50835 + return;
50836 +}
50837 +
50838 +static void
50839 +free_variables(void)
50840 +{
50841 + struct acl_subject_label *s;
50842 + struct acl_role_label *r;
50843 + struct task_struct *task, *task2;
50844 + unsigned int x;
50845 +
50846 + gr_clear_learn_entries();
50847 +
50848 + read_lock(&tasklist_lock);
50849 + do_each_thread(task2, task) {
50850 + task->acl_sp_role = 0;
50851 + task->acl_role_id = 0;
50852 + task->acl = NULL;
50853 + task->role = NULL;
50854 + } while_each_thread(task2, task);
50855 + read_unlock(&tasklist_lock);
50856 +
50857 + /* release the reference to the real root dentry and vfsmount */
50858 + path_put(&real_root);
50859 +
50860 + /* free all object hash tables */
50861 +
50862 + FOR_EACH_ROLE_START(r)
50863 + if (r->subj_hash == NULL)
50864 + goto next_role;
50865 + FOR_EACH_SUBJECT_START(r, s, x)
50866 + if (s->obj_hash == NULL)
50867 + break;
50868 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50869 + kfree(s->obj_hash);
50870 + else
50871 + vfree(s->obj_hash);
50872 + FOR_EACH_SUBJECT_END(s, x)
50873 + FOR_EACH_NESTED_SUBJECT_START(r, s)
50874 + if (s->obj_hash == NULL)
50875 + break;
50876 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50877 + kfree(s->obj_hash);
50878 + else
50879 + vfree(s->obj_hash);
50880 + FOR_EACH_NESTED_SUBJECT_END(s)
50881 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
50882 + kfree(r->subj_hash);
50883 + else
50884 + vfree(r->subj_hash);
50885 + r->subj_hash = NULL;
50886 +next_role:
50887 + FOR_EACH_ROLE_END(r)
50888 +
50889 + acl_free_all();
50890 +
50891 + if (acl_role_set.r_hash) {
50892 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
50893 + PAGE_SIZE)
50894 + kfree(acl_role_set.r_hash);
50895 + else
50896 + vfree(acl_role_set.r_hash);
50897 + }
50898 + if (name_set.n_hash) {
50899 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
50900 + PAGE_SIZE)
50901 + kfree(name_set.n_hash);
50902 + else
50903 + vfree(name_set.n_hash);
50904 + }
50905 +
50906 + if (inodev_set.i_hash) {
50907 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
50908 + PAGE_SIZE)
50909 + kfree(inodev_set.i_hash);
50910 + else
50911 + vfree(inodev_set.i_hash);
50912 + }
50913 +
50914 + gr_free_uidset();
50915 +
50916 + memset(&name_set, 0, sizeof (struct name_db));
50917 + memset(&inodev_set, 0, sizeof (struct inodev_db));
50918 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
50919 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
50920 +
50921 + default_role = NULL;
50922 + role_list = NULL;
50923 +
50924 + return;
50925 +}
50926 +
50927 +static __u32
50928 +count_user_objs(struct acl_object_label *userp)
50929 +{
50930 + struct acl_object_label o_tmp;
50931 + __u32 num = 0;
50932 +
50933 + while (userp) {
50934 + if (copy_from_user(&o_tmp, userp,
50935 + sizeof (struct acl_object_label)))
50936 + break;
50937 +
50938 + userp = o_tmp.prev;
50939 + num++;
50940 + }
50941 +
50942 + return num;
50943 +}
50944 +
50945 +static struct acl_subject_label *
50946 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
50947 +
50948 +static int
50949 +copy_user_glob(struct acl_object_label *obj)
50950 +{
50951 + struct acl_object_label *g_tmp, **guser;
50952 + unsigned int len;
50953 + char *tmp;
50954 +
50955 + if (obj->globbed == NULL)
50956 + return 0;
50957 +
50958 + guser = &obj->globbed;
50959 + while (*guser) {
50960 + g_tmp = (struct acl_object_label *)
50961 + acl_alloc(sizeof (struct acl_object_label));
50962 + if (g_tmp == NULL)
50963 + return -ENOMEM;
50964 +
50965 + if (copy_from_user(g_tmp, *guser,
50966 + sizeof (struct acl_object_label)))
50967 + return -EFAULT;
50968 +
50969 + len = strnlen_user(g_tmp->filename, PATH_MAX);
50970 +
50971 + if (!len || len >= PATH_MAX)
50972 + return -EINVAL;
50973 +
50974 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50975 + return -ENOMEM;
50976 +
50977 + if (copy_from_user(tmp, g_tmp->filename, len))
50978 + return -EFAULT;
50979 + tmp[len-1] = '\0';
50980 + g_tmp->filename = tmp;
50981 +
50982 + *guser = g_tmp;
50983 + guser = &(g_tmp->next);
50984 + }
50985 +
50986 + return 0;
50987 +}
50988 +
50989 +static int
50990 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
50991 + struct acl_role_label *role)
50992 +{
50993 + struct acl_object_label *o_tmp;
50994 + unsigned int len;
50995 + int ret;
50996 + char *tmp;
50997 +
50998 + while (userp) {
50999 + if ((o_tmp = (struct acl_object_label *)
51000 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51001 + return -ENOMEM;
51002 +
51003 + if (copy_from_user(o_tmp, userp,
51004 + sizeof (struct acl_object_label)))
51005 + return -EFAULT;
51006 +
51007 + userp = o_tmp->prev;
51008 +
51009 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51010 +
51011 + if (!len || len >= PATH_MAX)
51012 + return -EINVAL;
51013 +
51014 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51015 + return -ENOMEM;
51016 +
51017 + if (copy_from_user(tmp, o_tmp->filename, len))
51018 + return -EFAULT;
51019 + tmp[len-1] = '\0';
51020 + o_tmp->filename = tmp;
51021 +
51022 + insert_acl_obj_label(o_tmp, subj);
51023 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51024 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51025 + return -ENOMEM;
51026 +
51027 + ret = copy_user_glob(o_tmp);
51028 + if (ret)
51029 + return ret;
51030 +
51031 + if (o_tmp->nested) {
51032 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51033 + if (IS_ERR(o_tmp->nested))
51034 + return PTR_ERR(o_tmp->nested);
51035 +
51036 + /* insert into nested subject list */
51037 + o_tmp->nested->next = role->hash->first;
51038 + role->hash->first = o_tmp->nested;
51039 + }
51040 + }
51041 +
51042 + return 0;
51043 +}
51044 +
51045 +static __u32
51046 +count_user_subjs(struct acl_subject_label *userp)
51047 +{
51048 + struct acl_subject_label s_tmp;
51049 + __u32 num = 0;
51050 +
51051 + while (userp) {
51052 + if (copy_from_user(&s_tmp, userp,
51053 + sizeof (struct acl_subject_label)))
51054 + break;
51055 +
51056 + userp = s_tmp.prev;
51057 + /* do not count nested subjects against this count, since
51058 + they are not included in the hash table, but are
51059 + attached to objects. We have already counted
51060 + the subjects in userspace for the allocation
51061 + stack
51062 + */
51063 + if (!(s_tmp.mode & GR_NESTED))
51064 + num++;
51065 + }
51066 +
51067 + return num;
51068 +}
51069 +
51070 +static int
51071 +copy_user_allowedips(struct acl_role_label *rolep)
51072 +{
51073 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51074 +
51075 + ruserip = rolep->allowed_ips;
51076 +
51077 + while (ruserip) {
51078 + rlast = rtmp;
51079 +
51080 + if ((rtmp = (struct role_allowed_ip *)
51081 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51082 + return -ENOMEM;
51083 +
51084 + if (copy_from_user(rtmp, ruserip,
51085 + sizeof (struct role_allowed_ip)))
51086 + return -EFAULT;
51087 +
51088 + ruserip = rtmp->prev;
51089 +
51090 + if (!rlast) {
51091 + rtmp->prev = NULL;
51092 + rolep->allowed_ips = rtmp;
51093 + } else {
51094 + rlast->next = rtmp;
51095 + rtmp->prev = rlast;
51096 + }
51097 +
51098 + if (!ruserip)
51099 + rtmp->next = NULL;
51100 + }
51101 +
51102 + return 0;
51103 +}
51104 +
51105 +static int
51106 +copy_user_transitions(struct acl_role_label *rolep)
51107 +{
51108 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51109 +
51110 + unsigned int len;
51111 + char *tmp;
51112 +
51113 + rusertp = rolep->transitions;
51114 +
51115 + while (rusertp) {
51116 + rlast = rtmp;
51117 +
51118 + if ((rtmp = (struct role_transition *)
51119 + acl_alloc(sizeof (struct role_transition))) == NULL)
51120 + return -ENOMEM;
51121 +
51122 + if (copy_from_user(rtmp, rusertp,
51123 + sizeof (struct role_transition)))
51124 + return -EFAULT;
51125 +
51126 + rusertp = rtmp->prev;
51127 +
51128 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51129 +
51130 + if (!len || len >= GR_SPROLE_LEN)
51131 + return -EINVAL;
51132 +
51133 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51134 + return -ENOMEM;
51135 +
51136 + if (copy_from_user(tmp, rtmp->rolename, len))
51137 + return -EFAULT;
51138 + tmp[len-1] = '\0';
51139 + rtmp->rolename = tmp;
51140 +
51141 + if (!rlast) {
51142 + rtmp->prev = NULL;
51143 + rolep->transitions = rtmp;
51144 + } else {
51145 + rlast->next = rtmp;
51146 + rtmp->prev = rlast;
51147 + }
51148 +
51149 + if (!rusertp)
51150 + rtmp->next = NULL;
51151 + }
51152 +
51153 + return 0;
51154 +}
51155 +
51156 +static struct acl_subject_label *
51157 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51158 +{
51159 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51160 + unsigned int len;
51161 + char *tmp;
51162 + __u32 num_objs;
51163 + struct acl_ip_label **i_tmp, *i_utmp2;
51164 + struct gr_hash_struct ghash;
51165 + struct subject_map *subjmap;
51166 + unsigned int i_num;
51167 + int err;
51168 +
51169 + s_tmp = lookup_subject_map(userp);
51170 +
51171 + /* we've already copied this subject into the kernel, just return
51172 + the reference to it, and don't copy it over again
51173 + */
51174 + if (s_tmp)
51175 + return(s_tmp);
51176 +
51177 + if ((s_tmp = (struct acl_subject_label *)
51178 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51179 + return ERR_PTR(-ENOMEM);
51180 +
51181 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51182 + if (subjmap == NULL)
51183 + return ERR_PTR(-ENOMEM);
51184 +
51185 + subjmap->user = userp;
51186 + subjmap->kernel = s_tmp;
51187 + insert_subj_map_entry(subjmap);
51188 +
51189 + if (copy_from_user(s_tmp, userp,
51190 + sizeof (struct acl_subject_label)))
51191 + return ERR_PTR(-EFAULT);
51192 +
51193 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51194 +
51195 + if (!len || len >= PATH_MAX)
51196 + return ERR_PTR(-EINVAL);
51197 +
51198 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51199 + return ERR_PTR(-ENOMEM);
51200 +
51201 + if (copy_from_user(tmp, s_tmp->filename, len))
51202 + return ERR_PTR(-EFAULT);
51203 + tmp[len-1] = '\0';
51204 + s_tmp->filename = tmp;
51205 +
51206 + if (!strcmp(s_tmp->filename, "/"))
51207 + role->root_label = s_tmp;
51208 +
51209 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51210 + return ERR_PTR(-EFAULT);
51211 +
51212 + /* copy user and group transition tables */
51213 +
51214 + if (s_tmp->user_trans_num) {
51215 + uid_t *uidlist;
51216 +
51217 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51218 + if (uidlist == NULL)
51219 + return ERR_PTR(-ENOMEM);
51220 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51221 + return ERR_PTR(-EFAULT);
51222 +
51223 + s_tmp->user_transitions = uidlist;
51224 + }
51225 +
51226 + if (s_tmp->group_trans_num) {
51227 + gid_t *gidlist;
51228 +
51229 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51230 + if (gidlist == NULL)
51231 + return ERR_PTR(-ENOMEM);
51232 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51233 + return ERR_PTR(-EFAULT);
51234 +
51235 + s_tmp->group_transitions = gidlist;
51236 + }
51237 +
51238 + /* set up object hash table */
51239 + num_objs = count_user_objs(ghash.first);
51240 +
51241 + s_tmp->obj_hash_size = num_objs;
51242 + s_tmp->obj_hash =
51243 + (struct acl_object_label **)
51244 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51245 +
51246 + if (!s_tmp->obj_hash)
51247 + return ERR_PTR(-ENOMEM);
51248 +
51249 + memset(s_tmp->obj_hash, 0,
51250 + s_tmp->obj_hash_size *
51251 + sizeof (struct acl_object_label *));
51252 +
51253 + /* add in objects */
51254 + err = copy_user_objs(ghash.first, s_tmp, role);
51255 +
51256 + if (err)
51257 + return ERR_PTR(err);
51258 +
51259 + /* set pointer for parent subject */
51260 + if (s_tmp->parent_subject) {
51261 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51262 +
51263 + if (IS_ERR(s_tmp2))
51264 + return s_tmp2;
51265 +
51266 + s_tmp->parent_subject = s_tmp2;
51267 + }
51268 +
51269 + /* add in ip acls */
51270 +
51271 + if (!s_tmp->ip_num) {
51272 + s_tmp->ips = NULL;
51273 + goto insert;
51274 + }
51275 +
51276 + i_tmp =
51277 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51278 + sizeof (struct acl_ip_label *));
51279 +
51280 + if (!i_tmp)
51281 + return ERR_PTR(-ENOMEM);
51282 +
51283 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51284 + *(i_tmp + i_num) =
51285 + (struct acl_ip_label *)
51286 + acl_alloc(sizeof (struct acl_ip_label));
51287 + if (!*(i_tmp + i_num))
51288 + return ERR_PTR(-ENOMEM);
51289 +
51290 + if (copy_from_user
51291 + (&i_utmp2, s_tmp->ips + i_num,
51292 + sizeof (struct acl_ip_label *)))
51293 + return ERR_PTR(-EFAULT);
51294 +
51295 + if (copy_from_user
51296 + (*(i_tmp + i_num), i_utmp2,
51297 + sizeof (struct acl_ip_label)))
51298 + return ERR_PTR(-EFAULT);
51299 +
51300 + if ((*(i_tmp + i_num))->iface == NULL)
51301 + continue;
51302 +
51303 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
51304 + if (!len || len >= IFNAMSIZ)
51305 + return ERR_PTR(-EINVAL);
51306 + tmp = acl_alloc(len);
51307 + if (tmp == NULL)
51308 + return ERR_PTR(-ENOMEM);
51309 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
51310 + return ERR_PTR(-EFAULT);
51311 + (*(i_tmp + i_num))->iface = tmp;
51312 + }
51313 +
51314 + s_tmp->ips = i_tmp;
51315 +
51316 +insert:
51317 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
51318 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
51319 + return ERR_PTR(-ENOMEM);
51320 +
51321 + return s_tmp;
51322 +}
51323 +
51324 +static int
51325 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
51326 +{
51327 + struct acl_subject_label s_pre;
51328 + struct acl_subject_label * ret;
51329 + int err;
51330 +
51331 + while (userp) {
51332 + if (copy_from_user(&s_pre, userp,
51333 + sizeof (struct acl_subject_label)))
51334 + return -EFAULT;
51335 +
51336 + /* do not add nested subjects here, add
51337 + while parsing objects
51338 + */
51339 +
51340 + if (s_pre.mode & GR_NESTED) {
51341 + userp = s_pre.prev;
51342 + continue;
51343 + }
51344 +
51345 + ret = do_copy_user_subj(userp, role);
51346 +
51347 + err = PTR_ERR(ret);
51348 + if (IS_ERR(ret))
51349 + return err;
51350 +
51351 + insert_acl_subj_label(ret, role);
51352 +
51353 + userp = s_pre.prev;
51354 + }
51355 +
51356 + return 0;
51357 +}
51358 +
51359 +static int
51360 +copy_user_acl(struct gr_arg *arg)
51361 +{
51362 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51363 + struct sprole_pw *sptmp;
51364 + struct gr_hash_struct *ghash;
51365 + uid_t *domainlist;
51366 + unsigned int r_num;
51367 + unsigned int len;
51368 + char *tmp;
51369 + int err = 0;
51370 + __u16 i;
51371 + __u32 num_subjs;
51372 +
51373 + /* we need a default and kernel role */
51374 + if (arg->role_db.num_roles < 2)
51375 + return -EINVAL;
51376 +
51377 + /* copy special role authentication info from userspace */
51378 +
51379 + num_sprole_pws = arg->num_sprole_pws;
51380 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51381 +
51382 + if (!acl_special_roles) {
51383 + err = -ENOMEM;
51384 + goto cleanup;
51385 + }
51386 +
51387 + for (i = 0; i < num_sprole_pws; i++) {
51388 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51389 + if (!sptmp) {
51390 + err = -ENOMEM;
51391 + goto cleanup;
51392 + }
51393 + if (copy_from_user(sptmp, arg->sprole_pws + i,
51394 + sizeof (struct sprole_pw))) {
51395 + err = -EFAULT;
51396 + goto cleanup;
51397 + }
51398 +
51399 + len =
51400 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51401 +
51402 + if (!len || len >= GR_SPROLE_LEN) {
51403 + err = -EINVAL;
51404 + goto cleanup;
51405 + }
51406 +
51407 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
51408 + err = -ENOMEM;
51409 + goto cleanup;
51410 + }
51411 +
51412 + if (copy_from_user(tmp, sptmp->rolename, len)) {
51413 + err = -EFAULT;
51414 + goto cleanup;
51415 + }
51416 + tmp[len-1] = '\0';
51417 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51418 + printk(KERN_ALERT "Copying special role %s\n", tmp);
51419 +#endif
51420 + sptmp->rolename = tmp;
51421 + acl_special_roles[i] = sptmp;
51422 + }
51423 +
51424 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51425 +
51426 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51427 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
51428 +
51429 + if (!r_tmp) {
51430 + err = -ENOMEM;
51431 + goto cleanup;
51432 + }
51433 +
51434 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
51435 + sizeof (struct acl_role_label *))) {
51436 + err = -EFAULT;
51437 + goto cleanup;
51438 + }
51439 +
51440 + if (copy_from_user(r_tmp, r_utmp2,
51441 + sizeof (struct acl_role_label))) {
51442 + err = -EFAULT;
51443 + goto cleanup;
51444 + }
51445 +
51446 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51447 +
51448 + if (!len || len >= PATH_MAX) {
51449 + err = -EINVAL;
51450 + goto cleanup;
51451 + }
51452 +
51453 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
51454 + err = -ENOMEM;
51455 + goto cleanup;
51456 + }
51457 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
51458 + err = -EFAULT;
51459 + goto cleanup;
51460 + }
51461 + tmp[len-1] = '\0';
51462 + r_tmp->rolename = tmp;
51463 +
51464 + if (!strcmp(r_tmp->rolename, "default")
51465 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51466 + default_role = r_tmp;
51467 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51468 + kernel_role = r_tmp;
51469 + }
51470 +
51471 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
51472 + err = -ENOMEM;
51473 + goto cleanup;
51474 + }
51475 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
51476 + err = -EFAULT;
51477 + goto cleanup;
51478 + }
51479 +
51480 + r_tmp->hash = ghash;
51481 +
51482 + num_subjs = count_user_subjs(r_tmp->hash->first);
51483 +
51484 + r_tmp->subj_hash_size = num_subjs;
51485 + r_tmp->subj_hash =
51486 + (struct acl_subject_label **)
51487 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51488 +
51489 + if (!r_tmp->subj_hash) {
51490 + err = -ENOMEM;
51491 + goto cleanup;
51492 + }
51493 +
51494 + err = copy_user_allowedips(r_tmp);
51495 + if (err)
51496 + goto cleanup;
51497 +
51498 + /* copy domain info */
51499 + if (r_tmp->domain_children != NULL) {
51500 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51501 + if (domainlist == NULL) {
51502 + err = -ENOMEM;
51503 + goto cleanup;
51504 + }
51505 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
51506 + err = -EFAULT;
51507 + goto cleanup;
51508 + }
51509 + r_tmp->domain_children = domainlist;
51510 + }
51511 +
51512 + err = copy_user_transitions(r_tmp);
51513 + if (err)
51514 + goto cleanup;
51515 +
51516 + memset(r_tmp->subj_hash, 0,
51517 + r_tmp->subj_hash_size *
51518 + sizeof (struct acl_subject_label *));
51519 +
51520 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51521 +
51522 + if (err)
51523 + goto cleanup;
51524 +
51525 + /* set nested subject list to null */
51526 + r_tmp->hash->first = NULL;
51527 +
51528 + insert_acl_role_label(r_tmp);
51529 + }
51530 +
51531 + goto return_err;
51532 + cleanup:
51533 + free_variables();
51534 + return_err:
51535 + return err;
51536 +
51537 +}
51538 +
51539 +static int
51540 +gracl_init(struct gr_arg *args)
51541 +{
51542 + int error = 0;
51543 +
51544 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51545 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51546 +
51547 + if (init_variables(args)) {
51548 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51549 + error = -ENOMEM;
51550 + free_variables();
51551 + goto out;
51552 + }
51553 +
51554 + error = copy_user_acl(args);
51555 + free_init_variables();
51556 + if (error) {
51557 + free_variables();
51558 + goto out;
51559 + }
51560 +
51561 + if ((error = gr_set_acls(0))) {
51562 + free_variables();
51563 + goto out;
51564 + }
51565 +
51566 + pax_open_kernel();
51567 + gr_status |= GR_READY;
51568 + pax_close_kernel();
51569 +
51570 + out:
51571 + return error;
51572 +}
51573 +
51574 +/* derived from glibc fnmatch() 0: match, 1: no match*/
51575 +
51576 +static int
51577 +glob_match(const char *p, const char *n)
51578 +{
51579 + char c;
51580 +
51581 + while ((c = *p++) != '\0') {
51582 + switch (c) {
51583 + case '?':
51584 + if (*n == '\0')
51585 + return 1;
51586 + else if (*n == '/')
51587 + return 1;
51588 + break;
51589 + case '\\':
51590 + if (*n != c)
51591 + return 1;
51592 + break;
51593 + case '*':
51594 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
51595 + if (*n == '/')
51596 + return 1;
51597 + else if (c == '?') {
51598 + if (*n == '\0')
51599 + return 1;
51600 + else
51601 + ++n;
51602 + }
51603 + }
51604 + if (c == '\0') {
51605 + return 0;
51606 + } else {
51607 + const char *endp;
51608 +
51609 + if ((endp = strchr(n, '/')) == NULL)
51610 + endp = n + strlen(n);
51611 +
51612 + if (c == '[') {
51613 + for (--p; n < endp; ++n)
51614 + if (!glob_match(p, n))
51615 + return 0;
51616 + } else if (c == '/') {
51617 + while (*n != '\0' && *n != '/')
51618 + ++n;
51619 + if (*n == '/' && !glob_match(p, n + 1))
51620 + return 0;
51621 + } else {
51622 + for (--p; n < endp; ++n)
51623 + if (*n == c && !glob_match(p, n))
51624 + return 0;
51625 + }
51626 +
51627 + return 1;
51628 + }
51629 + case '[':
51630 + {
51631 + int not;
51632 + char cold;
51633 +
51634 + if (*n == '\0' || *n == '/')
51635 + return 1;
51636 +
51637 + not = (*p == '!' || *p == '^');
51638 + if (not)
51639 + ++p;
51640 +
51641 + c = *p++;
51642 + for (;;) {
51643 + unsigned char fn = (unsigned char)*n;
51644 +
51645 + if (c == '\0')
51646 + return 1;
51647 + else {
51648 + if (c == fn)
51649 + goto matched;
51650 + cold = c;
51651 + c = *p++;
51652 +
51653 + if (c == '-' && *p != ']') {
51654 + unsigned char cend = *p++;
51655 +
51656 + if (cend == '\0')
51657 + return 1;
51658 +
51659 + if (cold <= fn && fn <= cend)
51660 + goto matched;
51661 +
51662 + c = *p++;
51663 + }
51664 + }
51665 +
51666 + if (c == ']')
51667 + break;
51668 + }
51669 + if (!not)
51670 + return 1;
51671 + break;
51672 + matched:
51673 + while (c != ']') {
51674 + if (c == '\0')
51675 + return 1;
51676 +
51677 + c = *p++;
51678 + }
51679 + if (not)
51680 + return 1;
51681 + }
51682 + break;
51683 + default:
51684 + if (c != *n)
51685 + return 1;
51686 + }
51687 +
51688 + ++n;
51689 + }
51690 +
51691 + if (*n == '\0')
51692 + return 0;
51693 +
51694 + if (*n == '/')
51695 + return 0;
51696 +
51697 + return 1;
51698 +}
51699 +
51700 +static struct acl_object_label *
51701 +chk_glob_label(struct acl_object_label *globbed,
51702 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
51703 +{
51704 + struct acl_object_label *tmp;
51705 +
51706 + if (*path == NULL)
51707 + *path = gr_to_filename_nolock(dentry, mnt);
51708 +
51709 + tmp = globbed;
51710 +
51711 + while (tmp) {
51712 + if (!glob_match(tmp->filename, *path))
51713 + return tmp;
51714 + tmp = tmp->next;
51715 + }
51716 +
51717 + return NULL;
51718 +}
51719 +
51720 +static struct acl_object_label *
51721 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51722 + const ino_t curr_ino, const dev_t curr_dev,
51723 + const struct acl_subject_label *subj, char **path, const int checkglob)
51724 +{
51725 + struct acl_subject_label *tmpsubj;
51726 + struct acl_object_label *retval;
51727 + struct acl_object_label *retval2;
51728 +
51729 + tmpsubj = (struct acl_subject_label *) subj;
51730 + read_lock(&gr_inode_lock);
51731 + do {
51732 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
51733 + if (retval) {
51734 + if (checkglob && retval->globbed) {
51735 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
51736 + if (retval2)
51737 + retval = retval2;
51738 + }
51739 + break;
51740 + }
51741 + } while ((tmpsubj = tmpsubj->parent_subject));
51742 + read_unlock(&gr_inode_lock);
51743 +
51744 + return retval;
51745 +}
51746 +
51747 +static __inline__ struct acl_object_label *
51748 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51749 + struct dentry *curr_dentry,
51750 + const struct acl_subject_label *subj, char **path, const int checkglob)
51751 +{
51752 + int newglob = checkglob;
51753 + ino_t inode;
51754 + dev_t device;
51755 +
51756 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
51757 + as we don't want a / * rule to match instead of the / object
51758 + don't do this for create lookups that call this function though, since they're looking up
51759 + on the parent and thus need globbing checks on all paths
51760 + */
51761 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
51762 + newglob = GR_NO_GLOB;
51763 +
51764 + spin_lock(&curr_dentry->d_lock);
51765 + inode = curr_dentry->d_inode->i_ino;
51766 + device = __get_dev(curr_dentry);
51767 + spin_unlock(&curr_dentry->d_lock);
51768 +
51769 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
51770 +}
51771 +
51772 +static struct acl_object_label *
51773 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51774 + const struct acl_subject_label *subj, char *path, const int checkglob)
51775 +{
51776 + struct dentry *dentry = (struct dentry *) l_dentry;
51777 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51778 + struct acl_object_label *retval;
51779 + struct dentry *parent;
51780 +
51781 + write_seqlock(&rename_lock);
51782 + br_read_lock(vfsmount_lock);
51783 +
51784 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
51785 +#ifdef CONFIG_NET
51786 + mnt == sock_mnt ||
51787 +#endif
51788 +#ifdef CONFIG_HUGETLBFS
51789 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
51790 +#endif
51791 + /* ignore Eric Biederman */
51792 + IS_PRIVATE(l_dentry->d_inode))) {
51793 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
51794 + goto out;
51795 + }
51796 +
51797 + for (;;) {
51798 + if (dentry == real_root.dentry && mnt == real_root.mnt)
51799 + break;
51800 +
51801 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51802 + if (mnt->mnt_parent == mnt)
51803 + break;
51804 +
51805 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51806 + if (retval != NULL)
51807 + goto out;
51808 +
51809 + dentry = mnt->mnt_mountpoint;
51810 + mnt = mnt->mnt_parent;
51811 + continue;
51812 + }
51813 +
51814 + parent = dentry->d_parent;
51815 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51816 + if (retval != NULL)
51817 + goto out;
51818 +
51819 + dentry = parent;
51820 + }
51821 +
51822 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51823 +
51824 + /* real_root is pinned so we don't have to hold a reference */
51825 + if (retval == NULL)
51826 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
51827 +out:
51828 + br_read_unlock(vfsmount_lock);
51829 + write_sequnlock(&rename_lock);
51830 +
51831 + BUG_ON(retval == NULL);
51832 +
51833 + return retval;
51834 +}
51835 +
51836 +static __inline__ struct acl_object_label *
51837 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51838 + const struct acl_subject_label *subj)
51839 +{
51840 + char *path = NULL;
51841 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
51842 +}
51843 +
51844 +static __inline__ struct acl_object_label *
51845 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51846 + const struct acl_subject_label *subj)
51847 +{
51848 + char *path = NULL;
51849 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
51850 +}
51851 +
51852 +static __inline__ struct acl_object_label *
51853 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51854 + const struct acl_subject_label *subj, char *path)
51855 +{
51856 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
51857 +}
51858 +
51859 +static struct acl_subject_label *
51860 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51861 + const struct acl_role_label *role)
51862 +{
51863 + struct dentry *dentry = (struct dentry *) l_dentry;
51864 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51865 + struct acl_subject_label *retval;
51866 + struct dentry *parent;
51867 +
51868 + write_seqlock(&rename_lock);
51869 + br_read_lock(vfsmount_lock);
51870 +
51871 + for (;;) {
51872 + if (dentry == real_root.dentry && mnt == real_root.mnt)
51873 + break;
51874 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51875 + if (mnt->mnt_parent == mnt)
51876 + break;
51877 +
51878 + spin_lock(&dentry->d_lock);
51879 + read_lock(&gr_inode_lock);
51880 + retval =
51881 + lookup_acl_subj_label(dentry->d_inode->i_ino,
51882 + __get_dev(dentry), role);
51883 + read_unlock(&gr_inode_lock);
51884 + spin_unlock(&dentry->d_lock);
51885 + if (retval != NULL)
51886 + goto out;
51887 +
51888 + dentry = mnt->mnt_mountpoint;
51889 + mnt = mnt->mnt_parent;
51890 + continue;
51891 + }
51892 +
51893 + spin_lock(&dentry->d_lock);
51894 + read_lock(&gr_inode_lock);
51895 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51896 + __get_dev(dentry), role);
51897 + read_unlock(&gr_inode_lock);
51898 + parent = dentry->d_parent;
51899 + spin_unlock(&dentry->d_lock);
51900 +
51901 + if (retval != NULL)
51902 + goto out;
51903 +
51904 + dentry = parent;
51905 + }
51906 +
51907 + spin_lock(&dentry->d_lock);
51908 + read_lock(&gr_inode_lock);
51909 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51910 + __get_dev(dentry), role);
51911 + read_unlock(&gr_inode_lock);
51912 + spin_unlock(&dentry->d_lock);
51913 +
51914 + if (unlikely(retval == NULL)) {
51915 + /* real_root is pinned, we don't need to hold a reference */
51916 + read_lock(&gr_inode_lock);
51917 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
51918 + __get_dev(real_root.dentry), role);
51919 + read_unlock(&gr_inode_lock);
51920 + }
51921 +out:
51922 + br_read_unlock(vfsmount_lock);
51923 + write_sequnlock(&rename_lock);
51924 +
51925 + BUG_ON(retval == NULL);
51926 +
51927 + return retval;
51928 +}
51929 +
51930 +static void
51931 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
51932 +{
51933 + struct task_struct *task = current;
51934 + const struct cred *cred = current_cred();
51935 +
51936 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51937 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51938 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51939 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
51940 +
51941 + return;
51942 +}
51943 +
51944 +static void
51945 +gr_log_learn_sysctl(const char *path, const __u32 mode)
51946 +{
51947 + struct task_struct *task = current;
51948 + const struct cred *cred = current_cred();
51949 +
51950 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51951 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51952 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51953 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
51954 +
51955 + return;
51956 +}
51957 +
51958 +static void
51959 +gr_log_learn_id_change(const char type, const unsigned int real,
51960 + const unsigned int effective, const unsigned int fs)
51961 +{
51962 + struct task_struct *task = current;
51963 + const struct cred *cred = current_cred();
51964 +
51965 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
51966 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51967 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51968 + type, real, effective, fs, &task->signal->saved_ip);
51969 +
51970 + return;
51971 +}
51972 +
51973 +__u32
51974 +gr_search_file(const struct dentry * dentry, const __u32 mode,
51975 + const struct vfsmount * mnt)
51976 +{
51977 + __u32 retval = mode;
51978 + struct acl_subject_label *curracl;
51979 + struct acl_object_label *currobj;
51980 +
51981 + if (unlikely(!(gr_status & GR_READY)))
51982 + return (mode & ~GR_AUDITS);
51983 +
51984 + curracl = current->acl;
51985 +
51986 + currobj = chk_obj_label(dentry, mnt, curracl);
51987 + retval = currobj->mode & mode;
51988 +
51989 + /* if we're opening a specified transfer file for writing
51990 + (e.g. /dev/initctl), then transfer our role to init
51991 + */
51992 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
51993 + current->role->roletype & GR_ROLE_PERSIST)) {
51994 + struct task_struct *task = init_pid_ns.child_reaper;
51995 +
51996 + if (task->role != current->role) {
51997 + task->acl_sp_role = 0;
51998 + task->acl_role_id = current->acl_role_id;
51999 + task->role = current->role;
52000 + rcu_read_lock();
52001 + read_lock(&grsec_exec_file_lock);
52002 + gr_apply_subject_to_task(task);
52003 + read_unlock(&grsec_exec_file_lock);
52004 + rcu_read_unlock();
52005 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52006 + }
52007 + }
52008 +
52009 + if (unlikely
52010 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52011 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52012 + __u32 new_mode = mode;
52013 +
52014 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52015 +
52016 + retval = new_mode;
52017 +
52018 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52019 + new_mode |= GR_INHERIT;
52020 +
52021 + if (!(mode & GR_NOLEARN))
52022 + gr_log_learn(dentry, mnt, new_mode);
52023 + }
52024 +
52025 + return retval;
52026 +}
52027 +
52028 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52029 + const struct dentry *parent,
52030 + const struct vfsmount *mnt)
52031 +{
52032 + struct name_entry *match;
52033 + struct acl_object_label *matchpo;
52034 + struct acl_subject_label *curracl;
52035 + char *path;
52036 +
52037 + if (unlikely(!(gr_status & GR_READY)))
52038 + return NULL;
52039 +
52040 + preempt_disable();
52041 + path = gr_to_filename_rbac(new_dentry, mnt);
52042 + match = lookup_name_entry_create(path);
52043 +
52044 + curracl = current->acl;
52045 +
52046 + if (match) {
52047 + read_lock(&gr_inode_lock);
52048 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52049 + read_unlock(&gr_inode_lock);
52050 +
52051 + if (matchpo) {
52052 + preempt_enable();
52053 + return matchpo;
52054 + }
52055 + }
52056 +
52057 + // lookup parent
52058 +
52059 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52060 +
52061 + preempt_enable();
52062 + return matchpo;
52063 +}
52064 +
52065 +__u32
52066 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52067 + const struct vfsmount * mnt, const __u32 mode)
52068 +{
52069 + struct acl_object_label *matchpo;
52070 + __u32 retval;
52071 +
52072 + if (unlikely(!(gr_status & GR_READY)))
52073 + return (mode & ~GR_AUDITS);
52074 +
52075 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52076 +
52077 + retval = matchpo->mode & mode;
52078 +
52079 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52080 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52081 + __u32 new_mode = mode;
52082 +
52083 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52084 +
52085 + gr_log_learn(new_dentry, mnt, new_mode);
52086 + return new_mode;
52087 + }
52088 +
52089 + return retval;
52090 +}
52091 +
52092 +__u32
52093 +gr_check_link(const struct dentry * new_dentry,
52094 + const struct dentry * parent_dentry,
52095 + const struct vfsmount * parent_mnt,
52096 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52097 +{
52098 + struct acl_object_label *obj;
52099 + __u32 oldmode, newmode;
52100 + __u32 needmode;
52101 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52102 + GR_DELETE | GR_INHERIT;
52103 +
52104 + if (unlikely(!(gr_status & GR_READY)))
52105 + return (GR_CREATE | GR_LINK);
52106 +
52107 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52108 + oldmode = obj->mode;
52109 +
52110 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52111 + newmode = obj->mode;
52112 +
52113 + needmode = newmode & checkmodes;
52114 +
52115 + // old name for hardlink must have at least the permissions of the new name
52116 + if ((oldmode & needmode) != needmode)
52117 + goto bad;
52118 +
52119 + // if old name had restrictions/auditing, make sure the new name does as well
52120 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52121 +
52122 + // don't allow hardlinking of suid/sgid files without permission
52123 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52124 + needmode |= GR_SETID;
52125 +
52126 + if ((newmode & needmode) != needmode)
52127 + goto bad;
52128 +
52129 + // enforce minimum permissions
52130 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52131 + return newmode;
52132 +bad:
52133 + needmode = oldmode;
52134 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52135 + needmode |= GR_SETID;
52136 +
52137 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52138 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52139 + return (GR_CREATE | GR_LINK);
52140 + } else if (newmode & GR_SUPPRESS)
52141 + return GR_SUPPRESS;
52142 + else
52143 + return 0;
52144 +}
52145 +
52146 +int
52147 +gr_check_hidden_task(const struct task_struct *task)
52148 +{
52149 + if (unlikely(!(gr_status & GR_READY)))
52150 + return 0;
52151 +
52152 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52153 + return 1;
52154 +
52155 + return 0;
52156 +}
52157 +
52158 +int
52159 +gr_check_protected_task(const struct task_struct *task)
52160 +{
52161 + if (unlikely(!(gr_status & GR_READY) || !task))
52162 + return 0;
52163 +
52164 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52165 + task->acl != current->acl)
52166 + return 1;
52167 +
52168 + return 0;
52169 +}
52170 +
52171 +int
52172 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52173 +{
52174 + struct task_struct *p;
52175 + int ret = 0;
52176 +
52177 + if (unlikely(!(gr_status & GR_READY) || !pid))
52178 + return ret;
52179 +
52180 + read_lock(&tasklist_lock);
52181 + do_each_pid_task(pid, type, p) {
52182 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52183 + p->acl != current->acl) {
52184 + ret = 1;
52185 + goto out;
52186 + }
52187 + } while_each_pid_task(pid, type, p);
52188 +out:
52189 + read_unlock(&tasklist_lock);
52190 +
52191 + return ret;
52192 +}
52193 +
52194 +void
52195 +gr_copy_label(struct task_struct *tsk)
52196 +{
52197 + /* plain copying of fields is already done by dup_task_struct */
52198 + tsk->signal->used_accept = 0;
52199 + tsk->acl_sp_role = 0;
52200 + //tsk->acl_role_id = current->acl_role_id;
52201 + //tsk->acl = current->acl;
52202 + //tsk->role = current->role;
52203 + tsk->signal->curr_ip = current->signal->curr_ip;
52204 + tsk->signal->saved_ip = current->signal->saved_ip;
52205 + if (current->exec_file)
52206 + get_file(current->exec_file);
52207 + //tsk->exec_file = current->exec_file;
52208 + //tsk->is_writable = current->is_writable;
52209 + if (unlikely(current->signal->used_accept)) {
52210 + current->signal->curr_ip = 0;
52211 + current->signal->saved_ip = 0;
52212 + }
52213 +
52214 + return;
52215 +}
52216 +
52217 +static void
52218 +gr_set_proc_res(struct task_struct *task)
52219 +{
52220 + struct acl_subject_label *proc;
52221 + unsigned short i;
52222 +
52223 + proc = task->acl;
52224 +
52225 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52226 + return;
52227 +
52228 + for (i = 0; i < RLIM_NLIMITS; i++) {
52229 + if (!(proc->resmask & (1 << i)))
52230 + continue;
52231 +
52232 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52233 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52234 + }
52235 +
52236 + return;
52237 +}
52238 +
52239 +extern int __gr_process_user_ban(struct user_struct *user);
52240 +
52241 +int
52242 +gr_check_user_change(int real, int effective, int fs)
52243 +{
52244 + unsigned int i;
52245 + __u16 num;
52246 + uid_t *uidlist;
52247 + int curuid;
52248 + int realok = 0;
52249 + int effectiveok = 0;
52250 + int fsok = 0;
52251 +
52252 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52253 + struct user_struct *user;
52254 +
52255 + if (real == -1)
52256 + goto skipit;
52257 +
52258 + user = find_user(real);
52259 + if (user == NULL)
52260 + goto skipit;
52261 +
52262 + if (__gr_process_user_ban(user)) {
52263 + /* for find_user */
52264 + free_uid(user);
52265 + return 1;
52266 + }
52267 +
52268 + /* for find_user */
52269 + free_uid(user);
52270 +
52271 +skipit:
52272 +#endif
52273 +
52274 + if (unlikely(!(gr_status & GR_READY)))
52275 + return 0;
52276 +
52277 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52278 + gr_log_learn_id_change('u', real, effective, fs);
52279 +
52280 + num = current->acl->user_trans_num;
52281 + uidlist = current->acl->user_transitions;
52282 +
52283 + if (uidlist == NULL)
52284 + return 0;
52285 +
52286 + if (real == -1)
52287 + realok = 1;
52288 + if (effective == -1)
52289 + effectiveok = 1;
52290 + if (fs == -1)
52291 + fsok = 1;
52292 +
52293 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52294 + for (i = 0; i < num; i++) {
52295 + curuid = (int)uidlist[i];
52296 + if (real == curuid)
52297 + realok = 1;
52298 + if (effective == curuid)
52299 + effectiveok = 1;
52300 + if (fs == curuid)
52301 + fsok = 1;
52302 + }
52303 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52304 + for (i = 0; i < num; i++) {
52305 + curuid = (int)uidlist[i];
52306 + if (real == curuid)
52307 + break;
52308 + if (effective == curuid)
52309 + break;
52310 + if (fs == curuid)
52311 + break;
52312 + }
52313 + /* not in deny list */
52314 + if (i == num) {
52315 + realok = 1;
52316 + effectiveok = 1;
52317 + fsok = 1;
52318 + }
52319 + }
52320 +
52321 + if (realok && effectiveok && fsok)
52322 + return 0;
52323 + else {
52324 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52325 + return 1;
52326 + }
52327 +}
52328 +
52329 +int
52330 +gr_check_group_change(int real, int effective, int fs)
52331 +{
52332 + unsigned int i;
52333 + __u16 num;
52334 + gid_t *gidlist;
52335 + int curgid;
52336 + int realok = 0;
52337 + int effectiveok = 0;
52338 + int fsok = 0;
52339 +
52340 + if (unlikely(!(gr_status & GR_READY)))
52341 + return 0;
52342 +
52343 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52344 + gr_log_learn_id_change('g', real, effective, fs);
52345 +
52346 + num = current->acl->group_trans_num;
52347 + gidlist = current->acl->group_transitions;
52348 +
52349 + if (gidlist == NULL)
52350 + return 0;
52351 +
52352 + if (real == -1)
52353 + realok = 1;
52354 + if (effective == -1)
52355 + effectiveok = 1;
52356 + if (fs == -1)
52357 + fsok = 1;
52358 +
52359 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
52360 + for (i = 0; i < num; i++) {
52361 + curgid = (int)gidlist[i];
52362 + if (real == curgid)
52363 + realok = 1;
52364 + if (effective == curgid)
52365 + effectiveok = 1;
52366 + if (fs == curgid)
52367 + fsok = 1;
52368 + }
52369 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
52370 + for (i = 0; i < num; i++) {
52371 + curgid = (int)gidlist[i];
52372 + if (real == curgid)
52373 + break;
52374 + if (effective == curgid)
52375 + break;
52376 + if (fs == curgid)
52377 + break;
52378 + }
52379 + /* not in deny list */
52380 + if (i == num) {
52381 + realok = 1;
52382 + effectiveok = 1;
52383 + fsok = 1;
52384 + }
52385 + }
52386 +
52387 + if (realok && effectiveok && fsok)
52388 + return 0;
52389 + else {
52390 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52391 + return 1;
52392 + }
52393 +}
52394 +
52395 +extern int gr_acl_is_capable(const int cap);
52396 +
52397 +void
52398 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52399 +{
52400 + struct acl_role_label *role = task->role;
52401 + struct acl_subject_label *subj = NULL;
52402 + struct acl_object_label *obj;
52403 + struct file *filp;
52404 +
52405 + if (unlikely(!(gr_status & GR_READY)))
52406 + return;
52407 +
52408 + filp = task->exec_file;
52409 +
52410 + /* kernel process, we'll give them the kernel role */
52411 + if (unlikely(!filp)) {
52412 + task->role = kernel_role;
52413 + task->acl = kernel_role->root_label;
52414 + return;
52415 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52416 + role = lookup_acl_role_label(task, uid, gid);
52417 +
52418 + /* don't change the role if we're not a privileged process */
52419 + if (role && task->role != role &&
52420 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52421 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52422 + return;
52423 +
52424 + /* perform subject lookup in possibly new role
52425 + we can use this result below in the case where role == task->role
52426 + */
52427 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52428 +
52429 + /* if we changed uid/gid, but result in the same role
52430 + and are using inheritance, don't lose the inherited subject
52431 + if current subject is other than what normal lookup
52432 + would result in, we arrived via inheritance, don't
52433 + lose subject
52434 + */
52435 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52436 + (subj == task->acl)))
52437 + task->acl = subj;
52438 +
52439 + task->role = role;
52440 +
52441 + task->is_writable = 0;
52442 +
52443 + /* ignore additional mmap checks for processes that are writable
52444 + by the default ACL */
52445 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52446 + if (unlikely(obj->mode & GR_WRITE))
52447 + task->is_writable = 1;
52448 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52449 + if (unlikely(obj->mode & GR_WRITE))
52450 + task->is_writable = 1;
52451 +
52452 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52453 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52454 +#endif
52455 +
52456 + gr_set_proc_res(task);
52457 +
52458 + return;
52459 +}
52460 +
52461 +int
52462 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52463 + const int unsafe_flags)
52464 +{
52465 + struct task_struct *task = current;
52466 + struct acl_subject_label *newacl;
52467 + struct acl_object_label *obj;
52468 + __u32 retmode;
52469 +
52470 + if (unlikely(!(gr_status & GR_READY)))
52471 + return 0;
52472 +
52473 + newacl = chk_subj_label(dentry, mnt, task->role);
52474 +
52475 + task_lock(task);
52476 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52477 + !(task->role->roletype & GR_ROLE_GOD) &&
52478 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52479 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52480 + task_unlock(task);
52481 + if (unsafe_flags & LSM_UNSAFE_SHARE)
52482 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52483 + else
52484 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52485 + return -EACCES;
52486 + }
52487 + task_unlock(task);
52488 +
52489 + obj = chk_obj_label(dentry, mnt, task->acl);
52490 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52491 +
52492 + if (!(task->acl->mode & GR_INHERITLEARN) &&
52493 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52494 + if (obj->nested)
52495 + task->acl = obj->nested;
52496 + else
52497 + task->acl = newacl;
52498 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52499 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52500 +
52501 + task->is_writable = 0;
52502 +
52503 + /* ignore additional mmap checks for processes that are writable
52504 + by the default ACL */
52505 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
52506 + if (unlikely(obj->mode & GR_WRITE))
52507 + task->is_writable = 1;
52508 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
52509 + if (unlikely(obj->mode & GR_WRITE))
52510 + task->is_writable = 1;
52511 +
52512 + gr_set_proc_res(task);
52513 +
52514 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52515 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52516 +#endif
52517 + return 0;
52518 +}
52519 +
52520 +/* always called with valid inodev ptr */
52521 +static void
52522 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52523 +{
52524 + struct acl_object_label *matchpo;
52525 + struct acl_subject_label *matchps;
52526 + struct acl_subject_label *subj;
52527 + struct acl_role_label *role;
52528 + unsigned int x;
52529 +
52530 + FOR_EACH_ROLE_START(role)
52531 + FOR_EACH_SUBJECT_START(role, subj, x)
52532 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52533 + matchpo->mode |= GR_DELETED;
52534 + FOR_EACH_SUBJECT_END(subj,x)
52535 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52536 + if (subj->inode == ino && subj->device == dev)
52537 + subj->mode |= GR_DELETED;
52538 + FOR_EACH_NESTED_SUBJECT_END(subj)
52539 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52540 + matchps->mode |= GR_DELETED;
52541 + FOR_EACH_ROLE_END(role)
52542 +
52543 + inodev->nentry->deleted = 1;
52544 +
52545 + return;
52546 +}
52547 +
52548 +void
52549 +gr_handle_delete(const ino_t ino, const dev_t dev)
52550 +{
52551 + struct inodev_entry *inodev;
52552 +
52553 + if (unlikely(!(gr_status & GR_READY)))
52554 + return;
52555 +
52556 + write_lock(&gr_inode_lock);
52557 + inodev = lookup_inodev_entry(ino, dev);
52558 + if (inodev != NULL)
52559 + do_handle_delete(inodev, ino, dev);
52560 + write_unlock(&gr_inode_lock);
52561 +
52562 + return;
52563 +}
52564 +
52565 +static void
52566 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52567 + const ino_t newinode, const dev_t newdevice,
52568 + struct acl_subject_label *subj)
52569 +{
52570 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52571 + struct acl_object_label *match;
52572 +
52573 + match = subj->obj_hash[index];
52574 +
52575 + while (match && (match->inode != oldinode ||
52576 + match->device != olddevice ||
52577 + !(match->mode & GR_DELETED)))
52578 + match = match->next;
52579 +
52580 + if (match && (match->inode == oldinode)
52581 + && (match->device == olddevice)
52582 + && (match->mode & GR_DELETED)) {
52583 + if (match->prev == NULL) {
52584 + subj->obj_hash[index] = match->next;
52585 + if (match->next != NULL)
52586 + match->next->prev = NULL;
52587 + } else {
52588 + match->prev->next = match->next;
52589 + if (match->next != NULL)
52590 + match->next->prev = match->prev;
52591 + }
52592 + match->prev = NULL;
52593 + match->next = NULL;
52594 + match->inode = newinode;
52595 + match->device = newdevice;
52596 + match->mode &= ~GR_DELETED;
52597 +
52598 + insert_acl_obj_label(match, subj);
52599 + }
52600 +
52601 + return;
52602 +}
52603 +
52604 +static void
52605 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52606 + const ino_t newinode, const dev_t newdevice,
52607 + struct acl_role_label *role)
52608 +{
52609 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52610 + struct acl_subject_label *match;
52611 +
52612 + match = role->subj_hash[index];
52613 +
52614 + while (match && (match->inode != oldinode ||
52615 + match->device != olddevice ||
52616 + !(match->mode & GR_DELETED)))
52617 + match = match->next;
52618 +
52619 + if (match && (match->inode == oldinode)
52620 + && (match->device == olddevice)
52621 + && (match->mode & GR_DELETED)) {
52622 + if (match->prev == NULL) {
52623 + role->subj_hash[index] = match->next;
52624 + if (match->next != NULL)
52625 + match->next->prev = NULL;
52626 + } else {
52627 + match->prev->next = match->next;
52628 + if (match->next != NULL)
52629 + match->next->prev = match->prev;
52630 + }
52631 + match->prev = NULL;
52632 + match->next = NULL;
52633 + match->inode = newinode;
52634 + match->device = newdevice;
52635 + match->mode &= ~GR_DELETED;
52636 +
52637 + insert_acl_subj_label(match, role);
52638 + }
52639 +
52640 + return;
52641 +}
52642 +
52643 +static void
52644 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52645 + const ino_t newinode, const dev_t newdevice)
52646 +{
52647 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52648 + struct inodev_entry *match;
52649 +
52650 + match = inodev_set.i_hash[index];
52651 +
52652 + while (match && (match->nentry->inode != oldinode ||
52653 + match->nentry->device != olddevice || !match->nentry->deleted))
52654 + match = match->next;
52655 +
52656 + if (match && (match->nentry->inode == oldinode)
52657 + && (match->nentry->device == olddevice) &&
52658 + match->nentry->deleted) {
52659 + if (match->prev == NULL) {
52660 + inodev_set.i_hash[index] = match->next;
52661 + if (match->next != NULL)
52662 + match->next->prev = NULL;
52663 + } else {
52664 + match->prev->next = match->next;
52665 + if (match->next != NULL)
52666 + match->next->prev = match->prev;
52667 + }
52668 + match->prev = NULL;
52669 + match->next = NULL;
52670 + match->nentry->inode = newinode;
52671 + match->nentry->device = newdevice;
52672 + match->nentry->deleted = 0;
52673 +
52674 + insert_inodev_entry(match);
52675 + }
52676 +
52677 + return;
52678 +}
52679 +
52680 +static void
52681 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
52682 +{
52683 + struct acl_subject_label *subj;
52684 + struct acl_role_label *role;
52685 + unsigned int x;
52686 +
52687 + FOR_EACH_ROLE_START(role)
52688 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
52689 +
52690 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52691 + if ((subj->inode == ino) && (subj->device == dev)) {
52692 + subj->inode = ino;
52693 + subj->device = dev;
52694 + }
52695 + FOR_EACH_NESTED_SUBJECT_END(subj)
52696 + FOR_EACH_SUBJECT_START(role, subj, x)
52697 + update_acl_obj_label(matchn->inode, matchn->device,
52698 + ino, dev, subj);
52699 + FOR_EACH_SUBJECT_END(subj,x)
52700 + FOR_EACH_ROLE_END(role)
52701 +
52702 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
52703 +
52704 + return;
52705 +}
52706 +
52707 +static void
52708 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
52709 + const struct vfsmount *mnt)
52710 +{
52711 + ino_t ino = dentry->d_inode->i_ino;
52712 + dev_t dev = __get_dev(dentry);
52713 +
52714 + __do_handle_create(matchn, ino, dev);
52715 +
52716 + return;
52717 +}
52718 +
52719 +void
52720 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
52721 +{
52722 + struct name_entry *matchn;
52723 +
52724 + if (unlikely(!(gr_status & GR_READY)))
52725 + return;
52726 +
52727 + preempt_disable();
52728 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
52729 +
52730 + if (unlikely((unsigned long)matchn)) {
52731 + write_lock(&gr_inode_lock);
52732 + do_handle_create(matchn, dentry, mnt);
52733 + write_unlock(&gr_inode_lock);
52734 + }
52735 + preempt_enable();
52736 +
52737 + return;
52738 +}
52739 +
52740 +void
52741 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
52742 +{
52743 + struct name_entry *matchn;
52744 +
52745 + if (unlikely(!(gr_status & GR_READY)))
52746 + return;
52747 +
52748 + preempt_disable();
52749 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
52750 +
52751 + if (unlikely((unsigned long)matchn)) {
52752 + write_lock(&gr_inode_lock);
52753 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
52754 + write_unlock(&gr_inode_lock);
52755 + }
52756 + preempt_enable();
52757 +
52758 + return;
52759 +}
52760 +
52761 +void
52762 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
52763 + struct dentry *old_dentry,
52764 + struct dentry *new_dentry,
52765 + struct vfsmount *mnt, const __u8 replace)
52766 +{
52767 + struct name_entry *matchn;
52768 + struct inodev_entry *inodev;
52769 + struct inode *inode = new_dentry->d_inode;
52770 + ino_t old_ino = old_dentry->d_inode->i_ino;
52771 + dev_t old_dev = __get_dev(old_dentry);
52772 +
52773 + /* vfs_rename swaps the name and parent link for old_dentry and
52774 + new_dentry
52775 + at this point, old_dentry has the new name, parent link, and inode
52776 + for the renamed file
52777 + if a file is being replaced by a rename, new_dentry has the inode
52778 + and name for the replaced file
52779 + */
52780 +
52781 + if (unlikely(!(gr_status & GR_READY)))
52782 + return;
52783 +
52784 + preempt_disable();
52785 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
52786 +
52787 + /* we wouldn't have to check d_inode if it weren't for
52788 + NFS silly-renaming
52789 + */
52790 +
52791 + write_lock(&gr_inode_lock);
52792 + if (unlikely(replace && inode)) {
52793 + ino_t new_ino = inode->i_ino;
52794 + dev_t new_dev = __get_dev(new_dentry);
52795 +
52796 + inodev = lookup_inodev_entry(new_ino, new_dev);
52797 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
52798 + do_handle_delete(inodev, new_ino, new_dev);
52799 + }
52800 +
52801 + inodev = lookup_inodev_entry(old_ino, old_dev);
52802 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
52803 + do_handle_delete(inodev, old_ino, old_dev);
52804 +
52805 + if (unlikely((unsigned long)matchn))
52806 + do_handle_create(matchn, old_dentry, mnt);
52807 +
52808 + write_unlock(&gr_inode_lock);
52809 + preempt_enable();
52810 +
52811 + return;
52812 +}
52813 +
52814 +static int
52815 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
52816 + unsigned char **sum)
52817 +{
52818 + struct acl_role_label *r;
52819 + struct role_allowed_ip *ipp;
52820 + struct role_transition *trans;
52821 + unsigned int i;
52822 + int found = 0;
52823 + u32 curr_ip = current->signal->curr_ip;
52824 +
52825 + current->signal->saved_ip = curr_ip;
52826 +
52827 + /* check transition table */
52828 +
52829 + for (trans = current->role->transitions; trans; trans = trans->next) {
52830 + if (!strcmp(rolename, trans->rolename)) {
52831 + found = 1;
52832 + break;
52833 + }
52834 + }
52835 +
52836 + if (!found)
52837 + return 0;
52838 +
52839 + /* handle special roles that do not require authentication
52840 + and check ip */
52841 +
52842 + FOR_EACH_ROLE_START(r)
52843 + if (!strcmp(rolename, r->rolename) &&
52844 + (r->roletype & GR_ROLE_SPECIAL)) {
52845 + found = 0;
52846 + if (r->allowed_ips != NULL) {
52847 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
52848 + if ((ntohl(curr_ip) & ipp->netmask) ==
52849 + (ntohl(ipp->addr) & ipp->netmask))
52850 + found = 1;
52851 + }
52852 + } else
52853 + found = 2;
52854 + if (!found)
52855 + return 0;
52856 +
52857 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
52858 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
52859 + *salt = NULL;
52860 + *sum = NULL;
52861 + return 1;
52862 + }
52863 + }
52864 + FOR_EACH_ROLE_END(r)
52865 +
52866 + for (i = 0; i < num_sprole_pws; i++) {
52867 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
52868 + *salt = acl_special_roles[i]->salt;
52869 + *sum = acl_special_roles[i]->sum;
52870 + return 1;
52871 + }
52872 + }
52873 +
52874 + return 0;
52875 +}
52876 +
52877 +static void
52878 +assign_special_role(char *rolename)
52879 +{
52880 + struct acl_object_label *obj;
52881 + struct acl_role_label *r;
52882 + struct acl_role_label *assigned = NULL;
52883 + struct task_struct *tsk;
52884 + struct file *filp;
52885 +
52886 + FOR_EACH_ROLE_START(r)
52887 + if (!strcmp(rolename, r->rolename) &&
52888 + (r->roletype & GR_ROLE_SPECIAL)) {
52889 + assigned = r;
52890 + break;
52891 + }
52892 + FOR_EACH_ROLE_END(r)
52893 +
52894 + if (!assigned)
52895 + return;
52896 +
52897 + read_lock(&tasklist_lock);
52898 + read_lock(&grsec_exec_file_lock);
52899 +
52900 + tsk = current->real_parent;
52901 + if (tsk == NULL)
52902 + goto out_unlock;
52903 +
52904 + filp = tsk->exec_file;
52905 + if (filp == NULL)
52906 + goto out_unlock;
52907 +
52908 + tsk->is_writable = 0;
52909 +
52910 + tsk->acl_sp_role = 1;
52911 + tsk->acl_role_id = ++acl_sp_role_value;
52912 + tsk->role = assigned;
52913 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
52914 +
52915 + /* ignore additional mmap checks for processes that are writable
52916 + by the default ACL */
52917 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52918 + if (unlikely(obj->mode & GR_WRITE))
52919 + tsk->is_writable = 1;
52920 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
52921 + if (unlikely(obj->mode & GR_WRITE))
52922 + tsk->is_writable = 1;
52923 +
52924 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52925 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
52926 +#endif
52927 +
52928 +out_unlock:
52929 + read_unlock(&grsec_exec_file_lock);
52930 + read_unlock(&tasklist_lock);
52931 + return;
52932 +}
52933 +
52934 +int gr_check_secure_terminal(struct task_struct *task)
52935 +{
52936 + struct task_struct *p, *p2, *p3;
52937 + struct files_struct *files;
52938 + struct fdtable *fdt;
52939 + struct file *our_file = NULL, *file;
52940 + int i;
52941 +
52942 + if (task->signal->tty == NULL)
52943 + return 1;
52944 +
52945 + files = get_files_struct(task);
52946 + if (files != NULL) {
52947 + rcu_read_lock();
52948 + fdt = files_fdtable(files);
52949 + for (i=0; i < fdt->max_fds; i++) {
52950 + file = fcheck_files(files, i);
52951 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
52952 + get_file(file);
52953 + our_file = file;
52954 + }
52955 + }
52956 + rcu_read_unlock();
52957 + put_files_struct(files);
52958 + }
52959 +
52960 + if (our_file == NULL)
52961 + return 1;
52962 +
52963 + read_lock(&tasklist_lock);
52964 + do_each_thread(p2, p) {
52965 + files = get_files_struct(p);
52966 + if (files == NULL ||
52967 + (p->signal && p->signal->tty == task->signal->tty)) {
52968 + if (files != NULL)
52969 + put_files_struct(files);
52970 + continue;
52971 + }
52972 + rcu_read_lock();
52973 + fdt = files_fdtable(files);
52974 + for (i=0; i < fdt->max_fds; i++) {
52975 + file = fcheck_files(files, i);
52976 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
52977 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
52978 + p3 = task;
52979 + while (p3->pid > 0) {
52980 + if (p3 == p)
52981 + break;
52982 + p3 = p3->real_parent;
52983 + }
52984 + if (p3 == p)
52985 + break;
52986 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
52987 + gr_handle_alertkill(p);
52988 + rcu_read_unlock();
52989 + put_files_struct(files);
52990 + read_unlock(&tasklist_lock);
52991 + fput(our_file);
52992 + return 0;
52993 + }
52994 + }
52995 + rcu_read_unlock();
52996 + put_files_struct(files);
52997 + } while_each_thread(p2, p);
52998 + read_unlock(&tasklist_lock);
52999 +
53000 + fput(our_file);
53001 + return 1;
53002 +}
53003 +
53004 +ssize_t
53005 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53006 +{
53007 + struct gr_arg_wrapper uwrap;
53008 + unsigned char *sprole_salt = NULL;
53009 + unsigned char *sprole_sum = NULL;
53010 + int error = sizeof (struct gr_arg_wrapper);
53011 + int error2 = 0;
53012 +
53013 + mutex_lock(&gr_dev_mutex);
53014 +
53015 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53016 + error = -EPERM;
53017 + goto out;
53018 + }
53019 +
53020 + if (count != sizeof (struct gr_arg_wrapper)) {
53021 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53022 + error = -EINVAL;
53023 + goto out;
53024 + }
53025 +
53026 +
53027 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53028 + gr_auth_expires = 0;
53029 + gr_auth_attempts = 0;
53030 + }
53031 +
53032 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53033 + error = -EFAULT;
53034 + goto out;
53035 + }
53036 +
53037 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53038 + error = -EINVAL;
53039 + goto out;
53040 + }
53041 +
53042 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53043 + error = -EFAULT;
53044 + goto out;
53045 + }
53046 +
53047 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53048 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53049 + time_after(gr_auth_expires, get_seconds())) {
53050 + error = -EBUSY;
53051 + goto out;
53052 + }
53053 +
53054 + /* if non-root trying to do anything other than use a special role,
53055 + do not attempt authentication, do not count towards authentication
53056 + locking
53057 + */
53058 +
53059 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53060 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53061 + current_uid()) {
53062 + error = -EPERM;
53063 + goto out;
53064 + }
53065 +
53066 + /* ensure pw and special role name are null terminated */
53067 +
53068 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53069 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53070 +
53071 + /* Okay.
53072 + * We have our enough of the argument structure..(we have yet
53073 + * to copy_from_user the tables themselves) . Copy the tables
53074 + * only if we need them, i.e. for loading operations. */
53075 +
53076 + switch (gr_usermode->mode) {
53077 + case GR_STATUS:
53078 + if (gr_status & GR_READY) {
53079 + error = 1;
53080 + if (!gr_check_secure_terminal(current))
53081 + error = 3;
53082 + } else
53083 + error = 2;
53084 + goto out;
53085 + case GR_SHUTDOWN:
53086 + if ((gr_status & GR_READY)
53087 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53088 + pax_open_kernel();
53089 + gr_status &= ~GR_READY;
53090 + pax_close_kernel();
53091 +
53092 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53093 + free_variables();
53094 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53095 + memset(gr_system_salt, 0, GR_SALT_LEN);
53096 + memset(gr_system_sum, 0, GR_SHA_LEN);
53097 + } else if (gr_status & GR_READY) {
53098 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53099 + error = -EPERM;
53100 + } else {
53101 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53102 + error = -EAGAIN;
53103 + }
53104 + break;
53105 + case GR_ENABLE:
53106 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53107 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53108 + else {
53109 + if (gr_status & GR_READY)
53110 + error = -EAGAIN;
53111 + else
53112 + error = error2;
53113 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53114 + }
53115 + break;
53116 + case GR_RELOAD:
53117 + if (!(gr_status & GR_READY)) {
53118 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53119 + error = -EAGAIN;
53120 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53121 + preempt_disable();
53122 +
53123 + pax_open_kernel();
53124 + gr_status &= ~GR_READY;
53125 + pax_close_kernel();
53126 +
53127 + free_variables();
53128 + if (!(error2 = gracl_init(gr_usermode))) {
53129 + preempt_enable();
53130 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53131 + } else {
53132 + preempt_enable();
53133 + error = error2;
53134 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53135 + }
53136 + } else {
53137 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53138 + error = -EPERM;
53139 + }
53140 + break;
53141 + case GR_SEGVMOD:
53142 + if (unlikely(!(gr_status & GR_READY))) {
53143 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53144 + error = -EAGAIN;
53145 + break;
53146 + }
53147 +
53148 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53149 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53150 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53151 + struct acl_subject_label *segvacl;
53152 + segvacl =
53153 + lookup_acl_subj_label(gr_usermode->segv_inode,
53154 + gr_usermode->segv_device,
53155 + current->role);
53156 + if (segvacl) {
53157 + segvacl->crashes = 0;
53158 + segvacl->expires = 0;
53159 + }
53160 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53161 + gr_remove_uid(gr_usermode->segv_uid);
53162 + }
53163 + } else {
53164 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53165 + error = -EPERM;
53166 + }
53167 + break;
53168 + case GR_SPROLE:
53169 + case GR_SPROLEPAM:
53170 + if (unlikely(!(gr_status & GR_READY))) {
53171 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53172 + error = -EAGAIN;
53173 + break;
53174 + }
53175 +
53176 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53177 + current->role->expires = 0;
53178 + current->role->auth_attempts = 0;
53179 + }
53180 +
53181 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53182 + time_after(current->role->expires, get_seconds())) {
53183 + error = -EBUSY;
53184 + goto out;
53185 + }
53186 +
53187 + if (lookup_special_role_auth
53188 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53189 + && ((!sprole_salt && !sprole_sum)
53190 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53191 + char *p = "";
53192 + assign_special_role(gr_usermode->sp_role);
53193 + read_lock(&tasklist_lock);
53194 + if (current->real_parent)
53195 + p = current->real_parent->role->rolename;
53196 + read_unlock(&tasklist_lock);
53197 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53198 + p, acl_sp_role_value);
53199 + } else {
53200 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53201 + error = -EPERM;
53202 + if(!(current->role->auth_attempts++))
53203 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53204 +
53205 + goto out;
53206 + }
53207 + break;
53208 + case GR_UNSPROLE:
53209 + if (unlikely(!(gr_status & GR_READY))) {
53210 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53211 + error = -EAGAIN;
53212 + break;
53213 + }
53214 +
53215 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53216 + char *p = "";
53217 + int i = 0;
53218 +
53219 + read_lock(&tasklist_lock);
53220 + if (current->real_parent) {
53221 + p = current->real_parent->role->rolename;
53222 + i = current->real_parent->acl_role_id;
53223 + }
53224 + read_unlock(&tasklist_lock);
53225 +
53226 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53227 + gr_set_acls(1);
53228 + } else {
53229 + error = -EPERM;
53230 + goto out;
53231 + }
53232 + break;
53233 + default:
53234 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53235 + error = -EINVAL;
53236 + break;
53237 + }
53238 +
53239 + if (error != -EPERM)
53240 + goto out;
53241 +
53242 + if(!(gr_auth_attempts++))
53243 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53244 +
53245 + out:
53246 + mutex_unlock(&gr_dev_mutex);
53247 + return error;
53248 +}
53249 +
53250 +/* must be called with
53251 + rcu_read_lock();
53252 + read_lock(&tasklist_lock);
53253 + read_lock(&grsec_exec_file_lock);
53254 +*/
53255 +int gr_apply_subject_to_task(struct task_struct *task)
53256 +{
53257 + struct acl_object_label *obj;
53258 + char *tmpname;
53259 + struct acl_subject_label *tmpsubj;
53260 + struct file *filp;
53261 + struct name_entry *nmatch;
53262 +
53263 + filp = task->exec_file;
53264 + if (filp == NULL)
53265 + return 0;
53266 +
53267 + /* the following is to apply the correct subject
53268 + on binaries running when the RBAC system
53269 + is enabled, when the binaries have been
53270 + replaced or deleted since their execution
53271 + -----
53272 + when the RBAC system starts, the inode/dev
53273 + from exec_file will be one the RBAC system
53274 + is unaware of. It only knows the inode/dev
53275 + of the present file on disk, or the absence
53276 + of it.
53277 + */
53278 + preempt_disable();
53279 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53280 +
53281 + nmatch = lookup_name_entry(tmpname);
53282 + preempt_enable();
53283 + tmpsubj = NULL;
53284 + if (nmatch) {
53285 + if (nmatch->deleted)
53286 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53287 + else
53288 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53289 + if (tmpsubj != NULL)
53290 + task->acl = tmpsubj;
53291 + }
53292 + if (tmpsubj == NULL)
53293 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53294 + task->role);
53295 + if (task->acl) {
53296 + task->is_writable = 0;
53297 + /* ignore additional mmap checks for processes that are writable
53298 + by the default ACL */
53299 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53300 + if (unlikely(obj->mode & GR_WRITE))
53301 + task->is_writable = 1;
53302 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53303 + if (unlikely(obj->mode & GR_WRITE))
53304 + task->is_writable = 1;
53305 +
53306 + gr_set_proc_res(task);
53307 +
53308 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53309 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53310 +#endif
53311 + } else {
53312 + return 1;
53313 + }
53314 +
53315 + return 0;
53316 +}
53317 +
53318 +int
53319 +gr_set_acls(const int type)
53320 +{
53321 + struct task_struct *task, *task2;
53322 + struct acl_role_label *role = current->role;
53323 + __u16 acl_role_id = current->acl_role_id;
53324 + const struct cred *cred;
53325 + int ret;
53326 +
53327 + rcu_read_lock();
53328 + read_lock(&tasklist_lock);
53329 + read_lock(&grsec_exec_file_lock);
53330 + do_each_thread(task2, task) {
53331 + /* check to see if we're called from the exit handler,
53332 + if so, only replace ACLs that have inherited the admin
53333 + ACL */
53334 +
53335 + if (type && (task->role != role ||
53336 + task->acl_role_id != acl_role_id))
53337 + continue;
53338 +
53339 + task->acl_role_id = 0;
53340 + task->acl_sp_role = 0;
53341 +
53342 + if (task->exec_file) {
53343 + cred = __task_cred(task);
53344 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53345 + ret = gr_apply_subject_to_task(task);
53346 + if (ret) {
53347 + read_unlock(&grsec_exec_file_lock);
53348 + read_unlock(&tasklist_lock);
53349 + rcu_read_unlock();
53350 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53351 + return ret;
53352 + }
53353 + } else {
53354 + // it's a kernel process
53355 + task->role = kernel_role;
53356 + task->acl = kernel_role->root_label;
53357 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53358 + task->acl->mode &= ~GR_PROCFIND;
53359 +#endif
53360 + }
53361 + } while_each_thread(task2, task);
53362 + read_unlock(&grsec_exec_file_lock);
53363 + read_unlock(&tasklist_lock);
53364 + rcu_read_unlock();
53365 +
53366 + return 0;
53367 +}
53368 +
53369 +void
53370 +gr_learn_resource(const struct task_struct *task,
53371 + const int res, const unsigned long wanted, const int gt)
53372 +{
53373 + struct acl_subject_label *acl;
53374 + const struct cred *cred;
53375 +
53376 + if (unlikely((gr_status & GR_READY) &&
53377 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53378 + goto skip_reslog;
53379 +
53380 +#ifdef CONFIG_GRKERNSEC_RESLOG
53381 + gr_log_resource(task, res, wanted, gt);
53382 +#endif
53383 + skip_reslog:
53384 +
53385 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53386 + return;
53387 +
53388 + acl = task->acl;
53389 +
53390 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53391 + !(acl->resmask & (1 << (unsigned short) res))))
53392 + return;
53393 +
53394 + if (wanted >= acl->res[res].rlim_cur) {
53395 + unsigned long res_add;
53396 +
53397 + res_add = wanted;
53398 + switch (res) {
53399 + case RLIMIT_CPU:
53400 + res_add += GR_RLIM_CPU_BUMP;
53401 + break;
53402 + case RLIMIT_FSIZE:
53403 + res_add += GR_RLIM_FSIZE_BUMP;
53404 + break;
53405 + case RLIMIT_DATA:
53406 + res_add += GR_RLIM_DATA_BUMP;
53407 + break;
53408 + case RLIMIT_STACK:
53409 + res_add += GR_RLIM_STACK_BUMP;
53410 + break;
53411 + case RLIMIT_CORE:
53412 + res_add += GR_RLIM_CORE_BUMP;
53413 + break;
53414 + case RLIMIT_RSS:
53415 + res_add += GR_RLIM_RSS_BUMP;
53416 + break;
53417 + case RLIMIT_NPROC:
53418 + res_add += GR_RLIM_NPROC_BUMP;
53419 + break;
53420 + case RLIMIT_NOFILE:
53421 + res_add += GR_RLIM_NOFILE_BUMP;
53422 + break;
53423 + case RLIMIT_MEMLOCK:
53424 + res_add += GR_RLIM_MEMLOCK_BUMP;
53425 + break;
53426 + case RLIMIT_AS:
53427 + res_add += GR_RLIM_AS_BUMP;
53428 + break;
53429 + case RLIMIT_LOCKS:
53430 + res_add += GR_RLIM_LOCKS_BUMP;
53431 + break;
53432 + case RLIMIT_SIGPENDING:
53433 + res_add += GR_RLIM_SIGPENDING_BUMP;
53434 + break;
53435 + case RLIMIT_MSGQUEUE:
53436 + res_add += GR_RLIM_MSGQUEUE_BUMP;
53437 + break;
53438 + case RLIMIT_NICE:
53439 + res_add += GR_RLIM_NICE_BUMP;
53440 + break;
53441 + case RLIMIT_RTPRIO:
53442 + res_add += GR_RLIM_RTPRIO_BUMP;
53443 + break;
53444 + case RLIMIT_RTTIME:
53445 + res_add += GR_RLIM_RTTIME_BUMP;
53446 + break;
53447 + }
53448 +
53449 + acl->res[res].rlim_cur = res_add;
53450 +
53451 + if (wanted > acl->res[res].rlim_max)
53452 + acl->res[res].rlim_max = res_add;
53453 +
53454 + /* only log the subject filename, since resource logging is supported for
53455 + single-subject learning only */
53456 + rcu_read_lock();
53457 + cred = __task_cred(task);
53458 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53459 + task->role->roletype, cred->uid, cred->gid, acl->filename,
53460 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53461 + "", (unsigned long) res, &task->signal->saved_ip);
53462 + rcu_read_unlock();
53463 + }
53464 +
53465 + return;
53466 +}
53467 +
53468 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53469 +void
53470 +pax_set_initial_flags(struct linux_binprm *bprm)
53471 +{
53472 + struct task_struct *task = current;
53473 + struct acl_subject_label *proc;
53474 + unsigned long flags;
53475 +
53476 + if (unlikely(!(gr_status & GR_READY)))
53477 + return;
53478 +
53479 + flags = pax_get_flags(task);
53480 +
53481 + proc = task->acl;
53482 +
53483 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53484 + flags &= ~MF_PAX_PAGEEXEC;
53485 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53486 + flags &= ~MF_PAX_SEGMEXEC;
53487 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53488 + flags &= ~MF_PAX_RANDMMAP;
53489 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53490 + flags &= ~MF_PAX_EMUTRAMP;
53491 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53492 + flags &= ~MF_PAX_MPROTECT;
53493 +
53494 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53495 + flags |= MF_PAX_PAGEEXEC;
53496 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53497 + flags |= MF_PAX_SEGMEXEC;
53498 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53499 + flags |= MF_PAX_RANDMMAP;
53500 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53501 + flags |= MF_PAX_EMUTRAMP;
53502 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53503 + flags |= MF_PAX_MPROTECT;
53504 +
53505 + pax_set_flags(task, flags);
53506 +
53507 + return;
53508 +}
53509 +#endif
53510 +
53511 +#ifdef CONFIG_SYSCTL
53512 +/* Eric Biederman likes breaking userland ABI and every inode-based security
53513 + system to save 35kb of memory */
53514 +
53515 +/* we modify the passed in filename, but adjust it back before returning */
53516 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
53517 +{
53518 + struct name_entry *nmatch;
53519 + char *p, *lastp = NULL;
53520 + struct acl_object_label *obj = NULL, *tmp;
53521 + struct acl_subject_label *tmpsubj;
53522 + char c = '\0';
53523 +
53524 + read_lock(&gr_inode_lock);
53525 +
53526 + p = name + len - 1;
53527 + do {
53528 + nmatch = lookup_name_entry(name);
53529 + if (lastp != NULL)
53530 + *lastp = c;
53531 +
53532 + if (nmatch == NULL)
53533 + goto next_component;
53534 + tmpsubj = current->acl;
53535 + do {
53536 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
53537 + if (obj != NULL) {
53538 + tmp = obj->globbed;
53539 + while (tmp) {
53540 + if (!glob_match(tmp->filename, name)) {
53541 + obj = tmp;
53542 + goto found_obj;
53543 + }
53544 + tmp = tmp->next;
53545 + }
53546 + goto found_obj;
53547 + }
53548 + } while ((tmpsubj = tmpsubj->parent_subject));
53549 +next_component:
53550 + /* end case */
53551 + if (p == name)
53552 + break;
53553 +
53554 + while (*p != '/')
53555 + p--;
53556 + if (p == name)
53557 + lastp = p + 1;
53558 + else {
53559 + lastp = p;
53560 + p--;
53561 + }
53562 + c = *lastp;
53563 + *lastp = '\0';
53564 + } while (1);
53565 +found_obj:
53566 + read_unlock(&gr_inode_lock);
53567 + /* obj returned will always be non-null */
53568 + return obj;
53569 +}
53570 +
53571 +/* returns 0 when allowing, non-zero on error
53572 + op of 0 is used for readdir, so we don't log the names of hidden files
53573 +*/
53574 +__u32
53575 +gr_handle_sysctl(const struct ctl_table *table, const int op)
53576 +{
53577 + struct ctl_table *tmp;
53578 + const char *proc_sys = "/proc/sys";
53579 + char *path;
53580 + struct acl_object_label *obj;
53581 + unsigned short len = 0, pos = 0, depth = 0, i;
53582 + __u32 err = 0;
53583 + __u32 mode = 0;
53584 +
53585 + if (unlikely(!(gr_status & GR_READY)))
53586 + return 0;
53587 +
53588 + /* for now, ignore operations on non-sysctl entries if it's not a
53589 + readdir*/
53590 + if (table->child != NULL && op != 0)
53591 + return 0;
53592 +
53593 + mode |= GR_FIND;
53594 + /* it's only a read if it's an entry, read on dirs is for readdir */
53595 + if (op & MAY_READ)
53596 + mode |= GR_READ;
53597 + if (op & MAY_WRITE)
53598 + mode |= GR_WRITE;
53599 +
53600 + preempt_disable();
53601 +
53602 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53603 +
53604 + /* it's only a read/write if it's an actual entry, not a dir
53605 + (which are opened for readdir)
53606 + */
53607 +
53608 + /* convert the requested sysctl entry into a pathname */
53609 +
53610 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53611 + len += strlen(tmp->procname);
53612 + len++;
53613 + depth++;
53614 + }
53615 +
53616 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
53617 + /* deny */
53618 + goto out;
53619 + }
53620 +
53621 + memset(path, 0, PAGE_SIZE);
53622 +
53623 + memcpy(path, proc_sys, strlen(proc_sys));
53624 +
53625 + pos += strlen(proc_sys);
53626 +
53627 + for (; depth > 0; depth--) {
53628 + path[pos] = '/';
53629 + pos++;
53630 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53631 + if (depth == i) {
53632 + memcpy(path + pos, tmp->procname,
53633 + strlen(tmp->procname));
53634 + pos += strlen(tmp->procname);
53635 + }
53636 + i++;
53637 + }
53638 + }
53639 +
53640 + obj = gr_lookup_by_name(path, pos);
53641 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
53642 +
53643 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
53644 + ((err & mode) != mode))) {
53645 + __u32 new_mode = mode;
53646 +
53647 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53648 +
53649 + err = 0;
53650 + gr_log_learn_sysctl(path, new_mode);
53651 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
53652 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
53653 + err = -ENOENT;
53654 + } else if (!(err & GR_FIND)) {
53655 + err = -ENOENT;
53656 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
53657 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
53658 + path, (mode & GR_READ) ? " reading" : "",
53659 + (mode & GR_WRITE) ? " writing" : "");
53660 + err = -EACCES;
53661 + } else if ((err & mode) != mode) {
53662 + err = -EACCES;
53663 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
53664 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
53665 + path, (mode & GR_READ) ? " reading" : "",
53666 + (mode & GR_WRITE) ? " writing" : "");
53667 + err = 0;
53668 + } else
53669 + err = 0;
53670 +
53671 + out:
53672 + preempt_enable();
53673 +
53674 + return err;
53675 +}
53676 +#endif
53677 +
53678 +int
53679 +gr_handle_proc_ptrace(struct task_struct *task)
53680 +{
53681 + struct file *filp;
53682 + struct task_struct *tmp = task;
53683 + struct task_struct *curtemp = current;
53684 + __u32 retmode;
53685 +
53686 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53687 + if (unlikely(!(gr_status & GR_READY)))
53688 + return 0;
53689 +#endif
53690 +
53691 + read_lock(&tasklist_lock);
53692 + read_lock(&grsec_exec_file_lock);
53693 + filp = task->exec_file;
53694 +
53695 + while (tmp->pid > 0) {
53696 + if (tmp == curtemp)
53697 + break;
53698 + tmp = tmp->real_parent;
53699 + }
53700 +
53701 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53702 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53703 + read_unlock(&grsec_exec_file_lock);
53704 + read_unlock(&tasklist_lock);
53705 + return 1;
53706 + }
53707 +
53708 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53709 + if (!(gr_status & GR_READY)) {
53710 + read_unlock(&grsec_exec_file_lock);
53711 + read_unlock(&tasklist_lock);
53712 + return 0;
53713 + }
53714 +#endif
53715 +
53716 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53717 + read_unlock(&grsec_exec_file_lock);
53718 + read_unlock(&tasklist_lock);
53719 +
53720 + if (retmode & GR_NOPTRACE)
53721 + return 1;
53722 +
53723 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53724 + && (current->acl != task->acl || (current->acl != current->role->root_label
53725 + && current->pid != task->pid)))
53726 + return 1;
53727 +
53728 + return 0;
53729 +}
53730 +
53731 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53732 +{
53733 + if (unlikely(!(gr_status & GR_READY)))
53734 + return;
53735 +
53736 + if (!(current->role->roletype & GR_ROLE_GOD))
53737 + return;
53738 +
53739 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53740 + p->role->rolename, gr_task_roletype_to_char(p),
53741 + p->acl->filename);
53742 +}
53743 +
53744 +int
53745 +gr_handle_ptrace(struct task_struct *task, const long request)
53746 +{
53747 + struct task_struct *tmp = task;
53748 + struct task_struct *curtemp = current;
53749 + __u32 retmode;
53750 +
53751 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53752 + if (unlikely(!(gr_status & GR_READY)))
53753 + return 0;
53754 +#endif
53755 +
53756 + read_lock(&tasklist_lock);
53757 + while (tmp->pid > 0) {
53758 + if (tmp == curtemp)
53759 + break;
53760 + tmp = tmp->real_parent;
53761 + }
53762 +
53763 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53764 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53765 + read_unlock(&tasklist_lock);
53766 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53767 + return 1;
53768 + }
53769 + read_unlock(&tasklist_lock);
53770 +
53771 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53772 + if (!(gr_status & GR_READY))
53773 + return 0;
53774 +#endif
53775 +
53776 + read_lock(&grsec_exec_file_lock);
53777 + if (unlikely(!task->exec_file)) {
53778 + read_unlock(&grsec_exec_file_lock);
53779 + return 0;
53780 + }
53781 +
53782 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53783 + read_unlock(&grsec_exec_file_lock);
53784 +
53785 + if (retmode & GR_NOPTRACE) {
53786 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53787 + return 1;
53788 + }
53789 +
53790 + if (retmode & GR_PTRACERD) {
53791 + switch (request) {
53792 + case PTRACE_SEIZE:
53793 + case PTRACE_POKETEXT:
53794 + case PTRACE_POKEDATA:
53795 + case PTRACE_POKEUSR:
53796 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53797 + case PTRACE_SETREGS:
53798 + case PTRACE_SETFPREGS:
53799 +#endif
53800 +#ifdef CONFIG_X86
53801 + case PTRACE_SETFPXREGS:
53802 +#endif
53803 +#ifdef CONFIG_ALTIVEC
53804 + case PTRACE_SETVRREGS:
53805 +#endif
53806 + return 1;
53807 + default:
53808 + return 0;
53809 + }
53810 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
53811 + !(current->role->roletype & GR_ROLE_GOD) &&
53812 + (current->acl != task->acl)) {
53813 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53814 + return 1;
53815 + }
53816 +
53817 + return 0;
53818 +}
53819 +
53820 +static int is_writable_mmap(const struct file *filp)
53821 +{
53822 + struct task_struct *task = current;
53823 + struct acl_object_label *obj, *obj2;
53824 +
53825 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53826 + !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))) {
53827 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53828 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53829 + task->role->root_label);
53830 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53831 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53832 + return 1;
53833 + }
53834 + }
53835 + return 0;
53836 +}
53837 +
53838 +int
53839 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53840 +{
53841 + __u32 mode;
53842 +
53843 + if (unlikely(!file || !(prot & PROT_EXEC)))
53844 + return 1;
53845 +
53846 + if (is_writable_mmap(file))
53847 + return 0;
53848 +
53849 + mode =
53850 + gr_search_file(file->f_path.dentry,
53851 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53852 + file->f_path.mnt);
53853 +
53854 + if (!gr_tpe_allow(file))
53855 + return 0;
53856 +
53857 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53858 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53859 + return 0;
53860 + } else if (unlikely(!(mode & GR_EXEC))) {
53861 + return 0;
53862 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53863 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53864 + return 1;
53865 + }
53866 +
53867 + return 1;
53868 +}
53869 +
53870 +int
53871 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53872 +{
53873 + __u32 mode;
53874 +
53875 + if (unlikely(!file || !(prot & PROT_EXEC)))
53876 + return 1;
53877 +
53878 + if (is_writable_mmap(file))
53879 + return 0;
53880 +
53881 + mode =
53882 + gr_search_file(file->f_path.dentry,
53883 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53884 + file->f_path.mnt);
53885 +
53886 + if (!gr_tpe_allow(file))
53887 + return 0;
53888 +
53889 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53890 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53891 + return 0;
53892 + } else if (unlikely(!(mode & GR_EXEC))) {
53893 + return 0;
53894 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53895 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53896 + return 1;
53897 + }
53898 +
53899 + return 1;
53900 +}
53901 +
53902 +void
53903 +gr_acl_handle_psacct(struct task_struct *task, const long code)
53904 +{
53905 + unsigned long runtime;
53906 + unsigned long cputime;
53907 + unsigned int wday, cday;
53908 + __u8 whr, chr;
53909 + __u8 wmin, cmin;
53910 + __u8 wsec, csec;
53911 + struct timespec timeval;
53912 +
53913 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
53914 + !(task->acl->mode & GR_PROCACCT)))
53915 + return;
53916 +
53917 + do_posix_clock_monotonic_gettime(&timeval);
53918 + runtime = timeval.tv_sec - task->start_time.tv_sec;
53919 + wday = runtime / (3600 * 24);
53920 + runtime -= wday * (3600 * 24);
53921 + whr = runtime / 3600;
53922 + runtime -= whr * 3600;
53923 + wmin = runtime / 60;
53924 + runtime -= wmin * 60;
53925 + wsec = runtime;
53926 +
53927 + cputime = (task->utime + task->stime) / HZ;
53928 + cday = cputime / (3600 * 24);
53929 + cputime -= cday * (3600 * 24);
53930 + chr = cputime / 3600;
53931 + cputime -= chr * 3600;
53932 + cmin = cputime / 60;
53933 + cputime -= cmin * 60;
53934 + csec = cputime;
53935 +
53936 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
53937 +
53938 + return;
53939 +}
53940 +
53941 +void gr_set_kernel_label(struct task_struct *task)
53942 +{
53943 + if (gr_status & GR_READY) {
53944 + task->role = kernel_role;
53945 + task->acl = kernel_role->root_label;
53946 + }
53947 + return;
53948 +}
53949 +
53950 +#ifdef CONFIG_TASKSTATS
53951 +int gr_is_taskstats_denied(int pid)
53952 +{
53953 + struct task_struct *task;
53954 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53955 + const struct cred *cred;
53956 +#endif
53957 + int ret = 0;
53958 +
53959 + /* restrict taskstats viewing to un-chrooted root users
53960 + who have the 'view' subject flag if the RBAC system is enabled
53961 + */
53962 +
53963 + rcu_read_lock();
53964 + read_lock(&tasklist_lock);
53965 + task = find_task_by_vpid(pid);
53966 + if (task) {
53967 +#ifdef CONFIG_GRKERNSEC_CHROOT
53968 + if (proc_is_chrooted(task))
53969 + ret = -EACCES;
53970 +#endif
53971 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53972 + cred = __task_cred(task);
53973 +#ifdef CONFIG_GRKERNSEC_PROC_USER
53974 + if (cred->uid != 0)
53975 + ret = -EACCES;
53976 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53977 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
53978 + ret = -EACCES;
53979 +#endif
53980 +#endif
53981 + if (gr_status & GR_READY) {
53982 + if (!(task->acl->mode & GR_VIEW))
53983 + ret = -EACCES;
53984 + }
53985 + } else
53986 + ret = -ENOENT;
53987 +
53988 + read_unlock(&tasklist_lock);
53989 + rcu_read_unlock();
53990 +
53991 + return ret;
53992 +}
53993 +#endif
53994 +
53995 +/* AUXV entries are filled via a descendant of search_binary_handler
53996 + after we've already applied the subject for the target
53997 +*/
53998 +int gr_acl_enable_at_secure(void)
53999 +{
54000 + if (unlikely(!(gr_status & GR_READY)))
54001 + return 0;
54002 +
54003 + if (current->acl->mode & GR_ATSECURE)
54004 + return 1;
54005 +
54006 + return 0;
54007 +}
54008 +
54009 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54010 +{
54011 + struct task_struct *task = current;
54012 + struct dentry *dentry = file->f_path.dentry;
54013 + struct vfsmount *mnt = file->f_path.mnt;
54014 + struct acl_object_label *obj, *tmp;
54015 + struct acl_subject_label *subj;
54016 + unsigned int bufsize;
54017 + int is_not_root;
54018 + char *path;
54019 + dev_t dev = __get_dev(dentry);
54020 +
54021 + if (unlikely(!(gr_status & GR_READY)))
54022 + return 1;
54023 +
54024 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54025 + return 1;
54026 +
54027 + /* ignore Eric Biederman */
54028 + if (IS_PRIVATE(dentry->d_inode))
54029 + return 1;
54030 +
54031 + subj = task->acl;
54032 + do {
54033 + obj = lookup_acl_obj_label(ino, dev, subj);
54034 + if (obj != NULL)
54035 + return (obj->mode & GR_FIND) ? 1 : 0;
54036 + } while ((subj = subj->parent_subject));
54037 +
54038 + /* this is purely an optimization since we're looking for an object
54039 + for the directory we're doing a readdir on
54040 + if it's possible for any globbed object to match the entry we're
54041 + filling into the directory, then the object we find here will be
54042 + an anchor point with attached globbed objects
54043 + */
54044 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54045 + if (obj->globbed == NULL)
54046 + return (obj->mode & GR_FIND) ? 1 : 0;
54047 +
54048 + is_not_root = ((obj->filename[0] == '/') &&
54049 + (obj->filename[1] == '\0')) ? 0 : 1;
54050 + bufsize = PAGE_SIZE - namelen - is_not_root;
54051 +
54052 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54053 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54054 + return 1;
54055 +
54056 + preempt_disable();
54057 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54058 + bufsize);
54059 +
54060 + bufsize = strlen(path);
54061 +
54062 + /* if base is "/", don't append an additional slash */
54063 + if (is_not_root)
54064 + *(path + bufsize) = '/';
54065 + memcpy(path + bufsize + is_not_root, name, namelen);
54066 + *(path + bufsize + namelen + is_not_root) = '\0';
54067 +
54068 + tmp = obj->globbed;
54069 + while (tmp) {
54070 + if (!glob_match(tmp->filename, path)) {
54071 + preempt_enable();
54072 + return (tmp->mode & GR_FIND) ? 1 : 0;
54073 + }
54074 + tmp = tmp->next;
54075 + }
54076 + preempt_enable();
54077 + return (obj->mode & GR_FIND) ? 1 : 0;
54078 +}
54079 +
54080 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54081 +EXPORT_SYMBOL(gr_acl_is_enabled);
54082 +#endif
54083 +EXPORT_SYMBOL(gr_learn_resource);
54084 +EXPORT_SYMBOL(gr_set_kernel_label);
54085 +#ifdef CONFIG_SECURITY
54086 +EXPORT_SYMBOL(gr_check_user_change);
54087 +EXPORT_SYMBOL(gr_check_group_change);
54088 +#endif
54089 +
54090 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54091 new file mode 100644
54092 index 0000000..34fefda
54093 --- /dev/null
54094 +++ b/grsecurity/gracl_alloc.c
54095 @@ -0,0 +1,105 @@
54096 +#include <linux/kernel.h>
54097 +#include <linux/mm.h>
54098 +#include <linux/slab.h>
54099 +#include <linux/vmalloc.h>
54100 +#include <linux/gracl.h>
54101 +#include <linux/grsecurity.h>
54102 +
54103 +static unsigned long alloc_stack_next = 1;
54104 +static unsigned long alloc_stack_size = 1;
54105 +static void **alloc_stack;
54106 +
54107 +static __inline__ int
54108 +alloc_pop(void)
54109 +{
54110 + if (alloc_stack_next == 1)
54111 + return 0;
54112 +
54113 + kfree(alloc_stack[alloc_stack_next - 2]);
54114 +
54115 + alloc_stack_next--;
54116 +
54117 + return 1;
54118 +}
54119 +
54120 +static __inline__ int
54121 +alloc_push(void *buf)
54122 +{
54123 + if (alloc_stack_next >= alloc_stack_size)
54124 + return 1;
54125 +
54126 + alloc_stack[alloc_stack_next - 1] = buf;
54127 +
54128 + alloc_stack_next++;
54129 +
54130 + return 0;
54131 +}
54132 +
54133 +void *
54134 +acl_alloc(unsigned long len)
54135 +{
54136 + void *ret = NULL;
54137 +
54138 + if (!len || len > PAGE_SIZE)
54139 + goto out;
54140 +
54141 + ret = kmalloc(len, GFP_KERNEL);
54142 +
54143 + if (ret) {
54144 + if (alloc_push(ret)) {
54145 + kfree(ret);
54146 + ret = NULL;
54147 + }
54148 + }
54149 +
54150 +out:
54151 + return ret;
54152 +}
54153 +
54154 +void *
54155 +acl_alloc_num(unsigned long num, unsigned long len)
54156 +{
54157 + if (!len || (num > (PAGE_SIZE / len)))
54158 + return NULL;
54159 +
54160 + return acl_alloc(num * len);
54161 +}
54162 +
54163 +void
54164 +acl_free_all(void)
54165 +{
54166 + if (gr_acl_is_enabled() || !alloc_stack)
54167 + return;
54168 +
54169 + while (alloc_pop()) ;
54170 +
54171 + if (alloc_stack) {
54172 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54173 + kfree(alloc_stack);
54174 + else
54175 + vfree(alloc_stack);
54176 + }
54177 +
54178 + alloc_stack = NULL;
54179 + alloc_stack_size = 1;
54180 + alloc_stack_next = 1;
54181 +
54182 + return;
54183 +}
54184 +
54185 +int
54186 +acl_alloc_stack_init(unsigned long size)
54187 +{
54188 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54189 + alloc_stack =
54190 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54191 + else
54192 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54193 +
54194 + alloc_stack_size = size;
54195 +
54196 + if (!alloc_stack)
54197 + return 0;
54198 + else
54199 + return 1;
54200 +}
54201 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54202 new file mode 100644
54203 index 0000000..955ddfb
54204 --- /dev/null
54205 +++ b/grsecurity/gracl_cap.c
54206 @@ -0,0 +1,101 @@
54207 +#include <linux/kernel.h>
54208 +#include <linux/module.h>
54209 +#include <linux/sched.h>
54210 +#include <linux/gracl.h>
54211 +#include <linux/grsecurity.h>
54212 +#include <linux/grinternal.h>
54213 +
54214 +extern const char *captab_log[];
54215 +extern int captab_log_entries;
54216 +
54217 +int
54218 +gr_acl_is_capable(const int cap)
54219 +{
54220 + struct task_struct *task = current;
54221 + const struct cred *cred = current_cred();
54222 + struct acl_subject_label *curracl;
54223 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54224 + kernel_cap_t cap_audit = __cap_empty_set;
54225 +
54226 + if (!gr_acl_is_enabled())
54227 + return 1;
54228 +
54229 + curracl = task->acl;
54230 +
54231 + cap_drop = curracl->cap_lower;
54232 + cap_mask = curracl->cap_mask;
54233 + cap_audit = curracl->cap_invert_audit;
54234 +
54235 + while ((curracl = curracl->parent_subject)) {
54236 + /* if the cap isn't specified in the current computed mask but is specified in the
54237 + current level subject, and is lowered in the current level subject, then add
54238 + it to the set of dropped capabilities
54239 + otherwise, add the current level subject's mask to the current computed mask
54240 + */
54241 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54242 + cap_raise(cap_mask, cap);
54243 + if (cap_raised(curracl->cap_lower, cap))
54244 + cap_raise(cap_drop, cap);
54245 + if (cap_raised(curracl->cap_invert_audit, cap))
54246 + cap_raise(cap_audit, cap);
54247 + }
54248 + }
54249 +
54250 + if (!cap_raised(cap_drop, cap)) {
54251 + if (cap_raised(cap_audit, cap))
54252 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54253 + return 1;
54254 + }
54255 +
54256 + curracl = task->acl;
54257 +
54258 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54259 + && cap_raised(cred->cap_effective, cap)) {
54260 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54261 + task->role->roletype, cred->uid,
54262 + cred->gid, task->exec_file ?
54263 + gr_to_filename(task->exec_file->f_path.dentry,
54264 + task->exec_file->f_path.mnt) : curracl->filename,
54265 + curracl->filename, 0UL,
54266 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54267 + return 1;
54268 + }
54269 +
54270 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54271 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54272 + return 0;
54273 +}
54274 +
54275 +int
54276 +gr_acl_is_capable_nolog(const int cap)
54277 +{
54278 + struct acl_subject_label *curracl;
54279 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54280 +
54281 + if (!gr_acl_is_enabled())
54282 + return 1;
54283 +
54284 + curracl = current->acl;
54285 +
54286 + cap_drop = curracl->cap_lower;
54287 + cap_mask = curracl->cap_mask;
54288 +
54289 + while ((curracl = curracl->parent_subject)) {
54290 + /* if the cap isn't specified in the current computed mask but is specified in the
54291 + current level subject, and is lowered in the current level subject, then add
54292 + it to the set of dropped capabilities
54293 + otherwise, add the current level subject's mask to the current computed mask
54294 + */
54295 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54296 + cap_raise(cap_mask, cap);
54297 + if (cap_raised(curracl->cap_lower, cap))
54298 + cap_raise(cap_drop, cap);
54299 + }
54300 + }
54301 +
54302 + if (!cap_raised(cap_drop, cap))
54303 + return 1;
54304 +
54305 + return 0;
54306 +}
54307 +
54308 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54309 new file mode 100644
54310 index 0000000..88d0e87
54311 --- /dev/null
54312 +++ b/grsecurity/gracl_fs.c
54313 @@ -0,0 +1,435 @@
54314 +#include <linux/kernel.h>
54315 +#include <linux/sched.h>
54316 +#include <linux/types.h>
54317 +#include <linux/fs.h>
54318 +#include <linux/file.h>
54319 +#include <linux/stat.h>
54320 +#include <linux/grsecurity.h>
54321 +#include <linux/grinternal.h>
54322 +#include <linux/gracl.h>
54323 +
54324 +umode_t
54325 +gr_acl_umask(void)
54326 +{
54327 + if (unlikely(!gr_acl_is_enabled()))
54328 + return 0;
54329 +
54330 + return current->role->umask;
54331 +}
54332 +
54333 +__u32
54334 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54335 + const struct vfsmount * mnt)
54336 +{
54337 + __u32 mode;
54338 +
54339 + if (unlikely(!dentry->d_inode))
54340 + return GR_FIND;
54341 +
54342 + mode =
54343 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54344 +
54345 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54346 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54347 + return mode;
54348 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54349 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54350 + return 0;
54351 + } else if (unlikely(!(mode & GR_FIND)))
54352 + return 0;
54353 +
54354 + return GR_FIND;
54355 +}
54356 +
54357 +__u32
54358 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54359 + int acc_mode)
54360 +{
54361 + __u32 reqmode = GR_FIND;
54362 + __u32 mode;
54363 +
54364 + if (unlikely(!dentry->d_inode))
54365 + return reqmode;
54366 +
54367 + if (acc_mode & MAY_APPEND)
54368 + reqmode |= GR_APPEND;
54369 + else if (acc_mode & MAY_WRITE)
54370 + reqmode |= GR_WRITE;
54371 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54372 + reqmode |= GR_READ;
54373 +
54374 + mode =
54375 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54376 + mnt);
54377 +
54378 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54379 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54380 + reqmode & GR_READ ? " reading" : "",
54381 + reqmode & GR_WRITE ? " writing" : reqmode &
54382 + GR_APPEND ? " appending" : "");
54383 + return reqmode;
54384 + } else
54385 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54386 + {
54387 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54388 + reqmode & GR_READ ? " reading" : "",
54389 + reqmode & GR_WRITE ? " writing" : reqmode &
54390 + GR_APPEND ? " appending" : "");
54391 + return 0;
54392 + } else if (unlikely((mode & reqmode) != reqmode))
54393 + return 0;
54394 +
54395 + return reqmode;
54396 +}
54397 +
54398 +__u32
54399 +gr_acl_handle_creat(const struct dentry * dentry,
54400 + const struct dentry * p_dentry,
54401 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54402 + const int imode)
54403 +{
54404 + __u32 reqmode = GR_WRITE | GR_CREATE;
54405 + __u32 mode;
54406 +
54407 + if (acc_mode & MAY_APPEND)
54408 + reqmode |= GR_APPEND;
54409 + // if a directory was required or the directory already exists, then
54410 + // don't count this open as a read
54411 + if ((acc_mode & MAY_READ) &&
54412 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54413 + reqmode |= GR_READ;
54414 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54415 + reqmode |= GR_SETID;
54416 +
54417 + mode =
54418 + gr_check_create(dentry, p_dentry, p_mnt,
54419 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54420 +
54421 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54422 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54423 + reqmode & GR_READ ? " reading" : "",
54424 + reqmode & GR_WRITE ? " writing" : reqmode &
54425 + GR_APPEND ? " appending" : "");
54426 + return reqmode;
54427 + } else
54428 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54429 + {
54430 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54431 + reqmode & GR_READ ? " reading" : "",
54432 + reqmode & GR_WRITE ? " writing" : reqmode &
54433 + GR_APPEND ? " appending" : "");
54434 + return 0;
54435 + } else if (unlikely((mode & reqmode) != reqmode))
54436 + return 0;
54437 +
54438 + return reqmode;
54439 +}
54440 +
54441 +__u32
54442 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54443 + const int fmode)
54444 +{
54445 + __u32 mode, reqmode = GR_FIND;
54446 +
54447 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54448 + reqmode |= GR_EXEC;
54449 + if (fmode & S_IWOTH)
54450 + reqmode |= GR_WRITE;
54451 + if (fmode & S_IROTH)
54452 + reqmode |= GR_READ;
54453 +
54454 + mode =
54455 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54456 + mnt);
54457 +
54458 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54459 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54460 + reqmode & GR_READ ? " reading" : "",
54461 + reqmode & GR_WRITE ? " writing" : "",
54462 + reqmode & GR_EXEC ? " executing" : "");
54463 + return reqmode;
54464 + } else
54465 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54466 + {
54467 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54468 + reqmode & GR_READ ? " reading" : "",
54469 + reqmode & GR_WRITE ? " writing" : "",
54470 + reqmode & GR_EXEC ? " executing" : "");
54471 + return 0;
54472 + } else if (unlikely((mode & reqmode) != reqmode))
54473 + return 0;
54474 +
54475 + return reqmode;
54476 +}
54477 +
54478 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54479 +{
54480 + __u32 mode;
54481 +
54482 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54483 +
54484 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54485 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54486 + return mode;
54487 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54488 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54489 + return 0;
54490 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54491 + return 0;
54492 +
54493 + return (reqmode);
54494 +}
54495 +
54496 +__u32
54497 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54498 +{
54499 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54500 +}
54501 +
54502 +__u32
54503 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54504 +{
54505 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54506 +}
54507 +
54508 +__u32
54509 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54510 +{
54511 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54512 +}
54513 +
54514 +__u32
54515 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54516 +{
54517 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54518 +}
54519 +
54520 +__u32
54521 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54522 + umode_t *modeptr)
54523 +{
54524 + umode_t mode;
54525 +
54526 + *modeptr &= ~gr_acl_umask();
54527 + mode = *modeptr;
54528 +
54529 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54530 + return 1;
54531 +
54532 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
54533 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54534 + GR_CHMOD_ACL_MSG);
54535 + } else {
54536 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54537 + }
54538 +}
54539 +
54540 +__u32
54541 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54542 +{
54543 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54544 +}
54545 +
54546 +__u32
54547 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54548 +{
54549 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54550 +}
54551 +
54552 +__u32
54553 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54554 +{
54555 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54556 +}
54557 +
54558 +__u32
54559 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54560 +{
54561 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54562 + GR_UNIXCONNECT_ACL_MSG);
54563 +}
54564 +
54565 +/* hardlinks require at minimum create and link permission,
54566 + any additional privilege required is based on the
54567 + privilege of the file being linked to
54568 +*/
54569 +__u32
54570 +gr_acl_handle_link(const struct dentry * new_dentry,
54571 + const struct dentry * parent_dentry,
54572 + const struct vfsmount * parent_mnt,
54573 + const struct dentry * old_dentry,
54574 + const struct vfsmount * old_mnt, const char *to)
54575 +{
54576 + __u32 mode;
54577 + __u32 needmode = GR_CREATE | GR_LINK;
54578 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54579 +
54580 + mode =
54581 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54582 + old_mnt);
54583 +
54584 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54585 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54586 + return mode;
54587 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54588 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54589 + return 0;
54590 + } else if (unlikely((mode & needmode) != needmode))
54591 + return 0;
54592 +
54593 + return 1;
54594 +}
54595 +
54596 +__u32
54597 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54598 + const struct dentry * parent_dentry,
54599 + const struct vfsmount * parent_mnt, const char *from)
54600 +{
54601 + __u32 needmode = GR_WRITE | GR_CREATE;
54602 + __u32 mode;
54603 +
54604 + mode =
54605 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
54606 + GR_CREATE | GR_AUDIT_CREATE |
54607 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54608 +
54609 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54610 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54611 + return mode;
54612 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54613 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54614 + return 0;
54615 + } else if (unlikely((mode & needmode) != needmode))
54616 + return 0;
54617 +
54618 + return (GR_WRITE | GR_CREATE);
54619 +}
54620 +
54621 +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)
54622 +{
54623 + __u32 mode;
54624 +
54625 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54626 +
54627 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54628 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54629 + return mode;
54630 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54631 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54632 + return 0;
54633 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54634 + return 0;
54635 +
54636 + return (reqmode);
54637 +}
54638 +
54639 +__u32
54640 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54641 + const struct dentry * parent_dentry,
54642 + const struct vfsmount * parent_mnt,
54643 + const int mode)
54644 +{
54645 + __u32 reqmode = GR_WRITE | GR_CREATE;
54646 + if (unlikely(mode & (S_ISUID | S_ISGID)))
54647 + reqmode |= GR_SETID;
54648 +
54649 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54650 + reqmode, GR_MKNOD_ACL_MSG);
54651 +}
54652 +
54653 +__u32
54654 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
54655 + const struct dentry *parent_dentry,
54656 + const struct vfsmount *parent_mnt)
54657 +{
54658 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54659 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54660 +}
54661 +
54662 +#define RENAME_CHECK_SUCCESS(old, new) \
54663 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54664 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54665 +
54666 +int
54667 +gr_acl_handle_rename(struct dentry *new_dentry,
54668 + struct dentry *parent_dentry,
54669 + const struct vfsmount *parent_mnt,
54670 + struct dentry *old_dentry,
54671 + struct inode *old_parent_inode,
54672 + struct vfsmount *old_mnt, const char *newname)
54673 +{
54674 + __u32 comp1, comp2;
54675 + int error = 0;
54676 +
54677 + if (unlikely(!gr_acl_is_enabled()))
54678 + return 0;
54679 +
54680 + if (!new_dentry->d_inode) {
54681 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54682 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54683 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54684 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54685 + GR_DELETE | GR_AUDIT_DELETE |
54686 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54687 + GR_SUPPRESS, old_mnt);
54688 + } else {
54689 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54690 + GR_CREATE | GR_DELETE |
54691 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54692 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54693 + GR_SUPPRESS, parent_mnt);
54694 + comp2 =
54695 + gr_search_file(old_dentry,
54696 + GR_READ | GR_WRITE | GR_AUDIT_READ |
54697 + GR_DELETE | GR_AUDIT_DELETE |
54698 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54699 + }
54700 +
54701 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54702 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54703 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54704 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54705 + && !(comp2 & GR_SUPPRESS)) {
54706 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54707 + error = -EACCES;
54708 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54709 + error = -EACCES;
54710 +
54711 + return error;
54712 +}
54713 +
54714 +void
54715 +gr_acl_handle_exit(void)
54716 +{
54717 + u16 id;
54718 + char *rolename;
54719 + struct file *exec_file;
54720 +
54721 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54722 + !(current->role->roletype & GR_ROLE_PERSIST))) {
54723 + id = current->acl_role_id;
54724 + rolename = current->role->rolename;
54725 + gr_set_acls(1);
54726 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54727 + }
54728 +
54729 + write_lock(&grsec_exec_file_lock);
54730 + exec_file = current->exec_file;
54731 + current->exec_file = NULL;
54732 + write_unlock(&grsec_exec_file_lock);
54733 +
54734 + if (exec_file)
54735 + fput(exec_file);
54736 +}
54737 +
54738 +int
54739 +gr_acl_handle_procpidmem(const struct task_struct *task)
54740 +{
54741 + if (unlikely(!gr_acl_is_enabled()))
54742 + return 0;
54743 +
54744 + if (task != current && task->acl->mode & GR_PROTPROCFD)
54745 + return -EACCES;
54746 +
54747 + return 0;
54748 +}
54749 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54750 new file mode 100644
54751 index 0000000..17050ca
54752 --- /dev/null
54753 +++ b/grsecurity/gracl_ip.c
54754 @@ -0,0 +1,381 @@
54755 +#include <linux/kernel.h>
54756 +#include <asm/uaccess.h>
54757 +#include <asm/errno.h>
54758 +#include <net/sock.h>
54759 +#include <linux/file.h>
54760 +#include <linux/fs.h>
54761 +#include <linux/net.h>
54762 +#include <linux/in.h>
54763 +#include <linux/skbuff.h>
54764 +#include <linux/ip.h>
54765 +#include <linux/udp.h>
54766 +#include <linux/types.h>
54767 +#include <linux/sched.h>
54768 +#include <linux/netdevice.h>
54769 +#include <linux/inetdevice.h>
54770 +#include <linux/gracl.h>
54771 +#include <linux/grsecurity.h>
54772 +#include <linux/grinternal.h>
54773 +
54774 +#define GR_BIND 0x01
54775 +#define GR_CONNECT 0x02
54776 +#define GR_INVERT 0x04
54777 +#define GR_BINDOVERRIDE 0x08
54778 +#define GR_CONNECTOVERRIDE 0x10
54779 +#define GR_SOCK_FAMILY 0x20
54780 +
54781 +static const char * gr_protocols[IPPROTO_MAX] = {
54782 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54783 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54784 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54785 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54786 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54787 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54788 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54789 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54790 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54791 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54792 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54793 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54794 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54795 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54796 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54797 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54798 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54799 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54800 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54801 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54802 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54803 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54804 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54805 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54806 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54807 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54808 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54809 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54810 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54811 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54812 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54813 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54814 + };
54815 +
54816 +static const char * gr_socktypes[SOCK_MAX] = {
54817 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54818 + "unknown:7", "unknown:8", "unknown:9", "packet"
54819 + };
54820 +
54821 +static const char * gr_sockfamilies[AF_MAX+1] = {
54822 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54823 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54824 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54825 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54826 + };
54827 +
54828 +const char *
54829 +gr_proto_to_name(unsigned char proto)
54830 +{
54831 + return gr_protocols[proto];
54832 +}
54833 +
54834 +const char *
54835 +gr_socktype_to_name(unsigned char type)
54836 +{
54837 + return gr_socktypes[type];
54838 +}
54839 +
54840 +const char *
54841 +gr_sockfamily_to_name(unsigned char family)
54842 +{
54843 + return gr_sockfamilies[family];
54844 +}
54845 +
54846 +int
54847 +gr_search_socket(const int domain, const int type, const int protocol)
54848 +{
54849 + struct acl_subject_label *curr;
54850 + const struct cred *cred = current_cred();
54851 +
54852 + if (unlikely(!gr_acl_is_enabled()))
54853 + goto exit;
54854 +
54855 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
54856 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
54857 + goto exit; // let the kernel handle it
54858 +
54859 + curr = current->acl;
54860 +
54861 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
54862 + /* the family is allowed, if this is PF_INET allow it only if
54863 + the extra sock type/protocol checks pass */
54864 + if (domain == PF_INET)
54865 + goto inet_check;
54866 + goto exit;
54867 + } else {
54868 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54869 + __u32 fakeip = 0;
54870 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54871 + current->role->roletype, cred->uid,
54872 + cred->gid, current->exec_file ?
54873 + gr_to_filename(current->exec_file->f_path.dentry,
54874 + current->exec_file->f_path.mnt) :
54875 + curr->filename, curr->filename,
54876 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
54877 + &current->signal->saved_ip);
54878 + goto exit;
54879 + }
54880 + goto exit_fail;
54881 + }
54882 +
54883 +inet_check:
54884 + /* the rest of this checking is for IPv4 only */
54885 + if (!curr->ips)
54886 + goto exit;
54887 +
54888 + if ((curr->ip_type & (1 << type)) &&
54889 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
54890 + goto exit;
54891 +
54892 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54893 + /* we don't place acls on raw sockets , and sometimes
54894 + dgram/ip sockets are opened for ioctl and not
54895 + bind/connect, so we'll fake a bind learn log */
54896 + if (type == SOCK_RAW || type == SOCK_PACKET) {
54897 + __u32 fakeip = 0;
54898 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54899 + current->role->roletype, cred->uid,
54900 + cred->gid, current->exec_file ?
54901 + gr_to_filename(current->exec_file->f_path.dentry,
54902 + current->exec_file->f_path.mnt) :
54903 + curr->filename, curr->filename,
54904 + &fakeip, 0, type,
54905 + protocol, GR_CONNECT, &current->signal->saved_ip);
54906 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
54907 + __u32 fakeip = 0;
54908 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54909 + current->role->roletype, cred->uid,
54910 + cred->gid, current->exec_file ?
54911 + gr_to_filename(current->exec_file->f_path.dentry,
54912 + current->exec_file->f_path.mnt) :
54913 + curr->filename, curr->filename,
54914 + &fakeip, 0, type,
54915 + protocol, GR_BIND, &current->signal->saved_ip);
54916 + }
54917 + /* we'll log when they use connect or bind */
54918 + goto exit;
54919 + }
54920 +
54921 +exit_fail:
54922 + if (domain == PF_INET)
54923 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
54924 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
54925 + else
54926 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
54927 + gr_socktype_to_name(type), protocol);
54928 +
54929 + return 0;
54930 +exit:
54931 + return 1;
54932 +}
54933 +
54934 +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)
54935 +{
54936 + if ((ip->mode & mode) &&
54937 + (ip_port >= ip->low) &&
54938 + (ip_port <= ip->high) &&
54939 + ((ntohl(ip_addr) & our_netmask) ==
54940 + (ntohl(our_addr) & our_netmask))
54941 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
54942 + && (ip->type & (1 << type))) {
54943 + if (ip->mode & GR_INVERT)
54944 + return 2; // specifically denied
54945 + else
54946 + return 1; // allowed
54947 + }
54948 +
54949 + return 0; // not specifically allowed, may continue parsing
54950 +}
54951 +
54952 +static int
54953 +gr_search_connectbind(const int full_mode, struct sock *sk,
54954 + struct sockaddr_in *addr, const int type)
54955 +{
54956 + char iface[IFNAMSIZ] = {0};
54957 + struct acl_subject_label *curr;
54958 + struct acl_ip_label *ip;
54959 + struct inet_sock *isk;
54960 + struct net_device *dev;
54961 + struct in_device *idev;
54962 + unsigned long i;
54963 + int ret;
54964 + int mode = full_mode & (GR_BIND | GR_CONNECT);
54965 + __u32 ip_addr = 0;
54966 + __u32 our_addr;
54967 + __u32 our_netmask;
54968 + char *p;
54969 + __u16 ip_port = 0;
54970 + const struct cred *cred = current_cred();
54971 +
54972 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
54973 + return 0;
54974 +
54975 + curr = current->acl;
54976 + isk = inet_sk(sk);
54977 +
54978 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
54979 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
54980 + addr->sin_addr.s_addr = curr->inaddr_any_override;
54981 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
54982 + struct sockaddr_in saddr;
54983 + int err;
54984 +
54985 + saddr.sin_family = AF_INET;
54986 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
54987 + saddr.sin_port = isk->inet_sport;
54988 +
54989 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54990 + if (err)
54991 + return err;
54992 +
54993 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54994 + if (err)
54995 + return err;
54996 + }
54997 +
54998 + if (!curr->ips)
54999 + return 0;
55000 +
55001 + ip_addr = addr->sin_addr.s_addr;
55002 + ip_port = ntohs(addr->sin_port);
55003 +
55004 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55005 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55006 + current->role->roletype, cred->uid,
55007 + cred->gid, current->exec_file ?
55008 + gr_to_filename(current->exec_file->f_path.dentry,
55009 + current->exec_file->f_path.mnt) :
55010 + curr->filename, curr->filename,
55011 + &ip_addr, ip_port, type,
55012 + sk->sk_protocol, mode, &current->signal->saved_ip);
55013 + return 0;
55014 + }
55015 +
55016 + for (i = 0; i < curr->ip_num; i++) {
55017 + ip = *(curr->ips + i);
55018 + if (ip->iface != NULL) {
55019 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55020 + p = strchr(iface, ':');
55021 + if (p != NULL)
55022 + *p = '\0';
55023 + dev = dev_get_by_name(sock_net(sk), iface);
55024 + if (dev == NULL)
55025 + continue;
55026 + idev = in_dev_get(dev);
55027 + if (idev == NULL) {
55028 + dev_put(dev);
55029 + continue;
55030 + }
55031 + rcu_read_lock();
55032 + for_ifa(idev) {
55033 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55034 + our_addr = ifa->ifa_address;
55035 + our_netmask = 0xffffffff;
55036 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55037 + if (ret == 1) {
55038 + rcu_read_unlock();
55039 + in_dev_put(idev);
55040 + dev_put(dev);
55041 + return 0;
55042 + } else if (ret == 2) {
55043 + rcu_read_unlock();
55044 + in_dev_put(idev);
55045 + dev_put(dev);
55046 + goto denied;
55047 + }
55048 + }
55049 + } endfor_ifa(idev);
55050 + rcu_read_unlock();
55051 + in_dev_put(idev);
55052 + dev_put(dev);
55053 + } else {
55054 + our_addr = ip->addr;
55055 + our_netmask = ip->netmask;
55056 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55057 + if (ret == 1)
55058 + return 0;
55059 + else if (ret == 2)
55060 + goto denied;
55061 + }
55062 + }
55063 +
55064 +denied:
55065 + if (mode == GR_BIND)
55066 + 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));
55067 + else if (mode == GR_CONNECT)
55068 + 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));
55069 +
55070 + return -EACCES;
55071 +}
55072 +
55073 +int
55074 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55075 +{
55076 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55077 +}
55078 +
55079 +int
55080 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55081 +{
55082 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55083 +}
55084 +
55085 +int gr_search_listen(struct socket *sock)
55086 +{
55087 + struct sock *sk = sock->sk;
55088 + struct sockaddr_in addr;
55089 +
55090 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55091 + addr.sin_port = inet_sk(sk)->inet_sport;
55092 +
55093 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55094 +}
55095 +
55096 +int gr_search_accept(struct socket *sock)
55097 +{
55098 + struct sock *sk = sock->sk;
55099 + struct sockaddr_in addr;
55100 +
55101 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55102 + addr.sin_port = inet_sk(sk)->inet_sport;
55103 +
55104 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55105 +}
55106 +
55107 +int
55108 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55109 +{
55110 + if (addr)
55111 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55112 + else {
55113 + struct sockaddr_in sin;
55114 + const struct inet_sock *inet = inet_sk(sk);
55115 +
55116 + sin.sin_addr.s_addr = inet->inet_daddr;
55117 + sin.sin_port = inet->inet_dport;
55118 +
55119 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55120 + }
55121 +}
55122 +
55123 +int
55124 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55125 +{
55126 + struct sockaddr_in sin;
55127 +
55128 + if (unlikely(skb->len < sizeof (struct udphdr)))
55129 + return 0; // skip this packet
55130 +
55131 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55132 + sin.sin_port = udp_hdr(skb)->source;
55133 +
55134 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55135 +}
55136 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55137 new file mode 100644
55138 index 0000000..25f54ef
55139 --- /dev/null
55140 +++ b/grsecurity/gracl_learn.c
55141 @@ -0,0 +1,207 @@
55142 +#include <linux/kernel.h>
55143 +#include <linux/mm.h>
55144 +#include <linux/sched.h>
55145 +#include <linux/poll.h>
55146 +#include <linux/string.h>
55147 +#include <linux/file.h>
55148 +#include <linux/types.h>
55149 +#include <linux/vmalloc.h>
55150 +#include <linux/grinternal.h>
55151 +
55152 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55153 + size_t count, loff_t *ppos);
55154 +extern int gr_acl_is_enabled(void);
55155 +
55156 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55157 +static int gr_learn_attached;
55158 +
55159 +/* use a 512k buffer */
55160 +#define LEARN_BUFFER_SIZE (512 * 1024)
55161 +
55162 +static DEFINE_SPINLOCK(gr_learn_lock);
55163 +static DEFINE_MUTEX(gr_learn_user_mutex);
55164 +
55165 +/* we need to maintain two buffers, so that the kernel context of grlearn
55166 + uses a semaphore around the userspace copying, and the other kernel contexts
55167 + use a spinlock when copying into the buffer, since they cannot sleep
55168 +*/
55169 +static char *learn_buffer;
55170 +static char *learn_buffer_user;
55171 +static int learn_buffer_len;
55172 +static int learn_buffer_user_len;
55173 +
55174 +static ssize_t
55175 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55176 +{
55177 + DECLARE_WAITQUEUE(wait, current);
55178 + ssize_t retval = 0;
55179 +
55180 + add_wait_queue(&learn_wait, &wait);
55181 + set_current_state(TASK_INTERRUPTIBLE);
55182 + do {
55183 + mutex_lock(&gr_learn_user_mutex);
55184 + spin_lock(&gr_learn_lock);
55185 + if (learn_buffer_len)
55186 + break;
55187 + spin_unlock(&gr_learn_lock);
55188 + mutex_unlock(&gr_learn_user_mutex);
55189 + if (file->f_flags & O_NONBLOCK) {
55190 + retval = -EAGAIN;
55191 + goto out;
55192 + }
55193 + if (signal_pending(current)) {
55194 + retval = -ERESTARTSYS;
55195 + goto out;
55196 + }
55197 +
55198 + schedule();
55199 + } while (1);
55200 +
55201 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55202 + learn_buffer_user_len = learn_buffer_len;
55203 + retval = learn_buffer_len;
55204 + learn_buffer_len = 0;
55205 +
55206 + spin_unlock(&gr_learn_lock);
55207 +
55208 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55209 + retval = -EFAULT;
55210 +
55211 + mutex_unlock(&gr_learn_user_mutex);
55212 +out:
55213 + set_current_state(TASK_RUNNING);
55214 + remove_wait_queue(&learn_wait, &wait);
55215 + return retval;
55216 +}
55217 +
55218 +static unsigned int
55219 +poll_learn(struct file * file, poll_table * wait)
55220 +{
55221 + poll_wait(file, &learn_wait, wait);
55222 +
55223 + if (learn_buffer_len)
55224 + return (POLLIN | POLLRDNORM);
55225 +
55226 + return 0;
55227 +}
55228 +
55229 +void
55230 +gr_clear_learn_entries(void)
55231 +{
55232 + char *tmp;
55233 +
55234 + mutex_lock(&gr_learn_user_mutex);
55235 + spin_lock(&gr_learn_lock);
55236 + tmp = learn_buffer;
55237 + learn_buffer = NULL;
55238 + spin_unlock(&gr_learn_lock);
55239 + if (tmp)
55240 + vfree(tmp);
55241 + if (learn_buffer_user != NULL) {
55242 + vfree(learn_buffer_user);
55243 + learn_buffer_user = NULL;
55244 + }
55245 + learn_buffer_len = 0;
55246 + mutex_unlock(&gr_learn_user_mutex);
55247 +
55248 + return;
55249 +}
55250 +
55251 +void
55252 +gr_add_learn_entry(const char *fmt, ...)
55253 +{
55254 + va_list args;
55255 + unsigned int len;
55256 +
55257 + if (!gr_learn_attached)
55258 + return;
55259 +
55260 + spin_lock(&gr_learn_lock);
55261 +
55262 + /* leave a gap at the end so we know when it's "full" but don't have to
55263 + compute the exact length of the string we're trying to append
55264 + */
55265 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55266 + spin_unlock(&gr_learn_lock);
55267 + wake_up_interruptible(&learn_wait);
55268 + return;
55269 + }
55270 + if (learn_buffer == NULL) {
55271 + spin_unlock(&gr_learn_lock);
55272 + return;
55273 + }
55274 +
55275 + va_start(args, fmt);
55276 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55277 + va_end(args);
55278 +
55279 + learn_buffer_len += len + 1;
55280 +
55281 + spin_unlock(&gr_learn_lock);
55282 + wake_up_interruptible(&learn_wait);
55283 +
55284 + return;
55285 +}
55286 +
55287 +static int
55288 +open_learn(struct inode *inode, struct file *file)
55289 +{
55290 + if (file->f_mode & FMODE_READ && gr_learn_attached)
55291 + return -EBUSY;
55292 + if (file->f_mode & FMODE_READ) {
55293 + int retval = 0;
55294 + mutex_lock(&gr_learn_user_mutex);
55295 + if (learn_buffer == NULL)
55296 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55297 + if (learn_buffer_user == NULL)
55298 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55299 + if (learn_buffer == NULL) {
55300 + retval = -ENOMEM;
55301 + goto out_error;
55302 + }
55303 + if (learn_buffer_user == NULL) {
55304 + retval = -ENOMEM;
55305 + goto out_error;
55306 + }
55307 + learn_buffer_len = 0;
55308 + learn_buffer_user_len = 0;
55309 + gr_learn_attached = 1;
55310 +out_error:
55311 + mutex_unlock(&gr_learn_user_mutex);
55312 + return retval;
55313 + }
55314 + return 0;
55315 +}
55316 +
55317 +static int
55318 +close_learn(struct inode *inode, struct file *file)
55319 +{
55320 + if (file->f_mode & FMODE_READ) {
55321 + char *tmp = NULL;
55322 + mutex_lock(&gr_learn_user_mutex);
55323 + spin_lock(&gr_learn_lock);
55324 + tmp = learn_buffer;
55325 + learn_buffer = NULL;
55326 + spin_unlock(&gr_learn_lock);
55327 + if (tmp)
55328 + vfree(tmp);
55329 + if (learn_buffer_user != NULL) {
55330 + vfree(learn_buffer_user);
55331 + learn_buffer_user = NULL;
55332 + }
55333 + learn_buffer_len = 0;
55334 + learn_buffer_user_len = 0;
55335 + gr_learn_attached = 0;
55336 + mutex_unlock(&gr_learn_user_mutex);
55337 + }
55338 +
55339 + return 0;
55340 +}
55341 +
55342 +const struct file_operations grsec_fops = {
55343 + .read = read_learn,
55344 + .write = write_grsec_handler,
55345 + .open = open_learn,
55346 + .release = close_learn,
55347 + .poll = poll_learn,
55348 +};
55349 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55350 new file mode 100644
55351 index 0000000..39645c9
55352 --- /dev/null
55353 +++ b/grsecurity/gracl_res.c
55354 @@ -0,0 +1,68 @@
55355 +#include <linux/kernel.h>
55356 +#include <linux/sched.h>
55357 +#include <linux/gracl.h>
55358 +#include <linux/grinternal.h>
55359 +
55360 +static const char *restab_log[] = {
55361 + [RLIMIT_CPU] = "RLIMIT_CPU",
55362 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55363 + [RLIMIT_DATA] = "RLIMIT_DATA",
55364 + [RLIMIT_STACK] = "RLIMIT_STACK",
55365 + [RLIMIT_CORE] = "RLIMIT_CORE",
55366 + [RLIMIT_RSS] = "RLIMIT_RSS",
55367 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
55368 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55369 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55370 + [RLIMIT_AS] = "RLIMIT_AS",
55371 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55372 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55373 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55374 + [RLIMIT_NICE] = "RLIMIT_NICE",
55375 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55376 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55377 + [GR_CRASH_RES] = "RLIMIT_CRASH"
55378 +};
55379 +
55380 +void
55381 +gr_log_resource(const struct task_struct *task,
55382 + const int res, const unsigned long wanted, const int gt)
55383 +{
55384 + const struct cred *cred;
55385 + unsigned long rlim;
55386 +
55387 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
55388 + return;
55389 +
55390 + // not yet supported resource
55391 + if (unlikely(!restab_log[res]))
55392 + return;
55393 +
55394 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55395 + rlim = task_rlimit_max(task, res);
55396 + else
55397 + rlim = task_rlimit(task, res);
55398 +
55399 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55400 + return;
55401 +
55402 + rcu_read_lock();
55403 + cred = __task_cred(task);
55404 +
55405 + if (res == RLIMIT_NPROC &&
55406 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55407 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55408 + goto out_rcu_unlock;
55409 + else if (res == RLIMIT_MEMLOCK &&
55410 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55411 + goto out_rcu_unlock;
55412 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55413 + goto out_rcu_unlock;
55414 + rcu_read_unlock();
55415 +
55416 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55417 +
55418 + return;
55419 +out_rcu_unlock:
55420 + rcu_read_unlock();
55421 + return;
55422 +}
55423 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55424 new file mode 100644
55425 index 0000000..5556be3
55426 --- /dev/null
55427 +++ b/grsecurity/gracl_segv.c
55428 @@ -0,0 +1,299 @@
55429 +#include <linux/kernel.h>
55430 +#include <linux/mm.h>
55431 +#include <asm/uaccess.h>
55432 +#include <asm/errno.h>
55433 +#include <asm/mman.h>
55434 +#include <net/sock.h>
55435 +#include <linux/file.h>
55436 +#include <linux/fs.h>
55437 +#include <linux/net.h>
55438 +#include <linux/in.h>
55439 +#include <linux/slab.h>
55440 +#include <linux/types.h>
55441 +#include <linux/sched.h>
55442 +#include <linux/timer.h>
55443 +#include <linux/gracl.h>
55444 +#include <linux/grsecurity.h>
55445 +#include <linux/grinternal.h>
55446 +
55447 +static struct crash_uid *uid_set;
55448 +static unsigned short uid_used;
55449 +static DEFINE_SPINLOCK(gr_uid_lock);
55450 +extern rwlock_t gr_inode_lock;
55451 +extern struct acl_subject_label *
55452 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55453 + struct acl_role_label *role);
55454 +
55455 +#ifdef CONFIG_BTRFS_FS
55456 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55457 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55458 +#endif
55459 +
55460 +static inline dev_t __get_dev(const struct dentry *dentry)
55461 +{
55462 +#ifdef CONFIG_BTRFS_FS
55463 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55464 + return get_btrfs_dev_from_inode(dentry->d_inode);
55465 + else
55466 +#endif
55467 + return dentry->d_inode->i_sb->s_dev;
55468 +}
55469 +
55470 +int
55471 +gr_init_uidset(void)
55472 +{
55473 + uid_set =
55474 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55475 + uid_used = 0;
55476 +
55477 + return uid_set ? 1 : 0;
55478 +}
55479 +
55480 +void
55481 +gr_free_uidset(void)
55482 +{
55483 + if (uid_set)
55484 + kfree(uid_set);
55485 +
55486 + return;
55487 +}
55488 +
55489 +int
55490 +gr_find_uid(const uid_t uid)
55491 +{
55492 + struct crash_uid *tmp = uid_set;
55493 + uid_t buid;
55494 + int low = 0, high = uid_used - 1, mid;
55495 +
55496 + while (high >= low) {
55497 + mid = (low + high) >> 1;
55498 + buid = tmp[mid].uid;
55499 + if (buid == uid)
55500 + return mid;
55501 + if (buid > uid)
55502 + high = mid - 1;
55503 + if (buid < uid)
55504 + low = mid + 1;
55505 + }
55506 +
55507 + return -1;
55508 +}
55509 +
55510 +static __inline__ void
55511 +gr_insertsort(void)
55512 +{
55513 + unsigned short i, j;
55514 + struct crash_uid index;
55515 +
55516 + for (i = 1; i < uid_used; i++) {
55517 + index = uid_set[i];
55518 + j = i;
55519 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55520 + uid_set[j] = uid_set[j - 1];
55521 + j--;
55522 + }
55523 + uid_set[j] = index;
55524 + }
55525 +
55526 + return;
55527 +}
55528 +
55529 +static __inline__ void
55530 +gr_insert_uid(const uid_t uid, const unsigned long expires)
55531 +{
55532 + int loc;
55533 +
55534 + if (uid_used == GR_UIDTABLE_MAX)
55535 + return;
55536 +
55537 + loc = gr_find_uid(uid);
55538 +
55539 + if (loc >= 0) {
55540 + uid_set[loc].expires = expires;
55541 + return;
55542 + }
55543 +
55544 + uid_set[uid_used].uid = uid;
55545 + uid_set[uid_used].expires = expires;
55546 + uid_used++;
55547 +
55548 + gr_insertsort();
55549 +
55550 + return;
55551 +}
55552 +
55553 +void
55554 +gr_remove_uid(const unsigned short loc)
55555 +{
55556 + unsigned short i;
55557 +
55558 + for (i = loc + 1; i < uid_used; i++)
55559 + uid_set[i - 1] = uid_set[i];
55560 +
55561 + uid_used--;
55562 +
55563 + return;
55564 +}
55565 +
55566 +int
55567 +gr_check_crash_uid(const uid_t uid)
55568 +{
55569 + int loc;
55570 + int ret = 0;
55571 +
55572 + if (unlikely(!gr_acl_is_enabled()))
55573 + return 0;
55574 +
55575 + spin_lock(&gr_uid_lock);
55576 + loc = gr_find_uid(uid);
55577 +
55578 + if (loc < 0)
55579 + goto out_unlock;
55580 +
55581 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
55582 + gr_remove_uid(loc);
55583 + else
55584 + ret = 1;
55585 +
55586 +out_unlock:
55587 + spin_unlock(&gr_uid_lock);
55588 + return ret;
55589 +}
55590 +
55591 +static __inline__ int
55592 +proc_is_setxid(const struct cred *cred)
55593 +{
55594 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
55595 + cred->uid != cred->fsuid)
55596 + return 1;
55597 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55598 + cred->gid != cred->fsgid)
55599 + return 1;
55600 +
55601 + return 0;
55602 +}
55603 +
55604 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
55605 +
55606 +void
55607 +gr_handle_crash(struct task_struct *task, const int sig)
55608 +{
55609 + struct acl_subject_label *curr;
55610 + struct task_struct *tsk, *tsk2;
55611 + const struct cred *cred;
55612 + const struct cred *cred2;
55613 +
55614 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55615 + return;
55616 +
55617 + if (unlikely(!gr_acl_is_enabled()))
55618 + return;
55619 +
55620 + curr = task->acl;
55621 +
55622 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
55623 + return;
55624 +
55625 + if (time_before_eq(curr->expires, get_seconds())) {
55626 + curr->expires = 0;
55627 + curr->crashes = 0;
55628 + }
55629 +
55630 + curr->crashes++;
55631 +
55632 + if (!curr->expires)
55633 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55634 +
55635 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55636 + time_after(curr->expires, get_seconds())) {
55637 + rcu_read_lock();
55638 + cred = __task_cred(task);
55639 + if (cred->uid && proc_is_setxid(cred)) {
55640 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55641 + spin_lock(&gr_uid_lock);
55642 + gr_insert_uid(cred->uid, curr->expires);
55643 + spin_unlock(&gr_uid_lock);
55644 + curr->expires = 0;
55645 + curr->crashes = 0;
55646 + read_lock(&tasklist_lock);
55647 + do_each_thread(tsk2, tsk) {
55648 + cred2 = __task_cred(tsk);
55649 + if (tsk != task && cred2->uid == cred->uid)
55650 + gr_fake_force_sig(SIGKILL, tsk);
55651 + } while_each_thread(tsk2, tsk);
55652 + read_unlock(&tasklist_lock);
55653 + } else {
55654 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55655 + read_lock(&tasklist_lock);
55656 + read_lock(&grsec_exec_file_lock);
55657 + do_each_thread(tsk2, tsk) {
55658 + if (likely(tsk != task)) {
55659 + // if this thread has the same subject as the one that triggered
55660 + // RES_CRASH and it's the same binary, kill it
55661 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55662 + gr_fake_force_sig(SIGKILL, tsk);
55663 + }
55664 + } while_each_thread(tsk2, tsk);
55665 + read_unlock(&grsec_exec_file_lock);
55666 + read_unlock(&tasklist_lock);
55667 + }
55668 + rcu_read_unlock();
55669 + }
55670 +
55671 + return;
55672 +}
55673 +
55674 +int
55675 +gr_check_crash_exec(const struct file *filp)
55676 +{
55677 + struct acl_subject_label *curr;
55678 +
55679 + if (unlikely(!gr_acl_is_enabled()))
55680 + return 0;
55681 +
55682 + read_lock(&gr_inode_lock);
55683 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55684 + __get_dev(filp->f_path.dentry),
55685 + current->role);
55686 + read_unlock(&gr_inode_lock);
55687 +
55688 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55689 + (!curr->crashes && !curr->expires))
55690 + return 0;
55691 +
55692 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55693 + time_after(curr->expires, get_seconds()))
55694 + return 1;
55695 + else if (time_before_eq(curr->expires, get_seconds())) {
55696 + curr->crashes = 0;
55697 + curr->expires = 0;
55698 + }
55699 +
55700 + return 0;
55701 +}
55702 +
55703 +void
55704 +gr_handle_alertkill(struct task_struct *task)
55705 +{
55706 + struct acl_subject_label *curracl;
55707 + __u32 curr_ip;
55708 + struct task_struct *p, *p2;
55709 +
55710 + if (unlikely(!gr_acl_is_enabled()))
55711 + return;
55712 +
55713 + curracl = task->acl;
55714 + curr_ip = task->signal->curr_ip;
55715 +
55716 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55717 + read_lock(&tasklist_lock);
55718 + do_each_thread(p2, p) {
55719 + if (p->signal->curr_ip == curr_ip)
55720 + gr_fake_force_sig(SIGKILL, p);
55721 + } while_each_thread(p2, p);
55722 + read_unlock(&tasklist_lock);
55723 + } else if (curracl->mode & GR_KILLPROC)
55724 + gr_fake_force_sig(SIGKILL, task);
55725 +
55726 + return;
55727 +}
55728 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55729 new file mode 100644
55730 index 0000000..9d83a69
55731 --- /dev/null
55732 +++ b/grsecurity/gracl_shm.c
55733 @@ -0,0 +1,40 @@
55734 +#include <linux/kernel.h>
55735 +#include <linux/mm.h>
55736 +#include <linux/sched.h>
55737 +#include <linux/file.h>
55738 +#include <linux/ipc.h>
55739 +#include <linux/gracl.h>
55740 +#include <linux/grsecurity.h>
55741 +#include <linux/grinternal.h>
55742 +
55743 +int
55744 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55745 + const time_t shm_createtime, const uid_t cuid, const int shmid)
55746 +{
55747 + struct task_struct *task;
55748 +
55749 + if (!gr_acl_is_enabled())
55750 + return 1;
55751 +
55752 + rcu_read_lock();
55753 + read_lock(&tasklist_lock);
55754 +
55755 + task = find_task_by_vpid(shm_cprid);
55756 +
55757 + if (unlikely(!task))
55758 + task = find_task_by_vpid(shm_lapid);
55759 +
55760 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55761 + (task->pid == shm_lapid)) &&
55762 + (task->acl->mode & GR_PROTSHM) &&
55763 + (task->acl != current->acl))) {
55764 + read_unlock(&tasklist_lock);
55765 + rcu_read_unlock();
55766 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55767 + return 0;
55768 + }
55769 + read_unlock(&tasklist_lock);
55770 + rcu_read_unlock();
55771 +
55772 + return 1;
55773 +}
55774 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55775 new file mode 100644
55776 index 0000000..bc0be01
55777 --- /dev/null
55778 +++ b/grsecurity/grsec_chdir.c
55779 @@ -0,0 +1,19 @@
55780 +#include <linux/kernel.h>
55781 +#include <linux/sched.h>
55782 +#include <linux/fs.h>
55783 +#include <linux/file.h>
55784 +#include <linux/grsecurity.h>
55785 +#include <linux/grinternal.h>
55786 +
55787 +void
55788 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55789 +{
55790 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55791 + if ((grsec_enable_chdir && grsec_enable_group &&
55792 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55793 + !grsec_enable_group)) {
55794 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55795 + }
55796 +#endif
55797 + return;
55798 +}
55799 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55800 new file mode 100644
55801 index 0000000..a2dc675
55802 --- /dev/null
55803 +++ b/grsecurity/grsec_chroot.c
55804 @@ -0,0 +1,351 @@
55805 +#include <linux/kernel.h>
55806 +#include <linux/module.h>
55807 +#include <linux/sched.h>
55808 +#include <linux/file.h>
55809 +#include <linux/fs.h>
55810 +#include <linux/mount.h>
55811 +#include <linux/types.h>
55812 +#include <linux/pid_namespace.h>
55813 +#include <linux/grsecurity.h>
55814 +#include <linux/grinternal.h>
55815 +
55816 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55817 +{
55818 +#ifdef CONFIG_GRKERNSEC
55819 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55820 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
55821 + task->gr_is_chrooted = 1;
55822 + else
55823 + task->gr_is_chrooted = 0;
55824 +
55825 + task->gr_chroot_dentry = path->dentry;
55826 +#endif
55827 + return;
55828 +}
55829 +
55830 +void gr_clear_chroot_entries(struct task_struct *task)
55831 +{
55832 +#ifdef CONFIG_GRKERNSEC
55833 + task->gr_is_chrooted = 0;
55834 + task->gr_chroot_dentry = NULL;
55835 +#endif
55836 + return;
55837 +}
55838 +
55839 +int
55840 +gr_handle_chroot_unix(const pid_t pid)
55841 +{
55842 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55843 + struct task_struct *p;
55844 +
55845 + if (unlikely(!grsec_enable_chroot_unix))
55846 + return 1;
55847 +
55848 + if (likely(!proc_is_chrooted(current)))
55849 + return 1;
55850 +
55851 + rcu_read_lock();
55852 + read_lock(&tasklist_lock);
55853 + p = find_task_by_vpid_unrestricted(pid);
55854 + if (unlikely(p && !have_same_root(current, p))) {
55855 + read_unlock(&tasklist_lock);
55856 + rcu_read_unlock();
55857 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
55858 + return 0;
55859 + }
55860 + read_unlock(&tasklist_lock);
55861 + rcu_read_unlock();
55862 +#endif
55863 + return 1;
55864 +}
55865 +
55866 +int
55867 +gr_handle_chroot_nice(void)
55868 +{
55869 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55870 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
55871 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
55872 + return -EPERM;
55873 + }
55874 +#endif
55875 + return 0;
55876 +}
55877 +
55878 +int
55879 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
55880 +{
55881 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55882 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
55883 + && proc_is_chrooted(current)) {
55884 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
55885 + return -EACCES;
55886 + }
55887 +#endif
55888 + return 0;
55889 +}
55890 +
55891 +int
55892 +gr_handle_chroot_rawio(const struct inode *inode)
55893 +{
55894 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55895 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55896 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
55897 + return 1;
55898 +#endif
55899 + return 0;
55900 +}
55901 +
55902 +int
55903 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
55904 +{
55905 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55906 + struct task_struct *p;
55907 + int ret = 0;
55908 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
55909 + return ret;
55910 +
55911 + read_lock(&tasklist_lock);
55912 + do_each_pid_task(pid, type, p) {
55913 + if (!have_same_root(current, p)) {
55914 + ret = 1;
55915 + goto out;
55916 + }
55917 + } while_each_pid_task(pid, type, p);
55918 +out:
55919 + read_unlock(&tasklist_lock);
55920 + return ret;
55921 +#endif
55922 + return 0;
55923 +}
55924 +
55925 +int
55926 +gr_pid_is_chrooted(struct task_struct *p)
55927 +{
55928 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55929 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
55930 + return 0;
55931 +
55932 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
55933 + !have_same_root(current, p)) {
55934 + return 1;
55935 + }
55936 +#endif
55937 + return 0;
55938 +}
55939 +
55940 +EXPORT_SYMBOL(gr_pid_is_chrooted);
55941 +
55942 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
55943 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
55944 +{
55945 + struct path path, currentroot;
55946 + int ret = 0;
55947 +
55948 + path.dentry = (struct dentry *)u_dentry;
55949 + path.mnt = (struct vfsmount *)u_mnt;
55950 + get_fs_root(current->fs, &currentroot);
55951 + if (path_is_under(&path, &currentroot))
55952 + ret = 1;
55953 + path_put(&currentroot);
55954 +
55955 + return ret;
55956 +}
55957 +#endif
55958 +
55959 +int
55960 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
55961 +{
55962 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55963 + if (!grsec_enable_chroot_fchdir)
55964 + return 1;
55965 +
55966 + if (!proc_is_chrooted(current))
55967 + return 1;
55968 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
55969 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
55970 + return 0;
55971 + }
55972 +#endif
55973 + return 1;
55974 +}
55975 +
55976 +int
55977 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55978 + const time_t shm_createtime)
55979 +{
55980 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55981 + struct task_struct *p;
55982 + time_t starttime;
55983 +
55984 + if (unlikely(!grsec_enable_chroot_shmat))
55985 + return 1;
55986 +
55987 + if (likely(!proc_is_chrooted(current)))
55988 + return 1;
55989 +
55990 + rcu_read_lock();
55991 + read_lock(&tasklist_lock);
55992 +
55993 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
55994 + starttime = p->start_time.tv_sec;
55995 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
55996 + if (have_same_root(current, p)) {
55997 + goto allow;
55998 + } else {
55999 + read_unlock(&tasklist_lock);
56000 + rcu_read_unlock();
56001 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56002 + return 0;
56003 + }
56004 + }
56005 + /* creator exited, pid reuse, fall through to next check */
56006 + }
56007 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56008 + if (unlikely(!have_same_root(current, p))) {
56009 + read_unlock(&tasklist_lock);
56010 + rcu_read_unlock();
56011 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56012 + return 0;
56013 + }
56014 + }
56015 +
56016 +allow:
56017 + read_unlock(&tasklist_lock);
56018 + rcu_read_unlock();
56019 +#endif
56020 + return 1;
56021 +}
56022 +
56023 +void
56024 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56025 +{
56026 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56027 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56028 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56029 +#endif
56030 + return;
56031 +}
56032 +
56033 +int
56034 +gr_handle_chroot_mknod(const struct dentry *dentry,
56035 + const struct vfsmount *mnt, const int mode)
56036 +{
56037 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56038 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56039 + proc_is_chrooted(current)) {
56040 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56041 + return -EPERM;
56042 + }
56043 +#endif
56044 + return 0;
56045 +}
56046 +
56047 +int
56048 +gr_handle_chroot_mount(const struct dentry *dentry,
56049 + const struct vfsmount *mnt, const char *dev_name)
56050 +{
56051 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56052 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56053 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56054 + return -EPERM;
56055 + }
56056 +#endif
56057 + return 0;
56058 +}
56059 +
56060 +int
56061 +gr_handle_chroot_pivot(void)
56062 +{
56063 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56064 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56065 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56066 + return -EPERM;
56067 + }
56068 +#endif
56069 + return 0;
56070 +}
56071 +
56072 +int
56073 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56074 +{
56075 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56076 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56077 + !gr_is_outside_chroot(dentry, mnt)) {
56078 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56079 + return -EPERM;
56080 + }
56081 +#endif
56082 + return 0;
56083 +}
56084 +
56085 +extern const char *captab_log[];
56086 +extern int captab_log_entries;
56087 +
56088 +int
56089 +gr_chroot_is_capable(const int cap)
56090 +{
56091 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56092 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
56093 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56094 + if (cap_raised(chroot_caps, cap)) {
56095 + const struct cred *creds = current_cred();
56096 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
56097 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
56098 + }
56099 + return 0;
56100 + }
56101 + }
56102 +#endif
56103 + return 1;
56104 +}
56105 +
56106 +int
56107 +gr_chroot_is_capable_nolog(const int cap)
56108 +{
56109 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56110 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
56111 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56112 + if (cap_raised(chroot_caps, cap)) {
56113 + return 0;
56114 + }
56115 + }
56116 +#endif
56117 + return 1;
56118 +}
56119 +
56120 +int
56121 +gr_handle_chroot_sysctl(const int op)
56122 +{
56123 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56124 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56125 + proc_is_chrooted(current))
56126 + return -EACCES;
56127 +#endif
56128 + return 0;
56129 +}
56130 +
56131 +void
56132 +gr_handle_chroot_chdir(struct path *path)
56133 +{
56134 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56135 + if (grsec_enable_chroot_chdir)
56136 + set_fs_pwd(current->fs, path);
56137 +#endif
56138 + return;
56139 +}
56140 +
56141 +int
56142 +gr_handle_chroot_chmod(const struct dentry *dentry,
56143 + const struct vfsmount *mnt, const int mode)
56144 +{
56145 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56146 + /* allow chmod +s on directories, but not files */
56147 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56148 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56149 + proc_is_chrooted(current)) {
56150 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56151 + return -EPERM;
56152 + }
56153 +#endif
56154 + return 0;
56155 +}
56156 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56157 new file mode 100644
56158 index 0000000..213ad8b
56159 --- /dev/null
56160 +++ b/grsecurity/grsec_disabled.c
56161 @@ -0,0 +1,437 @@
56162 +#include <linux/kernel.h>
56163 +#include <linux/module.h>
56164 +#include <linux/sched.h>
56165 +#include <linux/file.h>
56166 +#include <linux/fs.h>
56167 +#include <linux/kdev_t.h>
56168 +#include <linux/net.h>
56169 +#include <linux/in.h>
56170 +#include <linux/ip.h>
56171 +#include <linux/skbuff.h>
56172 +#include <linux/sysctl.h>
56173 +
56174 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56175 +void
56176 +pax_set_initial_flags(struct linux_binprm *bprm)
56177 +{
56178 + return;
56179 +}
56180 +#endif
56181 +
56182 +#ifdef CONFIG_SYSCTL
56183 +__u32
56184 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56185 +{
56186 + return 0;
56187 +}
56188 +#endif
56189 +
56190 +#ifdef CONFIG_TASKSTATS
56191 +int gr_is_taskstats_denied(int pid)
56192 +{
56193 + return 0;
56194 +}
56195 +#endif
56196 +
56197 +int
56198 +gr_acl_is_enabled(void)
56199 +{
56200 + return 0;
56201 +}
56202 +
56203 +void
56204 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56205 +{
56206 + return;
56207 +}
56208 +
56209 +int
56210 +gr_handle_rawio(const struct inode *inode)
56211 +{
56212 + return 0;
56213 +}
56214 +
56215 +void
56216 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56217 +{
56218 + return;
56219 +}
56220 +
56221 +int
56222 +gr_handle_ptrace(struct task_struct *task, const long request)
56223 +{
56224 + return 0;
56225 +}
56226 +
56227 +int
56228 +gr_handle_proc_ptrace(struct task_struct *task)
56229 +{
56230 + return 0;
56231 +}
56232 +
56233 +void
56234 +gr_learn_resource(const struct task_struct *task,
56235 + const int res, const unsigned long wanted, const int gt)
56236 +{
56237 + return;
56238 +}
56239 +
56240 +int
56241 +gr_set_acls(const int type)
56242 +{
56243 + return 0;
56244 +}
56245 +
56246 +int
56247 +gr_check_hidden_task(const struct task_struct *tsk)
56248 +{
56249 + return 0;
56250 +}
56251 +
56252 +int
56253 +gr_check_protected_task(const struct task_struct *task)
56254 +{
56255 + return 0;
56256 +}
56257 +
56258 +int
56259 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56260 +{
56261 + return 0;
56262 +}
56263 +
56264 +void
56265 +gr_copy_label(struct task_struct *tsk)
56266 +{
56267 + return;
56268 +}
56269 +
56270 +void
56271 +gr_set_pax_flags(struct task_struct *task)
56272 +{
56273 + return;
56274 +}
56275 +
56276 +int
56277 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56278 + const int unsafe_share)
56279 +{
56280 + return 0;
56281 +}
56282 +
56283 +void
56284 +gr_handle_delete(const ino_t ino, const dev_t dev)
56285 +{
56286 + return;
56287 +}
56288 +
56289 +void
56290 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56291 +{
56292 + return;
56293 +}
56294 +
56295 +void
56296 +gr_handle_crash(struct task_struct *task, const int sig)
56297 +{
56298 + return;
56299 +}
56300 +
56301 +int
56302 +gr_check_crash_exec(const struct file *filp)
56303 +{
56304 + return 0;
56305 +}
56306 +
56307 +int
56308 +gr_check_crash_uid(const uid_t uid)
56309 +{
56310 + return 0;
56311 +}
56312 +
56313 +void
56314 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56315 + struct dentry *old_dentry,
56316 + struct dentry *new_dentry,
56317 + struct vfsmount *mnt, const __u8 replace)
56318 +{
56319 + return;
56320 +}
56321 +
56322 +int
56323 +gr_search_socket(const int family, const int type, const int protocol)
56324 +{
56325 + return 1;
56326 +}
56327 +
56328 +int
56329 +gr_search_connectbind(const int mode, const struct socket *sock,
56330 + const struct sockaddr_in *addr)
56331 +{
56332 + return 0;
56333 +}
56334 +
56335 +void
56336 +gr_handle_alertkill(struct task_struct *task)
56337 +{
56338 + return;
56339 +}
56340 +
56341 +__u32
56342 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56343 +{
56344 + return 1;
56345 +}
56346 +
56347 +__u32
56348 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56349 + const struct vfsmount * mnt)
56350 +{
56351 + return 1;
56352 +}
56353 +
56354 +__u32
56355 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56356 + int acc_mode)
56357 +{
56358 + return 1;
56359 +}
56360 +
56361 +__u32
56362 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56363 +{
56364 + return 1;
56365 +}
56366 +
56367 +__u32
56368 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56369 +{
56370 + return 1;
56371 +}
56372 +
56373 +int
56374 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56375 + unsigned int *vm_flags)
56376 +{
56377 + return 1;
56378 +}
56379 +
56380 +__u32
56381 +gr_acl_handle_truncate(const struct dentry * dentry,
56382 + const struct vfsmount * mnt)
56383 +{
56384 + return 1;
56385 +}
56386 +
56387 +__u32
56388 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56389 +{
56390 + return 1;
56391 +}
56392 +
56393 +__u32
56394 +gr_acl_handle_access(const struct dentry * dentry,
56395 + const struct vfsmount * mnt, const int fmode)
56396 +{
56397 + return 1;
56398 +}
56399 +
56400 +__u32
56401 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56402 + umode_t *mode)
56403 +{
56404 + return 1;
56405 +}
56406 +
56407 +__u32
56408 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56409 +{
56410 + return 1;
56411 +}
56412 +
56413 +__u32
56414 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56415 +{
56416 + return 1;
56417 +}
56418 +
56419 +void
56420 +grsecurity_init(void)
56421 +{
56422 + return;
56423 +}
56424 +
56425 +umode_t gr_acl_umask(void)
56426 +{
56427 + return 0;
56428 +}
56429 +
56430 +__u32
56431 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56432 + const struct dentry * parent_dentry,
56433 + const struct vfsmount * parent_mnt,
56434 + const int mode)
56435 +{
56436 + return 1;
56437 +}
56438 +
56439 +__u32
56440 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
56441 + const struct dentry * parent_dentry,
56442 + const struct vfsmount * parent_mnt)
56443 +{
56444 + return 1;
56445 +}
56446 +
56447 +__u32
56448 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56449 + const struct dentry * parent_dentry,
56450 + const struct vfsmount * parent_mnt, const char *from)
56451 +{
56452 + return 1;
56453 +}
56454 +
56455 +__u32
56456 +gr_acl_handle_link(const struct dentry * new_dentry,
56457 + const struct dentry * parent_dentry,
56458 + const struct vfsmount * parent_mnt,
56459 + const struct dentry * old_dentry,
56460 + const struct vfsmount * old_mnt, const char *to)
56461 +{
56462 + return 1;
56463 +}
56464 +
56465 +int
56466 +gr_acl_handle_rename(const struct dentry *new_dentry,
56467 + const struct dentry *parent_dentry,
56468 + const struct vfsmount *parent_mnt,
56469 + const struct dentry *old_dentry,
56470 + const struct inode *old_parent_inode,
56471 + const struct vfsmount *old_mnt, const char *newname)
56472 +{
56473 + return 0;
56474 +}
56475 +
56476 +int
56477 +gr_acl_handle_filldir(const struct file *file, const char *name,
56478 + const int namelen, const ino_t ino)
56479 +{
56480 + return 1;
56481 +}
56482 +
56483 +int
56484 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56485 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56486 +{
56487 + return 1;
56488 +}
56489 +
56490 +int
56491 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56492 +{
56493 + return 0;
56494 +}
56495 +
56496 +int
56497 +gr_search_accept(const struct socket *sock)
56498 +{
56499 + return 0;
56500 +}
56501 +
56502 +int
56503 +gr_search_listen(const struct socket *sock)
56504 +{
56505 + return 0;
56506 +}
56507 +
56508 +int
56509 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56510 +{
56511 + return 0;
56512 +}
56513 +
56514 +__u32
56515 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56516 +{
56517 + return 1;
56518 +}
56519 +
56520 +__u32
56521 +gr_acl_handle_creat(const struct dentry * dentry,
56522 + const struct dentry * p_dentry,
56523 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56524 + const int imode)
56525 +{
56526 + return 1;
56527 +}
56528 +
56529 +void
56530 +gr_acl_handle_exit(void)
56531 +{
56532 + return;
56533 +}
56534 +
56535 +int
56536 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56537 +{
56538 + return 1;
56539 +}
56540 +
56541 +void
56542 +gr_set_role_label(const uid_t uid, const gid_t gid)
56543 +{
56544 + return;
56545 +}
56546 +
56547 +int
56548 +gr_acl_handle_procpidmem(const struct task_struct *task)
56549 +{
56550 + return 0;
56551 +}
56552 +
56553 +int
56554 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56555 +{
56556 + return 0;
56557 +}
56558 +
56559 +int
56560 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56561 +{
56562 + return 0;
56563 +}
56564 +
56565 +void
56566 +gr_set_kernel_label(struct task_struct *task)
56567 +{
56568 + return;
56569 +}
56570 +
56571 +int
56572 +gr_check_user_change(int real, int effective, int fs)
56573 +{
56574 + return 0;
56575 +}
56576 +
56577 +int
56578 +gr_check_group_change(int real, int effective, int fs)
56579 +{
56580 + return 0;
56581 +}
56582 +
56583 +int gr_acl_enable_at_secure(void)
56584 +{
56585 + return 0;
56586 +}
56587 +
56588 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56589 +{
56590 + return dentry->d_inode->i_sb->s_dev;
56591 +}
56592 +
56593 +EXPORT_SYMBOL(gr_learn_resource);
56594 +EXPORT_SYMBOL(gr_set_kernel_label);
56595 +#ifdef CONFIG_SECURITY
56596 +EXPORT_SYMBOL(gr_check_user_change);
56597 +EXPORT_SYMBOL(gr_check_group_change);
56598 +#endif
56599 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56600 new file mode 100644
56601 index 0000000..2b05ada
56602 --- /dev/null
56603 +++ b/grsecurity/grsec_exec.c
56604 @@ -0,0 +1,146 @@
56605 +#include <linux/kernel.h>
56606 +#include <linux/sched.h>
56607 +#include <linux/file.h>
56608 +#include <linux/binfmts.h>
56609 +#include <linux/fs.h>
56610 +#include <linux/types.h>
56611 +#include <linux/grdefs.h>
56612 +#include <linux/grsecurity.h>
56613 +#include <linux/grinternal.h>
56614 +#include <linux/capability.h>
56615 +#include <linux/module.h>
56616 +
56617 +#include <asm/uaccess.h>
56618 +
56619 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56620 +static char gr_exec_arg_buf[132];
56621 +static DEFINE_MUTEX(gr_exec_arg_mutex);
56622 +#endif
56623 +
56624 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56625 +
56626 +void
56627 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56628 +{
56629 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56630 + char *grarg = gr_exec_arg_buf;
56631 + unsigned int i, x, execlen = 0;
56632 + char c;
56633 +
56634 + if (!((grsec_enable_execlog && grsec_enable_group &&
56635 + in_group_p(grsec_audit_gid))
56636 + || (grsec_enable_execlog && !grsec_enable_group)))
56637 + return;
56638 +
56639 + mutex_lock(&gr_exec_arg_mutex);
56640 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
56641 +
56642 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
56643 + const char __user *p;
56644 + unsigned int len;
56645 +
56646 + p = get_user_arg_ptr(argv, i);
56647 + if (IS_ERR(p))
56648 + goto log;
56649 +
56650 + len = strnlen_user(p, 128 - execlen);
56651 + if (len > 128 - execlen)
56652 + len = 128 - execlen;
56653 + else if (len > 0)
56654 + len--;
56655 + if (copy_from_user(grarg + execlen, p, len))
56656 + goto log;
56657 +
56658 + /* rewrite unprintable characters */
56659 + for (x = 0; x < len; x++) {
56660 + c = *(grarg + execlen + x);
56661 + if (c < 32 || c > 126)
56662 + *(grarg + execlen + x) = ' ';
56663 + }
56664 +
56665 + execlen += len;
56666 + *(grarg + execlen) = ' ';
56667 + *(grarg + execlen + 1) = '\0';
56668 + execlen++;
56669 + }
56670 +
56671 + log:
56672 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56673 + bprm->file->f_path.mnt, grarg);
56674 + mutex_unlock(&gr_exec_arg_mutex);
56675 +#endif
56676 + return;
56677 +}
56678 +
56679 +#ifdef CONFIG_GRKERNSEC
56680 +extern int gr_acl_is_capable(const int cap);
56681 +extern int gr_acl_is_capable_nolog(const int cap);
56682 +extern int gr_chroot_is_capable(const int cap);
56683 +extern int gr_chroot_is_capable_nolog(const int cap);
56684 +#endif
56685 +
56686 +const char *captab_log[] = {
56687 + "CAP_CHOWN",
56688 + "CAP_DAC_OVERRIDE",
56689 + "CAP_DAC_READ_SEARCH",
56690 + "CAP_FOWNER",
56691 + "CAP_FSETID",
56692 + "CAP_KILL",
56693 + "CAP_SETGID",
56694 + "CAP_SETUID",
56695 + "CAP_SETPCAP",
56696 + "CAP_LINUX_IMMUTABLE",
56697 + "CAP_NET_BIND_SERVICE",
56698 + "CAP_NET_BROADCAST",
56699 + "CAP_NET_ADMIN",
56700 + "CAP_NET_RAW",
56701 + "CAP_IPC_LOCK",
56702 + "CAP_IPC_OWNER",
56703 + "CAP_SYS_MODULE",
56704 + "CAP_SYS_RAWIO",
56705 + "CAP_SYS_CHROOT",
56706 + "CAP_SYS_PTRACE",
56707 + "CAP_SYS_PACCT",
56708 + "CAP_SYS_ADMIN",
56709 + "CAP_SYS_BOOT",
56710 + "CAP_SYS_NICE",
56711 + "CAP_SYS_RESOURCE",
56712 + "CAP_SYS_TIME",
56713 + "CAP_SYS_TTY_CONFIG",
56714 + "CAP_MKNOD",
56715 + "CAP_LEASE",
56716 + "CAP_AUDIT_WRITE",
56717 + "CAP_AUDIT_CONTROL",
56718 + "CAP_SETFCAP",
56719 + "CAP_MAC_OVERRIDE",
56720 + "CAP_MAC_ADMIN",
56721 + "CAP_SYSLOG",
56722 + "CAP_WAKE_ALARM"
56723 +};
56724 +
56725 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56726 +
56727 +int gr_is_capable(const int cap)
56728 +{
56729 +#ifdef CONFIG_GRKERNSEC
56730 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56731 + return 1;
56732 + return 0;
56733 +#else
56734 + return 1;
56735 +#endif
56736 +}
56737 +
56738 +int gr_is_capable_nolog(const int cap)
56739 +{
56740 +#ifdef CONFIG_GRKERNSEC
56741 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56742 + return 1;
56743 + return 0;
56744 +#else
56745 + return 1;
56746 +#endif
56747 +}
56748 +
56749 +EXPORT_SYMBOL(gr_is_capable);
56750 +EXPORT_SYMBOL(gr_is_capable_nolog);
56751 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56752 new file mode 100644
56753 index 0000000..d3ee748
56754 --- /dev/null
56755 +++ b/grsecurity/grsec_fifo.c
56756 @@ -0,0 +1,24 @@
56757 +#include <linux/kernel.h>
56758 +#include <linux/sched.h>
56759 +#include <linux/fs.h>
56760 +#include <linux/file.h>
56761 +#include <linux/grinternal.h>
56762 +
56763 +int
56764 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56765 + const struct dentry *dir, const int flag, const int acc_mode)
56766 +{
56767 +#ifdef CONFIG_GRKERNSEC_FIFO
56768 + const struct cred *cred = current_cred();
56769 +
56770 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56771 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56772 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56773 + (cred->fsuid != dentry->d_inode->i_uid)) {
56774 + if (!inode_permission(dentry->d_inode, acc_mode))
56775 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56776 + return -EACCES;
56777 + }
56778 +#endif
56779 + return 0;
56780 +}
56781 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56782 new file mode 100644
56783 index 0000000..8ca18bf
56784 --- /dev/null
56785 +++ b/grsecurity/grsec_fork.c
56786 @@ -0,0 +1,23 @@
56787 +#include <linux/kernel.h>
56788 +#include <linux/sched.h>
56789 +#include <linux/grsecurity.h>
56790 +#include <linux/grinternal.h>
56791 +#include <linux/errno.h>
56792 +
56793 +void
56794 +gr_log_forkfail(const int retval)
56795 +{
56796 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56797 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
56798 + switch (retval) {
56799 + case -EAGAIN:
56800 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
56801 + break;
56802 + case -ENOMEM:
56803 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
56804 + break;
56805 + }
56806 + }
56807 +#endif
56808 + return;
56809 +}
56810 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
56811 new file mode 100644
56812 index 0000000..01ddde4
56813 --- /dev/null
56814 +++ b/grsecurity/grsec_init.c
56815 @@ -0,0 +1,277 @@
56816 +#include <linux/kernel.h>
56817 +#include <linux/sched.h>
56818 +#include <linux/mm.h>
56819 +#include <linux/gracl.h>
56820 +#include <linux/slab.h>
56821 +#include <linux/vmalloc.h>
56822 +#include <linux/percpu.h>
56823 +#include <linux/module.h>
56824 +
56825 +int grsec_enable_ptrace_readexec;
56826 +int grsec_enable_setxid;
56827 +int grsec_enable_brute;
56828 +int grsec_enable_link;
56829 +int grsec_enable_dmesg;
56830 +int grsec_enable_harden_ptrace;
56831 +int grsec_enable_fifo;
56832 +int grsec_enable_execlog;
56833 +int grsec_enable_signal;
56834 +int grsec_enable_forkfail;
56835 +int grsec_enable_audit_ptrace;
56836 +int grsec_enable_time;
56837 +int grsec_enable_audit_textrel;
56838 +int grsec_enable_group;
56839 +int grsec_audit_gid;
56840 +int grsec_enable_chdir;
56841 +int grsec_enable_mount;
56842 +int grsec_enable_rofs;
56843 +int grsec_enable_chroot_findtask;
56844 +int grsec_enable_chroot_mount;
56845 +int grsec_enable_chroot_shmat;
56846 +int grsec_enable_chroot_fchdir;
56847 +int grsec_enable_chroot_double;
56848 +int grsec_enable_chroot_pivot;
56849 +int grsec_enable_chroot_chdir;
56850 +int grsec_enable_chroot_chmod;
56851 +int grsec_enable_chroot_mknod;
56852 +int grsec_enable_chroot_nice;
56853 +int grsec_enable_chroot_execlog;
56854 +int grsec_enable_chroot_caps;
56855 +int grsec_enable_chroot_sysctl;
56856 +int grsec_enable_chroot_unix;
56857 +int grsec_enable_tpe;
56858 +int grsec_tpe_gid;
56859 +int grsec_enable_blackhole;
56860 +#ifdef CONFIG_IPV6_MODULE
56861 +EXPORT_SYMBOL(grsec_enable_blackhole);
56862 +#endif
56863 +int grsec_lastack_retries;
56864 +int grsec_enable_tpe_all;
56865 +int grsec_enable_tpe_invert;
56866 +int grsec_enable_socket_all;
56867 +int grsec_socket_all_gid;
56868 +int grsec_enable_socket_client;
56869 +int grsec_socket_client_gid;
56870 +int grsec_enable_socket_server;
56871 +int grsec_socket_server_gid;
56872 +int grsec_resource_logging;
56873 +int grsec_disable_privio;
56874 +int grsec_enable_log_rwxmaps;
56875 +int grsec_lock;
56876 +
56877 +DEFINE_SPINLOCK(grsec_alert_lock);
56878 +unsigned long grsec_alert_wtime = 0;
56879 +unsigned long grsec_alert_fyet = 0;
56880 +
56881 +DEFINE_SPINLOCK(grsec_audit_lock);
56882 +
56883 +DEFINE_RWLOCK(grsec_exec_file_lock);
56884 +
56885 +char *gr_shared_page[4];
56886 +
56887 +char *gr_alert_log_fmt;
56888 +char *gr_audit_log_fmt;
56889 +char *gr_alert_log_buf;
56890 +char *gr_audit_log_buf;
56891 +
56892 +extern struct gr_arg *gr_usermode;
56893 +extern unsigned char *gr_system_salt;
56894 +extern unsigned char *gr_system_sum;
56895 +
56896 +void __init
56897 +grsecurity_init(void)
56898 +{
56899 + int j;
56900 + /* create the per-cpu shared pages */
56901 +
56902 +#ifdef CONFIG_X86
56903 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
56904 +#endif
56905 +
56906 + for (j = 0; j < 4; j++) {
56907 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
56908 + if (gr_shared_page[j] == NULL) {
56909 + panic("Unable to allocate grsecurity shared page");
56910 + return;
56911 + }
56912 + }
56913 +
56914 + /* allocate log buffers */
56915 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
56916 + if (!gr_alert_log_fmt) {
56917 + panic("Unable to allocate grsecurity alert log format buffer");
56918 + return;
56919 + }
56920 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
56921 + if (!gr_audit_log_fmt) {
56922 + panic("Unable to allocate grsecurity audit log format buffer");
56923 + return;
56924 + }
56925 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56926 + if (!gr_alert_log_buf) {
56927 + panic("Unable to allocate grsecurity alert log buffer");
56928 + return;
56929 + }
56930 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56931 + if (!gr_audit_log_buf) {
56932 + panic("Unable to allocate grsecurity audit log buffer");
56933 + return;
56934 + }
56935 +
56936 + /* allocate memory for authentication structure */
56937 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
56938 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
56939 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
56940 +
56941 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
56942 + panic("Unable to allocate grsecurity authentication structure");
56943 + return;
56944 + }
56945 +
56946 +
56947 +#ifdef CONFIG_GRKERNSEC_IO
56948 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
56949 + grsec_disable_privio = 1;
56950 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56951 + grsec_disable_privio = 1;
56952 +#else
56953 + grsec_disable_privio = 0;
56954 +#endif
56955 +#endif
56956 +
56957 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56958 + /* for backward compatibility, tpe_invert always defaults to on if
56959 + enabled in the kernel
56960 + */
56961 + grsec_enable_tpe_invert = 1;
56962 +#endif
56963 +
56964 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56965 +#ifndef CONFIG_GRKERNSEC_SYSCTL
56966 + grsec_lock = 1;
56967 +#endif
56968 +
56969 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56970 + grsec_enable_audit_textrel = 1;
56971 +#endif
56972 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56973 + grsec_enable_log_rwxmaps = 1;
56974 +#endif
56975 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
56976 + grsec_enable_group = 1;
56977 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
56978 +#endif
56979 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56980 + grsec_enable_ptrace_readexec = 1;
56981 +#endif
56982 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56983 + grsec_enable_chdir = 1;
56984 +#endif
56985 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56986 + grsec_enable_harden_ptrace = 1;
56987 +#endif
56988 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56989 + grsec_enable_mount = 1;
56990 +#endif
56991 +#ifdef CONFIG_GRKERNSEC_LINK
56992 + grsec_enable_link = 1;
56993 +#endif
56994 +#ifdef CONFIG_GRKERNSEC_BRUTE
56995 + grsec_enable_brute = 1;
56996 +#endif
56997 +#ifdef CONFIG_GRKERNSEC_DMESG
56998 + grsec_enable_dmesg = 1;
56999 +#endif
57000 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57001 + grsec_enable_blackhole = 1;
57002 + grsec_lastack_retries = 4;
57003 +#endif
57004 +#ifdef CONFIG_GRKERNSEC_FIFO
57005 + grsec_enable_fifo = 1;
57006 +#endif
57007 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57008 + grsec_enable_execlog = 1;
57009 +#endif
57010 +#ifdef CONFIG_GRKERNSEC_SETXID
57011 + grsec_enable_setxid = 1;
57012 +#endif
57013 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57014 + grsec_enable_signal = 1;
57015 +#endif
57016 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57017 + grsec_enable_forkfail = 1;
57018 +#endif
57019 +#ifdef CONFIG_GRKERNSEC_TIME
57020 + grsec_enable_time = 1;
57021 +#endif
57022 +#ifdef CONFIG_GRKERNSEC_RESLOG
57023 + grsec_resource_logging = 1;
57024 +#endif
57025 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57026 + grsec_enable_chroot_findtask = 1;
57027 +#endif
57028 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57029 + grsec_enable_chroot_unix = 1;
57030 +#endif
57031 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57032 + grsec_enable_chroot_mount = 1;
57033 +#endif
57034 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57035 + grsec_enable_chroot_fchdir = 1;
57036 +#endif
57037 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57038 + grsec_enable_chroot_shmat = 1;
57039 +#endif
57040 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57041 + grsec_enable_audit_ptrace = 1;
57042 +#endif
57043 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57044 + grsec_enable_chroot_double = 1;
57045 +#endif
57046 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57047 + grsec_enable_chroot_pivot = 1;
57048 +#endif
57049 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57050 + grsec_enable_chroot_chdir = 1;
57051 +#endif
57052 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57053 + grsec_enable_chroot_chmod = 1;
57054 +#endif
57055 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57056 + grsec_enable_chroot_mknod = 1;
57057 +#endif
57058 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57059 + grsec_enable_chroot_nice = 1;
57060 +#endif
57061 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57062 + grsec_enable_chroot_execlog = 1;
57063 +#endif
57064 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57065 + grsec_enable_chroot_caps = 1;
57066 +#endif
57067 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57068 + grsec_enable_chroot_sysctl = 1;
57069 +#endif
57070 +#ifdef CONFIG_GRKERNSEC_TPE
57071 + grsec_enable_tpe = 1;
57072 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57073 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57074 + grsec_enable_tpe_all = 1;
57075 +#endif
57076 +#endif
57077 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57078 + grsec_enable_socket_all = 1;
57079 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57080 +#endif
57081 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57082 + grsec_enable_socket_client = 1;
57083 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57084 +#endif
57085 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57086 + grsec_enable_socket_server = 1;
57087 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57088 +#endif
57089 +#endif
57090 +
57091 + return;
57092 +}
57093 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57094 new file mode 100644
57095 index 0000000..3efe141
57096 --- /dev/null
57097 +++ b/grsecurity/grsec_link.c
57098 @@ -0,0 +1,43 @@
57099 +#include <linux/kernel.h>
57100 +#include <linux/sched.h>
57101 +#include <linux/fs.h>
57102 +#include <linux/file.h>
57103 +#include <linux/grinternal.h>
57104 +
57105 +int
57106 +gr_handle_follow_link(const struct inode *parent,
57107 + const struct inode *inode,
57108 + const struct dentry *dentry, const struct vfsmount *mnt)
57109 +{
57110 +#ifdef CONFIG_GRKERNSEC_LINK
57111 + const struct cred *cred = current_cred();
57112 +
57113 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57114 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57115 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57116 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57117 + return -EACCES;
57118 + }
57119 +#endif
57120 + return 0;
57121 +}
57122 +
57123 +int
57124 +gr_handle_hardlink(const struct dentry *dentry,
57125 + const struct vfsmount *mnt,
57126 + struct inode *inode, const int mode, const char *to)
57127 +{
57128 +#ifdef CONFIG_GRKERNSEC_LINK
57129 + const struct cred *cred = current_cred();
57130 +
57131 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57132 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57133 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57134 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57135 + !capable(CAP_FOWNER) && cred->uid) {
57136 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57137 + return -EPERM;
57138 + }
57139 +#endif
57140 + return 0;
57141 +}
57142 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57143 new file mode 100644
57144 index 0000000..a45d2e9
57145 --- /dev/null
57146 +++ b/grsecurity/grsec_log.c
57147 @@ -0,0 +1,322 @@
57148 +#include <linux/kernel.h>
57149 +#include <linux/sched.h>
57150 +#include <linux/file.h>
57151 +#include <linux/tty.h>
57152 +#include <linux/fs.h>
57153 +#include <linux/grinternal.h>
57154 +
57155 +#ifdef CONFIG_TREE_PREEMPT_RCU
57156 +#define DISABLE_PREEMPT() preempt_disable()
57157 +#define ENABLE_PREEMPT() preempt_enable()
57158 +#else
57159 +#define DISABLE_PREEMPT()
57160 +#define ENABLE_PREEMPT()
57161 +#endif
57162 +
57163 +#define BEGIN_LOCKS(x) \
57164 + DISABLE_PREEMPT(); \
57165 + rcu_read_lock(); \
57166 + read_lock(&tasklist_lock); \
57167 + read_lock(&grsec_exec_file_lock); \
57168 + if (x != GR_DO_AUDIT) \
57169 + spin_lock(&grsec_alert_lock); \
57170 + else \
57171 + spin_lock(&grsec_audit_lock)
57172 +
57173 +#define END_LOCKS(x) \
57174 + if (x != GR_DO_AUDIT) \
57175 + spin_unlock(&grsec_alert_lock); \
57176 + else \
57177 + spin_unlock(&grsec_audit_lock); \
57178 + read_unlock(&grsec_exec_file_lock); \
57179 + read_unlock(&tasklist_lock); \
57180 + rcu_read_unlock(); \
57181 + ENABLE_PREEMPT(); \
57182 + if (x == GR_DONT_AUDIT) \
57183 + gr_handle_alertkill(current)
57184 +
57185 +enum {
57186 + FLOODING,
57187 + NO_FLOODING
57188 +};
57189 +
57190 +extern char *gr_alert_log_fmt;
57191 +extern char *gr_audit_log_fmt;
57192 +extern char *gr_alert_log_buf;
57193 +extern char *gr_audit_log_buf;
57194 +
57195 +static int gr_log_start(int audit)
57196 +{
57197 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57198 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57199 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57200 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57201 + unsigned long curr_secs = get_seconds();
57202 +
57203 + if (audit == GR_DO_AUDIT)
57204 + goto set_fmt;
57205 +
57206 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57207 + grsec_alert_wtime = curr_secs;
57208 + grsec_alert_fyet = 0;
57209 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57210 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57211 + grsec_alert_fyet++;
57212 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57213 + grsec_alert_wtime = curr_secs;
57214 + grsec_alert_fyet++;
57215 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57216 + return FLOODING;
57217 + }
57218 + else return FLOODING;
57219 +
57220 +set_fmt:
57221 +#endif
57222 + memset(buf, 0, PAGE_SIZE);
57223 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57224 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57225 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57226 + } else if (current->signal->curr_ip) {
57227 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57228 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57229 + } else if (gr_acl_is_enabled()) {
57230 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57231 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57232 + } else {
57233 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57234 + strcpy(buf, fmt);
57235 + }
57236 +
57237 + return NO_FLOODING;
57238 +}
57239 +
57240 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57241 + __attribute__ ((format (printf, 2, 0)));
57242 +
57243 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57244 +{
57245 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57246 + unsigned int len = strlen(buf);
57247 +
57248 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57249 +
57250 + return;
57251 +}
57252 +
57253 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57254 + __attribute__ ((format (printf, 2, 3)));
57255 +
57256 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57257 +{
57258 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57259 + unsigned int len = strlen(buf);
57260 + va_list ap;
57261 +
57262 + va_start(ap, msg);
57263 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57264 + va_end(ap);
57265 +
57266 + return;
57267 +}
57268 +
57269 +static void gr_log_end(int audit, int append_default)
57270 +{
57271 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57272 +
57273 + if (append_default) {
57274 + unsigned int len = strlen(buf);
57275 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57276 + }
57277 +
57278 + printk("%s\n", buf);
57279 +
57280 + return;
57281 +}
57282 +
57283 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57284 +{
57285 + int logtype;
57286 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57287 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57288 + void *voidptr = NULL;
57289 + int num1 = 0, num2 = 0;
57290 + unsigned long ulong1 = 0, ulong2 = 0;
57291 + struct dentry *dentry = NULL;
57292 + struct vfsmount *mnt = NULL;
57293 + struct file *file = NULL;
57294 + struct task_struct *task = NULL;
57295 + const struct cred *cred, *pcred;
57296 + va_list ap;
57297 +
57298 + BEGIN_LOCKS(audit);
57299 + logtype = gr_log_start(audit);
57300 + if (logtype == FLOODING) {
57301 + END_LOCKS(audit);
57302 + return;
57303 + }
57304 + va_start(ap, argtypes);
57305 + switch (argtypes) {
57306 + case GR_TTYSNIFF:
57307 + task = va_arg(ap, struct task_struct *);
57308 + 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);
57309 + break;
57310 + case GR_SYSCTL_HIDDEN:
57311 + str1 = va_arg(ap, char *);
57312 + gr_log_middle_varargs(audit, msg, result, str1);
57313 + break;
57314 + case GR_RBAC:
57315 + dentry = va_arg(ap, struct dentry *);
57316 + mnt = va_arg(ap, struct vfsmount *);
57317 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57318 + break;
57319 + case GR_RBAC_STR:
57320 + dentry = va_arg(ap, struct dentry *);
57321 + mnt = va_arg(ap, struct vfsmount *);
57322 + str1 = va_arg(ap, char *);
57323 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57324 + break;
57325 + case GR_STR_RBAC:
57326 + str1 = va_arg(ap, char *);
57327 + dentry = va_arg(ap, struct dentry *);
57328 + mnt = va_arg(ap, struct vfsmount *);
57329 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57330 + break;
57331 + case GR_RBAC_MODE2:
57332 + dentry = va_arg(ap, struct dentry *);
57333 + mnt = va_arg(ap, struct vfsmount *);
57334 + str1 = va_arg(ap, char *);
57335 + str2 = va_arg(ap, char *);
57336 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57337 + break;
57338 + case GR_RBAC_MODE3:
57339 + dentry = va_arg(ap, struct dentry *);
57340 + mnt = va_arg(ap, struct vfsmount *);
57341 + str1 = va_arg(ap, char *);
57342 + str2 = va_arg(ap, char *);
57343 + str3 = va_arg(ap, char *);
57344 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57345 + break;
57346 + case GR_FILENAME:
57347 + dentry = va_arg(ap, struct dentry *);
57348 + mnt = va_arg(ap, struct vfsmount *);
57349 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57350 + break;
57351 + case GR_STR_FILENAME:
57352 + str1 = va_arg(ap, char *);
57353 + dentry = va_arg(ap, struct dentry *);
57354 + mnt = va_arg(ap, struct vfsmount *);
57355 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57356 + break;
57357 + case GR_FILENAME_STR:
57358 + dentry = va_arg(ap, struct dentry *);
57359 + mnt = va_arg(ap, struct vfsmount *);
57360 + str1 = va_arg(ap, char *);
57361 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57362 + break;
57363 + case GR_FILENAME_TWO_INT:
57364 + dentry = va_arg(ap, struct dentry *);
57365 + mnt = va_arg(ap, struct vfsmount *);
57366 + num1 = va_arg(ap, int);
57367 + num2 = va_arg(ap, int);
57368 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57369 + break;
57370 + case GR_FILENAME_TWO_INT_STR:
57371 + dentry = va_arg(ap, struct dentry *);
57372 + mnt = va_arg(ap, struct vfsmount *);
57373 + num1 = va_arg(ap, int);
57374 + num2 = va_arg(ap, int);
57375 + str1 = va_arg(ap, char *);
57376 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57377 + break;
57378 + case GR_TEXTREL:
57379 + file = va_arg(ap, struct file *);
57380 + ulong1 = va_arg(ap, unsigned long);
57381 + ulong2 = va_arg(ap, unsigned long);
57382 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57383 + break;
57384 + case GR_PTRACE:
57385 + task = va_arg(ap, struct task_struct *);
57386 + 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);
57387 + break;
57388 + case GR_RESOURCE:
57389 + task = va_arg(ap, struct task_struct *);
57390 + cred = __task_cred(task);
57391 + pcred = __task_cred(task->real_parent);
57392 + ulong1 = va_arg(ap, unsigned long);
57393 + str1 = va_arg(ap, char *);
57394 + ulong2 = va_arg(ap, unsigned long);
57395 + 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);
57396 + break;
57397 + case GR_CAP:
57398 + task = va_arg(ap, struct task_struct *);
57399 + cred = __task_cred(task);
57400 + pcred = __task_cred(task->real_parent);
57401 + str1 = va_arg(ap, char *);
57402 + 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);
57403 + break;
57404 + case GR_SIG:
57405 + str1 = va_arg(ap, char *);
57406 + voidptr = va_arg(ap, void *);
57407 + gr_log_middle_varargs(audit, msg, str1, voidptr);
57408 + break;
57409 + case GR_SIG2:
57410 + task = va_arg(ap, struct task_struct *);
57411 + cred = __task_cred(task);
57412 + pcred = __task_cred(task->real_parent);
57413 + num1 = va_arg(ap, int);
57414 + 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);
57415 + break;
57416 + case GR_CRASH1:
57417 + task = va_arg(ap, struct task_struct *);
57418 + cred = __task_cred(task);
57419 + pcred = __task_cred(task->real_parent);
57420 + ulong1 = va_arg(ap, unsigned long);
57421 + 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);
57422 + break;
57423 + case GR_CRASH2:
57424 + task = va_arg(ap, struct task_struct *);
57425 + cred = __task_cred(task);
57426 + pcred = __task_cred(task->real_parent);
57427 + ulong1 = va_arg(ap, unsigned long);
57428 + 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);
57429 + break;
57430 + case GR_RWXMAP:
57431 + file = va_arg(ap, struct file *);
57432 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57433 + break;
57434 + case GR_PSACCT:
57435 + {
57436 + unsigned int wday, cday;
57437 + __u8 whr, chr;
57438 + __u8 wmin, cmin;
57439 + __u8 wsec, csec;
57440 + char cur_tty[64] = { 0 };
57441 + char parent_tty[64] = { 0 };
57442 +
57443 + task = va_arg(ap, struct task_struct *);
57444 + wday = va_arg(ap, unsigned int);
57445 + cday = va_arg(ap, unsigned int);
57446 + whr = va_arg(ap, int);
57447 + chr = va_arg(ap, int);
57448 + wmin = va_arg(ap, int);
57449 + cmin = va_arg(ap, int);
57450 + wsec = va_arg(ap, int);
57451 + csec = va_arg(ap, int);
57452 + ulong1 = va_arg(ap, unsigned long);
57453 + cred = __task_cred(task);
57454 + pcred = __task_cred(task->real_parent);
57455 +
57456 + 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);
57457 + }
57458 + break;
57459 + default:
57460 + gr_log_middle(audit, msg, ap);
57461 + }
57462 + va_end(ap);
57463 + // these don't need DEFAULTSECARGS printed on the end
57464 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57465 + gr_log_end(audit, 0);
57466 + else
57467 + gr_log_end(audit, 1);
57468 + END_LOCKS(audit);
57469 +}
57470 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57471 new file mode 100644
57472 index 0000000..f536303
57473 --- /dev/null
57474 +++ b/grsecurity/grsec_mem.c
57475 @@ -0,0 +1,40 @@
57476 +#include <linux/kernel.h>
57477 +#include <linux/sched.h>
57478 +#include <linux/mm.h>
57479 +#include <linux/mman.h>
57480 +#include <linux/grinternal.h>
57481 +
57482 +void
57483 +gr_handle_ioperm(void)
57484 +{
57485 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57486 + return;
57487 +}
57488 +
57489 +void
57490 +gr_handle_iopl(void)
57491 +{
57492 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57493 + return;
57494 +}
57495 +
57496 +void
57497 +gr_handle_mem_readwrite(u64 from, u64 to)
57498 +{
57499 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57500 + return;
57501 +}
57502 +
57503 +void
57504 +gr_handle_vm86(void)
57505 +{
57506 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57507 + return;
57508 +}
57509 +
57510 +void
57511 +gr_log_badprocpid(const char *entry)
57512 +{
57513 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57514 + return;
57515 +}
57516 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57517 new file mode 100644
57518 index 0000000..2131422
57519 --- /dev/null
57520 +++ b/grsecurity/grsec_mount.c
57521 @@ -0,0 +1,62 @@
57522 +#include <linux/kernel.h>
57523 +#include <linux/sched.h>
57524 +#include <linux/mount.h>
57525 +#include <linux/grsecurity.h>
57526 +#include <linux/grinternal.h>
57527 +
57528 +void
57529 +gr_log_remount(const char *devname, const int retval)
57530 +{
57531 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57532 + if (grsec_enable_mount && (retval >= 0))
57533 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57534 +#endif
57535 + return;
57536 +}
57537 +
57538 +void
57539 +gr_log_unmount(const char *devname, const int retval)
57540 +{
57541 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57542 + if (grsec_enable_mount && (retval >= 0))
57543 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57544 +#endif
57545 + return;
57546 +}
57547 +
57548 +void
57549 +gr_log_mount(const char *from, const char *to, const int retval)
57550 +{
57551 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57552 + if (grsec_enable_mount && (retval >= 0))
57553 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57554 +#endif
57555 + return;
57556 +}
57557 +
57558 +int
57559 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57560 +{
57561 +#ifdef CONFIG_GRKERNSEC_ROFS
57562 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57563 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57564 + return -EPERM;
57565 + } else
57566 + return 0;
57567 +#endif
57568 + return 0;
57569 +}
57570 +
57571 +int
57572 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57573 +{
57574 +#ifdef CONFIG_GRKERNSEC_ROFS
57575 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57576 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57577 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57578 + return -EPERM;
57579 + } else
57580 + return 0;
57581 +#endif
57582 + return 0;
57583 +}
57584 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57585 new file mode 100644
57586 index 0000000..a3b12a0
57587 --- /dev/null
57588 +++ b/grsecurity/grsec_pax.c
57589 @@ -0,0 +1,36 @@
57590 +#include <linux/kernel.h>
57591 +#include <linux/sched.h>
57592 +#include <linux/mm.h>
57593 +#include <linux/file.h>
57594 +#include <linux/grinternal.h>
57595 +#include <linux/grsecurity.h>
57596 +
57597 +void
57598 +gr_log_textrel(struct vm_area_struct * vma)
57599 +{
57600 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57601 + if (grsec_enable_audit_textrel)
57602 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57603 +#endif
57604 + return;
57605 +}
57606 +
57607 +void
57608 +gr_log_rwxmmap(struct file *file)
57609 +{
57610 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57611 + if (grsec_enable_log_rwxmaps)
57612 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57613 +#endif
57614 + return;
57615 +}
57616 +
57617 +void
57618 +gr_log_rwxmprotect(struct file *file)
57619 +{
57620 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57621 + if (grsec_enable_log_rwxmaps)
57622 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57623 +#endif
57624 + return;
57625 +}
57626 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57627 new file mode 100644
57628 index 0000000..f7f29aa
57629 --- /dev/null
57630 +++ b/grsecurity/grsec_ptrace.c
57631 @@ -0,0 +1,30 @@
57632 +#include <linux/kernel.h>
57633 +#include <linux/sched.h>
57634 +#include <linux/grinternal.h>
57635 +#include <linux/security.h>
57636 +
57637 +void
57638 +gr_audit_ptrace(struct task_struct *task)
57639 +{
57640 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57641 + if (grsec_enable_audit_ptrace)
57642 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57643 +#endif
57644 + return;
57645 +}
57646 +
57647 +int
57648 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
57649 +{
57650 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57651 + const struct dentry *dentry = file->f_path.dentry;
57652 + const struct vfsmount *mnt = file->f_path.mnt;
57653 +
57654 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57655 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57656 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57657 + return -EACCES;
57658 + }
57659 +#endif
57660 + return 0;
57661 +}
57662 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57663 new file mode 100644
57664 index 0000000..7a5b2de
57665 --- /dev/null
57666 +++ b/grsecurity/grsec_sig.c
57667 @@ -0,0 +1,207 @@
57668 +#include <linux/kernel.h>
57669 +#include <linux/sched.h>
57670 +#include <linux/delay.h>
57671 +#include <linux/grsecurity.h>
57672 +#include <linux/grinternal.h>
57673 +#include <linux/hardirq.h>
57674 +
57675 +char *signames[] = {
57676 + [SIGSEGV] = "Segmentation fault",
57677 + [SIGILL] = "Illegal instruction",
57678 + [SIGABRT] = "Abort",
57679 + [SIGBUS] = "Invalid alignment/Bus error"
57680 +};
57681 +
57682 +void
57683 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57684 +{
57685 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57686 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57687 + (sig == SIGABRT) || (sig == SIGBUS))) {
57688 + if (t->pid == current->pid) {
57689 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57690 + } else {
57691 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57692 + }
57693 + }
57694 +#endif
57695 + return;
57696 +}
57697 +
57698 +int
57699 +gr_handle_signal(const struct task_struct *p, const int sig)
57700 +{
57701 +#ifdef CONFIG_GRKERNSEC
57702 + /* ignore the 0 signal for protected task checks */
57703 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57704 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57705 + return -EPERM;
57706 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57707 + return -EPERM;
57708 + }
57709 +#endif
57710 + return 0;
57711 +}
57712 +
57713 +#ifdef CONFIG_GRKERNSEC
57714 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57715 +
57716 +int gr_fake_force_sig(int sig, struct task_struct *t)
57717 +{
57718 + unsigned long int flags;
57719 + int ret, blocked, ignored;
57720 + struct k_sigaction *action;
57721 +
57722 + spin_lock_irqsave(&t->sighand->siglock, flags);
57723 + action = &t->sighand->action[sig-1];
57724 + ignored = action->sa.sa_handler == SIG_IGN;
57725 + blocked = sigismember(&t->blocked, sig);
57726 + if (blocked || ignored) {
57727 + action->sa.sa_handler = SIG_DFL;
57728 + if (blocked) {
57729 + sigdelset(&t->blocked, sig);
57730 + recalc_sigpending_and_wake(t);
57731 + }
57732 + }
57733 + if (action->sa.sa_handler == SIG_DFL)
57734 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
57735 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57736 +
57737 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
57738 +
57739 + return ret;
57740 +}
57741 +#endif
57742 +
57743 +#ifdef CONFIG_GRKERNSEC_BRUTE
57744 +#define GR_USER_BAN_TIME (15 * 60)
57745 +
57746 +static int __get_dumpable(unsigned long mm_flags)
57747 +{
57748 + int ret;
57749 +
57750 + ret = mm_flags & MMF_DUMPABLE_MASK;
57751 + return (ret >= 2) ? 2 : ret;
57752 +}
57753 +#endif
57754 +
57755 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57756 +{
57757 +#ifdef CONFIG_GRKERNSEC_BRUTE
57758 + uid_t uid = 0;
57759 +
57760 + if (!grsec_enable_brute)
57761 + return;
57762 +
57763 + rcu_read_lock();
57764 + read_lock(&tasklist_lock);
57765 + read_lock(&grsec_exec_file_lock);
57766 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57767 + p->real_parent->brute = 1;
57768 + else {
57769 + const struct cred *cred = __task_cred(p), *cred2;
57770 + struct task_struct *tsk, *tsk2;
57771 +
57772 + if (!__get_dumpable(mm_flags) && cred->uid) {
57773 + struct user_struct *user;
57774 +
57775 + uid = cred->uid;
57776 +
57777 + /* this is put upon execution past expiration */
57778 + user = find_user(uid);
57779 + if (user == NULL)
57780 + goto unlock;
57781 + user->banned = 1;
57782 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57783 + if (user->ban_expires == ~0UL)
57784 + user->ban_expires--;
57785 +
57786 + do_each_thread(tsk2, tsk) {
57787 + cred2 = __task_cred(tsk);
57788 + if (tsk != p && cred2->uid == uid)
57789 + gr_fake_force_sig(SIGKILL, tsk);
57790 + } while_each_thread(tsk2, tsk);
57791 + }
57792 + }
57793 +unlock:
57794 + read_unlock(&grsec_exec_file_lock);
57795 + read_unlock(&tasklist_lock);
57796 + rcu_read_unlock();
57797 +
57798 + if (uid)
57799 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
57800 +
57801 +#endif
57802 + return;
57803 +}
57804 +
57805 +void gr_handle_brute_check(void)
57806 +{
57807 +#ifdef CONFIG_GRKERNSEC_BRUTE
57808 + if (current->brute)
57809 + msleep(30 * 1000);
57810 +#endif
57811 + return;
57812 +}
57813 +
57814 +void gr_handle_kernel_exploit(void)
57815 +{
57816 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
57817 + const struct cred *cred;
57818 + struct task_struct *tsk, *tsk2;
57819 + struct user_struct *user;
57820 + uid_t uid;
57821 +
57822 + if (in_irq() || in_serving_softirq() || in_nmi())
57823 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
57824 +
57825 + uid = current_uid();
57826 +
57827 + if (uid == 0)
57828 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
57829 + else {
57830 + /* kill all the processes of this user, hold a reference
57831 + to their creds struct, and prevent them from creating
57832 + another process until system reset
57833 + */
57834 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
57835 + /* we intentionally leak this ref */
57836 + user = get_uid(current->cred->user);
57837 + if (user) {
57838 + user->banned = 1;
57839 + user->ban_expires = ~0UL;
57840 + }
57841 +
57842 + read_lock(&tasklist_lock);
57843 + do_each_thread(tsk2, tsk) {
57844 + cred = __task_cred(tsk);
57845 + if (cred->uid == uid)
57846 + gr_fake_force_sig(SIGKILL, tsk);
57847 + } while_each_thread(tsk2, tsk);
57848 + read_unlock(&tasklist_lock);
57849 + }
57850 +#endif
57851 +}
57852 +
57853 +int __gr_process_user_ban(struct user_struct *user)
57854 +{
57855 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57856 + if (unlikely(user->banned)) {
57857 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
57858 + user->banned = 0;
57859 + user->ban_expires = 0;
57860 + free_uid(user);
57861 + } else
57862 + return -EPERM;
57863 + }
57864 +#endif
57865 + return 0;
57866 +}
57867 +
57868 +int gr_process_user_ban(void)
57869 +{
57870 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57871 + return __gr_process_user_ban(current->cred->user);
57872 +#endif
57873 + return 0;
57874 +}
57875 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
57876 new file mode 100644
57877 index 0000000..4030d57
57878 --- /dev/null
57879 +++ b/grsecurity/grsec_sock.c
57880 @@ -0,0 +1,244 @@
57881 +#include <linux/kernel.h>
57882 +#include <linux/module.h>
57883 +#include <linux/sched.h>
57884 +#include <linux/file.h>
57885 +#include <linux/net.h>
57886 +#include <linux/in.h>
57887 +#include <linux/ip.h>
57888 +#include <net/sock.h>
57889 +#include <net/inet_sock.h>
57890 +#include <linux/grsecurity.h>
57891 +#include <linux/grinternal.h>
57892 +#include <linux/gracl.h>
57893 +
57894 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
57895 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
57896 +
57897 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
57898 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
57899 +
57900 +#ifdef CONFIG_UNIX_MODULE
57901 +EXPORT_SYMBOL(gr_acl_handle_unix);
57902 +EXPORT_SYMBOL(gr_acl_handle_mknod);
57903 +EXPORT_SYMBOL(gr_handle_chroot_unix);
57904 +EXPORT_SYMBOL(gr_handle_create);
57905 +#endif
57906 +
57907 +#ifdef CONFIG_GRKERNSEC
57908 +#define gr_conn_table_size 32749
57909 +struct conn_table_entry {
57910 + struct conn_table_entry *next;
57911 + struct signal_struct *sig;
57912 +};
57913 +
57914 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
57915 +DEFINE_SPINLOCK(gr_conn_table_lock);
57916 +
57917 +extern const char * gr_socktype_to_name(unsigned char type);
57918 +extern const char * gr_proto_to_name(unsigned char proto);
57919 +extern const char * gr_sockfamily_to_name(unsigned char family);
57920 +
57921 +static __inline__ int
57922 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
57923 +{
57924 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
57925 +}
57926 +
57927 +static __inline__ int
57928 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
57929 + __u16 sport, __u16 dport)
57930 +{
57931 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
57932 + sig->gr_sport == sport && sig->gr_dport == dport))
57933 + return 1;
57934 + else
57935 + return 0;
57936 +}
57937 +
57938 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
57939 +{
57940 + struct conn_table_entry **match;
57941 + unsigned int index;
57942 +
57943 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57944 + sig->gr_sport, sig->gr_dport,
57945 + gr_conn_table_size);
57946 +
57947 + newent->sig = sig;
57948 +
57949 + match = &gr_conn_table[index];
57950 + newent->next = *match;
57951 + *match = newent;
57952 +
57953 + return;
57954 +}
57955 +
57956 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
57957 +{
57958 + struct conn_table_entry *match, *last = NULL;
57959 + unsigned int index;
57960 +
57961 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57962 + sig->gr_sport, sig->gr_dport,
57963 + gr_conn_table_size);
57964 +
57965 + match = gr_conn_table[index];
57966 + while (match && !conn_match(match->sig,
57967 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
57968 + sig->gr_dport)) {
57969 + last = match;
57970 + match = match->next;
57971 + }
57972 +
57973 + if (match) {
57974 + if (last)
57975 + last->next = match->next;
57976 + else
57977 + gr_conn_table[index] = NULL;
57978 + kfree(match);
57979 + }
57980 +
57981 + return;
57982 +}
57983 +
57984 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
57985 + __u16 sport, __u16 dport)
57986 +{
57987 + struct conn_table_entry *match;
57988 + unsigned int index;
57989 +
57990 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
57991 +
57992 + match = gr_conn_table[index];
57993 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
57994 + match = match->next;
57995 +
57996 + if (match)
57997 + return match->sig;
57998 + else
57999 + return NULL;
58000 +}
58001 +
58002 +#endif
58003 +
58004 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58005 +{
58006 +#ifdef CONFIG_GRKERNSEC
58007 + struct signal_struct *sig = task->signal;
58008 + struct conn_table_entry *newent;
58009 +
58010 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58011 + if (newent == NULL)
58012 + return;
58013 + /* no bh lock needed since we are called with bh disabled */
58014 + spin_lock(&gr_conn_table_lock);
58015 + gr_del_task_from_ip_table_nolock(sig);
58016 + sig->gr_saddr = inet->inet_rcv_saddr;
58017 + sig->gr_daddr = inet->inet_daddr;
58018 + sig->gr_sport = inet->inet_sport;
58019 + sig->gr_dport = inet->inet_dport;
58020 + gr_add_to_task_ip_table_nolock(sig, newent);
58021 + spin_unlock(&gr_conn_table_lock);
58022 +#endif
58023 + return;
58024 +}
58025 +
58026 +void gr_del_task_from_ip_table(struct task_struct *task)
58027 +{
58028 +#ifdef CONFIG_GRKERNSEC
58029 + spin_lock_bh(&gr_conn_table_lock);
58030 + gr_del_task_from_ip_table_nolock(task->signal);
58031 + spin_unlock_bh(&gr_conn_table_lock);
58032 +#endif
58033 + return;
58034 +}
58035 +
58036 +void
58037 +gr_attach_curr_ip(const struct sock *sk)
58038 +{
58039 +#ifdef CONFIG_GRKERNSEC
58040 + struct signal_struct *p, *set;
58041 + const struct inet_sock *inet = inet_sk(sk);
58042 +
58043 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58044 + return;
58045 +
58046 + set = current->signal;
58047 +
58048 + spin_lock_bh(&gr_conn_table_lock);
58049 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58050 + inet->inet_dport, inet->inet_sport);
58051 + if (unlikely(p != NULL)) {
58052 + set->curr_ip = p->curr_ip;
58053 + set->used_accept = 1;
58054 + gr_del_task_from_ip_table_nolock(p);
58055 + spin_unlock_bh(&gr_conn_table_lock);
58056 + return;
58057 + }
58058 + spin_unlock_bh(&gr_conn_table_lock);
58059 +
58060 + set->curr_ip = inet->inet_daddr;
58061 + set->used_accept = 1;
58062 +#endif
58063 + return;
58064 +}
58065 +
58066 +int
58067 +gr_handle_sock_all(const int family, const int type, const int protocol)
58068 +{
58069 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58070 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58071 + (family != AF_UNIX)) {
58072 + if (family == AF_INET)
58073 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58074 + else
58075 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58076 + return -EACCES;
58077 + }
58078 +#endif
58079 + return 0;
58080 +}
58081 +
58082 +int
58083 +gr_handle_sock_server(const struct sockaddr *sck)
58084 +{
58085 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58086 + if (grsec_enable_socket_server &&
58087 + in_group_p(grsec_socket_server_gid) &&
58088 + sck && (sck->sa_family != AF_UNIX) &&
58089 + (sck->sa_family != AF_LOCAL)) {
58090 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58091 + return -EACCES;
58092 + }
58093 +#endif
58094 + return 0;
58095 +}
58096 +
58097 +int
58098 +gr_handle_sock_server_other(const struct sock *sck)
58099 +{
58100 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58101 + if (grsec_enable_socket_server &&
58102 + in_group_p(grsec_socket_server_gid) &&
58103 + sck && (sck->sk_family != AF_UNIX) &&
58104 + (sck->sk_family != AF_LOCAL)) {
58105 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58106 + return -EACCES;
58107 + }
58108 +#endif
58109 + return 0;
58110 +}
58111 +
58112 +int
58113 +gr_handle_sock_client(const struct sockaddr *sck)
58114 +{
58115 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58116 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58117 + sck && (sck->sa_family != AF_UNIX) &&
58118 + (sck->sa_family != AF_LOCAL)) {
58119 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58120 + return -EACCES;
58121 + }
58122 +#endif
58123 + return 0;
58124 +}
58125 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58126 new file mode 100644
58127 index 0000000..a1aedd7
58128 --- /dev/null
58129 +++ b/grsecurity/grsec_sysctl.c
58130 @@ -0,0 +1,451 @@
58131 +#include <linux/kernel.h>
58132 +#include <linux/sched.h>
58133 +#include <linux/sysctl.h>
58134 +#include <linux/grsecurity.h>
58135 +#include <linux/grinternal.h>
58136 +
58137 +int
58138 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58139 +{
58140 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58141 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58142 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58143 + return -EACCES;
58144 + }
58145 +#endif
58146 + return 0;
58147 +}
58148 +
58149 +#ifdef CONFIG_GRKERNSEC_ROFS
58150 +static int __maybe_unused one = 1;
58151 +#endif
58152 +
58153 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58154 +struct ctl_table grsecurity_table[] = {
58155 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58156 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58157 +#ifdef CONFIG_GRKERNSEC_IO
58158 + {
58159 + .procname = "disable_priv_io",
58160 + .data = &grsec_disable_privio,
58161 + .maxlen = sizeof(int),
58162 + .mode = 0600,
58163 + .proc_handler = &proc_dointvec,
58164 + },
58165 +#endif
58166 +#endif
58167 +#ifdef CONFIG_GRKERNSEC_LINK
58168 + {
58169 + .procname = "linking_restrictions",
58170 + .data = &grsec_enable_link,
58171 + .maxlen = sizeof(int),
58172 + .mode = 0600,
58173 + .proc_handler = &proc_dointvec,
58174 + },
58175 +#endif
58176 +#ifdef CONFIG_GRKERNSEC_BRUTE
58177 + {
58178 + .procname = "deter_bruteforce",
58179 + .data = &grsec_enable_brute,
58180 + .maxlen = sizeof(int),
58181 + .mode = 0600,
58182 + .proc_handler = &proc_dointvec,
58183 + },
58184 +#endif
58185 +#ifdef CONFIG_GRKERNSEC_FIFO
58186 + {
58187 + .procname = "fifo_restrictions",
58188 + .data = &grsec_enable_fifo,
58189 + .maxlen = sizeof(int),
58190 + .mode = 0600,
58191 + .proc_handler = &proc_dointvec,
58192 + },
58193 +#endif
58194 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58195 + {
58196 + .procname = "ptrace_readexec",
58197 + .data = &grsec_enable_ptrace_readexec,
58198 + .maxlen = sizeof(int),
58199 + .mode = 0600,
58200 + .proc_handler = &proc_dointvec,
58201 + },
58202 +#endif
58203 +#ifdef CONFIG_GRKERNSEC_SETXID
58204 + {
58205 + .procname = "consistent_setxid",
58206 + .data = &grsec_enable_setxid,
58207 + .maxlen = sizeof(int),
58208 + .mode = 0600,
58209 + .proc_handler = &proc_dointvec,
58210 + },
58211 +#endif
58212 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58213 + {
58214 + .procname = "ip_blackhole",
58215 + .data = &grsec_enable_blackhole,
58216 + .maxlen = sizeof(int),
58217 + .mode = 0600,
58218 + .proc_handler = &proc_dointvec,
58219 + },
58220 + {
58221 + .procname = "lastack_retries",
58222 + .data = &grsec_lastack_retries,
58223 + .maxlen = sizeof(int),
58224 + .mode = 0600,
58225 + .proc_handler = &proc_dointvec,
58226 + },
58227 +#endif
58228 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58229 + {
58230 + .procname = "exec_logging",
58231 + .data = &grsec_enable_execlog,
58232 + .maxlen = sizeof(int),
58233 + .mode = 0600,
58234 + .proc_handler = &proc_dointvec,
58235 + },
58236 +#endif
58237 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58238 + {
58239 + .procname = "rwxmap_logging",
58240 + .data = &grsec_enable_log_rwxmaps,
58241 + .maxlen = sizeof(int),
58242 + .mode = 0600,
58243 + .proc_handler = &proc_dointvec,
58244 + },
58245 +#endif
58246 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58247 + {
58248 + .procname = "signal_logging",
58249 + .data = &grsec_enable_signal,
58250 + .maxlen = sizeof(int),
58251 + .mode = 0600,
58252 + .proc_handler = &proc_dointvec,
58253 + },
58254 +#endif
58255 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58256 + {
58257 + .procname = "forkfail_logging",
58258 + .data = &grsec_enable_forkfail,
58259 + .maxlen = sizeof(int),
58260 + .mode = 0600,
58261 + .proc_handler = &proc_dointvec,
58262 + },
58263 +#endif
58264 +#ifdef CONFIG_GRKERNSEC_TIME
58265 + {
58266 + .procname = "timechange_logging",
58267 + .data = &grsec_enable_time,
58268 + .maxlen = sizeof(int),
58269 + .mode = 0600,
58270 + .proc_handler = &proc_dointvec,
58271 + },
58272 +#endif
58273 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58274 + {
58275 + .procname = "chroot_deny_shmat",
58276 + .data = &grsec_enable_chroot_shmat,
58277 + .maxlen = sizeof(int),
58278 + .mode = 0600,
58279 + .proc_handler = &proc_dointvec,
58280 + },
58281 +#endif
58282 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58283 + {
58284 + .procname = "chroot_deny_unix",
58285 + .data = &grsec_enable_chroot_unix,
58286 + .maxlen = sizeof(int),
58287 + .mode = 0600,
58288 + .proc_handler = &proc_dointvec,
58289 + },
58290 +#endif
58291 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58292 + {
58293 + .procname = "chroot_deny_mount",
58294 + .data = &grsec_enable_chroot_mount,
58295 + .maxlen = sizeof(int),
58296 + .mode = 0600,
58297 + .proc_handler = &proc_dointvec,
58298 + },
58299 +#endif
58300 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58301 + {
58302 + .procname = "chroot_deny_fchdir",
58303 + .data = &grsec_enable_chroot_fchdir,
58304 + .maxlen = sizeof(int),
58305 + .mode = 0600,
58306 + .proc_handler = &proc_dointvec,
58307 + },
58308 +#endif
58309 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58310 + {
58311 + .procname = "chroot_deny_chroot",
58312 + .data = &grsec_enable_chroot_double,
58313 + .maxlen = sizeof(int),
58314 + .mode = 0600,
58315 + .proc_handler = &proc_dointvec,
58316 + },
58317 +#endif
58318 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58319 + {
58320 + .procname = "chroot_deny_pivot",
58321 + .data = &grsec_enable_chroot_pivot,
58322 + .maxlen = sizeof(int),
58323 + .mode = 0600,
58324 + .proc_handler = &proc_dointvec,
58325 + },
58326 +#endif
58327 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58328 + {
58329 + .procname = "chroot_enforce_chdir",
58330 + .data = &grsec_enable_chroot_chdir,
58331 + .maxlen = sizeof(int),
58332 + .mode = 0600,
58333 + .proc_handler = &proc_dointvec,
58334 + },
58335 +#endif
58336 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58337 + {
58338 + .procname = "chroot_deny_chmod",
58339 + .data = &grsec_enable_chroot_chmod,
58340 + .maxlen = sizeof(int),
58341 + .mode = 0600,
58342 + .proc_handler = &proc_dointvec,
58343 + },
58344 +#endif
58345 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58346 + {
58347 + .procname = "chroot_deny_mknod",
58348 + .data = &grsec_enable_chroot_mknod,
58349 + .maxlen = sizeof(int),
58350 + .mode = 0600,
58351 + .proc_handler = &proc_dointvec,
58352 + },
58353 +#endif
58354 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58355 + {
58356 + .procname = "chroot_restrict_nice",
58357 + .data = &grsec_enable_chroot_nice,
58358 + .maxlen = sizeof(int),
58359 + .mode = 0600,
58360 + .proc_handler = &proc_dointvec,
58361 + },
58362 +#endif
58363 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58364 + {
58365 + .procname = "chroot_execlog",
58366 + .data = &grsec_enable_chroot_execlog,
58367 + .maxlen = sizeof(int),
58368 + .mode = 0600,
58369 + .proc_handler = &proc_dointvec,
58370 + },
58371 +#endif
58372 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58373 + {
58374 + .procname = "chroot_caps",
58375 + .data = &grsec_enable_chroot_caps,
58376 + .maxlen = sizeof(int),
58377 + .mode = 0600,
58378 + .proc_handler = &proc_dointvec,
58379 + },
58380 +#endif
58381 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58382 + {
58383 + .procname = "chroot_deny_sysctl",
58384 + .data = &grsec_enable_chroot_sysctl,
58385 + .maxlen = sizeof(int),
58386 + .mode = 0600,
58387 + .proc_handler = &proc_dointvec,
58388 + },
58389 +#endif
58390 +#ifdef CONFIG_GRKERNSEC_TPE
58391 + {
58392 + .procname = "tpe",
58393 + .data = &grsec_enable_tpe,
58394 + .maxlen = sizeof(int),
58395 + .mode = 0600,
58396 + .proc_handler = &proc_dointvec,
58397 + },
58398 + {
58399 + .procname = "tpe_gid",
58400 + .data = &grsec_tpe_gid,
58401 + .maxlen = sizeof(int),
58402 + .mode = 0600,
58403 + .proc_handler = &proc_dointvec,
58404 + },
58405 +#endif
58406 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58407 + {
58408 + .procname = "tpe_invert",
58409 + .data = &grsec_enable_tpe_invert,
58410 + .maxlen = sizeof(int),
58411 + .mode = 0600,
58412 + .proc_handler = &proc_dointvec,
58413 + },
58414 +#endif
58415 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58416 + {
58417 + .procname = "tpe_restrict_all",
58418 + .data = &grsec_enable_tpe_all,
58419 + .maxlen = sizeof(int),
58420 + .mode = 0600,
58421 + .proc_handler = &proc_dointvec,
58422 + },
58423 +#endif
58424 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58425 + {
58426 + .procname = "socket_all",
58427 + .data = &grsec_enable_socket_all,
58428 + .maxlen = sizeof(int),
58429 + .mode = 0600,
58430 + .proc_handler = &proc_dointvec,
58431 + },
58432 + {
58433 + .procname = "socket_all_gid",
58434 + .data = &grsec_socket_all_gid,
58435 + .maxlen = sizeof(int),
58436 + .mode = 0600,
58437 + .proc_handler = &proc_dointvec,
58438 + },
58439 +#endif
58440 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58441 + {
58442 + .procname = "socket_client",
58443 + .data = &grsec_enable_socket_client,
58444 + .maxlen = sizeof(int),
58445 + .mode = 0600,
58446 + .proc_handler = &proc_dointvec,
58447 + },
58448 + {
58449 + .procname = "socket_client_gid",
58450 + .data = &grsec_socket_client_gid,
58451 + .maxlen = sizeof(int),
58452 + .mode = 0600,
58453 + .proc_handler = &proc_dointvec,
58454 + },
58455 +#endif
58456 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58457 + {
58458 + .procname = "socket_server",
58459 + .data = &grsec_enable_socket_server,
58460 + .maxlen = sizeof(int),
58461 + .mode = 0600,
58462 + .proc_handler = &proc_dointvec,
58463 + },
58464 + {
58465 + .procname = "socket_server_gid",
58466 + .data = &grsec_socket_server_gid,
58467 + .maxlen = sizeof(int),
58468 + .mode = 0600,
58469 + .proc_handler = &proc_dointvec,
58470 + },
58471 +#endif
58472 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58473 + {
58474 + .procname = "audit_group",
58475 + .data = &grsec_enable_group,
58476 + .maxlen = sizeof(int),
58477 + .mode = 0600,
58478 + .proc_handler = &proc_dointvec,
58479 + },
58480 + {
58481 + .procname = "audit_gid",
58482 + .data = &grsec_audit_gid,
58483 + .maxlen = sizeof(int),
58484 + .mode = 0600,
58485 + .proc_handler = &proc_dointvec,
58486 + },
58487 +#endif
58488 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58489 + {
58490 + .procname = "audit_chdir",
58491 + .data = &grsec_enable_chdir,
58492 + .maxlen = sizeof(int),
58493 + .mode = 0600,
58494 + .proc_handler = &proc_dointvec,
58495 + },
58496 +#endif
58497 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58498 + {
58499 + .procname = "audit_mount",
58500 + .data = &grsec_enable_mount,
58501 + .maxlen = sizeof(int),
58502 + .mode = 0600,
58503 + .proc_handler = &proc_dointvec,
58504 + },
58505 +#endif
58506 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58507 + {
58508 + .procname = "audit_textrel",
58509 + .data = &grsec_enable_audit_textrel,
58510 + .maxlen = sizeof(int),
58511 + .mode = 0600,
58512 + .proc_handler = &proc_dointvec,
58513 + },
58514 +#endif
58515 +#ifdef CONFIG_GRKERNSEC_DMESG
58516 + {
58517 + .procname = "dmesg",
58518 + .data = &grsec_enable_dmesg,
58519 + .maxlen = sizeof(int),
58520 + .mode = 0600,
58521 + .proc_handler = &proc_dointvec,
58522 + },
58523 +#endif
58524 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58525 + {
58526 + .procname = "chroot_findtask",
58527 + .data = &grsec_enable_chroot_findtask,
58528 + .maxlen = sizeof(int),
58529 + .mode = 0600,
58530 + .proc_handler = &proc_dointvec,
58531 + },
58532 +#endif
58533 +#ifdef CONFIG_GRKERNSEC_RESLOG
58534 + {
58535 + .procname = "resource_logging",
58536 + .data = &grsec_resource_logging,
58537 + .maxlen = sizeof(int),
58538 + .mode = 0600,
58539 + .proc_handler = &proc_dointvec,
58540 + },
58541 +#endif
58542 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58543 + {
58544 + .procname = "audit_ptrace",
58545 + .data = &grsec_enable_audit_ptrace,
58546 + .maxlen = sizeof(int),
58547 + .mode = 0600,
58548 + .proc_handler = &proc_dointvec,
58549 + },
58550 +#endif
58551 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58552 + {
58553 + .procname = "harden_ptrace",
58554 + .data = &grsec_enable_harden_ptrace,
58555 + .maxlen = sizeof(int),
58556 + .mode = 0600,
58557 + .proc_handler = &proc_dointvec,
58558 + },
58559 +#endif
58560 + {
58561 + .procname = "grsec_lock",
58562 + .data = &grsec_lock,
58563 + .maxlen = sizeof(int),
58564 + .mode = 0600,
58565 + .proc_handler = &proc_dointvec,
58566 + },
58567 +#endif
58568 +#ifdef CONFIG_GRKERNSEC_ROFS
58569 + {
58570 + .procname = "romount_protect",
58571 + .data = &grsec_enable_rofs,
58572 + .maxlen = sizeof(int),
58573 + .mode = 0600,
58574 + .proc_handler = &proc_dointvec_minmax,
58575 + .extra1 = &one,
58576 + .extra2 = &one,
58577 + },
58578 +#endif
58579 + { }
58580 +};
58581 +#endif
58582 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58583 new file mode 100644
58584 index 0000000..0dc13c3
58585 --- /dev/null
58586 +++ b/grsecurity/grsec_time.c
58587 @@ -0,0 +1,16 @@
58588 +#include <linux/kernel.h>
58589 +#include <linux/sched.h>
58590 +#include <linux/grinternal.h>
58591 +#include <linux/module.h>
58592 +
58593 +void
58594 +gr_log_timechange(void)
58595 +{
58596 +#ifdef CONFIG_GRKERNSEC_TIME
58597 + if (grsec_enable_time)
58598 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58599 +#endif
58600 + return;
58601 +}
58602 +
58603 +EXPORT_SYMBOL(gr_log_timechange);
58604 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58605 new file mode 100644
58606 index 0000000..07e0dc0
58607 --- /dev/null
58608 +++ b/grsecurity/grsec_tpe.c
58609 @@ -0,0 +1,73 @@
58610 +#include <linux/kernel.h>
58611 +#include <linux/sched.h>
58612 +#include <linux/file.h>
58613 +#include <linux/fs.h>
58614 +#include <linux/grinternal.h>
58615 +
58616 +extern int gr_acl_tpe_check(void);
58617 +
58618 +int
58619 +gr_tpe_allow(const struct file *file)
58620 +{
58621 +#ifdef CONFIG_GRKERNSEC
58622 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58623 + const struct cred *cred = current_cred();
58624 + char *msg = NULL;
58625 + char *msg2 = NULL;
58626 +
58627 + // never restrict root
58628 + if (!cred->uid)
58629 + return 1;
58630 +
58631 + if (grsec_enable_tpe) {
58632 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58633 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58634 + msg = "not being in trusted group";
58635 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58636 + msg = "being in untrusted group";
58637 +#else
58638 + if (in_group_p(grsec_tpe_gid))
58639 + msg = "being in untrusted group";
58640 +#endif
58641 + }
58642 + if (!msg && gr_acl_tpe_check())
58643 + msg = "being in untrusted role";
58644 +
58645 + // not in any affected group/role
58646 + if (!msg)
58647 + goto next_check;
58648 +
58649 + if (inode->i_uid)
58650 + msg2 = "file in non-root-owned directory";
58651 + else if (inode->i_mode & S_IWOTH)
58652 + msg2 = "file in world-writable directory";
58653 + else if (inode->i_mode & S_IWGRP)
58654 + msg2 = "file in group-writable directory";
58655 +
58656 + if (msg && msg2) {
58657 + char fullmsg[70] = {0};
58658 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58659 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58660 + return 0;
58661 + }
58662 + msg = NULL;
58663 +next_check:
58664 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58665 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58666 + return 1;
58667 +
58668 + if (inode->i_uid && (inode->i_uid != cred->uid))
58669 + msg = "directory not owned by user";
58670 + else if (inode->i_mode & S_IWOTH)
58671 + msg = "file in world-writable directory";
58672 + else if (inode->i_mode & S_IWGRP)
58673 + msg = "file in group-writable directory";
58674 +
58675 + if (msg) {
58676 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58677 + return 0;
58678 + }
58679 +#endif
58680 +#endif
58681 + return 1;
58682 +}
58683 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58684 new file mode 100644
58685 index 0000000..9f7b1ac
58686 --- /dev/null
58687 +++ b/grsecurity/grsum.c
58688 @@ -0,0 +1,61 @@
58689 +#include <linux/err.h>
58690 +#include <linux/kernel.h>
58691 +#include <linux/sched.h>
58692 +#include <linux/mm.h>
58693 +#include <linux/scatterlist.h>
58694 +#include <linux/crypto.h>
58695 +#include <linux/gracl.h>
58696 +
58697 +
58698 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58699 +#error "crypto and sha256 must be built into the kernel"
58700 +#endif
58701 +
58702 +int
58703 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58704 +{
58705 + char *p;
58706 + struct crypto_hash *tfm;
58707 + struct hash_desc desc;
58708 + struct scatterlist sg;
58709 + unsigned char temp_sum[GR_SHA_LEN];
58710 + volatile int retval = 0;
58711 + volatile int dummy = 0;
58712 + unsigned int i;
58713 +
58714 + sg_init_table(&sg, 1);
58715 +
58716 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58717 + if (IS_ERR(tfm)) {
58718 + /* should never happen, since sha256 should be built in */
58719 + return 1;
58720 + }
58721 +
58722 + desc.tfm = tfm;
58723 + desc.flags = 0;
58724 +
58725 + crypto_hash_init(&desc);
58726 +
58727 + p = salt;
58728 + sg_set_buf(&sg, p, GR_SALT_LEN);
58729 + crypto_hash_update(&desc, &sg, sg.length);
58730 +
58731 + p = entry->pw;
58732 + sg_set_buf(&sg, p, strlen(p));
58733 +
58734 + crypto_hash_update(&desc, &sg, sg.length);
58735 +
58736 + crypto_hash_final(&desc, temp_sum);
58737 +
58738 + memset(entry->pw, 0, GR_PW_LEN);
58739 +
58740 + for (i = 0; i < GR_SHA_LEN; i++)
58741 + if (sum[i] != temp_sum[i])
58742 + retval = 1;
58743 + else
58744 + dummy = 1; // waste a cycle
58745 +
58746 + crypto_free_hash(tfm);
58747 +
58748 + return retval;
58749 +}
58750 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58751 index 6cd5b64..f620d2d 100644
58752 --- a/include/acpi/acpi_bus.h
58753 +++ b/include/acpi/acpi_bus.h
58754 @@ -107,7 +107,7 @@ struct acpi_device_ops {
58755 acpi_op_bind bind;
58756 acpi_op_unbind unbind;
58757 acpi_op_notify notify;
58758 -};
58759 +} __no_const;
58760
58761 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58762
58763 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58764 index b7babf0..71e4e74 100644
58765 --- a/include/asm-generic/atomic-long.h
58766 +++ b/include/asm-generic/atomic-long.h
58767 @@ -22,6 +22,12 @@
58768
58769 typedef atomic64_t atomic_long_t;
58770
58771 +#ifdef CONFIG_PAX_REFCOUNT
58772 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
58773 +#else
58774 +typedef atomic64_t atomic_long_unchecked_t;
58775 +#endif
58776 +
58777 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58778
58779 static inline long atomic_long_read(atomic_long_t *l)
58780 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58781 return (long)atomic64_read(v);
58782 }
58783
58784 +#ifdef CONFIG_PAX_REFCOUNT
58785 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58786 +{
58787 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58788 +
58789 + return (long)atomic64_read_unchecked(v);
58790 +}
58791 +#endif
58792 +
58793 static inline void atomic_long_set(atomic_long_t *l, long i)
58794 {
58795 atomic64_t *v = (atomic64_t *)l;
58796 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58797 atomic64_set(v, i);
58798 }
58799
58800 +#ifdef CONFIG_PAX_REFCOUNT
58801 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58802 +{
58803 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58804 +
58805 + atomic64_set_unchecked(v, i);
58806 +}
58807 +#endif
58808 +
58809 static inline void atomic_long_inc(atomic_long_t *l)
58810 {
58811 atomic64_t *v = (atomic64_t *)l;
58812 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58813 atomic64_inc(v);
58814 }
58815
58816 +#ifdef CONFIG_PAX_REFCOUNT
58817 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58818 +{
58819 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58820 +
58821 + atomic64_inc_unchecked(v);
58822 +}
58823 +#endif
58824 +
58825 static inline void atomic_long_dec(atomic_long_t *l)
58826 {
58827 atomic64_t *v = (atomic64_t *)l;
58828 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58829 atomic64_dec(v);
58830 }
58831
58832 +#ifdef CONFIG_PAX_REFCOUNT
58833 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58834 +{
58835 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58836 +
58837 + atomic64_dec_unchecked(v);
58838 +}
58839 +#endif
58840 +
58841 static inline void atomic_long_add(long i, atomic_long_t *l)
58842 {
58843 atomic64_t *v = (atomic64_t *)l;
58844 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58845 atomic64_add(i, v);
58846 }
58847
58848 +#ifdef CONFIG_PAX_REFCOUNT
58849 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58850 +{
58851 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58852 +
58853 + atomic64_add_unchecked(i, v);
58854 +}
58855 +#endif
58856 +
58857 static inline void atomic_long_sub(long i, atomic_long_t *l)
58858 {
58859 atomic64_t *v = (atomic64_t *)l;
58860 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58861 atomic64_sub(i, v);
58862 }
58863
58864 +#ifdef CONFIG_PAX_REFCOUNT
58865 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58866 +{
58867 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58868 +
58869 + atomic64_sub_unchecked(i, v);
58870 +}
58871 +#endif
58872 +
58873 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58874 {
58875 atomic64_t *v = (atomic64_t *)l;
58876 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
58877 return (long)atomic64_inc_return(v);
58878 }
58879
58880 +#ifdef CONFIG_PAX_REFCOUNT
58881 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
58882 +{
58883 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58884 +
58885 + return (long)atomic64_inc_return_unchecked(v);
58886 +}
58887 +#endif
58888 +
58889 static inline long atomic_long_dec_return(atomic_long_t *l)
58890 {
58891 atomic64_t *v = (atomic64_t *)l;
58892 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
58893
58894 typedef atomic_t atomic_long_t;
58895
58896 +#ifdef CONFIG_PAX_REFCOUNT
58897 +typedef atomic_unchecked_t atomic_long_unchecked_t;
58898 +#else
58899 +typedef atomic_t atomic_long_unchecked_t;
58900 +#endif
58901 +
58902 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
58903 static inline long atomic_long_read(atomic_long_t *l)
58904 {
58905 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58906 return (long)atomic_read(v);
58907 }
58908
58909 +#ifdef CONFIG_PAX_REFCOUNT
58910 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58911 +{
58912 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58913 +
58914 + return (long)atomic_read_unchecked(v);
58915 +}
58916 +#endif
58917 +
58918 static inline void atomic_long_set(atomic_long_t *l, long i)
58919 {
58920 atomic_t *v = (atomic_t *)l;
58921 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58922 atomic_set(v, i);
58923 }
58924
58925 +#ifdef CONFIG_PAX_REFCOUNT
58926 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58927 +{
58928 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58929 +
58930 + atomic_set_unchecked(v, i);
58931 +}
58932 +#endif
58933 +
58934 static inline void atomic_long_inc(atomic_long_t *l)
58935 {
58936 atomic_t *v = (atomic_t *)l;
58937 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58938 atomic_inc(v);
58939 }
58940
58941 +#ifdef CONFIG_PAX_REFCOUNT
58942 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58943 +{
58944 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58945 +
58946 + atomic_inc_unchecked(v);
58947 +}
58948 +#endif
58949 +
58950 static inline void atomic_long_dec(atomic_long_t *l)
58951 {
58952 atomic_t *v = (atomic_t *)l;
58953 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58954 atomic_dec(v);
58955 }
58956
58957 +#ifdef CONFIG_PAX_REFCOUNT
58958 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58959 +{
58960 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58961 +
58962 + atomic_dec_unchecked(v);
58963 +}
58964 +#endif
58965 +
58966 static inline void atomic_long_add(long i, atomic_long_t *l)
58967 {
58968 atomic_t *v = (atomic_t *)l;
58969 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58970 atomic_add(i, v);
58971 }
58972
58973 +#ifdef CONFIG_PAX_REFCOUNT
58974 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58975 +{
58976 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58977 +
58978 + atomic_add_unchecked(i, v);
58979 +}
58980 +#endif
58981 +
58982 static inline void atomic_long_sub(long i, atomic_long_t *l)
58983 {
58984 atomic_t *v = (atomic_t *)l;
58985 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58986 atomic_sub(i, v);
58987 }
58988
58989 +#ifdef CONFIG_PAX_REFCOUNT
58990 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58991 +{
58992 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58993 +
58994 + atomic_sub_unchecked(i, v);
58995 +}
58996 +#endif
58997 +
58998 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58999 {
59000 atomic_t *v = (atomic_t *)l;
59001 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59002 return (long)atomic_inc_return(v);
59003 }
59004
59005 +#ifdef CONFIG_PAX_REFCOUNT
59006 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59007 +{
59008 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59009 +
59010 + return (long)atomic_inc_return_unchecked(v);
59011 +}
59012 +#endif
59013 +
59014 static inline long atomic_long_dec_return(atomic_long_t *l)
59015 {
59016 atomic_t *v = (atomic_t *)l;
59017 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59018
59019 #endif /* BITS_PER_LONG == 64 */
59020
59021 +#ifdef CONFIG_PAX_REFCOUNT
59022 +static inline void pax_refcount_needs_these_functions(void)
59023 +{
59024 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59025 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59026 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59027 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59028 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59029 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59030 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59031 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59032 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59033 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59034 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59035 +
59036 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59037 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59038 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59039 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59040 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59041 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59042 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59043 +}
59044 +#else
59045 +#define atomic_read_unchecked(v) atomic_read(v)
59046 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59047 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59048 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59049 +#define atomic_inc_unchecked(v) atomic_inc(v)
59050 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59051 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59052 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59053 +#define atomic_dec_unchecked(v) atomic_dec(v)
59054 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59055 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59056 +
59057 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59058 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59059 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59060 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59061 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59062 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59063 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59064 +#endif
59065 +
59066 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59067 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59068 index b18ce4f..2ee2843 100644
59069 --- a/include/asm-generic/atomic64.h
59070 +++ b/include/asm-generic/atomic64.h
59071 @@ -16,6 +16,8 @@ typedef struct {
59072 long long counter;
59073 } atomic64_t;
59074
59075 +typedef atomic64_t atomic64_unchecked_t;
59076 +
59077 #define ATOMIC64_INIT(i) { (i) }
59078
59079 extern long long atomic64_read(const atomic64_t *v);
59080 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59081 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59082 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59083
59084 +#define atomic64_read_unchecked(v) atomic64_read(v)
59085 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59086 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59087 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59088 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59089 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59090 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59091 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59092 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59093 +
59094 #endif /* _ASM_GENERIC_ATOMIC64_H */
59095 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59096 index 1bfcfe5..e04c5c9 100644
59097 --- a/include/asm-generic/cache.h
59098 +++ b/include/asm-generic/cache.h
59099 @@ -6,7 +6,7 @@
59100 * cache lines need to provide their own cache.h.
59101 */
59102
59103 -#define L1_CACHE_SHIFT 5
59104 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59105 +#define L1_CACHE_SHIFT 5UL
59106 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59107
59108 #endif /* __ASM_GENERIC_CACHE_H */
59109 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59110 index 0d68a1e..b74a761 100644
59111 --- a/include/asm-generic/emergency-restart.h
59112 +++ b/include/asm-generic/emergency-restart.h
59113 @@ -1,7 +1,7 @@
59114 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59115 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59116
59117 -static inline void machine_emergency_restart(void)
59118 +static inline __noreturn void machine_emergency_restart(void)
59119 {
59120 machine_restart(NULL);
59121 }
59122 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
59123 index 1ca3efc..e3dc852 100644
59124 --- a/include/asm-generic/int-l64.h
59125 +++ b/include/asm-generic/int-l64.h
59126 @@ -46,6 +46,8 @@ typedef unsigned int u32;
59127 typedef signed long s64;
59128 typedef unsigned long u64;
59129
59130 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
59131 +
59132 #define S8_C(x) x
59133 #define U8_C(x) x ## U
59134 #define S16_C(x) x
59135 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
59136 index f394147..b6152b9 100644
59137 --- a/include/asm-generic/int-ll64.h
59138 +++ b/include/asm-generic/int-ll64.h
59139 @@ -51,6 +51,8 @@ typedef unsigned int u32;
59140 typedef signed long long s64;
59141 typedef unsigned long long u64;
59142
59143 +typedef unsigned long long intoverflow_t;
59144 +
59145 #define S8_C(x) x
59146 #define U8_C(x) x ## U
59147 #define S16_C(x) x
59148 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59149 index 0232ccb..13d9165 100644
59150 --- a/include/asm-generic/kmap_types.h
59151 +++ b/include/asm-generic/kmap_types.h
59152 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59153 KMAP_D(17) KM_NMI,
59154 KMAP_D(18) KM_NMI_PTE,
59155 KMAP_D(19) KM_KDB,
59156 +KMAP_D(20) KM_CLEARPAGE,
59157 /*
59158 * Remember to update debug_kmap_atomic() when adding new kmap types!
59159 */
59160 -KMAP_D(20) KM_TYPE_NR
59161 +KMAP_D(21) KM_TYPE_NR
59162 };
59163
59164 #undef KMAP_D
59165 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59166 index 9ceb03b..2efbcbd 100644
59167 --- a/include/asm-generic/local.h
59168 +++ b/include/asm-generic/local.h
59169 @@ -39,6 +39,7 @@ typedef struct
59170 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59171 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59172 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59173 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59174
59175 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59176 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59177 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59178 index 725612b..9cc513a 100644
59179 --- a/include/asm-generic/pgtable-nopmd.h
59180 +++ b/include/asm-generic/pgtable-nopmd.h
59181 @@ -1,14 +1,19 @@
59182 #ifndef _PGTABLE_NOPMD_H
59183 #define _PGTABLE_NOPMD_H
59184
59185 -#ifndef __ASSEMBLY__
59186 -
59187 #include <asm-generic/pgtable-nopud.h>
59188
59189 -struct mm_struct;
59190 -
59191 #define __PAGETABLE_PMD_FOLDED
59192
59193 +#define PMD_SHIFT PUD_SHIFT
59194 +#define PTRS_PER_PMD 1
59195 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59196 +#define PMD_MASK (~(PMD_SIZE-1))
59197 +
59198 +#ifndef __ASSEMBLY__
59199 +
59200 +struct mm_struct;
59201 +
59202 /*
59203 * Having the pmd type consist of a pud gets the size right, and allows
59204 * us to conceptually access the pud entry that this pmd is folded into
59205 @@ -16,11 +21,6 @@ struct mm_struct;
59206 */
59207 typedef struct { pud_t pud; } pmd_t;
59208
59209 -#define PMD_SHIFT PUD_SHIFT
59210 -#define PTRS_PER_PMD 1
59211 -#define PMD_SIZE (1UL << PMD_SHIFT)
59212 -#define PMD_MASK (~(PMD_SIZE-1))
59213 -
59214 /*
59215 * The "pud_xxx()" functions here are trivial for a folded two-level
59216 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59217 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59218 index 810431d..ccc3638 100644
59219 --- a/include/asm-generic/pgtable-nopud.h
59220 +++ b/include/asm-generic/pgtable-nopud.h
59221 @@ -1,10 +1,15 @@
59222 #ifndef _PGTABLE_NOPUD_H
59223 #define _PGTABLE_NOPUD_H
59224
59225 -#ifndef __ASSEMBLY__
59226 -
59227 #define __PAGETABLE_PUD_FOLDED
59228
59229 +#define PUD_SHIFT PGDIR_SHIFT
59230 +#define PTRS_PER_PUD 1
59231 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59232 +#define PUD_MASK (~(PUD_SIZE-1))
59233 +
59234 +#ifndef __ASSEMBLY__
59235 +
59236 /*
59237 * Having the pud type consist of a pgd gets the size right, and allows
59238 * us to conceptually access the pgd entry that this pud is folded into
59239 @@ -12,11 +17,6 @@
59240 */
59241 typedef struct { pgd_t pgd; } pud_t;
59242
59243 -#define PUD_SHIFT PGDIR_SHIFT
59244 -#define PTRS_PER_PUD 1
59245 -#define PUD_SIZE (1UL << PUD_SHIFT)
59246 -#define PUD_MASK (~(PUD_SIZE-1))
59247 -
59248 /*
59249 * The "pgd_xxx()" functions here are trivial for a folded two-level
59250 * setup: the pud is never bad, and a pud always exists (as it's folded
59251 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59252 index 76bff2b..c7a14e2 100644
59253 --- a/include/asm-generic/pgtable.h
59254 +++ b/include/asm-generic/pgtable.h
59255 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
59256 #endif /* __HAVE_ARCH_PMD_WRITE */
59257 #endif
59258
59259 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59260 +static inline unsigned long pax_open_kernel(void) { return 0; }
59261 +#endif
59262 +
59263 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59264 +static inline unsigned long pax_close_kernel(void) { return 0; }
59265 +#endif
59266 +
59267 #endif /* !__ASSEMBLY__ */
59268
59269 #endif /* _ASM_GENERIC_PGTABLE_H */
59270 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59271 index b5e2e4c..6a5373e 100644
59272 --- a/include/asm-generic/vmlinux.lds.h
59273 +++ b/include/asm-generic/vmlinux.lds.h
59274 @@ -217,6 +217,7 @@
59275 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59276 VMLINUX_SYMBOL(__start_rodata) = .; \
59277 *(.rodata) *(.rodata.*) \
59278 + *(.data..read_only) \
59279 *(__vermagic) /* Kernel version magic */ \
59280 . = ALIGN(8); \
59281 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
59282 @@ -722,17 +723,18 @@
59283 * section in the linker script will go there too. @phdr should have
59284 * a leading colon.
59285 *
59286 - * Note that this macros defines __per_cpu_load as an absolute symbol.
59287 + * Note that this macros defines per_cpu_load as an absolute symbol.
59288 * If there is no need to put the percpu section at a predetermined
59289 * address, use PERCPU_SECTION.
59290 */
59291 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
59292 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
59293 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
59294 + per_cpu_load = .; \
59295 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
59296 - LOAD_OFFSET) { \
59297 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
59298 PERCPU_INPUT(cacheline) \
59299 } phdr \
59300 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
59301 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
59302
59303 /**
59304 * PERCPU_SECTION - define output section for percpu area, simple version
59305 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59306 index bf4b2dc..2d0762f 100644
59307 --- a/include/drm/drmP.h
59308 +++ b/include/drm/drmP.h
59309 @@ -72,6 +72,7 @@
59310 #include <linux/workqueue.h>
59311 #include <linux/poll.h>
59312 #include <asm/pgalloc.h>
59313 +#include <asm/local.h>
59314 #include "drm.h"
59315
59316 #include <linux/idr.h>
59317 @@ -1038,7 +1039,7 @@ struct drm_device {
59318
59319 /** \name Usage Counters */
59320 /*@{ */
59321 - int open_count; /**< Outstanding files open */
59322 + local_t open_count; /**< Outstanding files open */
59323 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59324 atomic_t vma_count; /**< Outstanding vma areas open */
59325 int buf_use; /**< Buffers in use -- cannot alloc */
59326 @@ -1049,7 +1050,7 @@ struct drm_device {
59327 /*@{ */
59328 unsigned long counters;
59329 enum drm_stat_type types[15];
59330 - atomic_t counts[15];
59331 + atomic_unchecked_t counts[15];
59332 /*@} */
59333
59334 struct list_head filelist;
59335 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59336 index 73b0712..0b7ef2f 100644
59337 --- a/include/drm/drm_crtc_helper.h
59338 +++ b/include/drm/drm_crtc_helper.h
59339 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59340
59341 /* disable crtc when not in use - more explicit than dpms off */
59342 void (*disable)(struct drm_crtc *crtc);
59343 -};
59344 +} __no_const;
59345
59346 struct drm_encoder_helper_funcs {
59347 void (*dpms)(struct drm_encoder *encoder, int mode);
59348 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59349 struct drm_connector *connector);
59350 /* disable encoder when not in use - more explicit than dpms off */
59351 void (*disable)(struct drm_encoder *encoder);
59352 -};
59353 +} __no_const;
59354
59355 struct drm_connector_helper_funcs {
59356 int (*get_modes)(struct drm_connector *connector);
59357 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59358 index 26c1f78..6722682 100644
59359 --- a/include/drm/ttm/ttm_memory.h
59360 +++ b/include/drm/ttm/ttm_memory.h
59361 @@ -47,7 +47,7 @@
59362
59363 struct ttm_mem_shrink {
59364 int (*do_shrink) (struct ttm_mem_shrink *);
59365 -};
59366 +} __no_const;
59367
59368 /**
59369 * struct ttm_mem_global - Global memory accounting structure.
59370 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59371 index e86dfca..40cc55f 100644
59372 --- a/include/linux/a.out.h
59373 +++ b/include/linux/a.out.h
59374 @@ -39,6 +39,14 @@ enum machine_type {
59375 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59376 };
59377
59378 +/* Constants for the N_FLAGS field */
59379 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59380 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59381 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59382 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59383 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59384 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59385 +
59386 #if !defined (N_MAGIC)
59387 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59388 #endif
59389 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59390 index 49a83ca..df96b54 100644
59391 --- a/include/linux/atmdev.h
59392 +++ b/include/linux/atmdev.h
59393 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59394 #endif
59395
59396 struct k_atm_aal_stats {
59397 -#define __HANDLE_ITEM(i) atomic_t i
59398 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
59399 __AAL_STAT_ITEMS
59400 #undef __HANDLE_ITEM
59401 };
59402 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59403 index fd88a39..8a801b4 100644
59404 --- a/include/linux/binfmts.h
59405 +++ b/include/linux/binfmts.h
59406 @@ -18,7 +18,7 @@ struct pt_regs;
59407 #define BINPRM_BUF_SIZE 128
59408
59409 #ifdef __KERNEL__
59410 -#include <linux/list.h>
59411 +#include <linux/sched.h>
59412
59413 #define CORENAME_MAX_SIZE 128
59414
59415 @@ -58,6 +58,7 @@ struct linux_binprm {
59416 unsigned interp_flags;
59417 unsigned interp_data;
59418 unsigned long loader, exec;
59419 + char tcomm[TASK_COMM_LEN];
59420 };
59421
59422 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
59423 @@ -88,6 +89,7 @@ struct linux_binfmt {
59424 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59425 int (*load_shlib)(struct file *);
59426 int (*core_dump)(struct coredump_params *cprm);
59427 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59428 unsigned long min_coredump; /* minimal dump size */
59429 };
59430
59431 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59432 index 0ed1eb0..3ab569b 100644
59433 --- a/include/linux/blkdev.h
59434 +++ b/include/linux/blkdev.h
59435 @@ -1315,7 +1315,7 @@ struct block_device_operations {
59436 /* this callback is with swap_lock and sometimes page table lock held */
59437 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59438 struct module *owner;
59439 -};
59440 +} __do_const;
59441
59442 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59443 unsigned long);
59444 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59445 index 4d1a074..88f929a 100644
59446 --- a/include/linux/blktrace_api.h
59447 +++ b/include/linux/blktrace_api.h
59448 @@ -162,7 +162,7 @@ struct blk_trace {
59449 struct dentry *dir;
59450 struct dentry *dropped_file;
59451 struct dentry *msg_file;
59452 - atomic_t dropped;
59453 + atomic_unchecked_t dropped;
59454 };
59455
59456 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59457 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59458 index 83195fb..0b0f77d 100644
59459 --- a/include/linux/byteorder/little_endian.h
59460 +++ b/include/linux/byteorder/little_endian.h
59461 @@ -42,51 +42,51 @@
59462
59463 static inline __le64 __cpu_to_le64p(const __u64 *p)
59464 {
59465 - return (__force __le64)*p;
59466 + return (__force const __le64)*p;
59467 }
59468 static inline __u64 __le64_to_cpup(const __le64 *p)
59469 {
59470 - return (__force __u64)*p;
59471 + return (__force const __u64)*p;
59472 }
59473 static inline __le32 __cpu_to_le32p(const __u32 *p)
59474 {
59475 - return (__force __le32)*p;
59476 + return (__force const __le32)*p;
59477 }
59478 static inline __u32 __le32_to_cpup(const __le32 *p)
59479 {
59480 - return (__force __u32)*p;
59481 + return (__force const __u32)*p;
59482 }
59483 static inline __le16 __cpu_to_le16p(const __u16 *p)
59484 {
59485 - return (__force __le16)*p;
59486 + return (__force const __le16)*p;
59487 }
59488 static inline __u16 __le16_to_cpup(const __le16 *p)
59489 {
59490 - return (__force __u16)*p;
59491 + return (__force const __u16)*p;
59492 }
59493 static inline __be64 __cpu_to_be64p(const __u64 *p)
59494 {
59495 - return (__force __be64)__swab64p(p);
59496 + return (__force const __be64)__swab64p(p);
59497 }
59498 static inline __u64 __be64_to_cpup(const __be64 *p)
59499 {
59500 - return __swab64p((__u64 *)p);
59501 + return __swab64p((const __u64 *)p);
59502 }
59503 static inline __be32 __cpu_to_be32p(const __u32 *p)
59504 {
59505 - return (__force __be32)__swab32p(p);
59506 + return (__force const __be32)__swab32p(p);
59507 }
59508 static inline __u32 __be32_to_cpup(const __be32 *p)
59509 {
59510 - return __swab32p((__u32 *)p);
59511 + return __swab32p((const __u32 *)p);
59512 }
59513 static inline __be16 __cpu_to_be16p(const __u16 *p)
59514 {
59515 - return (__force __be16)__swab16p(p);
59516 + return (__force const __be16)__swab16p(p);
59517 }
59518 static inline __u16 __be16_to_cpup(const __be16 *p)
59519 {
59520 - return __swab16p((__u16 *)p);
59521 + return __swab16p((const __u16 *)p);
59522 }
59523 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59524 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59525 diff --git a/include/linux/cache.h b/include/linux/cache.h
59526 index 4c57065..4307975 100644
59527 --- a/include/linux/cache.h
59528 +++ b/include/linux/cache.h
59529 @@ -16,6 +16,10 @@
59530 #define __read_mostly
59531 #endif
59532
59533 +#ifndef __read_only
59534 +#define __read_only __read_mostly
59535 +#endif
59536 +
59537 #ifndef ____cacheline_aligned
59538 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59539 #endif
59540 diff --git a/include/linux/capability.h b/include/linux/capability.h
59541 index a63d13d..069bfd5 100644
59542 --- a/include/linux/capability.h
59543 +++ b/include/linux/capability.h
59544 @@ -548,6 +548,9 @@ extern bool capable(int cap);
59545 extern bool ns_capable(struct user_namespace *ns, int cap);
59546 extern bool task_ns_capable(struct task_struct *t, int cap);
59547 extern bool nsown_capable(int cap);
59548 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
59549 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59550 +extern bool capable_nolog(int cap);
59551
59552 /* audit system wants to get cap info from files as well */
59553 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59554 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59555 index 04ffb2e..6799180 100644
59556 --- a/include/linux/cleancache.h
59557 +++ b/include/linux/cleancache.h
59558 @@ -31,7 +31,7 @@ struct cleancache_ops {
59559 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
59560 void (*flush_inode)(int, struct cleancache_filekey);
59561 void (*flush_fs)(int);
59562 -};
59563 +} __no_const;
59564
59565 extern struct cleancache_ops
59566 cleancache_register_ops(struct cleancache_ops *ops);
59567 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59568 index dfadc96..c0e70c1 100644
59569 --- a/include/linux/compiler-gcc4.h
59570 +++ b/include/linux/compiler-gcc4.h
59571 @@ -31,6 +31,12 @@
59572
59573
59574 #if __GNUC_MINOR__ >= 5
59575 +
59576 +#ifdef CONSTIFY_PLUGIN
59577 +#define __no_const __attribute__((no_const))
59578 +#define __do_const __attribute__((do_const))
59579 +#endif
59580 +
59581 /*
59582 * Mark a position in code as unreachable. This can be used to
59583 * suppress control flow warnings after asm blocks that transfer
59584 @@ -46,6 +52,11 @@
59585 #define __noclone __attribute__((__noclone__))
59586
59587 #endif
59588 +
59589 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59590 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59591 +#define __bos0(ptr) __bos((ptr), 0)
59592 +#define __bos1(ptr) __bos((ptr), 1)
59593 #endif
59594
59595 #if __GNUC_MINOR__ > 0
59596 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59597 index 320d6c9..8573a1c 100644
59598 --- a/include/linux/compiler.h
59599 +++ b/include/linux/compiler.h
59600 @@ -5,31 +5,62 @@
59601
59602 #ifdef __CHECKER__
59603 # define __user __attribute__((noderef, address_space(1)))
59604 +# define __force_user __force __user
59605 # define __kernel __attribute__((address_space(0)))
59606 +# define __force_kernel __force __kernel
59607 # define __safe __attribute__((safe))
59608 # define __force __attribute__((force))
59609 # define __nocast __attribute__((nocast))
59610 # define __iomem __attribute__((noderef, address_space(2)))
59611 +# define __force_iomem __force __iomem
59612 # define __acquires(x) __attribute__((context(x,0,1)))
59613 # define __releases(x) __attribute__((context(x,1,0)))
59614 # define __acquire(x) __context__(x,1)
59615 # define __release(x) __context__(x,-1)
59616 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59617 # define __percpu __attribute__((noderef, address_space(3)))
59618 +# define __force_percpu __force __percpu
59619 #ifdef CONFIG_SPARSE_RCU_POINTER
59620 # define __rcu __attribute__((noderef, address_space(4)))
59621 +# define __force_rcu __force __rcu
59622 #else
59623 # define __rcu
59624 +# define __force_rcu
59625 #endif
59626 extern void __chk_user_ptr(const volatile void __user *);
59627 extern void __chk_io_ptr(const volatile void __iomem *);
59628 +#elif defined(CHECKER_PLUGIN)
59629 +//# define __user
59630 +//# define __force_user
59631 +//# define __kernel
59632 +//# define __force_kernel
59633 +# define __safe
59634 +# define __force
59635 +# define __nocast
59636 +# define __iomem
59637 +# define __force_iomem
59638 +# define __chk_user_ptr(x) (void)0
59639 +# define __chk_io_ptr(x) (void)0
59640 +# define __builtin_warning(x, y...) (1)
59641 +# define __acquires(x)
59642 +# define __releases(x)
59643 +# define __acquire(x) (void)0
59644 +# define __release(x) (void)0
59645 +# define __cond_lock(x,c) (c)
59646 +# define __percpu
59647 +# define __force_percpu
59648 +# define __rcu
59649 +# define __force_rcu
59650 #else
59651 # define __user
59652 +# define __force_user
59653 # define __kernel
59654 +# define __force_kernel
59655 # define __safe
59656 # define __force
59657 # define __nocast
59658 # define __iomem
59659 +# define __force_iomem
59660 # define __chk_user_ptr(x) (void)0
59661 # define __chk_io_ptr(x) (void)0
59662 # define __builtin_warning(x, y...) (1)
59663 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59664 # define __release(x) (void)0
59665 # define __cond_lock(x,c) (c)
59666 # define __percpu
59667 +# define __force_percpu
59668 # define __rcu
59669 +# define __force_rcu
59670 #endif
59671
59672 #ifdef __KERNEL__
59673 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59674 # define __attribute_const__ /* unimplemented */
59675 #endif
59676
59677 +#ifndef __no_const
59678 +# define __no_const
59679 +#endif
59680 +
59681 +#ifndef __do_const
59682 +# define __do_const
59683 +#endif
59684 +
59685 /*
59686 * Tell gcc if a function is cold. The compiler will assume any path
59687 * directly leading to the call is unlikely.
59688 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59689 #define __cold
59690 #endif
59691
59692 +#ifndef __alloc_size
59693 +#define __alloc_size(...)
59694 +#endif
59695 +
59696 +#ifndef __bos
59697 +#define __bos(ptr, arg)
59698 +#endif
59699 +
59700 +#ifndef __bos0
59701 +#define __bos0(ptr)
59702 +#endif
59703 +
59704 +#ifndef __bos1
59705 +#define __bos1(ptr)
59706 +#endif
59707 +
59708 /* Simple shorthand for a section definition */
59709 #ifndef __section
59710 # define __section(S) __attribute__ ((__section__(#S)))
59711 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59712 * use is to mediate communication between process-level code and irq/NMI
59713 * handlers, all running on the same CPU.
59714 */
59715 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59716 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59717 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59718
59719 #endif /* __LINUX_COMPILER_H */
59720 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
59721 index e9eaec5..bfeb9bb 100644
59722 --- a/include/linux/cpuset.h
59723 +++ b/include/linux/cpuset.h
59724 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
59725 * nodemask.
59726 */
59727 smp_mb();
59728 - --ACCESS_ONCE(current->mems_allowed_change_disable);
59729 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
59730 }
59731
59732 static inline void set_mems_allowed(nodemask_t nodemask)
59733 diff --git a/include/linux/cred.h b/include/linux/cred.h
59734 index 4030896..8d6f342 100644
59735 --- a/include/linux/cred.h
59736 +++ b/include/linux/cred.h
59737 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59738 static inline void validate_process_creds(void)
59739 {
59740 }
59741 +static inline void validate_task_creds(struct task_struct *task)
59742 +{
59743 +}
59744 #endif
59745
59746 /**
59747 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59748 index 8a94217..15d49e3 100644
59749 --- a/include/linux/crypto.h
59750 +++ b/include/linux/crypto.h
59751 @@ -365,7 +365,7 @@ struct cipher_tfm {
59752 const u8 *key, unsigned int keylen);
59753 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59754 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59755 -};
59756 +} __no_const;
59757
59758 struct hash_tfm {
59759 int (*init)(struct hash_desc *desc);
59760 @@ -386,13 +386,13 @@ struct compress_tfm {
59761 int (*cot_decompress)(struct crypto_tfm *tfm,
59762 const u8 *src, unsigned int slen,
59763 u8 *dst, unsigned int *dlen);
59764 -};
59765 +} __no_const;
59766
59767 struct rng_tfm {
59768 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59769 unsigned int dlen);
59770 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59771 -};
59772 +} __no_const;
59773
59774 #define crt_ablkcipher crt_u.ablkcipher
59775 #define crt_aead crt_u.aead
59776 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59777 index 7925bf0..d5143d2 100644
59778 --- a/include/linux/decompress/mm.h
59779 +++ b/include/linux/decompress/mm.h
59780 @@ -77,7 +77,7 @@ static void free(void *where)
59781 * warnings when not needed (indeed large_malloc / large_free are not
59782 * needed by inflate */
59783
59784 -#define malloc(a) kmalloc(a, GFP_KERNEL)
59785 +#define malloc(a) kmalloc((a), GFP_KERNEL)
59786 #define free(a) kfree(a)
59787
59788 #define large_malloc(a) vmalloc(a)
59789 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
59790 index e13117c..e9fc938 100644
59791 --- a/include/linux/dma-mapping.h
59792 +++ b/include/linux/dma-mapping.h
59793 @@ -46,7 +46,7 @@ struct dma_map_ops {
59794 u64 (*get_required_mask)(struct device *dev);
59795 #endif
59796 int is_phys;
59797 -};
59798 +} __do_const;
59799
59800 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
59801
59802 diff --git a/include/linux/efi.h b/include/linux/efi.h
59803 index 2362a0b..cfaf8fcc 100644
59804 --- a/include/linux/efi.h
59805 +++ b/include/linux/efi.h
59806 @@ -446,7 +446,7 @@ struct efivar_operations {
59807 efi_get_variable_t *get_variable;
59808 efi_get_next_variable_t *get_next_variable;
59809 efi_set_variable_t *set_variable;
59810 -};
59811 +} __no_const;
59812
59813 struct efivars {
59814 /*
59815 diff --git a/include/linux/elf.h b/include/linux/elf.h
59816 index 31f0508..5421c01 100644
59817 --- a/include/linux/elf.h
59818 +++ b/include/linux/elf.h
59819 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
59820 #define PT_GNU_EH_FRAME 0x6474e550
59821
59822 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
59823 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
59824 +
59825 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
59826 +
59827 +/* Constants for the e_flags field */
59828 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59829 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
59830 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
59831 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
59832 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59833 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59834
59835 /*
59836 * Extended Numbering
59837 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
59838 #define DT_DEBUG 21
59839 #define DT_TEXTREL 22
59840 #define DT_JMPREL 23
59841 +#define DT_FLAGS 30
59842 + #define DF_TEXTREL 0x00000004
59843 #define DT_ENCODING 32
59844 #define OLD_DT_LOOS 0x60000000
59845 #define DT_LOOS 0x6000000d
59846 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
59847 #define PF_W 0x2
59848 #define PF_X 0x1
59849
59850 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
59851 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
59852 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
59853 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
59854 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
59855 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
59856 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
59857 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
59858 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
59859 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
59860 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
59861 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
59862 +
59863 typedef struct elf32_phdr{
59864 Elf32_Word p_type;
59865 Elf32_Off p_offset;
59866 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
59867 #define EI_OSABI 7
59868 #define EI_PAD 8
59869
59870 +#define EI_PAX 14
59871 +
59872 #define ELFMAG0 0x7f /* EI_MAG */
59873 #define ELFMAG1 'E'
59874 #define ELFMAG2 'L'
59875 @@ -423,6 +451,7 @@ extern Elf32_Dyn _DYNAMIC [];
59876 #define elf_note elf32_note
59877 #define elf_addr_t Elf32_Off
59878 #define Elf_Half Elf32_Half
59879 +#define elf_dyn Elf32_Dyn
59880
59881 #else
59882
59883 @@ -433,6 +462,7 @@ extern Elf64_Dyn _DYNAMIC [];
59884 #define elf_note elf64_note
59885 #define elf_addr_t Elf64_Off
59886 #define Elf_Half Elf64_Half
59887 +#define elf_dyn Elf64_Dyn
59888
59889 #endif
59890
59891 diff --git a/include/linux/filter.h b/include/linux/filter.h
59892 index 8eeb205..d59bfa2 100644
59893 --- a/include/linux/filter.h
59894 +++ b/include/linux/filter.h
59895 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
59896
59897 struct sk_buff;
59898 struct sock;
59899 +struct bpf_jit_work;
59900
59901 struct sk_filter
59902 {
59903 @@ -141,6 +142,9 @@ struct sk_filter
59904 unsigned int len; /* Number of filter blocks */
59905 unsigned int (*bpf_func)(const struct sk_buff *skb,
59906 const struct sock_filter *filter);
59907 +#ifdef CONFIG_BPF_JIT
59908 + struct bpf_jit_work *work;
59909 +#endif
59910 struct rcu_head rcu;
59911 struct sock_filter insns[0];
59912 };
59913 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
59914 index 84ccf8e..2e9b14c 100644
59915 --- a/include/linux/firewire.h
59916 +++ b/include/linux/firewire.h
59917 @@ -428,7 +428,7 @@ struct fw_iso_context {
59918 union {
59919 fw_iso_callback_t sc;
59920 fw_iso_mc_callback_t mc;
59921 - } callback;
59922 + } __no_const callback;
59923 void *callback_data;
59924 };
59925
59926 diff --git a/include/linux/fs.h b/include/linux/fs.h
59927 index 10b2288..09180e4 100644
59928 --- a/include/linux/fs.h
59929 +++ b/include/linux/fs.h
59930 @@ -1609,7 +1609,8 @@ struct file_operations {
59931 int (*setlease)(struct file *, long, struct file_lock **);
59932 long (*fallocate)(struct file *file, int mode, loff_t offset,
59933 loff_t len);
59934 -};
59935 +} __do_const;
59936 +typedef struct file_operations __no_const file_operations_no_const;
59937
59938 struct inode_operations {
59939 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
59940 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
59941 index 003dc0f..3c4ea97 100644
59942 --- a/include/linux/fs_struct.h
59943 +++ b/include/linux/fs_struct.h
59944 @@ -6,7 +6,7 @@
59945 #include <linux/seqlock.h>
59946
59947 struct fs_struct {
59948 - int users;
59949 + atomic_t users;
59950 spinlock_t lock;
59951 seqcount_t seq;
59952 int umask;
59953 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
59954 index ce31408..b1ad003 100644
59955 --- a/include/linux/fscache-cache.h
59956 +++ b/include/linux/fscache-cache.h
59957 @@ -102,7 +102,7 @@ struct fscache_operation {
59958 fscache_operation_release_t release;
59959 };
59960
59961 -extern atomic_t fscache_op_debug_id;
59962 +extern atomic_unchecked_t fscache_op_debug_id;
59963 extern void fscache_op_work_func(struct work_struct *work);
59964
59965 extern void fscache_enqueue_operation(struct fscache_operation *);
59966 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
59967 {
59968 INIT_WORK(&op->work, fscache_op_work_func);
59969 atomic_set(&op->usage, 1);
59970 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59971 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59972 op->processor = processor;
59973 op->release = release;
59974 INIT_LIST_HEAD(&op->pend_link);
59975 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
59976 index 2a53f10..0187fdf 100644
59977 --- a/include/linux/fsnotify.h
59978 +++ b/include/linux/fsnotify.h
59979 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
59980 */
59981 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
59982 {
59983 - return kstrdup(name, GFP_KERNEL);
59984 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
59985 }
59986
59987 /*
59988 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
59989 index 91d0e0a3..035666b 100644
59990 --- a/include/linux/fsnotify_backend.h
59991 +++ b/include/linux/fsnotify_backend.h
59992 @@ -105,6 +105,7 @@ struct fsnotify_ops {
59993 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
59994 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
59995 };
59996 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
59997
59998 /*
59999 * A group is a "thing" that wants to receive notification about filesystem
60000 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60001 index c3da42d..c70e0df 100644
60002 --- a/include/linux/ftrace_event.h
60003 +++ b/include/linux/ftrace_event.h
60004 @@ -97,7 +97,7 @@ struct trace_event_functions {
60005 trace_print_func raw;
60006 trace_print_func hex;
60007 trace_print_func binary;
60008 -};
60009 +} __no_const;
60010
60011 struct trace_event {
60012 struct hlist_node node;
60013 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60014 extern int trace_add_event_call(struct ftrace_event_call *call);
60015 extern void trace_remove_event_call(struct ftrace_event_call *call);
60016
60017 -#define is_signed_type(type) (((type)(-1)) < 0)
60018 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60019
60020 int trace_set_clr_event(const char *system, const char *event, int set);
60021
60022 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60023 index 6d18f35..ab71e2c 100644
60024 --- a/include/linux/genhd.h
60025 +++ b/include/linux/genhd.h
60026 @@ -185,7 +185,7 @@ struct gendisk {
60027 struct kobject *slave_dir;
60028
60029 struct timer_rand_state *random;
60030 - atomic_t sync_io; /* RAID */
60031 + atomic_unchecked_t sync_io; /* RAID */
60032 struct disk_events *ev;
60033 #ifdef CONFIG_BLK_DEV_INTEGRITY
60034 struct blk_integrity *integrity;
60035 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60036 new file mode 100644
60037 index 0000000..8a130b6
60038 --- /dev/null
60039 +++ b/include/linux/gracl.h
60040 @@ -0,0 +1,319 @@
60041 +#ifndef GR_ACL_H
60042 +#define GR_ACL_H
60043 +
60044 +#include <linux/grdefs.h>
60045 +#include <linux/resource.h>
60046 +#include <linux/capability.h>
60047 +#include <linux/dcache.h>
60048 +#include <asm/resource.h>
60049 +
60050 +/* Major status information */
60051 +
60052 +#define GR_VERSION "grsecurity 2.9"
60053 +#define GRSECURITY_VERSION 0x2900
60054 +
60055 +enum {
60056 + GR_SHUTDOWN = 0,
60057 + GR_ENABLE = 1,
60058 + GR_SPROLE = 2,
60059 + GR_RELOAD = 3,
60060 + GR_SEGVMOD = 4,
60061 + GR_STATUS = 5,
60062 + GR_UNSPROLE = 6,
60063 + GR_PASSSET = 7,
60064 + GR_SPROLEPAM = 8,
60065 +};
60066 +
60067 +/* Password setup definitions
60068 + * kernel/grhash.c */
60069 +enum {
60070 + GR_PW_LEN = 128,
60071 + GR_SALT_LEN = 16,
60072 + GR_SHA_LEN = 32,
60073 +};
60074 +
60075 +enum {
60076 + GR_SPROLE_LEN = 64,
60077 +};
60078 +
60079 +enum {
60080 + GR_NO_GLOB = 0,
60081 + GR_REG_GLOB,
60082 + GR_CREATE_GLOB
60083 +};
60084 +
60085 +#define GR_NLIMITS 32
60086 +
60087 +/* Begin Data Structures */
60088 +
60089 +struct sprole_pw {
60090 + unsigned char *rolename;
60091 + unsigned char salt[GR_SALT_LEN];
60092 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60093 +};
60094 +
60095 +struct name_entry {
60096 + __u32 key;
60097 + ino_t inode;
60098 + dev_t device;
60099 + char *name;
60100 + __u16 len;
60101 + __u8 deleted;
60102 + struct name_entry *prev;
60103 + struct name_entry *next;
60104 +};
60105 +
60106 +struct inodev_entry {
60107 + struct name_entry *nentry;
60108 + struct inodev_entry *prev;
60109 + struct inodev_entry *next;
60110 +};
60111 +
60112 +struct acl_role_db {
60113 + struct acl_role_label **r_hash;
60114 + __u32 r_size;
60115 +};
60116 +
60117 +struct inodev_db {
60118 + struct inodev_entry **i_hash;
60119 + __u32 i_size;
60120 +};
60121 +
60122 +struct name_db {
60123 + struct name_entry **n_hash;
60124 + __u32 n_size;
60125 +};
60126 +
60127 +struct crash_uid {
60128 + uid_t uid;
60129 + unsigned long expires;
60130 +};
60131 +
60132 +struct gr_hash_struct {
60133 + void **table;
60134 + void **nametable;
60135 + void *first;
60136 + __u32 table_size;
60137 + __u32 used_size;
60138 + int type;
60139 +};
60140 +
60141 +/* Userspace Grsecurity ACL data structures */
60142 +
60143 +struct acl_subject_label {
60144 + char *filename;
60145 + ino_t inode;
60146 + dev_t device;
60147 + __u32 mode;
60148 + kernel_cap_t cap_mask;
60149 + kernel_cap_t cap_lower;
60150 + kernel_cap_t cap_invert_audit;
60151 +
60152 + struct rlimit res[GR_NLIMITS];
60153 + __u32 resmask;
60154 +
60155 + __u8 user_trans_type;
60156 + __u8 group_trans_type;
60157 + uid_t *user_transitions;
60158 + gid_t *group_transitions;
60159 + __u16 user_trans_num;
60160 + __u16 group_trans_num;
60161 +
60162 + __u32 sock_families[2];
60163 + __u32 ip_proto[8];
60164 + __u32 ip_type;
60165 + struct acl_ip_label **ips;
60166 + __u32 ip_num;
60167 + __u32 inaddr_any_override;
60168 +
60169 + __u32 crashes;
60170 + unsigned long expires;
60171 +
60172 + struct acl_subject_label *parent_subject;
60173 + struct gr_hash_struct *hash;
60174 + struct acl_subject_label *prev;
60175 + struct acl_subject_label *next;
60176 +
60177 + struct acl_object_label **obj_hash;
60178 + __u32 obj_hash_size;
60179 + __u16 pax_flags;
60180 +};
60181 +
60182 +struct role_allowed_ip {
60183 + __u32 addr;
60184 + __u32 netmask;
60185 +
60186 + struct role_allowed_ip *prev;
60187 + struct role_allowed_ip *next;
60188 +};
60189 +
60190 +struct role_transition {
60191 + char *rolename;
60192 +
60193 + struct role_transition *prev;
60194 + struct role_transition *next;
60195 +};
60196 +
60197 +struct acl_role_label {
60198 + char *rolename;
60199 + uid_t uidgid;
60200 + __u16 roletype;
60201 +
60202 + __u16 auth_attempts;
60203 + unsigned long expires;
60204 +
60205 + struct acl_subject_label *root_label;
60206 + struct gr_hash_struct *hash;
60207 +
60208 + struct acl_role_label *prev;
60209 + struct acl_role_label *next;
60210 +
60211 + struct role_transition *transitions;
60212 + struct role_allowed_ip *allowed_ips;
60213 + uid_t *domain_children;
60214 + __u16 domain_child_num;
60215 +
60216 + umode_t umask;
60217 +
60218 + struct acl_subject_label **subj_hash;
60219 + __u32 subj_hash_size;
60220 +};
60221 +
60222 +struct user_acl_role_db {
60223 + struct acl_role_label **r_table;
60224 + __u32 num_pointers; /* Number of allocations to track */
60225 + __u32 num_roles; /* Number of roles */
60226 + __u32 num_domain_children; /* Number of domain children */
60227 + __u32 num_subjects; /* Number of subjects */
60228 + __u32 num_objects; /* Number of objects */
60229 +};
60230 +
60231 +struct acl_object_label {
60232 + char *filename;
60233 + ino_t inode;
60234 + dev_t device;
60235 + __u32 mode;
60236 +
60237 + struct acl_subject_label *nested;
60238 + struct acl_object_label *globbed;
60239 +
60240 + /* next two structures not used */
60241 +
60242 + struct acl_object_label *prev;
60243 + struct acl_object_label *next;
60244 +};
60245 +
60246 +struct acl_ip_label {
60247 + char *iface;
60248 + __u32 addr;
60249 + __u32 netmask;
60250 + __u16 low, high;
60251 + __u8 mode;
60252 + __u32 type;
60253 + __u32 proto[8];
60254 +
60255 + /* next two structures not used */
60256 +
60257 + struct acl_ip_label *prev;
60258 + struct acl_ip_label *next;
60259 +};
60260 +
60261 +struct gr_arg {
60262 + struct user_acl_role_db role_db;
60263 + unsigned char pw[GR_PW_LEN];
60264 + unsigned char salt[GR_SALT_LEN];
60265 + unsigned char sum[GR_SHA_LEN];
60266 + unsigned char sp_role[GR_SPROLE_LEN];
60267 + struct sprole_pw *sprole_pws;
60268 + dev_t segv_device;
60269 + ino_t segv_inode;
60270 + uid_t segv_uid;
60271 + __u16 num_sprole_pws;
60272 + __u16 mode;
60273 +};
60274 +
60275 +struct gr_arg_wrapper {
60276 + struct gr_arg *arg;
60277 + __u32 version;
60278 + __u32 size;
60279 +};
60280 +
60281 +struct subject_map {
60282 + struct acl_subject_label *user;
60283 + struct acl_subject_label *kernel;
60284 + struct subject_map *prev;
60285 + struct subject_map *next;
60286 +};
60287 +
60288 +struct acl_subj_map_db {
60289 + struct subject_map **s_hash;
60290 + __u32 s_size;
60291 +};
60292 +
60293 +/* End Data Structures Section */
60294 +
60295 +/* Hash functions generated by empirical testing by Brad Spengler
60296 + Makes good use of the low bits of the inode. Generally 0-1 times
60297 + in loop for successful match. 0-3 for unsuccessful match.
60298 + Shift/add algorithm with modulus of table size and an XOR*/
60299 +
60300 +static __inline__ unsigned int
60301 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
60302 +{
60303 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
60304 +}
60305 +
60306 + static __inline__ unsigned int
60307 +shash(const struct acl_subject_label *userp, const unsigned int sz)
60308 +{
60309 + return ((const unsigned long)userp % sz);
60310 +}
60311 +
60312 +static __inline__ unsigned int
60313 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
60314 +{
60315 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
60316 +}
60317 +
60318 +static __inline__ unsigned int
60319 +nhash(const char *name, const __u16 len, const unsigned int sz)
60320 +{
60321 + return full_name_hash((const unsigned char *)name, len) % sz;
60322 +}
60323 +
60324 +#define FOR_EACH_ROLE_START(role) \
60325 + role = role_list; \
60326 + while (role) {
60327 +
60328 +#define FOR_EACH_ROLE_END(role) \
60329 + role = role->prev; \
60330 + }
60331 +
60332 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60333 + subj = NULL; \
60334 + iter = 0; \
60335 + while (iter < role->subj_hash_size) { \
60336 + if (subj == NULL) \
60337 + subj = role->subj_hash[iter]; \
60338 + if (subj == NULL) { \
60339 + iter++; \
60340 + continue; \
60341 + }
60342 +
60343 +#define FOR_EACH_SUBJECT_END(subj,iter) \
60344 + subj = subj->next; \
60345 + if (subj == NULL) \
60346 + iter++; \
60347 + }
60348 +
60349 +
60350 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60351 + subj = role->hash->first; \
60352 + while (subj != NULL) {
60353 +
60354 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60355 + subj = subj->next; \
60356 + }
60357 +
60358 +#endif
60359 +
60360 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60361 new file mode 100644
60362 index 0000000..323ecf2
60363 --- /dev/null
60364 +++ b/include/linux/gralloc.h
60365 @@ -0,0 +1,9 @@
60366 +#ifndef __GRALLOC_H
60367 +#define __GRALLOC_H
60368 +
60369 +void acl_free_all(void);
60370 +int acl_alloc_stack_init(unsigned long size);
60371 +void *acl_alloc(unsigned long len);
60372 +void *acl_alloc_num(unsigned long num, unsigned long len);
60373 +
60374 +#endif
60375 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60376 new file mode 100644
60377 index 0000000..b30e9bc
60378 --- /dev/null
60379 +++ b/include/linux/grdefs.h
60380 @@ -0,0 +1,140 @@
60381 +#ifndef GRDEFS_H
60382 +#define GRDEFS_H
60383 +
60384 +/* Begin grsecurity status declarations */
60385 +
60386 +enum {
60387 + GR_READY = 0x01,
60388 + GR_STATUS_INIT = 0x00 // disabled state
60389 +};
60390 +
60391 +/* Begin ACL declarations */
60392 +
60393 +/* Role flags */
60394 +
60395 +enum {
60396 + GR_ROLE_USER = 0x0001,
60397 + GR_ROLE_GROUP = 0x0002,
60398 + GR_ROLE_DEFAULT = 0x0004,
60399 + GR_ROLE_SPECIAL = 0x0008,
60400 + GR_ROLE_AUTH = 0x0010,
60401 + GR_ROLE_NOPW = 0x0020,
60402 + GR_ROLE_GOD = 0x0040,
60403 + GR_ROLE_LEARN = 0x0080,
60404 + GR_ROLE_TPE = 0x0100,
60405 + GR_ROLE_DOMAIN = 0x0200,
60406 + GR_ROLE_PAM = 0x0400,
60407 + GR_ROLE_PERSIST = 0x0800
60408 +};
60409 +
60410 +/* ACL Subject and Object mode flags */
60411 +enum {
60412 + GR_DELETED = 0x80000000
60413 +};
60414 +
60415 +/* ACL Object-only mode flags */
60416 +enum {
60417 + GR_READ = 0x00000001,
60418 + GR_APPEND = 0x00000002,
60419 + GR_WRITE = 0x00000004,
60420 + GR_EXEC = 0x00000008,
60421 + GR_FIND = 0x00000010,
60422 + GR_INHERIT = 0x00000020,
60423 + GR_SETID = 0x00000040,
60424 + GR_CREATE = 0x00000080,
60425 + GR_DELETE = 0x00000100,
60426 + GR_LINK = 0x00000200,
60427 + GR_AUDIT_READ = 0x00000400,
60428 + GR_AUDIT_APPEND = 0x00000800,
60429 + GR_AUDIT_WRITE = 0x00001000,
60430 + GR_AUDIT_EXEC = 0x00002000,
60431 + GR_AUDIT_FIND = 0x00004000,
60432 + GR_AUDIT_INHERIT= 0x00008000,
60433 + GR_AUDIT_SETID = 0x00010000,
60434 + GR_AUDIT_CREATE = 0x00020000,
60435 + GR_AUDIT_DELETE = 0x00040000,
60436 + GR_AUDIT_LINK = 0x00080000,
60437 + GR_PTRACERD = 0x00100000,
60438 + GR_NOPTRACE = 0x00200000,
60439 + GR_SUPPRESS = 0x00400000,
60440 + GR_NOLEARN = 0x00800000,
60441 + GR_INIT_TRANSFER= 0x01000000
60442 +};
60443 +
60444 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60445 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60446 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60447 +
60448 +/* ACL subject-only mode flags */
60449 +enum {
60450 + GR_KILL = 0x00000001,
60451 + GR_VIEW = 0x00000002,
60452 + GR_PROTECTED = 0x00000004,
60453 + GR_LEARN = 0x00000008,
60454 + GR_OVERRIDE = 0x00000010,
60455 + /* just a placeholder, this mode is only used in userspace */
60456 + GR_DUMMY = 0x00000020,
60457 + GR_PROTSHM = 0x00000040,
60458 + GR_KILLPROC = 0x00000080,
60459 + GR_KILLIPPROC = 0x00000100,
60460 + /* just a placeholder, this mode is only used in userspace */
60461 + GR_NOTROJAN = 0x00000200,
60462 + GR_PROTPROCFD = 0x00000400,
60463 + GR_PROCACCT = 0x00000800,
60464 + GR_RELAXPTRACE = 0x00001000,
60465 + GR_NESTED = 0x00002000,
60466 + GR_INHERITLEARN = 0x00004000,
60467 + GR_PROCFIND = 0x00008000,
60468 + GR_POVERRIDE = 0x00010000,
60469 + GR_KERNELAUTH = 0x00020000,
60470 + GR_ATSECURE = 0x00040000,
60471 + GR_SHMEXEC = 0x00080000
60472 +};
60473 +
60474 +enum {
60475 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60476 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60477 + GR_PAX_ENABLE_MPROTECT = 0x0004,
60478 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
60479 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60480 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60481 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60482 + GR_PAX_DISABLE_MPROTECT = 0x0400,
60483 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
60484 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60485 +};
60486 +
60487 +enum {
60488 + GR_ID_USER = 0x01,
60489 + GR_ID_GROUP = 0x02,
60490 +};
60491 +
60492 +enum {
60493 + GR_ID_ALLOW = 0x01,
60494 + GR_ID_DENY = 0x02,
60495 +};
60496 +
60497 +#define GR_CRASH_RES 31
60498 +#define GR_UIDTABLE_MAX 500
60499 +
60500 +/* begin resource learning section */
60501 +enum {
60502 + GR_RLIM_CPU_BUMP = 60,
60503 + GR_RLIM_FSIZE_BUMP = 50000,
60504 + GR_RLIM_DATA_BUMP = 10000,
60505 + GR_RLIM_STACK_BUMP = 1000,
60506 + GR_RLIM_CORE_BUMP = 10000,
60507 + GR_RLIM_RSS_BUMP = 500000,
60508 + GR_RLIM_NPROC_BUMP = 1,
60509 + GR_RLIM_NOFILE_BUMP = 5,
60510 + GR_RLIM_MEMLOCK_BUMP = 50000,
60511 + GR_RLIM_AS_BUMP = 500000,
60512 + GR_RLIM_LOCKS_BUMP = 2,
60513 + GR_RLIM_SIGPENDING_BUMP = 5,
60514 + GR_RLIM_MSGQUEUE_BUMP = 10000,
60515 + GR_RLIM_NICE_BUMP = 1,
60516 + GR_RLIM_RTPRIO_BUMP = 1,
60517 + GR_RLIM_RTTIME_BUMP = 1000000
60518 +};
60519 +
60520 +#endif
60521 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60522 new file mode 100644
60523 index 0000000..da390f1
60524 --- /dev/null
60525 +++ b/include/linux/grinternal.h
60526 @@ -0,0 +1,221 @@
60527 +#ifndef __GRINTERNAL_H
60528 +#define __GRINTERNAL_H
60529 +
60530 +#ifdef CONFIG_GRKERNSEC
60531 +
60532 +#include <linux/fs.h>
60533 +#include <linux/mnt_namespace.h>
60534 +#include <linux/nsproxy.h>
60535 +#include <linux/gracl.h>
60536 +#include <linux/grdefs.h>
60537 +#include <linux/grmsg.h>
60538 +
60539 +void gr_add_learn_entry(const char *fmt, ...)
60540 + __attribute__ ((format (printf, 1, 2)));
60541 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60542 + const struct vfsmount *mnt);
60543 +__u32 gr_check_create(const struct dentry *new_dentry,
60544 + const struct dentry *parent,
60545 + const struct vfsmount *mnt, const __u32 mode);
60546 +int gr_check_protected_task(const struct task_struct *task);
60547 +__u32 to_gr_audit(const __u32 reqmode);
60548 +int gr_set_acls(const int type);
60549 +int gr_apply_subject_to_task(struct task_struct *task);
60550 +int gr_acl_is_enabled(void);
60551 +char gr_roletype_to_char(void);
60552 +
60553 +void gr_handle_alertkill(struct task_struct *task);
60554 +char *gr_to_filename(const struct dentry *dentry,
60555 + const struct vfsmount *mnt);
60556 +char *gr_to_filename1(const struct dentry *dentry,
60557 + const struct vfsmount *mnt);
60558 +char *gr_to_filename2(const struct dentry *dentry,
60559 + const struct vfsmount *mnt);
60560 +char *gr_to_filename3(const struct dentry *dentry,
60561 + const struct vfsmount *mnt);
60562 +
60563 +extern int grsec_enable_ptrace_readexec;
60564 +extern int grsec_enable_harden_ptrace;
60565 +extern int grsec_enable_link;
60566 +extern int grsec_enable_fifo;
60567 +extern int grsec_enable_execve;
60568 +extern int grsec_enable_shm;
60569 +extern int grsec_enable_execlog;
60570 +extern int grsec_enable_signal;
60571 +extern int grsec_enable_audit_ptrace;
60572 +extern int grsec_enable_forkfail;
60573 +extern int grsec_enable_time;
60574 +extern int grsec_enable_rofs;
60575 +extern int grsec_enable_chroot_shmat;
60576 +extern int grsec_enable_chroot_mount;
60577 +extern int grsec_enable_chroot_double;
60578 +extern int grsec_enable_chroot_pivot;
60579 +extern int grsec_enable_chroot_chdir;
60580 +extern int grsec_enable_chroot_chmod;
60581 +extern int grsec_enable_chroot_mknod;
60582 +extern int grsec_enable_chroot_fchdir;
60583 +extern int grsec_enable_chroot_nice;
60584 +extern int grsec_enable_chroot_execlog;
60585 +extern int grsec_enable_chroot_caps;
60586 +extern int grsec_enable_chroot_sysctl;
60587 +extern int grsec_enable_chroot_unix;
60588 +extern int grsec_enable_tpe;
60589 +extern int grsec_tpe_gid;
60590 +extern int grsec_enable_tpe_all;
60591 +extern int grsec_enable_tpe_invert;
60592 +extern int grsec_enable_socket_all;
60593 +extern int grsec_socket_all_gid;
60594 +extern int grsec_enable_socket_client;
60595 +extern int grsec_socket_client_gid;
60596 +extern int grsec_enable_socket_server;
60597 +extern int grsec_socket_server_gid;
60598 +extern int grsec_audit_gid;
60599 +extern int grsec_enable_group;
60600 +extern int grsec_enable_audit_textrel;
60601 +extern int grsec_enable_log_rwxmaps;
60602 +extern int grsec_enable_mount;
60603 +extern int grsec_enable_chdir;
60604 +extern int grsec_resource_logging;
60605 +extern int grsec_enable_blackhole;
60606 +extern int grsec_lastack_retries;
60607 +extern int grsec_enable_brute;
60608 +extern int grsec_lock;
60609 +
60610 +extern spinlock_t grsec_alert_lock;
60611 +extern unsigned long grsec_alert_wtime;
60612 +extern unsigned long grsec_alert_fyet;
60613 +
60614 +extern spinlock_t grsec_audit_lock;
60615 +
60616 +extern rwlock_t grsec_exec_file_lock;
60617 +
60618 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60619 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60620 + (tsk)->exec_file->f_vfsmnt) : "/")
60621 +
60622 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60623 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60624 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60625 +
60626 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60627 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
60628 + (tsk)->exec_file->f_vfsmnt) : "/")
60629 +
60630 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60631 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60632 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60633 +
60634 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60635 +
60636 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60637 +
60638 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60639 + (task)->pid, (cred)->uid, \
60640 + (cred)->euid, (cred)->gid, (cred)->egid, \
60641 + gr_parent_task_fullpath(task), \
60642 + (task)->real_parent->comm, (task)->real_parent->pid, \
60643 + (pcred)->uid, (pcred)->euid, \
60644 + (pcred)->gid, (pcred)->egid
60645 +
60646 +#define GR_CHROOT_CAPS {{ \
60647 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60648 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60649 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60650 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60651 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60652 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60653 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60654 +
60655 +#define security_learn(normal_msg,args...) \
60656 +({ \
60657 + read_lock(&grsec_exec_file_lock); \
60658 + gr_add_learn_entry(normal_msg "\n", ## args); \
60659 + read_unlock(&grsec_exec_file_lock); \
60660 +})
60661 +
60662 +enum {
60663 + GR_DO_AUDIT,
60664 + GR_DONT_AUDIT,
60665 + /* used for non-audit messages that we shouldn't kill the task on */
60666 + GR_DONT_AUDIT_GOOD
60667 +};
60668 +
60669 +enum {
60670 + GR_TTYSNIFF,
60671 + GR_RBAC,
60672 + GR_RBAC_STR,
60673 + GR_STR_RBAC,
60674 + GR_RBAC_MODE2,
60675 + GR_RBAC_MODE3,
60676 + GR_FILENAME,
60677 + GR_SYSCTL_HIDDEN,
60678 + GR_NOARGS,
60679 + GR_ONE_INT,
60680 + GR_ONE_INT_TWO_STR,
60681 + GR_ONE_STR,
60682 + GR_STR_INT,
60683 + GR_TWO_STR_INT,
60684 + GR_TWO_INT,
60685 + GR_TWO_U64,
60686 + GR_THREE_INT,
60687 + GR_FIVE_INT_TWO_STR,
60688 + GR_TWO_STR,
60689 + GR_THREE_STR,
60690 + GR_FOUR_STR,
60691 + GR_STR_FILENAME,
60692 + GR_FILENAME_STR,
60693 + GR_FILENAME_TWO_INT,
60694 + GR_FILENAME_TWO_INT_STR,
60695 + GR_TEXTREL,
60696 + GR_PTRACE,
60697 + GR_RESOURCE,
60698 + GR_CAP,
60699 + GR_SIG,
60700 + GR_SIG2,
60701 + GR_CRASH1,
60702 + GR_CRASH2,
60703 + GR_PSACCT,
60704 + GR_RWXMAP
60705 +};
60706 +
60707 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60708 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60709 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60710 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60711 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60712 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60713 +#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)
60714 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60715 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60716 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60717 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60718 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60719 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60720 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60721 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60722 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60723 +#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)
60724 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60725 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60726 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60727 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60728 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60729 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60730 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60731 +#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)
60732 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60733 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60734 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60735 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60736 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60737 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60738 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60739 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60740 +#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)
60741 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60742 +
60743 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60744 +
60745 +#endif
60746 +
60747 +#endif
60748 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60749 new file mode 100644
60750 index 0000000..ae576a1
60751 --- /dev/null
60752 +++ b/include/linux/grmsg.h
60753 @@ -0,0 +1,109 @@
60754 +#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"
60755 +#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"
60756 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60757 +#define GR_STOPMOD_MSG "denied modification of module state by "
60758 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60759 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60760 +#define GR_IOPERM_MSG "denied use of ioperm() by "
60761 +#define GR_IOPL_MSG "denied use of iopl() by "
60762 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60763 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60764 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60765 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60766 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60767 +#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"
60768 +#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"
60769 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60770 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60771 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60772 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60773 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60774 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60775 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60776 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60777 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60778 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60779 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60780 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60781 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60782 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60783 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60784 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
60785 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
60786 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
60787 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
60788 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
60789 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
60790 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
60791 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
60792 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
60793 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
60794 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
60795 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
60796 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
60797 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
60798 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
60799 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
60800 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
60801 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
60802 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
60803 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
60804 +#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"
60805 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
60806 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
60807 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
60808 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
60809 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
60810 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
60811 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
60812 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
60813 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
60814 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
60815 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
60816 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
60817 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
60818 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
60819 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
60820 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
60821 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
60822 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
60823 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
60824 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
60825 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
60826 +#define GR_NICE_CHROOT_MSG "denied priority change by "
60827 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
60828 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
60829 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
60830 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
60831 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
60832 +#define GR_TIME_MSG "time set by "
60833 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
60834 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
60835 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
60836 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
60837 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
60838 +#define GR_BIND_MSG "denied bind() by "
60839 +#define GR_CONNECT_MSG "denied connect() by "
60840 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
60841 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
60842 +#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"
60843 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
60844 +#define GR_CAP_ACL_MSG "use of %s denied for "
60845 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
60846 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
60847 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
60848 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
60849 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
60850 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
60851 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
60852 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
60853 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
60854 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
60855 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
60856 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
60857 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
60858 +#define GR_VM86_MSG "denied use of vm86 by "
60859 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
60860 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
60861 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
60862 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
60863 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
60864 new file mode 100644
60865 index 0000000..2ccf677
60866 --- /dev/null
60867 +++ b/include/linux/grsecurity.h
60868 @@ -0,0 +1,229 @@
60869 +#ifndef GR_SECURITY_H
60870 +#define GR_SECURITY_H
60871 +#include <linux/fs.h>
60872 +#include <linux/fs_struct.h>
60873 +#include <linux/binfmts.h>
60874 +#include <linux/gracl.h>
60875 +
60876 +/* notify of brain-dead configs */
60877 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60878 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
60879 +#endif
60880 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
60881 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
60882 +#endif
60883 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
60884 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
60885 +#endif
60886 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
60887 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
60888 +#endif
60889 +
60890 +#include <linux/compat.h>
60891 +
60892 +struct user_arg_ptr {
60893 +#ifdef CONFIG_COMPAT
60894 + bool is_compat;
60895 +#endif
60896 + union {
60897 + const char __user *const __user *native;
60898 +#ifdef CONFIG_COMPAT
60899 + compat_uptr_t __user *compat;
60900 +#endif
60901 + } ptr;
60902 +};
60903 +
60904 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
60905 +void gr_handle_brute_check(void);
60906 +void gr_handle_kernel_exploit(void);
60907 +int gr_process_user_ban(void);
60908 +
60909 +char gr_roletype_to_char(void);
60910 +
60911 +int gr_acl_enable_at_secure(void);
60912 +
60913 +int gr_check_user_change(int real, int effective, int fs);
60914 +int gr_check_group_change(int real, int effective, int fs);
60915 +
60916 +void gr_del_task_from_ip_table(struct task_struct *p);
60917 +
60918 +int gr_pid_is_chrooted(struct task_struct *p);
60919 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
60920 +int gr_handle_chroot_nice(void);
60921 +int gr_handle_chroot_sysctl(const int op);
60922 +int gr_handle_chroot_setpriority(struct task_struct *p,
60923 + const int niceval);
60924 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
60925 +int gr_handle_chroot_chroot(const struct dentry *dentry,
60926 + const struct vfsmount *mnt);
60927 +void gr_handle_chroot_chdir(struct path *path);
60928 +int gr_handle_chroot_chmod(const struct dentry *dentry,
60929 + const struct vfsmount *mnt, const int mode);
60930 +int gr_handle_chroot_mknod(const struct dentry *dentry,
60931 + const struct vfsmount *mnt, const int mode);
60932 +int gr_handle_chroot_mount(const struct dentry *dentry,
60933 + const struct vfsmount *mnt,
60934 + const char *dev_name);
60935 +int gr_handle_chroot_pivot(void);
60936 +int gr_handle_chroot_unix(const pid_t pid);
60937 +
60938 +int gr_handle_rawio(const struct inode *inode);
60939 +
60940 +void gr_handle_ioperm(void);
60941 +void gr_handle_iopl(void);
60942 +
60943 +umode_t gr_acl_umask(void);
60944 +
60945 +int gr_tpe_allow(const struct file *file);
60946 +
60947 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
60948 +void gr_clear_chroot_entries(struct task_struct *task);
60949 +
60950 +void gr_log_forkfail(const int retval);
60951 +void gr_log_timechange(void);
60952 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
60953 +void gr_log_chdir(const struct dentry *dentry,
60954 + const struct vfsmount *mnt);
60955 +void gr_log_chroot_exec(const struct dentry *dentry,
60956 + const struct vfsmount *mnt);
60957 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
60958 +void gr_log_remount(const char *devname, const int retval);
60959 +void gr_log_unmount(const char *devname, const int retval);
60960 +void gr_log_mount(const char *from, const char *to, const int retval);
60961 +void gr_log_textrel(struct vm_area_struct *vma);
60962 +void gr_log_rwxmmap(struct file *file);
60963 +void gr_log_rwxmprotect(struct file *file);
60964 +
60965 +int gr_handle_follow_link(const struct inode *parent,
60966 + const struct inode *inode,
60967 + const struct dentry *dentry,
60968 + const struct vfsmount *mnt);
60969 +int gr_handle_fifo(const struct dentry *dentry,
60970 + const struct vfsmount *mnt,
60971 + const struct dentry *dir, const int flag,
60972 + const int acc_mode);
60973 +int gr_handle_hardlink(const struct dentry *dentry,
60974 + const struct vfsmount *mnt,
60975 + struct inode *inode,
60976 + const int mode, const char *to);
60977 +
60978 +int gr_is_capable(const int cap);
60979 +int gr_is_capable_nolog(const int cap);
60980 +void gr_learn_resource(const struct task_struct *task, const int limit,
60981 + const unsigned long wanted, const int gt);
60982 +void gr_copy_label(struct task_struct *tsk);
60983 +void gr_handle_crash(struct task_struct *task, const int sig);
60984 +int gr_handle_signal(const struct task_struct *p, const int sig);
60985 +int gr_check_crash_uid(const uid_t uid);
60986 +int gr_check_protected_task(const struct task_struct *task);
60987 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
60988 +int gr_acl_handle_mmap(const struct file *file,
60989 + const unsigned long prot);
60990 +int gr_acl_handle_mprotect(const struct file *file,
60991 + const unsigned long prot);
60992 +int gr_check_hidden_task(const struct task_struct *tsk);
60993 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
60994 + const struct vfsmount *mnt);
60995 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
60996 + const struct vfsmount *mnt);
60997 +__u32 gr_acl_handle_access(const struct dentry *dentry,
60998 + const struct vfsmount *mnt, const int fmode);
60999 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61000 + const struct vfsmount *mnt, umode_t *mode);
61001 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61002 + const struct vfsmount *mnt);
61003 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61004 + const struct vfsmount *mnt);
61005 +int gr_handle_ptrace(struct task_struct *task, const long request);
61006 +int gr_handle_proc_ptrace(struct task_struct *task);
61007 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61008 + const struct vfsmount *mnt);
61009 +int gr_check_crash_exec(const struct file *filp);
61010 +int gr_acl_is_enabled(void);
61011 +void gr_set_kernel_label(struct task_struct *task);
61012 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61013 + const gid_t gid);
61014 +int gr_set_proc_label(const struct dentry *dentry,
61015 + const struct vfsmount *mnt,
61016 + const int unsafe_flags);
61017 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61018 + const struct vfsmount *mnt);
61019 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61020 + const struct vfsmount *mnt, int acc_mode);
61021 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61022 + const struct dentry *p_dentry,
61023 + const struct vfsmount *p_mnt,
61024 + int open_flags, int acc_mode, const int imode);
61025 +void gr_handle_create(const struct dentry *dentry,
61026 + const struct vfsmount *mnt);
61027 +void gr_handle_proc_create(const struct dentry *dentry,
61028 + const struct inode *inode);
61029 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61030 + const struct dentry *parent_dentry,
61031 + const struct vfsmount *parent_mnt,
61032 + const int mode);
61033 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61034 + const struct dentry *parent_dentry,
61035 + const struct vfsmount *parent_mnt);
61036 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61037 + const struct vfsmount *mnt);
61038 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61039 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61040 + const struct vfsmount *mnt);
61041 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61042 + const struct dentry *parent_dentry,
61043 + const struct vfsmount *parent_mnt,
61044 + const char *from);
61045 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61046 + const struct dentry *parent_dentry,
61047 + const struct vfsmount *parent_mnt,
61048 + const struct dentry *old_dentry,
61049 + const struct vfsmount *old_mnt, const char *to);
61050 +int gr_acl_handle_rename(struct dentry *new_dentry,
61051 + struct dentry *parent_dentry,
61052 + const struct vfsmount *parent_mnt,
61053 + struct dentry *old_dentry,
61054 + struct inode *old_parent_inode,
61055 + struct vfsmount *old_mnt, const char *newname);
61056 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61057 + struct dentry *old_dentry,
61058 + struct dentry *new_dentry,
61059 + struct vfsmount *mnt, const __u8 replace);
61060 +__u32 gr_check_link(const struct dentry *new_dentry,
61061 + const struct dentry *parent_dentry,
61062 + const struct vfsmount *parent_mnt,
61063 + const struct dentry *old_dentry,
61064 + const struct vfsmount *old_mnt);
61065 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61066 + const unsigned int namelen, const ino_t ino);
61067 +
61068 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61069 + const struct vfsmount *mnt);
61070 +void gr_acl_handle_exit(void);
61071 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61072 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61073 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61074 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61075 +void gr_audit_ptrace(struct task_struct *task);
61076 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61077 +
61078 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61079 +
61080 +#ifdef CONFIG_GRKERNSEC
61081 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61082 +void gr_handle_vm86(void);
61083 +void gr_handle_mem_readwrite(u64 from, u64 to);
61084 +
61085 +void gr_log_badprocpid(const char *entry);
61086 +
61087 +extern int grsec_enable_dmesg;
61088 +extern int grsec_disable_privio;
61089 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61090 +extern int grsec_enable_chroot_findtask;
61091 +#endif
61092 +#ifdef CONFIG_GRKERNSEC_SETXID
61093 +extern int grsec_enable_setxid;
61094 +#endif
61095 +#endif
61096 +
61097 +#endif
61098 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61099 new file mode 100644
61100 index 0000000..e7ffaaf
61101 --- /dev/null
61102 +++ b/include/linux/grsock.h
61103 @@ -0,0 +1,19 @@
61104 +#ifndef __GRSOCK_H
61105 +#define __GRSOCK_H
61106 +
61107 +extern void gr_attach_curr_ip(const struct sock *sk);
61108 +extern int gr_handle_sock_all(const int family, const int type,
61109 + const int protocol);
61110 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61111 +extern int gr_handle_sock_server_other(const struct sock *sck);
61112 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61113 +extern int gr_search_connect(struct socket * sock,
61114 + struct sockaddr_in * addr);
61115 +extern int gr_search_bind(struct socket * sock,
61116 + struct sockaddr_in * addr);
61117 +extern int gr_search_listen(struct socket * sock);
61118 +extern int gr_search_accept(struct socket * sock);
61119 +extern int gr_search_socket(const int domain, const int type,
61120 + const int protocol);
61121 +
61122 +#endif
61123 diff --git a/include/linux/hid.h b/include/linux/hid.h
61124 index c235e4e..f0cf7a0 100644
61125 --- a/include/linux/hid.h
61126 +++ b/include/linux/hid.h
61127 @@ -679,7 +679,7 @@ struct hid_ll_driver {
61128 unsigned int code, int value);
61129
61130 int (*parse)(struct hid_device *hdev);
61131 -};
61132 +} __no_const;
61133
61134 #define PM_HINT_FULLON 1<<5
61135 #define PM_HINT_NORMAL 1<<1
61136 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61137 index 3a93f73..b19d0b3 100644
61138 --- a/include/linux/highmem.h
61139 +++ b/include/linux/highmem.h
61140 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61141 kunmap_atomic(kaddr, KM_USER0);
61142 }
61143
61144 +static inline void sanitize_highpage(struct page *page)
61145 +{
61146 + void *kaddr;
61147 + unsigned long flags;
61148 +
61149 + local_irq_save(flags);
61150 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
61151 + clear_page(kaddr);
61152 + kunmap_atomic(kaddr, KM_CLEARPAGE);
61153 + local_irq_restore(flags);
61154 +}
61155 +
61156 static inline void zero_user_segments(struct page *page,
61157 unsigned start1, unsigned end1,
61158 unsigned start2, unsigned end2)
61159 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61160 index 07d103a..04ec65b 100644
61161 --- a/include/linux/i2c.h
61162 +++ b/include/linux/i2c.h
61163 @@ -364,6 +364,7 @@ struct i2c_algorithm {
61164 /* To determine what the adapter supports */
61165 u32 (*functionality) (struct i2c_adapter *);
61166 };
61167 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61168
61169 /*
61170 * i2c_adapter is the structure used to identify a physical i2c bus along
61171 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61172 index a6deef4..c56a7f2 100644
61173 --- a/include/linux/i2o.h
61174 +++ b/include/linux/i2o.h
61175 @@ -564,7 +564,7 @@ struct i2o_controller {
61176 struct i2o_device *exec; /* Executive */
61177 #if BITS_PER_LONG == 64
61178 spinlock_t context_list_lock; /* lock for context_list */
61179 - atomic_t context_list_counter; /* needed for unique contexts */
61180 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61181 struct list_head context_list; /* list of context id's
61182 and pointers */
61183 #endif
61184 diff --git a/include/linux/init.h b/include/linux/init.h
61185 index 9146f39..885354d 100644
61186 --- a/include/linux/init.h
61187 +++ b/include/linux/init.h
61188 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
61189
61190 /* Each module must use one module_init(). */
61191 #define module_init(initfn) \
61192 - static inline initcall_t __inittest(void) \
61193 + static inline __used initcall_t __inittest(void) \
61194 { return initfn; } \
61195 int init_module(void) __attribute__((alias(#initfn)));
61196
61197 /* This is only required if you want to be unloadable. */
61198 #define module_exit(exitfn) \
61199 - static inline exitcall_t __exittest(void) \
61200 + static inline __used exitcall_t __exittest(void) \
61201 { return exitfn; } \
61202 void cleanup_module(void) __attribute__((alias(#exitfn)));
61203
61204 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61205 index 32574ee..00d4ef1 100644
61206 --- a/include/linux/init_task.h
61207 +++ b/include/linux/init_task.h
61208 @@ -128,6 +128,12 @@ extern struct cred init_cred;
61209
61210 #define INIT_TASK_COMM "swapper"
61211
61212 +#ifdef CONFIG_X86
61213 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61214 +#else
61215 +#define INIT_TASK_THREAD_INFO
61216 +#endif
61217 +
61218 /*
61219 * INIT_TASK is used to set up the first task table, touch at
61220 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61221 @@ -166,6 +172,7 @@ extern struct cred init_cred;
61222 RCU_INIT_POINTER(.cred, &init_cred), \
61223 .comm = INIT_TASK_COMM, \
61224 .thread = INIT_THREAD, \
61225 + INIT_TASK_THREAD_INFO \
61226 .fs = &init_fs, \
61227 .files = &init_files, \
61228 .signal = &init_signals, \
61229 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61230 index e6ca56d..8583707 100644
61231 --- a/include/linux/intel-iommu.h
61232 +++ b/include/linux/intel-iommu.h
61233 @@ -296,7 +296,7 @@ struct iommu_flush {
61234 u8 fm, u64 type);
61235 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61236 unsigned int size_order, u64 type);
61237 -};
61238 +} __no_const;
61239
61240 enum {
61241 SR_DMAR_FECTL_REG,
61242 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61243 index a64b00e..464d8bc 100644
61244 --- a/include/linux/interrupt.h
61245 +++ b/include/linux/interrupt.h
61246 @@ -441,7 +441,7 @@ enum
61247 /* map softirq index to softirq name. update 'softirq_to_name' in
61248 * kernel/softirq.c when adding a new softirq.
61249 */
61250 -extern char *softirq_to_name[NR_SOFTIRQS];
61251 +extern const char * const softirq_to_name[NR_SOFTIRQS];
61252
61253 /* softirq mask and active fields moved to irq_cpustat_t in
61254 * asm/hardirq.h to get better cache usage. KAO
61255 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61256
61257 struct softirq_action
61258 {
61259 - void (*action)(struct softirq_action *);
61260 + void (*action)(void);
61261 };
61262
61263 asmlinkage void do_softirq(void);
61264 asmlinkage void __do_softirq(void);
61265 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61266 +extern void open_softirq(int nr, void (*action)(void));
61267 extern void softirq_init(void);
61268 static inline void __raise_softirq_irqoff(unsigned int nr)
61269 {
61270 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
61271 index 3875719..4cd454c 100644
61272 --- a/include/linux/kallsyms.h
61273 +++ b/include/linux/kallsyms.h
61274 @@ -15,7 +15,8 @@
61275
61276 struct module;
61277
61278 -#ifdef CONFIG_KALLSYMS
61279 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
61280 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61281 /* Lookup the address for a symbol. Returns 0 if not found. */
61282 unsigned long kallsyms_lookup_name(const char *name);
61283
61284 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
61285 /* Stupid that this does nothing, but I didn't create this mess. */
61286 #define __print_symbol(fmt, addr)
61287 #endif /*CONFIG_KALLSYMS*/
61288 +#else /* when included by kallsyms.c, vsnprintf.c, or
61289 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
61290 +extern void __print_symbol(const char *fmt, unsigned long address);
61291 +extern int sprint_backtrace(char *buffer, unsigned long address);
61292 +extern int sprint_symbol(char *buffer, unsigned long address);
61293 +const char *kallsyms_lookup(unsigned long addr,
61294 + unsigned long *symbolsize,
61295 + unsigned long *offset,
61296 + char **modname, char *namebuf);
61297 +#endif
61298
61299 /* This macro allows us to keep printk typechecking */
61300 static __printf(1, 2)
61301 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61302 index fa39183..40160be 100644
61303 --- a/include/linux/kgdb.h
61304 +++ b/include/linux/kgdb.h
61305 @@ -53,7 +53,7 @@ extern int kgdb_connected;
61306 extern int kgdb_io_module_registered;
61307
61308 extern atomic_t kgdb_setting_breakpoint;
61309 -extern atomic_t kgdb_cpu_doing_single_step;
61310 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61311
61312 extern struct task_struct *kgdb_usethread;
61313 extern struct task_struct *kgdb_contthread;
61314 @@ -251,7 +251,7 @@ struct kgdb_arch {
61315 void (*disable_hw_break)(struct pt_regs *regs);
61316 void (*remove_all_hw_break)(void);
61317 void (*correct_hw_break)(void);
61318 -};
61319 +} __do_const;
61320
61321 /**
61322 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61323 @@ -276,7 +276,7 @@ struct kgdb_io {
61324 void (*pre_exception) (void);
61325 void (*post_exception) (void);
61326 int is_console;
61327 -};
61328 +} __do_const;
61329
61330 extern struct kgdb_arch arch_kgdb_ops;
61331
61332 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61333 index b16f653..eb908f4 100644
61334 --- a/include/linux/kmod.h
61335 +++ b/include/linux/kmod.h
61336 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61337 * usually useless though. */
61338 extern __printf(2, 3)
61339 int __request_module(bool wait, const char *name, ...);
61340 +extern __printf(3, 4)
61341 +int ___request_module(bool wait, char *param_name, const char *name, ...);
61342 #define request_module(mod...) __request_module(true, mod)
61343 #define request_module_nowait(mod...) __request_module(false, mod)
61344 #define try_then_request_module(x, mod...) \
61345 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61346 index d526231..086e89b 100644
61347 --- a/include/linux/kvm_host.h
61348 +++ b/include/linux/kvm_host.h
61349 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61350 void vcpu_load(struct kvm_vcpu *vcpu);
61351 void vcpu_put(struct kvm_vcpu *vcpu);
61352
61353 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61354 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61355 struct module *module);
61356 void kvm_exit(void);
61357
61358 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61359 struct kvm_guest_debug *dbg);
61360 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61361
61362 -int kvm_arch_init(void *opaque);
61363 +int kvm_arch_init(const void *opaque);
61364 void kvm_arch_exit(void);
61365
61366 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61367 diff --git a/include/linux/libata.h b/include/linux/libata.h
61368 index cafc09a..d7e7829 100644
61369 --- a/include/linux/libata.h
61370 +++ b/include/linux/libata.h
61371 @@ -909,7 +909,7 @@ struct ata_port_operations {
61372 * fields must be pointers.
61373 */
61374 const struct ata_port_operations *inherits;
61375 -};
61376 +} __do_const;
61377
61378 struct ata_port_info {
61379 unsigned long flags;
61380 diff --git a/include/linux/mca.h b/include/linux/mca.h
61381 index 3797270..7765ede 100644
61382 --- a/include/linux/mca.h
61383 +++ b/include/linux/mca.h
61384 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61385 int region);
61386 void * (*mca_transform_memory)(struct mca_device *,
61387 void *memory);
61388 -};
61389 +} __no_const;
61390
61391 struct mca_bus {
61392 u64 default_dma_mask;
61393 diff --git a/include/linux/memory.h b/include/linux/memory.h
61394 index 935699b..11042cc 100644
61395 --- a/include/linux/memory.h
61396 +++ b/include/linux/memory.h
61397 @@ -144,7 +144,7 @@ struct memory_accessor {
61398 size_t count);
61399 ssize_t (*write)(struct memory_accessor *, const char *buf,
61400 off_t offset, size_t count);
61401 -};
61402 +} __no_const;
61403
61404 /*
61405 * Kernel text modification mutex, used for code patching. Users of this lock
61406 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61407 index 9970337..9444122 100644
61408 --- a/include/linux/mfd/abx500.h
61409 +++ b/include/linux/mfd/abx500.h
61410 @@ -188,6 +188,7 @@ struct abx500_ops {
61411 int (*event_registers_startup_state_get) (struct device *, u8 *);
61412 int (*startup_irq_enabled) (struct device *, unsigned int);
61413 };
61414 +typedef struct abx500_ops __no_const abx500_ops_no_const;
61415
61416 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61417 void abx500_remove_ops(struct device *dev);
61418 diff --git a/include/linux/mm.h b/include/linux/mm.h
61419 index 4baadd1..2e0b45e 100644
61420 --- a/include/linux/mm.h
61421 +++ b/include/linux/mm.h
61422 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
61423
61424 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61425 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61426 +
61427 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61428 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61429 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61430 +#else
61431 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61432 +#endif
61433 +
61434 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61435 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61436
61437 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
61438 int set_page_dirty_lock(struct page *page);
61439 int clear_page_dirty_for_io(struct page *page);
61440
61441 -/* Is the vma a continuation of the stack vma above it? */
61442 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61443 -{
61444 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61445 -}
61446 -
61447 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
61448 - unsigned long addr)
61449 -{
61450 - return (vma->vm_flags & VM_GROWSDOWN) &&
61451 - (vma->vm_start == addr) &&
61452 - !vma_growsdown(vma->vm_prev, addr);
61453 -}
61454 -
61455 -/* Is the vma a continuation of the stack vma below it? */
61456 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61457 -{
61458 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61459 -}
61460 -
61461 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
61462 - unsigned long addr)
61463 -{
61464 - return (vma->vm_flags & VM_GROWSUP) &&
61465 - (vma->vm_end == addr) &&
61466 - !vma_growsup(vma->vm_next, addr);
61467 -}
61468 -
61469 extern unsigned long move_page_tables(struct vm_area_struct *vma,
61470 unsigned long old_addr, struct vm_area_struct *new_vma,
61471 unsigned long new_addr, unsigned long len);
61472 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
61473 }
61474 #endif
61475
61476 +#ifdef CONFIG_MMU
61477 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61478 +#else
61479 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61480 +{
61481 + return __pgprot(0);
61482 +}
61483 +#endif
61484 +
61485 int vma_wants_writenotify(struct vm_area_struct *vma);
61486
61487 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61488 @@ -1419,6 +1407,7 @@ out:
61489 }
61490
61491 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61492 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61493
61494 extern unsigned long do_brk(unsigned long, unsigned long);
61495
61496 @@ -1476,6 +1465,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61497 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61498 struct vm_area_struct **pprev);
61499
61500 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61501 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61502 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61503 +
61504 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61505 NULL if none. Assume start_addr < end_addr. */
61506 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61507 @@ -1492,15 +1485,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
61508 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
61509 }
61510
61511 -#ifdef CONFIG_MMU
61512 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
61513 -#else
61514 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61515 -{
61516 - return __pgprot(0);
61517 -}
61518 -#endif
61519 -
61520 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61521 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61522 unsigned long pfn, unsigned long size, pgprot_t);
61523 @@ -1614,7 +1598,7 @@ extern int unpoison_memory(unsigned long pfn);
61524 extern int sysctl_memory_failure_early_kill;
61525 extern int sysctl_memory_failure_recovery;
61526 extern void shake_page(struct page *p, int access);
61527 -extern atomic_long_t mce_bad_pages;
61528 +extern atomic_long_unchecked_t mce_bad_pages;
61529 extern int soft_offline_page(struct page *page, int flags);
61530
61531 extern void dump_page(struct page *page);
61532 @@ -1628,5 +1612,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
61533 unsigned int pages_per_huge_page);
61534 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
61535
61536 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61537 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61538 +#else
61539 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61540 +#endif
61541 +
61542 #endif /* __KERNEL__ */
61543 #endif /* _LINUX_MM_H */
61544 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61545 index 5b42f1b..759e4b4 100644
61546 --- a/include/linux/mm_types.h
61547 +++ b/include/linux/mm_types.h
61548 @@ -253,6 +253,8 @@ struct vm_area_struct {
61549 #ifdef CONFIG_NUMA
61550 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61551 #endif
61552 +
61553 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61554 };
61555
61556 struct core_thread {
61557 @@ -389,6 +391,24 @@ struct mm_struct {
61558 #ifdef CONFIG_CPUMASK_OFFSTACK
61559 struct cpumask cpumask_allocation;
61560 #endif
61561 +
61562 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61563 + unsigned long pax_flags;
61564 +#endif
61565 +
61566 +#ifdef CONFIG_PAX_DLRESOLVE
61567 + unsigned long call_dl_resolve;
61568 +#endif
61569 +
61570 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61571 + unsigned long call_syscall;
61572 +#endif
61573 +
61574 +#ifdef CONFIG_PAX_ASLR
61575 + unsigned long delta_mmap; /* randomized offset */
61576 + unsigned long delta_stack; /* randomized offset */
61577 +#endif
61578 +
61579 };
61580
61581 static inline void mm_init_cpumask(struct mm_struct *mm)
61582 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61583 index 1d1b1e1..2a13c78 100644
61584 --- a/include/linux/mmu_notifier.h
61585 +++ b/include/linux/mmu_notifier.h
61586 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61587 */
61588 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61589 ({ \
61590 - pte_t __pte; \
61591 + pte_t ___pte; \
61592 struct vm_area_struct *___vma = __vma; \
61593 unsigned long ___address = __address; \
61594 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61595 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61596 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61597 - __pte; \
61598 + ___pte; \
61599 })
61600
61601 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61602 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61603 index 188cb2f..d78409b 100644
61604 --- a/include/linux/mmzone.h
61605 +++ b/include/linux/mmzone.h
61606 @@ -369,7 +369,7 @@ struct zone {
61607 unsigned long flags; /* zone flags, see below */
61608
61609 /* Zone statistics */
61610 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61611 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61612
61613 /*
61614 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61615 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61616 index 468819c..17b9db3 100644
61617 --- a/include/linux/mod_devicetable.h
61618 +++ b/include/linux/mod_devicetable.h
61619 @@ -12,7 +12,7 @@
61620 typedef unsigned long kernel_ulong_t;
61621 #endif
61622
61623 -#define PCI_ANY_ID (~0)
61624 +#define PCI_ANY_ID ((__u16)~0)
61625
61626 struct pci_device_id {
61627 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61628 @@ -131,7 +131,7 @@ struct usb_device_id {
61629 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61630 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61631
61632 -#define HID_ANY_ID (~0)
61633 +#define HID_ANY_ID (~0U)
61634
61635 struct hid_device_id {
61636 __u16 bus;
61637 diff --git a/include/linux/module.h b/include/linux/module.h
61638 index 3cb7839..511cb87 100644
61639 --- a/include/linux/module.h
61640 +++ b/include/linux/module.h
61641 @@ -17,6 +17,7 @@
61642 #include <linux/moduleparam.h>
61643 #include <linux/tracepoint.h>
61644 #include <linux/export.h>
61645 +#include <linux/fs.h>
61646
61647 #include <linux/percpu.h>
61648 #include <asm/module.h>
61649 @@ -261,19 +262,16 @@ struct module
61650 int (*init)(void);
61651
61652 /* If this is non-NULL, vfree after init() returns */
61653 - void *module_init;
61654 + void *module_init_rx, *module_init_rw;
61655
61656 /* Here is the actual code + data, vfree'd on unload. */
61657 - void *module_core;
61658 + void *module_core_rx, *module_core_rw;
61659
61660 /* Here are the sizes of the init and core sections */
61661 - unsigned int init_size, core_size;
61662 + unsigned int init_size_rw, core_size_rw;
61663
61664 /* The size of the executable code in each section. */
61665 - unsigned int init_text_size, core_text_size;
61666 -
61667 - /* Size of RO sections of the module (text+rodata) */
61668 - unsigned int init_ro_size, core_ro_size;
61669 + unsigned int init_size_rx, core_size_rx;
61670
61671 /* Arch-specific module values */
61672 struct mod_arch_specific arch;
61673 @@ -329,6 +327,10 @@ struct module
61674 #ifdef CONFIG_EVENT_TRACING
61675 struct ftrace_event_call **trace_events;
61676 unsigned int num_trace_events;
61677 + struct file_operations trace_id;
61678 + struct file_operations trace_enable;
61679 + struct file_operations trace_format;
61680 + struct file_operations trace_filter;
61681 #endif
61682 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
61683 unsigned int num_ftrace_callsites;
61684 @@ -379,16 +381,46 @@ bool is_module_address(unsigned long addr);
61685 bool is_module_percpu_address(unsigned long addr);
61686 bool is_module_text_address(unsigned long addr);
61687
61688 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
61689 +{
61690 +
61691 +#ifdef CONFIG_PAX_KERNEXEC
61692 + if (ktla_ktva(addr) >= (unsigned long)start &&
61693 + ktla_ktva(addr) < (unsigned long)start + size)
61694 + return 1;
61695 +#endif
61696 +
61697 + return ((void *)addr >= start && (void *)addr < start + size);
61698 +}
61699 +
61700 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
61701 +{
61702 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
61703 +}
61704 +
61705 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
61706 +{
61707 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
61708 +}
61709 +
61710 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
61711 +{
61712 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
61713 +}
61714 +
61715 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
61716 +{
61717 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
61718 +}
61719 +
61720 static inline int within_module_core(unsigned long addr, struct module *mod)
61721 {
61722 - return (unsigned long)mod->module_core <= addr &&
61723 - addr < (unsigned long)mod->module_core + mod->core_size;
61724 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
61725 }
61726
61727 static inline int within_module_init(unsigned long addr, struct module *mod)
61728 {
61729 - return (unsigned long)mod->module_init <= addr &&
61730 - addr < (unsigned long)mod->module_init + mod->init_size;
61731 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
61732 }
61733
61734 /* Search for module by name: must hold module_mutex. */
61735 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
61736 index b2be02e..6a9fdb1 100644
61737 --- a/include/linux/moduleloader.h
61738 +++ b/include/linux/moduleloader.h
61739 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
61740 sections. Returns NULL on failure. */
61741 void *module_alloc(unsigned long size);
61742
61743 +#ifdef CONFIG_PAX_KERNEXEC
61744 +void *module_alloc_exec(unsigned long size);
61745 +#else
61746 +#define module_alloc_exec(x) module_alloc(x)
61747 +#endif
61748 +
61749 /* Free memory returned from module_alloc. */
61750 void module_free(struct module *mod, void *module_region);
61751
61752 +#ifdef CONFIG_PAX_KERNEXEC
61753 +void module_free_exec(struct module *mod, void *module_region);
61754 +#else
61755 +#define module_free_exec(x, y) module_free((x), (y))
61756 +#endif
61757 +
61758 /* Apply the given relocation to the (simplified) ELF. Return -error
61759 or 0. */
61760 int apply_relocate(Elf_Shdr *sechdrs,
61761 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
61762 index 7939f63..ec6df57 100644
61763 --- a/include/linux/moduleparam.h
61764 +++ b/include/linux/moduleparam.h
61765 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
61766 * @len is usually just sizeof(string).
61767 */
61768 #define module_param_string(name, string, len, perm) \
61769 - static const struct kparam_string __param_string_##name \
61770 + static const struct kparam_string __param_string_##name __used \
61771 = { len, string }; \
61772 __module_param_call(MODULE_PARAM_PREFIX, name, \
61773 &param_ops_string, \
61774 @@ -395,7 +395,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
61775 * module_param_named() for why this might be necessary.
61776 */
61777 #define module_param_array_named(name, array, type, nump, perm) \
61778 - static const struct kparam_array __param_arr_##name \
61779 + static const struct kparam_array __param_arr_##name __used \
61780 = { .max = ARRAY_SIZE(array), .num = nump, \
61781 .ops = &param_ops_##type, \
61782 .elemsize = sizeof(array[0]), .elem = array }; \
61783 diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
61784 index a9e6ba4..0f9e29b 100644
61785 --- a/include/linux/mtd/map.h
61786 +++ b/include/linux/mtd/map.h
61787 @@ -25,6 +25,7 @@
61788 #include <linux/types.h>
61789 #include <linux/list.h>
61790 #include <linux/string.h>
61791 +#include <linux/kernel.h>
61792 #include <linux/bug.h>
61793
61794
61795 diff --git a/include/linux/namei.h b/include/linux/namei.h
61796 index ffc0213..2c1f2cb 100644
61797 --- a/include/linux/namei.h
61798 +++ b/include/linux/namei.h
61799 @@ -24,7 +24,7 @@ struct nameidata {
61800 unsigned seq;
61801 int last_type;
61802 unsigned depth;
61803 - char *saved_names[MAX_NESTED_LINKS + 1];
61804 + const char *saved_names[MAX_NESTED_LINKS + 1];
61805
61806 /* Intent data */
61807 union {
61808 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
61809 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
61810 extern void unlock_rename(struct dentry *, struct dentry *);
61811
61812 -static inline void nd_set_link(struct nameidata *nd, char *path)
61813 +static inline void nd_set_link(struct nameidata *nd, const char *path)
61814 {
61815 nd->saved_names[nd->depth] = path;
61816 }
61817
61818 -static inline char *nd_get_link(struct nameidata *nd)
61819 +static inline const char *nd_get_link(const struct nameidata *nd)
61820 {
61821 return nd->saved_names[nd->depth];
61822 }
61823 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
61824 index a82ad4d..90d15b7 100644
61825 --- a/include/linux/netdevice.h
61826 +++ b/include/linux/netdevice.h
61827 @@ -949,6 +949,7 @@ struct net_device_ops {
61828 int (*ndo_set_features)(struct net_device *dev,
61829 u32 features);
61830 };
61831 +typedef struct net_device_ops __no_const net_device_ops_no_const;
61832
61833 /*
61834 * The DEVICE structure.
61835 @@ -1088,7 +1089,7 @@ struct net_device {
61836 int iflink;
61837
61838 struct net_device_stats stats;
61839 - atomic_long_t rx_dropped; /* dropped packets by core network
61840 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
61841 * Do not use this in drivers.
61842 */
61843
61844 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
61845 new file mode 100644
61846 index 0000000..33f4af8
61847 --- /dev/null
61848 +++ b/include/linux/netfilter/xt_gradm.h
61849 @@ -0,0 +1,9 @@
61850 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
61851 +#define _LINUX_NETFILTER_XT_GRADM_H 1
61852 +
61853 +struct xt_gradm_mtinfo {
61854 + __u16 flags;
61855 + __u16 invflags;
61856 +};
61857 +
61858 +#endif
61859 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
61860 index c65a18a..0c05f3a 100644
61861 --- a/include/linux/of_pdt.h
61862 +++ b/include/linux/of_pdt.h
61863 @@ -32,7 +32,7 @@ struct of_pdt_ops {
61864
61865 /* return 0 on success; fill in 'len' with number of bytes in path */
61866 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
61867 -};
61868 +} __no_const;
61869
61870 extern void *prom_early_alloc(unsigned long size);
61871
61872 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
61873 index a4c5624..79d6d88 100644
61874 --- a/include/linux/oprofile.h
61875 +++ b/include/linux/oprofile.h
61876 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
61877 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
61878 char const * name, ulong * val);
61879
61880 -/** Create a file for read-only access to an atomic_t. */
61881 +/** Create a file for read-only access to an atomic_unchecked_t. */
61882 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
61883 - char const * name, atomic_t * val);
61884 + char const * name, atomic_unchecked_t * val);
61885
61886 /** create a directory */
61887 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
61888 diff --git a/include/linux/padata.h b/include/linux/padata.h
61889 index 4633b2f..988bc08 100644
61890 --- a/include/linux/padata.h
61891 +++ b/include/linux/padata.h
61892 @@ -129,7 +129,7 @@ struct parallel_data {
61893 struct padata_instance *pinst;
61894 struct padata_parallel_queue __percpu *pqueue;
61895 struct padata_serial_queue __percpu *squeue;
61896 - atomic_t seq_nr;
61897 + atomic_unchecked_t seq_nr;
61898 atomic_t reorder_objects;
61899 atomic_t refcnt;
61900 unsigned int max_seq_nr;
61901 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
61902 index b1f8912..c955bff 100644
61903 --- a/include/linux/perf_event.h
61904 +++ b/include/linux/perf_event.h
61905 @@ -748,8 +748,8 @@ struct perf_event {
61906
61907 enum perf_event_active_state state;
61908 unsigned int attach_state;
61909 - local64_t count;
61910 - atomic64_t child_count;
61911 + local64_t count; /* PaX: fix it one day */
61912 + atomic64_unchecked_t child_count;
61913
61914 /*
61915 * These are the total time in nanoseconds that the event
61916 @@ -800,8 +800,8 @@ struct perf_event {
61917 * These accumulate total time (in nanoseconds) that children
61918 * events have been enabled and running, respectively.
61919 */
61920 - atomic64_t child_total_time_enabled;
61921 - atomic64_t child_total_time_running;
61922 + atomic64_unchecked_t child_total_time_enabled;
61923 + atomic64_unchecked_t child_total_time_running;
61924
61925 /*
61926 * Protect attach/detach and child_list:
61927 diff --git a/include/linux/personality.h b/include/linux/personality.h
61928 index 8fc7dd1a..c19d89e 100644
61929 --- a/include/linux/personality.h
61930 +++ b/include/linux/personality.h
61931 @@ -44,6 +44,7 @@ enum {
61932 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
61933 ADDR_NO_RANDOMIZE | \
61934 ADDR_COMPAT_LAYOUT | \
61935 + ADDR_LIMIT_3GB | \
61936 MMAP_PAGE_ZERO)
61937
61938 /*
61939 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
61940 index 77257c9..51d473a 100644
61941 --- a/include/linux/pipe_fs_i.h
61942 +++ b/include/linux/pipe_fs_i.h
61943 @@ -46,9 +46,9 @@ struct pipe_buffer {
61944 struct pipe_inode_info {
61945 wait_queue_head_t wait;
61946 unsigned int nrbufs, curbuf, buffers;
61947 - unsigned int readers;
61948 - unsigned int writers;
61949 - unsigned int waiting_writers;
61950 + atomic_t readers;
61951 + atomic_t writers;
61952 + atomic_t waiting_writers;
61953 unsigned int r_counter;
61954 unsigned int w_counter;
61955 struct page *tmp_page;
61956 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
61957 index d3085e7..fd01052 100644
61958 --- a/include/linux/pm_runtime.h
61959 +++ b/include/linux/pm_runtime.h
61960 @@ -95,7 +95,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
61961
61962 static inline void pm_runtime_mark_last_busy(struct device *dev)
61963 {
61964 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
61965 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
61966 }
61967
61968 #else /* !CONFIG_PM_RUNTIME */
61969 diff --git a/include/linux/poison.h b/include/linux/poison.h
61970 index 79159de..f1233a9 100644
61971 --- a/include/linux/poison.h
61972 +++ b/include/linux/poison.h
61973 @@ -19,8 +19,8 @@
61974 * under normal circumstances, used to verify that nobody uses
61975 * non-initialized list entries.
61976 */
61977 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
61978 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
61979 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
61980 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
61981
61982 /********** include/linux/timer.h **********/
61983 /*
61984 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
61985 index 58969b2..ead129b 100644
61986 --- a/include/linux/preempt.h
61987 +++ b/include/linux/preempt.h
61988 @@ -123,7 +123,7 @@ struct preempt_ops {
61989 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
61990 void (*sched_out)(struct preempt_notifier *notifier,
61991 struct task_struct *next);
61992 -};
61993 +} __no_const;
61994
61995 /**
61996 * preempt_notifier - key for installing preemption notifiers
61997 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
61998 index 643b96c..ef55a9c 100644
61999 --- a/include/linux/proc_fs.h
62000 +++ b/include/linux/proc_fs.h
62001 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
62002 return proc_create_data(name, mode, parent, proc_fops, NULL);
62003 }
62004
62005 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
62006 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62007 +{
62008 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62009 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62010 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62011 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62012 +#else
62013 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62014 +#endif
62015 +}
62016 +
62017 +
62018 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62019 mode_t mode, struct proc_dir_entry *base,
62020 read_proc_t *read_proc, void * data)
62021 @@ -258,7 +271,7 @@ union proc_op {
62022 int (*proc_show)(struct seq_file *m,
62023 struct pid_namespace *ns, struct pid *pid,
62024 struct task_struct *task);
62025 -};
62026 +} __no_const;
62027
62028 struct ctl_table_header;
62029 struct ctl_table;
62030 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62031 index 800f113..e9ee2e3 100644
62032 --- a/include/linux/ptrace.h
62033 +++ b/include/linux/ptrace.h
62034 @@ -129,10 +129,12 @@ extern void __ptrace_unlink(struct task_struct *child);
62035 extern void exit_ptrace(struct task_struct *tracer);
62036 #define PTRACE_MODE_READ 1
62037 #define PTRACE_MODE_ATTACH 2
62038 -/* Returns 0 on success, -errno on denial. */
62039 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
62040 /* Returns true on success, false on denial. */
62041 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
62042 +/* Returns true on success, false on denial. */
62043 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
62044 +/* Returns true on success, false on denial. */
62045 +extern bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode);
62046
62047 static inline int ptrace_reparented(struct task_struct *child)
62048 {
62049 diff --git a/include/linux/random.h b/include/linux/random.h
62050 index 8f74538..02a1012 100644
62051 --- a/include/linux/random.h
62052 +++ b/include/linux/random.h
62053 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62054
62055 u32 prandom32(struct rnd_state *);
62056
62057 +static inline unsigned long pax_get_random_long(void)
62058 +{
62059 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62060 +}
62061 +
62062 /*
62063 * Handle minimum values for seeds
62064 */
62065 static inline u32 __seed(u32 x, u32 m)
62066 {
62067 - return (x < m) ? x + m : x;
62068 + return (x <= m) ? x + m + 1 : x;
62069 }
62070
62071 /**
62072 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62073 index e0879a7..a12f962 100644
62074 --- a/include/linux/reboot.h
62075 +++ b/include/linux/reboot.h
62076 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62077 * Architecture-specific implementations of sys_reboot commands.
62078 */
62079
62080 -extern void machine_restart(char *cmd);
62081 -extern void machine_halt(void);
62082 -extern void machine_power_off(void);
62083 +extern void machine_restart(char *cmd) __noreturn;
62084 +extern void machine_halt(void) __noreturn;
62085 +extern void machine_power_off(void) __noreturn;
62086
62087 extern void machine_shutdown(void);
62088 struct pt_regs;
62089 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62090 */
62091
62092 extern void kernel_restart_prepare(char *cmd);
62093 -extern void kernel_restart(char *cmd);
62094 -extern void kernel_halt(void);
62095 -extern void kernel_power_off(void);
62096 +extern void kernel_restart(char *cmd) __noreturn;
62097 +extern void kernel_halt(void) __noreturn;
62098 +extern void kernel_power_off(void) __noreturn;
62099
62100 extern int C_A_D; /* for sysctl */
62101 void ctrl_alt_del(void);
62102 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62103 * Emergency restart, callable from an interrupt handler.
62104 */
62105
62106 -extern void emergency_restart(void);
62107 +extern void emergency_restart(void) __noreturn;
62108 #include <asm/emergency-restart.h>
62109
62110 #endif
62111 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
62112 index 96d465f..b084e05 100644
62113 --- a/include/linux/reiserfs_fs.h
62114 +++ b/include/linux/reiserfs_fs.h
62115 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
62116 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
62117
62118 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
62119 -#define get_generation(s) atomic_read (&fs_generation(s))
62120 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
62121 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
62122 #define __fs_changed(gen,s) (gen != get_generation (s))
62123 #define fs_changed(gen,s) \
62124 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
62125 index 52c83b6..18ed7eb 100644
62126 --- a/include/linux/reiserfs_fs_sb.h
62127 +++ b/include/linux/reiserfs_fs_sb.h
62128 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
62129 /* Comment? -Hans */
62130 wait_queue_head_t s_wait;
62131 /* To be obsoleted soon by per buffer seals.. -Hans */
62132 - atomic_t s_generation_counter; // increased by one every time the
62133 + atomic_unchecked_t s_generation_counter; // increased by one every time the
62134 // tree gets re-balanced
62135 unsigned long s_properties; /* File system properties. Currently holds
62136 on-disk FS format */
62137 diff --git a/include/linux/relay.h b/include/linux/relay.h
62138 index 14a86bc..17d0700 100644
62139 --- a/include/linux/relay.h
62140 +++ b/include/linux/relay.h
62141 @@ -159,7 +159,7 @@ struct rchan_callbacks
62142 * The callback should return 0 if successful, negative if not.
62143 */
62144 int (*remove_buf_file)(struct dentry *dentry);
62145 -};
62146 +} __no_const;
62147
62148 /*
62149 * CONFIG_RELAY kernel API, kernel/relay.c
62150 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62151 index c6c6084..5bf1212 100644
62152 --- a/include/linux/rfkill.h
62153 +++ b/include/linux/rfkill.h
62154 @@ -147,6 +147,7 @@ struct rfkill_ops {
62155 void (*query)(struct rfkill *rfkill, void *data);
62156 int (*set_block)(void *data, bool blocked);
62157 };
62158 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62159
62160 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62161 /**
62162 diff --git a/include/linux/rio.h b/include/linux/rio.h
62163 index 4d50611..c6858a2 100644
62164 --- a/include/linux/rio.h
62165 +++ b/include/linux/rio.h
62166 @@ -315,7 +315,7 @@ struct rio_ops {
62167 int mbox, void *buffer, size_t len);
62168 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62169 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62170 -};
62171 +} __no_const;
62172
62173 #define RIO_RESOURCE_MEM 0x00000100
62174 #define RIO_RESOURCE_DOORBELL 0x00000200
62175 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62176 index 2148b12..519b820 100644
62177 --- a/include/linux/rmap.h
62178 +++ b/include/linux/rmap.h
62179 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62180 void anon_vma_init(void); /* create anon_vma_cachep */
62181 int anon_vma_prepare(struct vm_area_struct *);
62182 void unlink_anon_vmas(struct vm_area_struct *);
62183 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
62184 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
62185 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
62186 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
62187 void __anon_vma_link(struct vm_area_struct *);
62188
62189 static inline void anon_vma_merge(struct vm_area_struct *vma,
62190 diff --git a/include/linux/sched.h b/include/linux/sched.h
62191 index 1c4f3e9..342eb1f 100644
62192 --- a/include/linux/sched.h
62193 +++ b/include/linux/sched.h
62194 @@ -101,6 +101,7 @@ struct bio_list;
62195 struct fs_struct;
62196 struct perf_event_context;
62197 struct blk_plug;
62198 +struct linux_binprm;
62199
62200 /*
62201 * List of flags we want to share for kernel threads,
62202 @@ -380,10 +381,13 @@ struct user_namespace;
62203 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
62204
62205 extern int sysctl_max_map_count;
62206 +extern unsigned long sysctl_heap_stack_gap;
62207
62208 #include <linux/aio.h>
62209
62210 #ifdef CONFIG_MMU
62211 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
62212 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
62213 extern void arch_pick_mmap_layout(struct mm_struct *mm);
62214 extern unsigned long
62215 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
62216 @@ -629,6 +633,17 @@ struct signal_struct {
62217 #ifdef CONFIG_TASKSTATS
62218 struct taskstats *stats;
62219 #endif
62220 +
62221 +#ifdef CONFIG_GRKERNSEC
62222 + u32 curr_ip;
62223 + u32 saved_ip;
62224 + u32 gr_saddr;
62225 + u32 gr_daddr;
62226 + u16 gr_sport;
62227 + u16 gr_dport;
62228 + u8 used_accept:1;
62229 +#endif
62230 +
62231 #ifdef CONFIG_AUDIT
62232 unsigned audit_tty;
62233 struct tty_audit_buf *tty_audit_buf;
62234 @@ -710,6 +725,11 @@ struct user_struct {
62235 struct key *session_keyring; /* UID's default session keyring */
62236 #endif
62237
62238 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62239 + unsigned int banned;
62240 + unsigned long ban_expires;
62241 +#endif
62242 +
62243 /* Hash table maintenance information */
62244 struct hlist_node uidhash_node;
62245 uid_t uid;
62246 @@ -1337,8 +1357,8 @@ struct task_struct {
62247 struct list_head thread_group;
62248
62249 struct completion *vfork_done; /* for vfork() */
62250 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
62251 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62252 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
62253 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62254
62255 cputime_t utime, stime, utimescaled, stimescaled;
62256 cputime_t gtime;
62257 @@ -1354,13 +1374,6 @@ struct task_struct {
62258 struct task_cputime cputime_expires;
62259 struct list_head cpu_timers[3];
62260
62261 -/* process credentials */
62262 - const struct cred __rcu *real_cred; /* objective and real subjective task
62263 - * credentials (COW) */
62264 - const struct cred __rcu *cred; /* effective (overridable) subjective task
62265 - * credentials (COW) */
62266 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62267 -
62268 char comm[TASK_COMM_LEN]; /* executable name excluding path
62269 - access with [gs]et_task_comm (which lock
62270 it with task_lock())
62271 @@ -1377,8 +1390,16 @@ struct task_struct {
62272 #endif
62273 /* CPU-specific state of this task */
62274 struct thread_struct thread;
62275 +/* thread_info moved to task_struct */
62276 +#ifdef CONFIG_X86
62277 + struct thread_info tinfo;
62278 +#endif
62279 /* filesystem information */
62280 struct fs_struct *fs;
62281 +
62282 + const struct cred __rcu *cred; /* effective (overridable) subjective task
62283 + * credentials (COW) */
62284 +
62285 /* open file information */
62286 struct files_struct *files;
62287 /* namespaces */
62288 @@ -1425,6 +1446,11 @@ struct task_struct {
62289 struct rt_mutex_waiter *pi_blocked_on;
62290 #endif
62291
62292 +/* process credentials */
62293 + const struct cred __rcu *real_cred; /* objective and real subjective task
62294 + * credentials (COW) */
62295 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62296 +
62297 #ifdef CONFIG_DEBUG_MUTEXES
62298 /* mutex deadlock detection */
62299 struct mutex_waiter *blocked_on;
62300 @@ -1540,6 +1566,27 @@ struct task_struct {
62301 unsigned long default_timer_slack_ns;
62302
62303 struct list_head *scm_work_list;
62304 +
62305 +#ifdef CONFIG_GRKERNSEC
62306 + /* grsecurity */
62307 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62308 + u64 exec_id;
62309 +#endif
62310 +#ifdef CONFIG_GRKERNSEC_SETXID
62311 + const struct cred *delayed_cred;
62312 +#endif
62313 + struct dentry *gr_chroot_dentry;
62314 + struct acl_subject_label *acl;
62315 + struct acl_role_label *role;
62316 + struct file *exec_file;
62317 + u16 acl_role_id;
62318 + /* is this the task that authenticated to the special role */
62319 + u8 acl_sp_role;
62320 + u8 is_writable;
62321 + u8 brute;
62322 + u8 gr_is_chrooted;
62323 +#endif
62324 +
62325 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62326 /* Index of current stored address in ret_stack */
62327 int curr_ret_stack;
62328 @@ -1574,6 +1621,51 @@ struct task_struct {
62329 #endif
62330 };
62331
62332 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62333 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62334 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62335 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62336 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62337 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62338 +
62339 +#ifdef CONFIG_PAX_SOFTMODE
62340 +extern int pax_softmode;
62341 +#endif
62342 +
62343 +extern int pax_check_flags(unsigned long *);
62344 +
62345 +/* if tsk != current then task_lock must be held on it */
62346 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62347 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
62348 +{
62349 + if (likely(tsk->mm))
62350 + return tsk->mm->pax_flags;
62351 + else
62352 + return 0UL;
62353 +}
62354 +
62355 +/* if tsk != current then task_lock must be held on it */
62356 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62357 +{
62358 + if (likely(tsk->mm)) {
62359 + tsk->mm->pax_flags = flags;
62360 + return 0;
62361 + }
62362 + return -EINVAL;
62363 +}
62364 +#endif
62365 +
62366 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62367 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
62368 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62369 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62370 +#endif
62371 +
62372 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62373 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62374 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
62375 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62376 +
62377 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62378 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62379
62380 @@ -2081,7 +2173,9 @@ void yield(void);
62381 extern struct exec_domain default_exec_domain;
62382
62383 union thread_union {
62384 +#ifndef CONFIG_X86
62385 struct thread_info thread_info;
62386 +#endif
62387 unsigned long stack[THREAD_SIZE/sizeof(long)];
62388 };
62389
62390 @@ -2114,6 +2208,7 @@ extern struct pid_namespace init_pid_ns;
62391 */
62392
62393 extern struct task_struct *find_task_by_vpid(pid_t nr);
62394 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62395 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62396 struct pid_namespace *ns);
62397
62398 @@ -2235,6 +2330,12 @@ static inline void mmdrop(struct mm_struct * mm)
62399 extern void mmput(struct mm_struct *);
62400 /* Grab a reference to a task's mm, if it is not already going away */
62401 extern struct mm_struct *get_task_mm(struct task_struct *task);
62402 +/*
62403 + * Grab a reference to a task's mm, if it is not already going away
62404 + * and ptrace_may_access with the mode parameter passed to it
62405 + * succeeds.
62406 + */
62407 +extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
62408 /* Remove the current tasks stale references to the old mm_struct */
62409 extern void mm_release(struct task_struct *, struct mm_struct *);
62410 /* Allocate a new mm structure and copy contents from tsk->mm */
62411 @@ -2251,7 +2352,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62412 extern void exit_itimers(struct signal_struct *);
62413 extern void flush_itimer_signals(void);
62414
62415 -extern NORET_TYPE void do_group_exit(int);
62416 +extern __noreturn void do_group_exit(int);
62417
62418 extern void daemonize(const char *, ...);
62419 extern int allow_signal(int);
62420 @@ -2416,13 +2517,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62421
62422 #endif
62423
62424 -static inline int object_is_on_stack(void *obj)
62425 +static inline int object_starts_on_stack(void *obj)
62426 {
62427 - void *stack = task_stack_page(current);
62428 + const void *stack = task_stack_page(current);
62429
62430 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62431 }
62432
62433 +#ifdef CONFIG_PAX_USERCOPY
62434 +extern int object_is_on_stack(const void *obj, unsigned long len);
62435 +#endif
62436 +
62437 extern void thread_info_cache_init(void);
62438
62439 #ifdef CONFIG_DEBUG_STACK_USAGE
62440 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62441 index 899fbb4..1cb4138 100644
62442 --- a/include/linux/screen_info.h
62443 +++ b/include/linux/screen_info.h
62444 @@ -43,7 +43,8 @@ struct screen_info {
62445 __u16 pages; /* 0x32 */
62446 __u16 vesa_attributes; /* 0x34 */
62447 __u32 capabilities; /* 0x36 */
62448 - __u8 _reserved[6]; /* 0x3a */
62449 + __u16 vesapm_size; /* 0x3a */
62450 + __u8 _reserved[4]; /* 0x3c */
62451 } __attribute__((packed));
62452
62453 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62454 diff --git a/include/linux/security.h b/include/linux/security.h
62455 index e8c619d..e0cbd1c 100644
62456 --- a/include/linux/security.h
62457 +++ b/include/linux/security.h
62458 @@ -37,6 +37,7 @@
62459 #include <linux/xfrm.h>
62460 #include <linux/slab.h>
62461 #include <linux/xattr.h>
62462 +#include <linux/grsecurity.h>
62463 #include <net/flow.h>
62464
62465 /* Maximum number of letters for an LSM name string */
62466 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62467 index 0b69a46..b2ffa4c 100644
62468 --- a/include/linux/seq_file.h
62469 +++ b/include/linux/seq_file.h
62470 @@ -24,6 +24,9 @@ struct seq_file {
62471 struct mutex lock;
62472 const struct seq_operations *op;
62473 int poll_event;
62474 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62475 + u64 exec_id;
62476 +#endif
62477 void *private;
62478 };
62479
62480 @@ -33,6 +36,7 @@ struct seq_operations {
62481 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62482 int (*show) (struct seq_file *m, void *v);
62483 };
62484 +typedef struct seq_operations __no_const seq_operations_no_const;
62485
62486 #define SEQ_SKIP 1
62487
62488 diff --git a/include/linux/shm.h b/include/linux/shm.h
62489 index 92808b8..c28cac4 100644
62490 --- a/include/linux/shm.h
62491 +++ b/include/linux/shm.h
62492 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62493
62494 /* The task created the shm object. NULL if the task is dead. */
62495 struct task_struct *shm_creator;
62496 +#ifdef CONFIG_GRKERNSEC
62497 + time_t shm_createtime;
62498 + pid_t shm_lapid;
62499 +#endif
62500 };
62501
62502 /* shm_mode upper byte flags */
62503 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62504 index fe86488..1563c1c 100644
62505 --- a/include/linux/skbuff.h
62506 +++ b/include/linux/skbuff.h
62507 @@ -642,7 +642,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62508 */
62509 static inline int skb_queue_empty(const struct sk_buff_head *list)
62510 {
62511 - return list->next == (struct sk_buff *)list;
62512 + return list->next == (const struct sk_buff *)list;
62513 }
62514
62515 /**
62516 @@ -655,7 +655,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62517 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62518 const struct sk_buff *skb)
62519 {
62520 - return skb->next == (struct sk_buff *)list;
62521 + return skb->next == (const struct sk_buff *)list;
62522 }
62523
62524 /**
62525 @@ -668,7 +668,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62526 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62527 const struct sk_buff *skb)
62528 {
62529 - return skb->prev == (struct sk_buff *)list;
62530 + return skb->prev == (const struct sk_buff *)list;
62531 }
62532
62533 /**
62534 @@ -1523,7 +1523,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62535 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62536 */
62537 #ifndef NET_SKB_PAD
62538 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62539 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62540 #endif
62541
62542 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62543 diff --git a/include/linux/slab.h b/include/linux/slab.h
62544 index 573c809..e84c132 100644
62545 --- a/include/linux/slab.h
62546 +++ b/include/linux/slab.h
62547 @@ -11,12 +11,20 @@
62548
62549 #include <linux/gfp.h>
62550 #include <linux/types.h>
62551 +#include <linux/err.h>
62552
62553 /*
62554 * Flags to pass to kmem_cache_create().
62555 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62556 */
62557 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62558 +
62559 +#ifdef CONFIG_PAX_USERCOPY
62560 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62561 +#else
62562 +#define SLAB_USERCOPY 0x00000000UL
62563 +#endif
62564 +
62565 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62566 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62567 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62568 @@ -87,10 +95,13 @@
62569 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62570 * Both make kfree a no-op.
62571 */
62572 -#define ZERO_SIZE_PTR ((void *)16)
62573 +#define ZERO_SIZE_PTR \
62574 +({ \
62575 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62576 + (void *)(-MAX_ERRNO-1L); \
62577 +})
62578
62579 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62580 - (unsigned long)ZERO_SIZE_PTR)
62581 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62582
62583 /*
62584 * struct kmem_cache related prototypes
62585 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62586 void kfree(const void *);
62587 void kzfree(const void *);
62588 size_t ksize(const void *);
62589 +void check_object_size(const void *ptr, unsigned long n, bool to);
62590
62591 /*
62592 * Allocator specific definitions. These are mainly used to establish optimized
62593 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
62594
62595 void __init kmem_cache_init_late(void);
62596
62597 +#define kmalloc(x, y) \
62598 +({ \
62599 + void *___retval; \
62600 + intoverflow_t ___x = (intoverflow_t)x; \
62601 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
62602 + ___retval = NULL; \
62603 + else \
62604 + ___retval = kmalloc((size_t)___x, (y)); \
62605 + ___retval; \
62606 +})
62607 +
62608 +#define kmalloc_node(x, y, z) \
62609 +({ \
62610 + void *___retval; \
62611 + intoverflow_t ___x = (intoverflow_t)x; \
62612 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
62613 + ___retval = NULL; \
62614 + else \
62615 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
62616 + ___retval; \
62617 +})
62618 +
62619 +#define kzalloc(x, y) \
62620 +({ \
62621 + void *___retval; \
62622 + intoverflow_t ___x = (intoverflow_t)x; \
62623 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
62624 + ___retval = NULL; \
62625 + else \
62626 + ___retval = kzalloc((size_t)___x, (y)); \
62627 + ___retval; \
62628 +})
62629 +
62630 +#define __krealloc(x, y, z) \
62631 +({ \
62632 + void *___retval; \
62633 + intoverflow_t ___y = (intoverflow_t)y; \
62634 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
62635 + ___retval = NULL; \
62636 + else \
62637 + ___retval = __krealloc((x), (size_t)___y, (z)); \
62638 + ___retval; \
62639 +})
62640 +
62641 +#define krealloc(x, y, z) \
62642 +({ \
62643 + void *___retval; \
62644 + intoverflow_t ___y = (intoverflow_t)y; \
62645 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
62646 + ___retval = NULL; \
62647 + else \
62648 + ___retval = krealloc((x), (size_t)___y, (z)); \
62649 + ___retval; \
62650 +})
62651 +
62652 #endif /* _LINUX_SLAB_H */
62653 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62654 index d00e0ba..1b3bf7b 100644
62655 --- a/include/linux/slab_def.h
62656 +++ b/include/linux/slab_def.h
62657 @@ -68,10 +68,10 @@ struct kmem_cache {
62658 unsigned long node_allocs;
62659 unsigned long node_frees;
62660 unsigned long node_overflow;
62661 - atomic_t allochit;
62662 - atomic_t allocmiss;
62663 - atomic_t freehit;
62664 - atomic_t freemiss;
62665 + atomic_unchecked_t allochit;
62666 + atomic_unchecked_t allocmiss;
62667 + atomic_unchecked_t freehit;
62668 + atomic_unchecked_t freemiss;
62669
62670 /*
62671 * If debugging is enabled, then the allocator can add additional
62672 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62673 index a32bcfd..53b71f4 100644
62674 --- a/include/linux/slub_def.h
62675 +++ b/include/linux/slub_def.h
62676 @@ -89,7 +89,7 @@ struct kmem_cache {
62677 struct kmem_cache_order_objects max;
62678 struct kmem_cache_order_objects min;
62679 gfp_t allocflags; /* gfp flags to use on each alloc */
62680 - int refcount; /* Refcount for slab cache destroy */
62681 + atomic_t refcount; /* Refcount for slab cache destroy */
62682 void (*ctor)(void *);
62683 int inuse; /* Offset to metadata */
62684 int align; /* Alignment */
62685 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62686 }
62687
62688 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62689 -void *__kmalloc(size_t size, gfp_t flags);
62690 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
62691
62692 static __always_inline void *
62693 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62694 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62695 index de8832d..0147b46 100644
62696 --- a/include/linux/sonet.h
62697 +++ b/include/linux/sonet.h
62698 @@ -61,7 +61,7 @@ struct sonet_stats {
62699 #include <linux/atomic.h>
62700
62701 struct k_sonet_stats {
62702 -#define __HANDLE_ITEM(i) atomic_t i
62703 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62704 __SONET_ITEMS
62705 #undef __HANDLE_ITEM
62706 };
62707 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
62708 index 3d8f9c4..69f1c0a 100644
62709 --- a/include/linux/sunrpc/clnt.h
62710 +++ b/include/linux/sunrpc/clnt.h
62711 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
62712 {
62713 switch (sap->sa_family) {
62714 case AF_INET:
62715 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
62716 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
62717 case AF_INET6:
62718 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
62719 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
62720 }
62721 return 0;
62722 }
62723 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
62724 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
62725 const struct sockaddr *src)
62726 {
62727 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
62728 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
62729 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
62730
62731 dsin->sin_family = ssin->sin_family;
62732 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
62733 if (sa->sa_family != AF_INET6)
62734 return 0;
62735
62736 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
62737 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
62738 }
62739
62740 #endif /* __KERNEL__ */
62741 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
62742 index e775689..9e206d9 100644
62743 --- a/include/linux/sunrpc/sched.h
62744 +++ b/include/linux/sunrpc/sched.h
62745 @@ -105,6 +105,7 @@ struct rpc_call_ops {
62746 void (*rpc_call_done)(struct rpc_task *, void *);
62747 void (*rpc_release)(void *);
62748 };
62749 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
62750
62751 struct rpc_task_setup {
62752 struct rpc_task *task;
62753 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
62754 index c14fe86..393245e 100644
62755 --- a/include/linux/sunrpc/svc_rdma.h
62756 +++ b/include/linux/sunrpc/svc_rdma.h
62757 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
62758 extern unsigned int svcrdma_max_requests;
62759 extern unsigned int svcrdma_max_req_size;
62760
62761 -extern atomic_t rdma_stat_recv;
62762 -extern atomic_t rdma_stat_read;
62763 -extern atomic_t rdma_stat_write;
62764 -extern atomic_t rdma_stat_sq_starve;
62765 -extern atomic_t rdma_stat_rq_starve;
62766 -extern atomic_t rdma_stat_rq_poll;
62767 -extern atomic_t rdma_stat_rq_prod;
62768 -extern atomic_t rdma_stat_sq_poll;
62769 -extern atomic_t rdma_stat_sq_prod;
62770 +extern atomic_unchecked_t rdma_stat_recv;
62771 +extern atomic_unchecked_t rdma_stat_read;
62772 +extern atomic_unchecked_t rdma_stat_write;
62773 +extern atomic_unchecked_t rdma_stat_sq_starve;
62774 +extern atomic_unchecked_t rdma_stat_rq_starve;
62775 +extern atomic_unchecked_t rdma_stat_rq_poll;
62776 +extern atomic_unchecked_t rdma_stat_rq_prod;
62777 +extern atomic_unchecked_t rdma_stat_sq_poll;
62778 +extern atomic_unchecked_t rdma_stat_sq_prod;
62779
62780 #define RPCRDMA_VERSION 1
62781
62782 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
62783 index 703cfa33..0b8ca72ac 100644
62784 --- a/include/linux/sysctl.h
62785 +++ b/include/linux/sysctl.h
62786 @@ -155,7 +155,11 @@ enum
62787 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
62788 };
62789
62790 -
62791 +#ifdef CONFIG_PAX_SOFTMODE
62792 +enum {
62793 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
62794 +};
62795 +#endif
62796
62797 /* CTL_VM names: */
62798 enum
62799 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
62800
62801 extern int proc_dostring(struct ctl_table *, int,
62802 void __user *, size_t *, loff_t *);
62803 +extern int proc_dostring_modpriv(struct ctl_table *, int,
62804 + void __user *, size_t *, loff_t *);
62805 extern int proc_dointvec(struct ctl_table *, int,
62806 void __user *, size_t *, loff_t *);
62807 extern int proc_dointvec_minmax(struct ctl_table *, int,
62808 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
62809 index a71a292..51bd91d 100644
62810 --- a/include/linux/tracehook.h
62811 +++ b/include/linux/tracehook.h
62812 @@ -54,12 +54,12 @@ struct linux_binprm;
62813 /*
62814 * ptrace report for syscall entry and exit looks identical.
62815 */
62816 -static inline void ptrace_report_syscall(struct pt_regs *regs)
62817 +static inline int ptrace_report_syscall(struct pt_regs *regs)
62818 {
62819 int ptrace = current->ptrace;
62820
62821 if (!(ptrace & PT_PTRACED))
62822 - return;
62823 + return 0;
62824
62825 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
62826
62827 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62828 send_sig(current->exit_code, current, 1);
62829 current->exit_code = 0;
62830 }
62831 +
62832 + return fatal_signal_pending(current);
62833 }
62834
62835 /**
62836 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62837 static inline __must_check int tracehook_report_syscall_entry(
62838 struct pt_regs *regs)
62839 {
62840 - ptrace_report_syscall(regs);
62841 - return 0;
62842 + return ptrace_report_syscall(regs);
62843 }
62844
62845 /**
62846 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
62847 index ff7dc08..893e1bd 100644
62848 --- a/include/linux/tty_ldisc.h
62849 +++ b/include/linux/tty_ldisc.h
62850 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
62851
62852 struct module *owner;
62853
62854 - int refcount;
62855 + atomic_t refcount;
62856 };
62857
62858 struct tty_ldisc {
62859 diff --git a/include/linux/types.h b/include/linux/types.h
62860 index 57a9723..dbe234a 100644
62861 --- a/include/linux/types.h
62862 +++ b/include/linux/types.h
62863 @@ -213,10 +213,26 @@ typedef struct {
62864 int counter;
62865 } atomic_t;
62866
62867 +#ifdef CONFIG_PAX_REFCOUNT
62868 +typedef struct {
62869 + int counter;
62870 +} atomic_unchecked_t;
62871 +#else
62872 +typedef atomic_t atomic_unchecked_t;
62873 +#endif
62874 +
62875 #ifdef CONFIG_64BIT
62876 typedef struct {
62877 long counter;
62878 } atomic64_t;
62879 +
62880 +#ifdef CONFIG_PAX_REFCOUNT
62881 +typedef struct {
62882 + long counter;
62883 +} atomic64_unchecked_t;
62884 +#else
62885 +typedef atomic64_t atomic64_unchecked_t;
62886 +#endif
62887 #endif
62888
62889 struct list_head {
62890 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
62891 index 5ca0951..ab496a5 100644
62892 --- a/include/linux/uaccess.h
62893 +++ b/include/linux/uaccess.h
62894 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
62895 long ret; \
62896 mm_segment_t old_fs = get_fs(); \
62897 \
62898 - set_fs(KERNEL_DS); \
62899 pagefault_disable(); \
62900 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
62901 - pagefault_enable(); \
62902 + set_fs(KERNEL_DS); \
62903 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
62904 set_fs(old_fs); \
62905 + pagefault_enable(); \
62906 ret; \
62907 })
62908
62909 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
62910 index 99c1b4d..bb94261 100644
62911 --- a/include/linux/unaligned/access_ok.h
62912 +++ b/include/linux/unaligned/access_ok.h
62913 @@ -6,32 +6,32 @@
62914
62915 static inline u16 get_unaligned_le16(const void *p)
62916 {
62917 - return le16_to_cpup((__le16 *)p);
62918 + return le16_to_cpup((const __le16 *)p);
62919 }
62920
62921 static inline u32 get_unaligned_le32(const void *p)
62922 {
62923 - return le32_to_cpup((__le32 *)p);
62924 + return le32_to_cpup((const __le32 *)p);
62925 }
62926
62927 static inline u64 get_unaligned_le64(const void *p)
62928 {
62929 - return le64_to_cpup((__le64 *)p);
62930 + return le64_to_cpup((const __le64 *)p);
62931 }
62932
62933 static inline u16 get_unaligned_be16(const void *p)
62934 {
62935 - return be16_to_cpup((__be16 *)p);
62936 + return be16_to_cpup((const __be16 *)p);
62937 }
62938
62939 static inline u32 get_unaligned_be32(const void *p)
62940 {
62941 - return be32_to_cpup((__be32 *)p);
62942 + return be32_to_cpup((const __be32 *)p);
62943 }
62944
62945 static inline u64 get_unaligned_be64(const void *p)
62946 {
62947 - return be64_to_cpup((__be64 *)p);
62948 + return be64_to_cpup((const __be64 *)p);
62949 }
62950
62951 static inline void put_unaligned_le16(u16 val, void *p)
62952 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
62953 index e5a40c3..20ab0f6 100644
62954 --- a/include/linux/usb/renesas_usbhs.h
62955 +++ b/include/linux/usb/renesas_usbhs.h
62956 @@ -39,7 +39,7 @@ enum {
62957 */
62958 struct renesas_usbhs_driver_callback {
62959 int (*notify_hotplug)(struct platform_device *pdev);
62960 -};
62961 +} __no_const;
62962
62963 /*
62964 * callback functions for platform
62965 @@ -89,7 +89,7 @@ struct renesas_usbhs_platform_callback {
62966 * VBUS control is needed for Host
62967 */
62968 int (*set_vbus)(struct platform_device *pdev, int enable);
62969 -};
62970 +} __no_const;
62971
62972 /*
62973 * parameters for renesas usbhs
62974 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
62975 index 6f8fbcf..8259001 100644
62976 --- a/include/linux/vermagic.h
62977 +++ b/include/linux/vermagic.h
62978 @@ -25,9 +25,35 @@
62979 #define MODULE_ARCH_VERMAGIC ""
62980 #endif
62981
62982 +#ifdef CONFIG_PAX_REFCOUNT
62983 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
62984 +#else
62985 +#define MODULE_PAX_REFCOUNT ""
62986 +#endif
62987 +
62988 +#ifdef CONSTIFY_PLUGIN
62989 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
62990 +#else
62991 +#define MODULE_CONSTIFY_PLUGIN ""
62992 +#endif
62993 +
62994 +#ifdef STACKLEAK_PLUGIN
62995 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
62996 +#else
62997 +#define MODULE_STACKLEAK_PLUGIN ""
62998 +#endif
62999 +
63000 +#ifdef CONFIG_GRKERNSEC
63001 +#define MODULE_GRSEC "GRSEC "
63002 +#else
63003 +#define MODULE_GRSEC ""
63004 +#endif
63005 +
63006 #define VERMAGIC_STRING \
63007 UTS_RELEASE " " \
63008 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63009 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63010 - MODULE_ARCH_VERMAGIC
63011 + MODULE_ARCH_VERMAGIC \
63012 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63013 + MODULE_GRSEC
63014
63015 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63016 index 4bde182..aec92c1 100644
63017 --- a/include/linux/vmalloc.h
63018 +++ b/include/linux/vmalloc.h
63019 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63020 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63021 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63022 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63023 +
63024 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63025 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63026 +#endif
63027 +
63028 /* bits [20..32] reserved for arch specific ioremap internals */
63029
63030 /*
63031 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
63032 # endif
63033 #endif
63034
63035 +#define vmalloc(x) \
63036 +({ \
63037 + void *___retval; \
63038 + intoverflow_t ___x = (intoverflow_t)x; \
63039 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
63040 + ___retval = NULL; \
63041 + else \
63042 + ___retval = vmalloc((unsigned long)___x); \
63043 + ___retval; \
63044 +})
63045 +
63046 +#define vzalloc(x) \
63047 +({ \
63048 + void *___retval; \
63049 + intoverflow_t ___x = (intoverflow_t)x; \
63050 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
63051 + ___retval = NULL; \
63052 + else \
63053 + ___retval = vzalloc((unsigned long)___x); \
63054 + ___retval; \
63055 +})
63056 +
63057 +#define __vmalloc(x, y, z) \
63058 +({ \
63059 + void *___retval; \
63060 + intoverflow_t ___x = (intoverflow_t)x; \
63061 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
63062 + ___retval = NULL; \
63063 + else \
63064 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
63065 + ___retval; \
63066 +})
63067 +
63068 +#define vmalloc_user(x) \
63069 +({ \
63070 + void *___retval; \
63071 + intoverflow_t ___x = (intoverflow_t)x; \
63072 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
63073 + ___retval = NULL; \
63074 + else \
63075 + ___retval = vmalloc_user((unsigned long)___x); \
63076 + ___retval; \
63077 +})
63078 +
63079 +#define vmalloc_exec(x) \
63080 +({ \
63081 + void *___retval; \
63082 + intoverflow_t ___x = (intoverflow_t)x; \
63083 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
63084 + ___retval = NULL; \
63085 + else \
63086 + ___retval = vmalloc_exec((unsigned long)___x); \
63087 + ___retval; \
63088 +})
63089 +
63090 +#define vmalloc_node(x, y) \
63091 +({ \
63092 + void *___retval; \
63093 + intoverflow_t ___x = (intoverflow_t)x; \
63094 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
63095 + ___retval = NULL; \
63096 + else \
63097 + ___retval = vmalloc_node((unsigned long)___x, (y));\
63098 + ___retval; \
63099 +})
63100 +
63101 +#define vzalloc_node(x, y) \
63102 +({ \
63103 + void *___retval; \
63104 + intoverflow_t ___x = (intoverflow_t)x; \
63105 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
63106 + ___retval = NULL; \
63107 + else \
63108 + ___retval = vzalloc_node((unsigned long)___x, (y));\
63109 + ___retval; \
63110 +})
63111 +
63112 +#define vmalloc_32(x) \
63113 +({ \
63114 + void *___retval; \
63115 + intoverflow_t ___x = (intoverflow_t)x; \
63116 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
63117 + ___retval = NULL; \
63118 + else \
63119 + ___retval = vmalloc_32((unsigned long)___x); \
63120 + ___retval; \
63121 +})
63122 +
63123 +#define vmalloc_32_user(x) \
63124 +({ \
63125 +void *___retval; \
63126 + intoverflow_t ___x = (intoverflow_t)x; \
63127 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
63128 + ___retval = NULL; \
63129 + else \
63130 + ___retval = vmalloc_32_user((unsigned long)___x);\
63131 + ___retval; \
63132 +})
63133 +
63134 #endif /* _LINUX_VMALLOC_H */
63135 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63136 index 65efb92..137adbb 100644
63137 --- a/include/linux/vmstat.h
63138 +++ b/include/linux/vmstat.h
63139 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63140 /*
63141 * Zone based page accounting with per cpu differentials.
63142 */
63143 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63144 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63145
63146 static inline void zone_page_state_add(long x, struct zone *zone,
63147 enum zone_stat_item item)
63148 {
63149 - atomic_long_add(x, &zone->vm_stat[item]);
63150 - atomic_long_add(x, &vm_stat[item]);
63151 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63152 + atomic_long_add_unchecked(x, &vm_stat[item]);
63153 }
63154
63155 static inline unsigned long global_page_state(enum zone_stat_item item)
63156 {
63157 - long x = atomic_long_read(&vm_stat[item]);
63158 + long x = atomic_long_read_unchecked(&vm_stat[item]);
63159 #ifdef CONFIG_SMP
63160 if (x < 0)
63161 x = 0;
63162 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63163 static inline unsigned long zone_page_state(struct zone *zone,
63164 enum zone_stat_item item)
63165 {
63166 - long x = atomic_long_read(&zone->vm_stat[item]);
63167 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63168 #ifdef CONFIG_SMP
63169 if (x < 0)
63170 x = 0;
63171 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63172 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63173 enum zone_stat_item item)
63174 {
63175 - long x = atomic_long_read(&zone->vm_stat[item]);
63176 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63177
63178 #ifdef CONFIG_SMP
63179 int cpu;
63180 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63181
63182 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63183 {
63184 - atomic_long_inc(&zone->vm_stat[item]);
63185 - atomic_long_inc(&vm_stat[item]);
63186 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
63187 + atomic_long_inc_unchecked(&vm_stat[item]);
63188 }
63189
63190 static inline void __inc_zone_page_state(struct page *page,
63191 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63192
63193 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63194 {
63195 - atomic_long_dec(&zone->vm_stat[item]);
63196 - atomic_long_dec(&vm_stat[item]);
63197 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
63198 + atomic_long_dec_unchecked(&vm_stat[item]);
63199 }
63200
63201 static inline void __dec_zone_page_state(struct page *page,
63202 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63203 index e5d1220..ef6e406 100644
63204 --- a/include/linux/xattr.h
63205 +++ b/include/linux/xattr.h
63206 @@ -57,6 +57,11 @@
63207 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63208 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63209
63210 +/* User namespace */
63211 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63212 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
63213 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63214 +
63215 #ifdef __KERNEL__
63216
63217 #include <linux/types.h>
63218 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63219 index 4aeff96..b378cdc 100644
63220 --- a/include/media/saa7146_vv.h
63221 +++ b/include/media/saa7146_vv.h
63222 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
63223 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63224
63225 /* the extension can override this */
63226 - struct v4l2_ioctl_ops ops;
63227 + v4l2_ioctl_ops_no_const ops;
63228 /* pointer to the saa7146 core ops */
63229 const struct v4l2_ioctl_ops *core_ops;
63230
63231 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63232 index c7c40f1..4f01585 100644
63233 --- a/include/media/v4l2-dev.h
63234 +++ b/include/media/v4l2-dev.h
63235 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
63236
63237
63238 struct v4l2_file_operations {
63239 - struct module *owner;
63240 + struct module * const owner;
63241 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
63242 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63243 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63244 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
63245 int (*open) (struct file *);
63246 int (*release) (struct file *);
63247 };
63248 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
63249
63250 /*
63251 * Newer version of video_device, handled by videodev2.c
63252 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
63253 index 4d1c74a..65e1221 100644
63254 --- a/include/media/v4l2-ioctl.h
63255 +++ b/include/media/v4l2-ioctl.h
63256 @@ -274,7 +274,7 @@ struct v4l2_ioctl_ops {
63257 long (*vidioc_default) (struct file *file, void *fh,
63258 bool valid_prio, int cmd, void *arg);
63259 };
63260 -
63261 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
63262
63263 /* v4l debugging and diagnostics */
63264
63265 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
63266 index 8d55251..dfe5b0a 100644
63267 --- a/include/net/caif/caif_hsi.h
63268 +++ b/include/net/caif/caif_hsi.h
63269 @@ -98,7 +98,7 @@ struct cfhsi_drv {
63270 void (*rx_done_cb) (struct cfhsi_drv *drv);
63271 void (*wake_up_cb) (struct cfhsi_drv *drv);
63272 void (*wake_down_cb) (struct cfhsi_drv *drv);
63273 -};
63274 +} __no_const;
63275
63276 /* Structure implemented by HSI device. */
63277 struct cfhsi_dev {
63278 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
63279 index 9e5425b..8136ffc 100644
63280 --- a/include/net/caif/cfctrl.h
63281 +++ b/include/net/caif/cfctrl.h
63282 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
63283 void (*radioset_rsp)(void);
63284 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
63285 struct cflayer *client_layer);
63286 -};
63287 +} __no_const;
63288
63289 /* Link Setup Parameters for CAIF-Links. */
63290 struct cfctrl_link_param {
63291 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
63292 struct cfctrl {
63293 struct cfsrvl serv;
63294 struct cfctrl_rsp res;
63295 - atomic_t req_seq_no;
63296 - atomic_t rsp_seq_no;
63297 + atomic_unchecked_t req_seq_no;
63298 + atomic_unchecked_t rsp_seq_no;
63299 struct list_head list;
63300 /* Protects from simultaneous access to first_req list */
63301 spinlock_t info_list_lock;
63302 diff --git a/include/net/flow.h b/include/net/flow.h
63303 index 2a7eefd..3250f3b 100644
63304 --- a/include/net/flow.h
63305 +++ b/include/net/flow.h
63306 @@ -218,6 +218,6 @@ extern struct flow_cache_object *flow_cache_lookup(
63307
63308 extern void flow_cache_flush(void);
63309 extern void flow_cache_flush_deferred(void);
63310 -extern atomic_t flow_cache_genid;
63311 +extern atomic_unchecked_t flow_cache_genid;
63312
63313 #endif
63314 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
63315 index e9ff3fc..9d3e5c7 100644
63316 --- a/include/net/inetpeer.h
63317 +++ b/include/net/inetpeer.h
63318 @@ -48,8 +48,8 @@ struct inet_peer {
63319 */
63320 union {
63321 struct {
63322 - atomic_t rid; /* Frag reception counter */
63323 - atomic_t ip_id_count; /* IP ID for the next packet */
63324 + atomic_unchecked_t rid; /* Frag reception counter */
63325 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63326 __u32 tcp_ts;
63327 __u32 tcp_ts_stamp;
63328 };
63329 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63330 more++;
63331 inet_peer_refcheck(p);
63332 do {
63333 - old = atomic_read(&p->ip_id_count);
63334 + old = atomic_read_unchecked(&p->ip_id_count);
63335 new = old + more;
63336 if (!new)
63337 new = 1;
63338 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63339 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63340 return new;
63341 }
63342
63343 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63344 index 10422ef..662570f 100644
63345 --- a/include/net/ip_fib.h
63346 +++ b/include/net/ip_fib.h
63347 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63348
63349 #define FIB_RES_SADDR(net, res) \
63350 ((FIB_RES_NH(res).nh_saddr_genid == \
63351 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63352 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63353 FIB_RES_NH(res).nh_saddr : \
63354 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63355 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63356 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63357 index e5a7b9a..f4fc44b 100644
63358 --- a/include/net/ip_vs.h
63359 +++ b/include/net/ip_vs.h
63360 @@ -509,7 +509,7 @@ struct ip_vs_conn {
63361 struct ip_vs_conn *control; /* Master control connection */
63362 atomic_t n_control; /* Number of controlled ones */
63363 struct ip_vs_dest *dest; /* real server */
63364 - atomic_t in_pkts; /* incoming packet counter */
63365 + atomic_unchecked_t in_pkts; /* incoming packet counter */
63366
63367 /* packet transmitter for different forwarding methods. If it
63368 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63369 @@ -647,7 +647,7 @@ struct ip_vs_dest {
63370 __be16 port; /* port number of the server */
63371 union nf_inet_addr addr; /* IP address of the server */
63372 volatile unsigned flags; /* dest status flags */
63373 - atomic_t conn_flags; /* flags to copy to conn */
63374 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
63375 atomic_t weight; /* server weight */
63376
63377 atomic_t refcnt; /* reference counter */
63378 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63379 index 69b610a..fe3962c 100644
63380 --- a/include/net/irda/ircomm_core.h
63381 +++ b/include/net/irda/ircomm_core.h
63382 @@ -51,7 +51,7 @@ typedef struct {
63383 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63384 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63385 struct ircomm_info *);
63386 -} call_t;
63387 +} __no_const call_t;
63388
63389 struct ircomm_cb {
63390 irda_queue_t queue;
63391 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63392 index 59ba38bc..d515662 100644
63393 --- a/include/net/irda/ircomm_tty.h
63394 +++ b/include/net/irda/ircomm_tty.h
63395 @@ -35,6 +35,7 @@
63396 #include <linux/termios.h>
63397 #include <linux/timer.h>
63398 #include <linux/tty.h> /* struct tty_struct */
63399 +#include <asm/local.h>
63400
63401 #include <net/irda/irias_object.h>
63402 #include <net/irda/ircomm_core.h>
63403 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63404 unsigned short close_delay;
63405 unsigned short closing_wait; /* time to wait before closing */
63406
63407 - int open_count;
63408 - int blocked_open; /* # of blocked opens */
63409 + local_t open_count;
63410 + local_t blocked_open; /* # of blocked opens */
63411
63412 /* Protect concurent access to :
63413 * o self->open_count
63414 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63415 index f2419cf..473679f 100644
63416 --- a/include/net/iucv/af_iucv.h
63417 +++ b/include/net/iucv/af_iucv.h
63418 @@ -139,7 +139,7 @@ struct iucv_sock {
63419 struct iucv_sock_list {
63420 struct hlist_head head;
63421 rwlock_t lock;
63422 - atomic_t autobind_name;
63423 + atomic_unchecked_t autobind_name;
63424 };
63425
63426 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63427 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63428 index 2720884..3aa5c25 100644
63429 --- a/include/net/neighbour.h
63430 +++ b/include/net/neighbour.h
63431 @@ -122,7 +122,7 @@ struct neigh_ops {
63432 void (*error_report)(struct neighbour *, struct sk_buff *);
63433 int (*output)(struct neighbour *, struct sk_buff *);
63434 int (*connected_output)(struct neighbour *, struct sk_buff *);
63435 -};
63436 +} __do_const;
63437
63438 struct pneigh_entry {
63439 struct pneigh_entry *next;
63440 diff --git a/include/net/netlink.h b/include/net/netlink.h
63441 index cb1f350..3279d2c 100644
63442 --- a/include/net/netlink.h
63443 +++ b/include/net/netlink.h
63444 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63445 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63446 {
63447 if (mark)
63448 - skb_trim(skb, (unsigned char *) mark - skb->data);
63449 + skb_trim(skb, (const unsigned char *) mark - skb->data);
63450 }
63451
63452 /**
63453 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63454 index d786b4f..4c3dd41 100644
63455 --- a/include/net/netns/ipv4.h
63456 +++ b/include/net/netns/ipv4.h
63457 @@ -56,8 +56,8 @@ struct netns_ipv4 {
63458
63459 unsigned int sysctl_ping_group_range[2];
63460
63461 - atomic_t rt_genid;
63462 - atomic_t dev_addr_genid;
63463 + atomic_unchecked_t rt_genid;
63464 + atomic_unchecked_t dev_addr_genid;
63465
63466 #ifdef CONFIG_IP_MROUTE
63467 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63468 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63469 index 6a72a58..e6a127d 100644
63470 --- a/include/net/sctp/sctp.h
63471 +++ b/include/net/sctp/sctp.h
63472 @@ -318,9 +318,9 @@ do { \
63473
63474 #else /* SCTP_DEBUG */
63475
63476 -#define SCTP_DEBUG_PRINTK(whatever...)
63477 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63478 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63479 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63480 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63481 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63482 #define SCTP_ENABLE_DEBUG
63483 #define SCTP_DISABLE_DEBUG
63484 #define SCTP_ASSERT(expr, str, func)
63485 diff --git a/include/net/sock.h b/include/net/sock.h
63486 index 32e3937..87a1dbc 100644
63487 --- a/include/net/sock.h
63488 +++ b/include/net/sock.h
63489 @@ -277,7 +277,7 @@ struct sock {
63490 #ifdef CONFIG_RPS
63491 __u32 sk_rxhash;
63492 #endif
63493 - atomic_t sk_drops;
63494 + atomic_unchecked_t sk_drops;
63495 int sk_rcvbuf;
63496
63497 struct sk_filter __rcu *sk_filter;
63498 @@ -1402,7 +1402,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
63499 }
63500
63501 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63502 - char __user *from, char *to,
63503 + char __user *from, unsigned char *to,
63504 int copy, int offset)
63505 {
63506 if (skb->ip_summed == CHECKSUM_NONE) {
63507 diff --git a/include/net/tcp.h b/include/net/tcp.h
63508 index bb18c4d..bb87972 100644
63509 --- a/include/net/tcp.h
63510 +++ b/include/net/tcp.h
63511 @@ -1409,7 +1409,7 @@ struct tcp_seq_afinfo {
63512 char *name;
63513 sa_family_t family;
63514 const struct file_operations *seq_fops;
63515 - struct seq_operations seq_ops;
63516 + seq_operations_no_const seq_ops;
63517 };
63518
63519 struct tcp_iter_state {
63520 diff --git a/include/net/udp.h b/include/net/udp.h
63521 index 3b285f4..0219639 100644
63522 --- a/include/net/udp.h
63523 +++ b/include/net/udp.h
63524 @@ -237,7 +237,7 @@ struct udp_seq_afinfo {
63525 sa_family_t family;
63526 struct udp_table *udp_table;
63527 const struct file_operations *seq_fops;
63528 - struct seq_operations seq_ops;
63529 + seq_operations_no_const seq_ops;
63530 };
63531
63532 struct udp_iter_state {
63533 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63534 index b203e14..1df3991 100644
63535 --- a/include/net/xfrm.h
63536 +++ b/include/net/xfrm.h
63537 @@ -505,7 +505,7 @@ struct xfrm_policy {
63538 struct timer_list timer;
63539
63540 struct flow_cache_object flo;
63541 - atomic_t genid;
63542 + atomic_unchecked_t genid;
63543 u32 priority;
63544 u32 index;
63545 struct xfrm_mark mark;
63546 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63547 index 1a046b1..ee0bef0 100644
63548 --- a/include/rdma/iw_cm.h
63549 +++ b/include/rdma/iw_cm.h
63550 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
63551 int backlog);
63552
63553 int (*destroy_listen)(struct iw_cm_id *cm_id);
63554 -};
63555 +} __no_const;
63556
63557 /**
63558 * iw_create_cm_id - Create an IW CM identifier.
63559 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63560 index 5d1a758..1dbf795 100644
63561 --- a/include/scsi/libfc.h
63562 +++ b/include/scsi/libfc.h
63563 @@ -748,6 +748,7 @@ struct libfc_function_template {
63564 */
63565 void (*disc_stop_final) (struct fc_lport *);
63566 };
63567 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63568
63569 /**
63570 * struct fc_disc - Discovery context
63571 @@ -851,7 +852,7 @@ struct fc_lport {
63572 struct fc_vport *vport;
63573
63574 /* Operational Information */
63575 - struct libfc_function_template tt;
63576 + libfc_function_template_no_const tt;
63577 u8 link_up;
63578 u8 qfull;
63579 enum fc_lport_state state;
63580 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63581 index 5591ed5..13eb457 100644
63582 --- a/include/scsi/scsi_device.h
63583 +++ b/include/scsi/scsi_device.h
63584 @@ -161,9 +161,9 @@ struct scsi_device {
63585 unsigned int max_device_blocked; /* what device_blocked counts down from */
63586 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63587
63588 - atomic_t iorequest_cnt;
63589 - atomic_t iodone_cnt;
63590 - atomic_t ioerr_cnt;
63591 + atomic_unchecked_t iorequest_cnt;
63592 + atomic_unchecked_t iodone_cnt;
63593 + atomic_unchecked_t ioerr_cnt;
63594
63595 struct device sdev_gendev,
63596 sdev_dev;
63597 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63598 index 2a65167..91e01f8 100644
63599 --- a/include/scsi/scsi_transport_fc.h
63600 +++ b/include/scsi/scsi_transport_fc.h
63601 @@ -711,7 +711,7 @@ struct fc_function_template {
63602 unsigned long show_host_system_hostname:1;
63603
63604 unsigned long disable_target_scan:1;
63605 -};
63606 +} __do_const;
63607
63608
63609 /**
63610 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63611 index 030b87c..98a6954 100644
63612 --- a/include/sound/ak4xxx-adda.h
63613 +++ b/include/sound/ak4xxx-adda.h
63614 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63615 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63616 unsigned char val);
63617 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63618 -};
63619 +} __no_const;
63620
63621 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63622
63623 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63624 index 8c05e47..2b5df97 100644
63625 --- a/include/sound/hwdep.h
63626 +++ b/include/sound/hwdep.h
63627 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63628 struct snd_hwdep_dsp_status *status);
63629 int (*dsp_load)(struct snd_hwdep *hw,
63630 struct snd_hwdep_dsp_image *image);
63631 -};
63632 +} __no_const;
63633
63634 struct snd_hwdep {
63635 struct snd_card *card;
63636 diff --git a/include/sound/info.h b/include/sound/info.h
63637 index 5492cc4..1a65278 100644
63638 --- a/include/sound/info.h
63639 +++ b/include/sound/info.h
63640 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
63641 struct snd_info_buffer *buffer);
63642 void (*write)(struct snd_info_entry *entry,
63643 struct snd_info_buffer *buffer);
63644 -};
63645 +} __no_const;
63646
63647 struct snd_info_entry_ops {
63648 int (*open)(struct snd_info_entry *entry,
63649 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63650 index 0cf91b2..b70cae4 100644
63651 --- a/include/sound/pcm.h
63652 +++ b/include/sound/pcm.h
63653 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
63654 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63655 int (*ack)(struct snd_pcm_substream *substream);
63656 };
63657 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63658
63659 /*
63660 *
63661 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63662 index af1b49e..a5d55a5 100644
63663 --- a/include/sound/sb16_csp.h
63664 +++ b/include/sound/sb16_csp.h
63665 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63666 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63667 int (*csp_stop) (struct snd_sb_csp * p);
63668 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63669 -};
63670 +} __no_const;
63671
63672 /*
63673 * CSP private data
63674 diff --git a/include/sound/soc.h b/include/sound/soc.h
63675 index 11cfb59..e3f93f4 100644
63676 --- a/include/sound/soc.h
63677 +++ b/include/sound/soc.h
63678 @@ -683,7 +683,7 @@ struct snd_soc_platform_driver {
63679 /* platform IO - used for platform DAPM */
63680 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63681 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63682 -};
63683 +} __do_const;
63684
63685 struct snd_soc_platform {
63686 const char *name;
63687 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63688 index 444cd6b..3327cc5 100644
63689 --- a/include/sound/ymfpci.h
63690 +++ b/include/sound/ymfpci.h
63691 @@ -358,7 +358,7 @@ struct snd_ymfpci {
63692 spinlock_t reg_lock;
63693 spinlock_t voice_lock;
63694 wait_queue_head_t interrupt_sleep;
63695 - atomic_t interrupt_sleep_count;
63696 + atomic_unchecked_t interrupt_sleep_count;
63697 struct snd_info_entry *proc_entry;
63698 const struct firmware *dsp_microcode;
63699 const struct firmware *controller_microcode;
63700 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63701 index 94bbec3..3a8c6b0 100644
63702 --- a/include/target/target_core_base.h
63703 +++ b/include/target/target_core_base.h
63704 @@ -346,7 +346,7 @@ struct t10_reservation_ops {
63705 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63706 int (*t10_pr_register)(struct se_cmd *);
63707 int (*t10_pr_clear)(struct se_cmd *);
63708 -};
63709 +} __no_const;
63710
63711 struct t10_reservation {
63712 /* Reservation effects all target ports */
63713 @@ -465,8 +465,8 @@ struct se_cmd {
63714 atomic_t t_se_count;
63715 atomic_t t_task_cdbs_left;
63716 atomic_t t_task_cdbs_ex_left;
63717 - atomic_t t_task_cdbs_sent;
63718 - atomic_t t_transport_aborted;
63719 + atomic_unchecked_t t_task_cdbs_sent;
63720 + atomic_unchecked_t t_transport_aborted;
63721 atomic_t t_transport_active;
63722 atomic_t t_transport_complete;
63723 atomic_t t_transport_queue_active;
63724 @@ -705,7 +705,7 @@ struct se_device {
63725 /* Active commands on this virtual SE device */
63726 atomic_t simple_cmds;
63727 atomic_t depth_left;
63728 - atomic_t dev_ordered_id;
63729 + atomic_unchecked_t dev_ordered_id;
63730 atomic_t execute_tasks;
63731 atomic_t dev_ordered_sync;
63732 atomic_t dev_qf_count;
63733 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63734 index 1c09820..7f5ec79 100644
63735 --- a/include/trace/events/irq.h
63736 +++ b/include/trace/events/irq.h
63737 @@ -36,7 +36,7 @@ struct softirq_action;
63738 */
63739 TRACE_EVENT(irq_handler_entry,
63740
63741 - TP_PROTO(int irq, struct irqaction *action),
63742 + TP_PROTO(int irq, const struct irqaction *action),
63743
63744 TP_ARGS(irq, action),
63745
63746 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63747 */
63748 TRACE_EVENT(irq_handler_exit,
63749
63750 - TP_PROTO(int irq, struct irqaction *action, int ret),
63751 + TP_PROTO(int irq, const struct irqaction *action, int ret),
63752
63753 TP_ARGS(irq, action, ret),
63754
63755 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
63756 index c41f308..6918de3 100644
63757 --- a/include/video/udlfb.h
63758 +++ b/include/video/udlfb.h
63759 @@ -52,10 +52,10 @@ struct dlfb_data {
63760 u32 pseudo_palette[256];
63761 int blank_mode; /*one of FB_BLANK_ */
63762 /* blit-only rendering path metrics, exposed through sysfs */
63763 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63764 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
63765 - atomic_t bytes_sent; /* to usb, after compression including overhead */
63766 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
63767 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63768 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
63769 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
63770 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
63771 };
63772
63773 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
63774 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
63775 index 0993a22..32ba2fe 100644
63776 --- a/include/video/uvesafb.h
63777 +++ b/include/video/uvesafb.h
63778 @@ -177,6 +177,7 @@ struct uvesafb_par {
63779 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
63780 u8 pmi_setpal; /* PMI for palette changes */
63781 u16 *pmi_base; /* protected mode interface location */
63782 + u8 *pmi_code; /* protected mode code location */
63783 void *pmi_start;
63784 void *pmi_pal;
63785 u8 *vbe_state_orig; /*
63786 diff --git a/init/Kconfig b/init/Kconfig
63787 index 43298f9..2f56c12 100644
63788 --- a/init/Kconfig
63789 +++ b/init/Kconfig
63790 @@ -1214,7 +1214,7 @@ config SLUB_DEBUG
63791
63792 config COMPAT_BRK
63793 bool "Disable heap randomization"
63794 - default y
63795 + default n
63796 help
63797 Randomizing heap placement makes heap exploits harder, but it
63798 also breaks ancient binaries (including anything libc5 based).
63799 diff --git a/init/do_mounts.c b/init/do_mounts.c
63800 index db6e5ee..7677ff7 100644
63801 --- a/init/do_mounts.c
63802 +++ b/init/do_mounts.c
63803 @@ -325,11 +325,11 @@ static void __init get_fs_names(char *page)
63804
63805 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
63806 {
63807 - int err = sys_mount(name, "/root", fs, flags, data);
63808 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
63809 if (err)
63810 return err;
63811
63812 - sys_chdir((const char __user __force *)"/root");
63813 + sys_chdir((const char __force_user*)"/root");
63814 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
63815 printk(KERN_INFO
63816 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
63817 @@ -448,18 +448,18 @@ void __init change_floppy(char *fmt, ...)
63818 va_start(args, fmt);
63819 vsprintf(buf, fmt, args);
63820 va_end(args);
63821 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
63822 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
63823 if (fd >= 0) {
63824 sys_ioctl(fd, FDEJECT, 0);
63825 sys_close(fd);
63826 }
63827 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
63828 - fd = sys_open("/dev/console", O_RDWR, 0);
63829 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
63830 if (fd >= 0) {
63831 sys_ioctl(fd, TCGETS, (long)&termios);
63832 termios.c_lflag &= ~ICANON;
63833 sys_ioctl(fd, TCSETSF, (long)&termios);
63834 - sys_read(fd, &c, 1);
63835 + sys_read(fd, (char __user *)&c, 1);
63836 termios.c_lflag |= ICANON;
63837 sys_ioctl(fd, TCSETSF, (long)&termios);
63838 sys_close(fd);
63839 @@ -553,6 +553,6 @@ void __init prepare_namespace(void)
63840 mount_root();
63841 out:
63842 devtmpfs_mount("dev");
63843 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
63844 - sys_chroot((const char __user __force *)".");
63845 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63846 + sys_chroot((const char __force_user *)".");
63847 }
63848 diff --git a/init/do_mounts.h b/init/do_mounts.h
63849 index f5b978a..69dbfe8 100644
63850 --- a/init/do_mounts.h
63851 +++ b/init/do_mounts.h
63852 @@ -15,15 +15,15 @@ extern int root_mountflags;
63853
63854 static inline int create_dev(char *name, dev_t dev)
63855 {
63856 - sys_unlink(name);
63857 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
63858 + sys_unlink((char __force_user *)name);
63859 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
63860 }
63861
63862 #if BITS_PER_LONG == 32
63863 static inline u32 bstat(char *name)
63864 {
63865 struct stat64 stat;
63866 - if (sys_stat64(name, &stat) != 0)
63867 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
63868 return 0;
63869 if (!S_ISBLK(stat.st_mode))
63870 return 0;
63871 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
63872 static inline u32 bstat(char *name)
63873 {
63874 struct stat stat;
63875 - if (sys_newstat(name, &stat) != 0)
63876 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
63877 return 0;
63878 if (!S_ISBLK(stat.st_mode))
63879 return 0;
63880 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
63881 index 3098a38..253064e 100644
63882 --- a/init/do_mounts_initrd.c
63883 +++ b/init/do_mounts_initrd.c
63884 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
63885 create_dev("/dev/root.old", Root_RAM0);
63886 /* mount initrd on rootfs' /root */
63887 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
63888 - sys_mkdir("/old", 0700);
63889 - root_fd = sys_open("/", 0, 0);
63890 - old_fd = sys_open("/old", 0, 0);
63891 + sys_mkdir((const char __force_user *)"/old", 0700);
63892 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
63893 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
63894 /* move initrd over / and chdir/chroot in initrd root */
63895 - sys_chdir("/root");
63896 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
63897 - sys_chroot(".");
63898 + sys_chdir((const char __force_user *)"/root");
63899 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63900 + sys_chroot((const char __force_user *)".");
63901
63902 /*
63903 * In case that a resume from disk is carried out by linuxrc or one of
63904 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
63905
63906 /* move initrd to rootfs' /old */
63907 sys_fchdir(old_fd);
63908 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
63909 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
63910 /* switch root and cwd back to / of rootfs */
63911 sys_fchdir(root_fd);
63912 - sys_chroot(".");
63913 + sys_chroot((const char __force_user *)".");
63914 sys_close(old_fd);
63915 sys_close(root_fd);
63916
63917 if (new_decode_dev(real_root_dev) == Root_RAM0) {
63918 - sys_chdir("/old");
63919 + sys_chdir((const char __force_user *)"/old");
63920 return;
63921 }
63922
63923 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
63924 mount_root();
63925
63926 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
63927 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
63928 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
63929 if (!error)
63930 printk("okay\n");
63931 else {
63932 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
63933 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
63934 if (error == -ENOENT)
63935 printk("/initrd does not exist. Ignored.\n");
63936 else
63937 printk("failed\n");
63938 printk(KERN_NOTICE "Unmounting old root\n");
63939 - sys_umount("/old", MNT_DETACH);
63940 + sys_umount((char __force_user *)"/old", MNT_DETACH);
63941 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
63942 if (fd < 0) {
63943 error = fd;
63944 @@ -116,11 +116,11 @@ int __init initrd_load(void)
63945 * mounted in the normal path.
63946 */
63947 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
63948 - sys_unlink("/initrd.image");
63949 + sys_unlink((const char __force_user *)"/initrd.image");
63950 handle_initrd();
63951 return 1;
63952 }
63953 }
63954 - sys_unlink("/initrd.image");
63955 + sys_unlink((const char __force_user *)"/initrd.image");
63956 return 0;
63957 }
63958 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
63959 index 32c4799..c27ee74 100644
63960 --- a/init/do_mounts_md.c
63961 +++ b/init/do_mounts_md.c
63962 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
63963 partitioned ? "_d" : "", minor,
63964 md_setup_args[ent].device_names);
63965
63966 - fd = sys_open(name, 0, 0);
63967 + fd = sys_open((char __force_user *)name, 0, 0);
63968 if (fd < 0) {
63969 printk(KERN_ERR "md: open failed - cannot start "
63970 "array %s\n", name);
63971 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
63972 * array without it
63973 */
63974 sys_close(fd);
63975 - fd = sys_open(name, 0, 0);
63976 + fd = sys_open((char __force_user *)name, 0, 0);
63977 sys_ioctl(fd, BLKRRPART, 0);
63978 }
63979 sys_close(fd);
63980 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
63981
63982 wait_for_device_probe();
63983
63984 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
63985 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
63986 if (fd >= 0) {
63987 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
63988 sys_close(fd);
63989 diff --git a/init/initramfs.c b/init/initramfs.c
63990 index 2531811..040d4d4 100644
63991 --- a/init/initramfs.c
63992 +++ b/init/initramfs.c
63993 @@ -74,7 +74,7 @@ static void __init free_hash(void)
63994 }
63995 }
63996
63997 -static long __init do_utime(char __user *filename, time_t mtime)
63998 +static long __init do_utime(__force char __user *filename, time_t mtime)
63999 {
64000 struct timespec t[2];
64001
64002 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64003 struct dir_entry *de, *tmp;
64004 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64005 list_del(&de->list);
64006 - do_utime(de->name, de->mtime);
64007 + do_utime((char __force_user *)de->name, de->mtime);
64008 kfree(de->name);
64009 kfree(de);
64010 }
64011 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64012 if (nlink >= 2) {
64013 char *old = find_link(major, minor, ino, mode, collected);
64014 if (old)
64015 - return (sys_link(old, collected) < 0) ? -1 : 1;
64016 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64017 }
64018 return 0;
64019 }
64020 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
64021 {
64022 struct stat st;
64023
64024 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64025 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64026 if (S_ISDIR(st.st_mode))
64027 - sys_rmdir(path);
64028 + sys_rmdir((char __force_user *)path);
64029 else
64030 - sys_unlink(path);
64031 + sys_unlink((char __force_user *)path);
64032 }
64033 }
64034
64035 @@ -305,7 +305,7 @@ static int __init do_name(void)
64036 int openflags = O_WRONLY|O_CREAT;
64037 if (ml != 1)
64038 openflags |= O_TRUNC;
64039 - wfd = sys_open(collected, openflags, mode);
64040 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64041
64042 if (wfd >= 0) {
64043 sys_fchown(wfd, uid, gid);
64044 @@ -317,17 +317,17 @@ static int __init do_name(void)
64045 }
64046 }
64047 } else if (S_ISDIR(mode)) {
64048 - sys_mkdir(collected, mode);
64049 - sys_chown(collected, uid, gid);
64050 - sys_chmod(collected, mode);
64051 + sys_mkdir((char __force_user *)collected, mode);
64052 + sys_chown((char __force_user *)collected, uid, gid);
64053 + sys_chmod((char __force_user *)collected, mode);
64054 dir_add(collected, mtime);
64055 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64056 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64057 if (maybe_link() == 0) {
64058 - sys_mknod(collected, mode, rdev);
64059 - sys_chown(collected, uid, gid);
64060 - sys_chmod(collected, mode);
64061 - do_utime(collected, mtime);
64062 + sys_mknod((char __force_user *)collected, mode, rdev);
64063 + sys_chown((char __force_user *)collected, uid, gid);
64064 + sys_chmod((char __force_user *)collected, mode);
64065 + do_utime((char __force_user *)collected, mtime);
64066 }
64067 }
64068 return 0;
64069 @@ -336,15 +336,15 @@ static int __init do_name(void)
64070 static int __init do_copy(void)
64071 {
64072 if (count >= body_len) {
64073 - sys_write(wfd, victim, body_len);
64074 + sys_write(wfd, (char __force_user *)victim, body_len);
64075 sys_close(wfd);
64076 - do_utime(vcollected, mtime);
64077 + do_utime((char __force_user *)vcollected, mtime);
64078 kfree(vcollected);
64079 eat(body_len);
64080 state = SkipIt;
64081 return 0;
64082 } else {
64083 - sys_write(wfd, victim, count);
64084 + sys_write(wfd, (char __force_user *)victim, count);
64085 body_len -= count;
64086 eat(count);
64087 return 1;
64088 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64089 {
64090 collected[N_ALIGN(name_len) + body_len] = '\0';
64091 clean_path(collected, 0);
64092 - sys_symlink(collected + N_ALIGN(name_len), collected);
64093 - sys_lchown(collected, uid, gid);
64094 - do_utime(collected, mtime);
64095 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64096 + sys_lchown((char __force_user *)collected, uid, gid);
64097 + do_utime((char __force_user *)collected, mtime);
64098 state = SkipIt;
64099 next_state = Reset;
64100 return 0;
64101 diff --git a/init/main.c b/init/main.c
64102 index 217ed23..ec5406f 100644
64103 --- a/init/main.c
64104 +++ b/init/main.c
64105 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
64106 extern void tc_init(void);
64107 #endif
64108
64109 +extern void grsecurity_init(void);
64110 +
64111 /*
64112 * Debug helper: via this flag we know that we are in 'early bootup code'
64113 * where only the boot processor is running with IRQ disabled. This means
64114 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
64115
64116 __setup("reset_devices", set_reset_devices);
64117
64118 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64119 +extern char pax_enter_kernel_user[];
64120 +extern char pax_exit_kernel_user[];
64121 +extern pgdval_t clone_pgd_mask;
64122 +#endif
64123 +
64124 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64125 +static int __init setup_pax_nouderef(char *str)
64126 +{
64127 +#ifdef CONFIG_X86_32
64128 + unsigned int cpu;
64129 + struct desc_struct *gdt;
64130 +
64131 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64132 + gdt = get_cpu_gdt_table(cpu);
64133 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64134 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64135 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64136 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64137 + }
64138 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64139 +#else
64140 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64141 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64142 + clone_pgd_mask = ~(pgdval_t)0UL;
64143 +#endif
64144 +
64145 + return 0;
64146 +}
64147 +early_param("pax_nouderef", setup_pax_nouderef);
64148 +#endif
64149 +
64150 +#ifdef CONFIG_PAX_SOFTMODE
64151 +int pax_softmode;
64152 +
64153 +static int __init setup_pax_softmode(char *str)
64154 +{
64155 + get_option(&str, &pax_softmode);
64156 + return 1;
64157 +}
64158 +__setup("pax_softmode=", setup_pax_softmode);
64159 +#endif
64160 +
64161 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64162 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64163 static const char *panic_later, *panic_param;
64164 @@ -681,6 +726,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64165 {
64166 int count = preempt_count();
64167 int ret;
64168 + const char *msg1 = "", *msg2 = "";
64169
64170 if (initcall_debug)
64171 ret = do_one_initcall_debug(fn);
64172 @@ -693,15 +739,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64173 sprintf(msgbuf, "error code %d ", ret);
64174
64175 if (preempt_count() != count) {
64176 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64177 + msg1 = " preemption imbalance";
64178 preempt_count() = count;
64179 }
64180 if (irqs_disabled()) {
64181 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64182 + msg2 = " disabled interrupts";
64183 local_irq_enable();
64184 }
64185 - if (msgbuf[0]) {
64186 - printk("initcall %pF returned with %s\n", fn, msgbuf);
64187 + if (msgbuf[0] || *msg1 || *msg2) {
64188 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64189 }
64190
64191 return ret;
64192 @@ -820,7 +866,7 @@ static int __init kernel_init(void * unused)
64193 do_basic_setup();
64194
64195 /* Open the /dev/console on the rootfs, this should never fail */
64196 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
64197 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
64198 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
64199
64200 (void) sys_dup(0);
64201 @@ -833,11 +879,13 @@ static int __init kernel_init(void * unused)
64202 if (!ramdisk_execute_command)
64203 ramdisk_execute_command = "/init";
64204
64205 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
64206 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
64207 ramdisk_execute_command = NULL;
64208 prepare_namespace();
64209 }
64210
64211 + grsecurity_init();
64212 +
64213 /*
64214 * Ok, we have completed the initial bootup, and
64215 * we're essentially up and running. Get rid of the
64216 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
64217 index 5b4293d..f179875 100644
64218 --- a/ipc/mqueue.c
64219 +++ b/ipc/mqueue.c
64220 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
64221 mq_bytes = (mq_msg_tblsz +
64222 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
64223
64224 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
64225 spin_lock(&mq_lock);
64226 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
64227 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
64228 diff --git a/ipc/msg.c b/ipc/msg.c
64229 index 7385de2..a8180e08 100644
64230 --- a/ipc/msg.c
64231 +++ b/ipc/msg.c
64232 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
64233 return security_msg_queue_associate(msq, msgflg);
64234 }
64235
64236 +static struct ipc_ops msg_ops = {
64237 + .getnew = newque,
64238 + .associate = msg_security,
64239 + .more_checks = NULL
64240 +};
64241 +
64242 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
64243 {
64244 struct ipc_namespace *ns;
64245 - struct ipc_ops msg_ops;
64246 struct ipc_params msg_params;
64247
64248 ns = current->nsproxy->ipc_ns;
64249
64250 - msg_ops.getnew = newque;
64251 - msg_ops.associate = msg_security;
64252 - msg_ops.more_checks = NULL;
64253 -
64254 msg_params.key = key;
64255 msg_params.flg = msgflg;
64256
64257 diff --git a/ipc/sem.c b/ipc/sem.c
64258 index 5215a81..cfc0cac 100644
64259 --- a/ipc/sem.c
64260 +++ b/ipc/sem.c
64261 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
64262 return 0;
64263 }
64264
64265 +static struct ipc_ops sem_ops = {
64266 + .getnew = newary,
64267 + .associate = sem_security,
64268 + .more_checks = sem_more_checks
64269 +};
64270 +
64271 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64272 {
64273 struct ipc_namespace *ns;
64274 - struct ipc_ops sem_ops;
64275 struct ipc_params sem_params;
64276
64277 ns = current->nsproxy->ipc_ns;
64278 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64279 if (nsems < 0 || nsems > ns->sc_semmsl)
64280 return -EINVAL;
64281
64282 - sem_ops.getnew = newary;
64283 - sem_ops.associate = sem_security;
64284 - sem_ops.more_checks = sem_more_checks;
64285 -
64286 sem_params.key = key;
64287 sem_params.flg = semflg;
64288 sem_params.u.nsems = nsems;
64289 diff --git a/ipc/shm.c b/ipc/shm.c
64290 index b76be5b..859e750 100644
64291 --- a/ipc/shm.c
64292 +++ b/ipc/shm.c
64293 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
64294 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
64295 #endif
64296
64297 +#ifdef CONFIG_GRKERNSEC
64298 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64299 + const time_t shm_createtime, const uid_t cuid,
64300 + const int shmid);
64301 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64302 + const time_t shm_createtime);
64303 +#endif
64304 +
64305 void shm_init_ns(struct ipc_namespace *ns)
64306 {
64307 ns->shm_ctlmax = SHMMAX;
64308 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64309 shp->shm_lprid = 0;
64310 shp->shm_atim = shp->shm_dtim = 0;
64311 shp->shm_ctim = get_seconds();
64312 +#ifdef CONFIG_GRKERNSEC
64313 + {
64314 + struct timespec timeval;
64315 + do_posix_clock_monotonic_gettime(&timeval);
64316 +
64317 + shp->shm_createtime = timeval.tv_sec;
64318 + }
64319 +#endif
64320 shp->shm_segsz = size;
64321 shp->shm_nattch = 0;
64322 shp->shm_file = file;
64323 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64324 return 0;
64325 }
64326
64327 +static struct ipc_ops shm_ops = {
64328 + .getnew = newseg,
64329 + .associate = shm_security,
64330 + .more_checks = shm_more_checks
64331 +};
64332 +
64333 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64334 {
64335 struct ipc_namespace *ns;
64336 - struct ipc_ops shm_ops;
64337 struct ipc_params shm_params;
64338
64339 ns = current->nsproxy->ipc_ns;
64340
64341 - shm_ops.getnew = newseg;
64342 - shm_ops.associate = shm_security;
64343 - shm_ops.more_checks = shm_more_checks;
64344 -
64345 shm_params.key = key;
64346 shm_params.flg = shmflg;
64347 shm_params.u.size = size;
64348 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64349 f_mode = FMODE_READ | FMODE_WRITE;
64350 }
64351 if (shmflg & SHM_EXEC) {
64352 +
64353 +#ifdef CONFIG_PAX_MPROTECT
64354 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
64355 + goto out;
64356 +#endif
64357 +
64358 prot |= PROT_EXEC;
64359 acc_mode |= S_IXUGO;
64360 }
64361 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64362 if (err)
64363 goto out_unlock;
64364
64365 +#ifdef CONFIG_GRKERNSEC
64366 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64367 + shp->shm_perm.cuid, shmid) ||
64368 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64369 + err = -EACCES;
64370 + goto out_unlock;
64371 + }
64372 +#endif
64373 +
64374 path = shp->shm_file->f_path;
64375 path_get(&path);
64376 shp->shm_nattch++;
64377 +#ifdef CONFIG_GRKERNSEC
64378 + shp->shm_lapid = current->pid;
64379 +#endif
64380 size = i_size_read(path.dentry->d_inode);
64381 shm_unlock(shp);
64382
64383 diff --git a/kernel/acct.c b/kernel/acct.c
64384 index fa7eb3d..7faf116 100644
64385 --- a/kernel/acct.c
64386 +++ b/kernel/acct.c
64387 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64388 */
64389 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64390 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64391 - file->f_op->write(file, (char *)&ac,
64392 + file->f_op->write(file, (char __force_user *)&ac,
64393 sizeof(acct_t), &file->f_pos);
64394 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64395 set_fs(fs);
64396 diff --git a/kernel/audit.c b/kernel/audit.c
64397 index 09fae26..ed71d5b 100644
64398 --- a/kernel/audit.c
64399 +++ b/kernel/audit.c
64400 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64401 3) suppressed due to audit_rate_limit
64402 4) suppressed due to audit_backlog_limit
64403 */
64404 -static atomic_t audit_lost = ATOMIC_INIT(0);
64405 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64406
64407 /* The netlink socket. */
64408 static struct sock *audit_sock;
64409 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64410 unsigned long now;
64411 int print;
64412
64413 - atomic_inc(&audit_lost);
64414 + atomic_inc_unchecked(&audit_lost);
64415
64416 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64417
64418 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64419 printk(KERN_WARNING
64420 "audit: audit_lost=%d audit_rate_limit=%d "
64421 "audit_backlog_limit=%d\n",
64422 - atomic_read(&audit_lost),
64423 + atomic_read_unchecked(&audit_lost),
64424 audit_rate_limit,
64425 audit_backlog_limit);
64426 audit_panic(message);
64427 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64428 status_set.pid = audit_pid;
64429 status_set.rate_limit = audit_rate_limit;
64430 status_set.backlog_limit = audit_backlog_limit;
64431 - status_set.lost = atomic_read(&audit_lost);
64432 + status_set.lost = atomic_read_unchecked(&audit_lost);
64433 status_set.backlog = skb_queue_len(&audit_skb_queue);
64434 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64435 &status_set, sizeof(status_set));
64436 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
64437 avail = audit_expand(ab,
64438 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
64439 if (!avail)
64440 - goto out;
64441 + goto out_va_end;
64442 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
64443 }
64444 - va_end(args2);
64445 if (len > 0)
64446 skb_put(skb, len);
64447 +out_va_end:
64448 + va_end(args2);
64449 out:
64450 return;
64451 }
64452 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64453 index 47b7fc1..c003c33 100644
64454 --- a/kernel/auditsc.c
64455 +++ b/kernel/auditsc.c
64456 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
64457 struct audit_buffer **ab,
64458 struct audit_aux_data_execve *axi)
64459 {
64460 - int i;
64461 - size_t len, len_sent = 0;
64462 + int i, len;
64463 + size_t len_sent = 0;
64464 const char __user *p;
64465 char *buf;
64466
64467 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64468 }
64469
64470 /* global counter which is incremented every time something logs in */
64471 -static atomic_t session_id = ATOMIC_INIT(0);
64472 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64473
64474 /**
64475 * audit_set_loginuid - set a task's audit_context loginuid
64476 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
64477 */
64478 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
64479 {
64480 - unsigned int sessionid = atomic_inc_return(&session_id);
64481 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
64482 struct audit_context *context = task->audit_context;
64483
64484 if (context && context->in_syscall) {
64485 diff --git a/kernel/capability.c b/kernel/capability.c
64486 index b463871..fa3ea1f 100644
64487 --- a/kernel/capability.c
64488 +++ b/kernel/capability.c
64489 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64490 * before modification is attempted and the application
64491 * fails.
64492 */
64493 + if (tocopy > ARRAY_SIZE(kdata))
64494 + return -EFAULT;
64495 +
64496 if (copy_to_user(dataptr, kdata, tocopy
64497 * sizeof(struct __user_cap_data_struct))) {
64498 return -EFAULT;
64499 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64500 BUG();
64501 }
64502
64503 - if (security_capable(ns, current_cred(), cap) == 0) {
64504 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
64505 current->flags |= PF_SUPERPRIV;
64506 return true;
64507 }
64508 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
64509 }
64510 EXPORT_SYMBOL(ns_capable);
64511
64512 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
64513 +{
64514 + if (unlikely(!cap_valid(cap))) {
64515 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64516 + BUG();
64517 + }
64518 +
64519 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
64520 + current->flags |= PF_SUPERPRIV;
64521 + return true;
64522 + }
64523 + return false;
64524 +}
64525 +EXPORT_SYMBOL(ns_capable_nolog);
64526 +
64527 +bool capable_nolog(int cap)
64528 +{
64529 + return ns_capable_nolog(&init_user_ns, cap);
64530 +}
64531 +EXPORT_SYMBOL(capable_nolog);
64532 +
64533 /**
64534 * task_ns_capable - Determine whether current task has a superior
64535 * capability targeted at a specific task's user namespace.
64536 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
64537 }
64538 EXPORT_SYMBOL(task_ns_capable);
64539
64540 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
64541 +{
64542 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
64543 +}
64544 +EXPORT_SYMBOL(task_ns_capable_nolog);
64545 +
64546 /**
64547 * nsown_capable - Check superior capability to one's own user_ns
64548 * @cap: The capability in question
64549 diff --git a/kernel/compat.c b/kernel/compat.c
64550 index f346ced..aa2b1f4 100644
64551 --- a/kernel/compat.c
64552 +++ b/kernel/compat.c
64553 @@ -13,6 +13,7 @@
64554
64555 #include <linux/linkage.h>
64556 #include <linux/compat.h>
64557 +#include <linux/module.h>
64558 #include <linux/errno.h>
64559 #include <linux/time.h>
64560 #include <linux/signal.h>
64561 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64562 mm_segment_t oldfs;
64563 long ret;
64564
64565 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64566 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64567 oldfs = get_fs();
64568 set_fs(KERNEL_DS);
64569 ret = hrtimer_nanosleep_restart(restart);
64570 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64571 oldfs = get_fs();
64572 set_fs(KERNEL_DS);
64573 ret = hrtimer_nanosleep(&tu,
64574 - rmtp ? (struct timespec __user *)&rmt : NULL,
64575 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
64576 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64577 set_fs(oldfs);
64578
64579 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64580 mm_segment_t old_fs = get_fs();
64581
64582 set_fs(KERNEL_DS);
64583 - ret = sys_sigpending((old_sigset_t __user *) &s);
64584 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
64585 set_fs(old_fs);
64586 if (ret == 0)
64587 ret = put_user(s, set);
64588 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
64589 old_fs = get_fs();
64590 set_fs(KERNEL_DS);
64591 ret = sys_sigprocmask(how,
64592 - set ? (old_sigset_t __user *) &s : NULL,
64593 - oset ? (old_sigset_t __user *) &s : NULL);
64594 + set ? (old_sigset_t __force_user *) &s : NULL,
64595 + oset ? (old_sigset_t __force_user *) &s : NULL);
64596 set_fs(old_fs);
64597 if (ret == 0)
64598 if (oset)
64599 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64600 mm_segment_t old_fs = get_fs();
64601
64602 set_fs(KERNEL_DS);
64603 - ret = sys_old_getrlimit(resource, &r);
64604 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64605 set_fs(old_fs);
64606
64607 if (!ret) {
64608 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64609 mm_segment_t old_fs = get_fs();
64610
64611 set_fs(KERNEL_DS);
64612 - ret = sys_getrusage(who, (struct rusage __user *) &r);
64613 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64614 set_fs(old_fs);
64615
64616 if (ret)
64617 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64618 set_fs (KERNEL_DS);
64619 ret = sys_wait4(pid,
64620 (stat_addr ?
64621 - (unsigned int __user *) &status : NULL),
64622 - options, (struct rusage __user *) &r);
64623 + (unsigned int __force_user *) &status : NULL),
64624 + options, (struct rusage __force_user *) &r);
64625 set_fs (old_fs);
64626
64627 if (ret > 0) {
64628 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64629 memset(&info, 0, sizeof(info));
64630
64631 set_fs(KERNEL_DS);
64632 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64633 - uru ? (struct rusage __user *)&ru : NULL);
64634 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64635 + uru ? (struct rusage __force_user *)&ru : NULL);
64636 set_fs(old_fs);
64637
64638 if ((ret < 0) || (info.si_signo == 0))
64639 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64640 oldfs = get_fs();
64641 set_fs(KERNEL_DS);
64642 err = sys_timer_settime(timer_id, flags,
64643 - (struct itimerspec __user *) &newts,
64644 - (struct itimerspec __user *) &oldts);
64645 + (struct itimerspec __force_user *) &newts,
64646 + (struct itimerspec __force_user *) &oldts);
64647 set_fs(oldfs);
64648 if (!err && old && put_compat_itimerspec(old, &oldts))
64649 return -EFAULT;
64650 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64651 oldfs = get_fs();
64652 set_fs(KERNEL_DS);
64653 err = sys_timer_gettime(timer_id,
64654 - (struct itimerspec __user *) &ts);
64655 + (struct itimerspec __force_user *) &ts);
64656 set_fs(oldfs);
64657 if (!err && put_compat_itimerspec(setting, &ts))
64658 return -EFAULT;
64659 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64660 oldfs = get_fs();
64661 set_fs(KERNEL_DS);
64662 err = sys_clock_settime(which_clock,
64663 - (struct timespec __user *) &ts);
64664 + (struct timespec __force_user *) &ts);
64665 set_fs(oldfs);
64666 return err;
64667 }
64668 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64669 oldfs = get_fs();
64670 set_fs(KERNEL_DS);
64671 err = sys_clock_gettime(which_clock,
64672 - (struct timespec __user *) &ts);
64673 + (struct timespec __force_user *) &ts);
64674 set_fs(oldfs);
64675 if (!err && put_compat_timespec(&ts, tp))
64676 return -EFAULT;
64677 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64678
64679 oldfs = get_fs();
64680 set_fs(KERNEL_DS);
64681 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64682 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64683 set_fs(oldfs);
64684
64685 err = compat_put_timex(utp, &txc);
64686 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64687 oldfs = get_fs();
64688 set_fs(KERNEL_DS);
64689 err = sys_clock_getres(which_clock,
64690 - (struct timespec __user *) &ts);
64691 + (struct timespec __force_user *) &ts);
64692 set_fs(oldfs);
64693 if (!err && tp && put_compat_timespec(&ts, tp))
64694 return -EFAULT;
64695 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64696 long err;
64697 mm_segment_t oldfs;
64698 struct timespec tu;
64699 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64700 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64701
64702 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64703 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64704 oldfs = get_fs();
64705 set_fs(KERNEL_DS);
64706 err = clock_nanosleep_restart(restart);
64707 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64708 oldfs = get_fs();
64709 set_fs(KERNEL_DS);
64710 err = sys_clock_nanosleep(which_clock, flags,
64711 - (struct timespec __user *) &in,
64712 - (struct timespec __user *) &out);
64713 + (struct timespec __force_user *) &in,
64714 + (struct timespec __force_user *) &out);
64715 set_fs(oldfs);
64716
64717 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64718 diff --git a/kernel/configs.c b/kernel/configs.c
64719 index 42e8fa0..9e7406b 100644
64720 --- a/kernel/configs.c
64721 +++ b/kernel/configs.c
64722 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64723 struct proc_dir_entry *entry;
64724
64725 /* create the current config file */
64726 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64727 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64728 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64729 + &ikconfig_file_ops);
64730 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64731 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64732 + &ikconfig_file_ops);
64733 +#endif
64734 +#else
64735 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64736 &ikconfig_file_ops);
64737 +#endif
64738 +
64739 if (!entry)
64740 return -ENOMEM;
64741
64742 diff --git a/kernel/cred.c b/kernel/cred.c
64743 index 5791612..a3c04dc 100644
64744 --- a/kernel/cred.c
64745 +++ b/kernel/cred.c
64746 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
64747 validate_creds(cred);
64748 put_cred(cred);
64749 }
64750 +
64751 +#ifdef CONFIG_GRKERNSEC_SETXID
64752 + cred = (struct cred *) tsk->delayed_cred;
64753 + if (cred) {
64754 + tsk->delayed_cred = NULL;
64755 + validate_creds(cred);
64756 + put_cred(cred);
64757 + }
64758 +#endif
64759 }
64760
64761 /**
64762 @@ -470,7 +479,7 @@ error_put:
64763 * Always returns 0 thus allowing this function to be tail-called at the end
64764 * of, say, sys_setgid().
64765 */
64766 -int commit_creds(struct cred *new)
64767 +static int __commit_creds(struct cred *new)
64768 {
64769 struct task_struct *task = current;
64770 const struct cred *old = task->real_cred;
64771 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
64772
64773 get_cred(new); /* we will require a ref for the subj creds too */
64774
64775 + gr_set_role_label(task, new->uid, new->gid);
64776 +
64777 /* dumpability changes */
64778 if (old->euid != new->euid ||
64779 old->egid != new->egid ||
64780 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
64781 put_cred(old);
64782 return 0;
64783 }
64784 +#ifdef CONFIG_GRKERNSEC_SETXID
64785 +extern int set_user(struct cred *new);
64786 +
64787 +void gr_delayed_cred_worker(void)
64788 +{
64789 + const struct cred *new = current->delayed_cred;
64790 + struct cred *ncred;
64791 +
64792 + current->delayed_cred = NULL;
64793 +
64794 + if (current_uid() && new != NULL) {
64795 + // from doing get_cred on it when queueing this
64796 + put_cred(new);
64797 + return;
64798 + } else if (new == NULL)
64799 + return;
64800 +
64801 + ncred = prepare_creds();
64802 + if (!ncred)
64803 + goto die;
64804 + // uids
64805 + ncred->uid = new->uid;
64806 + ncred->euid = new->euid;
64807 + ncred->suid = new->suid;
64808 + ncred->fsuid = new->fsuid;
64809 + // gids
64810 + ncred->gid = new->gid;
64811 + ncred->egid = new->egid;
64812 + ncred->sgid = new->sgid;
64813 + ncred->fsgid = new->fsgid;
64814 + // groups
64815 + if (set_groups(ncred, new->group_info) < 0) {
64816 + abort_creds(ncred);
64817 + goto die;
64818 + }
64819 + // caps
64820 + ncred->securebits = new->securebits;
64821 + ncred->cap_inheritable = new->cap_inheritable;
64822 + ncred->cap_permitted = new->cap_permitted;
64823 + ncred->cap_effective = new->cap_effective;
64824 + ncred->cap_bset = new->cap_bset;
64825 +
64826 + if (set_user(ncred)) {
64827 + abort_creds(ncred);
64828 + goto die;
64829 + }
64830 +
64831 + // from doing get_cred on it when queueing this
64832 + put_cred(new);
64833 +
64834 + __commit_creds(ncred);
64835 + return;
64836 +die:
64837 + // from doing get_cred on it when queueing this
64838 + put_cred(new);
64839 + do_group_exit(SIGKILL);
64840 +}
64841 +#endif
64842 +
64843 +int commit_creds(struct cred *new)
64844 +{
64845 +#ifdef CONFIG_GRKERNSEC_SETXID
64846 + struct task_struct *t;
64847 +
64848 + /* we won't get called with tasklist_lock held for writing
64849 + and interrupts disabled as the cred struct in that case is
64850 + init_cred
64851 + */
64852 + if (grsec_enable_setxid && !current_is_single_threaded() &&
64853 + !current_uid() && new->uid) {
64854 + rcu_read_lock();
64855 + read_lock(&tasklist_lock);
64856 + for (t = next_thread(current); t != current;
64857 + t = next_thread(t)) {
64858 + if (t->delayed_cred == NULL) {
64859 + t->delayed_cred = get_cred(new);
64860 + set_tsk_need_resched(t);
64861 + }
64862 + }
64863 + read_unlock(&tasklist_lock);
64864 + rcu_read_unlock();
64865 + }
64866 +#endif
64867 + return __commit_creds(new);
64868 +}
64869 +
64870 EXPORT_SYMBOL(commit_creds);
64871
64872 /**
64873 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
64874 index 0d7c087..01b8cef 100644
64875 --- a/kernel/debug/debug_core.c
64876 +++ b/kernel/debug/debug_core.c
64877 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
64878 */
64879 static atomic_t masters_in_kgdb;
64880 static atomic_t slaves_in_kgdb;
64881 -static atomic_t kgdb_break_tasklet_var;
64882 +static atomic_unchecked_t kgdb_break_tasklet_var;
64883 atomic_t kgdb_setting_breakpoint;
64884
64885 struct task_struct *kgdb_usethread;
64886 @@ -129,7 +129,7 @@ int kgdb_single_step;
64887 static pid_t kgdb_sstep_pid;
64888
64889 /* to keep track of the CPU which is doing the single stepping*/
64890 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64891 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64892
64893 /*
64894 * If you are debugging a problem where roundup (the collection of
64895 @@ -542,7 +542,7 @@ return_normal:
64896 * kernel will only try for the value of sstep_tries before
64897 * giving up and continuing on.
64898 */
64899 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
64900 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
64901 (kgdb_info[cpu].task &&
64902 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
64903 atomic_set(&kgdb_active, -1);
64904 @@ -636,8 +636,8 @@ cpu_master_loop:
64905 }
64906
64907 kgdb_restore:
64908 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
64909 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
64910 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
64911 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
64912 if (kgdb_info[sstep_cpu].task)
64913 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
64914 else
64915 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
64916 static void kgdb_tasklet_bpt(unsigned long ing)
64917 {
64918 kgdb_breakpoint();
64919 - atomic_set(&kgdb_break_tasklet_var, 0);
64920 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
64921 }
64922
64923 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
64924
64925 void kgdb_schedule_breakpoint(void)
64926 {
64927 - if (atomic_read(&kgdb_break_tasklet_var) ||
64928 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
64929 atomic_read(&kgdb_active) != -1 ||
64930 atomic_read(&kgdb_setting_breakpoint))
64931 return;
64932 - atomic_inc(&kgdb_break_tasklet_var);
64933 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
64934 tasklet_schedule(&kgdb_tasklet_breakpoint);
64935 }
64936 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
64937 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
64938 index 63786e7..0780cac 100644
64939 --- a/kernel/debug/kdb/kdb_main.c
64940 +++ b/kernel/debug/kdb/kdb_main.c
64941 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
64942 list_for_each_entry(mod, kdb_modules, list) {
64943
64944 kdb_printf("%-20s%8u 0x%p ", mod->name,
64945 - mod->core_size, (void *)mod);
64946 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
64947 #ifdef CONFIG_MODULE_UNLOAD
64948 kdb_printf("%4d ", module_refcount(mod));
64949 #endif
64950 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
64951 kdb_printf(" (Loading)");
64952 else
64953 kdb_printf(" (Live)");
64954 - kdb_printf(" 0x%p", mod->module_core);
64955 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
64956
64957 #ifdef CONFIG_MODULE_UNLOAD
64958 {
64959 diff --git a/kernel/events/core.c b/kernel/events/core.c
64960 index 58690af..d903d75 100644
64961 --- a/kernel/events/core.c
64962 +++ b/kernel/events/core.c
64963 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
64964 return 0;
64965 }
64966
64967 -static atomic64_t perf_event_id;
64968 +static atomic64_unchecked_t perf_event_id;
64969
64970 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
64971 enum event_type_t event_type);
64972 @@ -2540,7 +2540,7 @@ static void __perf_event_read(void *info)
64973
64974 static inline u64 perf_event_count(struct perf_event *event)
64975 {
64976 - return local64_read(&event->count) + atomic64_read(&event->child_count);
64977 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
64978 }
64979
64980 static u64 perf_event_read(struct perf_event *event)
64981 @@ -3065,9 +3065,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
64982 mutex_lock(&event->child_mutex);
64983 total += perf_event_read(event);
64984 *enabled += event->total_time_enabled +
64985 - atomic64_read(&event->child_total_time_enabled);
64986 + atomic64_read_unchecked(&event->child_total_time_enabled);
64987 *running += event->total_time_running +
64988 - atomic64_read(&event->child_total_time_running);
64989 + atomic64_read_unchecked(&event->child_total_time_running);
64990
64991 list_for_each_entry(child, &event->child_list, child_list) {
64992 total += perf_event_read(child);
64993 @@ -3474,10 +3474,10 @@ void perf_event_update_userpage(struct perf_event *event)
64994 userpg->offset -= local64_read(&event->hw.prev_count);
64995
64996 userpg->time_enabled = enabled +
64997 - atomic64_read(&event->child_total_time_enabled);
64998 + atomic64_read_unchecked(&event->child_total_time_enabled);
64999
65000 userpg->time_running = running +
65001 - atomic64_read(&event->child_total_time_running);
65002 + atomic64_read_unchecked(&event->child_total_time_running);
65003
65004 barrier();
65005 ++userpg->lock;
65006 @@ -3906,11 +3906,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65007 values[n++] = perf_event_count(event);
65008 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65009 values[n++] = enabled +
65010 - atomic64_read(&event->child_total_time_enabled);
65011 + atomic64_read_unchecked(&event->child_total_time_enabled);
65012 }
65013 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65014 values[n++] = running +
65015 - atomic64_read(&event->child_total_time_running);
65016 + atomic64_read_unchecked(&event->child_total_time_running);
65017 }
65018 if (read_format & PERF_FORMAT_ID)
65019 values[n++] = primary_event_id(event);
65020 @@ -4561,12 +4561,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65021 * need to add enough zero bytes after the string to handle
65022 * the 64bit alignment we do later.
65023 */
65024 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65025 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65026 if (!buf) {
65027 name = strncpy(tmp, "//enomem", sizeof(tmp));
65028 goto got_name;
65029 }
65030 - name = d_path(&file->f_path, buf, PATH_MAX);
65031 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65032 if (IS_ERR(name)) {
65033 name = strncpy(tmp, "//toolong", sizeof(tmp));
65034 goto got_name;
65035 @@ -5921,7 +5921,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65036 event->parent = parent_event;
65037
65038 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65039 - event->id = atomic64_inc_return(&perf_event_id);
65040 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65041
65042 event->state = PERF_EVENT_STATE_INACTIVE;
65043
65044 @@ -6443,10 +6443,10 @@ static void sync_child_event(struct perf_event *child_event,
65045 /*
65046 * Add back the child's count to the parent's count:
65047 */
65048 - atomic64_add(child_val, &parent_event->child_count);
65049 - atomic64_add(child_event->total_time_enabled,
65050 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65051 + atomic64_add_unchecked(child_event->total_time_enabled,
65052 &parent_event->child_total_time_enabled);
65053 - atomic64_add(child_event->total_time_running,
65054 + atomic64_add_unchecked(child_event->total_time_running,
65055 &parent_event->child_total_time_running);
65056
65057 /*
65058 diff --git a/kernel/exit.c b/kernel/exit.c
65059 index e6e01b9..0a21b0a 100644
65060 --- a/kernel/exit.c
65061 +++ b/kernel/exit.c
65062 @@ -57,6 +57,10 @@
65063 #include <asm/pgtable.h>
65064 #include <asm/mmu_context.h>
65065
65066 +#ifdef CONFIG_GRKERNSEC
65067 +extern rwlock_t grsec_exec_file_lock;
65068 +#endif
65069 +
65070 static void exit_mm(struct task_struct * tsk);
65071
65072 static void __unhash_process(struct task_struct *p, bool group_dead)
65073 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
65074 struct task_struct *leader;
65075 int zap_leader;
65076 repeat:
65077 +#ifdef CONFIG_NET
65078 + gr_del_task_from_ip_table(p);
65079 +#endif
65080 +
65081 /* don't need to get the RCU readlock here - the process is dead and
65082 * can't be modifying its own credentials. But shut RCU-lockdep up */
65083 rcu_read_lock();
65084 @@ -380,7 +388,7 @@ int allow_signal(int sig)
65085 * know it'll be handled, so that they don't get converted to
65086 * SIGKILL or just silently dropped.
65087 */
65088 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65089 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65090 recalc_sigpending();
65091 spin_unlock_irq(&current->sighand->siglock);
65092 return 0;
65093 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
65094 vsnprintf(current->comm, sizeof(current->comm), name, args);
65095 va_end(args);
65096
65097 +#ifdef CONFIG_GRKERNSEC
65098 + write_lock(&grsec_exec_file_lock);
65099 + if (current->exec_file) {
65100 + fput(current->exec_file);
65101 + current->exec_file = NULL;
65102 + }
65103 + write_unlock(&grsec_exec_file_lock);
65104 +#endif
65105 +
65106 + gr_set_kernel_label(current);
65107 +
65108 /*
65109 * If we were started as result of loading a module, close all of the
65110 * user space pages. We don't need them, and if we didn't close them
65111 @@ -893,6 +912,8 @@ NORET_TYPE void do_exit(long code)
65112 struct task_struct *tsk = current;
65113 int group_dead;
65114
65115 + set_fs(USER_DS);
65116 +
65117 profile_task_exit(tsk);
65118
65119 WARN_ON(blk_needs_flush_plug(tsk));
65120 @@ -909,7 +930,6 @@ NORET_TYPE void do_exit(long code)
65121 * mm_release()->clear_child_tid() from writing to a user-controlled
65122 * kernel address.
65123 */
65124 - set_fs(USER_DS);
65125
65126 ptrace_event(PTRACE_EVENT_EXIT, code);
65127
65128 @@ -971,6 +991,9 @@ NORET_TYPE void do_exit(long code)
65129 tsk->exit_code = code;
65130 taskstats_exit(tsk, group_dead);
65131
65132 + gr_acl_handle_psacct(tsk, code);
65133 + gr_acl_handle_exit();
65134 +
65135 exit_mm(tsk);
65136
65137 if (group_dead)
65138 @@ -1068,7 +1091,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65139 * Take down every thread in the group. This is called by fatal signals
65140 * as well as by sys_exit_group (below).
65141 */
65142 -NORET_TYPE void
65143 +__noreturn void
65144 do_group_exit(int exit_code)
65145 {
65146 struct signal_struct *sig = current->signal;
65147 diff --git a/kernel/fork.c b/kernel/fork.c
65148 index 0acf42c0..9e40e2e 100644
65149 --- a/kernel/fork.c
65150 +++ b/kernel/fork.c
65151 @@ -281,7 +281,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65152 *stackend = STACK_END_MAGIC; /* for overflow detection */
65153
65154 #ifdef CONFIG_CC_STACKPROTECTOR
65155 - tsk->stack_canary = get_random_int();
65156 + tsk->stack_canary = pax_get_random_long();
65157 #endif
65158
65159 /*
65160 @@ -305,13 +305,77 @@ out:
65161 }
65162
65163 #ifdef CONFIG_MMU
65164 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
65165 +{
65166 + struct vm_area_struct *tmp;
65167 + unsigned long charge;
65168 + struct mempolicy *pol;
65169 + struct file *file;
65170 +
65171 + charge = 0;
65172 + if (mpnt->vm_flags & VM_ACCOUNT) {
65173 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65174 + if (security_vm_enough_memory(len))
65175 + goto fail_nomem;
65176 + charge = len;
65177 + }
65178 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65179 + if (!tmp)
65180 + goto fail_nomem;
65181 + *tmp = *mpnt;
65182 + tmp->vm_mm = mm;
65183 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
65184 + pol = mpol_dup(vma_policy(mpnt));
65185 + if (IS_ERR(pol))
65186 + goto fail_nomem_policy;
65187 + vma_set_policy(tmp, pol);
65188 + if (anon_vma_fork(tmp, mpnt))
65189 + goto fail_nomem_anon_vma_fork;
65190 + tmp->vm_flags &= ~VM_LOCKED;
65191 + tmp->vm_next = tmp->vm_prev = NULL;
65192 + tmp->vm_mirror = NULL;
65193 + file = tmp->vm_file;
65194 + if (file) {
65195 + struct inode *inode = file->f_path.dentry->d_inode;
65196 + struct address_space *mapping = file->f_mapping;
65197 +
65198 + get_file(file);
65199 + if (tmp->vm_flags & VM_DENYWRITE)
65200 + atomic_dec(&inode->i_writecount);
65201 + mutex_lock(&mapping->i_mmap_mutex);
65202 + if (tmp->vm_flags & VM_SHARED)
65203 + mapping->i_mmap_writable++;
65204 + flush_dcache_mmap_lock(mapping);
65205 + /* insert tmp into the share list, just after mpnt */
65206 + vma_prio_tree_add(tmp, mpnt);
65207 + flush_dcache_mmap_unlock(mapping);
65208 + mutex_unlock(&mapping->i_mmap_mutex);
65209 + }
65210 +
65211 + /*
65212 + * Clear hugetlb-related page reserves for children. This only
65213 + * affects MAP_PRIVATE mappings. Faults generated by the child
65214 + * are not guaranteed to succeed, even if read-only
65215 + */
65216 + if (is_vm_hugetlb_page(tmp))
65217 + reset_vma_resv_huge_pages(tmp);
65218 +
65219 + return tmp;
65220 +
65221 +fail_nomem_anon_vma_fork:
65222 + mpol_put(pol);
65223 +fail_nomem_policy:
65224 + kmem_cache_free(vm_area_cachep, tmp);
65225 +fail_nomem:
65226 + vm_unacct_memory(charge);
65227 + return NULL;
65228 +}
65229 +
65230 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65231 {
65232 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
65233 struct rb_node **rb_link, *rb_parent;
65234 int retval;
65235 - unsigned long charge;
65236 - struct mempolicy *pol;
65237
65238 down_write(&oldmm->mmap_sem);
65239 flush_cache_dup_mm(oldmm);
65240 @@ -323,8 +387,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65241 mm->locked_vm = 0;
65242 mm->mmap = NULL;
65243 mm->mmap_cache = NULL;
65244 - mm->free_area_cache = oldmm->mmap_base;
65245 - mm->cached_hole_size = ~0UL;
65246 + mm->free_area_cache = oldmm->free_area_cache;
65247 + mm->cached_hole_size = oldmm->cached_hole_size;
65248 mm->map_count = 0;
65249 cpumask_clear(mm_cpumask(mm));
65250 mm->mm_rb = RB_ROOT;
65251 @@ -340,8 +404,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65252
65253 prev = NULL;
65254 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
65255 - struct file *file;
65256 -
65257 if (mpnt->vm_flags & VM_DONTCOPY) {
65258 long pages = vma_pages(mpnt);
65259 mm->total_vm -= pages;
65260 @@ -349,53 +411,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65261 -pages);
65262 continue;
65263 }
65264 - charge = 0;
65265 - if (mpnt->vm_flags & VM_ACCOUNT) {
65266 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65267 - if (security_vm_enough_memory(len))
65268 - goto fail_nomem;
65269 - charge = len;
65270 + tmp = dup_vma(mm, mpnt);
65271 + if (!tmp) {
65272 + retval = -ENOMEM;
65273 + goto out;
65274 }
65275 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65276 - if (!tmp)
65277 - goto fail_nomem;
65278 - *tmp = *mpnt;
65279 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
65280 - pol = mpol_dup(vma_policy(mpnt));
65281 - retval = PTR_ERR(pol);
65282 - if (IS_ERR(pol))
65283 - goto fail_nomem_policy;
65284 - vma_set_policy(tmp, pol);
65285 - tmp->vm_mm = mm;
65286 - if (anon_vma_fork(tmp, mpnt))
65287 - goto fail_nomem_anon_vma_fork;
65288 - tmp->vm_flags &= ~VM_LOCKED;
65289 - tmp->vm_next = tmp->vm_prev = NULL;
65290 - file = tmp->vm_file;
65291 - if (file) {
65292 - struct inode *inode = file->f_path.dentry->d_inode;
65293 - struct address_space *mapping = file->f_mapping;
65294 -
65295 - get_file(file);
65296 - if (tmp->vm_flags & VM_DENYWRITE)
65297 - atomic_dec(&inode->i_writecount);
65298 - mutex_lock(&mapping->i_mmap_mutex);
65299 - if (tmp->vm_flags & VM_SHARED)
65300 - mapping->i_mmap_writable++;
65301 - flush_dcache_mmap_lock(mapping);
65302 - /* insert tmp into the share list, just after mpnt */
65303 - vma_prio_tree_add(tmp, mpnt);
65304 - flush_dcache_mmap_unlock(mapping);
65305 - mutex_unlock(&mapping->i_mmap_mutex);
65306 - }
65307 -
65308 - /*
65309 - * Clear hugetlb-related page reserves for children. This only
65310 - * affects MAP_PRIVATE mappings. Faults generated by the child
65311 - * are not guaranteed to succeed, even if read-only
65312 - */
65313 - if (is_vm_hugetlb_page(tmp))
65314 - reset_vma_resv_huge_pages(tmp);
65315
65316 /*
65317 * Link in the new vma and copy the page table entries.
65318 @@ -418,6 +438,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65319 if (retval)
65320 goto out;
65321 }
65322 +
65323 +#ifdef CONFIG_PAX_SEGMEXEC
65324 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65325 + struct vm_area_struct *mpnt_m;
65326 +
65327 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65328 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65329 +
65330 + if (!mpnt->vm_mirror)
65331 + continue;
65332 +
65333 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65334 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65335 + mpnt->vm_mirror = mpnt_m;
65336 + } else {
65337 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65338 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65339 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65340 + mpnt->vm_mirror->vm_mirror = mpnt;
65341 + }
65342 + }
65343 + BUG_ON(mpnt_m);
65344 + }
65345 +#endif
65346 +
65347 /* a new mm has just been created */
65348 arch_dup_mmap(oldmm, mm);
65349 retval = 0;
65350 @@ -426,14 +471,6 @@ out:
65351 flush_tlb_mm(oldmm);
65352 up_write(&oldmm->mmap_sem);
65353 return retval;
65354 -fail_nomem_anon_vma_fork:
65355 - mpol_put(pol);
65356 -fail_nomem_policy:
65357 - kmem_cache_free(vm_area_cachep, tmp);
65358 -fail_nomem:
65359 - retval = -ENOMEM;
65360 - vm_unacct_memory(charge);
65361 - goto out;
65362 }
65363
65364 static inline int mm_alloc_pgd(struct mm_struct *mm)
65365 @@ -645,6 +682,26 @@ struct mm_struct *get_task_mm(struct task_struct *task)
65366 }
65367 EXPORT_SYMBOL_GPL(get_task_mm);
65368
65369 +struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65370 +{
65371 + struct mm_struct *mm;
65372 + int err;
65373 +
65374 + err = mutex_lock_killable(&task->signal->cred_guard_mutex);
65375 + if (err)
65376 + return ERR_PTR(err);
65377 +
65378 + mm = get_task_mm(task);
65379 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65380 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65381 + mmput(mm);
65382 + mm = ERR_PTR(-EACCES);
65383 + }
65384 + mutex_unlock(&task->signal->cred_guard_mutex);
65385 +
65386 + return mm;
65387 +}
65388 +
65389 /* Please note the differences between mmput and mm_release.
65390 * mmput is called whenever we stop holding onto a mm_struct,
65391 * error success whatever.
65392 @@ -830,13 +887,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65393 spin_unlock(&fs->lock);
65394 return -EAGAIN;
65395 }
65396 - fs->users++;
65397 + atomic_inc(&fs->users);
65398 spin_unlock(&fs->lock);
65399 return 0;
65400 }
65401 tsk->fs = copy_fs_struct(fs);
65402 if (!tsk->fs)
65403 return -ENOMEM;
65404 + gr_set_chroot_entries(tsk, &tsk->fs->root);
65405 return 0;
65406 }
65407
65408 @@ -1100,6 +1158,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65409 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65410 #endif
65411 retval = -EAGAIN;
65412 +
65413 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65414 +
65415 if (atomic_read(&p->real_cred->user->processes) >=
65416 task_rlimit(p, RLIMIT_NPROC)) {
65417 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65418 @@ -1259,6 +1320,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65419 if (clone_flags & CLONE_THREAD)
65420 p->tgid = current->tgid;
65421
65422 + gr_copy_label(p);
65423 +
65424 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
65425 /*
65426 * Clear TID on mm_release()?
65427 @@ -1421,6 +1484,8 @@ bad_fork_cleanup_count:
65428 bad_fork_free:
65429 free_task(p);
65430 fork_out:
65431 + gr_log_forkfail(retval);
65432 +
65433 return ERR_PTR(retval);
65434 }
65435
65436 @@ -1521,6 +1586,8 @@ long do_fork(unsigned long clone_flags,
65437 if (clone_flags & CLONE_PARENT_SETTID)
65438 put_user(nr, parent_tidptr);
65439
65440 + gr_handle_brute_check();
65441 +
65442 if (clone_flags & CLONE_VFORK) {
65443 p->vfork_done = &vfork;
65444 init_completion(&vfork);
65445 @@ -1630,7 +1697,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65446 return 0;
65447
65448 /* don't need lock here; in the worst case we'll do useless copy */
65449 - if (fs->users == 1)
65450 + if (atomic_read(&fs->users) == 1)
65451 return 0;
65452
65453 *new_fsp = copy_fs_struct(fs);
65454 @@ -1719,7 +1786,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65455 fs = current->fs;
65456 spin_lock(&fs->lock);
65457 current->fs = new_fs;
65458 - if (--fs->users)
65459 + gr_set_chroot_entries(current, &current->fs->root);
65460 + if (atomic_dec_return(&fs->users))
65461 new_fs = NULL;
65462 else
65463 new_fs = fs;
65464 diff --git a/kernel/futex.c b/kernel/futex.c
65465 index 1614be2..37abc7e 100644
65466 --- a/kernel/futex.c
65467 +++ b/kernel/futex.c
65468 @@ -54,6 +54,7 @@
65469 #include <linux/mount.h>
65470 #include <linux/pagemap.h>
65471 #include <linux/syscalls.h>
65472 +#include <linux/ptrace.h>
65473 #include <linux/signal.h>
65474 #include <linux/export.h>
65475 #include <linux/magic.h>
65476 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65477 struct page *page, *page_head;
65478 int err, ro = 0;
65479
65480 +#ifdef CONFIG_PAX_SEGMEXEC
65481 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65482 + return -EFAULT;
65483 +#endif
65484 +
65485 /*
65486 * The futex address must be "naturally" aligned.
65487 */
65488 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
65489 if (!p)
65490 goto err_unlock;
65491 ret = -EPERM;
65492 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65493 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
65494 + goto err_unlock;
65495 +#endif
65496 pcred = __task_cred(p);
65497 /* If victim is in different user_ns, then uids are not
65498 comparable, so we must have CAP_SYS_PTRACE */
65499 @@ -2724,6 +2734,7 @@ static int __init futex_init(void)
65500 {
65501 u32 curval;
65502 int i;
65503 + mm_segment_t oldfs;
65504
65505 /*
65506 * This will fail and we want it. Some arch implementations do
65507 @@ -2735,8 +2746,11 @@ static int __init futex_init(void)
65508 * implementation, the non-functional ones will return
65509 * -ENOSYS.
65510 */
65511 + oldfs = get_fs();
65512 + set_fs(USER_DS);
65513 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65514 futex_cmpxchg_enabled = 1;
65515 + set_fs(oldfs);
65516
65517 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65518 plist_head_init(&futex_queues[i].chain);
65519 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
65520 index 5f9e689..582d46d 100644
65521 --- a/kernel/futex_compat.c
65522 +++ b/kernel/futex_compat.c
65523 @@ -10,6 +10,7 @@
65524 #include <linux/compat.h>
65525 #include <linux/nsproxy.h>
65526 #include <linux/futex.h>
65527 +#include <linux/ptrace.h>
65528
65529 #include <asm/uaccess.h>
65530
65531 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65532 {
65533 struct compat_robust_list_head __user *head;
65534 unsigned long ret;
65535 - const struct cred *cred = current_cred(), *pcred;
65536 + const struct cred *cred = current_cred();
65537 + const struct cred *pcred;
65538
65539 if (!futex_cmpxchg_enabled)
65540 return -ENOSYS;
65541 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65542 if (!p)
65543 goto err_unlock;
65544 ret = -EPERM;
65545 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65546 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
65547 + goto err_unlock;
65548 +#endif
65549 pcred = __task_cred(p);
65550 /* If victim is in different user_ns, then uids are not
65551 comparable, so we must have CAP_SYS_PTRACE */
65552 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65553 index 9b22d03..6295b62 100644
65554 --- a/kernel/gcov/base.c
65555 +++ b/kernel/gcov/base.c
65556 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
65557 }
65558
65559 #ifdef CONFIG_MODULES
65560 -static inline int within(void *addr, void *start, unsigned long size)
65561 -{
65562 - return ((addr >= start) && (addr < start + size));
65563 -}
65564 -
65565 /* Update list and generate events when modules are unloaded. */
65566 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65567 void *data)
65568 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65569 prev = NULL;
65570 /* Remove entries located in module from linked list. */
65571 for (info = gcov_info_head; info; info = info->next) {
65572 - if (within(info, mod->module_core, mod->core_size)) {
65573 + if (within_module_core_rw((unsigned long)info, mod)) {
65574 if (prev)
65575 prev->next = info->next;
65576 else
65577 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65578 index ae34bf5..4e2f3d0 100644
65579 --- a/kernel/hrtimer.c
65580 +++ b/kernel/hrtimer.c
65581 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65582 local_irq_restore(flags);
65583 }
65584
65585 -static void run_hrtimer_softirq(struct softirq_action *h)
65586 +static void run_hrtimer_softirq(void)
65587 {
65588 hrtimer_peek_ahead_timers();
65589 }
65590 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65591 index 66ff710..05a5128 100644
65592 --- a/kernel/jump_label.c
65593 +++ b/kernel/jump_label.c
65594 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65595
65596 size = (((unsigned long)stop - (unsigned long)start)
65597 / sizeof(struct jump_entry));
65598 + pax_open_kernel();
65599 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65600 + pax_close_kernel();
65601 }
65602
65603 static void jump_label_update(struct jump_label_key *key, int enable);
65604 @@ -303,10 +305,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65605 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65606 struct jump_entry *iter;
65607
65608 + pax_open_kernel();
65609 for (iter = iter_start; iter < iter_stop; iter++) {
65610 if (within_module_init(iter->code, mod))
65611 iter->code = 0;
65612 }
65613 + pax_close_kernel();
65614 }
65615
65616 static int
65617 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65618 index 079f1d3..a407562 100644
65619 --- a/kernel/kallsyms.c
65620 +++ b/kernel/kallsyms.c
65621 @@ -11,6 +11,9 @@
65622 * Changed the compression method from stem compression to "table lookup"
65623 * compression (see scripts/kallsyms.c for a more complete description)
65624 */
65625 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65626 +#define __INCLUDED_BY_HIDESYM 1
65627 +#endif
65628 #include <linux/kallsyms.h>
65629 #include <linux/module.h>
65630 #include <linux/init.h>
65631 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65632
65633 static inline int is_kernel_inittext(unsigned long addr)
65634 {
65635 + if (system_state != SYSTEM_BOOTING)
65636 + return 0;
65637 +
65638 if (addr >= (unsigned long)_sinittext
65639 && addr <= (unsigned long)_einittext)
65640 return 1;
65641 return 0;
65642 }
65643
65644 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65645 +#ifdef CONFIG_MODULES
65646 +static inline int is_module_text(unsigned long addr)
65647 +{
65648 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65649 + return 1;
65650 +
65651 + addr = ktla_ktva(addr);
65652 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65653 +}
65654 +#else
65655 +static inline int is_module_text(unsigned long addr)
65656 +{
65657 + return 0;
65658 +}
65659 +#endif
65660 +#endif
65661 +
65662 static inline int is_kernel_text(unsigned long addr)
65663 {
65664 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65665 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65666
65667 static inline int is_kernel(unsigned long addr)
65668 {
65669 +
65670 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65671 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
65672 + return 1;
65673 +
65674 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65675 +#else
65676 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65677 +#endif
65678 +
65679 return 1;
65680 return in_gate_area_no_mm(addr);
65681 }
65682
65683 static int is_ksym_addr(unsigned long addr)
65684 {
65685 +
65686 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65687 + if (is_module_text(addr))
65688 + return 0;
65689 +#endif
65690 +
65691 if (all_var)
65692 return is_kernel(addr);
65693
65694 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65695
65696 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65697 {
65698 - iter->name[0] = '\0';
65699 iter->nameoff = get_symbol_offset(new_pos);
65700 iter->pos = new_pos;
65701 }
65702 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65703 {
65704 struct kallsym_iter *iter = m->private;
65705
65706 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65707 + if (current_uid())
65708 + return 0;
65709 +#endif
65710 +
65711 /* Some debugging symbols have no name. Ignore them. */
65712 if (!iter->name[0])
65713 return 0;
65714 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65715 struct kallsym_iter *iter;
65716 int ret;
65717
65718 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65719 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65720 if (!iter)
65721 return -ENOMEM;
65722 reset_iter(iter, 0);
65723 diff --git a/kernel/kexec.c b/kernel/kexec.c
65724 index dc7bc08..4601964 100644
65725 --- a/kernel/kexec.c
65726 +++ b/kernel/kexec.c
65727 @@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65728 unsigned long flags)
65729 {
65730 struct compat_kexec_segment in;
65731 - struct kexec_segment out, __user *ksegments;
65732 + struct kexec_segment out;
65733 + struct kexec_segment __user *ksegments;
65734 unsigned long i, result;
65735
65736 /* Don't allow clients that don't understand the native
65737 diff --git a/kernel/kmod.c b/kernel/kmod.c
65738 index a4bea97..7a1ae9a 100644
65739 --- a/kernel/kmod.c
65740 +++ b/kernel/kmod.c
65741 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
65742 * If module auto-loading support is disabled then this function
65743 * becomes a no-operation.
65744 */
65745 -int __request_module(bool wait, const char *fmt, ...)
65746 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65747 {
65748 - va_list args;
65749 char module_name[MODULE_NAME_LEN];
65750 unsigned int max_modprobes;
65751 int ret;
65752 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
65753 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
65754 static char *envp[] = { "HOME=/",
65755 "TERM=linux",
65756 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
65757 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
65758 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65759 static int kmod_loop_msg;
65760
65761 - va_start(args, fmt);
65762 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65763 - va_end(args);
65764 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65765 if (ret >= MODULE_NAME_LEN)
65766 return -ENAMETOOLONG;
65767
65768 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
65769 if (ret)
65770 return ret;
65771
65772 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65773 + if (!current_uid()) {
65774 + /* hack to workaround consolekit/udisks stupidity */
65775 + read_lock(&tasklist_lock);
65776 + if (!strcmp(current->comm, "mount") &&
65777 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65778 + read_unlock(&tasklist_lock);
65779 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65780 + return -EPERM;
65781 + }
65782 + read_unlock(&tasklist_lock);
65783 + }
65784 +#endif
65785 +
65786 /* If modprobe needs a service that is in a module, we get a recursive
65787 * loop. Limit the number of running kmod threads to max_threads/2 or
65788 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
65789 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
65790 atomic_dec(&kmod_concurrent);
65791 return ret;
65792 }
65793 +
65794 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
65795 +{
65796 + va_list args;
65797 + int ret;
65798 +
65799 + va_start(args, fmt);
65800 + ret = ____request_module(wait, module_param, fmt, args);
65801 + va_end(args);
65802 +
65803 + return ret;
65804 +}
65805 +
65806 +int __request_module(bool wait, const char *fmt, ...)
65807 +{
65808 + va_list args;
65809 + int ret;
65810 +
65811 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65812 + if (current_uid()) {
65813 + char module_param[MODULE_NAME_LEN];
65814 +
65815 + memset(module_param, 0, sizeof(module_param));
65816 +
65817 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
65818 +
65819 + va_start(args, fmt);
65820 + ret = ____request_module(wait, module_param, fmt, args);
65821 + va_end(args);
65822 +
65823 + return ret;
65824 + }
65825 +#endif
65826 +
65827 + va_start(args, fmt);
65828 + ret = ____request_module(wait, NULL, fmt, args);
65829 + va_end(args);
65830 +
65831 + return ret;
65832 +}
65833 +
65834 EXPORT_SYMBOL(__request_module);
65835 #endif /* CONFIG_MODULES */
65836
65837 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
65838 *
65839 * Thus the __user pointer cast is valid here.
65840 */
65841 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
65842 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
65843
65844 /*
65845 * If ret is 0, either ____call_usermodehelper failed and the
65846 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
65847 index bc90b87..43c7d8c 100644
65848 --- a/kernel/kprobes.c
65849 +++ b/kernel/kprobes.c
65850 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
65851 * kernel image and loaded module images reside. This is required
65852 * so x86_64 can correctly handle the %rip-relative fixups.
65853 */
65854 - kip->insns = module_alloc(PAGE_SIZE);
65855 + kip->insns = module_alloc_exec(PAGE_SIZE);
65856 if (!kip->insns) {
65857 kfree(kip);
65858 return NULL;
65859 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
65860 */
65861 if (!list_is_singular(&kip->list)) {
65862 list_del(&kip->list);
65863 - module_free(NULL, kip->insns);
65864 + module_free_exec(NULL, kip->insns);
65865 kfree(kip);
65866 }
65867 return 1;
65868 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
65869 {
65870 int i, err = 0;
65871 unsigned long offset = 0, size = 0;
65872 - char *modname, namebuf[128];
65873 + char *modname, namebuf[KSYM_NAME_LEN];
65874 const char *symbol_name;
65875 void *addr;
65876 struct kprobe_blackpoint *kb;
65877 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
65878 const char *sym = NULL;
65879 unsigned int i = *(loff_t *) v;
65880 unsigned long offset = 0;
65881 - char *modname, namebuf[128];
65882 + char *modname, namebuf[KSYM_NAME_LEN];
65883
65884 head = &kprobe_table[i];
65885 preempt_disable();
65886 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
65887 index b2e08c9..01d8049 100644
65888 --- a/kernel/lockdep.c
65889 +++ b/kernel/lockdep.c
65890 @@ -592,6 +592,10 @@ static int static_obj(void *obj)
65891 end = (unsigned long) &_end,
65892 addr = (unsigned long) obj;
65893
65894 +#ifdef CONFIG_PAX_KERNEXEC
65895 + start = ktla_ktva(start);
65896 +#endif
65897 +
65898 /*
65899 * static variable?
65900 */
65901 @@ -731,6 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
65902 if (!static_obj(lock->key)) {
65903 debug_locks_off();
65904 printk("INFO: trying to register non-static key.\n");
65905 + printk("lock:%pS key:%pS.\n", lock, lock->key);
65906 printk("the code is fine but needs lockdep annotation.\n");
65907 printk("turning off the locking correctness validator.\n");
65908 dump_stack();
65909 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
65910 if (!class)
65911 return 0;
65912 }
65913 - atomic_inc((atomic_t *)&class->ops);
65914 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
65915 if (very_verbose(class)) {
65916 printk("\nacquire class [%p] %s", class->key, class->name);
65917 if (class->name_version > 1)
65918 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
65919 index 91c32a0..b2c71c5 100644
65920 --- a/kernel/lockdep_proc.c
65921 +++ b/kernel/lockdep_proc.c
65922 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
65923
65924 static void print_name(struct seq_file *m, struct lock_class *class)
65925 {
65926 - char str[128];
65927 + char str[KSYM_NAME_LEN];
65928 const char *name = class->name;
65929
65930 if (!name) {
65931 diff --git a/kernel/module.c b/kernel/module.c
65932 index 178333c..04e3408 100644
65933 --- a/kernel/module.c
65934 +++ b/kernel/module.c
65935 @@ -58,6 +58,7 @@
65936 #include <linux/jump_label.h>
65937 #include <linux/pfn.h>
65938 #include <linux/bsearch.h>
65939 +#include <linux/grsecurity.h>
65940
65941 #define CREATE_TRACE_POINTS
65942 #include <trace/events/module.h>
65943 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
65944
65945 /* Bounds of module allocation, for speeding __module_address.
65946 * Protected by module_mutex. */
65947 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
65948 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
65949 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
65950
65951 int register_module_notifier(struct notifier_block * nb)
65952 {
65953 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65954 return true;
65955
65956 list_for_each_entry_rcu(mod, &modules, list) {
65957 - struct symsearch arr[] = {
65958 + struct symsearch modarr[] = {
65959 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
65960 NOT_GPL_ONLY, false },
65961 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
65962 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65963 #endif
65964 };
65965
65966 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
65967 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
65968 return true;
65969 }
65970 return false;
65971 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
65972 static int percpu_modalloc(struct module *mod,
65973 unsigned long size, unsigned long align)
65974 {
65975 - if (align > PAGE_SIZE) {
65976 + if (align-1 >= PAGE_SIZE) {
65977 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
65978 mod->name, align, PAGE_SIZE);
65979 align = PAGE_SIZE;
65980 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
65981 */
65982 #ifdef CONFIG_SYSFS
65983
65984 -#ifdef CONFIG_KALLSYMS
65985 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65986 static inline bool sect_empty(const Elf_Shdr *sect)
65987 {
65988 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
65989 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
65990
65991 static void unset_module_core_ro_nx(struct module *mod)
65992 {
65993 - set_page_attributes(mod->module_core + mod->core_text_size,
65994 - mod->module_core + mod->core_size,
65995 + set_page_attributes(mod->module_core_rw,
65996 + mod->module_core_rw + mod->core_size_rw,
65997 set_memory_x);
65998 - set_page_attributes(mod->module_core,
65999 - mod->module_core + mod->core_ro_size,
66000 + set_page_attributes(mod->module_core_rx,
66001 + mod->module_core_rx + mod->core_size_rx,
66002 set_memory_rw);
66003 }
66004
66005 static void unset_module_init_ro_nx(struct module *mod)
66006 {
66007 - set_page_attributes(mod->module_init + mod->init_text_size,
66008 - mod->module_init + mod->init_size,
66009 + set_page_attributes(mod->module_init_rw,
66010 + mod->module_init_rw + mod->init_size_rw,
66011 set_memory_x);
66012 - set_page_attributes(mod->module_init,
66013 - mod->module_init + mod->init_ro_size,
66014 + set_page_attributes(mod->module_init_rx,
66015 + mod->module_init_rx + mod->init_size_rx,
66016 set_memory_rw);
66017 }
66018
66019 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
66020
66021 mutex_lock(&module_mutex);
66022 list_for_each_entry_rcu(mod, &modules, list) {
66023 - if ((mod->module_core) && (mod->core_text_size)) {
66024 - set_page_attributes(mod->module_core,
66025 - mod->module_core + mod->core_text_size,
66026 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66027 + set_page_attributes(mod->module_core_rx,
66028 + mod->module_core_rx + mod->core_size_rx,
66029 set_memory_rw);
66030 }
66031 - if ((mod->module_init) && (mod->init_text_size)) {
66032 - set_page_attributes(mod->module_init,
66033 - mod->module_init + mod->init_text_size,
66034 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66035 + set_page_attributes(mod->module_init_rx,
66036 + mod->module_init_rx + mod->init_size_rx,
66037 set_memory_rw);
66038 }
66039 }
66040 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
66041
66042 mutex_lock(&module_mutex);
66043 list_for_each_entry_rcu(mod, &modules, list) {
66044 - if ((mod->module_core) && (mod->core_text_size)) {
66045 - set_page_attributes(mod->module_core,
66046 - mod->module_core + mod->core_text_size,
66047 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66048 + set_page_attributes(mod->module_core_rx,
66049 + mod->module_core_rx + mod->core_size_rx,
66050 set_memory_ro);
66051 }
66052 - if ((mod->module_init) && (mod->init_text_size)) {
66053 - set_page_attributes(mod->module_init,
66054 - mod->module_init + mod->init_text_size,
66055 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66056 + set_page_attributes(mod->module_init_rx,
66057 + mod->module_init_rx + mod->init_size_rx,
66058 set_memory_ro);
66059 }
66060 }
66061 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
66062
66063 /* This may be NULL, but that's OK */
66064 unset_module_init_ro_nx(mod);
66065 - module_free(mod, mod->module_init);
66066 + module_free(mod, mod->module_init_rw);
66067 + module_free_exec(mod, mod->module_init_rx);
66068 kfree(mod->args);
66069 percpu_modfree(mod);
66070
66071 /* Free lock-classes: */
66072 - lockdep_free_key_range(mod->module_core, mod->core_size);
66073 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66074 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66075
66076 /* Finally, free the core (containing the module structure) */
66077 unset_module_core_ro_nx(mod);
66078 - module_free(mod, mod->module_core);
66079 + module_free_exec(mod, mod->module_core_rx);
66080 + module_free(mod, mod->module_core_rw);
66081
66082 #ifdef CONFIG_MPU
66083 update_protections(current->mm);
66084 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66085 unsigned int i;
66086 int ret = 0;
66087 const struct kernel_symbol *ksym;
66088 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66089 + int is_fs_load = 0;
66090 + int register_filesystem_found = 0;
66091 + char *p;
66092 +
66093 + p = strstr(mod->args, "grsec_modharden_fs");
66094 + if (p) {
66095 + char *endptr = p + strlen("grsec_modharden_fs");
66096 + /* copy \0 as well */
66097 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66098 + is_fs_load = 1;
66099 + }
66100 +#endif
66101
66102 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66103 const char *name = info->strtab + sym[i].st_name;
66104
66105 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66106 + /* it's a real shame this will never get ripped and copied
66107 + upstream! ;(
66108 + */
66109 + if (is_fs_load && !strcmp(name, "register_filesystem"))
66110 + register_filesystem_found = 1;
66111 +#endif
66112 +
66113 switch (sym[i].st_shndx) {
66114 case SHN_COMMON:
66115 /* We compiled with -fno-common. These are not
66116 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66117 ksym = resolve_symbol_wait(mod, info, name);
66118 /* Ok if resolved. */
66119 if (ksym && !IS_ERR(ksym)) {
66120 + pax_open_kernel();
66121 sym[i].st_value = ksym->value;
66122 + pax_close_kernel();
66123 break;
66124 }
66125
66126 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66127 secbase = (unsigned long)mod_percpu(mod);
66128 else
66129 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66130 + pax_open_kernel();
66131 sym[i].st_value += secbase;
66132 + pax_close_kernel();
66133 break;
66134 }
66135 }
66136
66137 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66138 + if (is_fs_load && !register_filesystem_found) {
66139 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66140 + ret = -EPERM;
66141 + }
66142 +#endif
66143 +
66144 return ret;
66145 }
66146
66147 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66148 || s->sh_entsize != ~0UL
66149 || strstarts(sname, ".init"))
66150 continue;
66151 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66152 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66153 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66154 + else
66155 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66156 DEBUGP("\t%s\n", name);
66157 }
66158 - switch (m) {
66159 - case 0: /* executable */
66160 - mod->core_size = debug_align(mod->core_size);
66161 - mod->core_text_size = mod->core_size;
66162 - break;
66163 - case 1: /* RO: text and ro-data */
66164 - mod->core_size = debug_align(mod->core_size);
66165 - mod->core_ro_size = mod->core_size;
66166 - break;
66167 - case 3: /* whole core */
66168 - mod->core_size = debug_align(mod->core_size);
66169 - break;
66170 - }
66171 }
66172
66173 DEBUGP("Init section allocation order:\n");
66174 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66175 || s->sh_entsize != ~0UL
66176 || !strstarts(sname, ".init"))
66177 continue;
66178 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66179 - | INIT_OFFSET_MASK);
66180 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66181 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66182 + else
66183 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66184 + s->sh_entsize |= INIT_OFFSET_MASK;
66185 DEBUGP("\t%s\n", sname);
66186 }
66187 - switch (m) {
66188 - case 0: /* executable */
66189 - mod->init_size = debug_align(mod->init_size);
66190 - mod->init_text_size = mod->init_size;
66191 - break;
66192 - case 1: /* RO: text and ro-data */
66193 - mod->init_size = debug_align(mod->init_size);
66194 - mod->init_ro_size = mod->init_size;
66195 - break;
66196 - case 3: /* whole init */
66197 - mod->init_size = debug_align(mod->init_size);
66198 - break;
66199 - }
66200 }
66201 }
66202
66203 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66204
66205 /* Put symbol section at end of init part of module. */
66206 symsect->sh_flags |= SHF_ALLOC;
66207 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
66208 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
66209 info->index.sym) | INIT_OFFSET_MASK;
66210 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
66211
66212 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66213 }
66214
66215 /* Append room for core symbols at end of core part. */
66216 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
66217 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
66218 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
66219 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
66220
66221 /* Put string table section at end of init part of module. */
66222 strsect->sh_flags |= SHF_ALLOC;
66223 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
66224 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
66225 info->index.str) | INIT_OFFSET_MASK;
66226 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
66227
66228 /* Append room for core symbols' strings at end of core part. */
66229 - info->stroffs = mod->core_size;
66230 + info->stroffs = mod->core_size_rx;
66231 __set_bit(0, info->strmap);
66232 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
66233 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
66234 }
66235
66236 static void add_kallsyms(struct module *mod, const struct load_info *info)
66237 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66238 /* Make sure we get permanent strtab: don't use info->strtab. */
66239 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
66240
66241 + pax_open_kernel();
66242 +
66243 /* Set types up while we still have access to sections. */
66244 for (i = 0; i < mod->num_symtab; i++)
66245 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
66246
66247 - mod->core_symtab = dst = mod->module_core + info->symoffs;
66248 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
66249 src = mod->symtab;
66250 *dst = *src;
66251 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
66252 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66253 }
66254 mod->core_num_syms = ndst;
66255
66256 - mod->core_strtab = s = mod->module_core + info->stroffs;
66257 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
66258 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
66259 if (test_bit(i, info->strmap))
66260 *++s = mod->strtab[i];
66261 +
66262 + pax_close_kernel();
66263 }
66264 #else
66265 static inline void layout_symtab(struct module *mod, struct load_info *info)
66266 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
66267 return size == 0 ? NULL : vmalloc_exec(size);
66268 }
66269
66270 -static void *module_alloc_update_bounds(unsigned long size)
66271 +static void *module_alloc_update_bounds_rw(unsigned long size)
66272 {
66273 void *ret = module_alloc(size);
66274
66275 if (ret) {
66276 mutex_lock(&module_mutex);
66277 /* Update module bounds. */
66278 - if ((unsigned long)ret < module_addr_min)
66279 - module_addr_min = (unsigned long)ret;
66280 - if ((unsigned long)ret + size > module_addr_max)
66281 - module_addr_max = (unsigned long)ret + size;
66282 + if ((unsigned long)ret < module_addr_min_rw)
66283 + module_addr_min_rw = (unsigned long)ret;
66284 + if ((unsigned long)ret + size > module_addr_max_rw)
66285 + module_addr_max_rw = (unsigned long)ret + size;
66286 + mutex_unlock(&module_mutex);
66287 + }
66288 + return ret;
66289 +}
66290 +
66291 +static void *module_alloc_update_bounds_rx(unsigned long size)
66292 +{
66293 + void *ret = module_alloc_exec(size);
66294 +
66295 + if (ret) {
66296 + mutex_lock(&module_mutex);
66297 + /* Update module bounds. */
66298 + if ((unsigned long)ret < module_addr_min_rx)
66299 + module_addr_min_rx = (unsigned long)ret;
66300 + if ((unsigned long)ret + size > module_addr_max_rx)
66301 + module_addr_max_rx = (unsigned long)ret + size;
66302 mutex_unlock(&module_mutex);
66303 }
66304 return ret;
66305 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
66306 static int check_modinfo(struct module *mod, struct load_info *info)
66307 {
66308 const char *modmagic = get_modinfo(info, "vermagic");
66309 + const char *license = get_modinfo(info, "license");
66310 int err;
66311
66312 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66313 + if (!license || !license_is_gpl_compatible(license))
66314 + return -ENOEXEC;
66315 +#endif
66316 +
66317 /* This is allowed: modprobe --force will invalidate it. */
66318 if (!modmagic) {
66319 err = try_to_force_load(mod, "bad vermagic");
66320 @@ -2498,7 +2541,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66321 }
66322
66323 /* Set up license info based on the info section */
66324 - set_license(mod, get_modinfo(info, "license"));
66325 + set_license(mod, license);
66326
66327 return 0;
66328 }
66329 @@ -2592,7 +2635,7 @@ static int move_module(struct module *mod, struct load_info *info)
66330 void *ptr;
66331
66332 /* Do the allocs. */
66333 - ptr = module_alloc_update_bounds(mod->core_size);
66334 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66335 /*
66336 * The pointer to this block is stored in the module structure
66337 * which is inside the block. Just mark it as not being a
66338 @@ -2602,23 +2645,50 @@ static int move_module(struct module *mod, struct load_info *info)
66339 if (!ptr)
66340 return -ENOMEM;
66341
66342 - memset(ptr, 0, mod->core_size);
66343 - mod->module_core = ptr;
66344 + memset(ptr, 0, mod->core_size_rw);
66345 + mod->module_core_rw = ptr;
66346
66347 - ptr = module_alloc_update_bounds(mod->init_size);
66348 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66349 /*
66350 * The pointer to this block is stored in the module structure
66351 * which is inside the block. This block doesn't need to be
66352 * scanned as it contains data and code that will be freed
66353 * after the module is initialized.
66354 */
66355 - kmemleak_ignore(ptr);
66356 - if (!ptr && mod->init_size) {
66357 - module_free(mod, mod->module_core);
66358 + kmemleak_not_leak(ptr);
66359 + if (!ptr && mod->init_size_rw) {
66360 + module_free(mod, mod->module_core_rw);
66361 return -ENOMEM;
66362 }
66363 - memset(ptr, 0, mod->init_size);
66364 - mod->module_init = ptr;
66365 + memset(ptr, 0, mod->init_size_rw);
66366 + mod->module_init_rw = ptr;
66367 +
66368 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66369 + kmemleak_not_leak(ptr);
66370 + if (!ptr) {
66371 + module_free(mod, mod->module_init_rw);
66372 + module_free(mod, mod->module_core_rw);
66373 + return -ENOMEM;
66374 + }
66375 +
66376 + pax_open_kernel();
66377 + memset(ptr, 0, mod->core_size_rx);
66378 + pax_close_kernel();
66379 + mod->module_core_rx = ptr;
66380 +
66381 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66382 + kmemleak_not_leak(ptr);
66383 + if (!ptr && mod->init_size_rx) {
66384 + module_free_exec(mod, mod->module_core_rx);
66385 + module_free(mod, mod->module_init_rw);
66386 + module_free(mod, mod->module_core_rw);
66387 + return -ENOMEM;
66388 + }
66389 +
66390 + pax_open_kernel();
66391 + memset(ptr, 0, mod->init_size_rx);
66392 + pax_close_kernel();
66393 + mod->module_init_rx = ptr;
66394
66395 /* Transfer each section which specifies SHF_ALLOC */
66396 DEBUGP("final section addresses:\n");
66397 @@ -2629,16 +2699,45 @@ static int move_module(struct module *mod, struct load_info *info)
66398 if (!(shdr->sh_flags & SHF_ALLOC))
66399 continue;
66400
66401 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
66402 - dest = mod->module_init
66403 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66404 - else
66405 - dest = mod->module_core + shdr->sh_entsize;
66406 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66407 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66408 + dest = mod->module_init_rw
66409 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66410 + else
66411 + dest = mod->module_init_rx
66412 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66413 + } else {
66414 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66415 + dest = mod->module_core_rw + shdr->sh_entsize;
66416 + else
66417 + dest = mod->module_core_rx + shdr->sh_entsize;
66418 + }
66419 +
66420 + if (shdr->sh_type != SHT_NOBITS) {
66421 +
66422 +#ifdef CONFIG_PAX_KERNEXEC
66423 +#ifdef CONFIG_X86_64
66424 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66425 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66426 +#endif
66427 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66428 + pax_open_kernel();
66429 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66430 + pax_close_kernel();
66431 + } else
66432 +#endif
66433
66434 - if (shdr->sh_type != SHT_NOBITS)
66435 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66436 + }
66437 /* Update sh_addr to point to copy in image. */
66438 - shdr->sh_addr = (unsigned long)dest;
66439 +
66440 +#ifdef CONFIG_PAX_KERNEXEC
66441 + if (shdr->sh_flags & SHF_EXECINSTR)
66442 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
66443 + else
66444 +#endif
66445 +
66446 + shdr->sh_addr = (unsigned long)dest;
66447 DEBUGP("\t0x%lx %s\n",
66448 shdr->sh_addr, info->secstrings + shdr->sh_name);
66449 }
66450 @@ -2689,12 +2788,12 @@ static void flush_module_icache(const struct module *mod)
66451 * Do it before processing of module parameters, so the module
66452 * can provide parameter accessor functions of its own.
66453 */
66454 - if (mod->module_init)
66455 - flush_icache_range((unsigned long)mod->module_init,
66456 - (unsigned long)mod->module_init
66457 - + mod->init_size);
66458 - flush_icache_range((unsigned long)mod->module_core,
66459 - (unsigned long)mod->module_core + mod->core_size);
66460 + if (mod->module_init_rx)
66461 + flush_icache_range((unsigned long)mod->module_init_rx,
66462 + (unsigned long)mod->module_init_rx
66463 + + mod->init_size_rx);
66464 + flush_icache_range((unsigned long)mod->module_core_rx,
66465 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
66466
66467 set_fs(old_fs);
66468 }
66469 @@ -2774,8 +2873,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
66470 {
66471 kfree(info->strmap);
66472 percpu_modfree(mod);
66473 - module_free(mod, mod->module_init);
66474 - module_free(mod, mod->module_core);
66475 + module_free_exec(mod, mod->module_init_rx);
66476 + module_free_exec(mod, mod->module_core_rx);
66477 + module_free(mod, mod->module_init_rw);
66478 + module_free(mod, mod->module_core_rw);
66479 }
66480
66481 int __weak module_finalize(const Elf_Ehdr *hdr,
66482 @@ -2839,9 +2940,38 @@ static struct module *load_module(void __user *umod,
66483 if (err)
66484 goto free_unload;
66485
66486 + /* Now copy in args */
66487 + mod->args = strndup_user(uargs, ~0UL >> 1);
66488 + if (IS_ERR(mod->args)) {
66489 + err = PTR_ERR(mod->args);
66490 + goto free_unload;
66491 + }
66492 +
66493 /* Set up MODINFO_ATTR fields */
66494 setup_modinfo(mod, &info);
66495
66496 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66497 + {
66498 + char *p, *p2;
66499 +
66500 + if (strstr(mod->args, "grsec_modharden_netdev")) {
66501 + 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);
66502 + err = -EPERM;
66503 + goto free_modinfo;
66504 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66505 + p += strlen("grsec_modharden_normal");
66506 + p2 = strstr(p, "_");
66507 + if (p2) {
66508 + *p2 = '\0';
66509 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66510 + *p2 = '_';
66511 + }
66512 + err = -EPERM;
66513 + goto free_modinfo;
66514 + }
66515 + }
66516 +#endif
66517 +
66518 /* Fix up syms, so that st_value is a pointer to location. */
66519 err = simplify_symbols(mod, &info);
66520 if (err < 0)
66521 @@ -2857,13 +2987,6 @@ static struct module *load_module(void __user *umod,
66522
66523 flush_module_icache(mod);
66524
66525 - /* Now copy in args */
66526 - mod->args = strndup_user(uargs, ~0UL >> 1);
66527 - if (IS_ERR(mod->args)) {
66528 - err = PTR_ERR(mod->args);
66529 - goto free_arch_cleanup;
66530 - }
66531 -
66532 /* Mark state as coming so strong_try_module_get() ignores us. */
66533 mod->state = MODULE_STATE_COMING;
66534
66535 @@ -2921,11 +3044,10 @@ static struct module *load_module(void __user *umod,
66536 unlock:
66537 mutex_unlock(&module_mutex);
66538 synchronize_sched();
66539 - kfree(mod->args);
66540 - free_arch_cleanup:
66541 module_arch_cleanup(mod);
66542 free_modinfo:
66543 free_modinfo(mod);
66544 + kfree(mod->args);
66545 free_unload:
66546 module_unload_free(mod);
66547 free_module:
66548 @@ -2966,16 +3088,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66549 MODULE_STATE_COMING, mod);
66550
66551 /* Set RO and NX regions for core */
66552 - set_section_ro_nx(mod->module_core,
66553 - mod->core_text_size,
66554 - mod->core_ro_size,
66555 - mod->core_size);
66556 + set_section_ro_nx(mod->module_core_rx,
66557 + mod->core_size_rx,
66558 + mod->core_size_rx,
66559 + mod->core_size_rx);
66560
66561 /* Set RO and NX regions for init */
66562 - set_section_ro_nx(mod->module_init,
66563 - mod->init_text_size,
66564 - mod->init_ro_size,
66565 - mod->init_size);
66566 + set_section_ro_nx(mod->module_init_rx,
66567 + mod->init_size_rx,
66568 + mod->init_size_rx,
66569 + mod->init_size_rx);
66570
66571 do_mod_ctors(mod);
66572 /* Start the module */
66573 @@ -3021,11 +3143,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66574 mod->strtab = mod->core_strtab;
66575 #endif
66576 unset_module_init_ro_nx(mod);
66577 - module_free(mod, mod->module_init);
66578 - mod->module_init = NULL;
66579 - mod->init_size = 0;
66580 - mod->init_ro_size = 0;
66581 - mod->init_text_size = 0;
66582 + module_free(mod, mod->module_init_rw);
66583 + module_free_exec(mod, mod->module_init_rx);
66584 + mod->module_init_rw = NULL;
66585 + mod->module_init_rx = NULL;
66586 + mod->init_size_rw = 0;
66587 + mod->init_size_rx = 0;
66588 mutex_unlock(&module_mutex);
66589
66590 return 0;
66591 @@ -3056,10 +3179,16 @@ static const char *get_ksymbol(struct module *mod,
66592 unsigned long nextval;
66593
66594 /* At worse, next value is at end of module */
66595 - if (within_module_init(addr, mod))
66596 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
66597 + if (within_module_init_rx(addr, mod))
66598 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66599 + else if (within_module_init_rw(addr, mod))
66600 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66601 + else if (within_module_core_rx(addr, mod))
66602 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66603 + else if (within_module_core_rw(addr, mod))
66604 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66605 else
66606 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
66607 + return NULL;
66608
66609 /* Scan for closest preceding symbol, and next symbol. (ELF
66610 starts real symbols at 1). */
66611 @@ -3307,7 +3436,7 @@ static int m_show(struct seq_file *m, void *p)
66612 char buf[8];
66613
66614 seq_printf(m, "%s %u",
66615 - mod->name, mod->init_size + mod->core_size);
66616 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66617 print_unload_info(m, mod);
66618
66619 /* Informative for users. */
66620 @@ -3316,7 +3445,7 @@ static int m_show(struct seq_file *m, void *p)
66621 mod->state == MODULE_STATE_COMING ? "Loading":
66622 "Live");
66623 /* Used by oprofile and other similar tools. */
66624 - seq_printf(m, " 0x%pK", mod->module_core);
66625 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66626
66627 /* Taints info */
66628 if (mod->taints)
66629 @@ -3352,7 +3481,17 @@ static const struct file_operations proc_modules_operations = {
66630
66631 static int __init proc_modules_init(void)
66632 {
66633 +#ifndef CONFIG_GRKERNSEC_HIDESYM
66634 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66635 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66636 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66637 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66638 +#else
66639 proc_create("modules", 0, NULL, &proc_modules_operations);
66640 +#endif
66641 +#else
66642 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66643 +#endif
66644 return 0;
66645 }
66646 module_init(proc_modules_init);
66647 @@ -3411,12 +3550,12 @@ struct module *__module_address(unsigned long addr)
66648 {
66649 struct module *mod;
66650
66651 - if (addr < module_addr_min || addr > module_addr_max)
66652 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66653 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
66654 return NULL;
66655
66656 list_for_each_entry_rcu(mod, &modules, list)
66657 - if (within_module_core(addr, mod)
66658 - || within_module_init(addr, mod))
66659 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
66660 return mod;
66661 return NULL;
66662 }
66663 @@ -3450,11 +3589,20 @@ bool is_module_text_address(unsigned long addr)
66664 */
66665 struct module *__module_text_address(unsigned long addr)
66666 {
66667 - struct module *mod = __module_address(addr);
66668 + struct module *mod;
66669 +
66670 +#ifdef CONFIG_X86_32
66671 + addr = ktla_ktva(addr);
66672 +#endif
66673 +
66674 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66675 + return NULL;
66676 +
66677 + mod = __module_address(addr);
66678 +
66679 if (mod) {
66680 /* Make sure it's within the text section. */
66681 - if (!within(addr, mod->module_init, mod->init_text_size)
66682 - && !within(addr, mod->module_core, mod->core_text_size))
66683 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66684 mod = NULL;
66685 }
66686 return mod;
66687 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66688 index 7e3443f..b2a1e6b 100644
66689 --- a/kernel/mutex-debug.c
66690 +++ b/kernel/mutex-debug.c
66691 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66692 }
66693
66694 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66695 - struct thread_info *ti)
66696 + struct task_struct *task)
66697 {
66698 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66699
66700 /* Mark the current thread as blocked on the lock: */
66701 - ti->task->blocked_on = waiter;
66702 + task->blocked_on = waiter;
66703 }
66704
66705 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66706 - struct thread_info *ti)
66707 + struct task_struct *task)
66708 {
66709 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66710 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66711 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66712 - ti->task->blocked_on = NULL;
66713 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
66714 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66715 + task->blocked_on = NULL;
66716
66717 list_del_init(&waiter->list);
66718 waiter->task = NULL;
66719 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66720 index 0799fd3..d06ae3b 100644
66721 --- a/kernel/mutex-debug.h
66722 +++ b/kernel/mutex-debug.h
66723 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66724 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66725 extern void debug_mutex_add_waiter(struct mutex *lock,
66726 struct mutex_waiter *waiter,
66727 - struct thread_info *ti);
66728 + struct task_struct *task);
66729 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66730 - struct thread_info *ti);
66731 + struct task_struct *task);
66732 extern void debug_mutex_unlock(struct mutex *lock);
66733 extern void debug_mutex_init(struct mutex *lock, const char *name,
66734 struct lock_class_key *key);
66735 diff --git a/kernel/mutex.c b/kernel/mutex.c
66736 index 89096dd..f91ebc5 100644
66737 --- a/kernel/mutex.c
66738 +++ b/kernel/mutex.c
66739 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66740 spin_lock_mutex(&lock->wait_lock, flags);
66741
66742 debug_mutex_lock_common(lock, &waiter);
66743 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66744 + debug_mutex_add_waiter(lock, &waiter, task);
66745
66746 /* add waiting tasks to the end of the waitqueue (FIFO): */
66747 list_add_tail(&waiter.list, &lock->wait_list);
66748 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66749 * TASK_UNINTERRUPTIBLE case.)
66750 */
66751 if (unlikely(signal_pending_state(state, task))) {
66752 - mutex_remove_waiter(lock, &waiter,
66753 - task_thread_info(task));
66754 + mutex_remove_waiter(lock, &waiter, task);
66755 mutex_release(&lock->dep_map, 1, ip);
66756 spin_unlock_mutex(&lock->wait_lock, flags);
66757
66758 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66759 done:
66760 lock_acquired(&lock->dep_map, ip);
66761 /* got the lock - rejoice! */
66762 - mutex_remove_waiter(lock, &waiter, current_thread_info());
66763 + mutex_remove_waiter(lock, &waiter, task);
66764 mutex_set_owner(lock);
66765
66766 /* set it to 0 if there are no waiters left: */
66767 diff --git a/kernel/padata.c b/kernel/padata.c
66768 index b452599..5d68f4e 100644
66769 --- a/kernel/padata.c
66770 +++ b/kernel/padata.c
66771 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
66772 padata->pd = pd;
66773 padata->cb_cpu = cb_cpu;
66774
66775 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
66776 - atomic_set(&pd->seq_nr, -1);
66777 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
66778 + atomic_set_unchecked(&pd->seq_nr, -1);
66779
66780 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
66781 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
66782
66783 target_cpu = padata_cpu_hash(padata);
66784 queue = per_cpu_ptr(pd->pqueue, target_cpu);
66785 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
66786 padata_init_pqueues(pd);
66787 padata_init_squeues(pd);
66788 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
66789 - atomic_set(&pd->seq_nr, -1);
66790 + atomic_set_unchecked(&pd->seq_nr, -1);
66791 atomic_set(&pd->reorder_objects, 0);
66792 atomic_set(&pd->refcnt, 0);
66793 pd->pinst = pinst;
66794 diff --git a/kernel/panic.c b/kernel/panic.c
66795 index 3458469..342c500 100644
66796 --- a/kernel/panic.c
66797 +++ b/kernel/panic.c
66798 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
66799 va_end(args);
66800 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
66801 #ifdef CONFIG_DEBUG_BUGVERBOSE
66802 - dump_stack();
66803 + /*
66804 + * Avoid nested stack-dumping if a panic occurs during oops processing
66805 + */
66806 + if (!oops_in_progress)
66807 + dump_stack();
66808 #endif
66809
66810 /*
66811 @@ -382,7 +386,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
66812 const char *board;
66813
66814 printk(KERN_WARNING "------------[ cut here ]------------\n");
66815 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
66816 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
66817 board = dmi_get_system_info(DMI_PRODUCT_NAME);
66818 if (board)
66819 printk(KERN_WARNING "Hardware name: %s\n", board);
66820 @@ -437,7 +441,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
66821 */
66822 void __stack_chk_fail(void)
66823 {
66824 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
66825 + dump_stack();
66826 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
66827 __builtin_return_address(0));
66828 }
66829 EXPORT_SYMBOL(__stack_chk_fail);
66830 diff --git a/kernel/pid.c b/kernel/pid.c
66831 index fa5f722..0c93e57 100644
66832 --- a/kernel/pid.c
66833 +++ b/kernel/pid.c
66834 @@ -33,6 +33,7 @@
66835 #include <linux/rculist.h>
66836 #include <linux/bootmem.h>
66837 #include <linux/hash.h>
66838 +#include <linux/security.h>
66839 #include <linux/pid_namespace.h>
66840 #include <linux/init_task.h>
66841 #include <linux/syscalls.h>
66842 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
66843
66844 int pid_max = PID_MAX_DEFAULT;
66845
66846 -#define RESERVED_PIDS 300
66847 +#define RESERVED_PIDS 500
66848
66849 int pid_max_min = RESERVED_PIDS + 1;
66850 int pid_max_max = PID_MAX_LIMIT;
66851 @@ -418,10 +419,18 @@ EXPORT_SYMBOL(pid_task);
66852 */
66853 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
66854 {
66855 + struct task_struct *task;
66856 +
66857 rcu_lockdep_assert(rcu_read_lock_held(),
66858 "find_task_by_pid_ns() needs rcu_read_lock()"
66859 " protection");
66860 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66861 +
66862 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66863 +
66864 + if (gr_pid_is_chrooted(task))
66865 + return NULL;
66866 +
66867 + return task;
66868 }
66869
66870 struct task_struct *find_task_by_vpid(pid_t vnr)
66871 @@ -429,6 +438,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
66872 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
66873 }
66874
66875 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
66876 +{
66877 + rcu_lockdep_assert(rcu_read_lock_held(),
66878 + "find_task_by_pid_ns() needs rcu_read_lock()"
66879 + " protection");
66880 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
66881 +}
66882 +
66883 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
66884 {
66885 struct pid *pid;
66886 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
66887 index e7cb76d..75eceb3 100644
66888 --- a/kernel/posix-cpu-timers.c
66889 +++ b/kernel/posix-cpu-timers.c
66890 @@ -6,6 +6,7 @@
66891 #include <linux/posix-timers.h>
66892 #include <linux/errno.h>
66893 #include <linux/math64.h>
66894 +#include <linux/security.h>
66895 #include <asm/uaccess.h>
66896 #include <linux/kernel_stat.h>
66897 #include <trace/events/timer.h>
66898 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
66899
66900 static __init int init_posix_cpu_timers(void)
66901 {
66902 - struct k_clock process = {
66903 + static struct k_clock process = {
66904 .clock_getres = process_cpu_clock_getres,
66905 .clock_get = process_cpu_clock_get,
66906 .timer_create = process_cpu_timer_create,
66907 .nsleep = process_cpu_nsleep,
66908 .nsleep_restart = process_cpu_nsleep_restart,
66909 };
66910 - struct k_clock thread = {
66911 + static struct k_clock thread = {
66912 .clock_getres = thread_cpu_clock_getres,
66913 .clock_get = thread_cpu_clock_get,
66914 .timer_create = thread_cpu_timer_create,
66915 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
66916 index 69185ae..cc2847a 100644
66917 --- a/kernel/posix-timers.c
66918 +++ b/kernel/posix-timers.c
66919 @@ -43,6 +43,7 @@
66920 #include <linux/idr.h>
66921 #include <linux/posix-clock.h>
66922 #include <linux/posix-timers.h>
66923 +#include <linux/grsecurity.h>
66924 #include <linux/syscalls.h>
66925 #include <linux/wait.h>
66926 #include <linux/workqueue.h>
66927 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
66928 * which we beg off on and pass to do_sys_settimeofday().
66929 */
66930
66931 -static struct k_clock posix_clocks[MAX_CLOCKS];
66932 +static struct k_clock *posix_clocks[MAX_CLOCKS];
66933
66934 /*
66935 * These ones are defined below.
66936 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
66937 */
66938 static __init int init_posix_timers(void)
66939 {
66940 - struct k_clock clock_realtime = {
66941 + static struct k_clock clock_realtime = {
66942 .clock_getres = hrtimer_get_res,
66943 .clock_get = posix_clock_realtime_get,
66944 .clock_set = posix_clock_realtime_set,
66945 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
66946 .timer_get = common_timer_get,
66947 .timer_del = common_timer_del,
66948 };
66949 - struct k_clock clock_monotonic = {
66950 + static struct k_clock clock_monotonic = {
66951 .clock_getres = hrtimer_get_res,
66952 .clock_get = posix_ktime_get_ts,
66953 .nsleep = common_nsleep,
66954 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
66955 .timer_get = common_timer_get,
66956 .timer_del = common_timer_del,
66957 };
66958 - struct k_clock clock_monotonic_raw = {
66959 + static struct k_clock clock_monotonic_raw = {
66960 .clock_getres = hrtimer_get_res,
66961 .clock_get = posix_get_monotonic_raw,
66962 };
66963 - struct k_clock clock_realtime_coarse = {
66964 + static struct k_clock clock_realtime_coarse = {
66965 .clock_getres = posix_get_coarse_res,
66966 .clock_get = posix_get_realtime_coarse,
66967 };
66968 - struct k_clock clock_monotonic_coarse = {
66969 + static struct k_clock clock_monotonic_coarse = {
66970 .clock_getres = posix_get_coarse_res,
66971 .clock_get = posix_get_monotonic_coarse,
66972 };
66973 - struct k_clock clock_boottime = {
66974 + static struct k_clock clock_boottime = {
66975 .clock_getres = hrtimer_get_res,
66976 .clock_get = posix_get_boottime,
66977 .nsleep = common_nsleep,
66978 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
66979 return;
66980 }
66981
66982 - posix_clocks[clock_id] = *new_clock;
66983 + posix_clocks[clock_id] = new_clock;
66984 }
66985 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
66986
66987 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
66988 return (id & CLOCKFD_MASK) == CLOCKFD ?
66989 &clock_posix_dynamic : &clock_posix_cpu;
66990
66991 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
66992 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
66993 return NULL;
66994 - return &posix_clocks[id];
66995 + return posix_clocks[id];
66996 }
66997
66998 static int common_timer_create(struct k_itimer *new_timer)
66999 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67000 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67001 return -EFAULT;
67002
67003 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67004 + have their clock_set fptr set to a nosettime dummy function
67005 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67006 + call common_clock_set, which calls do_sys_settimeofday, which
67007 + we hook
67008 + */
67009 +
67010 return kc->clock_set(which_clock, &new_tp);
67011 }
67012
67013 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67014 index d523593..68197a4 100644
67015 --- a/kernel/power/poweroff.c
67016 +++ b/kernel/power/poweroff.c
67017 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67018 .enable_mask = SYSRQ_ENABLE_BOOT,
67019 };
67020
67021 -static int pm_sysrq_init(void)
67022 +static int __init pm_sysrq_init(void)
67023 {
67024 register_sysrq_key('o', &sysrq_poweroff_op);
67025 return 0;
67026 diff --git a/kernel/power/process.c b/kernel/power/process.c
67027 index 3d4b954..11af930 100644
67028 --- a/kernel/power/process.c
67029 +++ b/kernel/power/process.c
67030 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
67031 u64 elapsed_csecs64;
67032 unsigned int elapsed_csecs;
67033 bool wakeup = false;
67034 + bool timedout = false;
67035
67036 do_gettimeofday(&start);
67037
67038 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
67039
67040 while (true) {
67041 todo = 0;
67042 + if (time_after(jiffies, end_time))
67043 + timedout = true;
67044 read_lock(&tasklist_lock);
67045 do_each_thread(g, p) {
67046 if (frozen(p) || !freezable(p))
67047 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
67048 * try_to_stop() after schedule() in ptrace/signal
67049 * stop sees TIF_FREEZE.
67050 */
67051 - if (!task_is_stopped_or_traced(p) &&
67052 - !freezer_should_skip(p))
67053 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67054 todo++;
67055 + if (timedout) {
67056 + printk(KERN_ERR "Task refusing to freeze:\n");
67057 + sched_show_task(p);
67058 + }
67059 + }
67060 } while_each_thread(g, p);
67061 read_unlock(&tasklist_lock);
67062
67063 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
67064 todo += wq_busy;
67065 }
67066
67067 - if (!todo || time_after(jiffies, end_time))
67068 + if (!todo || timedout)
67069 break;
67070
67071 if (pm_wakeup_pending()) {
67072 diff --git a/kernel/printk.c b/kernel/printk.c
67073 index 7982a0a..2095fdc 100644
67074 --- a/kernel/printk.c
67075 +++ b/kernel/printk.c
67076 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67077 if (from_file && type != SYSLOG_ACTION_OPEN)
67078 return 0;
67079
67080 +#ifdef CONFIG_GRKERNSEC_DMESG
67081 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67082 + return -EPERM;
67083 +#endif
67084 +
67085 if (syslog_action_restricted(type)) {
67086 if (capable(CAP_SYSLOG))
67087 return 0;
67088 diff --git a/kernel/profile.c b/kernel/profile.c
67089 index 76b8e77..a2930e8 100644
67090 --- a/kernel/profile.c
67091 +++ b/kernel/profile.c
67092 @@ -39,7 +39,7 @@ struct profile_hit {
67093 /* Oprofile timer tick hook */
67094 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67095
67096 -static atomic_t *prof_buffer;
67097 +static atomic_unchecked_t *prof_buffer;
67098 static unsigned long prof_len, prof_shift;
67099
67100 int prof_on __read_mostly;
67101 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67102 hits[i].pc = 0;
67103 continue;
67104 }
67105 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67106 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67107 hits[i].hits = hits[i].pc = 0;
67108 }
67109 }
67110 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67111 * Add the current hit(s) and flush the write-queue out
67112 * to the global buffer:
67113 */
67114 - atomic_add(nr_hits, &prof_buffer[pc]);
67115 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67116 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67117 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67118 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67119 hits[i].pc = hits[i].hits = 0;
67120 }
67121 out:
67122 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67123 {
67124 unsigned long pc;
67125 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67126 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67127 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67128 }
67129 #endif /* !CONFIG_SMP */
67130
67131 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67132 return -EFAULT;
67133 buf++; p++; count--; read++;
67134 }
67135 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67136 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67137 if (copy_to_user(buf, (void *)pnt, count))
67138 return -EFAULT;
67139 read += count;
67140 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67141 }
67142 #endif
67143 profile_discard_flip_buffers();
67144 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67145 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67146 return count;
67147 }
67148
67149 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67150 index 78ab24a..332c915 100644
67151 --- a/kernel/ptrace.c
67152 +++ b/kernel/ptrace.c
67153 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
67154 return ret;
67155 }
67156
67157 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
67158 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
67159 + unsigned int log)
67160 {
67161 const struct cred *cred = current_cred(), *tcred;
67162
67163 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
67164 cred->gid == tcred->sgid &&
67165 cred->gid == tcred->gid))
67166 goto ok;
67167 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
67168 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
67169 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
67170 goto ok;
67171 rcu_read_unlock();
67172 return -EPERM;
67173 @@ -207,7 +209,9 @@ ok:
67174 smp_rmb();
67175 if (task->mm)
67176 dumpable = get_dumpable(task->mm);
67177 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
67178 + if (!dumpable &&
67179 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
67180 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
67181 return -EPERM;
67182
67183 return security_ptrace_access_check(task, mode);
67184 @@ -217,7 +221,21 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
67185 {
67186 int err;
67187 task_lock(task);
67188 - err = __ptrace_may_access(task, mode);
67189 + err = __ptrace_may_access(task, mode, 0);
67190 + task_unlock(task);
67191 + return !err;
67192 +}
67193 +
67194 +bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode)
67195 +{
67196 + return __ptrace_may_access(task, mode, 0);
67197 +}
67198 +
67199 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
67200 +{
67201 + int err;
67202 + task_lock(task);
67203 + err = __ptrace_may_access(task, mode, 1);
67204 task_unlock(task);
67205 return !err;
67206 }
67207 @@ -262,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67208 goto out;
67209
67210 task_lock(task);
67211 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
67212 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
67213 task_unlock(task);
67214 if (retval)
67215 goto unlock_creds;
67216 @@ -277,7 +295,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67217 task->ptrace = PT_PTRACED;
67218 if (seize)
67219 task->ptrace |= PT_SEIZED;
67220 - if (task_ns_capable(task, CAP_SYS_PTRACE))
67221 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
67222 task->ptrace |= PT_PTRACE_CAP;
67223
67224 __ptrace_link(task, current);
67225 @@ -483,7 +501,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67226 break;
67227 return -EIO;
67228 }
67229 - if (copy_to_user(dst, buf, retval))
67230 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67231 return -EFAULT;
67232 copied += retval;
67233 src += retval;
67234 @@ -680,7 +698,7 @@ int ptrace_request(struct task_struct *child, long request,
67235 bool seized = child->ptrace & PT_SEIZED;
67236 int ret = -EIO;
67237 siginfo_t siginfo, *si;
67238 - void __user *datavp = (void __user *) data;
67239 + void __user *datavp = (__force void __user *) data;
67240 unsigned long __user *datalp = datavp;
67241 unsigned long flags;
67242
67243 @@ -882,14 +900,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67244 goto out;
67245 }
67246
67247 + if (gr_handle_ptrace(child, request)) {
67248 + ret = -EPERM;
67249 + goto out_put_task_struct;
67250 + }
67251 +
67252 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67253 ret = ptrace_attach(child, request, data);
67254 /*
67255 * Some architectures need to do book-keeping after
67256 * a ptrace attach.
67257 */
67258 - if (!ret)
67259 + if (!ret) {
67260 arch_ptrace_attach(child);
67261 + gr_audit_ptrace(child);
67262 + }
67263 goto out_put_task_struct;
67264 }
67265
67266 @@ -915,7 +940,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67267 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67268 if (copied != sizeof(tmp))
67269 return -EIO;
67270 - return put_user(tmp, (unsigned long __user *)data);
67271 + return put_user(tmp, (__force unsigned long __user *)data);
67272 }
67273
67274 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67275 @@ -1025,14 +1050,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67276 goto out;
67277 }
67278
67279 + if (gr_handle_ptrace(child, request)) {
67280 + ret = -EPERM;
67281 + goto out_put_task_struct;
67282 + }
67283 +
67284 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67285 ret = ptrace_attach(child, request, data);
67286 /*
67287 * Some architectures need to do book-keeping after
67288 * a ptrace attach.
67289 */
67290 - if (!ret)
67291 + if (!ret) {
67292 arch_ptrace_attach(child);
67293 + gr_audit_ptrace(child);
67294 + }
67295 goto out_put_task_struct;
67296 }
67297
67298 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
67299 index 636af6d..8af70ab 100644
67300 --- a/kernel/rcutiny.c
67301 +++ b/kernel/rcutiny.c
67302 @@ -46,7 +46,7 @@
67303 struct rcu_ctrlblk;
67304 static void invoke_rcu_callbacks(void);
67305 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
67306 -static void rcu_process_callbacks(struct softirq_action *unused);
67307 +static void rcu_process_callbacks(void);
67308 static void __call_rcu(struct rcu_head *head,
67309 void (*func)(struct rcu_head *rcu),
67310 struct rcu_ctrlblk *rcp);
67311 @@ -186,7 +186,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
67312 RCU_TRACE(trace_rcu_batch_end(rcp->name, cb_count));
67313 }
67314
67315 -static void rcu_process_callbacks(struct softirq_action *unused)
67316 +static void rcu_process_callbacks(void)
67317 {
67318 __rcu_process_callbacks(&rcu_sched_ctrlblk);
67319 __rcu_process_callbacks(&rcu_bh_ctrlblk);
67320 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
67321 index 764825c..3aa6ac4 100644
67322 --- a/kernel/rcutorture.c
67323 +++ b/kernel/rcutorture.c
67324 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
67325 { 0 };
67326 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
67327 { 0 };
67328 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67329 -static atomic_t n_rcu_torture_alloc;
67330 -static atomic_t n_rcu_torture_alloc_fail;
67331 -static atomic_t n_rcu_torture_free;
67332 -static atomic_t n_rcu_torture_mberror;
67333 -static atomic_t n_rcu_torture_error;
67334 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67335 +static atomic_unchecked_t n_rcu_torture_alloc;
67336 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
67337 +static atomic_unchecked_t n_rcu_torture_free;
67338 +static atomic_unchecked_t n_rcu_torture_mberror;
67339 +static atomic_unchecked_t n_rcu_torture_error;
67340 static long n_rcu_torture_boost_ktrerror;
67341 static long n_rcu_torture_boost_rterror;
67342 static long n_rcu_torture_boost_failure;
67343 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
67344
67345 spin_lock_bh(&rcu_torture_lock);
67346 if (list_empty(&rcu_torture_freelist)) {
67347 - atomic_inc(&n_rcu_torture_alloc_fail);
67348 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
67349 spin_unlock_bh(&rcu_torture_lock);
67350 return NULL;
67351 }
67352 - atomic_inc(&n_rcu_torture_alloc);
67353 + atomic_inc_unchecked(&n_rcu_torture_alloc);
67354 p = rcu_torture_freelist.next;
67355 list_del_init(p);
67356 spin_unlock_bh(&rcu_torture_lock);
67357 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
67358 static void
67359 rcu_torture_free(struct rcu_torture *p)
67360 {
67361 - atomic_inc(&n_rcu_torture_free);
67362 + atomic_inc_unchecked(&n_rcu_torture_free);
67363 spin_lock_bh(&rcu_torture_lock);
67364 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
67365 spin_unlock_bh(&rcu_torture_lock);
67366 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
67367 i = rp->rtort_pipe_count;
67368 if (i > RCU_TORTURE_PIPE_LEN)
67369 i = RCU_TORTURE_PIPE_LEN;
67370 - atomic_inc(&rcu_torture_wcount[i]);
67371 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67372 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67373 rp->rtort_mbtest = 0;
67374 rcu_torture_free(rp);
67375 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67376 i = rp->rtort_pipe_count;
67377 if (i > RCU_TORTURE_PIPE_LEN)
67378 i = RCU_TORTURE_PIPE_LEN;
67379 - atomic_inc(&rcu_torture_wcount[i]);
67380 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67381 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67382 rp->rtort_mbtest = 0;
67383 list_del(&rp->rtort_free);
67384 @@ -872,7 +872,7 @@ rcu_torture_writer(void *arg)
67385 i = old_rp->rtort_pipe_count;
67386 if (i > RCU_TORTURE_PIPE_LEN)
67387 i = RCU_TORTURE_PIPE_LEN;
67388 - atomic_inc(&rcu_torture_wcount[i]);
67389 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67390 old_rp->rtort_pipe_count++;
67391 cur_ops->deferred_free(old_rp);
67392 }
67393 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
67394 return;
67395 }
67396 if (p->rtort_mbtest == 0)
67397 - atomic_inc(&n_rcu_torture_mberror);
67398 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67399 spin_lock(&rand_lock);
67400 cur_ops->read_delay(&rand);
67401 n_rcu_torture_timers++;
67402 @@ -1001,7 +1001,7 @@ rcu_torture_reader(void *arg)
67403 continue;
67404 }
67405 if (p->rtort_mbtest == 0)
67406 - atomic_inc(&n_rcu_torture_mberror);
67407 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67408 cur_ops->read_delay(&rand);
67409 preempt_disable();
67410 pipe_count = p->rtort_pipe_count;
67411 @@ -1060,16 +1060,16 @@ rcu_torture_printk(char *page)
67412 rcu_torture_current,
67413 rcu_torture_current_version,
67414 list_empty(&rcu_torture_freelist),
67415 - atomic_read(&n_rcu_torture_alloc),
67416 - atomic_read(&n_rcu_torture_alloc_fail),
67417 - atomic_read(&n_rcu_torture_free),
67418 - atomic_read(&n_rcu_torture_mberror),
67419 + atomic_read_unchecked(&n_rcu_torture_alloc),
67420 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67421 + atomic_read_unchecked(&n_rcu_torture_free),
67422 + atomic_read_unchecked(&n_rcu_torture_mberror),
67423 n_rcu_torture_boost_ktrerror,
67424 n_rcu_torture_boost_rterror,
67425 n_rcu_torture_boost_failure,
67426 n_rcu_torture_boosts,
67427 n_rcu_torture_timers);
67428 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67429 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67430 n_rcu_torture_boost_ktrerror != 0 ||
67431 n_rcu_torture_boost_rterror != 0 ||
67432 n_rcu_torture_boost_failure != 0)
67433 @@ -1077,7 +1077,7 @@ rcu_torture_printk(char *page)
67434 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67435 if (i > 1) {
67436 cnt += sprintf(&page[cnt], "!!! ");
67437 - atomic_inc(&n_rcu_torture_error);
67438 + atomic_inc_unchecked(&n_rcu_torture_error);
67439 WARN_ON_ONCE(1);
67440 }
67441 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67442 @@ -1091,7 +1091,7 @@ rcu_torture_printk(char *page)
67443 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67444 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67445 cnt += sprintf(&page[cnt], " %d",
67446 - atomic_read(&rcu_torture_wcount[i]));
67447 + atomic_read_unchecked(&rcu_torture_wcount[i]));
67448 }
67449 cnt += sprintf(&page[cnt], "\n");
67450 if (cur_ops->stats)
67451 @@ -1401,7 +1401,7 @@ rcu_torture_cleanup(void)
67452
67453 if (cur_ops->cleanup)
67454 cur_ops->cleanup();
67455 - if (atomic_read(&n_rcu_torture_error))
67456 + if (atomic_read_unchecked(&n_rcu_torture_error))
67457 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67458 else
67459 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
67460 @@ -1465,17 +1465,17 @@ rcu_torture_init(void)
67461
67462 rcu_torture_current = NULL;
67463 rcu_torture_current_version = 0;
67464 - atomic_set(&n_rcu_torture_alloc, 0);
67465 - atomic_set(&n_rcu_torture_alloc_fail, 0);
67466 - atomic_set(&n_rcu_torture_free, 0);
67467 - atomic_set(&n_rcu_torture_mberror, 0);
67468 - atomic_set(&n_rcu_torture_error, 0);
67469 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67470 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67471 + atomic_set_unchecked(&n_rcu_torture_free, 0);
67472 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67473 + atomic_set_unchecked(&n_rcu_torture_error, 0);
67474 n_rcu_torture_boost_ktrerror = 0;
67475 n_rcu_torture_boost_rterror = 0;
67476 n_rcu_torture_boost_failure = 0;
67477 n_rcu_torture_boosts = 0;
67478 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67479 - atomic_set(&rcu_torture_wcount[i], 0);
67480 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67481 for_each_possible_cpu(cpu) {
67482 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67483 per_cpu(rcu_torture_count, cpu)[i] = 0;
67484 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67485 index 6b76d81..7afc1b3 100644
67486 --- a/kernel/rcutree.c
67487 +++ b/kernel/rcutree.c
67488 @@ -367,9 +367,9 @@ void rcu_enter_nohz(void)
67489 trace_rcu_dyntick("Start");
67490 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67491 smp_mb__before_atomic_inc(); /* See above. */
67492 - atomic_inc(&rdtp->dynticks);
67493 + atomic_inc_unchecked(&rdtp->dynticks);
67494 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67495 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67496 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67497 local_irq_restore(flags);
67498 }
67499
67500 @@ -391,10 +391,10 @@ void rcu_exit_nohz(void)
67501 return;
67502 }
67503 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67504 - atomic_inc(&rdtp->dynticks);
67505 + atomic_inc_unchecked(&rdtp->dynticks);
67506 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67507 smp_mb__after_atomic_inc(); /* See above. */
67508 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67509 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67510 trace_rcu_dyntick("End");
67511 local_irq_restore(flags);
67512 }
67513 @@ -411,14 +411,14 @@ void rcu_nmi_enter(void)
67514 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67515
67516 if (rdtp->dynticks_nmi_nesting == 0 &&
67517 - (atomic_read(&rdtp->dynticks) & 0x1))
67518 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67519 return;
67520 rdtp->dynticks_nmi_nesting++;
67521 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67522 - atomic_inc(&rdtp->dynticks);
67523 + atomic_inc_unchecked(&rdtp->dynticks);
67524 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67525 smp_mb__after_atomic_inc(); /* See above. */
67526 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67527 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67528 }
67529
67530 /**
67531 @@ -437,9 +437,9 @@ void rcu_nmi_exit(void)
67532 return;
67533 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67534 smp_mb__before_atomic_inc(); /* See above. */
67535 - atomic_inc(&rdtp->dynticks);
67536 + atomic_inc_unchecked(&rdtp->dynticks);
67537 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67538 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67539 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67540 }
67541
67542 /**
67543 @@ -474,7 +474,7 @@ void rcu_irq_exit(void)
67544 */
67545 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67546 {
67547 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67548 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67549 return 0;
67550 }
67551
67552 @@ -489,7 +489,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67553 unsigned int curr;
67554 unsigned int snap;
67555
67556 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67557 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67558 snap = (unsigned int)rdp->dynticks_snap;
67559
67560 /*
67561 @@ -1552,7 +1552,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67562 /*
67563 * Do RCU core processing for the current CPU.
67564 */
67565 -static void rcu_process_callbacks(struct softirq_action *unused)
67566 +static void rcu_process_callbacks(void)
67567 {
67568 trace_rcu_utilization("Start RCU core");
67569 __rcu_process_callbacks(&rcu_sched_state,
67570 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67571 index 849ce9e..74bc9de 100644
67572 --- a/kernel/rcutree.h
67573 +++ b/kernel/rcutree.h
67574 @@ -86,7 +86,7 @@
67575 struct rcu_dynticks {
67576 int dynticks_nesting; /* Track irq/process nesting level. */
67577 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67578 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
67579 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
67580 };
67581
67582 /* RCU's kthread states for tracing. */
67583 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67584 index 4b9b9f8..2326053 100644
67585 --- a/kernel/rcutree_plugin.h
67586 +++ b/kernel/rcutree_plugin.h
67587 @@ -842,7 +842,7 @@ void synchronize_rcu_expedited(void)
67588
67589 /* Clean up and exit. */
67590 smp_mb(); /* ensure expedited GP seen before counter increment. */
67591 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67592 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67593 unlock_mb_ret:
67594 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67595 mb_ret:
67596 @@ -1815,8 +1815,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
67597
67598 #else /* #ifndef CONFIG_SMP */
67599
67600 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67601 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67602 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67603 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67604
67605 static int synchronize_sched_expedited_cpu_stop(void *data)
67606 {
67607 @@ -1871,7 +1871,7 @@ void synchronize_sched_expedited(void)
67608 int firstsnap, s, snap, trycount = 0;
67609
67610 /* Note that atomic_inc_return() implies full memory barrier. */
67611 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67612 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67613 get_online_cpus();
67614
67615 /*
67616 @@ -1892,7 +1892,7 @@ void synchronize_sched_expedited(void)
67617 }
67618
67619 /* Check to see if someone else did our work for us. */
67620 - s = atomic_read(&sync_sched_expedited_done);
67621 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67622 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67623 smp_mb(); /* ensure test happens before caller kfree */
67624 return;
67625 @@ -1907,7 +1907,7 @@ void synchronize_sched_expedited(void)
67626 * grace period works for us.
67627 */
67628 get_online_cpus();
67629 - snap = atomic_read(&sync_sched_expedited_started) - 1;
67630 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
67631 smp_mb(); /* ensure read is before try_stop_cpus(). */
67632 }
67633
67634 @@ -1918,12 +1918,12 @@ void synchronize_sched_expedited(void)
67635 * than we did beat us to the punch.
67636 */
67637 do {
67638 - s = atomic_read(&sync_sched_expedited_done);
67639 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67640 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67641 smp_mb(); /* ensure test happens before caller kfree */
67642 break;
67643 }
67644 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67645 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67646
67647 put_online_cpus();
67648 }
67649 @@ -1985,7 +1985,7 @@ int rcu_needs_cpu(int cpu)
67650 for_each_online_cpu(thatcpu) {
67651 if (thatcpu == cpu)
67652 continue;
67653 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
67654 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
67655 thatcpu).dynticks);
67656 smp_mb(); /* Order sampling of snap with end of grace period. */
67657 if ((snap & 0x1) != 0) {
67658 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67659 index 9feffa4..54058df 100644
67660 --- a/kernel/rcutree_trace.c
67661 +++ b/kernel/rcutree_trace.c
67662 @@ -69,7 +69,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67663 rdp->qs_pending);
67664 #ifdef CONFIG_NO_HZ
67665 seq_printf(m, " dt=%d/%d/%d df=%lu",
67666 - atomic_read(&rdp->dynticks->dynticks),
67667 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67668 rdp->dynticks->dynticks_nesting,
67669 rdp->dynticks->dynticks_nmi_nesting,
67670 rdp->dynticks_fqs);
67671 @@ -143,7 +143,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67672 rdp->qs_pending);
67673 #ifdef CONFIG_NO_HZ
67674 seq_printf(m, ",%d,%d,%d,%lu",
67675 - atomic_read(&rdp->dynticks->dynticks),
67676 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67677 rdp->dynticks->dynticks_nesting,
67678 rdp->dynticks->dynticks_nmi_nesting,
67679 rdp->dynticks_fqs);
67680 diff --git a/kernel/resource.c b/kernel/resource.c
67681 index 7640b3a..5879283 100644
67682 --- a/kernel/resource.c
67683 +++ b/kernel/resource.c
67684 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67685
67686 static int __init ioresources_init(void)
67687 {
67688 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67689 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67690 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67691 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67692 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67693 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67694 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67695 +#endif
67696 +#else
67697 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67698 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67699 +#endif
67700 return 0;
67701 }
67702 __initcall(ioresources_init);
67703 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67704 index 3d9f31c..7fefc9e 100644
67705 --- a/kernel/rtmutex-tester.c
67706 +++ b/kernel/rtmutex-tester.c
67707 @@ -20,7 +20,7 @@
67708 #define MAX_RT_TEST_MUTEXES 8
67709
67710 static spinlock_t rttest_lock;
67711 -static atomic_t rttest_event;
67712 +static atomic_unchecked_t rttest_event;
67713
67714 struct test_thread_data {
67715 int opcode;
67716 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67717
67718 case RTTEST_LOCKCONT:
67719 td->mutexes[td->opdata] = 1;
67720 - td->event = atomic_add_return(1, &rttest_event);
67721 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67722 return 0;
67723
67724 case RTTEST_RESET:
67725 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67726 return 0;
67727
67728 case RTTEST_RESETEVENT:
67729 - atomic_set(&rttest_event, 0);
67730 + atomic_set_unchecked(&rttest_event, 0);
67731 return 0;
67732
67733 default:
67734 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67735 return ret;
67736
67737 td->mutexes[id] = 1;
67738 - td->event = atomic_add_return(1, &rttest_event);
67739 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67740 rt_mutex_lock(&mutexes[id]);
67741 - td->event = atomic_add_return(1, &rttest_event);
67742 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67743 td->mutexes[id] = 4;
67744 return 0;
67745
67746 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67747 return ret;
67748
67749 td->mutexes[id] = 1;
67750 - td->event = atomic_add_return(1, &rttest_event);
67751 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67752 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67753 - td->event = atomic_add_return(1, &rttest_event);
67754 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67755 td->mutexes[id] = ret ? 0 : 4;
67756 return ret ? -EINTR : 0;
67757
67758 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67759 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67760 return ret;
67761
67762 - td->event = atomic_add_return(1, &rttest_event);
67763 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67764 rt_mutex_unlock(&mutexes[id]);
67765 - td->event = atomic_add_return(1, &rttest_event);
67766 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67767 td->mutexes[id] = 0;
67768 return 0;
67769
67770 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67771 break;
67772
67773 td->mutexes[dat] = 2;
67774 - td->event = atomic_add_return(1, &rttest_event);
67775 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67776 break;
67777
67778 default:
67779 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67780 return;
67781
67782 td->mutexes[dat] = 3;
67783 - td->event = atomic_add_return(1, &rttest_event);
67784 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67785 break;
67786
67787 case RTTEST_LOCKNOWAIT:
67788 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67789 return;
67790
67791 td->mutexes[dat] = 1;
67792 - td->event = atomic_add_return(1, &rttest_event);
67793 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67794 return;
67795
67796 default:
67797 diff --git a/kernel/sched.c b/kernel/sched.c
67798 index d6b149c..896cbb8 100644
67799 --- a/kernel/sched.c
67800 +++ b/kernel/sched.c
67801 @@ -4389,6 +4389,19 @@ pick_next_task(struct rq *rq)
67802 BUG(); /* the idle class will always have a runnable task */
67803 }
67804
67805 +#ifdef CONFIG_GRKERNSEC_SETXID
67806 +extern void gr_delayed_cred_worker(void);
67807 +static inline void gr_cred_schedule(void)
67808 +{
67809 + if (unlikely(current->delayed_cred))
67810 + gr_delayed_cred_worker();
67811 +}
67812 +#else
67813 +static inline void gr_cred_schedule(void)
67814 +{
67815 +}
67816 +#endif
67817 +
67818 /*
67819 * __schedule() is the main scheduler function.
67820 */
67821 @@ -4408,6 +4421,8 @@ need_resched:
67822
67823 schedule_debug(prev);
67824
67825 + gr_cred_schedule();
67826 +
67827 if (sched_feat(HRTICK))
67828 hrtick_clear(rq);
67829
67830 @@ -5098,6 +5113,8 @@ int can_nice(const struct task_struct *p, const int nice)
67831 /* convert nice value [19,-20] to rlimit style value [1,40] */
67832 int nice_rlim = 20 - nice;
67833
67834 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
67835 +
67836 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
67837 capable(CAP_SYS_NICE));
67838 }
67839 @@ -5131,7 +5148,8 @@ SYSCALL_DEFINE1(nice, int, increment)
67840 if (nice > 19)
67841 nice = 19;
67842
67843 - if (increment < 0 && !can_nice(current, nice))
67844 + if (increment < 0 && (!can_nice(current, nice) ||
67845 + gr_handle_chroot_nice()))
67846 return -EPERM;
67847
67848 retval = security_task_setnice(current, nice);
67849 @@ -5288,6 +5306,7 @@ recheck:
67850 unsigned long rlim_rtprio =
67851 task_rlimit(p, RLIMIT_RTPRIO);
67852
67853 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
67854 /* can't set/change the rt policy */
67855 if (policy != p->policy && !rlim_rtprio)
67856 return -EPERM;
67857 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
67858 index 429242f..d7cca82 100644
67859 --- a/kernel/sched_autogroup.c
67860 +++ b/kernel/sched_autogroup.c
67861 @@ -7,7 +7,7 @@
67862
67863 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67864 static struct autogroup autogroup_default;
67865 -static atomic_t autogroup_seq_nr;
67866 +static atomic_unchecked_t autogroup_seq_nr;
67867
67868 static void __init autogroup_init(struct task_struct *init_task)
67869 {
67870 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
67871
67872 kref_init(&ag->kref);
67873 init_rwsem(&ag->lock);
67874 - ag->id = atomic_inc_return(&autogroup_seq_nr);
67875 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
67876 ag->tg = tg;
67877 #ifdef CONFIG_RT_GROUP_SCHED
67878 /*
67879 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
67880 index 8a39fa3..34f3dbc 100644
67881 --- a/kernel/sched_fair.c
67882 +++ b/kernel/sched_fair.c
67883 @@ -4801,7 +4801,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
67884 * run_rebalance_domains is triggered when needed from the scheduler tick.
67885 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
67886 */
67887 -static void run_rebalance_domains(struct softirq_action *h)
67888 +static void run_rebalance_domains(void)
67889 {
67890 int this_cpu = smp_processor_id();
67891 struct rq *this_rq = cpu_rq(this_cpu);
67892 diff --git a/kernel/signal.c b/kernel/signal.c
67893 index 2065515..aed2987 100644
67894 --- a/kernel/signal.c
67895 +++ b/kernel/signal.c
67896 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
67897
67898 int print_fatal_signals __read_mostly;
67899
67900 -static void __user *sig_handler(struct task_struct *t, int sig)
67901 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
67902 {
67903 return t->sighand->action[sig - 1].sa.sa_handler;
67904 }
67905
67906 -static int sig_handler_ignored(void __user *handler, int sig)
67907 +static int sig_handler_ignored(__sighandler_t handler, int sig)
67908 {
67909 /* Is it explicitly or implicitly ignored? */
67910 return handler == SIG_IGN ||
67911 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
67912 static int sig_task_ignored(struct task_struct *t, int sig,
67913 int from_ancestor_ns)
67914 {
67915 - void __user *handler;
67916 + __sighandler_t handler;
67917
67918 handler = sig_handler(t, sig);
67919
67920 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
67921 atomic_inc(&user->sigpending);
67922 rcu_read_unlock();
67923
67924 + if (!override_rlimit)
67925 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
67926 +
67927 if (override_rlimit ||
67928 atomic_read(&user->sigpending) <=
67929 task_rlimit(t, RLIMIT_SIGPENDING)) {
67930 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
67931
67932 int unhandled_signal(struct task_struct *tsk, int sig)
67933 {
67934 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
67935 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
67936 if (is_global_init(tsk))
67937 return 1;
67938 if (handler != SIG_IGN && handler != SIG_DFL)
67939 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
67940 }
67941 }
67942
67943 + /* allow glibc communication via tgkill to other threads in our
67944 + thread group */
67945 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
67946 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
67947 + && gr_handle_signal(t, sig))
67948 + return -EPERM;
67949 +
67950 return security_task_kill(t, info, sig, 0);
67951 }
67952
67953 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67954 return send_signal(sig, info, p, 1);
67955 }
67956
67957 -static int
67958 +int
67959 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67960 {
67961 return send_signal(sig, info, t, 0);
67962 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67963 unsigned long int flags;
67964 int ret, blocked, ignored;
67965 struct k_sigaction *action;
67966 + int is_unhandled = 0;
67967
67968 spin_lock_irqsave(&t->sighand->siglock, flags);
67969 action = &t->sighand->action[sig-1];
67970 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67971 }
67972 if (action->sa.sa_handler == SIG_DFL)
67973 t->signal->flags &= ~SIGNAL_UNKILLABLE;
67974 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
67975 + is_unhandled = 1;
67976 ret = specific_send_sig_info(sig, info, t);
67977 spin_unlock_irqrestore(&t->sighand->siglock, flags);
67978
67979 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
67980 + normal operation */
67981 + if (is_unhandled) {
67982 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
67983 + gr_handle_crash(t, sig);
67984 + }
67985 +
67986 return ret;
67987 }
67988
67989 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67990 ret = check_kill_permission(sig, info, p);
67991 rcu_read_unlock();
67992
67993 - if (!ret && sig)
67994 + if (!ret && sig) {
67995 ret = do_send_sig_info(sig, info, p, true);
67996 + if (!ret)
67997 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
67998 + }
67999
68000 return ret;
68001 }
68002 @@ -2754,7 +2777,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68003 int error = -ESRCH;
68004
68005 rcu_read_lock();
68006 - p = find_task_by_vpid(pid);
68007 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68008 + /* allow glibc communication via tgkill to other threads in our
68009 + thread group */
68010 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68011 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68012 + p = find_task_by_vpid_unrestricted(pid);
68013 + else
68014 +#endif
68015 + p = find_task_by_vpid(pid);
68016 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68017 error = check_kill_permission(sig, info, p);
68018 /*
68019 diff --git a/kernel/smp.c b/kernel/smp.c
68020 index db197d6..17aef0b 100644
68021 --- a/kernel/smp.c
68022 +++ b/kernel/smp.c
68023 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68024 }
68025 EXPORT_SYMBOL(smp_call_function);
68026
68027 -void ipi_call_lock(void)
68028 +void ipi_call_lock(void) __acquires(call_function.lock)
68029 {
68030 raw_spin_lock(&call_function.lock);
68031 }
68032
68033 -void ipi_call_unlock(void)
68034 +void ipi_call_unlock(void) __releases(call_function.lock)
68035 {
68036 raw_spin_unlock(&call_function.lock);
68037 }
68038
68039 -void ipi_call_lock_irq(void)
68040 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68041 {
68042 raw_spin_lock_irq(&call_function.lock);
68043 }
68044
68045 -void ipi_call_unlock_irq(void)
68046 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68047 {
68048 raw_spin_unlock_irq(&call_function.lock);
68049 }
68050 diff --git a/kernel/softirq.c b/kernel/softirq.c
68051 index 2c71d91..1021f81 100644
68052 --- a/kernel/softirq.c
68053 +++ b/kernel/softirq.c
68054 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68055
68056 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68057
68058 -char *softirq_to_name[NR_SOFTIRQS] = {
68059 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68060 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68061 "TASKLET", "SCHED", "HRTIMER", "RCU"
68062 };
68063 @@ -235,7 +235,7 @@ restart:
68064 kstat_incr_softirqs_this_cpu(vec_nr);
68065
68066 trace_softirq_entry(vec_nr);
68067 - h->action(h);
68068 + h->action();
68069 trace_softirq_exit(vec_nr);
68070 if (unlikely(prev_count != preempt_count())) {
68071 printk(KERN_ERR "huh, entered softirq %u %s %p"
68072 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68073 local_irq_restore(flags);
68074 }
68075
68076 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68077 +void open_softirq(int nr, void (*action)(void))
68078 {
68079 - softirq_vec[nr].action = action;
68080 + pax_open_kernel();
68081 + *(void **)&softirq_vec[nr].action = action;
68082 + pax_close_kernel();
68083 }
68084
68085 /*
68086 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68087
68088 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68089
68090 -static void tasklet_action(struct softirq_action *a)
68091 +static void tasklet_action(void)
68092 {
68093 struct tasklet_struct *list;
68094
68095 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68096 }
68097 }
68098
68099 -static void tasklet_hi_action(struct softirq_action *a)
68100 +static void tasklet_hi_action(void)
68101 {
68102 struct tasklet_struct *list;
68103
68104 diff --git a/kernel/sys.c b/kernel/sys.c
68105 index 481611f..0754d86 100644
68106 --- a/kernel/sys.c
68107 +++ b/kernel/sys.c
68108 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68109 error = -EACCES;
68110 goto out;
68111 }
68112 +
68113 + if (gr_handle_chroot_setpriority(p, niceval)) {
68114 + error = -EACCES;
68115 + goto out;
68116 + }
68117 +
68118 no_nice = security_task_setnice(p, niceval);
68119 if (no_nice) {
68120 error = no_nice;
68121 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68122 goto error;
68123 }
68124
68125 + if (gr_check_group_change(new->gid, new->egid, -1))
68126 + goto error;
68127 +
68128 if (rgid != (gid_t) -1 ||
68129 (egid != (gid_t) -1 && egid != old->gid))
68130 new->sgid = new->egid;
68131 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68132 old = current_cred();
68133
68134 retval = -EPERM;
68135 +
68136 + if (gr_check_group_change(gid, gid, gid))
68137 + goto error;
68138 +
68139 if (nsown_capable(CAP_SETGID))
68140 new->gid = new->egid = new->sgid = new->fsgid = gid;
68141 else if (gid == old->gid || gid == old->sgid)
68142 @@ -618,7 +631,7 @@ error:
68143 /*
68144 * change the user struct in a credentials set to match the new UID
68145 */
68146 -static int set_user(struct cred *new)
68147 +int set_user(struct cred *new)
68148 {
68149 struct user_struct *new_user;
68150
68151 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68152 goto error;
68153 }
68154
68155 + if (gr_check_user_change(new->uid, new->euid, -1))
68156 + goto error;
68157 +
68158 if (new->uid != old->uid) {
68159 retval = set_user(new);
68160 if (retval < 0)
68161 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68162 old = current_cred();
68163
68164 retval = -EPERM;
68165 +
68166 + if (gr_check_crash_uid(uid))
68167 + goto error;
68168 + if (gr_check_user_change(uid, uid, uid))
68169 + goto error;
68170 +
68171 if (nsown_capable(CAP_SETUID)) {
68172 new->suid = new->uid = uid;
68173 if (uid != old->uid) {
68174 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68175 goto error;
68176 }
68177
68178 + if (gr_check_user_change(ruid, euid, -1))
68179 + goto error;
68180 +
68181 if (ruid != (uid_t) -1) {
68182 new->uid = ruid;
68183 if (ruid != old->uid) {
68184 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68185 goto error;
68186 }
68187
68188 + if (gr_check_group_change(rgid, egid, -1))
68189 + goto error;
68190 +
68191 if (rgid != (gid_t) -1)
68192 new->gid = rgid;
68193 if (egid != (gid_t) -1)
68194 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68195 old = current_cred();
68196 old_fsuid = old->fsuid;
68197
68198 + if (gr_check_user_change(-1, -1, uid))
68199 + goto error;
68200 +
68201 if (uid == old->uid || uid == old->euid ||
68202 uid == old->suid || uid == old->fsuid ||
68203 nsown_capable(CAP_SETUID)) {
68204 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68205 }
68206 }
68207
68208 +error:
68209 abort_creds(new);
68210 return old_fsuid;
68211
68212 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68213 if (gid == old->gid || gid == old->egid ||
68214 gid == old->sgid || gid == old->fsgid ||
68215 nsown_capable(CAP_SETGID)) {
68216 + if (gr_check_group_change(-1, -1, gid))
68217 + goto error;
68218 +
68219 if (gid != old_fsgid) {
68220 new->fsgid = gid;
68221 goto change_okay;
68222 }
68223 }
68224
68225 +error:
68226 abort_creds(new);
68227 return old_fsgid;
68228
68229 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
68230 }
68231 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68232 snprintf(buf, len, "2.6.%u%s", v, rest);
68233 - ret = copy_to_user(release, buf, len);
68234 + if (len > sizeof(buf))
68235 + ret = -EFAULT;
68236 + else
68237 + ret = copy_to_user(release, buf, len);
68238 }
68239 return ret;
68240 }
68241 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68242 return -EFAULT;
68243
68244 down_read(&uts_sem);
68245 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
68246 + error = __copy_to_user(name->sysname, &utsname()->sysname,
68247 __OLD_UTS_LEN);
68248 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68249 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68250 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
68251 __OLD_UTS_LEN);
68252 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68253 - error |= __copy_to_user(&name->release, &utsname()->release,
68254 + error |= __copy_to_user(name->release, &utsname()->release,
68255 __OLD_UTS_LEN);
68256 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68257 - error |= __copy_to_user(&name->version, &utsname()->version,
68258 + error |= __copy_to_user(name->version, &utsname()->version,
68259 __OLD_UTS_LEN);
68260 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68261 - error |= __copy_to_user(&name->machine, &utsname()->machine,
68262 + error |= __copy_to_user(name->machine, &utsname()->machine,
68263 __OLD_UTS_LEN);
68264 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68265 up_read(&uts_sem);
68266 @@ -1720,7 +1759,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68267 error = get_dumpable(me->mm);
68268 break;
68269 case PR_SET_DUMPABLE:
68270 - if (arg2 < 0 || arg2 > 1) {
68271 + if (arg2 > 1) {
68272 error = -EINVAL;
68273 break;
68274 }
68275 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68276 index ae27196..7506d69 100644
68277 --- a/kernel/sysctl.c
68278 +++ b/kernel/sysctl.c
68279 @@ -86,6 +86,13 @@
68280
68281
68282 #if defined(CONFIG_SYSCTL)
68283 +#include <linux/grsecurity.h>
68284 +#include <linux/grinternal.h>
68285 +
68286 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
68287 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
68288 + const int op);
68289 +extern int gr_handle_chroot_sysctl(const int op);
68290
68291 /* External variables not in a header file. */
68292 extern int sysctl_overcommit_memory;
68293 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
68294 }
68295
68296 #endif
68297 +extern struct ctl_table grsecurity_table[];
68298
68299 static struct ctl_table root_table[];
68300 static struct ctl_table_root sysctl_table_root;
68301 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
68302 int sysctl_legacy_va_layout;
68303 #endif
68304
68305 +#ifdef CONFIG_PAX_SOFTMODE
68306 +static ctl_table pax_table[] = {
68307 + {
68308 + .procname = "softmode",
68309 + .data = &pax_softmode,
68310 + .maxlen = sizeof(unsigned int),
68311 + .mode = 0600,
68312 + .proc_handler = &proc_dointvec,
68313 + },
68314 +
68315 + { }
68316 +};
68317 +#endif
68318 +
68319 /* The default sysctl tables: */
68320
68321 static struct ctl_table root_table[] = {
68322 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
68323 #endif
68324
68325 static struct ctl_table kern_table[] = {
68326 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
68327 + {
68328 + .procname = "grsecurity",
68329 + .mode = 0500,
68330 + .child = grsecurity_table,
68331 + },
68332 +#endif
68333 +
68334 +#ifdef CONFIG_PAX_SOFTMODE
68335 + {
68336 + .procname = "pax",
68337 + .mode = 0500,
68338 + .child = pax_table,
68339 + },
68340 +#endif
68341 +
68342 {
68343 .procname = "sched_child_runs_first",
68344 .data = &sysctl_sched_child_runs_first,
68345 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
68346 .data = &modprobe_path,
68347 .maxlen = KMOD_PATH_LEN,
68348 .mode = 0644,
68349 - .proc_handler = proc_dostring,
68350 + .proc_handler = proc_dostring_modpriv,
68351 },
68352 {
68353 .procname = "modules_disabled",
68354 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
68355 .extra1 = &zero,
68356 .extra2 = &one,
68357 },
68358 +#endif
68359 {
68360 .procname = "kptr_restrict",
68361 .data = &kptr_restrict,
68362 .maxlen = sizeof(int),
68363 .mode = 0644,
68364 .proc_handler = proc_dmesg_restrict,
68365 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68366 + .extra1 = &two,
68367 +#else
68368 .extra1 = &zero,
68369 +#endif
68370 .extra2 = &two,
68371 },
68372 -#endif
68373 {
68374 .procname = "ngroups_max",
68375 .data = &ngroups_max,
68376 @@ -1216,6 +1258,13 @@ static struct ctl_table vm_table[] = {
68377 .proc_handler = proc_dointvec_minmax,
68378 .extra1 = &zero,
68379 },
68380 + {
68381 + .procname = "heap_stack_gap",
68382 + .data = &sysctl_heap_stack_gap,
68383 + .maxlen = sizeof(sysctl_heap_stack_gap),
68384 + .mode = 0644,
68385 + .proc_handler = proc_doulongvec_minmax,
68386 + },
68387 #else
68388 {
68389 .procname = "nr_trim_pages",
68390 @@ -1720,6 +1769,17 @@ static int test_perm(int mode, int op)
68391 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
68392 {
68393 int mode;
68394 + int error;
68395 +
68396 + if (table->parent != NULL && table->parent->procname != NULL &&
68397 + table->procname != NULL &&
68398 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
68399 + return -EACCES;
68400 + if (gr_handle_chroot_sysctl(op))
68401 + return -EACCES;
68402 + error = gr_handle_sysctl(table, op);
68403 + if (error)
68404 + return error;
68405
68406 if (root->permissions)
68407 mode = root->permissions(root, current->nsproxy, table);
68408 @@ -2124,6 +2184,16 @@ int proc_dostring(struct ctl_table *table, int write,
68409 buffer, lenp, ppos);
68410 }
68411
68412 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68413 + void __user *buffer, size_t *lenp, loff_t *ppos)
68414 +{
68415 + if (write && !capable(CAP_SYS_MODULE))
68416 + return -EPERM;
68417 +
68418 + return _proc_do_string(table->data, table->maxlen, write,
68419 + buffer, lenp, ppos);
68420 +}
68421 +
68422 static size_t proc_skip_spaces(char **buf)
68423 {
68424 size_t ret;
68425 @@ -2229,6 +2299,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68426 len = strlen(tmp);
68427 if (len > *size)
68428 len = *size;
68429 + if (len > sizeof(tmp))
68430 + len = sizeof(tmp);
68431 if (copy_to_user(*buf, tmp, len))
68432 return -EFAULT;
68433 *size -= len;
68434 @@ -2545,8 +2617,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68435 *i = val;
68436 } else {
68437 val = convdiv * (*i) / convmul;
68438 - if (!first)
68439 + if (!first) {
68440 err = proc_put_char(&buffer, &left, '\t');
68441 + if (err)
68442 + break;
68443 + }
68444 err = proc_put_long(&buffer, &left, val, false);
68445 if (err)
68446 break;
68447 @@ -2941,6 +3016,12 @@ int proc_dostring(struct ctl_table *table, int write,
68448 return -ENOSYS;
68449 }
68450
68451 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68452 + void __user *buffer, size_t *lenp, loff_t *ppos)
68453 +{
68454 + return -ENOSYS;
68455 +}
68456 +
68457 int proc_dointvec(struct ctl_table *table, int write,
68458 void __user *buffer, size_t *lenp, loff_t *ppos)
68459 {
68460 @@ -2997,6 +3078,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68461 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68462 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68463 EXPORT_SYMBOL(proc_dostring);
68464 +EXPORT_SYMBOL(proc_dostring_modpriv);
68465 EXPORT_SYMBOL(proc_doulongvec_minmax);
68466 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68467 EXPORT_SYMBOL(register_sysctl_table);
68468 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68469 index a650694..aaeeb20 100644
68470 --- a/kernel/sysctl_binary.c
68471 +++ b/kernel/sysctl_binary.c
68472 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68473 int i;
68474
68475 set_fs(KERNEL_DS);
68476 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68477 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68478 set_fs(old_fs);
68479 if (result < 0)
68480 goto out_kfree;
68481 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68482 }
68483
68484 set_fs(KERNEL_DS);
68485 - result = vfs_write(file, buffer, str - buffer, &pos);
68486 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68487 set_fs(old_fs);
68488 if (result < 0)
68489 goto out_kfree;
68490 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68491 int i;
68492
68493 set_fs(KERNEL_DS);
68494 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68495 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68496 set_fs(old_fs);
68497 if (result < 0)
68498 goto out_kfree;
68499 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68500 }
68501
68502 set_fs(KERNEL_DS);
68503 - result = vfs_write(file, buffer, str - buffer, &pos);
68504 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68505 set_fs(old_fs);
68506 if (result < 0)
68507 goto out_kfree;
68508 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68509 int i;
68510
68511 set_fs(KERNEL_DS);
68512 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68513 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68514 set_fs(old_fs);
68515 if (result < 0)
68516 goto out;
68517 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68518 __le16 dnaddr;
68519
68520 set_fs(KERNEL_DS);
68521 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68522 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68523 set_fs(old_fs);
68524 if (result < 0)
68525 goto out;
68526 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68527 le16_to_cpu(dnaddr) & 0x3ff);
68528
68529 set_fs(KERNEL_DS);
68530 - result = vfs_write(file, buf, len, &pos);
68531 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68532 set_fs(old_fs);
68533 if (result < 0)
68534 goto out;
68535 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
68536 index 362da65..ab8ef8c 100644
68537 --- a/kernel/sysctl_check.c
68538 +++ b/kernel/sysctl_check.c
68539 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
68540 set_fail(&fail, table, "Directory with extra2");
68541 } else {
68542 if ((table->proc_handler == proc_dostring) ||
68543 + (table->proc_handler == proc_dostring_modpriv) ||
68544 (table->proc_handler == proc_dointvec) ||
68545 (table->proc_handler == proc_dointvec_minmax) ||
68546 (table->proc_handler == proc_dointvec_jiffies) ||
68547 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68548 index e660464..c8b9e67 100644
68549 --- a/kernel/taskstats.c
68550 +++ b/kernel/taskstats.c
68551 @@ -27,9 +27,12 @@
68552 #include <linux/cgroup.h>
68553 #include <linux/fs.h>
68554 #include <linux/file.h>
68555 +#include <linux/grsecurity.h>
68556 #include <net/genetlink.h>
68557 #include <linux/atomic.h>
68558
68559 +extern int gr_is_taskstats_denied(int pid);
68560 +
68561 /*
68562 * Maximum length of a cpumask that can be specified in
68563 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68564 @@ -556,6 +559,9 @@ err:
68565
68566 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68567 {
68568 + if (gr_is_taskstats_denied(current->pid))
68569 + return -EACCES;
68570 +
68571 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68572 return cmd_attr_register_cpumask(info);
68573 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68574 diff --git a/kernel/time.c b/kernel/time.c
68575 index 73e416d..cfc6f69 100644
68576 --- a/kernel/time.c
68577 +++ b/kernel/time.c
68578 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68579 return error;
68580
68581 if (tz) {
68582 + /* we log in do_settimeofday called below, so don't log twice
68583 + */
68584 + if (!tv)
68585 + gr_log_timechange();
68586 +
68587 /* SMP safe, global irq locking makes it work. */
68588 sys_tz = *tz;
68589 update_vsyscall_tz();
68590 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68591 index 8a46f5d..bbe6f9c 100644
68592 --- a/kernel/time/alarmtimer.c
68593 +++ b/kernel/time/alarmtimer.c
68594 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
68595 struct platform_device *pdev;
68596 int error = 0;
68597 int i;
68598 - struct k_clock alarm_clock = {
68599 + static struct k_clock alarm_clock = {
68600 .clock_getres = alarm_clock_getres,
68601 .clock_get = alarm_clock_get,
68602 .timer_create = alarm_timer_create,
68603 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68604 index fd4a7b1..fae5c2a 100644
68605 --- a/kernel/time/tick-broadcast.c
68606 +++ b/kernel/time/tick-broadcast.c
68607 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68608 * then clear the broadcast bit.
68609 */
68610 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68611 - int cpu = smp_processor_id();
68612 + cpu = smp_processor_id();
68613
68614 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68615 tick_broadcast_clear_oneshot(cpu);
68616 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68617 index 2378413..be455fd 100644
68618 --- a/kernel/time/timekeeping.c
68619 +++ b/kernel/time/timekeeping.c
68620 @@ -14,6 +14,7 @@
68621 #include <linux/init.h>
68622 #include <linux/mm.h>
68623 #include <linux/sched.h>
68624 +#include <linux/grsecurity.h>
68625 #include <linux/syscore_ops.h>
68626 #include <linux/clocksource.h>
68627 #include <linux/jiffies.h>
68628 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
68629 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68630 return -EINVAL;
68631
68632 + gr_log_timechange();
68633 +
68634 write_seqlock_irqsave(&xtime_lock, flags);
68635
68636 timekeeping_forward_now();
68637 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68638 index 3258455..f35227d 100644
68639 --- a/kernel/time/timer_list.c
68640 +++ b/kernel/time/timer_list.c
68641 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68642
68643 static void print_name_offset(struct seq_file *m, void *sym)
68644 {
68645 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68646 + SEQ_printf(m, "<%p>", NULL);
68647 +#else
68648 char symname[KSYM_NAME_LEN];
68649
68650 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68651 SEQ_printf(m, "<%pK>", sym);
68652 else
68653 SEQ_printf(m, "%s", symname);
68654 +#endif
68655 }
68656
68657 static void
68658 @@ -112,7 +116,11 @@ next_one:
68659 static void
68660 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68661 {
68662 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68663 + SEQ_printf(m, " .base: %p\n", NULL);
68664 +#else
68665 SEQ_printf(m, " .base: %pK\n", base);
68666 +#endif
68667 SEQ_printf(m, " .index: %d\n",
68668 base->index);
68669 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68670 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68671 {
68672 struct proc_dir_entry *pe;
68673
68674 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68675 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68676 +#else
68677 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68678 +#endif
68679 if (!pe)
68680 return -ENOMEM;
68681 return 0;
68682 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68683 index 0b537f2..9e71eca 100644
68684 --- a/kernel/time/timer_stats.c
68685 +++ b/kernel/time/timer_stats.c
68686 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68687 static unsigned long nr_entries;
68688 static struct entry entries[MAX_ENTRIES];
68689
68690 -static atomic_t overflow_count;
68691 +static atomic_unchecked_t overflow_count;
68692
68693 /*
68694 * The entries are in a hash-table, for fast lookup:
68695 @@ -140,7 +140,7 @@ static void reset_entries(void)
68696 nr_entries = 0;
68697 memset(entries, 0, sizeof(entries));
68698 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68699 - atomic_set(&overflow_count, 0);
68700 + atomic_set_unchecked(&overflow_count, 0);
68701 }
68702
68703 static struct entry *alloc_entry(void)
68704 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68705 if (likely(entry))
68706 entry->count++;
68707 else
68708 - atomic_inc(&overflow_count);
68709 + atomic_inc_unchecked(&overflow_count);
68710
68711 out_unlock:
68712 raw_spin_unlock_irqrestore(lock, flags);
68713 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68714
68715 static void print_name_offset(struct seq_file *m, unsigned long addr)
68716 {
68717 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68718 + seq_printf(m, "<%p>", NULL);
68719 +#else
68720 char symname[KSYM_NAME_LEN];
68721
68722 if (lookup_symbol_name(addr, symname) < 0)
68723 seq_printf(m, "<%p>", (void *)addr);
68724 else
68725 seq_printf(m, "%s", symname);
68726 +#endif
68727 }
68728
68729 static int tstats_show(struct seq_file *m, void *v)
68730 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68731
68732 seq_puts(m, "Timer Stats Version: v0.2\n");
68733 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68734 - if (atomic_read(&overflow_count))
68735 + if (atomic_read_unchecked(&overflow_count))
68736 seq_printf(m, "Overflow: %d entries\n",
68737 - atomic_read(&overflow_count));
68738 + atomic_read_unchecked(&overflow_count));
68739
68740 for (i = 0; i < nr_entries; i++) {
68741 entry = entries + i;
68742 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68743 {
68744 struct proc_dir_entry *pe;
68745
68746 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68747 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68748 +#else
68749 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68750 +#endif
68751 if (!pe)
68752 return -ENOMEM;
68753 return 0;
68754 diff --git a/kernel/timer.c b/kernel/timer.c
68755 index 9c3c62b..441690e 100644
68756 --- a/kernel/timer.c
68757 +++ b/kernel/timer.c
68758 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
68759 /*
68760 * This function runs timers and the timer-tq in bottom half context.
68761 */
68762 -static void run_timer_softirq(struct softirq_action *h)
68763 +static void run_timer_softirq(void)
68764 {
68765 struct tvec_base *base = __this_cpu_read(tvec_bases);
68766
68767 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68768 index 16fc34a..efd8bb8 100644
68769 --- a/kernel/trace/blktrace.c
68770 +++ b/kernel/trace/blktrace.c
68771 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68772 struct blk_trace *bt = filp->private_data;
68773 char buf[16];
68774
68775 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68776 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68777
68778 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68779 }
68780 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68781 return 1;
68782
68783 bt = buf->chan->private_data;
68784 - atomic_inc(&bt->dropped);
68785 + atomic_inc_unchecked(&bt->dropped);
68786 return 0;
68787 }
68788
68789 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68790
68791 bt->dir = dir;
68792 bt->dev = dev;
68793 - atomic_set(&bt->dropped, 0);
68794 + atomic_set_unchecked(&bt->dropped, 0);
68795
68796 ret = -EIO;
68797 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68798 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68799 index 25b4f4d..6f4772d 100644
68800 --- a/kernel/trace/ftrace.c
68801 +++ b/kernel/trace/ftrace.c
68802 @@ -1587,12 +1587,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68803 if (unlikely(ftrace_disabled))
68804 return 0;
68805
68806 + ret = ftrace_arch_code_modify_prepare();
68807 + FTRACE_WARN_ON(ret);
68808 + if (ret)
68809 + return 0;
68810 +
68811 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68812 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68813 if (ret) {
68814 ftrace_bug(ret, ip);
68815 - return 0;
68816 }
68817 - return 1;
68818 + return ret ? 0 : 1;
68819 }
68820
68821 /*
68822 @@ -2608,7 +2613,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68823
68824 int
68825 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68826 - void *data)
68827 + void *data)
68828 {
68829 struct ftrace_func_probe *entry;
68830 struct ftrace_page *pg;
68831 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68832 index f2bd275..adaf3a2 100644
68833 --- a/kernel/trace/trace.c
68834 +++ b/kernel/trace/trace.c
68835 @@ -4201,10 +4201,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68836 };
68837 #endif
68838
68839 -static struct dentry *d_tracer;
68840 -
68841 struct dentry *tracing_init_dentry(void)
68842 {
68843 + static struct dentry *d_tracer;
68844 static int once;
68845
68846 if (d_tracer)
68847 @@ -4224,10 +4223,9 @@ struct dentry *tracing_init_dentry(void)
68848 return d_tracer;
68849 }
68850
68851 -static struct dentry *d_percpu;
68852 -
68853 struct dentry *tracing_dentry_percpu(void)
68854 {
68855 + static struct dentry *d_percpu;
68856 static int once;
68857 struct dentry *d_tracer;
68858
68859 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
68860 index c212a7f..7b02394 100644
68861 --- a/kernel/trace/trace_events.c
68862 +++ b/kernel/trace/trace_events.c
68863 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
68864 struct ftrace_module_file_ops {
68865 struct list_head list;
68866 struct module *mod;
68867 - struct file_operations id;
68868 - struct file_operations enable;
68869 - struct file_operations format;
68870 - struct file_operations filter;
68871 };
68872
68873 static struct ftrace_module_file_ops *
68874 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
68875
68876 file_ops->mod = mod;
68877
68878 - file_ops->id = ftrace_event_id_fops;
68879 - file_ops->id.owner = mod;
68880 -
68881 - file_ops->enable = ftrace_enable_fops;
68882 - file_ops->enable.owner = mod;
68883 -
68884 - file_ops->filter = ftrace_event_filter_fops;
68885 - file_ops->filter.owner = mod;
68886 -
68887 - file_ops->format = ftrace_event_format_fops;
68888 - file_ops->format.owner = mod;
68889 + pax_open_kernel();
68890 + *(void **)&mod->trace_id.owner = mod;
68891 + *(void **)&mod->trace_enable.owner = mod;
68892 + *(void **)&mod->trace_filter.owner = mod;
68893 + *(void **)&mod->trace_format.owner = mod;
68894 + pax_close_kernel();
68895
68896 list_add(&file_ops->list, &ftrace_module_file_list);
68897
68898 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
68899
68900 for_each_event(call, start, end) {
68901 __trace_add_event_call(*call, mod,
68902 - &file_ops->id, &file_ops->enable,
68903 - &file_ops->filter, &file_ops->format);
68904 + &mod->trace_id, &mod->trace_enable,
68905 + &mod->trace_filter, &mod->trace_format);
68906 }
68907 }
68908
68909 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
68910 index 00d527c..7c5b1a3 100644
68911 --- a/kernel/trace/trace_kprobe.c
68912 +++ b/kernel/trace/trace_kprobe.c
68913 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68914 long ret;
68915 int maxlen = get_rloc_len(*(u32 *)dest);
68916 u8 *dst = get_rloc_data(dest);
68917 - u8 *src = addr;
68918 + const u8 __user *src = (const u8 __force_user *)addr;
68919 mm_segment_t old_fs = get_fs();
68920 if (!maxlen)
68921 return;
68922 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68923 pagefault_disable();
68924 do
68925 ret = __copy_from_user_inatomic(dst++, src++, 1);
68926 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
68927 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
68928 dst[-1] = '\0';
68929 pagefault_enable();
68930 set_fs(old_fs);
68931 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68932 ((u8 *)get_rloc_data(dest))[0] = '\0';
68933 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
68934 } else
68935 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
68936 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
68937 get_rloc_offs(*(u32 *)dest));
68938 }
68939 /* Return the length of string -- including null terminal byte */
68940 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
68941 set_fs(KERNEL_DS);
68942 pagefault_disable();
68943 do {
68944 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
68945 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
68946 len++;
68947 } while (c && ret == 0 && len < MAX_STRING_SIZE);
68948 pagefault_enable();
68949 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
68950 index fd3c8aa..5f324a6 100644
68951 --- a/kernel/trace/trace_mmiotrace.c
68952 +++ b/kernel/trace/trace_mmiotrace.c
68953 @@ -24,7 +24,7 @@ struct header_iter {
68954 static struct trace_array *mmio_trace_array;
68955 static bool overrun_detected;
68956 static unsigned long prev_overruns;
68957 -static atomic_t dropped_count;
68958 +static atomic_unchecked_t dropped_count;
68959
68960 static void mmio_reset_data(struct trace_array *tr)
68961 {
68962 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
68963
68964 static unsigned long count_overruns(struct trace_iterator *iter)
68965 {
68966 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
68967 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
68968 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
68969
68970 if (over > prev_overruns)
68971 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
68972 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
68973 sizeof(*entry), 0, pc);
68974 if (!event) {
68975 - atomic_inc(&dropped_count);
68976 + atomic_inc_unchecked(&dropped_count);
68977 return;
68978 }
68979 entry = ring_buffer_event_data(event);
68980 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
68981 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
68982 sizeof(*entry), 0, pc);
68983 if (!event) {
68984 - atomic_inc(&dropped_count);
68985 + atomic_inc_unchecked(&dropped_count);
68986 return;
68987 }
68988 entry = ring_buffer_event_data(event);
68989 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
68990 index 5199930..26c73a0 100644
68991 --- a/kernel/trace/trace_output.c
68992 +++ b/kernel/trace/trace_output.c
68993 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
68994
68995 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
68996 if (!IS_ERR(p)) {
68997 - p = mangle_path(s->buffer + s->len, p, "\n");
68998 + p = mangle_path(s->buffer + s->len, p, "\n\\");
68999 if (p) {
69000 s->len = p - s->buffer;
69001 return 1;
69002 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69003 index 77575b3..6e623d1 100644
69004 --- a/kernel/trace/trace_stack.c
69005 +++ b/kernel/trace/trace_stack.c
69006 @@ -50,7 +50,7 @@ static inline void check_stack(void)
69007 return;
69008
69009 /* we do not handle interrupt stacks yet */
69010 - if (!object_is_on_stack(&this_size))
69011 + if (!object_starts_on_stack(&this_size))
69012 return;
69013
69014 local_irq_save(flags);
69015 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69016 index 209b379..7f76423 100644
69017 --- a/kernel/trace/trace_workqueue.c
69018 +++ b/kernel/trace/trace_workqueue.c
69019 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69020 int cpu;
69021 pid_t pid;
69022 /* Can be inserted from interrupt or user context, need to be atomic */
69023 - atomic_t inserted;
69024 + atomic_unchecked_t inserted;
69025 /*
69026 * Don't need to be atomic, works are serialized in a single workqueue thread
69027 * on a single CPU.
69028 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69029 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69030 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69031 if (node->pid == wq_thread->pid) {
69032 - atomic_inc(&node->inserted);
69033 + atomic_inc_unchecked(&node->inserted);
69034 goto found;
69035 }
69036 }
69037 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69038 tsk = get_pid_task(pid, PIDTYPE_PID);
69039 if (tsk) {
69040 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69041 - atomic_read(&cws->inserted), cws->executed,
69042 + atomic_read_unchecked(&cws->inserted), cws->executed,
69043 tsk->comm);
69044 put_task_struct(tsk);
69045 }
69046 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69047 index 82928f5..92da771 100644
69048 --- a/lib/Kconfig.debug
69049 +++ b/lib/Kconfig.debug
69050 @@ -1103,6 +1103,7 @@ config LATENCYTOP
69051 depends on DEBUG_KERNEL
69052 depends on STACKTRACE_SUPPORT
69053 depends on PROC_FS
69054 + depends on !GRKERNSEC_HIDESYM
69055 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69056 select KALLSYMS
69057 select KALLSYMS_ALL
69058 diff --git a/lib/bitmap.c b/lib/bitmap.c
69059 index 0d4a127..33a06c7 100644
69060 --- a/lib/bitmap.c
69061 +++ b/lib/bitmap.c
69062 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69063 {
69064 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69065 u32 chunk;
69066 - const char __user __force *ubuf = (const char __user __force *)buf;
69067 + const char __user *ubuf = (const char __force_user *)buf;
69068
69069 bitmap_zero(maskp, nmaskbits);
69070
69071 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69072 {
69073 if (!access_ok(VERIFY_READ, ubuf, ulen))
69074 return -EFAULT;
69075 - return __bitmap_parse((const char __force *)ubuf,
69076 + return __bitmap_parse((const char __force_kernel *)ubuf,
69077 ulen, 1, maskp, nmaskbits);
69078
69079 }
69080 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69081 {
69082 unsigned a, b;
69083 int c, old_c, totaldigits;
69084 - const char __user __force *ubuf = (const char __user __force *)buf;
69085 + const char __user *ubuf = (const char __force_user *)buf;
69086 int exp_digit, in_range;
69087
69088 totaldigits = c = 0;
69089 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69090 {
69091 if (!access_ok(VERIFY_READ, ubuf, ulen))
69092 return -EFAULT;
69093 - return __bitmap_parselist((const char __force *)ubuf,
69094 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69095 ulen, 1, maskp, nmaskbits);
69096 }
69097 EXPORT_SYMBOL(bitmap_parselist_user);
69098 diff --git a/lib/bug.c b/lib/bug.c
69099 index 1955209..cbbb2ad 100644
69100 --- a/lib/bug.c
69101 +++ b/lib/bug.c
69102 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69103 return BUG_TRAP_TYPE_NONE;
69104
69105 bug = find_bug(bugaddr);
69106 + if (!bug)
69107 + return BUG_TRAP_TYPE_NONE;
69108
69109 file = NULL;
69110 line = 0;
69111 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69112 index a78b7c6..2c73084 100644
69113 --- a/lib/debugobjects.c
69114 +++ b/lib/debugobjects.c
69115 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69116 if (limit > 4)
69117 return;
69118
69119 - is_on_stack = object_is_on_stack(addr);
69120 + is_on_stack = object_starts_on_stack(addr);
69121 if (is_on_stack == onstack)
69122 return;
69123
69124 diff --git a/lib/devres.c b/lib/devres.c
69125 index 7c0e953..f642b5c 100644
69126 --- a/lib/devres.c
69127 +++ b/lib/devres.c
69128 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69129 void devm_iounmap(struct device *dev, void __iomem *addr)
69130 {
69131 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69132 - (void *)addr));
69133 + (void __force *)addr));
69134 iounmap(addr);
69135 }
69136 EXPORT_SYMBOL(devm_iounmap);
69137 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69138 {
69139 ioport_unmap(addr);
69140 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69141 - devm_ioport_map_match, (void *)addr));
69142 + devm_ioport_map_match, (void __force *)addr));
69143 }
69144 EXPORT_SYMBOL(devm_ioport_unmap);
69145
69146 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69147 index fea790a..ebb0e82 100644
69148 --- a/lib/dma-debug.c
69149 +++ b/lib/dma-debug.c
69150 @@ -925,7 +925,7 @@ out:
69151
69152 static void check_for_stack(struct device *dev, void *addr)
69153 {
69154 - if (object_is_on_stack(addr))
69155 + if (object_starts_on_stack(addr))
69156 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69157 "stack [addr=%p]\n", addr);
69158 }
69159 diff --git a/lib/extable.c b/lib/extable.c
69160 index 4cac81e..63e9b8f 100644
69161 --- a/lib/extable.c
69162 +++ b/lib/extable.c
69163 @@ -13,6 +13,7 @@
69164 #include <linux/init.h>
69165 #include <linux/sort.h>
69166 #include <asm/uaccess.h>
69167 +#include <asm/pgtable.h>
69168
69169 #ifndef ARCH_HAS_SORT_EXTABLE
69170 /*
69171 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69172 void sort_extable(struct exception_table_entry *start,
69173 struct exception_table_entry *finish)
69174 {
69175 + pax_open_kernel();
69176 sort(start, finish - start, sizeof(struct exception_table_entry),
69177 cmp_ex, NULL);
69178 + pax_close_kernel();
69179 }
69180
69181 #ifdef CONFIG_MODULES
69182 diff --git a/lib/inflate.c b/lib/inflate.c
69183 index 013a761..c28f3fc 100644
69184 --- a/lib/inflate.c
69185 +++ b/lib/inflate.c
69186 @@ -269,7 +269,7 @@ static void free(void *where)
69187 malloc_ptr = free_mem_ptr;
69188 }
69189 #else
69190 -#define malloc(a) kmalloc(a, GFP_KERNEL)
69191 +#define malloc(a) kmalloc((a), GFP_KERNEL)
69192 #define free(a) kfree(a)
69193 #endif
69194
69195 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69196 index bd2bea9..6b3c95e 100644
69197 --- a/lib/is_single_threaded.c
69198 +++ b/lib/is_single_threaded.c
69199 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69200 struct task_struct *p, *t;
69201 bool ret;
69202
69203 + if (!mm)
69204 + return true;
69205 +
69206 if (atomic_read(&task->signal->live) != 1)
69207 return false;
69208
69209 diff --git a/lib/kref.c b/lib/kref.c
69210 index 3efb882..8492f4c 100644
69211 --- a/lib/kref.c
69212 +++ b/lib/kref.c
69213 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
69214 */
69215 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
69216 {
69217 - WARN_ON(release == NULL);
69218 + BUG_ON(release == NULL);
69219 WARN_ON(release == (void (*)(struct kref *))kfree);
69220
69221 if (atomic_dec_and_test(&kref->refcount)) {
69222 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69223 index d9df745..e73c2fe 100644
69224 --- a/lib/radix-tree.c
69225 +++ b/lib/radix-tree.c
69226 @@ -80,7 +80,7 @@ struct radix_tree_preload {
69227 int nr;
69228 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69229 };
69230 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69231 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69232
69233 static inline void *ptr_to_indirect(void *ptr)
69234 {
69235 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69236 index 993599e..f1dbc14 100644
69237 --- a/lib/vsprintf.c
69238 +++ b/lib/vsprintf.c
69239 @@ -16,6 +16,9 @@
69240 * - scnprintf and vscnprintf
69241 */
69242
69243 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69244 +#define __INCLUDED_BY_HIDESYM 1
69245 +#endif
69246 #include <stdarg.h>
69247 #include <linux/module.h>
69248 #include <linux/types.h>
69249 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
69250 char sym[KSYM_SYMBOL_LEN];
69251 if (ext == 'B')
69252 sprint_backtrace(sym, value);
69253 - else if (ext != 'f' && ext != 's')
69254 + else if (ext != 'f' && ext != 's' && ext != 'a')
69255 sprint_symbol(sym, value);
69256 else
69257 kallsyms_lookup(value, NULL, NULL, NULL, sym);
69258 @@ -777,7 +780,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
69259 return string(buf, end, uuid, spec);
69260 }
69261
69262 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69263 +int kptr_restrict __read_mostly = 2;
69264 +#else
69265 int kptr_restrict __read_mostly;
69266 +#endif
69267
69268 /*
69269 * Show a '%p' thing. A kernel extension is that the '%p' is followed
69270 @@ -791,6 +798,8 @@ int kptr_restrict __read_mostly;
69271 * - 'S' For symbolic direct pointers with offset
69272 * - 's' For symbolic direct pointers without offset
69273 * - 'B' For backtraced symbolic direct pointers with offset
69274 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
69275 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
69276 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
69277 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
69278 * - 'M' For a 6-byte MAC address, it prints the address in the
69279 @@ -835,12 +844,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69280 {
69281 if (!ptr && *fmt != 'K') {
69282 /*
69283 - * Print (null) with the same width as a pointer so it makes
69284 + * Print (nil) with the same width as a pointer so it makes
69285 * tabular output look nice.
69286 */
69287 if (spec.field_width == -1)
69288 spec.field_width = 2 * sizeof(void *);
69289 - return string(buf, end, "(null)", spec);
69290 + return string(buf, end, "(nil)", spec);
69291 }
69292
69293 switch (*fmt) {
69294 @@ -850,6 +859,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69295 /* Fallthrough */
69296 case 'S':
69297 case 's':
69298 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69299 + break;
69300 +#else
69301 + return symbol_string(buf, end, ptr, spec, *fmt);
69302 +#endif
69303 + case 'A':
69304 + case 'a':
69305 case 'B':
69306 return symbol_string(buf, end, ptr, spec, *fmt);
69307 case 'R':
69308 @@ -878,9 +894,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69309 case 'U':
69310 return uuid_string(buf, end, ptr, spec, fmt);
69311 case 'V':
69312 - return buf + vsnprintf(buf, end > buf ? end - buf : 0,
69313 - ((struct va_format *)ptr)->fmt,
69314 - *(((struct va_format *)ptr)->va));
69315 + {
69316 + va_list va;
69317 +
69318 + va_copy(va, *((struct va_format *)ptr)->va);
69319 + buf += vsnprintf(buf, end > buf ? end - buf : 0,
69320 + ((struct va_format *)ptr)->fmt, va);
69321 + va_end(va);
69322 + return buf;
69323 + }
69324 case 'K':
69325 /*
69326 * %pK cannot be used in IRQ context because its test
69327 @@ -1608,11 +1630,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69328 typeof(type) value; \
69329 if (sizeof(type) == 8) { \
69330 args = PTR_ALIGN(args, sizeof(u32)); \
69331 - *(u32 *)&value = *(u32 *)args; \
69332 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
69333 + *(u32 *)&value = *(const u32 *)args; \
69334 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
69335 } else { \
69336 args = PTR_ALIGN(args, sizeof(type)); \
69337 - value = *(typeof(type) *)args; \
69338 + value = *(const typeof(type) *)args; \
69339 } \
69340 args += sizeof(type); \
69341 value; \
69342 @@ -1675,7 +1697,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69343 case FORMAT_TYPE_STR: {
69344 const char *str_arg = args;
69345 args += strlen(str_arg) + 1;
69346 - str = string(str, end, (char *)str_arg, spec);
69347 + str = string(str, end, str_arg, spec);
69348 break;
69349 }
69350
69351 diff --git a/localversion-grsec b/localversion-grsec
69352 new file mode 100644
69353 index 0000000..7cd6065
69354 --- /dev/null
69355 +++ b/localversion-grsec
69356 @@ -0,0 +1 @@
69357 +-grsec
69358 diff --git a/mm/Kconfig b/mm/Kconfig
69359 index 011b110..b492af2 100644
69360 --- a/mm/Kconfig
69361 +++ b/mm/Kconfig
69362 @@ -241,10 +241,10 @@ config KSM
69363 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
69364
69365 config DEFAULT_MMAP_MIN_ADDR
69366 - int "Low address space to protect from user allocation"
69367 + int "Low address space to protect from user allocation"
69368 depends on MMU
69369 - default 4096
69370 - help
69371 + default 65536
69372 + help
69373 This is the portion of low virtual memory which should be protected
69374 from userspace allocation. Keeping a user from writing to low pages
69375 can help reduce the impact of kernel NULL pointer bugs.
69376 diff --git a/mm/filemap.c b/mm/filemap.c
69377 index 03c5b0e..a01e793 100644
69378 --- a/mm/filemap.c
69379 +++ b/mm/filemap.c
69380 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
69381 struct address_space *mapping = file->f_mapping;
69382
69383 if (!mapping->a_ops->readpage)
69384 - return -ENOEXEC;
69385 + return -ENODEV;
69386 file_accessed(file);
69387 vma->vm_ops = &generic_file_vm_ops;
69388 vma->vm_flags |= VM_CAN_NONLINEAR;
69389 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69390 *pos = i_size_read(inode);
69391
69392 if (limit != RLIM_INFINITY) {
69393 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69394 if (*pos >= limit) {
69395 send_sig(SIGXFSZ, current, 0);
69396 return -EFBIG;
69397 diff --git a/mm/fremap.c b/mm/fremap.c
69398 index 9ed4fd4..c42648d 100644
69399 --- a/mm/fremap.c
69400 +++ b/mm/fremap.c
69401 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69402 retry:
69403 vma = find_vma(mm, start);
69404
69405 +#ifdef CONFIG_PAX_SEGMEXEC
69406 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69407 + goto out;
69408 +#endif
69409 +
69410 /*
69411 * Make sure the vma is shared, that it supports prefaulting,
69412 * and that the remapped range is valid and fully within
69413 diff --git a/mm/highmem.c b/mm/highmem.c
69414 index 57d82c6..e9e0552 100644
69415 --- a/mm/highmem.c
69416 +++ b/mm/highmem.c
69417 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69418 * So no dangers, even with speculative execution.
69419 */
69420 page = pte_page(pkmap_page_table[i]);
69421 + pax_open_kernel();
69422 pte_clear(&init_mm, (unsigned long)page_address(page),
69423 &pkmap_page_table[i]);
69424 -
69425 + pax_close_kernel();
69426 set_page_address(page, NULL);
69427 need_flush = 1;
69428 }
69429 @@ -186,9 +187,11 @@ start:
69430 }
69431 }
69432 vaddr = PKMAP_ADDR(last_pkmap_nr);
69433 +
69434 + pax_open_kernel();
69435 set_pte_at(&init_mm, vaddr,
69436 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69437 -
69438 + pax_close_kernel();
69439 pkmap_count[last_pkmap_nr] = 1;
69440 set_page_address(page, (void *)vaddr);
69441
69442 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69443 index 8f005e9..1cb1036 100644
69444 --- a/mm/huge_memory.c
69445 +++ b/mm/huge_memory.c
69446 @@ -704,7 +704,7 @@ out:
69447 * run pte_offset_map on the pmd, if an huge pmd could
69448 * materialize from under us from a different thread.
69449 */
69450 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69451 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69452 return VM_FAULT_OOM;
69453 /* if an huge pmd materialized from under us just retry later */
69454 if (unlikely(pmd_trans_huge(*pmd)))
69455 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69456 index 2316840..b418671 100644
69457 --- a/mm/hugetlb.c
69458 +++ b/mm/hugetlb.c
69459 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69460 return 1;
69461 }
69462
69463 +#ifdef CONFIG_PAX_SEGMEXEC
69464 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69465 +{
69466 + struct mm_struct *mm = vma->vm_mm;
69467 + struct vm_area_struct *vma_m;
69468 + unsigned long address_m;
69469 + pte_t *ptep_m;
69470 +
69471 + vma_m = pax_find_mirror_vma(vma);
69472 + if (!vma_m)
69473 + return;
69474 +
69475 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69476 + address_m = address + SEGMEXEC_TASK_SIZE;
69477 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69478 + get_page(page_m);
69479 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
69480 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69481 +}
69482 +#endif
69483 +
69484 /*
69485 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69486 */
69487 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
69488 make_huge_pte(vma, new_page, 1));
69489 page_remove_rmap(old_page);
69490 hugepage_add_new_anon_rmap(new_page, vma, address);
69491 +
69492 +#ifdef CONFIG_PAX_SEGMEXEC
69493 + pax_mirror_huge_pte(vma, address, new_page);
69494 +#endif
69495 +
69496 /* Make the old page be freed below */
69497 new_page = old_page;
69498 mmu_notifier_invalidate_range_end(mm,
69499 @@ -2601,6 +2627,10 @@ retry:
69500 && (vma->vm_flags & VM_SHARED)));
69501 set_huge_pte_at(mm, address, ptep, new_pte);
69502
69503 +#ifdef CONFIG_PAX_SEGMEXEC
69504 + pax_mirror_huge_pte(vma, address, page);
69505 +#endif
69506 +
69507 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69508 /* Optimization, do the COW without a second fault */
69509 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69510 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69511 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69512 struct hstate *h = hstate_vma(vma);
69513
69514 +#ifdef CONFIG_PAX_SEGMEXEC
69515 + struct vm_area_struct *vma_m;
69516 +#endif
69517 +
69518 ptep = huge_pte_offset(mm, address);
69519 if (ptep) {
69520 entry = huge_ptep_get(ptep);
69521 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69522 VM_FAULT_SET_HINDEX(h - hstates);
69523 }
69524
69525 +#ifdef CONFIG_PAX_SEGMEXEC
69526 + vma_m = pax_find_mirror_vma(vma);
69527 + if (vma_m) {
69528 + unsigned long address_m;
69529 +
69530 + if (vma->vm_start > vma_m->vm_start) {
69531 + address_m = address;
69532 + address -= SEGMEXEC_TASK_SIZE;
69533 + vma = vma_m;
69534 + h = hstate_vma(vma);
69535 + } else
69536 + address_m = address + SEGMEXEC_TASK_SIZE;
69537 +
69538 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69539 + return VM_FAULT_OOM;
69540 + address_m &= HPAGE_MASK;
69541 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69542 + }
69543 +#endif
69544 +
69545 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69546 if (!ptep)
69547 return VM_FAULT_OOM;
69548 diff --git a/mm/internal.h b/mm/internal.h
69549 index 2189af4..f2ca332 100644
69550 --- a/mm/internal.h
69551 +++ b/mm/internal.h
69552 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69553 * in mm/page_alloc.c
69554 */
69555 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69556 +extern void free_compound_page(struct page *page);
69557 extern void prep_compound_page(struct page *page, unsigned long order);
69558 #ifdef CONFIG_MEMORY_FAILURE
69559 extern bool is_free_buddy_page(struct page *page);
69560 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69561 index f3b2a00..61da94d 100644
69562 --- a/mm/kmemleak.c
69563 +++ b/mm/kmemleak.c
69564 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
69565
69566 for (i = 0; i < object->trace_len; i++) {
69567 void *ptr = (void *)object->trace[i];
69568 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69569 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69570 }
69571 }
69572
69573 diff --git a/mm/maccess.c b/mm/maccess.c
69574 index d53adf9..03a24bf 100644
69575 --- a/mm/maccess.c
69576 +++ b/mm/maccess.c
69577 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69578 set_fs(KERNEL_DS);
69579 pagefault_disable();
69580 ret = __copy_from_user_inatomic(dst,
69581 - (__force const void __user *)src, size);
69582 + (const void __force_user *)src, size);
69583 pagefault_enable();
69584 set_fs(old_fs);
69585
69586 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69587
69588 set_fs(KERNEL_DS);
69589 pagefault_disable();
69590 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69591 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69592 pagefault_enable();
69593 set_fs(old_fs);
69594
69595 diff --git a/mm/madvise.c b/mm/madvise.c
69596 index 74bf193..feb6fd3 100644
69597 --- a/mm/madvise.c
69598 +++ b/mm/madvise.c
69599 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69600 pgoff_t pgoff;
69601 unsigned long new_flags = vma->vm_flags;
69602
69603 +#ifdef CONFIG_PAX_SEGMEXEC
69604 + struct vm_area_struct *vma_m;
69605 +#endif
69606 +
69607 switch (behavior) {
69608 case MADV_NORMAL:
69609 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69610 @@ -110,6 +114,13 @@ success:
69611 /*
69612 * vm_flags is protected by the mmap_sem held in write mode.
69613 */
69614 +
69615 +#ifdef CONFIG_PAX_SEGMEXEC
69616 + vma_m = pax_find_mirror_vma(vma);
69617 + if (vma_m)
69618 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69619 +#endif
69620 +
69621 vma->vm_flags = new_flags;
69622
69623 out:
69624 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69625 struct vm_area_struct ** prev,
69626 unsigned long start, unsigned long end)
69627 {
69628 +
69629 +#ifdef CONFIG_PAX_SEGMEXEC
69630 + struct vm_area_struct *vma_m;
69631 +#endif
69632 +
69633 *prev = vma;
69634 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69635 return -EINVAL;
69636 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69637 zap_page_range(vma, start, end - start, &details);
69638 } else
69639 zap_page_range(vma, start, end - start, NULL);
69640 +
69641 +#ifdef CONFIG_PAX_SEGMEXEC
69642 + vma_m = pax_find_mirror_vma(vma);
69643 + if (vma_m) {
69644 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69645 + struct zap_details details = {
69646 + .nonlinear_vma = vma_m,
69647 + .last_index = ULONG_MAX,
69648 + };
69649 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69650 + } else
69651 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69652 + }
69653 +#endif
69654 +
69655 return 0;
69656 }
69657
69658 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69659 if (end < start)
69660 goto out;
69661
69662 +#ifdef CONFIG_PAX_SEGMEXEC
69663 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69664 + if (end > SEGMEXEC_TASK_SIZE)
69665 + goto out;
69666 + } else
69667 +#endif
69668 +
69669 + if (end > TASK_SIZE)
69670 + goto out;
69671 +
69672 error = 0;
69673 if (end == start)
69674 goto out;
69675 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69676 index 06d3479..0778eef 100644
69677 --- a/mm/memory-failure.c
69678 +++ b/mm/memory-failure.c
69679 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69680
69681 int sysctl_memory_failure_recovery __read_mostly = 1;
69682
69683 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69684 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69685
69686 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69687
69688 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
69689 si.si_signo = SIGBUS;
69690 si.si_errno = 0;
69691 si.si_code = BUS_MCEERR_AO;
69692 - si.si_addr = (void *)addr;
69693 + si.si_addr = (void __user *)addr;
69694 #ifdef __ARCH_SI_TRAPNO
69695 si.si_trapno = trapno;
69696 #endif
69697 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69698 }
69699
69700 nr_pages = 1 << compound_trans_order(hpage);
69701 - atomic_long_add(nr_pages, &mce_bad_pages);
69702 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69703
69704 /*
69705 * We need/can do nothing about count=0 pages.
69706 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69707 if (!PageHWPoison(hpage)
69708 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69709 || (p != hpage && TestSetPageHWPoison(hpage))) {
69710 - atomic_long_sub(nr_pages, &mce_bad_pages);
69711 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69712 return 0;
69713 }
69714 set_page_hwpoison_huge_page(hpage);
69715 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69716 }
69717 if (hwpoison_filter(p)) {
69718 if (TestClearPageHWPoison(p))
69719 - atomic_long_sub(nr_pages, &mce_bad_pages);
69720 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69721 unlock_page(hpage);
69722 put_page(hpage);
69723 return 0;
69724 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
69725 return 0;
69726 }
69727 if (TestClearPageHWPoison(p))
69728 - atomic_long_sub(nr_pages, &mce_bad_pages);
69729 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69730 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69731 return 0;
69732 }
69733 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
69734 */
69735 if (TestClearPageHWPoison(page)) {
69736 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69737 - atomic_long_sub(nr_pages, &mce_bad_pages);
69738 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69739 freeit = 1;
69740 if (PageHuge(page))
69741 clear_page_hwpoison_huge_page(page);
69742 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69743 }
69744 done:
69745 if (!PageHWPoison(hpage))
69746 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69747 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69748 set_page_hwpoison_huge_page(hpage);
69749 dequeue_hwpoisoned_huge_page(hpage);
69750 /* keep elevated page count for bad page */
69751 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
69752 return ret;
69753
69754 done:
69755 - atomic_long_add(1, &mce_bad_pages);
69756 + atomic_long_add_unchecked(1, &mce_bad_pages);
69757 SetPageHWPoison(page);
69758 /* keep elevated page count for bad page */
69759 return ret;
69760 diff --git a/mm/memory.c b/mm/memory.c
69761 index 829d437..3d3926a 100644
69762 --- a/mm/memory.c
69763 +++ b/mm/memory.c
69764 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69765 return;
69766
69767 pmd = pmd_offset(pud, start);
69768 +
69769 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69770 pud_clear(pud);
69771 pmd_free_tlb(tlb, pmd, start);
69772 +#endif
69773 +
69774 }
69775
69776 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69777 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69778 if (end - 1 > ceiling - 1)
69779 return;
69780
69781 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69782 pud = pud_offset(pgd, start);
69783 pgd_clear(pgd);
69784 pud_free_tlb(tlb, pud, start);
69785 +#endif
69786 +
69787 }
69788
69789 /*
69790 @@ -1566,12 +1573,6 @@ no_page_table:
69791 return page;
69792 }
69793
69794 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69795 -{
69796 - return stack_guard_page_start(vma, addr) ||
69797 - stack_guard_page_end(vma, addr+PAGE_SIZE);
69798 -}
69799 -
69800 /**
69801 * __get_user_pages() - pin user pages in memory
69802 * @tsk: task_struct of target task
69803 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69804 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69805 i = 0;
69806
69807 - do {
69808 + while (nr_pages) {
69809 struct vm_area_struct *vma;
69810
69811 - vma = find_extend_vma(mm, start);
69812 + vma = find_vma(mm, start);
69813 if (!vma && in_gate_area(mm, start)) {
69814 unsigned long pg = start & PAGE_MASK;
69815 pgd_t *pgd;
69816 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69817 goto next_page;
69818 }
69819
69820 - if (!vma ||
69821 + if (!vma || start < vma->vm_start ||
69822 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69823 !(vm_flags & vma->vm_flags))
69824 return i ? : -EFAULT;
69825 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69826 int ret;
69827 unsigned int fault_flags = 0;
69828
69829 - /* For mlock, just skip the stack guard page. */
69830 - if (foll_flags & FOLL_MLOCK) {
69831 - if (stack_guard_page(vma, start))
69832 - goto next_page;
69833 - }
69834 if (foll_flags & FOLL_WRITE)
69835 fault_flags |= FAULT_FLAG_WRITE;
69836 if (nonblocking)
69837 @@ -1800,7 +1796,7 @@ next_page:
69838 start += PAGE_SIZE;
69839 nr_pages--;
69840 } while (nr_pages && start < vma->vm_end);
69841 - } while (nr_pages);
69842 + }
69843 return i;
69844 }
69845 EXPORT_SYMBOL(__get_user_pages);
69846 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69847 page_add_file_rmap(page);
69848 set_pte_at(mm, addr, pte, mk_pte(page, prot));
69849
69850 +#ifdef CONFIG_PAX_SEGMEXEC
69851 + pax_mirror_file_pte(vma, addr, page, ptl);
69852 +#endif
69853 +
69854 retval = 0;
69855 pte_unmap_unlock(pte, ptl);
69856 return retval;
69857 @@ -2041,10 +2041,22 @@ out:
69858 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
69859 struct page *page)
69860 {
69861 +
69862 +#ifdef CONFIG_PAX_SEGMEXEC
69863 + struct vm_area_struct *vma_m;
69864 +#endif
69865 +
69866 if (addr < vma->vm_start || addr >= vma->vm_end)
69867 return -EFAULT;
69868 if (!page_count(page))
69869 return -EINVAL;
69870 +
69871 +#ifdef CONFIG_PAX_SEGMEXEC
69872 + vma_m = pax_find_mirror_vma(vma);
69873 + if (vma_m)
69874 + vma_m->vm_flags |= VM_INSERTPAGE;
69875 +#endif
69876 +
69877 vma->vm_flags |= VM_INSERTPAGE;
69878 return insert_page(vma, addr, page, vma->vm_page_prot);
69879 }
69880 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
69881 unsigned long pfn)
69882 {
69883 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
69884 + BUG_ON(vma->vm_mirror);
69885
69886 if (addr < vma->vm_start || addr >= vma->vm_end)
69887 return -EFAULT;
69888 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
69889 copy_user_highpage(dst, src, va, vma);
69890 }
69891
69892 +#ifdef CONFIG_PAX_SEGMEXEC
69893 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
69894 +{
69895 + struct mm_struct *mm = vma->vm_mm;
69896 + spinlock_t *ptl;
69897 + pte_t *pte, entry;
69898 +
69899 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
69900 + entry = *pte;
69901 + if (!pte_present(entry)) {
69902 + if (!pte_none(entry)) {
69903 + BUG_ON(pte_file(entry));
69904 + free_swap_and_cache(pte_to_swp_entry(entry));
69905 + pte_clear_not_present_full(mm, address, pte, 0);
69906 + }
69907 + } else {
69908 + struct page *page;
69909 +
69910 + flush_cache_page(vma, address, pte_pfn(entry));
69911 + entry = ptep_clear_flush(vma, address, pte);
69912 + BUG_ON(pte_dirty(entry));
69913 + page = vm_normal_page(vma, address, entry);
69914 + if (page) {
69915 + update_hiwater_rss(mm);
69916 + if (PageAnon(page))
69917 + dec_mm_counter_fast(mm, MM_ANONPAGES);
69918 + else
69919 + dec_mm_counter_fast(mm, MM_FILEPAGES);
69920 + page_remove_rmap(page);
69921 + page_cache_release(page);
69922 + }
69923 + }
69924 + pte_unmap_unlock(pte, ptl);
69925 +}
69926 +
69927 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
69928 + *
69929 + * the ptl of the lower mapped page is held on entry and is not released on exit
69930 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
69931 + */
69932 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69933 +{
69934 + struct mm_struct *mm = vma->vm_mm;
69935 + unsigned long address_m;
69936 + spinlock_t *ptl_m;
69937 + struct vm_area_struct *vma_m;
69938 + pmd_t *pmd_m;
69939 + pte_t *pte_m, entry_m;
69940 +
69941 + BUG_ON(!page_m || !PageAnon(page_m));
69942 +
69943 + vma_m = pax_find_mirror_vma(vma);
69944 + if (!vma_m)
69945 + return;
69946 +
69947 + BUG_ON(!PageLocked(page_m));
69948 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69949 + address_m = address + SEGMEXEC_TASK_SIZE;
69950 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69951 + pte_m = pte_offset_map(pmd_m, address_m);
69952 + ptl_m = pte_lockptr(mm, pmd_m);
69953 + if (ptl != ptl_m) {
69954 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69955 + if (!pte_none(*pte_m))
69956 + goto out;
69957 + }
69958 +
69959 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69960 + page_cache_get(page_m);
69961 + page_add_anon_rmap(page_m, vma_m, address_m);
69962 + inc_mm_counter_fast(mm, MM_ANONPAGES);
69963 + set_pte_at(mm, address_m, pte_m, entry_m);
69964 + update_mmu_cache(vma_m, address_m, entry_m);
69965 +out:
69966 + if (ptl != ptl_m)
69967 + spin_unlock(ptl_m);
69968 + pte_unmap(pte_m);
69969 + unlock_page(page_m);
69970 +}
69971 +
69972 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69973 +{
69974 + struct mm_struct *mm = vma->vm_mm;
69975 + unsigned long address_m;
69976 + spinlock_t *ptl_m;
69977 + struct vm_area_struct *vma_m;
69978 + pmd_t *pmd_m;
69979 + pte_t *pte_m, entry_m;
69980 +
69981 + BUG_ON(!page_m || PageAnon(page_m));
69982 +
69983 + vma_m = pax_find_mirror_vma(vma);
69984 + if (!vma_m)
69985 + return;
69986 +
69987 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69988 + address_m = address + SEGMEXEC_TASK_SIZE;
69989 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69990 + pte_m = pte_offset_map(pmd_m, address_m);
69991 + ptl_m = pte_lockptr(mm, pmd_m);
69992 + if (ptl != ptl_m) {
69993 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69994 + if (!pte_none(*pte_m))
69995 + goto out;
69996 + }
69997 +
69998 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69999 + page_cache_get(page_m);
70000 + page_add_file_rmap(page_m);
70001 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70002 + set_pte_at(mm, address_m, pte_m, entry_m);
70003 + update_mmu_cache(vma_m, address_m, entry_m);
70004 +out:
70005 + if (ptl != ptl_m)
70006 + spin_unlock(ptl_m);
70007 + pte_unmap(pte_m);
70008 +}
70009 +
70010 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70011 +{
70012 + struct mm_struct *mm = vma->vm_mm;
70013 + unsigned long address_m;
70014 + spinlock_t *ptl_m;
70015 + struct vm_area_struct *vma_m;
70016 + pmd_t *pmd_m;
70017 + pte_t *pte_m, entry_m;
70018 +
70019 + vma_m = pax_find_mirror_vma(vma);
70020 + if (!vma_m)
70021 + return;
70022 +
70023 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70024 + address_m = address + SEGMEXEC_TASK_SIZE;
70025 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70026 + pte_m = pte_offset_map(pmd_m, address_m);
70027 + ptl_m = pte_lockptr(mm, pmd_m);
70028 + if (ptl != ptl_m) {
70029 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70030 + if (!pte_none(*pte_m))
70031 + goto out;
70032 + }
70033 +
70034 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70035 + set_pte_at(mm, address_m, pte_m, entry_m);
70036 +out:
70037 + if (ptl != ptl_m)
70038 + spin_unlock(ptl_m);
70039 + pte_unmap(pte_m);
70040 +}
70041 +
70042 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70043 +{
70044 + struct page *page_m;
70045 + pte_t entry;
70046 +
70047 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70048 + goto out;
70049 +
70050 + entry = *pte;
70051 + page_m = vm_normal_page(vma, address, entry);
70052 + if (!page_m)
70053 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70054 + else if (PageAnon(page_m)) {
70055 + if (pax_find_mirror_vma(vma)) {
70056 + pte_unmap_unlock(pte, ptl);
70057 + lock_page(page_m);
70058 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70059 + if (pte_same(entry, *pte))
70060 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70061 + else
70062 + unlock_page(page_m);
70063 + }
70064 + } else
70065 + pax_mirror_file_pte(vma, address, page_m, ptl);
70066 +
70067 +out:
70068 + pte_unmap_unlock(pte, ptl);
70069 +}
70070 +#endif
70071 +
70072 /*
70073 * This routine handles present pages, when users try to write
70074 * to a shared page. It is done by copying the page to a new address
70075 @@ -2656,6 +2849,12 @@ gotten:
70076 */
70077 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70078 if (likely(pte_same(*page_table, orig_pte))) {
70079 +
70080 +#ifdef CONFIG_PAX_SEGMEXEC
70081 + if (pax_find_mirror_vma(vma))
70082 + BUG_ON(!trylock_page(new_page));
70083 +#endif
70084 +
70085 if (old_page) {
70086 if (!PageAnon(old_page)) {
70087 dec_mm_counter_fast(mm, MM_FILEPAGES);
70088 @@ -2707,6 +2906,10 @@ gotten:
70089 page_remove_rmap(old_page);
70090 }
70091
70092 +#ifdef CONFIG_PAX_SEGMEXEC
70093 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70094 +#endif
70095 +
70096 /* Free the old page.. */
70097 new_page = old_page;
70098 ret |= VM_FAULT_WRITE;
70099 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70100 swap_free(entry);
70101 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70102 try_to_free_swap(page);
70103 +
70104 +#ifdef CONFIG_PAX_SEGMEXEC
70105 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70106 +#endif
70107 +
70108 unlock_page(page);
70109 if (swapcache) {
70110 /*
70111 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70112
70113 /* No need to invalidate - it was non-present before */
70114 update_mmu_cache(vma, address, page_table);
70115 +
70116 +#ifdef CONFIG_PAX_SEGMEXEC
70117 + pax_mirror_anon_pte(vma, address, page, ptl);
70118 +#endif
70119 +
70120 unlock:
70121 pte_unmap_unlock(page_table, ptl);
70122 out:
70123 @@ -3028,40 +3241,6 @@ out_release:
70124 }
70125
70126 /*
70127 - * This is like a special single-page "expand_{down|up}wards()",
70128 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70129 - * doesn't hit another vma.
70130 - */
70131 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70132 -{
70133 - address &= PAGE_MASK;
70134 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70135 - struct vm_area_struct *prev = vma->vm_prev;
70136 -
70137 - /*
70138 - * Is there a mapping abutting this one below?
70139 - *
70140 - * That's only ok if it's the same stack mapping
70141 - * that has gotten split..
70142 - */
70143 - if (prev && prev->vm_end == address)
70144 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70145 -
70146 - expand_downwards(vma, address - PAGE_SIZE);
70147 - }
70148 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70149 - struct vm_area_struct *next = vma->vm_next;
70150 -
70151 - /* As VM_GROWSDOWN but s/below/above/ */
70152 - if (next && next->vm_start == address + PAGE_SIZE)
70153 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70154 -
70155 - expand_upwards(vma, address + PAGE_SIZE);
70156 - }
70157 - return 0;
70158 -}
70159 -
70160 -/*
70161 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70162 * but allow concurrent faults), and pte mapped but not yet locked.
70163 * We return with mmap_sem still held, but pte unmapped and unlocked.
70164 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70165 unsigned long address, pte_t *page_table, pmd_t *pmd,
70166 unsigned int flags)
70167 {
70168 - struct page *page;
70169 + struct page *page = NULL;
70170 spinlock_t *ptl;
70171 pte_t entry;
70172
70173 - pte_unmap(page_table);
70174 -
70175 - /* Check if we need to add a guard page to the stack */
70176 - if (check_stack_guard_page(vma, address) < 0)
70177 - return VM_FAULT_SIGBUS;
70178 -
70179 - /* Use the zero-page for reads */
70180 if (!(flags & FAULT_FLAG_WRITE)) {
70181 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70182 vma->vm_page_prot));
70183 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70184 + ptl = pte_lockptr(mm, pmd);
70185 + spin_lock(ptl);
70186 if (!pte_none(*page_table))
70187 goto unlock;
70188 goto setpte;
70189 }
70190
70191 /* Allocate our own private page. */
70192 + pte_unmap(page_table);
70193 +
70194 if (unlikely(anon_vma_prepare(vma)))
70195 goto oom;
70196 page = alloc_zeroed_user_highpage_movable(vma, address);
70197 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70198 if (!pte_none(*page_table))
70199 goto release;
70200
70201 +#ifdef CONFIG_PAX_SEGMEXEC
70202 + if (pax_find_mirror_vma(vma))
70203 + BUG_ON(!trylock_page(page));
70204 +#endif
70205 +
70206 inc_mm_counter_fast(mm, MM_ANONPAGES);
70207 page_add_new_anon_rmap(page, vma, address);
70208 setpte:
70209 @@ -3116,6 +3296,12 @@ setpte:
70210
70211 /* No need to invalidate - it was non-present before */
70212 update_mmu_cache(vma, address, page_table);
70213 +
70214 +#ifdef CONFIG_PAX_SEGMEXEC
70215 + if (page)
70216 + pax_mirror_anon_pte(vma, address, page, ptl);
70217 +#endif
70218 +
70219 unlock:
70220 pte_unmap_unlock(page_table, ptl);
70221 return 0;
70222 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70223 */
70224 /* Only go through if we didn't race with anybody else... */
70225 if (likely(pte_same(*page_table, orig_pte))) {
70226 +
70227 +#ifdef CONFIG_PAX_SEGMEXEC
70228 + if (anon && pax_find_mirror_vma(vma))
70229 + BUG_ON(!trylock_page(page));
70230 +#endif
70231 +
70232 flush_icache_page(vma, page);
70233 entry = mk_pte(page, vma->vm_page_prot);
70234 if (flags & FAULT_FLAG_WRITE)
70235 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70236
70237 /* no need to invalidate: a not-present page won't be cached */
70238 update_mmu_cache(vma, address, page_table);
70239 +
70240 +#ifdef CONFIG_PAX_SEGMEXEC
70241 + if (anon)
70242 + pax_mirror_anon_pte(vma, address, page, ptl);
70243 + else
70244 + pax_mirror_file_pte(vma, address, page, ptl);
70245 +#endif
70246 +
70247 } else {
70248 if (cow_page)
70249 mem_cgroup_uncharge_page(cow_page);
70250 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
70251 if (flags & FAULT_FLAG_WRITE)
70252 flush_tlb_fix_spurious_fault(vma, address);
70253 }
70254 +
70255 +#ifdef CONFIG_PAX_SEGMEXEC
70256 + pax_mirror_pte(vma, address, pte, pmd, ptl);
70257 + return 0;
70258 +#endif
70259 +
70260 unlock:
70261 pte_unmap_unlock(pte, ptl);
70262 return 0;
70263 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70264 pmd_t *pmd;
70265 pte_t *pte;
70266
70267 +#ifdef CONFIG_PAX_SEGMEXEC
70268 + struct vm_area_struct *vma_m;
70269 +#endif
70270 +
70271 __set_current_state(TASK_RUNNING);
70272
70273 count_vm_event(PGFAULT);
70274 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70275 if (unlikely(is_vm_hugetlb_page(vma)))
70276 return hugetlb_fault(mm, vma, address, flags);
70277
70278 +#ifdef CONFIG_PAX_SEGMEXEC
70279 + vma_m = pax_find_mirror_vma(vma);
70280 + if (vma_m) {
70281 + unsigned long address_m;
70282 + pgd_t *pgd_m;
70283 + pud_t *pud_m;
70284 + pmd_t *pmd_m;
70285 +
70286 + if (vma->vm_start > vma_m->vm_start) {
70287 + address_m = address;
70288 + address -= SEGMEXEC_TASK_SIZE;
70289 + vma = vma_m;
70290 + } else
70291 + address_m = address + SEGMEXEC_TASK_SIZE;
70292 +
70293 + pgd_m = pgd_offset(mm, address_m);
70294 + pud_m = pud_alloc(mm, pgd_m, address_m);
70295 + if (!pud_m)
70296 + return VM_FAULT_OOM;
70297 + pmd_m = pmd_alloc(mm, pud_m, address_m);
70298 + if (!pmd_m)
70299 + return VM_FAULT_OOM;
70300 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
70301 + return VM_FAULT_OOM;
70302 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
70303 + }
70304 +#endif
70305 +
70306 pgd = pgd_offset(mm, address);
70307 pud = pud_alloc(mm, pgd, address);
70308 if (!pud)
70309 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70310 * run pte_offset_map on the pmd, if an huge pmd could
70311 * materialize from under us from a different thread.
70312 */
70313 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
70314 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70315 return VM_FAULT_OOM;
70316 /* if an huge pmd materialized from under us just retry later */
70317 if (unlikely(pmd_trans_huge(*pmd)))
70318 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
70319 gate_vma.vm_start = FIXADDR_USER_START;
70320 gate_vma.vm_end = FIXADDR_USER_END;
70321 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
70322 - gate_vma.vm_page_prot = __P101;
70323 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
70324 /*
70325 * Make sure the vDSO gets into every core dump.
70326 * Dumping its contents makes post-mortem fully interpretable later
70327 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
70328 index c3fdbcb..2e8ef90 100644
70329 --- a/mm/mempolicy.c
70330 +++ b/mm/mempolicy.c
70331 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70332 unsigned long vmstart;
70333 unsigned long vmend;
70334
70335 +#ifdef CONFIG_PAX_SEGMEXEC
70336 + struct vm_area_struct *vma_m;
70337 +#endif
70338 +
70339 vma = find_vma_prev(mm, start, &prev);
70340 if (!vma || vma->vm_start > start)
70341 return -EFAULT;
70342 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70343 err = policy_vma(vma, new_pol);
70344 if (err)
70345 goto out;
70346 +
70347 +#ifdef CONFIG_PAX_SEGMEXEC
70348 + vma_m = pax_find_mirror_vma(vma);
70349 + if (vma_m) {
70350 + err = policy_vma(vma_m, new_pol);
70351 + if (err)
70352 + goto out;
70353 + }
70354 +#endif
70355 +
70356 }
70357
70358 out:
70359 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
70360
70361 if (end < start)
70362 return -EINVAL;
70363 +
70364 +#ifdef CONFIG_PAX_SEGMEXEC
70365 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70366 + if (end > SEGMEXEC_TASK_SIZE)
70367 + return -EINVAL;
70368 + } else
70369 +#endif
70370 +
70371 + if (end > TASK_SIZE)
70372 + return -EINVAL;
70373 +
70374 if (end == start)
70375 return 0;
70376
70377 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70378 if (!mm)
70379 goto out;
70380
70381 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70382 + if (mm != current->mm &&
70383 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70384 + err = -EPERM;
70385 + goto out;
70386 + }
70387 +#endif
70388 +
70389 /*
70390 * Check if this process has the right to modify the specified
70391 * process. The right exists if the process has administrative
70392 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70393 rcu_read_lock();
70394 tcred = __task_cred(task);
70395 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70396 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70397 - !capable(CAP_SYS_NICE)) {
70398 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70399 rcu_read_unlock();
70400 err = -EPERM;
70401 goto out;
70402 diff --git a/mm/migrate.c b/mm/migrate.c
70403 index 177aca4..ab3a744 100644
70404 --- a/mm/migrate.c
70405 +++ b/mm/migrate.c
70406 @@ -1313,6 +1313,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70407 if (!mm)
70408 return -EINVAL;
70409
70410 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70411 + if (mm != current->mm &&
70412 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70413 + err = -EPERM;
70414 + goto out;
70415 + }
70416 +#endif
70417 +
70418 /*
70419 * Check if this process has the right to modify the specified
70420 * process. The right exists if the process has administrative
70421 @@ -1322,8 +1330,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70422 rcu_read_lock();
70423 tcred = __task_cred(task);
70424 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70425 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70426 - !capable(CAP_SYS_NICE)) {
70427 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70428 rcu_read_unlock();
70429 err = -EPERM;
70430 goto out;
70431 diff --git a/mm/mlock.c b/mm/mlock.c
70432 index 4f4f53b..9511904 100644
70433 --- a/mm/mlock.c
70434 +++ b/mm/mlock.c
70435 @@ -13,6 +13,7 @@
70436 #include <linux/pagemap.h>
70437 #include <linux/mempolicy.h>
70438 #include <linux/syscalls.h>
70439 +#include <linux/security.h>
70440 #include <linux/sched.h>
70441 #include <linux/export.h>
70442 #include <linux/rmap.h>
70443 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70444 return -EINVAL;
70445 if (end == start)
70446 return 0;
70447 + if (end > TASK_SIZE)
70448 + return -EINVAL;
70449 +
70450 vma = find_vma_prev(current->mm, start, &prev);
70451 if (!vma || vma->vm_start > start)
70452 return -ENOMEM;
70453 @@ -395,6 +399,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70454 for (nstart = start ; ; ) {
70455 vm_flags_t newflags;
70456
70457 +#ifdef CONFIG_PAX_SEGMEXEC
70458 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70459 + break;
70460 +#endif
70461 +
70462 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70463
70464 newflags = vma->vm_flags | VM_LOCKED;
70465 @@ -500,6 +509,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70466 lock_limit >>= PAGE_SHIFT;
70467
70468 /* check against resource limits */
70469 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70470 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70471 error = do_mlock(start, len, 1);
70472 up_write(&current->mm->mmap_sem);
70473 @@ -523,17 +533,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70474 static int do_mlockall(int flags)
70475 {
70476 struct vm_area_struct * vma, * prev = NULL;
70477 - unsigned int def_flags = 0;
70478
70479 if (flags & MCL_FUTURE)
70480 - def_flags = VM_LOCKED;
70481 - current->mm->def_flags = def_flags;
70482 + current->mm->def_flags |= VM_LOCKED;
70483 + else
70484 + current->mm->def_flags &= ~VM_LOCKED;
70485 if (flags == MCL_FUTURE)
70486 goto out;
70487
70488 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70489 vm_flags_t newflags;
70490
70491 +#ifdef CONFIG_PAX_SEGMEXEC
70492 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70493 + break;
70494 +#endif
70495 +
70496 + BUG_ON(vma->vm_end > TASK_SIZE);
70497 newflags = vma->vm_flags | VM_LOCKED;
70498 if (!(flags & MCL_CURRENT))
70499 newflags &= ~VM_LOCKED;
70500 @@ -566,6 +582,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70501 lock_limit >>= PAGE_SHIFT;
70502
70503 ret = -ENOMEM;
70504 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70505 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70506 capable(CAP_IPC_LOCK))
70507 ret = do_mlockall(flags);
70508 diff --git a/mm/mmap.c b/mm/mmap.c
70509 index eae90af..c930262 100644
70510 --- a/mm/mmap.c
70511 +++ b/mm/mmap.c
70512 @@ -46,6 +46,16 @@
70513 #define arch_rebalance_pgtables(addr, len) (addr)
70514 #endif
70515
70516 +static inline void verify_mm_writelocked(struct mm_struct *mm)
70517 +{
70518 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70519 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70520 + up_read(&mm->mmap_sem);
70521 + BUG();
70522 + }
70523 +#endif
70524 +}
70525 +
70526 static void unmap_region(struct mm_struct *mm,
70527 struct vm_area_struct *vma, struct vm_area_struct *prev,
70528 unsigned long start, unsigned long end);
70529 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70530 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70531 *
70532 */
70533 -pgprot_t protection_map[16] = {
70534 +pgprot_t protection_map[16] __read_only = {
70535 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70536 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70537 };
70538
70539 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
70540 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70541 {
70542 - return __pgprot(pgprot_val(protection_map[vm_flags &
70543 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70544 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70545 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70546 +
70547 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70548 + if (!(__supported_pte_mask & _PAGE_NX) &&
70549 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70550 + (vm_flags & (VM_READ | VM_WRITE)))
70551 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70552 +#endif
70553 +
70554 + return prot;
70555 }
70556 EXPORT_SYMBOL(vm_get_page_prot);
70557
70558 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70559 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70560 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70561 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70562 /*
70563 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70564 * other variables. It can be updated by several CPUs frequently.
70565 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70566 struct vm_area_struct *next = vma->vm_next;
70567
70568 might_sleep();
70569 + BUG_ON(vma->vm_mirror);
70570 if (vma->vm_ops && vma->vm_ops->close)
70571 vma->vm_ops->close(vma);
70572 if (vma->vm_file) {
70573 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70574 * not page aligned -Ram Gupta
70575 */
70576 rlim = rlimit(RLIMIT_DATA);
70577 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70578 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70579 (mm->end_data - mm->start_data) > rlim)
70580 goto out;
70581 @@ -689,6 +711,12 @@ static int
70582 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70583 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70584 {
70585 +
70586 +#ifdef CONFIG_PAX_SEGMEXEC
70587 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70588 + return 0;
70589 +#endif
70590 +
70591 if (is_mergeable_vma(vma, file, vm_flags) &&
70592 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70593 if (vma->vm_pgoff == vm_pgoff)
70594 @@ -708,6 +736,12 @@ static int
70595 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70596 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70597 {
70598 +
70599 +#ifdef CONFIG_PAX_SEGMEXEC
70600 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70601 + return 0;
70602 +#endif
70603 +
70604 if (is_mergeable_vma(vma, file, vm_flags) &&
70605 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70606 pgoff_t vm_pglen;
70607 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70608 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70609 struct vm_area_struct *prev, unsigned long addr,
70610 unsigned long end, unsigned long vm_flags,
70611 - struct anon_vma *anon_vma, struct file *file,
70612 + struct anon_vma *anon_vma, struct file *file,
70613 pgoff_t pgoff, struct mempolicy *policy)
70614 {
70615 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70616 struct vm_area_struct *area, *next;
70617 int err;
70618
70619 +#ifdef CONFIG_PAX_SEGMEXEC
70620 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70621 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70622 +
70623 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70624 +#endif
70625 +
70626 /*
70627 * We later require that vma->vm_flags == vm_flags,
70628 * so this tests vma->vm_flags & VM_SPECIAL, too.
70629 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70630 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70631 next = next->vm_next;
70632
70633 +#ifdef CONFIG_PAX_SEGMEXEC
70634 + if (prev)
70635 + prev_m = pax_find_mirror_vma(prev);
70636 + if (area)
70637 + area_m = pax_find_mirror_vma(area);
70638 + if (next)
70639 + next_m = pax_find_mirror_vma(next);
70640 +#endif
70641 +
70642 /*
70643 * Can it merge with the predecessor?
70644 */
70645 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70646 /* cases 1, 6 */
70647 err = vma_adjust(prev, prev->vm_start,
70648 next->vm_end, prev->vm_pgoff, NULL);
70649 - } else /* cases 2, 5, 7 */
70650 +
70651 +#ifdef CONFIG_PAX_SEGMEXEC
70652 + if (!err && prev_m)
70653 + err = vma_adjust(prev_m, prev_m->vm_start,
70654 + next_m->vm_end, prev_m->vm_pgoff, NULL);
70655 +#endif
70656 +
70657 + } else { /* cases 2, 5, 7 */
70658 err = vma_adjust(prev, prev->vm_start,
70659 end, prev->vm_pgoff, NULL);
70660 +
70661 +#ifdef CONFIG_PAX_SEGMEXEC
70662 + if (!err && prev_m)
70663 + err = vma_adjust(prev_m, prev_m->vm_start,
70664 + end_m, prev_m->vm_pgoff, NULL);
70665 +#endif
70666 +
70667 + }
70668 if (err)
70669 return NULL;
70670 khugepaged_enter_vma_merge(prev);
70671 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70672 mpol_equal(policy, vma_policy(next)) &&
70673 can_vma_merge_before(next, vm_flags,
70674 anon_vma, file, pgoff+pglen)) {
70675 - if (prev && addr < prev->vm_end) /* case 4 */
70676 + if (prev && addr < prev->vm_end) { /* case 4 */
70677 err = vma_adjust(prev, prev->vm_start,
70678 addr, prev->vm_pgoff, NULL);
70679 - else /* cases 3, 8 */
70680 +
70681 +#ifdef CONFIG_PAX_SEGMEXEC
70682 + if (!err && prev_m)
70683 + err = vma_adjust(prev_m, prev_m->vm_start,
70684 + addr_m, prev_m->vm_pgoff, NULL);
70685 +#endif
70686 +
70687 + } else { /* cases 3, 8 */
70688 err = vma_adjust(area, addr, next->vm_end,
70689 next->vm_pgoff - pglen, NULL);
70690 +
70691 +#ifdef CONFIG_PAX_SEGMEXEC
70692 + if (!err && area_m)
70693 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
70694 + next_m->vm_pgoff - pglen, NULL);
70695 +#endif
70696 +
70697 + }
70698 if (err)
70699 return NULL;
70700 khugepaged_enter_vma_merge(area);
70701 @@ -921,14 +1001,11 @@ none:
70702 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70703 struct file *file, long pages)
70704 {
70705 - const unsigned long stack_flags
70706 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70707 -
70708 if (file) {
70709 mm->shared_vm += pages;
70710 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70711 mm->exec_vm += pages;
70712 - } else if (flags & stack_flags)
70713 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70714 mm->stack_vm += pages;
70715 if (flags & (VM_RESERVED|VM_IO))
70716 mm->reserved_vm += pages;
70717 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70718 * (the exception is when the underlying filesystem is noexec
70719 * mounted, in which case we dont add PROT_EXEC.)
70720 */
70721 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70722 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70723 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70724 prot |= PROT_EXEC;
70725
70726 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70727 /* Obtain the address to map to. we verify (or select) it and ensure
70728 * that it represents a valid section of the address space.
70729 */
70730 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
70731 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70732 if (addr & ~PAGE_MASK)
70733 return addr;
70734
70735 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70736 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70737 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70738
70739 +#ifdef CONFIG_PAX_MPROTECT
70740 + if (mm->pax_flags & MF_PAX_MPROTECT) {
70741 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
70742 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70743 + gr_log_rwxmmap(file);
70744 +
70745 +#ifdef CONFIG_PAX_EMUPLT
70746 + vm_flags &= ~VM_EXEC;
70747 +#else
70748 + return -EPERM;
70749 +#endif
70750 +
70751 + }
70752 +
70753 + if (!(vm_flags & VM_EXEC))
70754 + vm_flags &= ~VM_MAYEXEC;
70755 +#else
70756 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70757 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70758 +#endif
70759 + else
70760 + vm_flags &= ~VM_MAYWRITE;
70761 + }
70762 +#endif
70763 +
70764 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70765 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70766 + vm_flags &= ~VM_PAGEEXEC;
70767 +#endif
70768 +
70769 if (flags & MAP_LOCKED)
70770 if (!can_do_mlock())
70771 return -EPERM;
70772 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70773 locked += mm->locked_vm;
70774 lock_limit = rlimit(RLIMIT_MEMLOCK);
70775 lock_limit >>= PAGE_SHIFT;
70776 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70777 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70778 return -EAGAIN;
70779 }
70780 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70781 if (error)
70782 return error;
70783
70784 + if (!gr_acl_handle_mmap(file, prot))
70785 + return -EACCES;
70786 +
70787 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70788 }
70789 EXPORT_SYMBOL(do_mmap_pgoff);
70790 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70791 vm_flags_t vm_flags = vma->vm_flags;
70792
70793 /* If it was private or non-writable, the write bit is already clear */
70794 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70795 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70796 return 0;
70797
70798 /* The backer wishes to know when pages are first written to? */
70799 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
70800 unsigned long charged = 0;
70801 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
70802
70803 +#ifdef CONFIG_PAX_SEGMEXEC
70804 + struct vm_area_struct *vma_m = NULL;
70805 +#endif
70806 +
70807 + /*
70808 + * mm->mmap_sem is required to protect against another thread
70809 + * changing the mappings in case we sleep.
70810 + */
70811 + verify_mm_writelocked(mm);
70812 +
70813 /* Clear old maps */
70814 error = -ENOMEM;
70815 -munmap_back:
70816 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70817 if (vma && vma->vm_start < addr + len) {
70818 if (do_munmap(mm, addr, len))
70819 return -ENOMEM;
70820 - goto munmap_back;
70821 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70822 + BUG_ON(vma && vma->vm_start < addr + len);
70823 }
70824
70825 /* Check against address space limit. */
70826 @@ -1258,6 +1379,16 @@ munmap_back:
70827 goto unacct_error;
70828 }
70829
70830 +#ifdef CONFIG_PAX_SEGMEXEC
70831 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
70832 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70833 + if (!vma_m) {
70834 + error = -ENOMEM;
70835 + goto free_vma;
70836 + }
70837 + }
70838 +#endif
70839 +
70840 vma->vm_mm = mm;
70841 vma->vm_start = addr;
70842 vma->vm_end = addr + len;
70843 @@ -1266,8 +1397,9 @@ munmap_back:
70844 vma->vm_pgoff = pgoff;
70845 INIT_LIST_HEAD(&vma->anon_vma_chain);
70846
70847 + error = -EINVAL; /* when rejecting VM_GROWSDOWN|VM_GROWSUP */
70848 +
70849 if (file) {
70850 - error = -EINVAL;
70851 if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
70852 goto free_vma;
70853 if (vm_flags & VM_DENYWRITE) {
70854 @@ -1281,6 +1413,19 @@ munmap_back:
70855 error = file->f_op->mmap(file, vma);
70856 if (error)
70857 goto unmap_and_free_vma;
70858 +
70859 +#ifdef CONFIG_PAX_SEGMEXEC
70860 + if (vma_m && (vm_flags & VM_EXECUTABLE))
70861 + added_exe_file_vma(mm);
70862 +#endif
70863 +
70864 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70865 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
70866 + vma->vm_flags |= VM_PAGEEXEC;
70867 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
70868 + }
70869 +#endif
70870 +
70871 if (vm_flags & VM_EXECUTABLE)
70872 added_exe_file_vma(mm);
70873
70874 @@ -1293,6 +1438,8 @@ munmap_back:
70875 pgoff = vma->vm_pgoff;
70876 vm_flags = vma->vm_flags;
70877 } else if (vm_flags & VM_SHARED) {
70878 + if (unlikely(vm_flags & (VM_GROWSDOWN|VM_GROWSUP)))
70879 + goto free_vma;
70880 error = shmem_zero_setup(vma);
70881 if (error)
70882 goto free_vma;
70883 @@ -1316,6 +1463,11 @@ munmap_back:
70884 vma_link(mm, vma, prev, rb_link, rb_parent);
70885 file = vma->vm_file;
70886
70887 +#ifdef CONFIG_PAX_SEGMEXEC
70888 + if (vma_m)
70889 + BUG_ON(pax_mirror_vma(vma_m, vma));
70890 +#endif
70891 +
70892 /* Once vma denies write, undo our temporary denial count */
70893 if (correct_wcount)
70894 atomic_inc(&inode->i_writecount);
70895 @@ -1324,6 +1476,7 @@ out:
70896
70897 mm->total_vm += len >> PAGE_SHIFT;
70898 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
70899 + track_exec_limit(mm, addr, addr + len, vm_flags);
70900 if (vm_flags & VM_LOCKED) {
70901 if (!mlock_vma_pages_range(vma, addr, addr + len))
70902 mm->locked_vm += (len >> PAGE_SHIFT);
70903 @@ -1341,6 +1494,12 @@ unmap_and_free_vma:
70904 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
70905 charged = 0;
70906 free_vma:
70907 +
70908 +#ifdef CONFIG_PAX_SEGMEXEC
70909 + if (vma_m)
70910 + kmem_cache_free(vm_area_cachep, vma_m);
70911 +#endif
70912 +
70913 kmem_cache_free(vm_area_cachep, vma);
70914 unacct_error:
70915 if (charged)
70916 @@ -1348,6 +1507,44 @@ unacct_error:
70917 return error;
70918 }
70919
70920 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
70921 +{
70922 + if (!vma) {
70923 +#ifdef CONFIG_STACK_GROWSUP
70924 + if (addr > sysctl_heap_stack_gap)
70925 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
70926 + else
70927 + vma = find_vma(current->mm, 0);
70928 + if (vma && (vma->vm_flags & VM_GROWSUP))
70929 + return false;
70930 +#endif
70931 + return true;
70932 + }
70933 +
70934 + if (addr + len > vma->vm_start)
70935 + return false;
70936 +
70937 + if (vma->vm_flags & VM_GROWSDOWN)
70938 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
70939 +#ifdef CONFIG_STACK_GROWSUP
70940 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
70941 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
70942 +#endif
70943 +
70944 + return true;
70945 +}
70946 +
70947 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
70948 +{
70949 + if (vma->vm_start < len)
70950 + return -ENOMEM;
70951 + if (!(vma->vm_flags & VM_GROWSDOWN))
70952 + return vma->vm_start - len;
70953 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
70954 + return vma->vm_start - len - sysctl_heap_stack_gap;
70955 + return -ENOMEM;
70956 +}
70957 +
70958 /* Get an address range which is currently unmapped.
70959 * For shmat() with addr=0.
70960 *
70961 @@ -1374,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
70962 if (flags & MAP_FIXED)
70963 return addr;
70964
70965 +#ifdef CONFIG_PAX_RANDMMAP
70966 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
70967 +#endif
70968 +
70969 if (addr) {
70970 addr = PAGE_ALIGN(addr);
70971 - vma = find_vma(mm, addr);
70972 - if (TASK_SIZE - len >= addr &&
70973 - (!vma || addr + len <= vma->vm_start))
70974 - return addr;
70975 + if (TASK_SIZE - len >= addr) {
70976 + vma = find_vma(mm, addr);
70977 + if (check_heap_stack_gap(vma, addr, len))
70978 + return addr;
70979 + }
70980 }
70981 if (len > mm->cached_hole_size) {
70982 - start_addr = addr = mm->free_area_cache;
70983 + start_addr = addr = mm->free_area_cache;
70984 } else {
70985 - start_addr = addr = TASK_UNMAPPED_BASE;
70986 - mm->cached_hole_size = 0;
70987 + start_addr = addr = mm->mmap_base;
70988 + mm->cached_hole_size = 0;
70989 }
70990
70991 full_search:
70992 @@ -1396,34 +1598,40 @@ full_search:
70993 * Start a new search - just in case we missed
70994 * some holes.
70995 */
70996 - if (start_addr != TASK_UNMAPPED_BASE) {
70997 - addr = TASK_UNMAPPED_BASE;
70998 - start_addr = addr;
70999 + if (start_addr != mm->mmap_base) {
71000 + start_addr = addr = mm->mmap_base;
71001 mm->cached_hole_size = 0;
71002 goto full_search;
71003 }
71004 return -ENOMEM;
71005 }
71006 - if (!vma || addr + len <= vma->vm_start) {
71007 - /*
71008 - * Remember the place where we stopped the search:
71009 - */
71010 - mm->free_area_cache = addr + len;
71011 - return addr;
71012 - }
71013 + if (check_heap_stack_gap(vma, addr, len))
71014 + break;
71015 if (addr + mm->cached_hole_size < vma->vm_start)
71016 mm->cached_hole_size = vma->vm_start - addr;
71017 addr = vma->vm_end;
71018 }
71019 +
71020 + /*
71021 + * Remember the place where we stopped the search:
71022 + */
71023 + mm->free_area_cache = addr + len;
71024 + return addr;
71025 }
71026 #endif
71027
71028 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71029 {
71030 +
71031 +#ifdef CONFIG_PAX_SEGMEXEC
71032 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71033 + return;
71034 +#endif
71035 +
71036 /*
71037 * Is this a new hole at the lowest possible address?
71038 */
71039 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71040 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71041 mm->free_area_cache = addr;
71042 mm->cached_hole_size = ~0UL;
71043 }
71044 @@ -1441,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71045 {
71046 struct vm_area_struct *vma;
71047 struct mm_struct *mm = current->mm;
71048 - unsigned long addr = addr0;
71049 + unsigned long base = mm->mmap_base, addr = addr0;
71050
71051 /* requested length too big for entire address space */
71052 if (len > TASK_SIZE)
71053 @@ -1450,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71054 if (flags & MAP_FIXED)
71055 return addr;
71056
71057 +#ifdef CONFIG_PAX_RANDMMAP
71058 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71059 +#endif
71060 +
71061 /* requesting a specific address */
71062 if (addr) {
71063 addr = PAGE_ALIGN(addr);
71064 - vma = find_vma(mm, addr);
71065 - if (TASK_SIZE - len >= addr &&
71066 - (!vma || addr + len <= vma->vm_start))
71067 - return addr;
71068 + if (TASK_SIZE - len >= addr) {
71069 + vma = find_vma(mm, addr);
71070 + if (check_heap_stack_gap(vma, addr, len))
71071 + return addr;
71072 + }
71073 }
71074
71075 /* check if free_area_cache is useful for us */
71076 @@ -1471,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71077 /* make sure it can fit in the remaining address space */
71078 if (addr > len) {
71079 vma = find_vma(mm, addr-len);
71080 - if (!vma || addr <= vma->vm_start)
71081 + if (check_heap_stack_gap(vma, addr - len, len))
71082 /* remember the address as a hint for next time */
71083 return (mm->free_area_cache = addr-len);
71084 }
71085 @@ -1488,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71086 * return with success:
71087 */
71088 vma = find_vma(mm, addr);
71089 - if (!vma || addr+len <= vma->vm_start)
71090 + if (check_heap_stack_gap(vma, addr, len))
71091 /* remember the address as a hint for next time */
71092 return (mm->free_area_cache = addr);
71093
71094 @@ -1497,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71095 mm->cached_hole_size = vma->vm_start - addr;
71096
71097 /* try just below the current vma->vm_start */
71098 - addr = vma->vm_start-len;
71099 - } while (len < vma->vm_start);
71100 + addr = skip_heap_stack_gap(vma, len);
71101 + } while (!IS_ERR_VALUE(addr));
71102
71103 bottomup:
71104 /*
71105 @@ -1507,13 +1720,21 @@ bottomup:
71106 * can happen with large stack limits and large mmap()
71107 * allocations.
71108 */
71109 + mm->mmap_base = TASK_UNMAPPED_BASE;
71110 +
71111 +#ifdef CONFIG_PAX_RANDMMAP
71112 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71113 + mm->mmap_base += mm->delta_mmap;
71114 +#endif
71115 +
71116 + mm->free_area_cache = mm->mmap_base;
71117 mm->cached_hole_size = ~0UL;
71118 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71119 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71120 /*
71121 * Restore the topdown base:
71122 */
71123 - mm->free_area_cache = mm->mmap_base;
71124 + mm->mmap_base = base;
71125 + mm->free_area_cache = base;
71126 mm->cached_hole_size = ~0UL;
71127
71128 return addr;
71129 @@ -1522,6 +1743,12 @@ bottomup:
71130
71131 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71132 {
71133 +
71134 +#ifdef CONFIG_PAX_SEGMEXEC
71135 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71136 + return;
71137 +#endif
71138 +
71139 /*
71140 * Is this a new hole at the highest possible address?
71141 */
71142 @@ -1529,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71143 mm->free_area_cache = addr;
71144
71145 /* dont allow allocations above current base */
71146 - if (mm->free_area_cache > mm->mmap_base)
71147 + if (mm->free_area_cache > mm->mmap_base) {
71148 mm->free_area_cache = mm->mmap_base;
71149 + mm->cached_hole_size = ~0UL;
71150 + }
71151 }
71152
71153 unsigned long
71154 @@ -1603,40 +1832,50 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
71155
71156 EXPORT_SYMBOL(find_vma);
71157
71158 -/* Same as find_vma, but also return a pointer to the previous VMA in *pprev. */
71159 +/*
71160 + * Same as find_vma, but also return a pointer to the previous VMA in *pprev.
71161 + */
71162 struct vm_area_struct *
71163 find_vma_prev(struct mm_struct *mm, unsigned long addr,
71164 struct vm_area_struct **pprev)
71165 {
71166 - struct vm_area_struct *vma = NULL, *prev = NULL;
71167 - struct rb_node *rb_node;
71168 - if (!mm)
71169 - goto out;
71170 -
71171 - /* Guard against addr being lower than the first VMA */
71172 - vma = mm->mmap;
71173 -
71174 - /* Go through the RB tree quickly. */
71175 - rb_node = mm->mm_rb.rb_node;
71176 -
71177 - while (rb_node) {
71178 - struct vm_area_struct *vma_tmp;
71179 - vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);
71180 -
71181 - if (addr < vma_tmp->vm_end) {
71182 - rb_node = rb_node->rb_left;
71183 - } else {
71184 - prev = vma_tmp;
71185 - if (!prev->vm_next || (addr < prev->vm_next->vm_end))
71186 - break;
71187 + struct vm_area_struct *vma;
71188 +
71189 + vma = find_vma(mm, addr);
71190 + if (vma) {
71191 + *pprev = vma->vm_prev;
71192 + } else {
71193 + struct rb_node *rb_node = mm->mm_rb.rb_node;
71194 + *pprev = NULL;
71195 + while (rb_node) {
71196 + *pprev = rb_entry(rb_node, struct vm_area_struct, vm_rb);
71197 rb_node = rb_node->rb_right;
71198 }
71199 }
71200 + return vma;
71201 +}
71202 +
71203 +#ifdef CONFIG_PAX_SEGMEXEC
71204 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71205 +{
71206 + struct vm_area_struct *vma_m;
71207
71208 -out:
71209 - *pprev = prev;
71210 - return prev ? prev->vm_next : vma;
71211 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71212 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71213 + BUG_ON(vma->vm_mirror);
71214 + return NULL;
71215 + }
71216 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71217 + vma_m = vma->vm_mirror;
71218 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71219 + BUG_ON(vma->vm_file != vma_m->vm_file);
71220 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71221 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71222 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71223 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71224 + return vma_m;
71225 }
71226 +#endif
71227
71228 /*
71229 * Verify that the stack growth is acceptable and
71230 @@ -1654,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71231 return -ENOMEM;
71232
71233 /* Stack limit test */
71234 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
71235 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71236 return -ENOMEM;
71237
71238 @@ -1664,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71239 locked = mm->locked_vm + grow;
71240 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71241 limit >>= PAGE_SHIFT;
71242 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71243 if (locked > limit && !capable(CAP_IPC_LOCK))
71244 return -ENOMEM;
71245 }
71246 @@ -1694,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71247 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
71248 * vma is the last one with address > vma->vm_end. Have to extend vma.
71249 */
71250 +#ifndef CONFIG_IA64
71251 +static
71252 +#endif
71253 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71254 {
71255 int error;
71256 + bool locknext;
71257
71258 if (!(vma->vm_flags & VM_GROWSUP))
71259 return -EFAULT;
71260
71261 + /* Also guard against wrapping around to address 0. */
71262 + if (address < PAGE_ALIGN(address+1))
71263 + address = PAGE_ALIGN(address+1);
71264 + else
71265 + return -ENOMEM;
71266 +
71267 /*
71268 * We must make sure the anon_vma is allocated
71269 * so that the anon_vma locking is not a noop.
71270 */
71271 if (unlikely(anon_vma_prepare(vma)))
71272 return -ENOMEM;
71273 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
71274 + if (locknext && anon_vma_prepare(vma->vm_next))
71275 + return -ENOMEM;
71276 vma_lock_anon_vma(vma);
71277 + if (locknext)
71278 + vma_lock_anon_vma(vma->vm_next);
71279
71280 /*
71281 * vma->vm_start/vm_end cannot change under us because the caller
71282 * is required to hold the mmap_sem in read mode. We need the
71283 - * anon_vma lock to serialize against concurrent expand_stacks.
71284 - * Also guard against wrapping around to address 0.
71285 + * anon_vma locks to serialize against concurrent expand_stacks
71286 + * and expand_upwards.
71287 */
71288 - if (address < PAGE_ALIGN(address+4))
71289 - address = PAGE_ALIGN(address+4);
71290 - else {
71291 - vma_unlock_anon_vma(vma);
71292 - return -ENOMEM;
71293 - }
71294 error = 0;
71295
71296 /* Somebody else might have raced and expanded it already */
71297 - if (address > vma->vm_end) {
71298 + 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)
71299 + error = -ENOMEM;
71300 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
71301 unsigned long size, grow;
71302
71303 size = address - vma->vm_start;
71304 @@ -1739,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71305 }
71306 }
71307 }
71308 + if (locknext)
71309 + vma_unlock_anon_vma(vma->vm_next);
71310 vma_unlock_anon_vma(vma);
71311 khugepaged_enter_vma_merge(vma);
71312 return error;
71313 @@ -1752,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
71314 unsigned long address)
71315 {
71316 int error;
71317 + bool lockprev = false;
71318 + struct vm_area_struct *prev;
71319
71320 /*
71321 * We must make sure the anon_vma is allocated
71322 @@ -1765,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
71323 if (error)
71324 return error;
71325
71326 + prev = vma->vm_prev;
71327 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
71328 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
71329 +#endif
71330 + if (lockprev && anon_vma_prepare(prev))
71331 + return -ENOMEM;
71332 + if (lockprev)
71333 + vma_lock_anon_vma(prev);
71334 +
71335 vma_lock_anon_vma(vma);
71336
71337 /*
71338 @@ -1774,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
71339 */
71340
71341 /* Somebody else might have raced and expanded it already */
71342 - if (address < vma->vm_start) {
71343 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
71344 + error = -ENOMEM;
71345 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
71346 unsigned long size, grow;
71347
71348 +#ifdef CONFIG_PAX_SEGMEXEC
71349 + struct vm_area_struct *vma_m;
71350 +
71351 + vma_m = pax_find_mirror_vma(vma);
71352 +#endif
71353 +
71354 size = vma->vm_end - address;
71355 grow = (vma->vm_start - address) >> PAGE_SHIFT;
71356
71357 @@ -1786,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
71358 if (!error) {
71359 vma->vm_start = address;
71360 vma->vm_pgoff -= grow;
71361 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
71362 +
71363 +#ifdef CONFIG_PAX_SEGMEXEC
71364 + if (vma_m) {
71365 + vma_m->vm_start -= grow << PAGE_SHIFT;
71366 + vma_m->vm_pgoff -= grow;
71367 + }
71368 +#endif
71369 +
71370 perf_event_mmap(vma);
71371 }
71372 }
71373 }
71374 vma_unlock_anon_vma(vma);
71375 + if (lockprev)
71376 + vma_unlock_anon_vma(prev);
71377 khugepaged_enter_vma_merge(vma);
71378 return error;
71379 }
71380 @@ -1860,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
71381 do {
71382 long nrpages = vma_pages(vma);
71383
71384 +#ifdef CONFIG_PAX_SEGMEXEC
71385 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
71386 + vma = remove_vma(vma);
71387 + continue;
71388 + }
71389 +#endif
71390 +
71391 mm->total_vm -= nrpages;
71392 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
71393 vma = remove_vma(vma);
71394 @@ -1905,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
71395 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
71396 vma->vm_prev = NULL;
71397 do {
71398 +
71399 +#ifdef CONFIG_PAX_SEGMEXEC
71400 + if (vma->vm_mirror) {
71401 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
71402 + vma->vm_mirror->vm_mirror = NULL;
71403 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
71404 + vma->vm_mirror = NULL;
71405 + }
71406 +#endif
71407 +
71408 rb_erase(&vma->vm_rb, &mm->mm_rb);
71409 mm->map_count--;
71410 tail_vma = vma;
71411 @@ -1933,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71412 struct vm_area_struct *new;
71413 int err = -ENOMEM;
71414
71415 +#ifdef CONFIG_PAX_SEGMEXEC
71416 + struct vm_area_struct *vma_m, *new_m = NULL;
71417 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
71418 +#endif
71419 +
71420 if (is_vm_hugetlb_page(vma) && (addr &
71421 ~(huge_page_mask(hstate_vma(vma)))))
71422 return -EINVAL;
71423
71424 +#ifdef CONFIG_PAX_SEGMEXEC
71425 + vma_m = pax_find_mirror_vma(vma);
71426 +#endif
71427 +
71428 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71429 if (!new)
71430 goto out_err;
71431
71432 +#ifdef CONFIG_PAX_SEGMEXEC
71433 + if (vma_m) {
71434 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71435 + if (!new_m) {
71436 + kmem_cache_free(vm_area_cachep, new);
71437 + goto out_err;
71438 + }
71439 + }
71440 +#endif
71441 +
71442 /* most fields are the same, copy all, and then fixup */
71443 *new = *vma;
71444
71445 @@ -1953,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71446 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
71447 }
71448
71449 +#ifdef CONFIG_PAX_SEGMEXEC
71450 + if (vma_m) {
71451 + *new_m = *vma_m;
71452 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
71453 + new_m->vm_mirror = new;
71454 + new->vm_mirror = new_m;
71455 +
71456 + if (new_below)
71457 + new_m->vm_end = addr_m;
71458 + else {
71459 + new_m->vm_start = addr_m;
71460 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71461 + }
71462 + }
71463 +#endif
71464 +
71465 pol = mpol_dup(vma_policy(vma));
71466 if (IS_ERR(pol)) {
71467 err = PTR_ERR(pol);
71468 @@ -1978,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71469 else
71470 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71471
71472 +#ifdef CONFIG_PAX_SEGMEXEC
71473 + if (!err && vma_m) {
71474 + if (anon_vma_clone(new_m, vma_m))
71475 + goto out_free_mpol;
71476 +
71477 + mpol_get(pol);
71478 + vma_set_policy(new_m, pol);
71479 +
71480 + if (new_m->vm_file) {
71481 + get_file(new_m->vm_file);
71482 + if (vma_m->vm_flags & VM_EXECUTABLE)
71483 + added_exe_file_vma(mm);
71484 + }
71485 +
71486 + if (new_m->vm_ops && new_m->vm_ops->open)
71487 + new_m->vm_ops->open(new_m);
71488 +
71489 + if (new_below)
71490 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71491 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71492 + else
71493 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71494 +
71495 + if (err) {
71496 + if (new_m->vm_ops && new_m->vm_ops->close)
71497 + new_m->vm_ops->close(new_m);
71498 + if (new_m->vm_file) {
71499 + if (vma_m->vm_flags & VM_EXECUTABLE)
71500 + removed_exe_file_vma(mm);
71501 + fput(new_m->vm_file);
71502 + }
71503 + mpol_put(pol);
71504 + }
71505 + }
71506 +#endif
71507 +
71508 /* Success. */
71509 if (!err)
71510 return 0;
71511 @@ -1990,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71512 removed_exe_file_vma(mm);
71513 fput(new->vm_file);
71514 }
71515 - unlink_anon_vmas(new);
71516 out_free_mpol:
71517 mpol_put(pol);
71518 out_free_vma:
71519 +
71520 +#ifdef CONFIG_PAX_SEGMEXEC
71521 + if (new_m) {
71522 + unlink_anon_vmas(new_m);
71523 + kmem_cache_free(vm_area_cachep, new_m);
71524 + }
71525 +#endif
71526 +
71527 + unlink_anon_vmas(new);
71528 kmem_cache_free(vm_area_cachep, new);
71529 out_err:
71530 return err;
71531 @@ -2006,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71532 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71533 unsigned long addr, int new_below)
71534 {
71535 +
71536 +#ifdef CONFIG_PAX_SEGMEXEC
71537 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71538 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71539 + if (mm->map_count >= sysctl_max_map_count-1)
71540 + return -ENOMEM;
71541 + } else
71542 +#endif
71543 +
71544 if (mm->map_count >= sysctl_max_map_count)
71545 return -ENOMEM;
71546
71547 @@ -2017,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71548 * work. This now handles partial unmappings.
71549 * Jeremy Fitzhardinge <jeremy@goop.org>
71550 */
71551 +#ifdef CONFIG_PAX_SEGMEXEC
71552 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71553 {
71554 + int ret = __do_munmap(mm, start, len);
71555 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71556 + return ret;
71557 +
71558 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71559 +}
71560 +
71561 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71562 +#else
71563 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71564 +#endif
71565 +{
71566 unsigned long end;
71567 struct vm_area_struct *vma, *prev, *last;
71568
71569 + /*
71570 + * mm->mmap_sem is required to protect against another thread
71571 + * changing the mappings in case we sleep.
71572 + */
71573 + verify_mm_writelocked(mm);
71574 +
71575 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71576 return -EINVAL;
71577
71578 @@ -2096,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71579 /* Fix up all other VM information */
71580 remove_vma_list(mm, vma);
71581
71582 + track_exec_limit(mm, start, end, 0UL);
71583 +
71584 return 0;
71585 }
71586
71587 @@ -2108,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71588
71589 profile_munmap(addr);
71590
71591 +#ifdef CONFIG_PAX_SEGMEXEC
71592 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71593 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
71594 + return -EINVAL;
71595 +#endif
71596 +
71597 down_write(&mm->mmap_sem);
71598 ret = do_munmap(mm, addr, len);
71599 up_write(&mm->mmap_sem);
71600 return ret;
71601 }
71602
71603 -static inline void verify_mm_writelocked(struct mm_struct *mm)
71604 -{
71605 -#ifdef CONFIG_DEBUG_VM
71606 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71607 - WARN_ON(1);
71608 - up_read(&mm->mmap_sem);
71609 - }
71610 -#endif
71611 -}
71612 -
71613 /*
71614 * this is really a simplified "do_mmap". it only handles
71615 * anonymous maps. eventually we may be able to do some
71616 @@ -2137,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71617 struct rb_node ** rb_link, * rb_parent;
71618 pgoff_t pgoff = addr >> PAGE_SHIFT;
71619 int error;
71620 + unsigned long charged;
71621
71622 len = PAGE_ALIGN(len);
71623 if (!len)
71624 @@ -2148,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71625
71626 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71627
71628 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71629 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71630 + flags &= ~VM_EXEC;
71631 +
71632 +#ifdef CONFIG_PAX_MPROTECT
71633 + if (mm->pax_flags & MF_PAX_MPROTECT)
71634 + flags &= ~VM_MAYEXEC;
71635 +#endif
71636 +
71637 + }
71638 +#endif
71639 +
71640 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71641 if (error & ~PAGE_MASK)
71642 return error;
71643
71644 + charged = len >> PAGE_SHIFT;
71645 +
71646 /*
71647 * mlock MCL_FUTURE?
71648 */
71649 if (mm->def_flags & VM_LOCKED) {
71650 unsigned long locked, lock_limit;
71651 - locked = len >> PAGE_SHIFT;
71652 + locked = charged;
71653 locked += mm->locked_vm;
71654 lock_limit = rlimit(RLIMIT_MEMLOCK);
71655 lock_limit >>= PAGE_SHIFT;
71656 @@ -2174,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71657 /*
71658 * Clear old maps. this also does some error checking for us
71659 */
71660 - munmap_back:
71661 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71662 if (vma && vma->vm_start < addr + len) {
71663 if (do_munmap(mm, addr, len))
71664 return -ENOMEM;
71665 - goto munmap_back;
71666 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71667 + BUG_ON(vma && vma->vm_start < addr + len);
71668 }
71669
71670 /* Check against address space limits *after* clearing old maps... */
71671 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71672 + if (!may_expand_vm(mm, charged))
71673 return -ENOMEM;
71674
71675 if (mm->map_count > sysctl_max_map_count)
71676 return -ENOMEM;
71677
71678 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
71679 + if (security_vm_enough_memory(charged))
71680 return -ENOMEM;
71681
71682 /* Can we just expand an old private anonymous mapping? */
71683 @@ -2203,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71684 */
71685 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71686 if (!vma) {
71687 - vm_unacct_memory(len >> PAGE_SHIFT);
71688 + vm_unacct_memory(charged);
71689 return -ENOMEM;
71690 }
71691
71692 @@ -2217,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71693 vma_link(mm, vma, prev, rb_link, rb_parent);
71694 out:
71695 perf_event_mmap(vma);
71696 - mm->total_vm += len >> PAGE_SHIFT;
71697 + mm->total_vm += charged;
71698 if (flags & VM_LOCKED) {
71699 if (!mlock_vma_pages_range(vma, addr, addr + len))
71700 - mm->locked_vm += (len >> PAGE_SHIFT);
71701 + mm->locked_vm += charged;
71702 }
71703 + track_exec_limit(mm, addr, addr + len, flags);
71704 return addr;
71705 }
71706
71707 @@ -2268,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
71708 * Walk the list again, actually closing and freeing it,
71709 * with preemption enabled, without holding any MM locks.
71710 */
71711 - while (vma)
71712 + while (vma) {
71713 + vma->vm_mirror = NULL;
71714 vma = remove_vma(vma);
71715 + }
71716
71717 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71718 }
71719 @@ -2283,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71720 struct vm_area_struct * __vma, * prev;
71721 struct rb_node ** rb_link, * rb_parent;
71722
71723 +#ifdef CONFIG_PAX_SEGMEXEC
71724 + struct vm_area_struct *vma_m = NULL;
71725 +#endif
71726 +
71727 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71728 + return -EPERM;
71729 +
71730 /*
71731 * The vm_pgoff of a purely anonymous vma should be irrelevant
71732 * until its first write fault, when page's anon_vma and index
71733 @@ -2305,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71734 if ((vma->vm_flags & VM_ACCOUNT) &&
71735 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71736 return -ENOMEM;
71737 +
71738 +#ifdef CONFIG_PAX_SEGMEXEC
71739 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71740 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71741 + if (!vma_m)
71742 + return -ENOMEM;
71743 + }
71744 +#endif
71745 +
71746 vma_link(mm, vma, prev, rb_link, rb_parent);
71747 +
71748 +#ifdef CONFIG_PAX_SEGMEXEC
71749 + if (vma_m)
71750 + BUG_ON(pax_mirror_vma(vma_m, vma));
71751 +#endif
71752 +
71753 return 0;
71754 }
71755
71756 @@ -2323,6 +2769,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71757 struct rb_node **rb_link, *rb_parent;
71758 struct mempolicy *pol;
71759
71760 + BUG_ON(vma->vm_mirror);
71761 +
71762 /*
71763 * If anonymous vma has not yet been faulted, update new pgoff
71764 * to match new location, to increase its chance of merging.
71765 @@ -2373,6 +2821,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71766 return NULL;
71767 }
71768
71769 +#ifdef CONFIG_PAX_SEGMEXEC
71770 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71771 +{
71772 + struct vm_area_struct *prev_m;
71773 + struct rb_node **rb_link_m, *rb_parent_m;
71774 + struct mempolicy *pol_m;
71775 +
71776 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71777 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71778 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71779 + *vma_m = *vma;
71780 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71781 + if (anon_vma_clone(vma_m, vma))
71782 + return -ENOMEM;
71783 + pol_m = vma_policy(vma_m);
71784 + mpol_get(pol_m);
71785 + vma_set_policy(vma_m, pol_m);
71786 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71787 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71788 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71789 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71790 + if (vma_m->vm_file)
71791 + get_file(vma_m->vm_file);
71792 + if (vma_m->vm_ops && vma_m->vm_ops->open)
71793 + vma_m->vm_ops->open(vma_m);
71794 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71795 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71796 + vma_m->vm_mirror = vma;
71797 + vma->vm_mirror = vma_m;
71798 + return 0;
71799 +}
71800 +#endif
71801 +
71802 /*
71803 * Return true if the calling process may expand its vm space by the passed
71804 * number of pages
71805 @@ -2383,7 +2864,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71806 unsigned long lim;
71807
71808 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71809 -
71810 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71811 if (cur + npages > lim)
71812 return 0;
71813 return 1;
71814 @@ -2454,6 +2935,22 @@ int install_special_mapping(struct mm_struct *mm,
71815 vma->vm_start = addr;
71816 vma->vm_end = addr + len;
71817
71818 +#ifdef CONFIG_PAX_MPROTECT
71819 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71820 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71821 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71822 + return -EPERM;
71823 + if (!(vm_flags & VM_EXEC))
71824 + vm_flags &= ~VM_MAYEXEC;
71825 +#else
71826 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71827 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71828 +#endif
71829 + else
71830 + vm_flags &= ~VM_MAYWRITE;
71831 + }
71832 +#endif
71833 +
71834 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71835 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71836
71837 diff --git a/mm/mprotect.c b/mm/mprotect.c
71838 index 5a688a2..27e031c 100644
71839 --- a/mm/mprotect.c
71840 +++ b/mm/mprotect.c
71841 @@ -23,10 +23,16 @@
71842 #include <linux/mmu_notifier.h>
71843 #include <linux/migrate.h>
71844 #include <linux/perf_event.h>
71845 +
71846 +#ifdef CONFIG_PAX_MPROTECT
71847 +#include <linux/elf.h>
71848 +#endif
71849 +
71850 #include <asm/uaccess.h>
71851 #include <asm/pgtable.h>
71852 #include <asm/cacheflush.h>
71853 #include <asm/tlbflush.h>
71854 +#include <asm/mmu_context.h>
71855
71856 #ifndef pgprot_modify
71857 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71858 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
71859 flush_tlb_range(vma, start, end);
71860 }
71861
71862 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71863 +/* called while holding the mmap semaphor for writing except stack expansion */
71864 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71865 +{
71866 + unsigned long oldlimit, newlimit = 0UL;
71867 +
71868 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
71869 + return;
71870 +
71871 + spin_lock(&mm->page_table_lock);
71872 + oldlimit = mm->context.user_cs_limit;
71873 + if ((prot & VM_EXEC) && oldlimit < end)
71874 + /* USER_CS limit moved up */
71875 + newlimit = end;
71876 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
71877 + /* USER_CS limit moved down */
71878 + newlimit = start;
71879 +
71880 + if (newlimit) {
71881 + mm->context.user_cs_limit = newlimit;
71882 +
71883 +#ifdef CONFIG_SMP
71884 + wmb();
71885 + cpus_clear(mm->context.cpu_user_cs_mask);
71886 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
71887 +#endif
71888 +
71889 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
71890 + }
71891 + spin_unlock(&mm->page_table_lock);
71892 + if (newlimit == end) {
71893 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
71894 +
71895 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
71896 + if (is_vm_hugetlb_page(vma))
71897 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
71898 + else
71899 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
71900 + }
71901 +}
71902 +#endif
71903 +
71904 int
71905 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71906 unsigned long start, unsigned long end, unsigned long newflags)
71907 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71908 int error;
71909 int dirty_accountable = 0;
71910
71911 +#ifdef CONFIG_PAX_SEGMEXEC
71912 + struct vm_area_struct *vma_m = NULL;
71913 + unsigned long start_m, end_m;
71914 +
71915 + start_m = start + SEGMEXEC_TASK_SIZE;
71916 + end_m = end + SEGMEXEC_TASK_SIZE;
71917 +#endif
71918 +
71919 if (newflags == oldflags) {
71920 *pprev = vma;
71921 return 0;
71922 }
71923
71924 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
71925 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
71926 +
71927 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
71928 + return -ENOMEM;
71929 +
71930 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
71931 + return -ENOMEM;
71932 + }
71933 +
71934 /*
71935 * If we make a private mapping writable we increase our commit;
71936 * but (without finer accounting) cannot reduce our commit if we
71937 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71938 }
71939 }
71940
71941 +#ifdef CONFIG_PAX_SEGMEXEC
71942 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
71943 + if (start != vma->vm_start) {
71944 + error = split_vma(mm, vma, start, 1);
71945 + if (error)
71946 + goto fail;
71947 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
71948 + *pprev = (*pprev)->vm_next;
71949 + }
71950 +
71951 + if (end != vma->vm_end) {
71952 + error = split_vma(mm, vma, end, 0);
71953 + if (error)
71954 + goto fail;
71955 + }
71956 +
71957 + if (pax_find_mirror_vma(vma)) {
71958 + error = __do_munmap(mm, start_m, end_m - start_m);
71959 + if (error)
71960 + goto fail;
71961 + } else {
71962 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71963 + if (!vma_m) {
71964 + error = -ENOMEM;
71965 + goto fail;
71966 + }
71967 + vma->vm_flags = newflags;
71968 + error = pax_mirror_vma(vma_m, vma);
71969 + if (error) {
71970 + vma->vm_flags = oldflags;
71971 + goto fail;
71972 + }
71973 + }
71974 + }
71975 +#endif
71976 +
71977 /*
71978 * First try to merge with previous and/or next vma.
71979 */
71980 @@ -204,9 +306,21 @@ success:
71981 * vm_flags and vm_page_prot are protected by the mmap_sem
71982 * held in write mode.
71983 */
71984 +
71985 +#ifdef CONFIG_PAX_SEGMEXEC
71986 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
71987 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
71988 +#endif
71989 +
71990 vma->vm_flags = newflags;
71991 +
71992 +#ifdef CONFIG_PAX_MPROTECT
71993 + if (mm->binfmt && mm->binfmt->handle_mprotect)
71994 + mm->binfmt->handle_mprotect(vma, newflags);
71995 +#endif
71996 +
71997 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
71998 - vm_get_page_prot(newflags));
71999 + vm_get_page_prot(vma->vm_flags));
72000
72001 if (vma_wants_writenotify(vma)) {
72002 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72003 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72004 end = start + len;
72005 if (end <= start)
72006 return -ENOMEM;
72007 +
72008 +#ifdef CONFIG_PAX_SEGMEXEC
72009 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72010 + if (end > SEGMEXEC_TASK_SIZE)
72011 + return -EINVAL;
72012 + } else
72013 +#endif
72014 +
72015 + if (end > TASK_SIZE)
72016 + return -EINVAL;
72017 +
72018 if (!arch_validate_prot(prot))
72019 return -EINVAL;
72020
72021 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72022 /*
72023 * Does the application expect PROT_READ to imply PROT_EXEC:
72024 */
72025 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72026 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72027 prot |= PROT_EXEC;
72028
72029 vm_flags = calc_vm_prot_bits(prot);
72030 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72031 if (start > vma->vm_start)
72032 prev = vma;
72033
72034 +#ifdef CONFIG_PAX_MPROTECT
72035 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72036 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72037 +#endif
72038 +
72039 for (nstart = start ; ; ) {
72040 unsigned long newflags;
72041
72042 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72043
72044 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72045 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72046 + if (prot & (PROT_WRITE | PROT_EXEC))
72047 + gr_log_rwxmprotect(vma->vm_file);
72048 +
72049 + error = -EACCES;
72050 + goto out;
72051 + }
72052 +
72053 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72054 error = -EACCES;
72055 goto out;
72056 }
72057 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72058 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72059 if (error)
72060 goto out;
72061 +
72062 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72063 +
72064 nstart = tmp;
72065
72066 if (nstart < prev->vm_end)
72067 diff --git a/mm/mremap.c b/mm/mremap.c
72068 index d6959cb..18a402a 100644
72069 --- a/mm/mremap.c
72070 +++ b/mm/mremap.c
72071 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72072 continue;
72073 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72074 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72075 +
72076 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72077 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72078 + pte = pte_exprotect(pte);
72079 +#endif
72080 +
72081 set_pte_at(mm, new_addr, new_pte, pte);
72082 }
72083
72084 @@ -290,6 +296,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72085 if (is_vm_hugetlb_page(vma))
72086 goto Einval;
72087
72088 +#ifdef CONFIG_PAX_SEGMEXEC
72089 + if (pax_find_mirror_vma(vma))
72090 + goto Einval;
72091 +#endif
72092 +
72093 /* We can't remap across vm area boundaries */
72094 if (old_len > vma->vm_end - addr)
72095 goto Efault;
72096 @@ -346,20 +357,25 @@ static unsigned long mremap_to(unsigned long addr,
72097 unsigned long ret = -EINVAL;
72098 unsigned long charged = 0;
72099 unsigned long map_flags;
72100 + unsigned long pax_task_size = TASK_SIZE;
72101
72102 if (new_addr & ~PAGE_MASK)
72103 goto out;
72104
72105 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72106 +#ifdef CONFIG_PAX_SEGMEXEC
72107 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72108 + pax_task_size = SEGMEXEC_TASK_SIZE;
72109 +#endif
72110 +
72111 + pax_task_size -= PAGE_SIZE;
72112 +
72113 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72114 goto out;
72115
72116 /* Check if the location we're moving into overlaps the
72117 * old location at all, and fail if it does.
72118 */
72119 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72120 - goto out;
72121 -
72122 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72123 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72124 goto out;
72125
72126 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72127 @@ -431,6 +447,7 @@ unsigned long do_mremap(unsigned long addr,
72128 struct vm_area_struct *vma;
72129 unsigned long ret = -EINVAL;
72130 unsigned long charged = 0;
72131 + unsigned long pax_task_size = TASK_SIZE;
72132
72133 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72134 goto out;
72135 @@ -449,6 +466,17 @@ unsigned long do_mremap(unsigned long addr,
72136 if (!new_len)
72137 goto out;
72138
72139 +#ifdef CONFIG_PAX_SEGMEXEC
72140 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72141 + pax_task_size = SEGMEXEC_TASK_SIZE;
72142 +#endif
72143 +
72144 + pax_task_size -= PAGE_SIZE;
72145 +
72146 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72147 + old_len > pax_task_size || addr > pax_task_size-old_len)
72148 + goto out;
72149 +
72150 if (flags & MREMAP_FIXED) {
72151 if (flags & MREMAP_MAYMOVE)
72152 ret = mremap_to(addr, old_len, new_addr, new_len);
72153 @@ -498,6 +526,7 @@ unsigned long do_mremap(unsigned long addr,
72154 addr + new_len);
72155 }
72156 ret = addr;
72157 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72158 goto out;
72159 }
72160 }
72161 @@ -524,7 +553,13 @@ unsigned long do_mremap(unsigned long addr,
72162 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72163 if (ret)
72164 goto out;
72165 +
72166 + map_flags = vma->vm_flags;
72167 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72168 + if (!(ret & ~PAGE_MASK)) {
72169 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72170 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72171 + }
72172 }
72173 out:
72174 if (ret & ~PAGE_MASK)
72175 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
72176 index 7fa41b4..6087460 100644
72177 --- a/mm/nobootmem.c
72178 +++ b/mm/nobootmem.c
72179 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
72180 unsigned long __init free_all_memory_core_early(int nodeid)
72181 {
72182 int i;
72183 - u64 start, end;
72184 + u64 start, end, startrange, endrange;
72185 unsigned long count = 0;
72186 - struct range *range = NULL;
72187 + struct range *range = NULL, rangerange = { 0, 0 };
72188 int nr_range;
72189
72190 nr_range = get_free_all_memory_range(&range, nodeid);
72191 + startrange = __pa(range) >> PAGE_SHIFT;
72192 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
72193
72194 for (i = 0; i < nr_range; i++) {
72195 start = range[i].start;
72196 end = range[i].end;
72197 + if (start <= endrange && startrange < end) {
72198 + BUG_ON(rangerange.start | rangerange.end);
72199 + rangerange = range[i];
72200 + continue;
72201 + }
72202 count += end - start;
72203 __free_pages_memory(start, end);
72204 }
72205 + start = rangerange.start;
72206 + end = rangerange.end;
72207 + count += end - start;
72208 + __free_pages_memory(start, end);
72209
72210 return count;
72211 }
72212 diff --git a/mm/nommu.c b/mm/nommu.c
72213 index f59e170..34e2a2b 100644
72214 --- a/mm/nommu.c
72215 +++ b/mm/nommu.c
72216 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72217 int sysctl_overcommit_ratio = 50; /* default is 50% */
72218 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72219 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72220 -int heap_stack_gap = 0;
72221
72222 atomic_long_t mmap_pages_allocated;
72223
72224 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72225 EXPORT_SYMBOL(find_vma);
72226
72227 /*
72228 - * find a VMA
72229 - * - we don't extend stack VMAs under NOMMU conditions
72230 - */
72231 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72232 -{
72233 - return find_vma(mm, addr);
72234 -}
72235 -
72236 -/*
72237 * expand a stack to a given address
72238 * - not supported under NOMMU conditions
72239 */
72240 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72241
72242 /* most fields are the same, copy all, and then fixup */
72243 *new = *vma;
72244 + INIT_LIST_HEAD(&new->anon_vma_chain);
72245 *region = *vma->vm_region;
72246 new->vm_region = region;
72247
72248 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72249 index 485be89..c059ad3 100644
72250 --- a/mm/page_alloc.c
72251 +++ b/mm/page_alloc.c
72252 @@ -341,7 +341,7 @@ out:
72253 * This usage means that zero-order pages may not be compound.
72254 */
72255
72256 -static void free_compound_page(struct page *page)
72257 +void free_compound_page(struct page *page)
72258 {
72259 __free_pages_ok(page, compound_order(page));
72260 }
72261 @@ -654,6 +654,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72262 int i;
72263 int bad = 0;
72264
72265 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72266 + unsigned long index = 1UL << order;
72267 +#endif
72268 +
72269 trace_mm_page_free_direct(page, order);
72270 kmemcheck_free_shadow(page, order);
72271
72272 @@ -669,6 +673,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72273 debug_check_no_obj_freed(page_address(page),
72274 PAGE_SIZE << order);
72275 }
72276 +
72277 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72278 + for (; index; --index)
72279 + sanitize_highpage(page + index - 1);
72280 +#endif
72281 +
72282 arch_free_page(page, order);
72283 kernel_map_pages(page, 1 << order, 0);
72284
72285 @@ -784,8 +794,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
72286 arch_alloc_page(page, order);
72287 kernel_map_pages(page, 1 << order, 1);
72288
72289 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
72290 if (gfp_flags & __GFP_ZERO)
72291 prep_zero_page(page, order, gfp_flags);
72292 +#endif
72293
72294 if (order && (gfp_flags & __GFP_COMP))
72295 prep_compound_page(page, order);
72296 @@ -3357,7 +3369,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
72297 unsigned long pfn;
72298
72299 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
72300 +#ifdef CONFIG_X86_32
72301 + /* boot failures in VMware 8 on 32bit vanilla since
72302 + this change */
72303 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
72304 +#else
72305 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
72306 +#endif
72307 return 1;
72308 }
72309 return 0;
72310 diff --git a/mm/percpu.c b/mm/percpu.c
72311 index 716eb4a..8d10419 100644
72312 --- a/mm/percpu.c
72313 +++ b/mm/percpu.c
72314 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
72315 static unsigned int pcpu_high_unit_cpu __read_mostly;
72316
72317 /* the address of the first chunk which starts with the kernel static area */
72318 -void *pcpu_base_addr __read_mostly;
72319 +void *pcpu_base_addr __read_only;
72320 EXPORT_SYMBOL_GPL(pcpu_base_addr);
72321
72322 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
72323 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
72324 index e920aa3..137702a 100644
72325 --- a/mm/process_vm_access.c
72326 +++ b/mm/process_vm_access.c
72327 @@ -13,6 +13,7 @@
72328 #include <linux/uio.h>
72329 #include <linux/sched.h>
72330 #include <linux/highmem.h>
72331 +#include <linux/security.h>
72332 #include <linux/ptrace.h>
72333 #include <linux/slab.h>
72334 #include <linux/syscalls.h>
72335 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72336 size_t iov_l_curr_offset = 0;
72337 ssize_t iov_len;
72338
72339 + return -ENOSYS; // PaX: until properly audited
72340 +
72341 /*
72342 * Work out how many pages of struct pages we're going to need
72343 * when eventually calling get_user_pages
72344 */
72345 for (i = 0; i < riovcnt; i++) {
72346 iov_len = rvec[i].iov_len;
72347 - if (iov_len > 0) {
72348 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
72349 - + iov_len)
72350 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
72351 - / PAGE_SIZE + 1;
72352 - nr_pages = max(nr_pages, nr_pages_iov);
72353 - }
72354 + if (iov_len <= 0)
72355 + continue;
72356 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
72357 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
72358 + nr_pages = max(nr_pages, nr_pages_iov);
72359 }
72360
72361 if (nr_pages == 0)
72362 @@ -298,23 +299,23 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72363 goto free_proc_pages;
72364 }
72365
72366 - task_lock(task);
72367 - if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
72368 - task_unlock(task);
72369 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
72370 rc = -EPERM;
72371 goto put_task_struct;
72372 }
72373 - mm = task->mm;
72374
72375 - if (!mm || (task->flags & PF_KTHREAD)) {
72376 - task_unlock(task);
72377 - rc = -EINVAL;
72378 + mm = mm_access(task, PTRACE_MODE_ATTACH);
72379 + if (!mm || IS_ERR(mm)) {
72380 + rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
72381 + /*
72382 + * Explicitly map EACCES to EPERM as EPERM is a more a
72383 + * appropriate error code for process_vw_readv/writev
72384 + */
72385 + if (rc == -EACCES)
72386 + rc = -EPERM;
72387 goto put_task_struct;
72388 }
72389
72390 - atomic_inc(&mm->mm_users);
72391 - task_unlock(task);
72392 -
72393 for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
72394 rc = process_vm_rw_single_vec(
72395 (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
72396 diff --git a/mm/rmap.c b/mm/rmap.c
72397 index a4fd368..e0ffec7 100644
72398 --- a/mm/rmap.c
72399 +++ b/mm/rmap.c
72400 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72401 struct anon_vma *anon_vma = vma->anon_vma;
72402 struct anon_vma_chain *avc;
72403
72404 +#ifdef CONFIG_PAX_SEGMEXEC
72405 + struct anon_vma_chain *avc_m = NULL;
72406 +#endif
72407 +
72408 might_sleep();
72409 if (unlikely(!anon_vma)) {
72410 struct mm_struct *mm = vma->vm_mm;
72411 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72412 if (!avc)
72413 goto out_enomem;
72414
72415 +#ifdef CONFIG_PAX_SEGMEXEC
72416 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
72417 + if (!avc_m)
72418 + goto out_enomem_free_avc;
72419 +#endif
72420 +
72421 anon_vma = find_mergeable_anon_vma(vma);
72422 allocated = NULL;
72423 if (!anon_vma) {
72424 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72425 /* page_table_lock to protect against threads */
72426 spin_lock(&mm->page_table_lock);
72427 if (likely(!vma->anon_vma)) {
72428 +
72429 +#ifdef CONFIG_PAX_SEGMEXEC
72430 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
72431 +
72432 + if (vma_m) {
72433 + BUG_ON(vma_m->anon_vma);
72434 + vma_m->anon_vma = anon_vma;
72435 + avc_m->anon_vma = anon_vma;
72436 + avc_m->vma = vma;
72437 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
72438 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
72439 + avc_m = NULL;
72440 + }
72441 +#endif
72442 +
72443 vma->anon_vma = anon_vma;
72444 avc->anon_vma = anon_vma;
72445 avc->vma = vma;
72446 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72447
72448 if (unlikely(allocated))
72449 put_anon_vma(allocated);
72450 +
72451 +#ifdef CONFIG_PAX_SEGMEXEC
72452 + if (unlikely(avc_m))
72453 + anon_vma_chain_free(avc_m);
72454 +#endif
72455 +
72456 if (unlikely(avc))
72457 anon_vma_chain_free(avc);
72458 }
72459 return 0;
72460
72461 out_enomem_free_avc:
72462 +
72463 +#ifdef CONFIG_PAX_SEGMEXEC
72464 + if (avc_m)
72465 + anon_vma_chain_free(avc_m);
72466 +#endif
72467 +
72468 anon_vma_chain_free(avc);
72469 out_enomem:
72470 return -ENOMEM;
72471 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
72472 * Attach the anon_vmas from src to dst.
72473 * Returns 0 on success, -ENOMEM on failure.
72474 */
72475 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72476 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
72477 {
72478 struct anon_vma_chain *avc, *pavc;
72479 struct anon_vma *root = NULL;
72480 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72481 * the corresponding VMA in the parent process is attached to.
72482 * Returns 0 on success, non-zero on failure.
72483 */
72484 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
72485 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
72486 {
72487 struct anon_vma_chain *avc;
72488 struct anon_vma *anon_vma;
72489 diff --git a/mm/shmem.c b/mm/shmem.c
72490 index 6c253f7..367e20a 100644
72491 --- a/mm/shmem.c
72492 +++ b/mm/shmem.c
72493 @@ -31,7 +31,7 @@
72494 #include <linux/export.h>
72495 #include <linux/swap.h>
72496
72497 -static struct vfsmount *shm_mnt;
72498 +struct vfsmount *shm_mnt;
72499
72500 #ifdef CONFIG_SHMEM
72501 /*
72502 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
72503 #define BOGO_DIRENT_SIZE 20
72504
72505 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72506 -#define SHORT_SYMLINK_LEN 128
72507 +#define SHORT_SYMLINK_LEN 64
72508
72509 struct shmem_xattr {
72510 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72511 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72512 int err = -ENOMEM;
72513
72514 /* Round up to L1_CACHE_BYTES to resist false sharing */
72515 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72516 - L1_CACHE_BYTES), GFP_KERNEL);
72517 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72518 if (!sbinfo)
72519 return -ENOMEM;
72520
72521 diff --git a/mm/slab.c b/mm/slab.c
72522 index 83311c9a..fcf8f86 100644
72523 --- a/mm/slab.c
72524 +++ b/mm/slab.c
72525 @@ -151,7 +151,7 @@
72526
72527 /* Legal flag mask for kmem_cache_create(). */
72528 #if DEBUG
72529 -# define CREATE_MASK (SLAB_RED_ZONE | \
72530 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72531 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72532 SLAB_CACHE_DMA | \
72533 SLAB_STORE_USER | \
72534 @@ -159,7 +159,7 @@
72535 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72536 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72537 #else
72538 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72539 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72540 SLAB_CACHE_DMA | \
72541 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72542 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72543 @@ -288,7 +288,7 @@ struct kmem_list3 {
72544 * Need this for bootstrapping a per node allocator.
72545 */
72546 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72547 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72548 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72549 #define CACHE_CACHE 0
72550 #define SIZE_AC MAX_NUMNODES
72551 #define SIZE_L3 (2 * MAX_NUMNODES)
72552 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72553 if ((x)->max_freeable < i) \
72554 (x)->max_freeable = i; \
72555 } while (0)
72556 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72557 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72558 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72559 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72560 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72561 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72562 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72563 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72564 #else
72565 #define STATS_INC_ACTIVE(x) do { } while (0)
72566 #define STATS_DEC_ACTIVE(x) do { } while (0)
72567 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72568 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72569 */
72570 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72571 - const struct slab *slab, void *obj)
72572 + const struct slab *slab, const void *obj)
72573 {
72574 u32 offset = (obj - slab->s_mem);
72575 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72576 @@ -564,7 +564,7 @@ struct cache_names {
72577 static struct cache_names __initdata cache_names[] = {
72578 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72579 #include <linux/kmalloc_sizes.h>
72580 - {NULL,}
72581 + {NULL}
72582 #undef CACHE
72583 };
72584
72585 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
72586 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72587 sizes[INDEX_AC].cs_size,
72588 ARCH_KMALLOC_MINALIGN,
72589 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72590 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72591 NULL);
72592
72593 if (INDEX_AC != INDEX_L3) {
72594 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
72595 kmem_cache_create(names[INDEX_L3].name,
72596 sizes[INDEX_L3].cs_size,
72597 ARCH_KMALLOC_MINALIGN,
72598 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72599 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72600 NULL);
72601 }
72602
72603 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
72604 sizes->cs_cachep = kmem_cache_create(names->name,
72605 sizes->cs_size,
72606 ARCH_KMALLOC_MINALIGN,
72607 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72608 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72609 NULL);
72610 }
72611 #ifdef CONFIG_ZONE_DMA
72612 @@ -4322,10 +4322,10 @@ static int s_show(struct seq_file *m, void *p)
72613 }
72614 /* cpu stats */
72615 {
72616 - unsigned long allochit = atomic_read(&cachep->allochit);
72617 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72618 - unsigned long freehit = atomic_read(&cachep->freehit);
72619 - unsigned long freemiss = atomic_read(&cachep->freemiss);
72620 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72621 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72622 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72623 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72624
72625 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72626 allochit, allocmiss, freehit, freemiss);
72627 @@ -4584,13 +4584,62 @@ static int __init slab_proc_init(void)
72628 {
72629 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72630 #ifdef CONFIG_DEBUG_SLAB_LEAK
72631 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72632 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72633 #endif
72634 return 0;
72635 }
72636 module_init(slab_proc_init);
72637 #endif
72638
72639 +void check_object_size(const void *ptr, unsigned long n, bool to)
72640 +{
72641 +
72642 +#ifdef CONFIG_PAX_USERCOPY
72643 + struct page *page;
72644 + struct kmem_cache *cachep = NULL;
72645 + struct slab *slabp;
72646 + unsigned int objnr;
72647 + unsigned long offset;
72648 + const char *type;
72649 +
72650 + if (!n)
72651 + return;
72652 +
72653 + type = "<null>";
72654 + if (ZERO_OR_NULL_PTR(ptr))
72655 + goto report;
72656 +
72657 + if (!virt_addr_valid(ptr))
72658 + return;
72659 +
72660 + page = virt_to_head_page(ptr);
72661 +
72662 + type = "<process stack>";
72663 + if (!PageSlab(page)) {
72664 + if (object_is_on_stack(ptr, n) == -1)
72665 + goto report;
72666 + return;
72667 + }
72668 +
72669 + cachep = page_get_cache(page);
72670 + type = cachep->name;
72671 + if (!(cachep->flags & SLAB_USERCOPY))
72672 + goto report;
72673 +
72674 + slabp = page_get_slab(page);
72675 + objnr = obj_to_index(cachep, slabp, ptr);
72676 + BUG_ON(objnr >= cachep->num);
72677 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72678 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72679 + return;
72680 +
72681 +report:
72682 + pax_report_usercopy(ptr, n, to, type);
72683 +#endif
72684 +
72685 +}
72686 +EXPORT_SYMBOL(check_object_size);
72687 +
72688 /**
72689 * ksize - get the actual amount of memory allocated for a given object
72690 * @objp: Pointer to the object
72691 diff --git a/mm/slob.c b/mm/slob.c
72692 index 8105be4..e045f96 100644
72693 --- a/mm/slob.c
72694 +++ b/mm/slob.c
72695 @@ -29,7 +29,7 @@
72696 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72697 * alloc_pages() directly, allocating compound pages so the page order
72698 * does not have to be separately tracked, and also stores the exact
72699 - * allocation size in page->private so that it can be used to accurately
72700 + * allocation size in slob_page->size so that it can be used to accurately
72701 * provide ksize(). These objects are detected in kfree() because slob_page()
72702 * is false for them.
72703 *
72704 @@ -58,6 +58,7 @@
72705 */
72706
72707 #include <linux/kernel.h>
72708 +#include <linux/sched.h>
72709 #include <linux/slab.h>
72710 #include <linux/mm.h>
72711 #include <linux/swap.h> /* struct reclaim_state */
72712 @@ -102,7 +103,8 @@ struct slob_page {
72713 unsigned long flags; /* mandatory */
72714 atomic_t _count; /* mandatory */
72715 slobidx_t units; /* free units left in page */
72716 - unsigned long pad[2];
72717 + unsigned long pad[1];
72718 + unsigned long size; /* size when >=PAGE_SIZE */
72719 slob_t *free; /* first free slob_t in page */
72720 struct list_head list; /* linked list of free pages */
72721 };
72722 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72723 */
72724 static inline int is_slob_page(struct slob_page *sp)
72725 {
72726 - return PageSlab((struct page *)sp);
72727 + return PageSlab((struct page *)sp) && !sp->size;
72728 }
72729
72730 static inline void set_slob_page(struct slob_page *sp)
72731 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72732
72733 static inline struct slob_page *slob_page(const void *addr)
72734 {
72735 - return (struct slob_page *)virt_to_page(addr);
72736 + return (struct slob_page *)virt_to_head_page(addr);
72737 }
72738
72739 /*
72740 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72741 /*
72742 * Return the size of a slob block.
72743 */
72744 -static slobidx_t slob_units(slob_t *s)
72745 +static slobidx_t slob_units(const slob_t *s)
72746 {
72747 if (s->units > 0)
72748 return s->units;
72749 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72750 /*
72751 * Return the next free slob block pointer after this one.
72752 */
72753 -static slob_t *slob_next(slob_t *s)
72754 +static slob_t *slob_next(const slob_t *s)
72755 {
72756 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72757 slobidx_t next;
72758 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72759 /*
72760 * Returns true if s is the last free block in its page.
72761 */
72762 -static int slob_last(slob_t *s)
72763 +static int slob_last(const slob_t *s)
72764 {
72765 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72766 }
72767 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72768 if (!page)
72769 return NULL;
72770
72771 + set_slob_page(page);
72772 return page_address(page);
72773 }
72774
72775 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72776 if (!b)
72777 return NULL;
72778 sp = slob_page(b);
72779 - set_slob_page(sp);
72780
72781 spin_lock_irqsave(&slob_lock, flags);
72782 sp->units = SLOB_UNITS(PAGE_SIZE);
72783 sp->free = b;
72784 + sp->size = 0;
72785 INIT_LIST_HEAD(&sp->list);
72786 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72787 set_slob_page_free(sp, slob_list);
72788 @@ -476,10 +479,9 @@ out:
72789 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72790 */
72791
72792 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72793 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72794 {
72795 - unsigned int *m;
72796 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72797 + slob_t *m;
72798 void *ret;
72799
72800 gfp &= gfp_allowed_mask;
72801 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72802
72803 if (!m)
72804 return NULL;
72805 - *m = size;
72806 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72807 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72808 + m[0].units = size;
72809 + m[1].units = align;
72810 ret = (void *)m + align;
72811
72812 trace_kmalloc_node(_RET_IP_, ret,
72813 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72814 gfp |= __GFP_COMP;
72815 ret = slob_new_pages(gfp, order, node);
72816 if (ret) {
72817 - struct page *page;
72818 - page = virt_to_page(ret);
72819 - page->private = size;
72820 + struct slob_page *sp;
72821 + sp = slob_page(ret);
72822 + sp->size = size;
72823 }
72824
72825 trace_kmalloc_node(_RET_IP_, ret,
72826 size, PAGE_SIZE << order, gfp, node);
72827 }
72828
72829 - kmemleak_alloc(ret, size, 1, gfp);
72830 + return ret;
72831 +}
72832 +
72833 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72834 +{
72835 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72836 + void *ret = __kmalloc_node_align(size, gfp, node, align);
72837 +
72838 + if (!ZERO_OR_NULL_PTR(ret))
72839 + kmemleak_alloc(ret, size, 1, gfp);
72840 return ret;
72841 }
72842 EXPORT_SYMBOL(__kmalloc_node);
72843 @@ -533,13 +547,92 @@ void kfree(const void *block)
72844 sp = slob_page(block);
72845 if (is_slob_page(sp)) {
72846 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72847 - unsigned int *m = (unsigned int *)(block - align);
72848 - slob_free(m, *m + align);
72849 - } else
72850 + slob_t *m = (slob_t *)(block - align);
72851 + slob_free(m, m[0].units + align);
72852 + } else {
72853 + clear_slob_page(sp);
72854 + free_slob_page(sp);
72855 + sp->size = 0;
72856 put_page(&sp->page);
72857 + }
72858 }
72859 EXPORT_SYMBOL(kfree);
72860
72861 +void check_object_size(const void *ptr, unsigned long n, bool to)
72862 +{
72863 +
72864 +#ifdef CONFIG_PAX_USERCOPY
72865 + struct slob_page *sp;
72866 + const slob_t *free;
72867 + const void *base;
72868 + unsigned long flags;
72869 + const char *type;
72870 +
72871 + if (!n)
72872 + return;
72873 +
72874 + type = "<null>";
72875 + if (ZERO_OR_NULL_PTR(ptr))
72876 + goto report;
72877 +
72878 + if (!virt_addr_valid(ptr))
72879 + return;
72880 +
72881 + type = "<process stack>";
72882 + sp = slob_page(ptr);
72883 + if (!PageSlab((struct page *)sp)) {
72884 + if (object_is_on_stack(ptr, n) == -1)
72885 + goto report;
72886 + return;
72887 + }
72888 +
72889 + type = "<slob>";
72890 + if (sp->size) {
72891 + base = page_address(&sp->page);
72892 + if (base <= ptr && n <= sp->size - (ptr - base))
72893 + return;
72894 + goto report;
72895 + }
72896 +
72897 + /* some tricky double walking to find the chunk */
72898 + spin_lock_irqsave(&slob_lock, flags);
72899 + base = (void *)((unsigned long)ptr & PAGE_MASK);
72900 + free = sp->free;
72901 +
72902 + while (!slob_last(free) && (void *)free <= ptr) {
72903 + base = free + slob_units(free);
72904 + free = slob_next(free);
72905 + }
72906 +
72907 + while (base < (void *)free) {
72908 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72909 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
72910 + int offset;
72911 +
72912 + if (ptr < base + align)
72913 + break;
72914 +
72915 + offset = ptr - base - align;
72916 + if (offset >= m) {
72917 + base += size;
72918 + continue;
72919 + }
72920 +
72921 + if (n > m - offset)
72922 + break;
72923 +
72924 + spin_unlock_irqrestore(&slob_lock, flags);
72925 + return;
72926 + }
72927 +
72928 + spin_unlock_irqrestore(&slob_lock, flags);
72929 +report:
72930 + pax_report_usercopy(ptr, n, to, type);
72931 +#endif
72932 +
72933 +}
72934 +EXPORT_SYMBOL(check_object_size);
72935 +
72936 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
72937 size_t ksize(const void *block)
72938 {
72939 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
72940 sp = slob_page(block);
72941 if (is_slob_page(sp)) {
72942 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72943 - unsigned int *m = (unsigned int *)(block - align);
72944 - return SLOB_UNITS(*m) * SLOB_UNIT;
72945 + slob_t *m = (slob_t *)(block - align);
72946 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
72947 } else
72948 - return sp->page.private;
72949 + return sp->size;
72950 }
72951 EXPORT_SYMBOL(ksize);
72952
72953 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72954 {
72955 struct kmem_cache *c;
72956
72957 +#ifdef CONFIG_PAX_USERCOPY
72958 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
72959 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
72960 +#else
72961 c = slob_alloc(sizeof(struct kmem_cache),
72962 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
72963 +#endif
72964
72965 if (c) {
72966 c->name = name;
72967 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
72968
72969 lockdep_trace_alloc(flags);
72970
72971 +#ifdef CONFIG_PAX_USERCOPY
72972 + b = __kmalloc_node_align(c->size, flags, node, c->align);
72973 +#else
72974 if (c->size < PAGE_SIZE) {
72975 b = slob_alloc(c->size, flags, c->align, node);
72976 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72977 SLOB_UNITS(c->size) * SLOB_UNIT,
72978 flags, node);
72979 } else {
72980 + struct slob_page *sp;
72981 +
72982 b = slob_new_pages(flags, get_order(c->size), node);
72983 + sp = slob_page(b);
72984 + sp->size = c->size;
72985 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72986 PAGE_SIZE << get_order(c->size),
72987 flags, node);
72988 }
72989 +#endif
72990
72991 if (c->ctor)
72992 c->ctor(b);
72993 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
72994
72995 static void __kmem_cache_free(void *b, int size)
72996 {
72997 - if (size < PAGE_SIZE)
72998 + struct slob_page *sp = slob_page(b);
72999 +
73000 + if (is_slob_page(sp))
73001 slob_free(b, size);
73002 - else
73003 + else {
73004 + clear_slob_page(sp);
73005 + free_slob_page(sp);
73006 + sp->size = 0;
73007 slob_free_pages(b, get_order(size));
73008 + }
73009 }
73010
73011 static void kmem_rcu_free(struct rcu_head *head)
73012 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73013
73014 void kmem_cache_free(struct kmem_cache *c, void *b)
73015 {
73016 + int size = c->size;
73017 +
73018 +#ifdef CONFIG_PAX_USERCOPY
73019 + if (size + c->align < PAGE_SIZE) {
73020 + size += c->align;
73021 + b -= c->align;
73022 + }
73023 +#endif
73024 +
73025 kmemleak_free_recursive(b, c->flags);
73026 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73027 struct slob_rcu *slob_rcu;
73028 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73029 - slob_rcu->size = c->size;
73030 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73031 + slob_rcu->size = size;
73032 call_rcu(&slob_rcu->head, kmem_rcu_free);
73033 } else {
73034 - __kmem_cache_free(b, c->size);
73035 + __kmem_cache_free(b, size);
73036 }
73037
73038 +#ifdef CONFIG_PAX_USERCOPY
73039 + trace_kfree(_RET_IP_, b);
73040 +#else
73041 trace_kmem_cache_free(_RET_IP_, b);
73042 +#endif
73043 +
73044 }
73045 EXPORT_SYMBOL(kmem_cache_free);
73046
73047 diff --git a/mm/slub.c b/mm/slub.c
73048 index 1a919f0..1739c9b 100644
73049 --- a/mm/slub.c
73050 +++ b/mm/slub.c
73051 @@ -208,7 +208,7 @@ struct track {
73052
73053 enum track_item { TRACK_ALLOC, TRACK_FREE };
73054
73055 -#ifdef CONFIG_SYSFS
73056 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73057 static int sysfs_slab_add(struct kmem_cache *);
73058 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73059 static void sysfs_slab_remove(struct kmem_cache *);
73060 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
73061 if (!t->addr)
73062 return;
73063
73064 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73065 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73066 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73067 #ifdef CONFIG_STACKTRACE
73068 {
73069 @@ -2559,6 +2559,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73070
73071 page = virt_to_head_page(x);
73072
73073 + BUG_ON(!PageSlab(page));
73074 +
73075 slab_free(s, page, x, _RET_IP_);
73076
73077 trace_kmem_cache_free(_RET_IP_, x);
73078 @@ -2592,7 +2594,7 @@ static int slub_min_objects;
73079 * Merge control. If this is set then no merging of slab caches will occur.
73080 * (Could be removed. This was introduced to pacify the merge skeptics.)
73081 */
73082 -static int slub_nomerge;
73083 +static int slub_nomerge = 1;
73084
73085 /*
73086 * Calculate the order of allocation given an slab object size.
73087 @@ -3042,7 +3044,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73088 else
73089 s->cpu_partial = 30;
73090
73091 - s->refcount = 1;
73092 + atomic_set(&s->refcount, 1);
73093 #ifdef CONFIG_NUMA
73094 s->remote_node_defrag_ratio = 1000;
73095 #endif
73096 @@ -3146,8 +3148,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73097 void kmem_cache_destroy(struct kmem_cache *s)
73098 {
73099 down_write(&slub_lock);
73100 - s->refcount--;
73101 - if (!s->refcount) {
73102 + if (atomic_dec_and_test(&s->refcount)) {
73103 list_del(&s->list);
73104 up_write(&slub_lock);
73105 if (kmem_cache_close(s)) {
73106 @@ -3358,6 +3359,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73107 EXPORT_SYMBOL(__kmalloc_node);
73108 #endif
73109
73110 +void check_object_size(const void *ptr, unsigned long n, bool to)
73111 +{
73112 +
73113 +#ifdef CONFIG_PAX_USERCOPY
73114 + struct page *page;
73115 + struct kmem_cache *s = NULL;
73116 + unsigned long offset;
73117 + const char *type;
73118 +
73119 + if (!n)
73120 + return;
73121 +
73122 + type = "<null>";
73123 + if (ZERO_OR_NULL_PTR(ptr))
73124 + goto report;
73125 +
73126 + if (!virt_addr_valid(ptr))
73127 + return;
73128 +
73129 + page = virt_to_head_page(ptr);
73130 +
73131 + type = "<process stack>";
73132 + if (!PageSlab(page)) {
73133 + if (object_is_on_stack(ptr, n) == -1)
73134 + goto report;
73135 + return;
73136 + }
73137 +
73138 + s = page->slab;
73139 + type = s->name;
73140 + if (!(s->flags & SLAB_USERCOPY))
73141 + goto report;
73142 +
73143 + offset = (ptr - page_address(page)) % s->size;
73144 + if (offset <= s->objsize && n <= s->objsize - offset)
73145 + return;
73146 +
73147 +report:
73148 + pax_report_usercopy(ptr, n, to, type);
73149 +#endif
73150 +
73151 +}
73152 +EXPORT_SYMBOL(check_object_size);
73153 +
73154 size_t ksize(const void *object)
73155 {
73156 struct page *page;
73157 @@ -3632,7 +3677,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73158 int node;
73159
73160 list_add(&s->list, &slab_caches);
73161 - s->refcount = -1;
73162 + atomic_set(&s->refcount, -1);
73163
73164 for_each_node_state(node, N_NORMAL_MEMORY) {
73165 struct kmem_cache_node *n = get_node(s, node);
73166 @@ -3749,17 +3794,17 @@ void __init kmem_cache_init(void)
73167
73168 /* Caches that are not of the two-to-the-power-of size */
73169 if (KMALLOC_MIN_SIZE <= 32) {
73170 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73171 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73172 caches++;
73173 }
73174
73175 if (KMALLOC_MIN_SIZE <= 64) {
73176 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73177 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73178 caches++;
73179 }
73180
73181 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73182 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73183 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73184 caches++;
73185 }
73186
73187 @@ -3827,7 +3872,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73188 /*
73189 * We may have set a slab to be unmergeable during bootstrap.
73190 */
73191 - if (s->refcount < 0)
73192 + if (atomic_read(&s->refcount) < 0)
73193 return 1;
73194
73195 return 0;
73196 @@ -3886,7 +3931,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73197 down_write(&slub_lock);
73198 s = find_mergeable(size, align, flags, name, ctor);
73199 if (s) {
73200 - s->refcount++;
73201 + atomic_inc(&s->refcount);
73202 /*
73203 * Adjust the object sizes so that we clear
73204 * the complete object on kzalloc.
73205 @@ -3895,7 +3940,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73206 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73207
73208 if (sysfs_slab_alias(s, name)) {
73209 - s->refcount--;
73210 + atomic_dec(&s->refcount);
73211 goto err;
73212 }
73213 up_write(&slub_lock);
73214 @@ -4023,7 +4068,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73215 }
73216 #endif
73217
73218 -#ifdef CONFIG_SYSFS
73219 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73220 static int count_inuse(struct page *page)
73221 {
73222 return page->inuse;
73223 @@ -4410,12 +4455,12 @@ static void resiliency_test(void)
73224 validate_slab_cache(kmalloc_caches[9]);
73225 }
73226 #else
73227 -#ifdef CONFIG_SYSFS
73228 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73229 static void resiliency_test(void) {};
73230 #endif
73231 #endif
73232
73233 -#ifdef CONFIG_SYSFS
73234 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73235 enum slab_stat_type {
73236 SL_ALL, /* All slabs */
73237 SL_PARTIAL, /* Only partially allocated slabs */
73238 @@ -4656,7 +4701,7 @@ SLAB_ATTR_RO(ctor);
73239
73240 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73241 {
73242 - return sprintf(buf, "%d\n", s->refcount - 1);
73243 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73244 }
73245 SLAB_ATTR_RO(aliases);
73246
73247 @@ -5223,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
73248 return name;
73249 }
73250
73251 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73252 static int sysfs_slab_add(struct kmem_cache *s)
73253 {
73254 int err;
73255 @@ -5285,6 +5331,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73256 kobject_del(&s->kobj);
73257 kobject_put(&s->kobj);
73258 }
73259 +#endif
73260
73261 /*
73262 * Need to buffer aliases during bootup until sysfs becomes
73263 @@ -5298,6 +5345,7 @@ struct saved_alias {
73264
73265 static struct saved_alias *alias_list;
73266
73267 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73268 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73269 {
73270 struct saved_alias *al;
73271 @@ -5320,6 +5368,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73272 alias_list = al;
73273 return 0;
73274 }
73275 +#endif
73276
73277 static int __init slab_sysfs_init(void)
73278 {
73279 diff --git a/mm/swap.c b/mm/swap.c
73280 index 55b266d..a532537 100644
73281 --- a/mm/swap.c
73282 +++ b/mm/swap.c
73283 @@ -31,6 +31,7 @@
73284 #include <linux/backing-dev.h>
73285 #include <linux/memcontrol.h>
73286 #include <linux/gfp.h>
73287 +#include <linux/hugetlb.h>
73288
73289 #include "internal.h"
73290
73291 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
73292
73293 __page_cache_release(page);
73294 dtor = get_compound_page_dtor(page);
73295 + if (!PageHuge(page))
73296 + BUG_ON(dtor != free_compound_page);
73297 (*dtor)(page);
73298 }
73299
73300 diff --git a/mm/swapfile.c b/mm/swapfile.c
73301 index b1cd120..aaae885 100644
73302 --- a/mm/swapfile.c
73303 +++ b/mm/swapfile.c
73304 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
73305
73306 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
73307 /* Activity counter to indicate that a swapon or swapoff has occurred */
73308 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
73309 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
73310
73311 static inline unsigned char swap_count(unsigned char ent)
73312 {
73313 @@ -1670,7 +1670,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
73314 }
73315 filp_close(swap_file, NULL);
73316 err = 0;
73317 - atomic_inc(&proc_poll_event);
73318 + atomic_inc_unchecked(&proc_poll_event);
73319 wake_up_interruptible(&proc_poll_wait);
73320
73321 out_dput:
73322 @@ -1686,8 +1686,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
73323
73324 poll_wait(file, &proc_poll_wait, wait);
73325
73326 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
73327 - seq->poll_event = atomic_read(&proc_poll_event);
73328 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
73329 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73330 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
73331 }
73332
73333 @@ -1785,7 +1785,7 @@ static int swaps_open(struct inode *inode, struct file *file)
73334 return ret;
73335
73336 seq = file->private_data;
73337 - seq->poll_event = atomic_read(&proc_poll_event);
73338 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73339 return 0;
73340 }
73341
73342 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
73343 (p->flags & SWP_DISCARDABLE) ? "D" : "");
73344
73345 mutex_unlock(&swapon_mutex);
73346 - atomic_inc(&proc_poll_event);
73347 + atomic_inc_unchecked(&proc_poll_event);
73348 wake_up_interruptible(&proc_poll_wait);
73349
73350 if (S_ISREG(inode->i_mode))
73351 diff --git a/mm/util.c b/mm/util.c
73352 index 136ac4f..5117eef 100644
73353 --- a/mm/util.c
73354 +++ b/mm/util.c
73355 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
73356 * allocated buffer. Use this if you don't want to free the buffer immediately
73357 * like, for example, with RCU.
73358 */
73359 +#undef __krealloc
73360 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
73361 {
73362 void *ret;
73363 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
73364 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
73365 * %NULL pointer, the object pointed to is freed.
73366 */
73367 +#undef krealloc
73368 void *krealloc(const void *p, size_t new_size, gfp_t flags)
73369 {
73370 void *ret;
73371 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
73372 void arch_pick_mmap_layout(struct mm_struct *mm)
73373 {
73374 mm->mmap_base = TASK_UNMAPPED_BASE;
73375 +
73376 +#ifdef CONFIG_PAX_RANDMMAP
73377 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73378 + mm->mmap_base += mm->delta_mmap;
73379 +#endif
73380 +
73381 mm->get_unmapped_area = arch_get_unmapped_area;
73382 mm->unmap_area = arch_unmap_area;
73383 }
73384 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
73385 index 27be2f0..0aef2c2 100644
73386 --- a/mm/vmalloc.c
73387 +++ b/mm/vmalloc.c
73388 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
73389
73390 pte = pte_offset_kernel(pmd, addr);
73391 do {
73392 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73393 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73394 +
73395 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73396 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
73397 + BUG_ON(!pte_exec(*pte));
73398 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
73399 + continue;
73400 + }
73401 +#endif
73402 +
73403 + {
73404 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73405 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73406 + }
73407 } while (pte++, addr += PAGE_SIZE, addr != end);
73408 }
73409
73410 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73411 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
73412 {
73413 pte_t *pte;
73414 + int ret = -ENOMEM;
73415
73416 /*
73417 * nr is a running index into the array which helps higher level
73418 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73419 pte = pte_alloc_kernel(pmd, addr);
73420 if (!pte)
73421 return -ENOMEM;
73422 +
73423 + pax_open_kernel();
73424 do {
73425 struct page *page = pages[*nr];
73426
73427 - if (WARN_ON(!pte_none(*pte)))
73428 - return -EBUSY;
73429 - if (WARN_ON(!page))
73430 - return -ENOMEM;
73431 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73432 + if (pgprot_val(prot) & _PAGE_NX)
73433 +#endif
73434 +
73435 + if (WARN_ON(!pte_none(*pte))) {
73436 + ret = -EBUSY;
73437 + goto out;
73438 + }
73439 + if (WARN_ON(!page)) {
73440 + ret = -ENOMEM;
73441 + goto out;
73442 + }
73443 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
73444 (*nr)++;
73445 } while (pte++, addr += PAGE_SIZE, addr != end);
73446 - return 0;
73447 + ret = 0;
73448 +out:
73449 + pax_close_kernel();
73450 + return ret;
73451 }
73452
73453 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73454 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
73455 * and fall back on vmalloc() if that fails. Others
73456 * just put it in the vmalloc space.
73457 */
73458 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
73459 +#ifdef CONFIG_MODULES
73460 +#ifdef MODULES_VADDR
73461 unsigned long addr = (unsigned long)x;
73462 if (addr >= MODULES_VADDR && addr < MODULES_END)
73463 return 1;
73464 #endif
73465 +
73466 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73467 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
73468 + return 1;
73469 +#endif
73470 +
73471 +#endif
73472 +
73473 return is_vmalloc_addr(x);
73474 }
73475
73476 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
73477
73478 if (!pgd_none(*pgd)) {
73479 pud_t *pud = pud_offset(pgd, addr);
73480 +#ifdef CONFIG_X86
73481 + if (!pud_large(*pud))
73482 +#endif
73483 if (!pud_none(*pud)) {
73484 pmd_t *pmd = pmd_offset(pud, addr);
73485 +#ifdef CONFIG_X86
73486 + if (!pmd_large(*pmd))
73487 +#endif
73488 if (!pmd_none(*pmd)) {
73489 pte_t *ptep, pte;
73490
73491 @@ -1294,6 +1334,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
73492 struct vm_struct *area;
73493
73494 BUG_ON(in_interrupt());
73495 +
73496 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73497 + if (flags & VM_KERNEXEC) {
73498 + if (start != VMALLOC_START || end != VMALLOC_END)
73499 + return NULL;
73500 + start = (unsigned long)MODULES_EXEC_VADDR;
73501 + end = (unsigned long)MODULES_EXEC_END;
73502 + }
73503 +#endif
73504 +
73505 if (flags & VM_IOREMAP) {
73506 int bit = fls(size);
73507
73508 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
73509 if (count > totalram_pages)
73510 return NULL;
73511
73512 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73513 + if (!(pgprot_val(prot) & _PAGE_NX))
73514 + flags |= VM_KERNEXEC;
73515 +#endif
73516 +
73517 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73518 __builtin_return_address(0));
73519 if (!area)
73520 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73521 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73522 goto fail;
73523
73524 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73525 + if (!(pgprot_val(prot) & _PAGE_NX))
73526 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73527 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73528 + else
73529 +#endif
73530 +
73531 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73532 start, end, node, gfp_mask, caller);
73533 if (!area)
73534 @@ -1679,6 +1741,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
73535 gfp_mask, prot, node, caller);
73536 }
73537
73538 +#undef __vmalloc
73539 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
73540 {
73541 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
73542 @@ -1702,6 +1765,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
73543 * For tight control over page level allocator and protection flags
73544 * use __vmalloc() instead.
73545 */
73546 +#undef vmalloc
73547 void *vmalloc(unsigned long size)
73548 {
73549 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
73550 @@ -1718,6 +1782,7 @@ EXPORT_SYMBOL(vmalloc);
73551 * For tight control over page level allocator and protection flags
73552 * use __vmalloc() instead.
73553 */
73554 +#undef vzalloc
73555 void *vzalloc(unsigned long size)
73556 {
73557 return __vmalloc_node_flags(size, -1,
73558 @@ -1732,6 +1797,7 @@ EXPORT_SYMBOL(vzalloc);
73559 * The resulting memory area is zeroed so it can be mapped to userspace
73560 * without leaking data.
73561 */
73562 +#undef vmalloc_user
73563 void *vmalloc_user(unsigned long size)
73564 {
73565 struct vm_struct *area;
73566 @@ -1759,6 +1825,7 @@ EXPORT_SYMBOL(vmalloc_user);
73567 * For tight control over page level allocator and protection flags
73568 * use __vmalloc() instead.
73569 */
73570 +#undef vmalloc_node
73571 void *vmalloc_node(unsigned long size, int node)
73572 {
73573 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
73574 @@ -1778,6 +1845,7 @@ EXPORT_SYMBOL(vmalloc_node);
73575 * For tight control over page level allocator and protection flags
73576 * use __vmalloc_node() instead.
73577 */
73578 +#undef vzalloc_node
73579 void *vzalloc_node(unsigned long size, int node)
73580 {
73581 return __vmalloc_node_flags(size, node,
73582 @@ -1800,10 +1868,10 @@ EXPORT_SYMBOL(vzalloc_node);
73583 * For tight control over page level allocator and protection flags
73584 * use __vmalloc() instead.
73585 */
73586 -
73587 +#undef vmalloc_exec
73588 void *vmalloc_exec(unsigned long size)
73589 {
73590 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73591 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73592 -1, __builtin_return_address(0));
73593 }
73594
73595 @@ -1822,6 +1890,7 @@ void *vmalloc_exec(unsigned long size)
73596 * Allocate enough 32bit PA addressable pages to cover @size from the
73597 * page level allocator and map them into contiguous kernel virtual space.
73598 */
73599 +#undef vmalloc_32
73600 void *vmalloc_32(unsigned long size)
73601 {
73602 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
73603 @@ -1836,6 +1905,7 @@ EXPORT_SYMBOL(vmalloc_32);
73604 * The resulting memory area is 32bit addressable and zeroed so it can be
73605 * mapped to userspace without leaking data.
73606 */
73607 +#undef vmalloc_32_user
73608 void *vmalloc_32_user(unsigned long size)
73609 {
73610 struct vm_struct *area;
73611 @@ -2098,6 +2168,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73612 unsigned long uaddr = vma->vm_start;
73613 unsigned long usize = vma->vm_end - vma->vm_start;
73614
73615 + BUG_ON(vma->vm_mirror);
73616 +
73617 if ((PAGE_SIZE-1) & (unsigned long)addr)
73618 return -EINVAL;
73619
73620 diff --git a/mm/vmstat.c b/mm/vmstat.c
73621 index 8fd603b..cf0d930 100644
73622 --- a/mm/vmstat.c
73623 +++ b/mm/vmstat.c
73624 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73625 *
73626 * vm_stat contains the global counters
73627 */
73628 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73629 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73630 EXPORT_SYMBOL(vm_stat);
73631
73632 #ifdef CONFIG_SMP
73633 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73634 v = p->vm_stat_diff[i];
73635 p->vm_stat_diff[i] = 0;
73636 local_irq_restore(flags);
73637 - atomic_long_add(v, &zone->vm_stat[i]);
73638 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73639 global_diff[i] += v;
73640 #ifdef CONFIG_NUMA
73641 /* 3 seconds idle till flush */
73642 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73643
73644 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73645 if (global_diff[i])
73646 - atomic_long_add(global_diff[i], &vm_stat[i]);
73647 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73648 }
73649
73650 #endif
73651 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73652 start_cpu_timer(cpu);
73653 #endif
73654 #ifdef CONFIG_PROC_FS
73655 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73656 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73657 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73658 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73659 + {
73660 + mode_t gr_mode = S_IRUGO;
73661 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73662 + gr_mode = S_IRUSR;
73663 +#endif
73664 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73665 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73666 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73667 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73668 +#else
73669 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73670 +#endif
73671 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73672 + }
73673 #endif
73674 return 0;
73675 }
73676 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73677 index 5471628..cef8398 100644
73678 --- a/net/8021q/vlan.c
73679 +++ b/net/8021q/vlan.c
73680 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73681 err = -EPERM;
73682 if (!capable(CAP_NET_ADMIN))
73683 break;
73684 - if ((args.u.name_type >= 0) &&
73685 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73686 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73687 struct vlan_net *vn;
73688
73689 vn = net_generic(net, vlan_net_id);
73690 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73691 index fdfdb57..38d368c 100644
73692 --- a/net/9p/trans_fd.c
73693 +++ b/net/9p/trans_fd.c
73694 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73695 oldfs = get_fs();
73696 set_fs(get_ds());
73697 /* The cast to a user pointer is valid due to the set_fs() */
73698 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73699 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73700 set_fs(oldfs);
73701
73702 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73703 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73704 index f41f026..fe76ea8 100644
73705 --- a/net/atm/atm_misc.c
73706 +++ b/net/atm/atm_misc.c
73707 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73708 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73709 return 1;
73710 atm_return(vcc, truesize);
73711 - atomic_inc(&vcc->stats->rx_drop);
73712 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73713 return 0;
73714 }
73715 EXPORT_SYMBOL(atm_charge);
73716 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73717 }
73718 }
73719 atm_return(vcc, guess);
73720 - atomic_inc(&vcc->stats->rx_drop);
73721 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73722 return NULL;
73723 }
73724 EXPORT_SYMBOL(atm_alloc_charge);
73725 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73726
73727 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73728 {
73729 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73730 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73731 __SONET_ITEMS
73732 #undef __HANDLE_ITEM
73733 }
73734 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73735
73736 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73737 {
73738 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73739 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73740 __SONET_ITEMS
73741 #undef __HANDLE_ITEM
73742 }
73743 diff --git a/net/atm/lec.h b/net/atm/lec.h
73744 index dfc0719..47c5322 100644
73745 --- a/net/atm/lec.h
73746 +++ b/net/atm/lec.h
73747 @@ -48,7 +48,7 @@ struct lane2_ops {
73748 const u8 *tlvs, u32 sizeoftlvs);
73749 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73750 const u8 *tlvs, u32 sizeoftlvs);
73751 -};
73752 +} __no_const;
73753
73754 /*
73755 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73756 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73757 index 0919a88..a23d54e 100644
73758 --- a/net/atm/mpc.h
73759 +++ b/net/atm/mpc.h
73760 @@ -33,7 +33,7 @@ struct mpoa_client {
73761 struct mpc_parameters parameters; /* parameters for this client */
73762
73763 const struct net_device_ops *old_ops;
73764 - struct net_device_ops new_ops;
73765 + net_device_ops_no_const new_ops;
73766 };
73767
73768
73769 diff --git a/net/atm/proc.c b/net/atm/proc.c
73770 index 0d020de..011c7bb 100644
73771 --- a/net/atm/proc.c
73772 +++ b/net/atm/proc.c
73773 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73774 const struct k_atm_aal_stats *stats)
73775 {
73776 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73777 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73778 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73779 - atomic_read(&stats->rx_drop));
73780 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73781 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73782 + atomic_read_unchecked(&stats->rx_drop));
73783 }
73784
73785 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73786 diff --git a/net/atm/resources.c b/net/atm/resources.c
73787 index 23f45ce..c748f1a 100644
73788 --- a/net/atm/resources.c
73789 +++ b/net/atm/resources.c
73790 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73791 static void copy_aal_stats(struct k_atm_aal_stats *from,
73792 struct atm_aal_stats *to)
73793 {
73794 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73795 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73796 __AAL_STAT_ITEMS
73797 #undef __HANDLE_ITEM
73798 }
73799 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73800 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73801 struct atm_aal_stats *to)
73802 {
73803 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73804 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73805 __AAL_STAT_ITEMS
73806 #undef __HANDLE_ITEM
73807 }
73808 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73809 index 3512e25..2b33401 100644
73810 --- a/net/batman-adv/bat_iv_ogm.c
73811 +++ b/net/batman-adv/bat_iv_ogm.c
73812 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73813
73814 /* change sequence number to network order */
73815 batman_ogm_packet->seqno =
73816 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
73817 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73818
73819 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73820 batman_ogm_packet->tt_crc = htons((uint16_t)
73821 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73822 else
73823 batman_ogm_packet->gw_flags = NO_FLAGS;
73824
73825 - atomic_inc(&hard_iface->seqno);
73826 + atomic_inc_unchecked(&hard_iface->seqno);
73827
73828 slide_own_bcast_window(hard_iface);
73829 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73830 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
73831 return;
73832
73833 /* could be changed by schedule_own_packet() */
73834 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
73835 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73836
73837 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73838
73839 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73840 index 7704df4..beb4e16 100644
73841 --- a/net/batman-adv/hard-interface.c
73842 +++ b/net/batman-adv/hard-interface.c
73843 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73844 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73845 dev_add_pack(&hard_iface->batman_adv_ptype);
73846
73847 - atomic_set(&hard_iface->seqno, 1);
73848 - atomic_set(&hard_iface->frag_seqno, 1);
73849 + atomic_set_unchecked(&hard_iface->seqno, 1);
73850 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73851 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73852 hard_iface->net_dev->name);
73853
73854 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73855 index f9cc957..efd9dae 100644
73856 --- a/net/batman-adv/soft-interface.c
73857 +++ b/net/batman-adv/soft-interface.c
73858 @@ -634,7 +634,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73859
73860 /* set broadcast sequence number */
73861 bcast_packet->seqno =
73862 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73863 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73864
73865 add_bcast_packet_to_list(bat_priv, skb, 1);
73866
73867 @@ -828,7 +828,7 @@ struct net_device *softif_create(const char *name)
73868 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73869
73870 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73871 - atomic_set(&bat_priv->bcast_seqno, 1);
73872 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73873 atomic_set(&bat_priv->ttvn, 0);
73874 atomic_set(&bat_priv->tt_local_changes, 0);
73875 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73876 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73877 index ab8d0fe..ceba3fd 100644
73878 --- a/net/batman-adv/types.h
73879 +++ b/net/batman-adv/types.h
73880 @@ -38,8 +38,8 @@ struct hard_iface {
73881 int16_t if_num;
73882 char if_status;
73883 struct net_device *net_dev;
73884 - atomic_t seqno;
73885 - atomic_t frag_seqno;
73886 + atomic_unchecked_t seqno;
73887 + atomic_unchecked_t frag_seqno;
73888 unsigned char *packet_buff;
73889 int packet_len;
73890 struct kobject *hardif_obj;
73891 @@ -154,7 +154,7 @@ struct bat_priv {
73892 atomic_t orig_interval; /* uint */
73893 atomic_t hop_penalty; /* uint */
73894 atomic_t log_level; /* uint */
73895 - atomic_t bcast_seqno;
73896 + atomic_unchecked_t bcast_seqno;
73897 atomic_t bcast_queue_left;
73898 atomic_t batman_queue_left;
73899 atomic_t ttvn; /* translation table version number */
73900 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73901 index 07d1c1d..7e9bea9 100644
73902 --- a/net/batman-adv/unicast.c
73903 +++ b/net/batman-adv/unicast.c
73904 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73905 frag1->flags = UNI_FRAG_HEAD | large_tail;
73906 frag2->flags = large_tail;
73907
73908 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73909 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73910 frag1->seqno = htons(seqno - 1);
73911 frag2->seqno = htons(seqno);
73912
73913 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73914 index c1c597e..05ebb40 100644
73915 --- a/net/bluetooth/hci_conn.c
73916 +++ b/net/bluetooth/hci_conn.c
73917 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73918 memset(&cp, 0, sizeof(cp));
73919
73920 cp.handle = cpu_to_le16(conn->handle);
73921 - memcpy(cp.ltk, ltk, sizeof(ltk));
73922 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73923
73924 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73925 }
73926 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73927 index 17b5b1c..826d872 100644
73928 --- a/net/bluetooth/l2cap_core.c
73929 +++ b/net/bluetooth/l2cap_core.c
73930 @@ -2176,8 +2176,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73931 break;
73932
73933 case L2CAP_CONF_RFC:
73934 - if (olen == sizeof(rfc))
73935 - memcpy(&rfc, (void *)val, olen);
73936 + if (olen != sizeof(rfc))
73937 + break;
73938 +
73939 + memcpy(&rfc, (void *)val, olen);
73940
73941 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73942 rfc.mode != chan->mode)
73943 @@ -2265,8 +2267,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73944
73945 switch (type) {
73946 case L2CAP_CONF_RFC:
73947 - if (olen == sizeof(rfc))
73948 - memcpy(&rfc, (void *)val, olen);
73949 + if (olen != sizeof(rfc))
73950 + break;
73951 +
73952 + memcpy(&rfc, (void *)val, olen);
73953 goto done;
73954 }
73955 }
73956 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
73957 index a5f4e57..910ee6d 100644
73958 --- a/net/bridge/br_multicast.c
73959 +++ b/net/bridge/br_multicast.c
73960 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
73961 nexthdr = ip6h->nexthdr;
73962 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
73963
73964 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
73965 + if (nexthdr != IPPROTO_ICMPV6)
73966 return 0;
73967
73968 /* Okay, we found ICMPv6 header */
73969 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
73970 index 5864cc4..121f3a30 100644
73971 --- a/net/bridge/netfilter/ebtables.c
73972 +++ b/net/bridge/netfilter/ebtables.c
73973 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
73974 tmp.valid_hooks = t->table->valid_hooks;
73975 }
73976 mutex_unlock(&ebt_mutex);
73977 - if (copy_to_user(user, &tmp, *len) != 0){
73978 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
73979 BUGPRINT("c2u Didn't work\n");
73980 ret = -EFAULT;
73981 break;
73982 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
73983 index a986280..13444a1 100644
73984 --- a/net/caif/caif_socket.c
73985 +++ b/net/caif/caif_socket.c
73986 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
73987 #ifdef CONFIG_DEBUG_FS
73988 struct debug_fs_counter {
73989 atomic_t caif_nr_socks;
73990 - atomic_t caif_sock_create;
73991 - atomic_t num_connect_req;
73992 - atomic_t num_connect_resp;
73993 - atomic_t num_connect_fail_resp;
73994 - atomic_t num_disconnect;
73995 - atomic_t num_remote_shutdown_ind;
73996 - atomic_t num_tx_flow_off_ind;
73997 - atomic_t num_tx_flow_on_ind;
73998 - atomic_t num_rx_flow_off;
73999 - atomic_t num_rx_flow_on;
74000 + atomic_unchecked_t caif_sock_create;
74001 + atomic_unchecked_t num_connect_req;
74002 + atomic_unchecked_t num_connect_resp;
74003 + atomic_unchecked_t num_connect_fail_resp;
74004 + atomic_unchecked_t num_disconnect;
74005 + atomic_unchecked_t num_remote_shutdown_ind;
74006 + atomic_unchecked_t num_tx_flow_off_ind;
74007 + atomic_unchecked_t num_tx_flow_on_ind;
74008 + atomic_unchecked_t num_rx_flow_off;
74009 + atomic_unchecked_t num_rx_flow_on;
74010 };
74011 static struct debug_fs_counter cnt;
74012 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74013 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74014 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74015 #else
74016 #define dbfs_atomic_inc(v) 0
74017 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74018 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74019 sk_rcvbuf_lowwater(cf_sk));
74020 set_rx_flow_off(cf_sk);
74021 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74022 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74023 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74024 }
74025
74026 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74027 set_rx_flow_off(cf_sk);
74028 if (net_ratelimit())
74029 pr_debug("sending flow OFF due to rmem_schedule\n");
74030 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74031 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74032 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74033 }
74034 skb->dev = NULL;
74035 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74036 switch (flow) {
74037 case CAIF_CTRLCMD_FLOW_ON_IND:
74038 /* OK from modem to start sending again */
74039 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74040 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74041 set_tx_flow_on(cf_sk);
74042 cf_sk->sk.sk_state_change(&cf_sk->sk);
74043 break;
74044
74045 case CAIF_CTRLCMD_FLOW_OFF_IND:
74046 /* Modem asks us to shut up */
74047 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74048 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74049 set_tx_flow_off(cf_sk);
74050 cf_sk->sk.sk_state_change(&cf_sk->sk);
74051 break;
74052 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74053 /* We're now connected */
74054 caif_client_register_refcnt(&cf_sk->layer,
74055 cfsk_hold, cfsk_put);
74056 - dbfs_atomic_inc(&cnt.num_connect_resp);
74057 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74058 cf_sk->sk.sk_state = CAIF_CONNECTED;
74059 set_tx_flow_on(cf_sk);
74060 cf_sk->sk.sk_state_change(&cf_sk->sk);
74061 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74062
74063 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74064 /* Connect request failed */
74065 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74066 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74067 cf_sk->sk.sk_err = ECONNREFUSED;
74068 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74069 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74070 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74071
74072 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74073 /* Modem has closed this connection, or device is down. */
74074 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74075 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74076 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74077 cf_sk->sk.sk_err = ECONNRESET;
74078 set_rx_flow_on(cf_sk);
74079 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74080 return;
74081
74082 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74083 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
74084 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74085 set_rx_flow_on(cf_sk);
74086 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74087 }
74088 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74089 /*ifindex = id of the interface.*/
74090 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74091
74092 - dbfs_atomic_inc(&cnt.num_connect_req);
74093 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74094 cf_sk->layer.receive = caif_sktrecv_cb;
74095
74096 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74097 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
74098 spin_unlock_bh(&sk->sk_receive_queue.lock);
74099 sock->sk = NULL;
74100
74101 - dbfs_atomic_inc(&cnt.num_disconnect);
74102 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74103
74104 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74105 if (cf_sk->debugfs_socket_dir != NULL)
74106 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74107 cf_sk->conn_req.protocol = protocol;
74108 /* Increase the number of sockets created. */
74109 dbfs_atomic_inc(&cnt.caif_nr_socks);
74110 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
74111 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74112 #ifdef CONFIG_DEBUG_FS
74113 if (!IS_ERR(debugfsdir)) {
74114
74115 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74116 index 5cf5222..6f704ad 100644
74117 --- a/net/caif/cfctrl.c
74118 +++ b/net/caif/cfctrl.c
74119 @@ -9,6 +9,7 @@
74120 #include <linux/stddef.h>
74121 #include <linux/spinlock.h>
74122 #include <linux/slab.h>
74123 +#include <linux/sched.h>
74124 #include <net/caif/caif_layer.h>
74125 #include <net/caif/cfpkt.h>
74126 #include <net/caif/cfctrl.h>
74127 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74128 memset(&dev_info, 0, sizeof(dev_info));
74129 dev_info.id = 0xff;
74130 cfsrvl_init(&this->serv, 0, &dev_info, false);
74131 - atomic_set(&this->req_seq_no, 1);
74132 - atomic_set(&this->rsp_seq_no, 1);
74133 + atomic_set_unchecked(&this->req_seq_no, 1);
74134 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74135 this->serv.layer.receive = cfctrl_recv;
74136 sprintf(this->serv.layer.name, "ctrl");
74137 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74138 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74139 struct cfctrl_request_info *req)
74140 {
74141 spin_lock_bh(&ctrl->info_list_lock);
74142 - atomic_inc(&ctrl->req_seq_no);
74143 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74144 + atomic_inc_unchecked(&ctrl->req_seq_no);
74145 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74146 list_add_tail(&req->list, &ctrl->list);
74147 spin_unlock_bh(&ctrl->info_list_lock);
74148 }
74149 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74150 if (p != first)
74151 pr_warn("Requests are not received in order\n");
74152
74153 - atomic_set(&ctrl->rsp_seq_no,
74154 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74155 p->sequence_no);
74156 list_del(&p->list);
74157 goto out;
74158 diff --git a/net/can/gw.c b/net/can/gw.c
74159 index 3d79b12..8de85fa 100644
74160 --- a/net/can/gw.c
74161 +++ b/net/can/gw.c
74162 @@ -96,7 +96,7 @@ struct cf_mod {
74163 struct {
74164 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74165 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74166 - } csumfunc;
74167 + } __no_const csumfunc;
74168 };
74169
74170
74171 diff --git a/net/compat.c b/net/compat.c
74172 index 6def90e..c6992fa 100644
74173 --- a/net/compat.c
74174 +++ b/net/compat.c
74175 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74176 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74177 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74178 return -EFAULT;
74179 - kmsg->msg_name = compat_ptr(tmp1);
74180 - kmsg->msg_iov = compat_ptr(tmp2);
74181 - kmsg->msg_control = compat_ptr(tmp3);
74182 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74183 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74184 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74185 return 0;
74186 }
74187
74188 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74189
74190 if (kern_msg->msg_namelen) {
74191 if (mode == VERIFY_READ) {
74192 - int err = move_addr_to_kernel(kern_msg->msg_name,
74193 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74194 kern_msg->msg_namelen,
74195 kern_address);
74196 if (err < 0)
74197 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74198 kern_msg->msg_name = NULL;
74199
74200 tot_len = iov_from_user_compat_to_kern(kern_iov,
74201 - (struct compat_iovec __user *)kern_msg->msg_iov,
74202 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74203 kern_msg->msg_iovlen);
74204 if (tot_len >= 0)
74205 kern_msg->msg_iov = kern_iov;
74206 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74207
74208 #define CMSG_COMPAT_FIRSTHDR(msg) \
74209 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74210 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74211 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74212 (struct compat_cmsghdr __user *)NULL)
74213
74214 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74215 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74216 (ucmlen) <= (unsigned long) \
74217 ((mhdr)->msg_controllen - \
74218 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74219 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74220
74221 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74222 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74223 {
74224 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74225 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74226 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74227 msg->msg_controllen)
74228 return NULL;
74229 return (struct compat_cmsghdr __user *)ptr;
74230 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74231 {
74232 struct compat_timeval ctv;
74233 struct compat_timespec cts[3];
74234 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74235 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74236 struct compat_cmsghdr cmhdr;
74237 int cmlen;
74238
74239 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74240
74241 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74242 {
74243 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74244 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74245 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74246 int fdnum = scm->fp->count;
74247 struct file **fp = scm->fp->fp;
74248 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74249 return -EFAULT;
74250 old_fs = get_fs();
74251 set_fs(KERNEL_DS);
74252 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74253 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74254 set_fs(old_fs);
74255
74256 return err;
74257 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74258 len = sizeof(ktime);
74259 old_fs = get_fs();
74260 set_fs(KERNEL_DS);
74261 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74262 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74263 set_fs(old_fs);
74264
74265 if (!err) {
74266 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74267 case MCAST_JOIN_GROUP:
74268 case MCAST_LEAVE_GROUP:
74269 {
74270 - struct compat_group_req __user *gr32 = (void *)optval;
74271 + struct compat_group_req __user *gr32 = (void __user *)optval;
74272 struct group_req __user *kgr =
74273 compat_alloc_user_space(sizeof(struct group_req));
74274 u32 interface;
74275 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74276 case MCAST_BLOCK_SOURCE:
74277 case MCAST_UNBLOCK_SOURCE:
74278 {
74279 - struct compat_group_source_req __user *gsr32 = (void *)optval;
74280 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74281 struct group_source_req __user *kgsr = compat_alloc_user_space(
74282 sizeof(struct group_source_req));
74283 u32 interface;
74284 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74285 }
74286 case MCAST_MSFILTER:
74287 {
74288 - struct compat_group_filter __user *gf32 = (void *)optval;
74289 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74290 struct group_filter __user *kgf;
74291 u32 interface, fmode, numsrc;
74292
74293 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74294 char __user *optval, int __user *optlen,
74295 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74296 {
74297 - struct compat_group_filter __user *gf32 = (void *)optval;
74298 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74299 struct group_filter __user *kgf;
74300 int __user *koptlen;
74301 u32 interface, fmode, numsrc;
74302 diff --git a/net/core/datagram.c b/net/core/datagram.c
74303 index 68bbf9f..5ef0d12 100644
74304 --- a/net/core/datagram.c
74305 +++ b/net/core/datagram.c
74306 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74307 }
74308
74309 kfree_skb(skb);
74310 - atomic_inc(&sk->sk_drops);
74311 + atomic_inc_unchecked(&sk->sk_drops);
74312 sk_mem_reclaim_partial(sk);
74313
74314 return err;
74315 diff --git a/net/core/dev.c b/net/core/dev.c
74316 index c56cacf..b28e35f 100644
74317 --- a/net/core/dev.c
74318 +++ b/net/core/dev.c
74319 @@ -1139,10 +1139,14 @@ void dev_load(struct net *net, const char *name)
74320 if (no_module && capable(CAP_NET_ADMIN))
74321 no_module = request_module("netdev-%s", name);
74322 if (no_module && capable(CAP_SYS_MODULE)) {
74323 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74324 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
74325 +#else
74326 if (!request_module("%s", name))
74327 pr_err("Loading kernel module for a network device "
74328 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
74329 "instead\n", name);
74330 +#endif
74331 }
74332 }
74333 EXPORT_SYMBOL(dev_load);
74334 @@ -1573,7 +1577,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74335 {
74336 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74337 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74338 - atomic_long_inc(&dev->rx_dropped);
74339 + atomic_long_inc_unchecked(&dev->rx_dropped);
74340 kfree_skb(skb);
74341 return NET_RX_DROP;
74342 }
74343 @@ -1583,7 +1587,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74344 nf_reset(skb);
74345
74346 if (unlikely(!is_skb_forwardable(dev, skb))) {
74347 - atomic_long_inc(&dev->rx_dropped);
74348 + atomic_long_inc_unchecked(&dev->rx_dropped);
74349 kfree_skb(skb);
74350 return NET_RX_DROP;
74351 }
74352 @@ -2036,7 +2040,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74353
74354 struct dev_gso_cb {
74355 void (*destructor)(struct sk_buff *skb);
74356 -};
74357 +} __no_const;
74358
74359 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74360
74361 @@ -2970,7 +2974,7 @@ enqueue:
74362
74363 local_irq_restore(flags);
74364
74365 - atomic_long_inc(&skb->dev->rx_dropped);
74366 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74367 kfree_skb(skb);
74368 return NET_RX_DROP;
74369 }
74370 @@ -3044,7 +3048,7 @@ int netif_rx_ni(struct sk_buff *skb)
74371 }
74372 EXPORT_SYMBOL(netif_rx_ni);
74373
74374 -static void net_tx_action(struct softirq_action *h)
74375 +static void net_tx_action(void)
74376 {
74377 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74378
74379 @@ -3333,7 +3337,7 @@ ncls:
74380 if (pt_prev) {
74381 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74382 } else {
74383 - atomic_long_inc(&skb->dev->rx_dropped);
74384 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74385 kfree_skb(skb);
74386 /* Jamal, now you will not able to escape explaining
74387 * me how you were going to use this. :-)
74388 @@ -3897,7 +3901,7 @@ void netif_napi_del(struct napi_struct *napi)
74389 }
74390 EXPORT_SYMBOL(netif_napi_del);
74391
74392 -static void net_rx_action(struct softirq_action *h)
74393 +static void net_rx_action(void)
74394 {
74395 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74396 unsigned long time_limit = jiffies + 2;
74397 @@ -5955,7 +5959,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
74398 } else {
74399 netdev_stats_to_stats64(storage, &dev->stats);
74400 }
74401 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
74402 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
74403 return storage;
74404 }
74405 EXPORT_SYMBOL(dev_get_stats);
74406 diff --git a/net/core/flow.c b/net/core/flow.c
74407 index e318c7e..168b1d0 100644
74408 --- a/net/core/flow.c
74409 +++ b/net/core/flow.c
74410 @@ -61,7 +61,7 @@ struct flow_cache {
74411 struct timer_list rnd_timer;
74412 };
74413
74414 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
74415 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
74416 EXPORT_SYMBOL(flow_cache_genid);
74417 static struct flow_cache flow_cache_global;
74418 static struct kmem_cache *flow_cachep __read_mostly;
74419 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
74420
74421 static int flow_entry_valid(struct flow_cache_entry *fle)
74422 {
74423 - if (atomic_read(&flow_cache_genid) != fle->genid)
74424 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
74425 return 0;
74426 if (fle->object && !fle->object->ops->check(fle->object))
74427 return 0;
74428 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
74429 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
74430 fcp->hash_count++;
74431 }
74432 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
74433 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
74434 flo = fle->object;
74435 if (!flo)
74436 goto ret_object;
74437 @@ -280,7 +280,7 @@ nocache:
74438 }
74439 flo = resolver(net, key, family, dir, flo, ctx);
74440 if (fle) {
74441 - fle->genid = atomic_read(&flow_cache_genid);
74442 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
74443 if (!IS_ERR(flo))
74444 fle->object = flo;
74445 else
74446 diff --git a/net/core/iovec.c b/net/core/iovec.c
74447 index c40f27e..7f49254 100644
74448 --- a/net/core/iovec.c
74449 +++ b/net/core/iovec.c
74450 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
74451 if (m->msg_namelen) {
74452 if (mode == VERIFY_READ) {
74453 void __user *namep;
74454 - namep = (void __user __force *) m->msg_name;
74455 + namep = (void __force_user *) m->msg_name;
74456 err = move_addr_to_kernel(namep, m->msg_namelen,
74457 address);
74458 if (err < 0)
74459 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
74460 }
74461
74462 size = m->msg_iovlen * sizeof(struct iovec);
74463 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
74464 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
74465 return -EFAULT;
74466
74467 m->msg_iov = iov;
74468 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
74469 index 9083e82..1673203 100644
74470 --- a/net/core/rtnetlink.c
74471 +++ b/net/core/rtnetlink.c
74472 @@ -57,7 +57,7 @@ struct rtnl_link {
74473 rtnl_doit_func doit;
74474 rtnl_dumpit_func dumpit;
74475 rtnl_calcit_func calcit;
74476 -};
74477 +} __no_const;
74478
74479 static DEFINE_MUTEX(rtnl_mutex);
74480 static u16 min_ifinfo_dump_size;
74481 diff --git a/net/core/scm.c b/net/core/scm.c
74482 index ff52ad0..aff1c0f 100644
74483 --- a/net/core/scm.c
74484 +++ b/net/core/scm.c
74485 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
74486 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74487 {
74488 struct cmsghdr __user *cm
74489 - = (__force struct cmsghdr __user *)msg->msg_control;
74490 + = (struct cmsghdr __force_user *)msg->msg_control;
74491 struct cmsghdr cmhdr;
74492 int cmlen = CMSG_LEN(len);
74493 int err;
74494 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74495 err = -EFAULT;
74496 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
74497 goto out;
74498 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
74499 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
74500 goto out;
74501 cmlen = CMSG_SPACE(len);
74502 if (msg->msg_controllen < cmlen)
74503 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
74504 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74505 {
74506 struct cmsghdr __user *cm
74507 - = (__force struct cmsghdr __user*)msg->msg_control;
74508 + = (struct cmsghdr __force_user *)msg->msg_control;
74509
74510 int fdmax = 0;
74511 int fdnum = scm->fp->count;
74512 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74513 if (fdnum < fdmax)
74514 fdmax = fdnum;
74515
74516 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74517 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74518 i++, cmfptr++)
74519 {
74520 int new_fd;
74521 diff --git a/net/core/sock.c b/net/core/sock.c
74522 index b23f174..b9a0d26 100644
74523 --- a/net/core/sock.c
74524 +++ b/net/core/sock.c
74525 @@ -289,7 +289,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74526 struct sk_buff_head *list = &sk->sk_receive_queue;
74527
74528 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74529 - atomic_inc(&sk->sk_drops);
74530 + atomic_inc_unchecked(&sk->sk_drops);
74531 trace_sock_rcvqueue_full(sk, skb);
74532 return -ENOMEM;
74533 }
74534 @@ -299,7 +299,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74535 return err;
74536
74537 if (!sk_rmem_schedule(sk, skb->truesize)) {
74538 - atomic_inc(&sk->sk_drops);
74539 + atomic_inc_unchecked(&sk->sk_drops);
74540 return -ENOBUFS;
74541 }
74542
74543 @@ -319,7 +319,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74544 skb_dst_force(skb);
74545
74546 spin_lock_irqsave(&list->lock, flags);
74547 - skb->dropcount = atomic_read(&sk->sk_drops);
74548 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74549 __skb_queue_tail(list, skb);
74550 spin_unlock_irqrestore(&list->lock, flags);
74551
74552 @@ -339,7 +339,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74553 skb->dev = NULL;
74554
74555 if (sk_rcvqueues_full(sk, skb)) {
74556 - atomic_inc(&sk->sk_drops);
74557 + atomic_inc_unchecked(&sk->sk_drops);
74558 goto discard_and_relse;
74559 }
74560 if (nested)
74561 @@ -357,7 +357,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74562 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74563 } else if (sk_add_backlog(sk, skb)) {
74564 bh_unlock_sock(sk);
74565 - atomic_inc(&sk->sk_drops);
74566 + atomic_inc_unchecked(&sk->sk_drops);
74567 goto discard_and_relse;
74568 }
74569
74570 @@ -917,7 +917,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74571 if (len > sizeof(peercred))
74572 len = sizeof(peercred);
74573 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74574 - if (copy_to_user(optval, &peercred, len))
74575 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74576 return -EFAULT;
74577 goto lenout;
74578 }
74579 @@ -930,7 +930,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74580 return -ENOTCONN;
74581 if (lv < len)
74582 return -EINVAL;
74583 - if (copy_to_user(optval, address, len))
74584 + if (len > sizeof(address) || copy_to_user(optval, address, len))
74585 return -EFAULT;
74586 goto lenout;
74587 }
74588 @@ -963,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74589
74590 if (len > lv)
74591 len = lv;
74592 - if (copy_to_user(optval, &v, len))
74593 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
74594 return -EFAULT;
74595 lenout:
74596 if (put_user(len, optlen))
74597 @@ -2020,7 +2020,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74598 */
74599 smp_wmb();
74600 atomic_set(&sk->sk_refcnt, 1);
74601 - atomic_set(&sk->sk_drops, 0);
74602 + atomic_set_unchecked(&sk->sk_drops, 0);
74603 }
74604 EXPORT_SYMBOL(sock_init_data);
74605
74606 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74607 index 02e75d1..9a57a7c 100644
74608 --- a/net/decnet/sysctl_net_decnet.c
74609 +++ b/net/decnet/sysctl_net_decnet.c
74610 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74611
74612 if (len > *lenp) len = *lenp;
74613
74614 - if (copy_to_user(buffer, addr, len))
74615 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
74616 return -EFAULT;
74617
74618 *lenp = len;
74619 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74620
74621 if (len > *lenp) len = *lenp;
74622
74623 - if (copy_to_user(buffer, devname, len))
74624 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
74625 return -EFAULT;
74626
74627 *lenp = len;
74628 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74629 index 39a2d29..f39c0fe 100644
74630 --- a/net/econet/Kconfig
74631 +++ b/net/econet/Kconfig
74632 @@ -4,7 +4,7 @@
74633
74634 config ECONET
74635 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74636 - depends on EXPERIMENTAL && INET
74637 + depends on EXPERIMENTAL && INET && BROKEN
74638 ---help---
74639 Econet is a fairly old and slow networking protocol mainly used by
74640 Acorn computers to access file and print servers. It uses native
74641 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74642 index 92fc5f6..b790d91 100644
74643 --- a/net/ipv4/fib_frontend.c
74644 +++ b/net/ipv4/fib_frontend.c
74645 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74646 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74647 fib_sync_up(dev);
74648 #endif
74649 - atomic_inc(&net->ipv4.dev_addr_genid);
74650 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74651 rt_cache_flush(dev_net(dev), -1);
74652 break;
74653 case NETDEV_DOWN:
74654 fib_del_ifaddr(ifa, NULL);
74655 - atomic_inc(&net->ipv4.dev_addr_genid);
74656 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74657 if (ifa->ifa_dev->ifa_list == NULL) {
74658 /* Last address was deleted from this interface.
74659 * Disable IP.
74660 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74661 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74662 fib_sync_up(dev);
74663 #endif
74664 - atomic_inc(&net->ipv4.dev_addr_genid);
74665 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74666 rt_cache_flush(dev_net(dev), -1);
74667 break;
74668 case NETDEV_DOWN:
74669 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74670 index 80106d8..232e898 100644
74671 --- a/net/ipv4/fib_semantics.c
74672 +++ b/net/ipv4/fib_semantics.c
74673 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74674 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74675 nh->nh_gw,
74676 nh->nh_parent->fib_scope);
74677 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74678 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74679
74680 return nh->nh_saddr;
74681 }
74682 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
74683 index ccee270..db23c3c 100644
74684 --- a/net/ipv4/inet_diag.c
74685 +++ b/net/ipv4/inet_diag.c
74686 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
74687 r->idiag_retrans = 0;
74688
74689 r->id.idiag_if = sk->sk_bound_dev_if;
74690 +
74691 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74692 + r->id.idiag_cookie[0] = 0;
74693 + r->id.idiag_cookie[1] = 0;
74694 +#else
74695 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
74696 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74697 +#endif
74698
74699 r->id.idiag_sport = inet->inet_sport;
74700 r->id.idiag_dport = inet->inet_dport;
74701 @@ -210,8 +216,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
74702 r->idiag_family = tw->tw_family;
74703 r->idiag_retrans = 0;
74704 r->id.idiag_if = tw->tw_bound_dev_if;
74705 +
74706 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74707 + r->id.idiag_cookie[0] = 0;
74708 + r->id.idiag_cookie[1] = 0;
74709 +#else
74710 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
74711 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
74712 +#endif
74713 +
74714 r->id.idiag_sport = tw->tw_sport;
74715 r->id.idiag_dport = tw->tw_dport;
74716 r->id.idiag_src[0] = tw->tw_rcv_saddr;
74717 @@ -294,12 +307,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
74718 if (sk == NULL)
74719 goto unlock;
74720
74721 +#ifndef CONFIG_GRKERNSEC_HIDESYM
74722 err = -ESTALE;
74723 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
74724 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
74725 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
74726 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
74727 goto out;
74728 +#endif
74729
74730 err = -ENOMEM;
74731 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
74732 @@ -589,8 +604,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
74733 r->idiag_retrans = req->retrans;
74734
74735 r->id.idiag_if = sk->sk_bound_dev_if;
74736 +
74737 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74738 + r->id.idiag_cookie[0] = 0;
74739 + r->id.idiag_cookie[1] = 0;
74740 +#else
74741 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
74742 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
74743 +#endif
74744
74745 tmo = req->expires - jiffies;
74746 if (tmo < 0)
74747 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74748 index 984ec65..97ac518 100644
74749 --- a/net/ipv4/inet_hashtables.c
74750 +++ b/net/ipv4/inet_hashtables.c
74751 @@ -18,12 +18,15 @@
74752 #include <linux/sched.h>
74753 #include <linux/slab.h>
74754 #include <linux/wait.h>
74755 +#include <linux/security.h>
74756
74757 #include <net/inet_connection_sock.h>
74758 #include <net/inet_hashtables.h>
74759 #include <net/secure_seq.h>
74760 #include <net/ip.h>
74761
74762 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74763 +
74764 /*
74765 * Allocate and initialize a new local port bind bucket.
74766 * The bindhash mutex for snum's hash chain must be held here.
74767 @@ -530,6 +533,8 @@ ok:
74768 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74769 spin_unlock(&head->lock);
74770
74771 + gr_update_task_in_ip_table(current, inet_sk(sk));
74772 +
74773 if (tw) {
74774 inet_twsk_deschedule(tw, death_row);
74775 while (twrefcnt) {
74776 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74777 index 86f13c67..59a35b5 100644
74778 --- a/net/ipv4/inetpeer.c
74779 +++ b/net/ipv4/inetpeer.c
74780 @@ -436,8 +436,8 @@ relookup:
74781 if (p) {
74782 p->daddr = *daddr;
74783 atomic_set(&p->refcnt, 1);
74784 - atomic_set(&p->rid, 0);
74785 - atomic_set(&p->ip_id_count,
74786 + atomic_set_unchecked(&p->rid, 0);
74787 + atomic_set_unchecked(&p->ip_id_count,
74788 (daddr->family == AF_INET) ?
74789 secure_ip_id(daddr->addr.a4) :
74790 secure_ipv6_id(daddr->addr.a6));
74791 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74792 index fdaabf2..0ec3205 100644
74793 --- a/net/ipv4/ip_fragment.c
74794 +++ b/net/ipv4/ip_fragment.c
74795 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74796 return 0;
74797
74798 start = qp->rid;
74799 - end = atomic_inc_return(&peer->rid);
74800 + end = atomic_inc_return_unchecked(&peer->rid);
74801 qp->rid = end;
74802
74803 rc = qp->q.fragments && (end - start) > max;
74804 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74805 index 09ff51b..d3968eb 100644
74806 --- a/net/ipv4/ip_sockglue.c
74807 +++ b/net/ipv4/ip_sockglue.c
74808 @@ -1111,7 +1111,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74809 len = min_t(unsigned int, len, opt->optlen);
74810 if (put_user(len, optlen))
74811 return -EFAULT;
74812 - if (copy_to_user(optval, opt->__data, len))
74813 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74814 + copy_to_user(optval, opt->__data, len))
74815 return -EFAULT;
74816 return 0;
74817 }
74818 @@ -1239,7 +1240,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74819 if (sk->sk_type != SOCK_STREAM)
74820 return -ENOPROTOOPT;
74821
74822 - msg.msg_control = optval;
74823 + msg.msg_control = (void __force_kernel *)optval;
74824 msg.msg_controllen = len;
74825 msg.msg_flags = flags;
74826
74827 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74828 index 99ec116..c5628fe 100644
74829 --- a/net/ipv4/ipconfig.c
74830 +++ b/net/ipv4/ipconfig.c
74831 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74832
74833 mm_segment_t oldfs = get_fs();
74834 set_fs(get_ds());
74835 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74836 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74837 set_fs(oldfs);
74838 return res;
74839 }
74840 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74841
74842 mm_segment_t oldfs = get_fs();
74843 set_fs(get_ds());
74844 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74845 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74846 set_fs(oldfs);
74847 return res;
74848 }
74849 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74850
74851 mm_segment_t oldfs = get_fs();
74852 set_fs(get_ds());
74853 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74854 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74855 set_fs(oldfs);
74856 return res;
74857 }
74858 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74859 index 2133c30..5c4b40b 100644
74860 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
74861 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74862 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
74863
74864 *len = 0;
74865
74866 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
74867 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
74868 if (*octets == NULL)
74869 return 0;
74870
74871 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74872 index 43d4c3b..1914409 100644
74873 --- a/net/ipv4/ping.c
74874 +++ b/net/ipv4/ping.c
74875 @@ -836,7 +836,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74876 sk_rmem_alloc_get(sp),
74877 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74878 atomic_read(&sp->sk_refcnt), sp,
74879 - atomic_read(&sp->sk_drops), len);
74880 + atomic_read_unchecked(&sp->sk_drops), len);
74881 }
74882
74883 static int ping_seq_show(struct seq_file *seq, void *v)
74884 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74885 index 007e2eb..85a18a0 100644
74886 --- a/net/ipv4/raw.c
74887 +++ b/net/ipv4/raw.c
74888 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74889 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74890 {
74891 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74892 - atomic_inc(&sk->sk_drops);
74893 + atomic_inc_unchecked(&sk->sk_drops);
74894 kfree_skb(skb);
74895 return NET_RX_DROP;
74896 }
74897 @@ -738,16 +738,20 @@ static int raw_init(struct sock *sk)
74898
74899 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74900 {
74901 + struct icmp_filter filter;
74902 +
74903 if (optlen > sizeof(struct icmp_filter))
74904 optlen = sizeof(struct icmp_filter);
74905 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74906 + if (copy_from_user(&filter, optval, optlen))
74907 return -EFAULT;
74908 + raw_sk(sk)->filter = filter;
74909 return 0;
74910 }
74911
74912 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74913 {
74914 int len, ret = -EFAULT;
74915 + struct icmp_filter filter;
74916
74917 if (get_user(len, optlen))
74918 goto out;
74919 @@ -757,8 +761,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74920 if (len > sizeof(struct icmp_filter))
74921 len = sizeof(struct icmp_filter);
74922 ret = -EFAULT;
74923 - if (put_user(len, optlen) ||
74924 - copy_to_user(optval, &raw_sk(sk)->filter, len))
74925 + filter = raw_sk(sk)->filter;
74926 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74927 goto out;
74928 ret = 0;
74929 out: return ret;
74930 @@ -986,7 +990,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74931 sk_wmem_alloc_get(sp),
74932 sk_rmem_alloc_get(sp),
74933 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74934 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74935 + atomic_read(&sp->sk_refcnt),
74936 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74937 + NULL,
74938 +#else
74939 + sp,
74940 +#endif
74941 + atomic_read_unchecked(&sp->sk_drops));
74942 }
74943
74944 static int raw_seq_show(struct seq_file *seq, void *v)
74945 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74946 index 94cdbc5..0cb0063 100644
74947 --- a/net/ipv4/route.c
74948 +++ b/net/ipv4/route.c
74949 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74950
74951 static inline int rt_genid(struct net *net)
74952 {
74953 - return atomic_read(&net->ipv4.rt_genid);
74954 + return atomic_read_unchecked(&net->ipv4.rt_genid);
74955 }
74956
74957 #ifdef CONFIG_PROC_FS
74958 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
74959 unsigned char shuffle;
74960
74961 get_random_bytes(&shuffle, sizeof(shuffle));
74962 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74963 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74964 redirect_genid++;
74965 }
74966
74967 @@ -3022,7 +3022,7 @@ static int rt_fill_info(struct net *net,
74968 error = rt->dst.error;
74969 if (peer) {
74970 inet_peer_refcheck(rt->peer);
74971 - id = atomic_read(&peer->ip_id_count) & 0xffff;
74972 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74973 if (peer->tcp_ts_stamp) {
74974 ts = peer->tcp_ts;
74975 tsage = get_seconds() - peer->tcp_ts_stamp;
74976 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74977 index eb90aa8..22bf114 100644
74978 --- a/net/ipv4/tcp_ipv4.c
74979 +++ b/net/ipv4/tcp_ipv4.c
74980 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
74981 int sysctl_tcp_low_latency __read_mostly;
74982 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74983
74984 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74985 +extern int grsec_enable_blackhole;
74986 +#endif
74987
74988 #ifdef CONFIG_TCP_MD5SIG
74989 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
74990 @@ -1632,6 +1635,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74991 return 0;
74992
74993 reset:
74994 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74995 + if (!grsec_enable_blackhole)
74996 +#endif
74997 tcp_v4_send_reset(rsk, skb);
74998 discard:
74999 kfree_skb(skb);
75000 @@ -1694,12 +1700,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75001 TCP_SKB_CB(skb)->sacked = 0;
75002
75003 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75004 - if (!sk)
75005 + if (!sk) {
75006 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75007 + ret = 1;
75008 +#endif
75009 goto no_tcp_socket;
75010 -
75011 + }
75012 process:
75013 - if (sk->sk_state == TCP_TIME_WAIT)
75014 + if (sk->sk_state == TCP_TIME_WAIT) {
75015 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75016 + ret = 2;
75017 +#endif
75018 goto do_time_wait;
75019 + }
75020
75021 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75022 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75023 @@ -1749,6 +1762,10 @@ no_tcp_socket:
75024 bad_packet:
75025 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75026 } else {
75027 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75028 + if (!grsec_enable_blackhole || (ret == 1 &&
75029 + (skb->dev->flags & IFF_LOOPBACK)))
75030 +#endif
75031 tcp_v4_send_reset(NULL, skb);
75032 }
75033
75034 @@ -2409,7 +2426,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75035 0, /* non standard timer */
75036 0, /* open_requests have no inode */
75037 atomic_read(&sk->sk_refcnt),
75038 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75039 + NULL,
75040 +#else
75041 req,
75042 +#endif
75043 len);
75044 }
75045
75046 @@ -2459,7 +2480,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75047 sock_i_uid(sk),
75048 icsk->icsk_probes_out,
75049 sock_i_ino(sk),
75050 - atomic_read(&sk->sk_refcnt), sk,
75051 + atomic_read(&sk->sk_refcnt),
75052 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75053 + NULL,
75054 +#else
75055 + sk,
75056 +#endif
75057 jiffies_to_clock_t(icsk->icsk_rto),
75058 jiffies_to_clock_t(icsk->icsk_ack.ato),
75059 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75060 @@ -2487,7 +2513,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75061 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75062 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75063 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75064 - atomic_read(&tw->tw_refcnt), tw, len);
75065 + atomic_read(&tw->tw_refcnt),
75066 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75067 + NULL,
75068 +#else
75069 + tw,
75070 +#endif
75071 + len);
75072 }
75073
75074 #define TMPSZ 150
75075 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75076 index 66363b6..b0654a3 100644
75077 --- a/net/ipv4/tcp_minisocks.c
75078 +++ b/net/ipv4/tcp_minisocks.c
75079 @@ -27,6 +27,10 @@
75080 #include <net/inet_common.h>
75081 #include <net/xfrm.h>
75082
75083 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75084 +extern int grsec_enable_blackhole;
75085 +#endif
75086 +
75087 int sysctl_tcp_syncookies __read_mostly = 1;
75088 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75089
75090 @@ -751,6 +755,10 @@ listen_overflow:
75091
75092 embryonic_reset:
75093 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75094 +
75095 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75096 + if (!grsec_enable_blackhole)
75097 +#endif
75098 if (!(flg & TCP_FLAG_RST))
75099 req->rsk_ops->send_reset(sk, skb);
75100
75101 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75102 index 85ee7eb..53277ab 100644
75103 --- a/net/ipv4/tcp_probe.c
75104 +++ b/net/ipv4/tcp_probe.c
75105 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75106 if (cnt + width >= len)
75107 break;
75108
75109 - if (copy_to_user(buf + cnt, tbuf, width))
75110 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75111 return -EFAULT;
75112 cnt += width;
75113 }
75114 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75115 index 2e0f0af..e2948bf 100644
75116 --- a/net/ipv4/tcp_timer.c
75117 +++ b/net/ipv4/tcp_timer.c
75118 @@ -22,6 +22,10 @@
75119 #include <linux/gfp.h>
75120 #include <net/tcp.h>
75121
75122 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75123 +extern int grsec_lastack_retries;
75124 +#endif
75125 +
75126 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75127 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75128 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75129 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
75130 }
75131 }
75132
75133 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75134 + if ((sk->sk_state == TCP_LAST_ACK) &&
75135 + (grsec_lastack_retries > 0) &&
75136 + (grsec_lastack_retries < retry_until))
75137 + retry_until = grsec_lastack_retries;
75138 +#endif
75139 +
75140 if (retransmits_timed_out(sk, retry_until,
75141 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75142 /* Has it gone just too far? */
75143 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75144 index 5a65eea..bd913a1 100644
75145 --- a/net/ipv4/udp.c
75146 +++ b/net/ipv4/udp.c
75147 @@ -86,6 +86,7 @@
75148 #include <linux/types.h>
75149 #include <linux/fcntl.h>
75150 #include <linux/module.h>
75151 +#include <linux/security.h>
75152 #include <linux/socket.h>
75153 #include <linux/sockios.h>
75154 #include <linux/igmp.h>
75155 @@ -108,6 +109,10 @@
75156 #include <trace/events/udp.h>
75157 #include "udp_impl.h"
75158
75159 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75160 +extern int grsec_enable_blackhole;
75161 +#endif
75162 +
75163 struct udp_table udp_table __read_mostly;
75164 EXPORT_SYMBOL(udp_table);
75165
75166 @@ -565,6 +570,9 @@ found:
75167 return s;
75168 }
75169
75170 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75171 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75172 +
75173 /*
75174 * This routine is called by the ICMP module when it gets some
75175 * sort of error condition. If err < 0 then the socket should
75176 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75177 dport = usin->sin_port;
75178 if (dport == 0)
75179 return -EINVAL;
75180 +
75181 + err = gr_search_udp_sendmsg(sk, usin);
75182 + if (err)
75183 + return err;
75184 } else {
75185 if (sk->sk_state != TCP_ESTABLISHED)
75186 return -EDESTADDRREQ;
75187 +
75188 + err = gr_search_udp_sendmsg(sk, NULL);
75189 + if (err)
75190 + return err;
75191 +
75192 daddr = inet->inet_daddr;
75193 dport = inet->inet_dport;
75194 /* Open fast path for connected socket.
75195 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
75196 udp_lib_checksum_complete(skb)) {
75197 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75198 IS_UDPLITE(sk));
75199 - atomic_inc(&sk->sk_drops);
75200 + atomic_inc_unchecked(&sk->sk_drops);
75201 __skb_unlink(skb, rcvq);
75202 __skb_queue_tail(&list_kill, skb);
75203 }
75204 @@ -1185,6 +1202,10 @@ try_again:
75205 if (!skb)
75206 goto out;
75207
75208 + err = gr_search_udp_recvmsg(sk, skb);
75209 + if (err)
75210 + goto out_free;
75211 +
75212 ulen = skb->len - sizeof(struct udphdr);
75213 copied = len;
75214 if (copied > ulen)
75215 @@ -1487,7 +1508,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75216
75217 drop:
75218 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75219 - atomic_inc(&sk->sk_drops);
75220 + atomic_inc_unchecked(&sk->sk_drops);
75221 kfree_skb(skb);
75222 return -1;
75223 }
75224 @@ -1506,7 +1527,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75225 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75226
75227 if (!skb1) {
75228 - atomic_inc(&sk->sk_drops);
75229 + atomic_inc_unchecked(&sk->sk_drops);
75230 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75231 IS_UDPLITE(sk));
75232 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75233 @@ -1675,6 +1696,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75234 goto csum_error;
75235
75236 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75237 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75238 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75239 +#endif
75240 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75241
75242 /*
75243 @@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75244 sk_wmem_alloc_get(sp),
75245 sk_rmem_alloc_get(sp),
75246 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75247 - atomic_read(&sp->sk_refcnt), sp,
75248 - atomic_read(&sp->sk_drops), len);
75249 + atomic_read(&sp->sk_refcnt),
75250 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75251 + NULL,
75252 +#else
75253 + sp,
75254 +#endif
75255 + atomic_read_unchecked(&sp->sk_drops), len);
75256 }
75257
75258 int udp4_seq_show(struct seq_file *seq, void *v)
75259 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75260 index 836c4ea..cbb74dc 100644
75261 --- a/net/ipv6/addrconf.c
75262 +++ b/net/ipv6/addrconf.c
75263 @@ -2149,7 +2149,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75264 p.iph.ihl = 5;
75265 p.iph.protocol = IPPROTO_IPV6;
75266 p.iph.ttl = 64;
75267 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75268 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75269
75270 if (ops->ndo_do_ioctl) {
75271 mm_segment_t oldfs = get_fs();
75272 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75273 index 1567fb1..29af910 100644
75274 --- a/net/ipv6/inet6_connection_sock.c
75275 +++ b/net/ipv6/inet6_connection_sock.c
75276 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75277 #ifdef CONFIG_XFRM
75278 {
75279 struct rt6_info *rt = (struct rt6_info *)dst;
75280 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75281 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75282 }
75283 #endif
75284 }
75285 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75286 #ifdef CONFIG_XFRM
75287 if (dst) {
75288 struct rt6_info *rt = (struct rt6_info *)dst;
75289 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75290 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75291 __sk_dst_reset(sk);
75292 dst = NULL;
75293 }
75294 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75295 index 26cb08c..8af9877 100644
75296 --- a/net/ipv6/ipv6_sockglue.c
75297 +++ b/net/ipv6/ipv6_sockglue.c
75298 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75299 if (sk->sk_type != SOCK_STREAM)
75300 return -ENOPROTOOPT;
75301
75302 - msg.msg_control = optval;
75303 + msg.msg_control = (void __force_kernel *)optval;
75304 msg.msg_controllen = len;
75305 msg.msg_flags = flags;
75306
75307 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75308 index 361ebf3..d5628fb 100644
75309 --- a/net/ipv6/raw.c
75310 +++ b/net/ipv6/raw.c
75311 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
75312 {
75313 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
75314 skb_checksum_complete(skb)) {
75315 - atomic_inc(&sk->sk_drops);
75316 + atomic_inc_unchecked(&sk->sk_drops);
75317 kfree_skb(skb);
75318 return NET_RX_DROP;
75319 }
75320 @@ -404,7 +404,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75321 struct raw6_sock *rp = raw6_sk(sk);
75322
75323 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
75324 - atomic_inc(&sk->sk_drops);
75325 + atomic_inc_unchecked(&sk->sk_drops);
75326 kfree_skb(skb);
75327 return NET_RX_DROP;
75328 }
75329 @@ -428,7 +428,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75330
75331 if (inet->hdrincl) {
75332 if (skb_checksum_complete(skb)) {
75333 - atomic_inc(&sk->sk_drops);
75334 + atomic_inc_unchecked(&sk->sk_drops);
75335 kfree_skb(skb);
75336 return NET_RX_DROP;
75337 }
75338 @@ -601,7 +601,7 @@ out:
75339 return err;
75340 }
75341
75342 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
75343 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
75344 struct flowi6 *fl6, struct dst_entry **dstp,
75345 unsigned int flags)
75346 {
75347 @@ -909,12 +909,15 @@ do_confirm:
75348 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
75349 char __user *optval, int optlen)
75350 {
75351 + struct icmp6_filter filter;
75352 +
75353 switch (optname) {
75354 case ICMPV6_FILTER:
75355 if (optlen > sizeof(struct icmp6_filter))
75356 optlen = sizeof(struct icmp6_filter);
75357 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75358 + if (copy_from_user(&filter, optval, optlen))
75359 return -EFAULT;
75360 + raw6_sk(sk)->filter = filter;
75361 return 0;
75362 default:
75363 return -ENOPROTOOPT;
75364 @@ -927,6 +930,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75365 char __user *optval, int __user *optlen)
75366 {
75367 int len;
75368 + struct icmp6_filter filter;
75369
75370 switch (optname) {
75371 case ICMPV6_FILTER:
75372 @@ -938,7 +942,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75373 len = sizeof(struct icmp6_filter);
75374 if (put_user(len, optlen))
75375 return -EFAULT;
75376 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
75377 + filter = raw6_sk(sk)->filter;
75378 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
75379 return -EFAULT;
75380 return 0;
75381 default:
75382 @@ -1245,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75383 0, 0L, 0,
75384 sock_i_uid(sp), 0,
75385 sock_i_ino(sp),
75386 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75387 + atomic_read(&sp->sk_refcnt),
75388 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75389 + NULL,
75390 +#else
75391 + sp,
75392 +#endif
75393 + atomic_read_unchecked(&sp->sk_drops));
75394 }
75395
75396 static int raw6_seq_show(struct seq_file *seq, void *v)
75397 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
75398 index b859e4a..f9d1589 100644
75399 --- a/net/ipv6/tcp_ipv6.c
75400 +++ b/net/ipv6/tcp_ipv6.c
75401 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
75402 }
75403 #endif
75404
75405 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75406 +extern int grsec_enable_blackhole;
75407 +#endif
75408 +
75409 static void tcp_v6_hash(struct sock *sk)
75410 {
75411 if (sk->sk_state != TCP_CLOSE) {
75412 @@ -1651,6 +1655,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
75413 return 0;
75414
75415 reset:
75416 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75417 + if (!grsec_enable_blackhole)
75418 +#endif
75419 tcp_v6_send_reset(sk, skb);
75420 discard:
75421 if (opt_skb)
75422 @@ -1730,12 +1737,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
75423 TCP_SKB_CB(skb)->sacked = 0;
75424
75425 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75426 - if (!sk)
75427 + if (!sk) {
75428 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75429 + ret = 1;
75430 +#endif
75431 goto no_tcp_socket;
75432 + }
75433
75434 process:
75435 - if (sk->sk_state == TCP_TIME_WAIT)
75436 + if (sk->sk_state == TCP_TIME_WAIT) {
75437 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75438 + ret = 2;
75439 +#endif
75440 goto do_time_wait;
75441 + }
75442
75443 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
75444 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75445 @@ -1783,6 +1798,10 @@ no_tcp_socket:
75446 bad_packet:
75447 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75448 } else {
75449 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75450 + if (!grsec_enable_blackhole || (ret == 1 &&
75451 + (skb->dev->flags & IFF_LOOPBACK)))
75452 +#endif
75453 tcp_v6_send_reset(NULL, skb);
75454 }
75455
75456 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
75457 uid,
75458 0, /* non standard timer */
75459 0, /* open_requests have no inode */
75460 - 0, req);
75461 + 0,
75462 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75463 + NULL
75464 +#else
75465 + req
75466 +#endif
75467 + );
75468 }
75469
75470 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75471 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75472 sock_i_uid(sp),
75473 icsk->icsk_probes_out,
75474 sock_i_ino(sp),
75475 - atomic_read(&sp->sk_refcnt), sp,
75476 + atomic_read(&sp->sk_refcnt),
75477 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75478 + NULL,
75479 +#else
75480 + sp,
75481 +#endif
75482 jiffies_to_clock_t(icsk->icsk_rto),
75483 jiffies_to_clock_t(icsk->icsk_ack.ato),
75484 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
75485 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
75486 dest->s6_addr32[2], dest->s6_addr32[3], destp,
75487 tw->tw_substate, 0, 0,
75488 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75489 - atomic_read(&tw->tw_refcnt), tw);
75490 + atomic_read(&tw->tw_refcnt),
75491 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75492 + NULL
75493 +#else
75494 + tw
75495 +#endif
75496 + );
75497 }
75498
75499 static int tcp6_seq_show(struct seq_file *seq, void *v)
75500 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
75501 index 8c25419..47a51ae 100644
75502 --- a/net/ipv6/udp.c
75503 +++ b/net/ipv6/udp.c
75504 @@ -50,6 +50,10 @@
75505 #include <linux/seq_file.h>
75506 #include "udp_impl.h"
75507
75508 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75509 +extern int grsec_enable_blackhole;
75510 +#endif
75511 +
75512 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
75513 {
75514 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
75515 @@ -549,7 +553,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
75516
75517 return 0;
75518 drop:
75519 - atomic_inc(&sk->sk_drops);
75520 + atomic_inc_unchecked(&sk->sk_drops);
75521 drop_no_sk_drops_inc:
75522 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75523 kfree_skb(skb);
75524 @@ -625,7 +629,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75525 continue;
75526 }
75527 drop:
75528 - atomic_inc(&sk->sk_drops);
75529 + atomic_inc_unchecked(&sk->sk_drops);
75530 UDP6_INC_STATS_BH(sock_net(sk),
75531 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
75532 UDP6_INC_STATS_BH(sock_net(sk),
75533 @@ -780,6 +784,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75534 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
75535 proto == IPPROTO_UDPLITE);
75536
75537 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75538 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75539 +#endif
75540 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
75541
75542 kfree_skb(skb);
75543 @@ -796,7 +803,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75544 if (!sock_owned_by_user(sk))
75545 udpv6_queue_rcv_skb(sk, skb);
75546 else if (sk_add_backlog(sk, skb)) {
75547 - atomic_inc(&sk->sk_drops);
75548 + atomic_inc_unchecked(&sk->sk_drops);
75549 bh_unlock_sock(sk);
75550 sock_put(sk);
75551 goto discard;
75552 @@ -1407,8 +1414,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75553 0, 0L, 0,
75554 sock_i_uid(sp), 0,
75555 sock_i_ino(sp),
75556 - atomic_read(&sp->sk_refcnt), sp,
75557 - atomic_read(&sp->sk_drops));
75558 + atomic_read(&sp->sk_refcnt),
75559 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75560 + NULL,
75561 +#else
75562 + sp,
75563 +#endif
75564 + atomic_read_unchecked(&sp->sk_drops));
75565 }
75566
75567 int udp6_seq_show(struct seq_file *seq, void *v)
75568 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75569 index 253695d..9481ce8 100644
75570 --- a/net/irda/ircomm/ircomm_tty.c
75571 +++ b/net/irda/ircomm/ircomm_tty.c
75572 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75573 add_wait_queue(&self->open_wait, &wait);
75574
75575 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75576 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75577 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75578
75579 /* As far as I can see, we protect open_count - Jean II */
75580 spin_lock_irqsave(&self->spinlock, flags);
75581 if (!tty_hung_up_p(filp)) {
75582 extra_count = 1;
75583 - self->open_count--;
75584 + local_dec(&self->open_count);
75585 }
75586 spin_unlock_irqrestore(&self->spinlock, flags);
75587 - self->blocked_open++;
75588 + local_inc(&self->blocked_open);
75589
75590 while (1) {
75591 if (tty->termios->c_cflag & CBAUD) {
75592 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75593 }
75594
75595 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75596 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75597 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75598
75599 schedule();
75600 }
75601 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75602 if (extra_count) {
75603 /* ++ is not atomic, so this should be protected - Jean II */
75604 spin_lock_irqsave(&self->spinlock, flags);
75605 - self->open_count++;
75606 + local_inc(&self->open_count);
75607 spin_unlock_irqrestore(&self->spinlock, flags);
75608 }
75609 - self->blocked_open--;
75610 + local_dec(&self->blocked_open);
75611
75612 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75613 - __FILE__,__LINE__, tty->driver->name, self->open_count);
75614 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75615
75616 if (!retval)
75617 self->flags |= ASYNC_NORMAL_ACTIVE;
75618 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75619 }
75620 /* ++ is not atomic, so this should be protected - Jean II */
75621 spin_lock_irqsave(&self->spinlock, flags);
75622 - self->open_count++;
75623 + local_inc(&self->open_count);
75624
75625 tty->driver_data = self;
75626 self->tty = tty;
75627 spin_unlock_irqrestore(&self->spinlock, flags);
75628
75629 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75630 - self->line, self->open_count);
75631 + self->line, local_read(&self->open_count));
75632
75633 /* Not really used by us, but lets do it anyway */
75634 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75635 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75636 return;
75637 }
75638
75639 - if ((tty->count == 1) && (self->open_count != 1)) {
75640 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75641 /*
75642 * Uh, oh. tty->count is 1, which means that the tty
75643 * structure will be freed. state->count should always
75644 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75645 */
75646 IRDA_DEBUG(0, "%s(), bad serial port count; "
75647 "tty->count is 1, state->count is %d\n", __func__ ,
75648 - self->open_count);
75649 - self->open_count = 1;
75650 + local_read(&self->open_count));
75651 + local_set(&self->open_count, 1);
75652 }
75653
75654 - if (--self->open_count < 0) {
75655 + if (local_dec_return(&self->open_count) < 0) {
75656 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75657 - __func__, self->line, self->open_count);
75658 - self->open_count = 0;
75659 + __func__, self->line, local_read(&self->open_count));
75660 + local_set(&self->open_count, 0);
75661 }
75662 - if (self->open_count) {
75663 + if (local_read(&self->open_count)) {
75664 spin_unlock_irqrestore(&self->spinlock, flags);
75665
75666 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75667 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75668 tty->closing = 0;
75669 self->tty = NULL;
75670
75671 - if (self->blocked_open) {
75672 + if (local_read(&self->blocked_open)) {
75673 if (self->close_delay)
75674 schedule_timeout_interruptible(self->close_delay);
75675 wake_up_interruptible(&self->open_wait);
75676 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75677 spin_lock_irqsave(&self->spinlock, flags);
75678 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75679 self->tty = NULL;
75680 - self->open_count = 0;
75681 + local_set(&self->open_count, 0);
75682 spin_unlock_irqrestore(&self->spinlock, flags);
75683
75684 wake_up_interruptible(&self->open_wait);
75685 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75686 seq_putc(m, '\n');
75687
75688 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75689 - seq_printf(m, "Open count: %d\n", self->open_count);
75690 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75691 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75692 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75693
75694 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75695 index 274d150..656a144 100644
75696 --- a/net/iucv/af_iucv.c
75697 +++ b/net/iucv/af_iucv.c
75698 @@ -787,10 +787,10 @@ static int iucv_sock_autobind(struct sock *sk)
75699
75700 write_lock_bh(&iucv_sk_list.lock);
75701
75702 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75703 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75704 while (__iucv_get_sock_by_name(name)) {
75705 sprintf(name, "%08x",
75706 - atomic_inc_return(&iucv_sk_list.autobind_name));
75707 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75708 }
75709
75710 write_unlock_bh(&iucv_sk_list.lock);
75711 diff --git a/net/key/af_key.c b/net/key/af_key.c
75712 index 1e733e9..3d73c9f 100644
75713 --- a/net/key/af_key.c
75714 +++ b/net/key/af_key.c
75715 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75716 static u32 get_acqseq(void)
75717 {
75718 u32 res;
75719 - static atomic_t acqseq;
75720 + static atomic_unchecked_t acqseq;
75721
75722 do {
75723 - res = atomic_inc_return(&acqseq);
75724 + res = atomic_inc_return_unchecked(&acqseq);
75725 } while (!res);
75726 return res;
75727 }
75728 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75729 index 73495f1..ad51356 100644
75730 --- a/net/mac80211/ieee80211_i.h
75731 +++ b/net/mac80211/ieee80211_i.h
75732 @@ -27,6 +27,7 @@
75733 #include <net/ieee80211_radiotap.h>
75734 #include <net/cfg80211.h>
75735 #include <net/mac80211.h>
75736 +#include <asm/local.h>
75737 #include "key.h"
75738 #include "sta_info.h"
75739
75740 @@ -764,7 +765,7 @@ struct ieee80211_local {
75741 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75742 spinlock_t queue_stop_reason_lock;
75743
75744 - int open_count;
75745 + local_t open_count;
75746 int monitors, cooked_mntrs;
75747 /* number of interfaces with corresponding FIF_ flags */
75748 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75749 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75750 index 30d7355..e260095 100644
75751 --- a/net/mac80211/iface.c
75752 +++ b/net/mac80211/iface.c
75753 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75754 break;
75755 }
75756
75757 - if (local->open_count == 0) {
75758 + if (local_read(&local->open_count) == 0) {
75759 res = drv_start(local);
75760 if (res)
75761 goto err_del_bss;
75762 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75763 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75764
75765 if (!is_valid_ether_addr(dev->dev_addr)) {
75766 - if (!local->open_count)
75767 + if (!local_read(&local->open_count))
75768 drv_stop(local);
75769 return -EADDRNOTAVAIL;
75770 }
75771 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75772 mutex_unlock(&local->mtx);
75773
75774 if (coming_up)
75775 - local->open_count++;
75776 + local_inc(&local->open_count);
75777
75778 if (hw_reconf_flags) {
75779 ieee80211_hw_config(local, hw_reconf_flags);
75780 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75781 err_del_interface:
75782 drv_remove_interface(local, &sdata->vif);
75783 err_stop:
75784 - if (!local->open_count)
75785 + if (!local_read(&local->open_count))
75786 drv_stop(local);
75787 err_del_bss:
75788 sdata->bss = NULL;
75789 @@ -472,7 +472,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75790 }
75791
75792 if (going_down)
75793 - local->open_count--;
75794 + local_dec(&local->open_count);
75795
75796 switch (sdata->vif.type) {
75797 case NL80211_IFTYPE_AP_VLAN:
75798 @@ -531,7 +531,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75799
75800 ieee80211_recalc_ps(local, -1);
75801
75802 - if (local->open_count == 0) {
75803 + if (local_read(&local->open_count) == 0) {
75804 if (local->ops->napi_poll)
75805 napi_disable(&local->napi);
75806 ieee80211_clear_tx_pending(local);
75807 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75808 index 7d9b21d..0687004 100644
75809 --- a/net/mac80211/main.c
75810 +++ b/net/mac80211/main.c
75811 @@ -163,7 +163,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75812 local->hw.conf.power_level = power;
75813 }
75814
75815 - if (changed && local->open_count) {
75816 + if (changed && local_read(&local->open_count)) {
75817 ret = drv_config(local, changed);
75818 /*
75819 * Goal:
75820 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75821 index 9ee7164..56c5061 100644
75822 --- a/net/mac80211/pm.c
75823 +++ b/net/mac80211/pm.c
75824 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75825 struct ieee80211_sub_if_data *sdata;
75826 struct sta_info *sta;
75827
75828 - if (!local->open_count)
75829 + if (!local_read(&local->open_count))
75830 goto suspend;
75831
75832 ieee80211_scan_cancel(local);
75833 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75834 cancel_work_sync(&local->dynamic_ps_enable_work);
75835 del_timer_sync(&local->dynamic_ps_timer);
75836
75837 - local->wowlan = wowlan && local->open_count;
75838 + local->wowlan = wowlan && local_read(&local->open_count);
75839 if (local->wowlan) {
75840 int err = drv_suspend(local, wowlan);
75841 if (err < 0) {
75842 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75843 }
75844
75845 /* stop hardware - this must stop RX */
75846 - if (local->open_count)
75847 + if (local_read(&local->open_count))
75848 ieee80211_stop_device(local);
75849
75850 suspend:
75851 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75852 index 7d84b87..6a69cd9 100644
75853 --- a/net/mac80211/rate.c
75854 +++ b/net/mac80211/rate.c
75855 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75856
75857 ASSERT_RTNL();
75858
75859 - if (local->open_count)
75860 + if (local_read(&local->open_count))
75861 return -EBUSY;
75862
75863 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75864 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75865 index c97a065..ff61928 100644
75866 --- a/net/mac80211/rc80211_pid_debugfs.c
75867 +++ b/net/mac80211/rc80211_pid_debugfs.c
75868 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75869
75870 spin_unlock_irqrestore(&events->lock, status);
75871
75872 - if (copy_to_user(buf, pb, p))
75873 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75874 return -EFAULT;
75875
75876 return p;
75877 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75878 index d5230ec..c604b21 100644
75879 --- a/net/mac80211/util.c
75880 +++ b/net/mac80211/util.c
75881 @@ -1000,7 +1000,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75882 drv_set_coverage_class(local, hw->wiphy->coverage_class);
75883
75884 /* everything else happens only if HW was up & running */
75885 - if (!local->open_count)
75886 + if (!local_read(&local->open_count))
75887 goto wake_up;
75888
75889 /*
75890 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75891 index d5597b7..ab6d39c 100644
75892 --- a/net/netfilter/Kconfig
75893 +++ b/net/netfilter/Kconfig
75894 @@ -779,6 +779,16 @@ config NETFILTER_XT_MATCH_ESP
75895
75896 To compile it as a module, choose M here. If unsure, say N.
75897
75898 +config NETFILTER_XT_MATCH_GRADM
75899 + tristate '"gradm" match support'
75900 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75901 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75902 + ---help---
75903 + The gradm match allows to match on grsecurity RBAC being enabled.
75904 + It is useful when iptables rules are applied early on bootup to
75905 + prevent connections to the machine (except from a trusted host)
75906 + while the RBAC system is disabled.
75907 +
75908 config NETFILTER_XT_MATCH_HASHLIMIT
75909 tristate '"hashlimit" match support'
75910 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75911 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75912 index 1a02853..5d8c22e 100644
75913 --- a/net/netfilter/Makefile
75914 +++ b/net/netfilter/Makefile
75915 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
75916 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75917 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75918 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75919 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75920 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75921 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75922 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75923 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75924 index 29fa5ba..8debc79 100644
75925 --- a/net/netfilter/ipvs/ip_vs_conn.c
75926 +++ b/net/netfilter/ipvs/ip_vs_conn.c
75927 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75928 /* Increase the refcnt counter of the dest */
75929 atomic_inc(&dest->refcnt);
75930
75931 - conn_flags = atomic_read(&dest->conn_flags);
75932 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
75933 if (cp->protocol != IPPROTO_UDP)
75934 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75935 /* Bind with the destination and its corresponding transmitter */
75936 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75937 atomic_set(&cp->refcnt, 1);
75938
75939 atomic_set(&cp->n_control, 0);
75940 - atomic_set(&cp->in_pkts, 0);
75941 + atomic_set_unchecked(&cp->in_pkts, 0);
75942
75943 atomic_inc(&ipvs->conn_count);
75944 if (flags & IP_VS_CONN_F_NO_CPORT)
75945 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75946
75947 /* Don't drop the entry if its number of incoming packets is not
75948 located in [0, 8] */
75949 - i = atomic_read(&cp->in_pkts);
75950 + i = atomic_read_unchecked(&cp->in_pkts);
75951 if (i > 8 || i < 0) return 0;
75952
75953 if (!todrop_rate[i]) return 0;
75954 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75955 index 6dc7d7d..e45913a 100644
75956 --- a/net/netfilter/ipvs/ip_vs_core.c
75957 +++ b/net/netfilter/ipvs/ip_vs_core.c
75958 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75959 ret = cp->packet_xmit(skb, cp, pd->pp);
75960 /* do not touch skb anymore */
75961
75962 - atomic_inc(&cp->in_pkts);
75963 + atomic_inc_unchecked(&cp->in_pkts);
75964 ip_vs_conn_put(cp);
75965 return ret;
75966 }
75967 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75968 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75969 pkts = sysctl_sync_threshold(ipvs);
75970 else
75971 - pkts = atomic_add_return(1, &cp->in_pkts);
75972 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75973
75974 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75975 cp->protocol == IPPROTO_SCTP) {
75976 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75977 index e1a66cf..0910076 100644
75978 --- a/net/netfilter/ipvs/ip_vs_ctl.c
75979 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
75980 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75981 ip_vs_rs_hash(ipvs, dest);
75982 write_unlock_bh(&ipvs->rs_lock);
75983 }
75984 - atomic_set(&dest->conn_flags, conn_flags);
75985 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
75986
75987 /* bind the service */
75988 if (!dest->svc) {
75989 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75990 " %-7s %-6d %-10d %-10d\n",
75991 &dest->addr.in6,
75992 ntohs(dest->port),
75993 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75994 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75995 atomic_read(&dest->weight),
75996 atomic_read(&dest->activeconns),
75997 atomic_read(&dest->inactconns));
75998 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75999 "%-7s %-6d %-10d %-10d\n",
76000 ntohl(dest->addr.ip),
76001 ntohs(dest->port),
76002 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76003 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76004 atomic_read(&dest->weight),
76005 atomic_read(&dest->activeconns),
76006 atomic_read(&dest->inactconns));
76007 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76008
76009 entry.addr = dest->addr.ip;
76010 entry.port = dest->port;
76011 - entry.conn_flags = atomic_read(&dest->conn_flags);
76012 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76013 entry.weight = atomic_read(&dest->weight);
76014 entry.u_threshold = dest->u_threshold;
76015 entry.l_threshold = dest->l_threshold;
76016 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76017 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76018
76019 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76020 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76021 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76022 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76023 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76024 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76025 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76026 index 2b6678c0..aaa41fc 100644
76027 --- a/net/netfilter/ipvs/ip_vs_sync.c
76028 +++ b/net/netfilter/ipvs/ip_vs_sync.c
76029 @@ -649,7 +649,7 @@ control:
76030 * i.e only increment in_pkts for Templates.
76031 */
76032 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76033 - int pkts = atomic_add_return(1, &cp->in_pkts);
76034 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76035
76036 if (pkts % sysctl_sync_period(ipvs) != 1)
76037 return;
76038 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76039
76040 if (opt)
76041 memcpy(&cp->in_seq, opt, sizeof(*opt));
76042 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76043 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76044 cp->state = state;
76045 cp->old_state = cp->state;
76046 /*
76047 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76048 index aa2d720..d8aa111 100644
76049 --- a/net/netfilter/ipvs/ip_vs_xmit.c
76050 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
76051 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76052 else
76053 rc = NF_ACCEPT;
76054 /* do not touch skb anymore */
76055 - atomic_inc(&cp->in_pkts);
76056 + atomic_inc_unchecked(&cp->in_pkts);
76057 goto out;
76058 }
76059
76060 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76061 else
76062 rc = NF_ACCEPT;
76063 /* do not touch skb anymore */
76064 - atomic_inc(&cp->in_pkts);
76065 + atomic_inc_unchecked(&cp->in_pkts);
76066 goto out;
76067 }
76068
76069 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76070 index 66b2c54..c7884e3 100644
76071 --- a/net/netfilter/nfnetlink_log.c
76072 +++ b/net/netfilter/nfnetlink_log.c
76073 @@ -70,7 +70,7 @@ struct nfulnl_instance {
76074 };
76075
76076 static DEFINE_SPINLOCK(instances_lock);
76077 -static atomic_t global_seq;
76078 +static atomic_unchecked_t global_seq;
76079
76080 #define INSTANCE_BUCKETS 16
76081 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76082 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76083 /* global sequence number */
76084 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76085 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76086 - htonl(atomic_inc_return(&global_seq)));
76087 + htonl(atomic_inc_return_unchecked(&global_seq)));
76088
76089 if (data_len) {
76090 struct nlattr *nla;
76091 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76092 new file mode 100644
76093 index 0000000..6905327
76094 --- /dev/null
76095 +++ b/net/netfilter/xt_gradm.c
76096 @@ -0,0 +1,51 @@
76097 +/*
76098 + * gradm match for netfilter
76099 + * Copyright © Zbigniew Krzystolik, 2010
76100 + *
76101 + * This program is free software; you can redistribute it and/or modify
76102 + * it under the terms of the GNU General Public License; either version
76103 + * 2 or 3 as published by the Free Software Foundation.
76104 + */
76105 +#include <linux/module.h>
76106 +#include <linux/moduleparam.h>
76107 +#include <linux/skbuff.h>
76108 +#include <linux/netfilter/x_tables.h>
76109 +#include <linux/grsecurity.h>
76110 +#include <linux/netfilter/xt_gradm.h>
76111 +
76112 +static bool
76113 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
76114 +{
76115 + const struct xt_gradm_mtinfo *info = par->matchinfo;
76116 + bool retval = false;
76117 + if (gr_acl_is_enabled())
76118 + retval = true;
76119 + return retval ^ info->invflags;
76120 +}
76121 +
76122 +static struct xt_match gradm_mt_reg __read_mostly = {
76123 + .name = "gradm",
76124 + .revision = 0,
76125 + .family = NFPROTO_UNSPEC,
76126 + .match = gradm_mt,
76127 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76128 + .me = THIS_MODULE,
76129 +};
76130 +
76131 +static int __init gradm_mt_init(void)
76132 +{
76133 + return xt_register_match(&gradm_mt_reg);
76134 +}
76135 +
76136 +static void __exit gradm_mt_exit(void)
76137 +{
76138 + xt_unregister_match(&gradm_mt_reg);
76139 +}
76140 +
76141 +module_init(gradm_mt_init);
76142 +module_exit(gradm_mt_exit);
76143 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
76144 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
76145 +MODULE_LICENSE("GPL");
76146 +MODULE_ALIAS("ipt_gradm");
76147 +MODULE_ALIAS("ip6t_gradm");
76148 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
76149 index 4fe4fb4..87a89e5 100644
76150 --- a/net/netfilter/xt_statistic.c
76151 +++ b/net/netfilter/xt_statistic.c
76152 @@ -19,7 +19,7 @@
76153 #include <linux/module.h>
76154
76155 struct xt_statistic_priv {
76156 - atomic_t count;
76157 + atomic_unchecked_t count;
76158 } ____cacheline_aligned_in_smp;
76159
76160 MODULE_LICENSE("GPL");
76161 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
76162 break;
76163 case XT_STATISTIC_MODE_NTH:
76164 do {
76165 - oval = atomic_read(&info->master->count);
76166 + oval = atomic_read_unchecked(&info->master->count);
76167 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
76168 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
76169 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
76170 if (nval == 0)
76171 ret = !ret;
76172 break;
76173 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
76174 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
76175 if (info->master == NULL)
76176 return -ENOMEM;
76177 - atomic_set(&info->master->count, info->u.nth.count);
76178 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
76179
76180 return 0;
76181 }
76182 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
76183 index 1201b6d..bcff8c6 100644
76184 --- a/net/netlink/af_netlink.c
76185 +++ b/net/netlink/af_netlink.c
76186 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
76187 sk->sk_error_report(sk);
76188 }
76189 }
76190 - atomic_inc(&sk->sk_drops);
76191 + atomic_inc_unchecked(&sk->sk_drops);
76192 }
76193
76194 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76195 @@ -1999,7 +1999,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
76196 sk_wmem_alloc_get(s),
76197 nlk->cb,
76198 atomic_read(&s->sk_refcnt),
76199 - atomic_read(&s->sk_drops),
76200 + atomic_read_unchecked(&s->sk_drops),
76201 sock_i_ino(s)
76202 );
76203
76204 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
76205 index 732152f..60bb09e 100644
76206 --- a/net/netrom/af_netrom.c
76207 +++ b/net/netrom/af_netrom.c
76208 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76209 struct sock *sk = sock->sk;
76210 struct nr_sock *nr = nr_sk(sk);
76211
76212 + memset(sax, 0, sizeof(*sax));
76213 lock_sock(sk);
76214 if (peer != 0) {
76215 if (sk->sk_state != TCP_ESTABLISHED) {
76216 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76217 *uaddr_len = sizeof(struct full_sockaddr_ax25);
76218 } else {
76219 sax->fsa_ax25.sax25_family = AF_NETROM;
76220 - sax->fsa_ax25.sax25_ndigis = 0;
76221 sax->fsa_ax25.sax25_call = nr->source_addr;
76222 *uaddr_len = sizeof(struct sockaddr_ax25);
76223 }
76224 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
76225 index d9d4970..d5a6a68 100644
76226 --- a/net/packet/af_packet.c
76227 +++ b/net/packet/af_packet.c
76228 @@ -1675,7 +1675,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76229
76230 spin_lock(&sk->sk_receive_queue.lock);
76231 po->stats.tp_packets++;
76232 - skb->dropcount = atomic_read(&sk->sk_drops);
76233 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76234 __skb_queue_tail(&sk->sk_receive_queue, skb);
76235 spin_unlock(&sk->sk_receive_queue.lock);
76236 sk->sk_data_ready(sk, skb->len);
76237 @@ -1684,7 +1684,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76238 drop_n_acct:
76239 spin_lock(&sk->sk_receive_queue.lock);
76240 po->stats.tp_drops++;
76241 - atomic_inc(&sk->sk_drops);
76242 + atomic_inc_unchecked(&sk->sk_drops);
76243 spin_unlock(&sk->sk_receive_queue.lock);
76244
76245 drop_n_restore:
76246 @@ -3266,7 +3266,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76247 case PACKET_HDRLEN:
76248 if (len > sizeof(int))
76249 len = sizeof(int);
76250 - if (copy_from_user(&val, optval, len))
76251 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
76252 return -EFAULT;
76253 switch (val) {
76254 case TPACKET_V1:
76255 @@ -3316,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76256
76257 if (put_user(len, optlen))
76258 return -EFAULT;
76259 - if (copy_to_user(optval, data, len))
76260 + if (len > sizeof(st) || copy_to_user(optval, data, len))
76261 return -EFAULT;
76262 return 0;
76263 }
76264 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
76265 index d65f699..05aa6ce 100644
76266 --- a/net/phonet/af_phonet.c
76267 +++ b/net/phonet/af_phonet.c
76268 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
76269 {
76270 struct phonet_protocol *pp;
76271
76272 - if (protocol >= PHONET_NPROTO)
76273 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76274 return NULL;
76275
76276 rcu_read_lock();
76277 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
76278 {
76279 int err = 0;
76280
76281 - if (protocol >= PHONET_NPROTO)
76282 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76283 return -EINVAL;
76284
76285 err = proto_register(pp->prot, 1);
76286 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
76287 index 2ba6e9f..409573f 100644
76288 --- a/net/phonet/pep.c
76289 +++ b/net/phonet/pep.c
76290 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76291
76292 case PNS_PEP_CTRL_REQ:
76293 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
76294 - atomic_inc(&sk->sk_drops);
76295 + atomic_inc_unchecked(&sk->sk_drops);
76296 break;
76297 }
76298 __skb_pull(skb, 4);
76299 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76300 }
76301
76302 if (pn->rx_credits == 0) {
76303 - atomic_inc(&sk->sk_drops);
76304 + atomic_inc_unchecked(&sk->sk_drops);
76305 err = -ENOBUFS;
76306 break;
76307 }
76308 @@ -557,7 +557,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
76309 }
76310
76311 if (pn->rx_credits == 0) {
76312 - atomic_inc(&sk->sk_drops);
76313 + atomic_inc_unchecked(&sk->sk_drops);
76314 err = NET_RX_DROP;
76315 break;
76316 }
76317 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
76318 index 4c7eff3..59c727f 100644
76319 --- a/net/phonet/socket.c
76320 +++ b/net/phonet/socket.c
76321 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
76322 pn->resource, sk->sk_state,
76323 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
76324 sock_i_uid(sk), sock_i_ino(sk),
76325 - atomic_read(&sk->sk_refcnt), sk,
76326 - atomic_read(&sk->sk_drops), &len);
76327 + atomic_read(&sk->sk_refcnt),
76328 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76329 + NULL,
76330 +#else
76331 + sk,
76332 +#endif
76333 + atomic_read_unchecked(&sk->sk_drops), &len);
76334 }
76335 seq_printf(seq, "%*s\n", 127 - len, "");
76336 return 0;
76337 diff --git a/net/rds/cong.c b/net/rds/cong.c
76338 index e5b65ac..f3b6fb7 100644
76339 --- a/net/rds/cong.c
76340 +++ b/net/rds/cong.c
76341 @@ -78,7 +78,7 @@
76342 * finds that the saved generation number is smaller than the global generation
76343 * number, it wakes up the process.
76344 */
76345 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
76346 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
76347
76348 /*
76349 * Congestion monitoring
76350 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
76351 rdsdebug("waking map %p for %pI4\n",
76352 map, &map->m_addr);
76353 rds_stats_inc(s_cong_update_received);
76354 - atomic_inc(&rds_cong_generation);
76355 + atomic_inc_unchecked(&rds_cong_generation);
76356 if (waitqueue_active(&map->m_waitq))
76357 wake_up(&map->m_waitq);
76358 if (waitqueue_active(&rds_poll_waitq))
76359 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
76360
76361 int rds_cong_updated_since(unsigned long *recent)
76362 {
76363 - unsigned long gen = atomic_read(&rds_cong_generation);
76364 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
76365
76366 if (likely(*recent == gen))
76367 return 0;
76368 diff --git a/net/rds/ib.h b/net/rds/ib.h
76369 index edfaaaf..8c89879 100644
76370 --- a/net/rds/ib.h
76371 +++ b/net/rds/ib.h
76372 @@ -128,7 +128,7 @@ struct rds_ib_connection {
76373 /* sending acks */
76374 unsigned long i_ack_flags;
76375 #ifdef KERNEL_HAS_ATOMIC64
76376 - atomic64_t i_ack_next; /* next ACK to send */
76377 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76378 #else
76379 spinlock_t i_ack_lock; /* protect i_ack_next */
76380 u64 i_ack_next; /* next ACK to send */
76381 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
76382 index 51c8689..36c555f 100644
76383 --- a/net/rds/ib_cm.c
76384 +++ b/net/rds/ib_cm.c
76385 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
76386 /* Clear the ACK state */
76387 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76388 #ifdef KERNEL_HAS_ATOMIC64
76389 - atomic64_set(&ic->i_ack_next, 0);
76390 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76391 #else
76392 ic->i_ack_next = 0;
76393 #endif
76394 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
76395 index e29e0ca..fa3a6a3 100644
76396 --- a/net/rds/ib_recv.c
76397 +++ b/net/rds/ib_recv.c
76398 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76399 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
76400 int ack_required)
76401 {
76402 - atomic64_set(&ic->i_ack_next, seq);
76403 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76404 if (ack_required) {
76405 smp_mb__before_clear_bit();
76406 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76407 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76408 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76409 smp_mb__after_clear_bit();
76410
76411 - return atomic64_read(&ic->i_ack_next);
76412 + return atomic64_read_unchecked(&ic->i_ack_next);
76413 }
76414 #endif
76415
76416 diff --git a/net/rds/iw.h b/net/rds/iw.h
76417 index 04ce3b1..48119a6 100644
76418 --- a/net/rds/iw.h
76419 +++ b/net/rds/iw.h
76420 @@ -134,7 +134,7 @@ struct rds_iw_connection {
76421 /* sending acks */
76422 unsigned long i_ack_flags;
76423 #ifdef KERNEL_HAS_ATOMIC64
76424 - atomic64_t i_ack_next; /* next ACK to send */
76425 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76426 #else
76427 spinlock_t i_ack_lock; /* protect i_ack_next */
76428 u64 i_ack_next; /* next ACK to send */
76429 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
76430 index 9556d28..f046d0e 100644
76431 --- a/net/rds/iw_cm.c
76432 +++ b/net/rds/iw_cm.c
76433 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
76434 /* Clear the ACK state */
76435 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76436 #ifdef KERNEL_HAS_ATOMIC64
76437 - atomic64_set(&ic->i_ack_next, 0);
76438 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76439 #else
76440 ic->i_ack_next = 0;
76441 #endif
76442 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
76443 index 5e57347..3916042 100644
76444 --- a/net/rds/iw_recv.c
76445 +++ b/net/rds/iw_recv.c
76446 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76447 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
76448 int ack_required)
76449 {
76450 - atomic64_set(&ic->i_ack_next, seq);
76451 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76452 if (ack_required) {
76453 smp_mb__before_clear_bit();
76454 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76455 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76456 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76457 smp_mb__after_clear_bit();
76458
76459 - return atomic64_read(&ic->i_ack_next);
76460 + return atomic64_read_unchecked(&ic->i_ack_next);
76461 }
76462 #endif
76463
76464 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
76465 index edac9ef..16bcb98 100644
76466 --- a/net/rds/tcp.c
76467 +++ b/net/rds/tcp.c
76468 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
76469 int val = 1;
76470
76471 set_fs(KERNEL_DS);
76472 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
76473 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
76474 sizeof(val));
76475 set_fs(oldfs);
76476 }
76477 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
76478 index 1b4fd68..2234175 100644
76479 --- a/net/rds/tcp_send.c
76480 +++ b/net/rds/tcp_send.c
76481 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
76482
76483 oldfs = get_fs();
76484 set_fs(KERNEL_DS);
76485 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
76486 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
76487 sizeof(val));
76488 set_fs(oldfs);
76489 }
76490 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
76491 index 74c064c..fdec26f 100644
76492 --- a/net/rxrpc/af_rxrpc.c
76493 +++ b/net/rxrpc/af_rxrpc.c
76494 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
76495 __be32 rxrpc_epoch;
76496
76497 /* current debugging ID */
76498 -atomic_t rxrpc_debug_id;
76499 +atomic_unchecked_t rxrpc_debug_id;
76500
76501 /* count of skbs currently in use */
76502 atomic_t rxrpc_n_skbs;
76503 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
76504 index f99cfce..cc529dd 100644
76505 --- a/net/rxrpc/ar-ack.c
76506 +++ b/net/rxrpc/ar-ack.c
76507 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76508
76509 _enter("{%d,%d,%d,%d},",
76510 call->acks_hard, call->acks_unacked,
76511 - atomic_read(&call->sequence),
76512 + atomic_read_unchecked(&call->sequence),
76513 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
76514
76515 stop = 0;
76516 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76517
76518 /* each Tx packet has a new serial number */
76519 sp->hdr.serial =
76520 - htonl(atomic_inc_return(&call->conn->serial));
76521 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
76522
76523 hdr = (struct rxrpc_header *) txb->head;
76524 hdr->serial = sp->hdr.serial;
76525 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
76526 */
76527 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
76528 {
76529 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
76530 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
76531 }
76532
76533 /*
76534 @@ -629,7 +629,7 @@ process_further:
76535
76536 latest = ntohl(sp->hdr.serial);
76537 hard = ntohl(ack.firstPacket);
76538 - tx = atomic_read(&call->sequence);
76539 + tx = atomic_read_unchecked(&call->sequence);
76540
76541 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76542 latest,
76543 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
76544 goto maybe_reschedule;
76545
76546 send_ACK_with_skew:
76547 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
76548 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
76549 ntohl(ack.serial));
76550 send_ACK:
76551 mtu = call->conn->trans->peer->if_mtu;
76552 @@ -1173,7 +1173,7 @@ send_ACK:
76553 ackinfo.rxMTU = htonl(5692);
76554 ackinfo.jumbo_max = htonl(4);
76555
76556 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76557 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76558 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76559 ntohl(hdr.serial),
76560 ntohs(ack.maxSkew),
76561 @@ -1191,7 +1191,7 @@ send_ACK:
76562 send_message:
76563 _debug("send message");
76564
76565 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76566 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76567 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
76568 send_message_2:
76569
76570 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
76571 index bf656c2..48f9d27 100644
76572 --- a/net/rxrpc/ar-call.c
76573 +++ b/net/rxrpc/ar-call.c
76574 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
76575 spin_lock_init(&call->lock);
76576 rwlock_init(&call->state_lock);
76577 atomic_set(&call->usage, 1);
76578 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
76579 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76580 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
76581
76582 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
76583 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
76584 index 4106ca9..a338d7a 100644
76585 --- a/net/rxrpc/ar-connection.c
76586 +++ b/net/rxrpc/ar-connection.c
76587 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
76588 rwlock_init(&conn->lock);
76589 spin_lock_init(&conn->state_lock);
76590 atomic_set(&conn->usage, 1);
76591 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
76592 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76593 conn->avail_calls = RXRPC_MAXCALLS;
76594 conn->size_align = 4;
76595 conn->header_size = sizeof(struct rxrpc_header);
76596 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
76597 index e7ed43a..6afa140 100644
76598 --- a/net/rxrpc/ar-connevent.c
76599 +++ b/net/rxrpc/ar-connevent.c
76600 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
76601
76602 len = iov[0].iov_len + iov[1].iov_len;
76603
76604 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76605 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76606 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
76607
76608 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76609 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
76610 index 1a2b0633..e8d1382 100644
76611 --- a/net/rxrpc/ar-input.c
76612 +++ b/net/rxrpc/ar-input.c
76613 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
76614 /* track the latest serial number on this connection for ACK packet
76615 * information */
76616 serial = ntohl(sp->hdr.serial);
76617 - hi_serial = atomic_read(&call->conn->hi_serial);
76618 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
76619 while (serial > hi_serial)
76620 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
76621 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
76622 serial);
76623
76624 /* request ACK generation for any ACK or DATA packet that requests
76625 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
76626 index 8e22bd3..f66d1c0 100644
76627 --- a/net/rxrpc/ar-internal.h
76628 +++ b/net/rxrpc/ar-internal.h
76629 @@ -272,8 +272,8 @@ struct rxrpc_connection {
76630 int error; /* error code for local abort */
76631 int debug_id; /* debug ID for printks */
76632 unsigned call_counter; /* call ID counter */
76633 - atomic_t serial; /* packet serial number counter */
76634 - atomic_t hi_serial; /* highest serial number received */
76635 + atomic_unchecked_t serial; /* packet serial number counter */
76636 + atomic_unchecked_t hi_serial; /* highest serial number received */
76637 u8 avail_calls; /* number of calls available */
76638 u8 size_align; /* data size alignment (for security) */
76639 u8 header_size; /* rxrpc + security header size */
76640 @@ -346,7 +346,7 @@ struct rxrpc_call {
76641 spinlock_t lock;
76642 rwlock_t state_lock; /* lock for state transition */
76643 atomic_t usage;
76644 - atomic_t sequence; /* Tx data packet sequence counter */
76645 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
76646 u32 abort_code; /* local/remote abort code */
76647 enum { /* current state of call */
76648 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
76649 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
76650 */
76651 extern atomic_t rxrpc_n_skbs;
76652 extern __be32 rxrpc_epoch;
76653 -extern atomic_t rxrpc_debug_id;
76654 +extern atomic_unchecked_t rxrpc_debug_id;
76655 extern struct workqueue_struct *rxrpc_workqueue;
76656
76657 /*
76658 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
76659 index 87f7135..74d3703 100644
76660 --- a/net/rxrpc/ar-local.c
76661 +++ b/net/rxrpc/ar-local.c
76662 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
76663 spin_lock_init(&local->lock);
76664 rwlock_init(&local->services_lock);
76665 atomic_set(&local->usage, 1);
76666 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
76667 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76668 memcpy(&local->srx, srx, sizeof(*srx));
76669 }
76670
76671 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
76672 index 338d793..47391d0 100644
76673 --- a/net/rxrpc/ar-output.c
76674 +++ b/net/rxrpc/ar-output.c
76675 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
76676 sp->hdr.cid = call->cid;
76677 sp->hdr.callNumber = call->call_id;
76678 sp->hdr.seq =
76679 - htonl(atomic_inc_return(&call->sequence));
76680 + htonl(atomic_inc_return_unchecked(&call->sequence));
76681 sp->hdr.serial =
76682 - htonl(atomic_inc_return(&conn->serial));
76683 + htonl(atomic_inc_return_unchecked(&conn->serial));
76684 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
76685 sp->hdr.userStatus = 0;
76686 sp->hdr.securityIndex = conn->security_ix;
76687 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
76688 index 2754f09..b20e38f 100644
76689 --- a/net/rxrpc/ar-peer.c
76690 +++ b/net/rxrpc/ar-peer.c
76691 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
76692 INIT_LIST_HEAD(&peer->error_targets);
76693 spin_lock_init(&peer->lock);
76694 atomic_set(&peer->usage, 1);
76695 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
76696 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76697 memcpy(&peer->srx, srx, sizeof(*srx));
76698
76699 rxrpc_assess_MTU_size(peer);
76700 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
76701 index 38047f7..9f48511 100644
76702 --- a/net/rxrpc/ar-proc.c
76703 +++ b/net/rxrpc/ar-proc.c
76704 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
76705 atomic_read(&conn->usage),
76706 rxrpc_conn_states[conn->state],
76707 key_serial(conn->key),
76708 - atomic_read(&conn->serial),
76709 - atomic_read(&conn->hi_serial));
76710 + atomic_read_unchecked(&conn->serial),
76711 + atomic_read_unchecked(&conn->hi_serial));
76712
76713 return 0;
76714 }
76715 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
76716 index 92df566..87ec1bf 100644
76717 --- a/net/rxrpc/ar-transport.c
76718 +++ b/net/rxrpc/ar-transport.c
76719 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
76720 spin_lock_init(&trans->client_lock);
76721 rwlock_init(&trans->conn_lock);
76722 atomic_set(&trans->usage, 1);
76723 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
76724 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76725
76726 if (peer->srx.transport.family == AF_INET) {
76727 switch (peer->srx.transport_type) {
76728 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
76729 index 7635107..4670276 100644
76730 --- a/net/rxrpc/rxkad.c
76731 +++ b/net/rxrpc/rxkad.c
76732 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
76733
76734 len = iov[0].iov_len + iov[1].iov_len;
76735
76736 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76737 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76738 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
76739
76740 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76741 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
76742
76743 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
76744
76745 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
76746 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76747 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
76748
76749 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
76750 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
76751 index 1e2eee8..ce3967e 100644
76752 --- a/net/sctp/proc.c
76753 +++ b/net/sctp/proc.c
76754 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
76755 seq_printf(seq,
76756 "%8pK %8pK %-3d %-3d %-2d %-4d "
76757 "%4d %8d %8d %7d %5lu %-5d %5d ",
76758 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
76759 + assoc, sk,
76760 + sctp_sk(sk)->type, sk->sk_state,
76761 assoc->state, hash,
76762 assoc->assoc_id,
76763 assoc->sndbuf_used,
76764 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
76765 index 54a7cd2..944edae 100644
76766 --- a/net/sctp/socket.c
76767 +++ b/net/sctp/socket.c
76768 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
76769 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
76770 if (space_left < addrlen)
76771 return -ENOMEM;
76772 - if (copy_to_user(to, &temp, addrlen))
76773 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
76774 return -EFAULT;
76775 to += addrlen;
76776 cnt++;
76777 diff --git a/net/socket.c b/net/socket.c
76778 index 2dce67a..1e91168 100644
76779 --- a/net/socket.c
76780 +++ b/net/socket.c
76781 @@ -88,6 +88,7 @@
76782 #include <linux/nsproxy.h>
76783 #include <linux/magic.h>
76784 #include <linux/slab.h>
76785 +#include <linux/in.h>
76786
76787 #include <asm/uaccess.h>
76788 #include <asm/unistd.h>
76789 @@ -105,6 +106,8 @@
76790 #include <linux/sockios.h>
76791 #include <linux/atalk.h>
76792
76793 +#include <linux/grsock.h>
76794 +
76795 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
76796 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
76797 unsigned long nr_segs, loff_t pos);
76798 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
76799 &sockfs_dentry_operations, SOCKFS_MAGIC);
76800 }
76801
76802 -static struct vfsmount *sock_mnt __read_mostly;
76803 +struct vfsmount *sock_mnt __read_mostly;
76804
76805 static struct file_system_type sock_fs_type = {
76806 .name = "sockfs",
76807 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
76808 return -EAFNOSUPPORT;
76809 if (type < 0 || type >= SOCK_MAX)
76810 return -EINVAL;
76811 + if (protocol < 0)
76812 + return -EINVAL;
76813
76814 /* Compatibility.
76815
76816 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
76817 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
76818 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
76819
76820 + if(!gr_search_socket(family, type, protocol)) {
76821 + retval = -EACCES;
76822 + goto out;
76823 + }
76824 +
76825 + if (gr_handle_sock_all(family, type, protocol)) {
76826 + retval = -EACCES;
76827 + goto out;
76828 + }
76829 +
76830 retval = sock_create(family, type, protocol, &sock);
76831 if (retval < 0)
76832 goto out;
76833 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76834 if (sock) {
76835 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
76836 if (err >= 0) {
76837 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
76838 + err = -EACCES;
76839 + goto error;
76840 + }
76841 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
76842 + if (err)
76843 + goto error;
76844 +
76845 err = security_socket_bind(sock,
76846 (struct sockaddr *)&address,
76847 addrlen);
76848 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76849 (struct sockaddr *)
76850 &address, addrlen);
76851 }
76852 +error:
76853 fput_light(sock->file, fput_needed);
76854 }
76855 return err;
76856 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
76857 if ((unsigned)backlog > somaxconn)
76858 backlog = somaxconn;
76859
76860 + if (gr_handle_sock_server_other(sock->sk)) {
76861 + err = -EPERM;
76862 + goto error;
76863 + }
76864 +
76865 + err = gr_search_listen(sock);
76866 + if (err)
76867 + goto error;
76868 +
76869 err = security_socket_listen(sock, backlog);
76870 if (!err)
76871 err = sock->ops->listen(sock, backlog);
76872
76873 +error:
76874 fput_light(sock->file, fput_needed);
76875 }
76876 return err;
76877 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76878 newsock->type = sock->type;
76879 newsock->ops = sock->ops;
76880
76881 + if (gr_handle_sock_server_other(sock->sk)) {
76882 + err = -EPERM;
76883 + sock_release(newsock);
76884 + goto out_put;
76885 + }
76886 +
76887 + err = gr_search_accept(sock);
76888 + if (err) {
76889 + sock_release(newsock);
76890 + goto out_put;
76891 + }
76892 +
76893 /*
76894 * We don't need try_module_get here, as the listening socket (sock)
76895 * has the protocol module (sock->ops->owner) held.
76896 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76897 fd_install(newfd, newfile);
76898 err = newfd;
76899
76900 + gr_attach_curr_ip(newsock->sk);
76901 +
76902 out_put:
76903 fput_light(sock->file, fput_needed);
76904 out:
76905 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76906 int, addrlen)
76907 {
76908 struct socket *sock;
76909 + struct sockaddr *sck;
76910 struct sockaddr_storage address;
76911 int err, fput_needed;
76912
76913 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76914 if (err < 0)
76915 goto out_put;
76916
76917 + sck = (struct sockaddr *)&address;
76918 +
76919 + if (gr_handle_sock_client(sck)) {
76920 + err = -EACCES;
76921 + goto out_put;
76922 + }
76923 +
76924 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
76925 + if (err)
76926 + goto out_put;
76927 +
76928 err =
76929 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
76930 if (err)
76931 @@ -1950,7 +2010,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
76932 * checking falls down on this.
76933 */
76934 if (copy_from_user(ctl_buf,
76935 - (void __user __force *)msg_sys->msg_control,
76936 + (void __force_user *)msg_sys->msg_control,
76937 ctl_len))
76938 goto out_freectl;
76939 msg_sys->msg_control = ctl_buf;
76940 @@ -2120,7 +2180,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
76941 * kernel msghdr to use the kernel address space)
76942 */
76943
76944 - uaddr = (__force void __user *)msg_sys->msg_name;
76945 + uaddr = (void __force_user *)msg_sys->msg_name;
76946 uaddr_len = COMPAT_NAMELEN(msg);
76947 if (MSG_CMSG_COMPAT & flags) {
76948 err = verify_compat_iovec(msg_sys, iov,
76949 @@ -2748,7 +2808,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76950 }
76951
76952 ifr = compat_alloc_user_space(buf_size);
76953 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
76954 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
76955
76956 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
76957 return -EFAULT;
76958 @@ -2772,12 +2832,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76959 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
76960
76961 if (copy_in_user(rxnfc, compat_rxnfc,
76962 - (void *)(&rxnfc->fs.m_ext + 1) -
76963 - (void *)rxnfc) ||
76964 + (void __user *)(&rxnfc->fs.m_ext + 1) -
76965 + (void __user *)rxnfc) ||
76966 copy_in_user(&rxnfc->fs.ring_cookie,
76967 &compat_rxnfc->fs.ring_cookie,
76968 - (void *)(&rxnfc->fs.location + 1) -
76969 - (void *)&rxnfc->fs.ring_cookie) ||
76970 + (void __user *)(&rxnfc->fs.location + 1) -
76971 + (void __user *)&rxnfc->fs.ring_cookie) ||
76972 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
76973 sizeof(rxnfc->rule_cnt)))
76974 return -EFAULT;
76975 @@ -2789,12 +2849,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76976
76977 if (convert_out) {
76978 if (copy_in_user(compat_rxnfc, rxnfc,
76979 - (const void *)(&rxnfc->fs.m_ext + 1) -
76980 - (const void *)rxnfc) ||
76981 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
76982 + (const void __user *)rxnfc) ||
76983 copy_in_user(&compat_rxnfc->fs.ring_cookie,
76984 &rxnfc->fs.ring_cookie,
76985 - (const void *)(&rxnfc->fs.location + 1) -
76986 - (const void *)&rxnfc->fs.ring_cookie) ||
76987 + (const void __user *)(&rxnfc->fs.location + 1) -
76988 + (const void __user *)&rxnfc->fs.ring_cookie) ||
76989 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
76990 sizeof(rxnfc->rule_cnt)))
76991 return -EFAULT;
76992 @@ -2864,7 +2924,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
76993 old_fs = get_fs();
76994 set_fs(KERNEL_DS);
76995 err = dev_ioctl(net, cmd,
76996 - (struct ifreq __user __force *) &kifr);
76997 + (struct ifreq __force_user *) &kifr);
76998 set_fs(old_fs);
76999
77000 return err;
77001 @@ -2973,7 +3033,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
77002
77003 old_fs = get_fs();
77004 set_fs(KERNEL_DS);
77005 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
77006 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
77007 set_fs(old_fs);
77008
77009 if (cmd == SIOCGIFMAP && !err) {
77010 @@ -3078,7 +3138,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
77011 ret |= __get_user(rtdev, &(ur4->rt_dev));
77012 if (rtdev) {
77013 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
77014 - r4.rt_dev = (char __user __force *)devname;
77015 + r4.rt_dev = (char __force_user *)devname;
77016 devname[15] = 0;
77017 } else
77018 r4.rt_dev = NULL;
77019 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
77020 int __user *uoptlen;
77021 int err;
77022
77023 - uoptval = (char __user __force *) optval;
77024 - uoptlen = (int __user __force *) optlen;
77025 + uoptval = (char __force_user *) optval;
77026 + uoptlen = (int __force_user *) optlen;
77027
77028 set_fs(KERNEL_DS);
77029 if (level == SOL_SOCKET)
77030 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
77031 char __user *uoptval;
77032 int err;
77033
77034 - uoptval = (char __user __force *) optval;
77035 + uoptval = (char __force_user *) optval;
77036
77037 set_fs(KERNEL_DS);
77038 if (level == SOL_SOCKET)
77039 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
77040 index 00a1a2a..6a0138a 100644
77041 --- a/net/sunrpc/sched.c
77042 +++ b/net/sunrpc/sched.c
77043 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
77044 #ifdef RPC_DEBUG
77045 static void rpc_task_set_debuginfo(struct rpc_task *task)
77046 {
77047 - static atomic_t rpc_pid;
77048 + static atomic_unchecked_t rpc_pid;
77049
77050 - task->tk_pid = atomic_inc_return(&rpc_pid);
77051 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
77052 }
77053 #else
77054 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
77055 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
77056 index 71bed1c..5dff36d 100644
77057 --- a/net/sunrpc/svcsock.c
77058 +++ b/net/sunrpc/svcsock.c
77059 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
77060 int buflen, unsigned int base)
77061 {
77062 size_t save_iovlen;
77063 - void __user *save_iovbase;
77064 + void *save_iovbase;
77065 unsigned int i;
77066 int ret;
77067
77068 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
77069 index 09af4fa..77110a9 100644
77070 --- a/net/sunrpc/xprtrdma/svc_rdma.c
77071 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
77072 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
77073 static unsigned int min_max_inline = 4096;
77074 static unsigned int max_max_inline = 65536;
77075
77076 -atomic_t rdma_stat_recv;
77077 -atomic_t rdma_stat_read;
77078 -atomic_t rdma_stat_write;
77079 -atomic_t rdma_stat_sq_starve;
77080 -atomic_t rdma_stat_rq_starve;
77081 -atomic_t rdma_stat_rq_poll;
77082 -atomic_t rdma_stat_rq_prod;
77083 -atomic_t rdma_stat_sq_poll;
77084 -atomic_t rdma_stat_sq_prod;
77085 +atomic_unchecked_t rdma_stat_recv;
77086 +atomic_unchecked_t rdma_stat_read;
77087 +atomic_unchecked_t rdma_stat_write;
77088 +atomic_unchecked_t rdma_stat_sq_starve;
77089 +atomic_unchecked_t rdma_stat_rq_starve;
77090 +atomic_unchecked_t rdma_stat_rq_poll;
77091 +atomic_unchecked_t rdma_stat_rq_prod;
77092 +atomic_unchecked_t rdma_stat_sq_poll;
77093 +atomic_unchecked_t rdma_stat_sq_prod;
77094
77095 /* Temporary NFS request map and context caches */
77096 struct kmem_cache *svc_rdma_map_cachep;
77097 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
77098 len -= *ppos;
77099 if (len > *lenp)
77100 len = *lenp;
77101 - if (len && copy_to_user(buffer, str_buf, len))
77102 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
77103 return -EFAULT;
77104 *lenp = len;
77105 *ppos += len;
77106 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
77107 {
77108 .procname = "rdma_stat_read",
77109 .data = &rdma_stat_read,
77110 - .maxlen = sizeof(atomic_t),
77111 + .maxlen = sizeof(atomic_unchecked_t),
77112 .mode = 0644,
77113 .proc_handler = read_reset_stat,
77114 },
77115 {
77116 .procname = "rdma_stat_recv",
77117 .data = &rdma_stat_recv,
77118 - .maxlen = sizeof(atomic_t),
77119 + .maxlen = sizeof(atomic_unchecked_t),
77120 .mode = 0644,
77121 .proc_handler = read_reset_stat,
77122 },
77123 {
77124 .procname = "rdma_stat_write",
77125 .data = &rdma_stat_write,
77126 - .maxlen = sizeof(atomic_t),
77127 + .maxlen = sizeof(atomic_unchecked_t),
77128 .mode = 0644,
77129 .proc_handler = read_reset_stat,
77130 },
77131 {
77132 .procname = "rdma_stat_sq_starve",
77133 .data = &rdma_stat_sq_starve,
77134 - .maxlen = sizeof(atomic_t),
77135 + .maxlen = sizeof(atomic_unchecked_t),
77136 .mode = 0644,
77137 .proc_handler = read_reset_stat,
77138 },
77139 {
77140 .procname = "rdma_stat_rq_starve",
77141 .data = &rdma_stat_rq_starve,
77142 - .maxlen = sizeof(atomic_t),
77143 + .maxlen = sizeof(atomic_unchecked_t),
77144 .mode = 0644,
77145 .proc_handler = read_reset_stat,
77146 },
77147 {
77148 .procname = "rdma_stat_rq_poll",
77149 .data = &rdma_stat_rq_poll,
77150 - .maxlen = sizeof(atomic_t),
77151 + .maxlen = sizeof(atomic_unchecked_t),
77152 .mode = 0644,
77153 .proc_handler = read_reset_stat,
77154 },
77155 {
77156 .procname = "rdma_stat_rq_prod",
77157 .data = &rdma_stat_rq_prod,
77158 - .maxlen = sizeof(atomic_t),
77159 + .maxlen = sizeof(atomic_unchecked_t),
77160 .mode = 0644,
77161 .proc_handler = read_reset_stat,
77162 },
77163 {
77164 .procname = "rdma_stat_sq_poll",
77165 .data = &rdma_stat_sq_poll,
77166 - .maxlen = sizeof(atomic_t),
77167 + .maxlen = sizeof(atomic_unchecked_t),
77168 .mode = 0644,
77169 .proc_handler = read_reset_stat,
77170 },
77171 {
77172 .procname = "rdma_stat_sq_prod",
77173 .data = &rdma_stat_sq_prod,
77174 - .maxlen = sizeof(atomic_t),
77175 + .maxlen = sizeof(atomic_unchecked_t),
77176 .mode = 0644,
77177 .proc_handler = read_reset_stat,
77178 },
77179 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77180 index df67211..c354b13 100644
77181 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77182 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77183 @@ -499,7 +499,7 @@ next_sge:
77184 svc_rdma_put_context(ctxt, 0);
77185 goto out;
77186 }
77187 - atomic_inc(&rdma_stat_read);
77188 + atomic_inc_unchecked(&rdma_stat_read);
77189
77190 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
77191 chl_map->ch[ch_no].count -= read_wr.num_sge;
77192 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77193 dto_q);
77194 list_del_init(&ctxt->dto_q);
77195 } else {
77196 - atomic_inc(&rdma_stat_rq_starve);
77197 + atomic_inc_unchecked(&rdma_stat_rq_starve);
77198 clear_bit(XPT_DATA, &xprt->xpt_flags);
77199 ctxt = NULL;
77200 }
77201 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77202 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
77203 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
77204 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
77205 - atomic_inc(&rdma_stat_recv);
77206 + atomic_inc_unchecked(&rdma_stat_recv);
77207
77208 /* Build up the XDR from the receive buffers. */
77209 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
77210 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77211 index 249a835..fb2794b 100644
77212 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77213 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77214 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
77215 write_wr.wr.rdma.remote_addr = to;
77216
77217 /* Post It */
77218 - atomic_inc(&rdma_stat_write);
77219 + atomic_inc_unchecked(&rdma_stat_write);
77220 if (svc_rdma_send(xprt, &write_wr))
77221 goto err;
77222 return 0;
77223 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77224 index ba1296d..0fec1a5 100644
77225 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
77226 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77227 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77228 return;
77229
77230 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
77231 - atomic_inc(&rdma_stat_rq_poll);
77232 + atomic_inc_unchecked(&rdma_stat_rq_poll);
77233
77234 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
77235 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
77236 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77237 }
77238
77239 if (ctxt)
77240 - atomic_inc(&rdma_stat_rq_prod);
77241 + atomic_inc_unchecked(&rdma_stat_rq_prod);
77242
77243 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
77244 /*
77245 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77246 return;
77247
77248 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
77249 - atomic_inc(&rdma_stat_sq_poll);
77250 + atomic_inc_unchecked(&rdma_stat_sq_poll);
77251 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
77252 if (wc.status != IB_WC_SUCCESS)
77253 /* Close the transport */
77254 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77255 }
77256
77257 if (ctxt)
77258 - atomic_inc(&rdma_stat_sq_prod);
77259 + atomic_inc_unchecked(&rdma_stat_sq_prod);
77260 }
77261
77262 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
77263 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
77264 spin_lock_bh(&xprt->sc_lock);
77265 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
77266 spin_unlock_bh(&xprt->sc_lock);
77267 - atomic_inc(&rdma_stat_sq_starve);
77268 + atomic_inc_unchecked(&rdma_stat_sq_starve);
77269
77270 /* See if we can opportunistically reap SQ WR to make room */
77271 sq_cq_reap(xprt);
77272 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
77273 index e758139..d29ea47 100644
77274 --- a/net/sysctl_net.c
77275 +++ b/net/sysctl_net.c
77276 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
77277 struct ctl_table *table)
77278 {
77279 /* Allow network administrator to have same access as root. */
77280 - if (capable(CAP_NET_ADMIN)) {
77281 + if (capable_nolog(CAP_NET_ADMIN)) {
77282 int mode = (table->mode >> 6) & 7;
77283 return (mode << 6) | (mode << 3) | mode;
77284 }
77285 diff --git a/net/tipc/link.c b/net/tipc/link.c
77286 index ae98a72..7bb6056 100644
77287 --- a/net/tipc/link.c
77288 +++ b/net/tipc/link.c
77289 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
77290 struct tipc_msg fragm_hdr;
77291 struct sk_buff *buf, *buf_chain, *prev;
77292 u32 fragm_crs, fragm_rest, hsz, sect_rest;
77293 - const unchar *sect_crs;
77294 + const unchar __user *sect_crs;
77295 int curr_sect;
77296 u32 fragm_no;
77297
77298 @@ -1247,7 +1247,7 @@ again:
77299
77300 if (!sect_rest) {
77301 sect_rest = msg_sect[++curr_sect].iov_len;
77302 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
77303 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
77304 }
77305
77306 if (sect_rest < fragm_rest)
77307 @@ -1266,7 +1266,7 @@ error:
77308 }
77309 } else
77310 skb_copy_to_linear_data_offset(buf, fragm_crs,
77311 - sect_crs, sz);
77312 + (const void __force_kernel *)sect_crs, sz);
77313 sect_crs += sz;
77314 sect_rest -= sz;
77315 fragm_crs += sz;
77316 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
77317 index 83d5096..dcba497 100644
77318 --- a/net/tipc/msg.c
77319 +++ b/net/tipc/msg.c
77320 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
77321 msg_sect[cnt].iov_len);
77322 else
77323 skb_copy_to_linear_data_offset(*buf, pos,
77324 - msg_sect[cnt].iov_base,
77325 + (const void __force_kernel *)msg_sect[cnt].iov_base,
77326 msg_sect[cnt].iov_len);
77327 pos += msg_sect[cnt].iov_len;
77328 }
77329 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
77330 index 1983717..4d6102c 100644
77331 --- a/net/tipc/subscr.c
77332 +++ b/net/tipc/subscr.c
77333 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
77334 {
77335 struct iovec msg_sect;
77336
77337 - msg_sect.iov_base = (void *)&sub->evt;
77338 + msg_sect.iov_base = (void __force_user *)&sub->evt;
77339 msg_sect.iov_len = sizeof(struct tipc_event);
77340
77341 sub->evt.event = htohl(event, sub->swap);
77342 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
77343 index d99678a..3514a21 100644
77344 --- a/net/unix/af_unix.c
77345 +++ b/net/unix/af_unix.c
77346 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
77347 err = -ECONNREFUSED;
77348 if (!S_ISSOCK(inode->i_mode))
77349 goto put_fail;
77350 +
77351 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
77352 + err = -EACCES;
77353 + goto put_fail;
77354 + }
77355 +
77356 u = unix_find_socket_byinode(inode);
77357 if (!u)
77358 goto put_fail;
77359 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
77360 if (u) {
77361 struct dentry *dentry;
77362 dentry = unix_sk(u)->dentry;
77363 +
77364 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
77365 + err = -EPERM;
77366 + sock_put(u);
77367 + goto fail;
77368 + }
77369 +
77370 if (dentry)
77371 touch_atime(unix_sk(u)->mnt, dentry);
77372 } else
77373 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
77374 err = security_path_mknod(&path, dentry, mode, 0);
77375 if (err)
77376 goto out_mknod_drop_write;
77377 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
77378 + err = -EACCES;
77379 + goto out_mknod_drop_write;
77380 + }
77381 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
77382 out_mknod_drop_write:
77383 mnt_drop_write(path.mnt);
77384 if (err)
77385 goto out_mknod_dput;
77386 +
77387 + gr_handle_create(dentry, path.mnt);
77388 +
77389 mutex_unlock(&path.dentry->d_inode->i_mutex);
77390 dput(path.dentry);
77391 path.dentry = dentry;
77392 diff --git a/net/wireless/core.h b/net/wireless/core.h
77393 index b9ec306..b4a563e 100644
77394 --- a/net/wireless/core.h
77395 +++ b/net/wireless/core.h
77396 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
77397 struct mutex mtx;
77398
77399 /* rfkill support */
77400 - struct rfkill_ops rfkill_ops;
77401 + rfkill_ops_no_const rfkill_ops;
77402 struct rfkill *rfkill;
77403 struct work_struct rfkill_sync;
77404
77405 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
77406 index 0af7f54..c916d2f 100644
77407 --- a/net/wireless/wext-core.c
77408 +++ b/net/wireless/wext-core.c
77409 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77410 */
77411
77412 /* Support for very large requests */
77413 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
77414 - (user_length > descr->max_tokens)) {
77415 + if (user_length > descr->max_tokens) {
77416 /* Allow userspace to GET more than max so
77417 * we can support any size GET requests.
77418 * There is still a limit : -ENOMEM.
77419 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77420 }
77421 }
77422
77423 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
77424 - /*
77425 - * If this is a GET, but not NOMAX, it means that the extra
77426 - * data is not bounded by userspace, but by max_tokens. Thus
77427 - * set the length to max_tokens. This matches the extra data
77428 - * allocation.
77429 - * The driver should fill it with the number of tokens it
77430 - * provided, and it may check iwp->length rather than having
77431 - * knowledge of max_tokens. If the driver doesn't change the
77432 - * iwp->length, this ioctl just copies back max_token tokens
77433 - * filled with zeroes. Hopefully the driver isn't claiming
77434 - * them to be valid data.
77435 - */
77436 - iwp->length = descr->max_tokens;
77437 - }
77438 -
77439 err = handler(dev, info, (union iwreq_data *) iwp, extra);
77440
77441 iwp->length += essid_compat;
77442 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
77443 index 9049a5c..cfa6f5c 100644
77444 --- a/net/xfrm/xfrm_policy.c
77445 +++ b/net/xfrm/xfrm_policy.c
77446 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
77447 {
77448 policy->walk.dead = 1;
77449
77450 - atomic_inc(&policy->genid);
77451 + atomic_inc_unchecked(&policy->genid);
77452
77453 if (del_timer(&policy->timer))
77454 xfrm_pol_put(policy);
77455 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
77456 hlist_add_head(&policy->bydst, chain);
77457 xfrm_pol_hold(policy);
77458 net->xfrm.policy_count[dir]++;
77459 - atomic_inc(&flow_cache_genid);
77460 + atomic_inc_unchecked(&flow_cache_genid);
77461 if (delpol)
77462 __xfrm_policy_unlink(delpol, dir);
77463 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
77464 @@ -1530,7 +1530,7 @@ free_dst:
77465 goto out;
77466 }
77467
77468 -static int inline
77469 +static inline int
77470 xfrm_dst_alloc_copy(void **target, const void *src, int size)
77471 {
77472 if (!*target) {
77473 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
77474 return 0;
77475 }
77476
77477 -static int inline
77478 +static inline int
77479 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77480 {
77481 #ifdef CONFIG_XFRM_SUB_POLICY
77482 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77483 #endif
77484 }
77485
77486 -static int inline
77487 +static inline int
77488 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
77489 {
77490 #ifdef CONFIG_XFRM_SUB_POLICY
77491 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
77492
77493 xdst->num_pols = num_pols;
77494 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
77495 - xdst->policy_genid = atomic_read(&pols[0]->genid);
77496 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
77497
77498 return xdst;
77499 }
77500 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
77501 if (xdst->xfrm_genid != dst->xfrm->genid)
77502 return 0;
77503 if (xdst->num_pols > 0 &&
77504 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
77505 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
77506 return 0;
77507
77508 mtu = dst_mtu(dst->child);
77509 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
77510 sizeof(pol->xfrm_vec[i].saddr));
77511 pol->xfrm_vec[i].encap_family = mp->new_family;
77512 /* flush bundles */
77513 - atomic_inc(&pol->genid);
77514 + atomic_inc_unchecked(&pol->genid);
77515 }
77516 }
77517
77518 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
77519 index d2b366c..51ff91ebc 100644
77520 --- a/scripts/Makefile.build
77521 +++ b/scripts/Makefile.build
77522 @@ -109,7 +109,7 @@ endif
77523 endif
77524
77525 # Do not include host rules unless needed
77526 -ifneq ($(hostprogs-y)$(hostprogs-m),)
77527 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
77528 include scripts/Makefile.host
77529 endif
77530
77531 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
77532 index 686cb0d..9d653bf 100644
77533 --- a/scripts/Makefile.clean
77534 +++ b/scripts/Makefile.clean
77535 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
77536 __clean-files := $(extra-y) $(always) \
77537 $(targets) $(clean-files) \
77538 $(host-progs) \
77539 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
77540 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
77541 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
77542
77543 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
77544
77545 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
77546 index 1ac414f..a1c1451 100644
77547 --- a/scripts/Makefile.host
77548 +++ b/scripts/Makefile.host
77549 @@ -31,6 +31,7 @@
77550 # Note: Shared libraries consisting of C++ files are not supported
77551
77552 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
77553 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
77554
77555 # C code
77556 # Executables compiled from a single .c file
77557 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
77558 # Shared libaries (only .c supported)
77559 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
77560 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
77561 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
77562 # Remove .so files from "xxx-objs"
77563 host-cobjs := $(filter-out %.so,$(host-cobjs))
77564
77565 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
77566 index cb1f50c..cef2a7c 100644
77567 --- a/scripts/basic/fixdep.c
77568 +++ b/scripts/basic/fixdep.c
77569 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
77570 /*
77571 * Lookup a value in the configuration string.
77572 */
77573 -static int is_defined_config(const char *name, int len, unsigned int hash)
77574 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
77575 {
77576 struct item *aux;
77577
77578 @@ -211,10 +211,10 @@ static void clear_config(void)
77579 /*
77580 * Record the use of a CONFIG_* word.
77581 */
77582 -static void use_config(const char *m, int slen)
77583 +static void use_config(const char *m, unsigned int slen)
77584 {
77585 unsigned int hash = strhash(m, slen);
77586 - int c, i;
77587 + unsigned int c, i;
77588
77589 if (is_defined_config(m, slen, hash))
77590 return;
77591 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
77592
77593 static void parse_config_file(const char *map, size_t len)
77594 {
77595 - const int *end = (const int *) (map + len);
77596 + const unsigned int *end = (const unsigned int *) (map + len);
77597 /* start at +1, so that p can never be < map */
77598 - const int *m = (const int *) map + 1;
77599 + const unsigned int *m = (const unsigned int *) map + 1;
77600 const char *p, *q;
77601
77602 for (; m < end; m++) {
77603 @@ -406,7 +406,7 @@ static void print_deps(void)
77604 static void traps(void)
77605 {
77606 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
77607 - int *p = (int *)test;
77608 + unsigned int *p = (unsigned int *)test;
77609
77610 if (*p != INT_CONF) {
77611 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
77612 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
77613 new file mode 100644
77614 index 0000000..8729101
77615 --- /dev/null
77616 +++ b/scripts/gcc-plugin.sh
77617 @@ -0,0 +1,2 @@
77618 +#!/bin/sh
77619 +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"
77620 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
77621 index f936d1f..a66d95f 100644
77622 --- a/scripts/mod/file2alias.c
77623 +++ b/scripts/mod/file2alias.c
77624 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
77625 unsigned long size, unsigned long id_size,
77626 void *symval)
77627 {
77628 - int i;
77629 + unsigned int i;
77630
77631 if (size % id_size || size < id_size) {
77632 if (cross_build != 0)
77633 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
77634 /* USB is special because the bcdDevice can be matched against a numeric range */
77635 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
77636 static void do_usb_entry(struct usb_device_id *id,
77637 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
77638 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
77639 unsigned char range_lo, unsigned char range_hi,
77640 unsigned char max, struct module *mod)
77641 {
77642 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
77643 {
77644 unsigned int devlo, devhi;
77645 unsigned char chi, clo, max;
77646 - int ndigits;
77647 + unsigned int ndigits;
77648
77649 id->match_flags = TO_NATIVE(id->match_flags);
77650 id->idVendor = TO_NATIVE(id->idVendor);
77651 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
77652 for (i = 0; i < count; i++) {
77653 const char *id = (char *)devs[i].id;
77654 char acpi_id[sizeof(devs[0].id)];
77655 - int j;
77656 + unsigned int j;
77657
77658 buf_printf(&mod->dev_table_buf,
77659 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77660 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77661
77662 for (j = 0; j < PNP_MAX_DEVICES; j++) {
77663 const char *id = (char *)card->devs[j].id;
77664 - int i2, j2;
77665 + unsigned int i2, j2;
77666 int dup = 0;
77667
77668 if (!id[0])
77669 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77670 /* add an individual alias for every device entry */
77671 if (!dup) {
77672 char acpi_id[sizeof(card->devs[0].id)];
77673 - int k;
77674 + unsigned int k;
77675
77676 buf_printf(&mod->dev_table_buf,
77677 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77678 @@ -807,7 +807,7 @@ static void dmi_ascii_filter(char *d, const char *s)
77679 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
77680 char *alias)
77681 {
77682 - int i, j;
77683 + unsigned int i, j;
77684
77685 sprintf(alias, "dmi*");
77686
77687 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
77688 index 2bd594e..d43245e 100644
77689 --- a/scripts/mod/modpost.c
77690 +++ b/scripts/mod/modpost.c
77691 @@ -919,6 +919,7 @@ enum mismatch {
77692 ANY_INIT_TO_ANY_EXIT,
77693 ANY_EXIT_TO_ANY_INIT,
77694 EXPORT_TO_INIT_EXIT,
77695 + DATA_TO_TEXT
77696 };
77697
77698 struct sectioncheck {
77699 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
77700 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
77701 .mismatch = EXPORT_TO_INIT_EXIT,
77702 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
77703 +},
77704 +/* Do not reference code from writable data */
77705 +{
77706 + .fromsec = { DATA_SECTIONS, NULL },
77707 + .tosec = { TEXT_SECTIONS, NULL },
77708 + .mismatch = DATA_TO_TEXT
77709 }
77710 };
77711
77712 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
77713 continue;
77714 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
77715 continue;
77716 - if (sym->st_value == addr)
77717 - return sym;
77718 /* Find a symbol nearby - addr are maybe negative */
77719 d = sym->st_value - addr;
77720 + if (d == 0)
77721 + return sym;
77722 if (d < 0)
77723 d = addr - sym->st_value;
77724 if (d < distance) {
77725 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
77726 tosym, prl_to, prl_to, tosym);
77727 free(prl_to);
77728 break;
77729 + case DATA_TO_TEXT:
77730 +/*
77731 + fprintf(stderr,
77732 + "The variable %s references\n"
77733 + "the %s %s%s%s\n",
77734 + fromsym, to, sec2annotation(tosec), tosym, to_p);
77735 +*/
77736 + break;
77737 }
77738 fprintf(stderr, "\n");
77739 }
77740 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
77741 static void check_sec_ref(struct module *mod, const char *modname,
77742 struct elf_info *elf)
77743 {
77744 - int i;
77745 + unsigned int i;
77746 Elf_Shdr *sechdrs = elf->sechdrs;
77747
77748 /* Walk through all sections */
77749 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
77750 va_end(ap);
77751 }
77752
77753 -void buf_write(struct buffer *buf, const char *s, int len)
77754 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
77755 {
77756 if (buf->size - buf->pos < len) {
77757 buf->size += len + SZ;
77758 @@ -1972,7 +1987,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
77759 if (fstat(fileno(file), &st) < 0)
77760 goto close_write;
77761
77762 - if (st.st_size != b->pos)
77763 + if (st.st_size != (off_t)b->pos)
77764 goto close_write;
77765
77766 tmp = NOFAIL(malloc(b->pos));
77767 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
77768 index 2031119..b5433af 100644
77769 --- a/scripts/mod/modpost.h
77770 +++ b/scripts/mod/modpost.h
77771 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
77772
77773 struct buffer {
77774 char *p;
77775 - int pos;
77776 - int size;
77777 + unsigned int pos;
77778 + unsigned int size;
77779 };
77780
77781 void __attribute__((format(printf, 2, 3)))
77782 buf_printf(struct buffer *buf, const char *fmt, ...);
77783
77784 void
77785 -buf_write(struct buffer *buf, const char *s, int len);
77786 +buf_write(struct buffer *buf, const char *s, unsigned int len);
77787
77788 struct module {
77789 struct module *next;
77790 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
77791 index 9dfcd6d..099068e 100644
77792 --- a/scripts/mod/sumversion.c
77793 +++ b/scripts/mod/sumversion.c
77794 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
77795 goto out;
77796 }
77797
77798 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
77799 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
77800 warn("writing sum in %s failed: %s\n",
77801 filename, strerror(errno));
77802 goto out;
77803 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
77804 index 5c11312..72742b5 100644
77805 --- a/scripts/pnmtologo.c
77806 +++ b/scripts/pnmtologo.c
77807 @@ -237,14 +237,14 @@ static void write_header(void)
77808 fprintf(out, " * Linux logo %s\n", logoname);
77809 fputs(" */\n\n", out);
77810 fputs("#include <linux/linux_logo.h>\n\n", out);
77811 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
77812 + fprintf(out, "static unsigned char %s_data[] = {\n",
77813 logoname);
77814 }
77815
77816 static void write_footer(void)
77817 {
77818 fputs("\n};\n\n", out);
77819 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
77820 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
77821 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
77822 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
77823 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
77824 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
77825 fputs("\n};\n\n", out);
77826
77827 /* write logo clut */
77828 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
77829 + fprintf(out, "static unsigned char %s_clut[] = {\n",
77830 logoname);
77831 write_hex_cnt = 0;
77832 for (i = 0; i < logo_clutsize; i++) {
77833 diff --git a/security/Kconfig b/security/Kconfig
77834 index 51bd5a0..3a4ebd0 100644
77835 --- a/security/Kconfig
77836 +++ b/security/Kconfig
77837 @@ -4,6 +4,627 @@
77838
77839 menu "Security options"
77840
77841 +source grsecurity/Kconfig
77842 +
77843 +menu "PaX"
77844 +
77845 + config ARCH_TRACK_EXEC_LIMIT
77846 + bool
77847 +
77848 + config PAX_KERNEXEC_PLUGIN
77849 + bool
77850 +
77851 + config PAX_PER_CPU_PGD
77852 + bool
77853 +
77854 + config TASK_SIZE_MAX_SHIFT
77855 + int
77856 + depends on X86_64
77857 + default 47 if !PAX_PER_CPU_PGD
77858 + default 42 if PAX_PER_CPU_PGD
77859 +
77860 + config PAX_ENABLE_PAE
77861 + bool
77862 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
77863 +
77864 +config PAX
77865 + bool "Enable various PaX features"
77866 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
77867 + help
77868 + This allows you to enable various PaX features. PaX adds
77869 + intrusion prevention mechanisms to the kernel that reduce
77870 + the risks posed by exploitable memory corruption bugs.
77871 +
77872 +menu "PaX Control"
77873 + depends on PAX
77874 +
77875 +config PAX_SOFTMODE
77876 + bool 'Support soft mode'
77877 + help
77878 + Enabling this option will allow you to run PaX in soft mode, that
77879 + is, PaX features will not be enforced by default, only on executables
77880 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
77881 + support as they are the only way to mark executables for soft mode use.
77882 +
77883 + Soft mode can be activated by using the "pax_softmode=1" kernel command
77884 + line option on boot. Furthermore you can control various PaX features
77885 + at runtime via the entries in /proc/sys/kernel/pax.
77886 +
77887 +config PAX_EI_PAX
77888 + bool 'Use legacy ELF header marking'
77889 + help
77890 + Enabling this option will allow you to control PaX features on
77891 + a per executable basis via the 'chpax' utility available at
77892 + http://pax.grsecurity.net/. The control flags will be read from
77893 + an otherwise reserved part of the ELF header. This marking has
77894 + numerous drawbacks (no support for soft-mode, toolchain does not
77895 + know about the non-standard use of the ELF header) therefore it
77896 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
77897 + support.
77898 +
77899 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77900 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
77901 + option otherwise they will not get any protection.
77902 +
77903 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
77904 + support as well, they will override the legacy EI_PAX marks.
77905 +
77906 +config PAX_PT_PAX_FLAGS
77907 + bool 'Use ELF program header marking'
77908 + help
77909 + Enabling this option will allow you to control PaX features on
77910 + a per executable basis via the 'paxctl' utility available at
77911 + http://pax.grsecurity.net/. The control flags will be read from
77912 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
77913 + has the benefits of supporting both soft mode and being fully
77914 + integrated into the toolchain (the binutils patch is available
77915 + from http://pax.grsecurity.net).
77916 +
77917 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77918 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
77919 + support otherwise they will not get any protection.
77920 +
77921 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
77922 + must make sure that the marks are the same if a binary has both marks.
77923 +
77924 + Note that if you enable the legacy EI_PAX marking support as well,
77925 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
77926 +
77927 +config PAX_XATTR_PAX_FLAGS
77928 + bool 'Use filesystem extended attributes marking'
77929 + depends on EXPERT
77930 + select CIFS_XATTR if CIFS
77931 + select EXT2_FS_XATTR if EXT2_FS
77932 + select EXT3_FS_XATTR if EXT3_FS
77933 + select EXT4_FS_XATTR if EXT4_FS
77934 + select JFFS2_FS_XATTR if JFFS2_FS
77935 + select REISERFS_FS_XATTR if REISERFS_FS
77936 + select SQUASHFS_XATTR if SQUASHFS
77937 + select TMPFS_XATTR if TMPFS
77938 + select UBIFS_FS_XATTR if UBIFS_FS
77939 + help
77940 + Enabling this option will allow you to control PaX features on
77941 + a per executable basis via the 'setfattr' utility. The control
77942 + flags will be read from the user.pax.flags extended attribute of
77943 + the file. This marking has the benefit of supporting binary-only
77944 + applications that self-check themselves (e.g., skype) and would
77945 + not tolerate chpax/paxctl changes. The main drawback is that
77946 + extended attributes are not supported by some filesystems (e.g.,
77947 + isofs, udf, vfat) so copying files through such filesystems will
77948 + lose the extended attributes and these PaX markings.
77949 +
77950 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77951 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
77952 + support otherwise they will not get any protection.
77953 +
77954 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
77955 + must make sure that the marks are the same if a binary has both marks.
77956 +
77957 + Note that if you enable the legacy EI_PAX marking support as well,
77958 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
77959 +
77960 +choice
77961 + prompt 'MAC system integration'
77962 + default PAX_HAVE_ACL_FLAGS
77963 + help
77964 + Mandatory Access Control systems have the option of controlling
77965 + PaX flags on a per executable basis, choose the method supported
77966 + by your particular system.
77967 +
77968 + - "none": if your MAC system does not interact with PaX,
77969 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
77970 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
77971 +
77972 + NOTE: this option is for developers/integrators only.
77973 +
77974 + config PAX_NO_ACL_FLAGS
77975 + bool 'none'
77976 +
77977 + config PAX_HAVE_ACL_FLAGS
77978 + bool 'direct'
77979 +
77980 + config PAX_HOOK_ACL_FLAGS
77981 + bool 'hook'
77982 +endchoice
77983 +
77984 +endmenu
77985 +
77986 +menu "Non-executable pages"
77987 + depends on PAX
77988 +
77989 +config PAX_NOEXEC
77990 + bool "Enforce non-executable pages"
77991 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
77992 + help
77993 + By design some architectures do not allow for protecting memory
77994 + pages against execution or even if they do, Linux does not make
77995 + use of this feature. In practice this means that if a page is
77996 + readable (such as the stack or heap) it is also executable.
77997 +
77998 + There is a well known exploit technique that makes use of this
77999 + fact and a common programming mistake where an attacker can
78000 + introduce code of his choice somewhere in the attacked program's
78001 + memory (typically the stack or the heap) and then execute it.
78002 +
78003 + If the attacked program was running with different (typically
78004 + higher) privileges than that of the attacker, then he can elevate
78005 + his own privilege level (e.g. get a root shell, write to files for
78006 + which he does not have write access to, etc).
78007 +
78008 + Enabling this option will let you choose from various features
78009 + that prevent the injection and execution of 'foreign' code in
78010 + a program.
78011 +
78012 + This will also break programs that rely on the old behaviour and
78013 + expect that dynamically allocated memory via the malloc() family
78014 + of functions is executable (which it is not). Notable examples
78015 + are the XFree86 4.x server, the java runtime and wine.
78016 +
78017 +config PAX_PAGEEXEC
78018 + bool "Paging based non-executable pages"
78019 + 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)
78020 + select S390_SWITCH_AMODE if S390
78021 + select S390_EXEC_PROTECT if S390
78022 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78023 + help
78024 + This implementation is based on the paging feature of the CPU.
78025 + On i386 without hardware non-executable bit support there is a
78026 + variable but usually low performance impact, however on Intel's
78027 + P4 core based CPUs it is very high so you should not enable this
78028 + for kernels meant to be used on such CPUs.
78029 +
78030 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78031 + with hardware non-executable bit support there is no performance
78032 + impact, on ppc the impact is negligible.
78033 +
78034 + Note that several architectures require various emulations due to
78035 + badly designed userland ABIs, this will cause a performance impact
78036 + but will disappear as soon as userland is fixed. For example, ppc
78037 + userland MUST have been built with secure-plt by a recent toolchain.
78038 +
78039 +config PAX_SEGMEXEC
78040 + bool "Segmentation based non-executable pages"
78041 + depends on PAX_NOEXEC && X86_32
78042 + help
78043 + This implementation is based on the segmentation feature of the
78044 + CPU and has a very small performance impact, however applications
78045 + will be limited to a 1.5 GB address space instead of the normal
78046 + 3 GB.
78047 +
78048 +config PAX_EMUTRAMP
78049 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78050 + default y if PARISC
78051 + help
78052 + There are some programs and libraries that for one reason or
78053 + another attempt to execute special small code snippets from
78054 + non-executable memory pages. Most notable examples are the
78055 + signal handler return code generated by the kernel itself and
78056 + the GCC trampolines.
78057 +
78058 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78059 + such programs will no longer work under your kernel.
78060 +
78061 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78062 + utilities to enable trampoline emulation for the affected programs
78063 + yet still have the protection provided by the non-executable pages.
78064 +
78065 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78066 + your system will not even boot.
78067 +
78068 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78069 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78070 + for the affected files.
78071 +
78072 + NOTE: enabling this feature *may* open up a loophole in the
78073 + protection provided by non-executable pages that an attacker
78074 + could abuse. Therefore the best solution is to not have any
78075 + files on your system that would require this option. This can
78076 + be achieved by not using libc5 (which relies on the kernel
78077 + signal handler return code) and not using or rewriting programs
78078 + that make use of the nested function implementation of GCC.
78079 + Skilled users can just fix GCC itself so that it implements
78080 + nested function calls in a way that does not interfere with PaX.
78081 +
78082 +config PAX_EMUSIGRT
78083 + bool "Automatically emulate sigreturn trampolines"
78084 + depends on PAX_EMUTRAMP && PARISC
78085 + default y
78086 + help
78087 + Enabling this option will have the kernel automatically detect
78088 + and emulate signal return trampolines executing on the stack
78089 + that would otherwise lead to task termination.
78090 +
78091 + This solution is intended as a temporary one for users with
78092 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78093 + Modula-3 runtime, etc) or executables linked to such, basically
78094 + everything that does not specify its own SA_RESTORER function in
78095 + normal executable memory like glibc 2.1+ does.
78096 +
78097 + On parisc you MUST enable this option, otherwise your system will
78098 + not even boot.
78099 +
78100 + NOTE: this feature cannot be disabled on a per executable basis
78101 + and since it *does* open up a loophole in the protection provided
78102 + by non-executable pages, the best solution is to not have any
78103 + files on your system that would require this option.
78104 +
78105 +config PAX_MPROTECT
78106 + bool "Restrict mprotect()"
78107 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78108 + help
78109 + Enabling this option will prevent programs from
78110 + - changing the executable status of memory pages that were
78111 + not originally created as executable,
78112 + - making read-only executable pages writable again,
78113 + - creating executable pages from anonymous memory,
78114 + - making read-only-after-relocations (RELRO) data pages writable again.
78115 +
78116 + You should say Y here to complete the protection provided by
78117 + the enforcement of non-executable pages.
78118 +
78119 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78120 + this feature on a per file basis.
78121 +
78122 +config PAX_MPROTECT_COMPAT
78123 + bool "Use legacy/compat protection demoting (read help)"
78124 + depends on PAX_MPROTECT
78125 + default n
78126 + help
78127 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78128 + by sending the proper error code to the application. For some broken
78129 + userland, this can cause problems with Python or other applications. The
78130 + current implementation however allows for applications like clamav to
78131 + detect if JIT compilation/execution is allowed and to fall back gracefully
78132 + to an interpreter-based mode if it does not. While we encourage everyone
78133 + to use the current implementation as-is and push upstream to fix broken
78134 + userland (note that the RWX logging option can assist with this), in some
78135 + environments this may not be possible. Having to disable MPROTECT
78136 + completely on certain binaries reduces the security benefit of PaX,
78137 + so this option is provided for those environments to revert to the old
78138 + behavior.
78139 +
78140 +config PAX_ELFRELOCS
78141 + bool "Allow ELF text relocations (read help)"
78142 + depends on PAX_MPROTECT
78143 + default n
78144 + help
78145 + Non-executable pages and mprotect() restrictions are effective
78146 + in preventing the introduction of new executable code into an
78147 + attacked task's address space. There remain only two venues
78148 + for this kind of attack: if the attacker can execute already
78149 + existing code in the attacked task then he can either have it
78150 + create and mmap() a file containing his code or have it mmap()
78151 + an already existing ELF library that does not have position
78152 + independent code in it and use mprotect() on it to make it
78153 + writable and copy his code there. While protecting against
78154 + the former approach is beyond PaX, the latter can be prevented
78155 + by having only PIC ELF libraries on one's system (which do not
78156 + need to relocate their code). If you are sure this is your case,
78157 + as is the case with all modern Linux distributions, then leave
78158 + this option disabled. You should say 'n' here.
78159 +
78160 +config PAX_ETEXECRELOCS
78161 + bool "Allow ELF ET_EXEC text relocations"
78162 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78163 + select PAX_ELFRELOCS
78164 + default y
78165 + help
78166 + On some architectures there are incorrectly created applications
78167 + that require text relocations and would not work without enabling
78168 + this option. If you are an alpha, ia64 or parisc user, you should
78169 + enable this option and disable it once you have made sure that
78170 + none of your applications need it.
78171 +
78172 +config PAX_EMUPLT
78173 + bool "Automatically emulate ELF PLT"
78174 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
78175 + default y
78176 + help
78177 + Enabling this option will have the kernel automatically detect
78178 + and emulate the Procedure Linkage Table entries in ELF files.
78179 + On some architectures such entries are in writable memory, and
78180 + become non-executable leading to task termination. Therefore
78181 + it is mandatory that you enable this option on alpha, parisc,
78182 + sparc and sparc64, otherwise your system would not even boot.
78183 +
78184 + NOTE: this feature *does* open up a loophole in the protection
78185 + provided by the non-executable pages, therefore the proper
78186 + solution is to modify the toolchain to produce a PLT that does
78187 + not need to be writable.
78188 +
78189 +config PAX_DLRESOLVE
78190 + bool 'Emulate old glibc resolver stub'
78191 + depends on PAX_EMUPLT && SPARC
78192 + default n
78193 + help
78194 + This option is needed if userland has an old glibc (before 2.4)
78195 + that puts a 'save' instruction into the runtime generated resolver
78196 + stub that needs special emulation.
78197 +
78198 +config PAX_KERNEXEC
78199 + bool "Enforce non-executable kernel pages"
78200 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
78201 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
78202 + select PAX_KERNEXEC_PLUGIN if X86_64
78203 + help
78204 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
78205 + that is, enabling this option will make it harder to inject
78206 + and execute 'foreign' code in kernel memory itself.
78207 +
78208 + Note that on x86_64 kernels there is a known regression when
78209 + this feature and KVM/VMX are both enabled in the host kernel.
78210 +
78211 +choice
78212 + prompt "Return Address Instrumentation Method"
78213 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
78214 + depends on PAX_KERNEXEC_PLUGIN
78215 + help
78216 + Select the method used to instrument function pointer dereferences.
78217 + Note that binary modules cannot be instrumented by this approach.
78218 +
78219 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
78220 + bool "bts"
78221 + help
78222 + This method is compatible with binary only modules but has
78223 + a higher runtime overhead.
78224 +
78225 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
78226 + bool "or"
78227 + depends on !PARAVIRT
78228 + help
78229 + This method is incompatible with binary only modules but has
78230 + a lower runtime overhead.
78231 +endchoice
78232 +
78233 +config PAX_KERNEXEC_PLUGIN_METHOD
78234 + string
78235 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
78236 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
78237 + default ""
78238 +
78239 +config PAX_KERNEXEC_MODULE_TEXT
78240 + int "Minimum amount of memory reserved for module code"
78241 + default "4"
78242 + depends on PAX_KERNEXEC && X86_32 && MODULES
78243 + help
78244 + Due to implementation details the kernel must reserve a fixed
78245 + amount of memory for module code at compile time that cannot be
78246 + changed at runtime. Here you can specify the minimum amount
78247 + in MB that will be reserved. Due to the same implementation
78248 + details this size will always be rounded up to the next 2/4 MB
78249 + boundary (depends on PAE) so the actually available memory for
78250 + module code will usually be more than this minimum.
78251 +
78252 + The default 4 MB should be enough for most users but if you have
78253 + an excessive number of modules (e.g., most distribution configs
78254 + compile many drivers as modules) or use huge modules such as
78255 + nvidia's kernel driver, you will need to adjust this amount.
78256 + A good rule of thumb is to look at your currently loaded kernel
78257 + modules and add up their sizes.
78258 +
78259 +endmenu
78260 +
78261 +menu "Address Space Layout Randomization"
78262 + depends on PAX
78263 +
78264 +config PAX_ASLR
78265 + bool "Address Space Layout Randomization"
78266 + help
78267 + Many if not most exploit techniques rely on the knowledge of
78268 + certain addresses in the attacked program. The following options
78269 + will allow the kernel to apply a certain amount of randomization
78270 + to specific parts of the program thereby forcing an attacker to
78271 + guess them in most cases. Any failed guess will most likely crash
78272 + the attacked program which allows the kernel to detect such attempts
78273 + and react on them. PaX itself provides no reaction mechanisms,
78274 + instead it is strongly encouraged that you make use of Nergal's
78275 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
78276 + (http://www.grsecurity.net/) built-in crash detection features or
78277 + develop one yourself.
78278 +
78279 + By saying Y here you can choose to randomize the following areas:
78280 + - top of the task's kernel stack
78281 + - top of the task's userland stack
78282 + - base address for mmap() requests that do not specify one
78283 + (this includes all libraries)
78284 + - base address of the main executable
78285 +
78286 + It is strongly recommended to say Y here as address space layout
78287 + randomization has negligible impact on performance yet it provides
78288 + a very effective protection.
78289 +
78290 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78291 + this feature on a per file basis.
78292 +
78293 +config PAX_RANDKSTACK
78294 + bool "Randomize kernel stack base"
78295 + depends on X86_TSC && X86
78296 + help
78297 + By saying Y here the kernel will randomize every task's kernel
78298 + stack on every system call. This will not only force an attacker
78299 + to guess it but also prevent him from making use of possible
78300 + leaked information about it.
78301 +
78302 + Since the kernel stack is a rather scarce resource, randomization
78303 + may cause unexpected stack overflows, therefore you should very
78304 + carefully test your system. Note that once enabled in the kernel
78305 + configuration, this feature cannot be disabled on a per file basis.
78306 +
78307 +config PAX_RANDUSTACK
78308 + bool "Randomize user stack base"
78309 + depends on PAX_ASLR
78310 + help
78311 + By saying Y here the kernel will randomize every task's userland
78312 + stack. The randomization is done in two steps where the second
78313 + one may apply a big amount of shift to the top of the stack and
78314 + cause problems for programs that want to use lots of memory (more
78315 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
78316 + For this reason the second step can be controlled by 'chpax' or
78317 + 'paxctl' on a per file basis.
78318 +
78319 +config PAX_RANDMMAP
78320 + bool "Randomize mmap() base"
78321 + depends on PAX_ASLR
78322 + help
78323 + By saying Y here the kernel will use a randomized base address for
78324 + mmap() requests that do not specify one themselves. As a result
78325 + all dynamically loaded libraries will appear at random addresses
78326 + and therefore be harder to exploit by a technique where an attacker
78327 + attempts to execute library code for his purposes (e.g. spawn a
78328 + shell from an exploited program that is running at an elevated
78329 + privilege level).
78330 +
78331 + Furthermore, if a program is relinked as a dynamic ELF file, its
78332 + base address will be randomized as well, completing the full
78333 + randomization of the address space layout. Attacking such programs
78334 + becomes a guess game. You can find an example of doing this at
78335 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
78336 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
78337 +
78338 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
78339 + feature on a per file basis.
78340 +
78341 +endmenu
78342 +
78343 +menu "Miscellaneous hardening features"
78344 +
78345 +config PAX_MEMORY_SANITIZE
78346 + bool "Sanitize all freed memory"
78347 + depends on !HIBERNATION
78348 + help
78349 + By saying Y here the kernel will erase memory pages as soon as they
78350 + are freed. This in turn reduces the lifetime of data stored in the
78351 + pages, making it less likely that sensitive information such as
78352 + passwords, cryptographic secrets, etc stay in memory for too long.
78353 +
78354 + This is especially useful for programs whose runtime is short, long
78355 + lived processes and the kernel itself benefit from this as long as
78356 + they operate on whole memory pages and ensure timely freeing of pages
78357 + that may hold sensitive information.
78358 +
78359 + The tradeoff is performance impact, on a single CPU system kernel
78360 + compilation sees a 3% slowdown, other systems and workloads may vary
78361 + and you are advised to test this feature on your expected workload
78362 + before deploying it.
78363 +
78364 + Note that this feature does not protect data stored in live pages,
78365 + e.g., process memory swapped to disk may stay there for a long time.
78366 +
78367 +config PAX_MEMORY_STACKLEAK
78368 + bool "Sanitize kernel stack"
78369 + depends on X86
78370 + help
78371 + By saying Y here the kernel will erase the kernel stack before it
78372 + returns from a system call. This in turn reduces the information
78373 + that a kernel stack leak bug can reveal.
78374 +
78375 + Note that such a bug can still leak information that was put on
78376 + the stack by the current system call (the one eventually triggering
78377 + the bug) but traces of earlier system calls on the kernel stack
78378 + cannot leak anymore.
78379 +
78380 + The tradeoff is performance impact: on a single CPU system kernel
78381 + compilation sees a 1% slowdown, other systems and workloads may vary
78382 + and you are advised to test this feature on your expected workload
78383 + before deploying it.
78384 +
78385 + Note: full support for this feature requires gcc with plugin support
78386 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
78387 + versions means that functions with large enough stack frames may
78388 + leave uninitialized memory behind that may be exposed to a later
78389 + syscall leaking the stack.
78390 +
78391 +config PAX_MEMORY_UDEREF
78392 + bool "Prevent invalid userland pointer dereference"
78393 + depends on X86 && !UML_X86 && !XEN
78394 + select PAX_PER_CPU_PGD if X86_64
78395 + help
78396 + By saying Y here the kernel will be prevented from dereferencing
78397 + userland pointers in contexts where the kernel expects only kernel
78398 + pointers. This is both a useful runtime debugging feature and a
78399 + security measure that prevents exploiting a class of kernel bugs.
78400 +
78401 + The tradeoff is that some virtualization solutions may experience
78402 + a huge slowdown and therefore you should not enable this feature
78403 + for kernels meant to run in such environments. Whether a given VM
78404 + solution is affected or not is best determined by simply trying it
78405 + out, the performance impact will be obvious right on boot as this
78406 + mechanism engages from very early on. A good rule of thumb is that
78407 + VMs running on CPUs without hardware virtualization support (i.e.,
78408 + the majority of IA-32 CPUs) will likely experience the slowdown.
78409 +
78410 +config PAX_REFCOUNT
78411 + bool "Prevent various kernel object reference counter overflows"
78412 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
78413 + help
78414 + By saying Y here the kernel will detect and prevent overflowing
78415 + various (but not all) kinds of object reference counters. Such
78416 + overflows can normally occur due to bugs only and are often, if
78417 + not always, exploitable.
78418 +
78419 + The tradeoff is that data structures protected by an overflowed
78420 + refcount will never be freed and therefore will leak memory. Note
78421 + that this leak also happens even without this protection but in
78422 + that case the overflow can eventually trigger the freeing of the
78423 + data structure while it is still being used elsewhere, resulting
78424 + in the exploitable situation that this feature prevents.
78425 +
78426 + Since this has a negligible performance impact, you should enable
78427 + this feature.
78428 +
78429 +config PAX_USERCOPY
78430 + bool "Harden heap object copies between kernel and userland"
78431 + depends on X86 || PPC || SPARC || ARM
78432 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
78433 + help
78434 + By saying Y here the kernel will enforce the size of heap objects
78435 + when they are copied in either direction between the kernel and
78436 + userland, even if only a part of the heap object is copied.
78437 +
78438 + Specifically, this checking prevents information leaking from the
78439 + kernel heap during kernel to userland copies (if the kernel heap
78440 + object is otherwise fully initialized) and prevents kernel heap
78441 + overflows during userland to kernel copies.
78442 +
78443 + Note that the current implementation provides the strictest bounds
78444 + checks for the SLUB allocator.
78445 +
78446 + Enabling this option also enables per-slab cache protection against
78447 + data in a given cache being copied into/out of via userland
78448 + accessors. Though the whitelist of regions will be reduced over
78449 + time, it notably protects important data structures like task structs.
78450 +
78451 + If frame pointers are enabled on x86, this option will also restrict
78452 + copies into and out of the kernel stack to local variables within a
78453 + single frame.
78454 +
78455 + Since this has a negligible performance impact, you should enable
78456 + this feature.
78457 +
78458 +endmenu
78459 +
78460 +endmenu
78461 +
78462 config KEYS
78463 bool "Enable access key retention support"
78464 help
78465 @@ -169,7 +790,7 @@ config INTEL_TXT
78466 config LSM_MMAP_MIN_ADDR
78467 int "Low address space for LSM to protect from user allocation"
78468 depends on SECURITY && SECURITY_SELINUX
78469 - default 32768 if ARM
78470 + default 32768 if ALPHA || ARM || PARISC || SPARC32
78471 default 65536
78472 help
78473 This is the portion of low virtual memory which should be protected
78474 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
78475 index 3783202..1852837 100644
78476 --- a/security/apparmor/lsm.c
78477 +++ b/security/apparmor/lsm.c
78478 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
78479 return error;
78480 }
78481
78482 -static struct security_operations apparmor_ops = {
78483 +static struct security_operations apparmor_ops __read_only = {
78484 .name = "apparmor",
78485
78486 .ptrace_access_check = apparmor_ptrace_access_check,
78487 diff --git a/security/commoncap.c b/security/commoncap.c
78488 index ee4f848..a320c64 100644
78489 --- a/security/commoncap.c
78490 +++ b/security/commoncap.c
78491 @@ -28,6 +28,7 @@
78492 #include <linux/prctl.h>
78493 #include <linux/securebits.h>
78494 #include <linux/user_namespace.h>
78495 +#include <net/sock.h>
78496
78497 /*
78498 * If a non-root user executes a setuid-root binary in
78499 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
78500
78501 int cap_netlink_recv(struct sk_buff *skb, int cap)
78502 {
78503 - if (!cap_raised(current_cap(), cap))
78504 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
78505 return -EPERM;
78506 return 0;
78507 }
78508 @@ -579,6 +580,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
78509 {
78510 const struct cred *cred = current_cred();
78511
78512 + if (gr_acl_enable_at_secure())
78513 + return 1;
78514 +
78515 if (cred->uid != 0) {
78516 if (bprm->cap_effective)
78517 return 1;
78518 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
78519 index 3ccf7ac..d73ad64 100644
78520 --- a/security/integrity/ima/ima.h
78521 +++ b/security/integrity/ima/ima.h
78522 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78523 extern spinlock_t ima_queue_lock;
78524
78525 struct ima_h_table {
78526 - atomic_long_t len; /* number of stored measurements in the list */
78527 - atomic_long_t violations;
78528 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
78529 + atomic_long_unchecked_t violations;
78530 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
78531 };
78532 extern struct ima_h_table ima_htable;
78533 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
78534 index 88a2788..581ab92 100644
78535 --- a/security/integrity/ima/ima_api.c
78536 +++ b/security/integrity/ima/ima_api.c
78537 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78538 int result;
78539
78540 /* can overflow, only indicator */
78541 - atomic_long_inc(&ima_htable.violations);
78542 + atomic_long_inc_unchecked(&ima_htable.violations);
78543
78544 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
78545 if (!entry) {
78546 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
78547 index c5c5a72..2ad942f 100644
78548 --- a/security/integrity/ima/ima_audit.c
78549 +++ b/security/integrity/ima/ima_audit.c
78550 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
78551 audit_log_format(ab, " name=");
78552 audit_log_untrustedstring(ab, fname);
78553 }
78554 - if (inode)
78555 - audit_log_format(ab, " dev=%s ino=%lu",
78556 - inode->i_sb->s_id, inode->i_ino);
78557 + if (inode) {
78558 + audit_log_format(ab, " dev=");
78559 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78560 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78561 + }
78562 audit_log_format(ab, " res=%d", !result ? 0 : 1);
78563 audit_log_end(ab);
78564 }
78565 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
78566 index e1aa2b4..52027bf 100644
78567 --- a/security/integrity/ima/ima_fs.c
78568 +++ b/security/integrity/ima/ima_fs.c
78569 @@ -28,12 +28,12 @@
78570 static int valid_policy = 1;
78571 #define TMPBUFLEN 12
78572 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
78573 - loff_t *ppos, atomic_long_t *val)
78574 + loff_t *ppos, atomic_long_unchecked_t *val)
78575 {
78576 char tmpbuf[TMPBUFLEN];
78577 ssize_t len;
78578
78579 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
78580 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
78581 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
78582 }
78583
78584 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
78585 index 55a6271..ad829c3 100644
78586 --- a/security/integrity/ima/ima_queue.c
78587 +++ b/security/integrity/ima/ima_queue.c
78588 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
78589 INIT_LIST_HEAD(&qe->later);
78590 list_add_tail_rcu(&qe->later, &ima_measurements);
78591
78592 - atomic_long_inc(&ima_htable.len);
78593 + atomic_long_inc_unchecked(&ima_htable.len);
78594 key = ima_hash_key(entry->digest);
78595 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
78596 return 0;
78597 diff --git a/security/keys/compat.c b/security/keys/compat.c
78598 index 4c48e13..7abdac9 100644
78599 --- a/security/keys/compat.c
78600 +++ b/security/keys/compat.c
78601 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
78602 if (ret == 0)
78603 goto no_payload_free;
78604
78605 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78606 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78607
78608 if (iov != iovstack)
78609 kfree(iov);
78610 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
78611 index 0b3f5d7..892c8a6 100644
78612 --- a/security/keys/keyctl.c
78613 +++ b/security/keys/keyctl.c
78614 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
78615 /*
78616 * Copy the iovec data from userspace
78617 */
78618 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78619 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
78620 unsigned ioc)
78621 {
78622 for (; ioc > 0; ioc--) {
78623 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78624 * If successful, 0 will be returned.
78625 */
78626 long keyctl_instantiate_key_common(key_serial_t id,
78627 - const struct iovec *payload_iov,
78628 + const struct iovec __user *payload_iov,
78629 unsigned ioc,
78630 size_t plen,
78631 key_serial_t ringid)
78632 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
78633 [0].iov_len = plen
78634 };
78635
78636 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
78637 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
78638 }
78639
78640 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
78641 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
78642 if (ret == 0)
78643 goto no_payload_free;
78644
78645 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78646 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78647
78648 if (iov != iovstack)
78649 kfree(iov);
78650 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
78651 index 37a7f3b..86dc19f 100644
78652 --- a/security/keys/keyring.c
78653 +++ b/security/keys/keyring.c
78654 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
78655 ret = -EFAULT;
78656
78657 for (loop = 0; loop < klist->nkeys; loop++) {
78658 + key_serial_t serial;
78659 key = klist->keys[loop];
78660 + serial = key->serial;
78661
78662 tmp = sizeof(key_serial_t);
78663 if (tmp > buflen)
78664 tmp = buflen;
78665
78666 - if (copy_to_user(buffer,
78667 - &key->serial,
78668 - tmp) != 0)
78669 + if (copy_to_user(buffer, &serial, tmp))
78670 goto error;
78671
78672 buflen -= tmp;
78673 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
78674 index 893af8a..ba9237c 100644
78675 --- a/security/lsm_audit.c
78676 +++ b/security/lsm_audit.c
78677 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
78678 audit_log_d_path(ab, "path=", &a->u.path);
78679
78680 inode = a->u.path.dentry->d_inode;
78681 - if (inode)
78682 - audit_log_format(ab, " dev=%s ino=%lu",
78683 - inode->i_sb->s_id,
78684 - inode->i_ino);
78685 + if (inode) {
78686 + audit_log_format(ab, " dev=");
78687 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78688 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78689 + }
78690 break;
78691 }
78692 case LSM_AUDIT_DATA_DENTRY: {
78693 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
78694 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
78695
78696 inode = a->u.dentry->d_inode;
78697 - if (inode)
78698 - audit_log_format(ab, " dev=%s ino=%lu",
78699 - inode->i_sb->s_id,
78700 - inode->i_ino);
78701 + if (inode) {
78702 + audit_log_format(ab, " dev=");
78703 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78704 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78705 + }
78706 break;
78707 }
78708 case LSM_AUDIT_DATA_INODE: {
78709 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
78710 dentry->d_name.name);
78711 dput(dentry);
78712 }
78713 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
78714 - inode->i_ino);
78715 + audit_log_format(ab, " dev=");
78716 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78717 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78718 break;
78719 }
78720 case LSM_AUDIT_DATA_TASK:
78721 diff --git a/security/min_addr.c b/security/min_addr.c
78722 index f728728..6457a0c 100644
78723 --- a/security/min_addr.c
78724 +++ b/security/min_addr.c
78725 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
78726 */
78727 static void update_mmap_min_addr(void)
78728 {
78729 +#ifndef SPARC
78730 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
78731 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
78732 mmap_min_addr = dac_mmap_min_addr;
78733 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
78734 #else
78735 mmap_min_addr = dac_mmap_min_addr;
78736 #endif
78737 +#endif
78738 }
78739
78740 /*
78741 diff --git a/security/security.c b/security/security.c
78742 index e2f684a..8d62ef5 100644
78743 --- a/security/security.c
78744 +++ b/security/security.c
78745 @@ -26,8 +26,8 @@
78746 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
78747 CONFIG_DEFAULT_SECURITY;
78748
78749 -static struct security_operations *security_ops;
78750 -static struct security_operations default_security_ops = {
78751 +static struct security_operations *security_ops __read_only;
78752 +static struct security_operations default_security_ops __read_only = {
78753 .name = "default",
78754 };
78755
78756 @@ -68,7 +68,9 @@ int __init security_init(void)
78757
78758 void reset_security_ops(void)
78759 {
78760 + pax_open_kernel();
78761 security_ops = &default_security_ops;
78762 + pax_close_kernel();
78763 }
78764
78765 /* Save user chosen LSM */
78766 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
78767 index 1126c10..effb32b 100644
78768 --- a/security/selinux/hooks.c
78769 +++ b/security/selinux/hooks.c
78770 @@ -94,8 +94,6 @@
78771
78772 #define NUM_SEL_MNT_OPTS 5
78773
78774 -extern struct security_operations *security_ops;
78775 -
78776 /* SECMARK reference count */
78777 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
78778
78779 @@ -5449,7 +5447,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
78780
78781 #endif
78782
78783 -static struct security_operations selinux_ops = {
78784 +static struct security_operations selinux_ops __read_only = {
78785 .name = "selinux",
78786
78787 .ptrace_access_check = selinux_ptrace_access_check,
78788 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
78789 index b43813c..74be837 100644
78790 --- a/security/selinux/include/xfrm.h
78791 +++ b/security/selinux/include/xfrm.h
78792 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
78793
78794 static inline void selinux_xfrm_notify_policyload(void)
78795 {
78796 - atomic_inc(&flow_cache_genid);
78797 + atomic_inc_unchecked(&flow_cache_genid);
78798 }
78799 #else
78800 static inline int selinux_xfrm_enabled(void)
78801 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
78802 index 7db62b4..ee4d949 100644
78803 --- a/security/smack/smack_lsm.c
78804 +++ b/security/smack/smack_lsm.c
78805 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
78806 return 0;
78807 }
78808
78809 -struct security_operations smack_ops = {
78810 +struct security_operations smack_ops __read_only = {
78811 .name = "smack",
78812
78813 .ptrace_access_check = smack_ptrace_access_check,
78814 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
78815 index 4b327b6..646c57a 100644
78816 --- a/security/tomoyo/tomoyo.c
78817 +++ b/security/tomoyo/tomoyo.c
78818 @@ -504,7 +504,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
78819 * tomoyo_security_ops is a "struct security_operations" which is used for
78820 * registering TOMOYO.
78821 */
78822 -static struct security_operations tomoyo_security_ops = {
78823 +static struct security_operations tomoyo_security_ops __read_only = {
78824 .name = "tomoyo",
78825 .cred_alloc_blank = tomoyo_cred_alloc_blank,
78826 .cred_prepare = tomoyo_cred_prepare,
78827 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
78828 index 762af68..7103453 100644
78829 --- a/sound/aoa/codecs/onyx.c
78830 +++ b/sound/aoa/codecs/onyx.c
78831 @@ -54,7 +54,7 @@ struct onyx {
78832 spdif_locked:1,
78833 analog_locked:1,
78834 original_mute:2;
78835 - int open_count;
78836 + local_t open_count;
78837 struct codec_info *codec_info;
78838
78839 /* mutex serializes concurrent access to the device
78840 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
78841 struct onyx *onyx = cii->codec_data;
78842
78843 mutex_lock(&onyx->mutex);
78844 - onyx->open_count++;
78845 + local_inc(&onyx->open_count);
78846 mutex_unlock(&onyx->mutex);
78847
78848 return 0;
78849 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
78850 struct onyx *onyx = cii->codec_data;
78851
78852 mutex_lock(&onyx->mutex);
78853 - onyx->open_count--;
78854 - if (!onyx->open_count)
78855 + if (local_dec_and_test(&onyx->open_count))
78856 onyx->spdif_locked = onyx->analog_locked = 0;
78857 mutex_unlock(&onyx->mutex);
78858
78859 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
78860 index ffd2025..df062c9 100644
78861 --- a/sound/aoa/codecs/onyx.h
78862 +++ b/sound/aoa/codecs/onyx.h
78863 @@ -11,6 +11,7 @@
78864 #include <linux/i2c.h>
78865 #include <asm/pmac_low_i2c.h>
78866 #include <asm/prom.h>
78867 +#include <asm/local.h>
78868
78869 /* PCM3052 register definitions */
78870
78871 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
78872 index 3cc4b86..af0a951 100644
78873 --- a/sound/core/oss/pcm_oss.c
78874 +++ b/sound/core/oss/pcm_oss.c
78875 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
78876 if (in_kernel) {
78877 mm_segment_t fs;
78878 fs = snd_enter_user();
78879 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78880 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78881 snd_leave_user(fs);
78882 } else {
78883 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78884 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78885 }
78886 if (ret != -EPIPE && ret != -ESTRPIPE)
78887 break;
78888 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
78889 if (in_kernel) {
78890 mm_segment_t fs;
78891 fs = snd_enter_user();
78892 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78893 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78894 snd_leave_user(fs);
78895 } else {
78896 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78897 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78898 }
78899 if (ret == -EPIPE) {
78900 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
78901 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
78902 struct snd_pcm_plugin_channel *channels;
78903 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
78904 if (!in_kernel) {
78905 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
78906 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
78907 return -EFAULT;
78908 buf = runtime->oss.buffer;
78909 }
78910 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
78911 }
78912 } else {
78913 tmp = snd_pcm_oss_write2(substream,
78914 - (const char __force *)buf,
78915 + (const char __force_kernel *)buf,
78916 runtime->oss.period_bytes, 0);
78917 if (tmp <= 0)
78918 goto err;
78919 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
78920 struct snd_pcm_runtime *runtime = substream->runtime;
78921 snd_pcm_sframes_t frames, frames1;
78922 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
78923 - char __user *final_dst = (char __force __user *)buf;
78924 + char __user *final_dst = (char __force_user *)buf;
78925 if (runtime->oss.plugin_first) {
78926 struct snd_pcm_plugin_channel *channels;
78927 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
78928 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
78929 xfer += tmp;
78930 runtime->oss.buffer_used -= tmp;
78931 } else {
78932 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
78933 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
78934 runtime->oss.period_bytes, 0);
78935 if (tmp <= 0)
78936 goto err;
78937 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
78938 size1);
78939 size1 /= runtime->channels; /* frames */
78940 fs = snd_enter_user();
78941 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
78942 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
78943 snd_leave_user(fs);
78944 }
78945 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
78946 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
78947 index 91cdf94..4085161 100644
78948 --- a/sound/core/pcm_compat.c
78949 +++ b/sound/core/pcm_compat.c
78950 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
78951 int err;
78952
78953 fs = snd_enter_user();
78954 - err = snd_pcm_delay(substream, &delay);
78955 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
78956 snd_leave_user(fs);
78957 if (err < 0)
78958 return err;
78959 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
78960 index 25ed9fe..24c46e9 100644
78961 --- a/sound/core/pcm_native.c
78962 +++ b/sound/core/pcm_native.c
78963 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
78964 switch (substream->stream) {
78965 case SNDRV_PCM_STREAM_PLAYBACK:
78966 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
78967 - (void __user *)arg);
78968 + (void __force_user *)arg);
78969 break;
78970 case SNDRV_PCM_STREAM_CAPTURE:
78971 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
78972 - (void __user *)arg);
78973 + (void __force_user *)arg);
78974 break;
78975 default:
78976 result = -EINVAL;
78977 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
78978 index 5cf8d65..912a79c 100644
78979 --- a/sound/core/seq/seq_device.c
78980 +++ b/sound/core/seq/seq_device.c
78981 @@ -64,7 +64,7 @@ struct ops_list {
78982 int argsize; /* argument size */
78983
78984 /* operators */
78985 - struct snd_seq_dev_ops ops;
78986 + struct snd_seq_dev_ops *ops;
78987
78988 /* registred devices */
78989 struct list_head dev_list; /* list of devices */
78990 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
78991
78992 mutex_lock(&ops->reg_mutex);
78993 /* copy driver operators */
78994 - ops->ops = *entry;
78995 + ops->ops = entry;
78996 ops->driver |= DRIVER_LOADED;
78997 ops->argsize = argsize;
78998
78999 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79000 dev->name, ops->id, ops->argsize, dev->argsize);
79001 return -EINVAL;
79002 }
79003 - if (ops->ops.init_device(dev) >= 0) {
79004 + if (ops->ops->init_device(dev) >= 0) {
79005 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79006 ops->num_init_devices++;
79007 } else {
79008 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79009 dev->name, ops->id, ops->argsize, dev->argsize);
79010 return -EINVAL;
79011 }
79012 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79013 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79014 dev->status = SNDRV_SEQ_DEVICE_FREE;
79015 dev->driver_data = NULL;
79016 ops->num_init_devices--;
79017 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79018 index f24bf9a..1f7b67c 100644
79019 --- a/sound/drivers/mts64.c
79020 +++ b/sound/drivers/mts64.c
79021 @@ -29,6 +29,7 @@
79022 #include <sound/initval.h>
79023 #include <sound/rawmidi.h>
79024 #include <sound/control.h>
79025 +#include <asm/local.h>
79026
79027 #define CARD_NAME "Miditerminal 4140"
79028 #define DRIVER_NAME "MTS64"
79029 @@ -67,7 +68,7 @@ struct mts64 {
79030 struct pardevice *pardev;
79031 int pardev_claimed;
79032
79033 - int open_count;
79034 + local_t open_count;
79035 int current_midi_output_port;
79036 int current_midi_input_port;
79037 u8 mode[MTS64_NUM_INPUT_PORTS];
79038 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79039 {
79040 struct mts64 *mts = substream->rmidi->private_data;
79041
79042 - if (mts->open_count == 0) {
79043 + if (local_read(&mts->open_count) == 0) {
79044 /* We don't need a spinlock here, because this is just called
79045 if the device has not been opened before.
79046 So there aren't any IRQs from the device */
79047 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79048
79049 msleep(50);
79050 }
79051 - ++(mts->open_count);
79052 + local_inc(&mts->open_count);
79053
79054 return 0;
79055 }
79056 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79057 struct mts64 *mts = substream->rmidi->private_data;
79058 unsigned long flags;
79059
79060 - --(mts->open_count);
79061 - if (mts->open_count == 0) {
79062 + if (local_dec_return(&mts->open_count) == 0) {
79063 /* We need the spinlock_irqsave here because we can still
79064 have IRQs at this point */
79065 spin_lock_irqsave(&mts->lock, flags);
79066 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79067
79068 msleep(500);
79069
79070 - } else if (mts->open_count < 0)
79071 - mts->open_count = 0;
79072 + } else if (local_read(&mts->open_count) < 0)
79073 + local_set(&mts->open_count, 0);
79074
79075 return 0;
79076 }
79077 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79078 index b953fb4..1999c01 100644
79079 --- a/sound/drivers/opl4/opl4_lib.c
79080 +++ b/sound/drivers/opl4/opl4_lib.c
79081 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79082 MODULE_DESCRIPTION("OPL4 driver");
79083 MODULE_LICENSE("GPL");
79084
79085 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79086 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79087 {
79088 int timeout = 10;
79089 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79090 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79091 index f664823..590c745 100644
79092 --- a/sound/drivers/portman2x4.c
79093 +++ b/sound/drivers/portman2x4.c
79094 @@ -48,6 +48,7 @@
79095 #include <sound/initval.h>
79096 #include <sound/rawmidi.h>
79097 #include <sound/control.h>
79098 +#include <asm/local.h>
79099
79100 #define CARD_NAME "Portman 2x4"
79101 #define DRIVER_NAME "portman"
79102 @@ -85,7 +86,7 @@ struct portman {
79103 struct pardevice *pardev;
79104 int pardev_claimed;
79105
79106 - int open_count;
79107 + local_t open_count;
79108 int mode[PORTMAN_NUM_INPUT_PORTS];
79109 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79110 };
79111 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79112 index 87657dd..a8268d4 100644
79113 --- a/sound/firewire/amdtp.c
79114 +++ b/sound/firewire/amdtp.c
79115 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79116 ptr = s->pcm_buffer_pointer + data_blocks;
79117 if (ptr >= pcm->runtime->buffer_size)
79118 ptr -= pcm->runtime->buffer_size;
79119 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79120 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79121
79122 s->pcm_period_pointer += data_blocks;
79123 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79124 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79125 */
79126 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79127 {
79128 - ACCESS_ONCE(s->source_node_id_field) =
79129 + ACCESS_ONCE_RW(s->source_node_id_field) =
79130 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79131 }
79132 EXPORT_SYMBOL(amdtp_out_stream_update);
79133 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79134 index 537a9cb..8e8c8e9 100644
79135 --- a/sound/firewire/amdtp.h
79136 +++ b/sound/firewire/amdtp.h
79137 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79138 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79139 struct snd_pcm_substream *pcm)
79140 {
79141 - ACCESS_ONCE(s->pcm) = pcm;
79142 + ACCESS_ONCE_RW(s->pcm) = pcm;
79143 }
79144
79145 /**
79146 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79147 index cd094ec..eca1277 100644
79148 --- a/sound/firewire/isight.c
79149 +++ b/sound/firewire/isight.c
79150 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79151 ptr += count;
79152 if (ptr >= runtime->buffer_size)
79153 ptr -= runtime->buffer_size;
79154 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79155 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79156
79157 isight->period_counter += count;
79158 if (isight->period_counter >= runtime->period_size) {
79159 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79160 if (err < 0)
79161 return err;
79162
79163 - ACCESS_ONCE(isight->pcm_active) = true;
79164 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79165
79166 return 0;
79167 }
79168 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79169 {
79170 struct isight *isight = substream->private_data;
79171
79172 - ACCESS_ONCE(isight->pcm_active) = false;
79173 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79174
79175 mutex_lock(&isight->mutex);
79176 isight_stop_streaming(isight);
79177 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79178
79179 switch (cmd) {
79180 case SNDRV_PCM_TRIGGER_START:
79181 - ACCESS_ONCE(isight->pcm_running) = true;
79182 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79183 break;
79184 case SNDRV_PCM_TRIGGER_STOP:
79185 - ACCESS_ONCE(isight->pcm_running) = false;
79186 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79187 break;
79188 default:
79189 return -EINVAL;
79190 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79191 index c94578d..0794ac1 100644
79192 --- a/sound/isa/cmi8330.c
79193 +++ b/sound/isa/cmi8330.c
79194 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79195
79196 struct snd_pcm *pcm;
79197 struct snd_cmi8330_stream {
79198 - struct snd_pcm_ops ops;
79199 + snd_pcm_ops_no_const ops;
79200 snd_pcm_open_callback_t open;
79201 void *private_data; /* sb or wss */
79202 } streams[2];
79203 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79204 index 733b014..56ce96f 100644
79205 --- a/sound/oss/sb_audio.c
79206 +++ b/sound/oss/sb_audio.c
79207 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79208 buf16 = (signed short *)(localbuf + localoffs);
79209 while (c)
79210 {
79211 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79212 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79213 if (copy_from_user(lbuf8,
79214 userbuf+useroffs + p,
79215 locallen))
79216 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79217 index 09d4648..cf234c7 100644
79218 --- a/sound/oss/swarm_cs4297a.c
79219 +++ b/sound/oss/swarm_cs4297a.c
79220 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79221 {
79222 struct cs4297a_state *s;
79223 u32 pwr, id;
79224 - mm_segment_t fs;
79225 int rval;
79226 #ifndef CONFIG_BCM_CS4297A_CSWARM
79227 u64 cfg;
79228 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
79229 if (!rval) {
79230 char *sb1250_duart_present;
79231
79232 +#if 0
79233 + mm_segment_t fs;
79234 fs = get_fs();
79235 set_fs(KERNEL_DS);
79236 -#if 0
79237 val = SOUND_MASK_LINE;
79238 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
79239 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
79240 val = initvol[i].vol;
79241 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
79242 }
79243 + set_fs(fs);
79244 // cs4297a_write_ac97(s, 0x18, 0x0808);
79245 #else
79246 // cs4297a_write_ac97(s, 0x5e, 0x180);
79247 cs4297a_write_ac97(s, 0x02, 0x0808);
79248 cs4297a_write_ac97(s, 0x18, 0x0808);
79249 #endif
79250 - set_fs(fs);
79251
79252 list_add(&s->list, &cs4297a_devs);
79253
79254 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
79255 index 71f6744..d8aeae7 100644
79256 --- a/sound/pci/hda/hda_codec.h
79257 +++ b/sound/pci/hda/hda_codec.h
79258 @@ -614,7 +614,7 @@ struct hda_bus_ops {
79259 /* notify power-up/down from codec to controller */
79260 void (*pm_notify)(struct hda_bus *bus);
79261 #endif
79262 -};
79263 +} __no_const;
79264
79265 /* template to pass to the bus constructor */
79266 struct hda_bus_template {
79267 @@ -716,6 +716,7 @@ struct hda_codec_ops {
79268 #endif
79269 void (*reboot_notify)(struct hda_codec *codec);
79270 };
79271 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
79272
79273 /* record for amp information cache */
79274 struct hda_cache_head {
79275 @@ -746,7 +747,7 @@ struct hda_pcm_ops {
79276 struct snd_pcm_substream *substream);
79277 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
79278 struct snd_pcm_substream *substream);
79279 -};
79280 +} __no_const;
79281
79282 /* PCM information for each substream */
79283 struct hda_pcm_stream {
79284 @@ -804,7 +805,7 @@ struct hda_codec {
79285 const char *modelname; /* model name for preset */
79286
79287 /* set by patch */
79288 - struct hda_codec_ops patch_ops;
79289 + hda_codec_ops_no_const patch_ops;
79290
79291 /* PCM to create, set by patch_ops.build_pcms callback */
79292 unsigned int num_pcms;
79293 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
79294 index 0da778a..bc38b84 100644
79295 --- a/sound/pci/ice1712/ice1712.h
79296 +++ b/sound/pci/ice1712/ice1712.h
79297 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
79298 unsigned int mask_flags; /* total mask bits */
79299 struct snd_akm4xxx_ops {
79300 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
79301 - } ops;
79302 + } __no_const ops;
79303 };
79304
79305 struct snd_ice1712_spdif {
79306 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
79307 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79308 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79309 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79310 - } ops;
79311 + } __no_const ops;
79312 };
79313
79314
79315 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
79316 index 03ee4e3..be86b46 100644
79317 --- a/sound/pci/ymfpci/ymfpci_main.c
79318 +++ b/sound/pci/ymfpci/ymfpci_main.c
79319 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
79320 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
79321 break;
79322 }
79323 - if (atomic_read(&chip->interrupt_sleep_count)) {
79324 - atomic_set(&chip->interrupt_sleep_count, 0);
79325 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79326 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79327 wake_up(&chip->interrupt_sleep);
79328 }
79329 __end:
79330 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
79331 continue;
79332 init_waitqueue_entry(&wait, current);
79333 add_wait_queue(&chip->interrupt_sleep, &wait);
79334 - atomic_inc(&chip->interrupt_sleep_count);
79335 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
79336 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
79337 remove_wait_queue(&chip->interrupt_sleep, &wait);
79338 }
79339 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
79340 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
79341 spin_unlock(&chip->reg_lock);
79342
79343 - if (atomic_read(&chip->interrupt_sleep_count)) {
79344 - atomic_set(&chip->interrupt_sleep_count, 0);
79345 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79346 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79347 wake_up(&chip->interrupt_sleep);
79348 }
79349 }
79350 @@ -2382,7 +2382,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
79351 spin_lock_init(&chip->reg_lock);
79352 spin_lock_init(&chip->voice_lock);
79353 init_waitqueue_head(&chip->interrupt_sleep);
79354 - atomic_set(&chip->interrupt_sleep_count, 0);
79355 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79356 chip->card = card;
79357 chip->pci = pci;
79358 chip->irq = -1;
79359 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
79360 index ee15337..e2187a6 100644
79361 --- a/sound/soc/soc-pcm.c
79362 +++ b/sound/soc/soc-pcm.c
79363 @@ -583,7 +583,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
79364 }
79365
79366 /* ASoC PCM operations */
79367 -static struct snd_pcm_ops soc_pcm_ops = {
79368 +static snd_pcm_ops_no_const soc_pcm_ops = {
79369 .open = soc_pcm_open,
79370 .close = soc_pcm_close,
79371 .hw_params = soc_pcm_hw_params,
79372 diff --git a/sound/usb/card.h b/sound/usb/card.h
79373 index a39edcc..1014050 100644
79374 --- a/sound/usb/card.h
79375 +++ b/sound/usb/card.h
79376 @@ -44,6 +44,7 @@ struct snd_urb_ops {
79377 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79378 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79379 };
79380 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
79381
79382 struct snd_usb_substream {
79383 struct snd_usb_stream *stream;
79384 @@ -93,7 +94,7 @@ struct snd_usb_substream {
79385 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
79386 spinlock_t lock;
79387
79388 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
79389 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
79390 int last_frame_number; /* stored frame number */
79391 int last_delay; /* stored delay */
79392 };
79393 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
79394 new file mode 100644
79395 index 0000000..894c8bf
79396 --- /dev/null
79397 +++ b/tools/gcc/Makefile
79398 @@ -0,0 +1,23 @@
79399 +#CC := gcc
79400 +#PLUGIN_SOURCE_FILES := pax_plugin.c
79401 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
79402 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
79403 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
79404 +
79405 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
79406 +
79407 +hostlibs-y := constify_plugin.so
79408 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
79409 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
79410 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
79411 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
79412 +hostlibs-y += colorize_plugin.so
79413 +
79414 +always := $(hostlibs-y)
79415 +
79416 +constify_plugin-objs := constify_plugin.o
79417 +stackleak_plugin-objs := stackleak_plugin.o
79418 +kallocstat_plugin-objs := kallocstat_plugin.o
79419 +kernexec_plugin-objs := kernexec_plugin.o
79420 +checker_plugin-objs := checker_plugin.o
79421 +colorize_plugin-objs := colorize_plugin.o
79422 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
79423 new file mode 100644
79424 index 0000000..d41b5af
79425 --- /dev/null
79426 +++ b/tools/gcc/checker_plugin.c
79427 @@ -0,0 +1,171 @@
79428 +/*
79429 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79430 + * Licensed under the GPL v2
79431 + *
79432 + * Note: the choice of the license means that the compilation process is
79433 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79434 + * but for the kernel it doesn't matter since it doesn't link against
79435 + * any of the gcc libraries
79436 + *
79437 + * gcc plugin to implement various sparse (source code checker) features
79438 + *
79439 + * TODO:
79440 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
79441 + *
79442 + * BUGS:
79443 + * - none known
79444 + */
79445 +#include "gcc-plugin.h"
79446 +#include "config.h"
79447 +#include "system.h"
79448 +#include "coretypes.h"
79449 +#include "tree.h"
79450 +#include "tree-pass.h"
79451 +#include "flags.h"
79452 +#include "intl.h"
79453 +#include "toplev.h"
79454 +#include "plugin.h"
79455 +//#include "expr.h" where are you...
79456 +#include "diagnostic.h"
79457 +#include "plugin-version.h"
79458 +#include "tm.h"
79459 +#include "function.h"
79460 +#include "basic-block.h"
79461 +#include "gimple.h"
79462 +#include "rtl.h"
79463 +#include "emit-rtl.h"
79464 +#include "tree-flow.h"
79465 +#include "target.h"
79466 +
79467 +extern void c_register_addr_space (const char *str, addr_space_t as);
79468 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
79469 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
79470 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
79471 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
79472 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
79473 +
79474 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79475 +extern rtx emit_move_insn(rtx x, rtx y);
79476 +
79477 +int plugin_is_GPL_compatible;
79478 +
79479 +static struct plugin_info checker_plugin_info = {
79480 + .version = "201111150100",
79481 +};
79482 +
79483 +#define ADDR_SPACE_KERNEL 0
79484 +#define ADDR_SPACE_FORCE_KERNEL 1
79485 +#define ADDR_SPACE_USER 2
79486 +#define ADDR_SPACE_FORCE_USER 3
79487 +#define ADDR_SPACE_IOMEM 0
79488 +#define ADDR_SPACE_FORCE_IOMEM 0
79489 +#define ADDR_SPACE_PERCPU 0
79490 +#define ADDR_SPACE_FORCE_PERCPU 0
79491 +#define ADDR_SPACE_RCU 0
79492 +#define ADDR_SPACE_FORCE_RCU 0
79493 +
79494 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
79495 +{
79496 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
79497 +}
79498 +
79499 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
79500 +{
79501 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
79502 +}
79503 +
79504 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
79505 +{
79506 + return default_addr_space_valid_pointer_mode(mode, as);
79507 +}
79508 +
79509 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
79510 +{
79511 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
79512 +}
79513 +
79514 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
79515 +{
79516 + return default_addr_space_legitimize_address(x, oldx, mode, as);
79517 +}
79518 +
79519 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
79520 +{
79521 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
79522 + return true;
79523 +
79524 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
79525 + return true;
79526 +
79527 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
79528 + return true;
79529 +
79530 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
79531 + return true;
79532 +
79533 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
79534 + return true;
79535 +
79536 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
79537 + return true;
79538 +
79539 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
79540 + return true;
79541 +
79542 + return subset == superset;
79543 +}
79544 +
79545 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
79546 +{
79547 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
79548 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
79549 +
79550 + return op;
79551 +}
79552 +
79553 +static void register_checker_address_spaces(void *event_data, void *data)
79554 +{
79555 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
79556 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
79557 + c_register_addr_space("__user", ADDR_SPACE_USER);
79558 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
79559 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
79560 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
79561 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
79562 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
79563 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
79564 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
79565 +
79566 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
79567 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
79568 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
79569 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
79570 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
79571 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
79572 + targetm.addr_space.convert = checker_addr_space_convert;
79573 +}
79574 +
79575 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79576 +{
79577 + const char * const plugin_name = plugin_info->base_name;
79578 + const int argc = plugin_info->argc;
79579 + const struct plugin_argument * const argv = plugin_info->argv;
79580 + int i;
79581 +
79582 + if (!plugin_default_version_check(version, &gcc_version)) {
79583 + error(G_("incompatible gcc/plugin versions"));
79584 + return 1;
79585 + }
79586 +
79587 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
79588 +
79589 + for (i = 0; i < argc; ++i)
79590 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79591 +
79592 + if (TARGET_64BIT == 0)
79593 + return 0;
79594 +
79595 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
79596 +
79597 + return 0;
79598 +}
79599 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
79600 new file mode 100644
79601 index 0000000..ee950d0
79602 --- /dev/null
79603 +++ b/tools/gcc/colorize_plugin.c
79604 @@ -0,0 +1,147 @@
79605 +/*
79606 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
79607 + * Licensed under the GPL v2
79608 + *
79609 + * Note: the choice of the license means that the compilation process is
79610 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79611 + * but for the kernel it doesn't matter since it doesn't link against
79612 + * any of the gcc libraries
79613 + *
79614 + * gcc plugin to colorize diagnostic output
79615 + *
79616 + */
79617 +
79618 +#include "gcc-plugin.h"
79619 +#include "config.h"
79620 +#include "system.h"
79621 +#include "coretypes.h"
79622 +#include "tree.h"
79623 +#include "tree-pass.h"
79624 +#include "flags.h"
79625 +#include "intl.h"
79626 +#include "toplev.h"
79627 +#include "plugin.h"
79628 +#include "diagnostic.h"
79629 +#include "plugin-version.h"
79630 +#include "tm.h"
79631 +
79632 +int plugin_is_GPL_compatible;
79633 +
79634 +static struct plugin_info colorize_plugin_info = {
79635 + .version = "201203092200",
79636 +};
79637 +
79638 +#define GREEN "\033[32m\033[2m"
79639 +#define LIGHTGREEN "\033[32m\033[1m"
79640 +#define YELLOW "\033[33m\033[2m"
79641 +#define LIGHTYELLOW "\033[33m\033[1m"
79642 +#define RED "\033[31m\033[2m"
79643 +#define LIGHTRED "\033[31m\033[1m"
79644 +#define BLUE "\033[34m\033[2m"
79645 +#define LIGHTBLUE "\033[34m\033[1m"
79646 +#define BRIGHT "\033[m\033[1m"
79647 +#define NORMAL "\033[m"
79648 +
79649 +static diagnostic_starter_fn old_starter;
79650 +static diagnostic_finalizer_fn old_finalizer;
79651 +
79652 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79653 +{
79654 + const char *color;
79655 + char *newprefix;
79656 +
79657 + switch (diagnostic->kind) {
79658 + case DK_NOTE:
79659 + color = LIGHTBLUE;
79660 + break;
79661 +
79662 + case DK_PEDWARN:
79663 + case DK_WARNING:
79664 + color = LIGHTYELLOW;
79665 + break;
79666 +
79667 + case DK_ERROR:
79668 + case DK_FATAL:
79669 + case DK_ICE:
79670 + case DK_PERMERROR:
79671 + case DK_SORRY:
79672 + color = LIGHTRED;
79673 + break;
79674 +
79675 + default:
79676 + color = NORMAL;
79677 + }
79678 +
79679 + old_starter(context, diagnostic);
79680 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
79681 + return;
79682 + pp_destroy_prefix(context->printer);
79683 + pp_set_prefix(context->printer, newprefix);
79684 +}
79685 +
79686 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79687 +{
79688 + old_finalizer(context, diagnostic);
79689 +}
79690 +
79691 +static void colorize_arm(void)
79692 +{
79693 + old_starter = diagnostic_starter(global_dc);
79694 + old_finalizer = diagnostic_finalizer(global_dc);
79695 +
79696 + diagnostic_starter(global_dc) = start_colorize;
79697 + diagnostic_finalizer(global_dc) = finalize_colorize;
79698 +}
79699 +
79700 +static unsigned int execute_colorize_rearm(void)
79701 +{
79702 + if (diagnostic_starter(global_dc) == start_colorize)
79703 + return 0;
79704 +
79705 + colorize_arm();
79706 + return 0;
79707 +}
79708 +
79709 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
79710 + .pass = {
79711 + .type = SIMPLE_IPA_PASS,
79712 + .name = "colorize_rearm",
79713 + .gate = NULL,
79714 + .execute = execute_colorize_rearm,
79715 + .sub = NULL,
79716 + .next = NULL,
79717 + .static_pass_number = 0,
79718 + .tv_id = TV_NONE,
79719 + .properties_required = 0,
79720 + .properties_provided = 0,
79721 + .properties_destroyed = 0,
79722 + .todo_flags_start = 0,
79723 + .todo_flags_finish = 0
79724 + }
79725 +};
79726 +
79727 +static void colorize_start_unit(void *gcc_data, void *user_data)
79728 +{
79729 + colorize_arm();
79730 +}
79731 +
79732 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79733 +{
79734 + const char * const plugin_name = plugin_info->base_name;
79735 + struct register_pass_info colorize_rearm_pass_info = {
79736 + .pass = &pass_ipa_colorize_rearm.pass,
79737 + .reference_pass_name = "*free_lang_data",
79738 + .ref_pass_instance_number = 0,
79739 + .pos_op = PASS_POS_INSERT_AFTER
79740 + };
79741 +
79742 + if (!plugin_default_version_check(version, &gcc_version)) {
79743 + error(G_("incompatible gcc/plugin versions"));
79744 + return 1;
79745 + }
79746 +
79747 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
79748 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
79749 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
79750 + return 0;
79751 +}
79752 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
79753 new file mode 100644
79754 index 0000000..704a564
79755 --- /dev/null
79756 +++ b/tools/gcc/constify_plugin.c
79757 @@ -0,0 +1,303 @@
79758 +/*
79759 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
79760 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
79761 + * Licensed under the GPL v2, or (at your option) v3
79762 + *
79763 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
79764 + *
79765 + * Homepage:
79766 + * http://www.grsecurity.net/~ephox/const_plugin/
79767 + *
79768 + * Usage:
79769 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
79770 + * $ gcc -fplugin=constify_plugin.so test.c -O2
79771 + */
79772 +
79773 +#include "gcc-plugin.h"
79774 +#include "config.h"
79775 +#include "system.h"
79776 +#include "coretypes.h"
79777 +#include "tree.h"
79778 +#include "tree-pass.h"
79779 +#include "flags.h"
79780 +#include "intl.h"
79781 +#include "toplev.h"
79782 +#include "plugin.h"
79783 +#include "diagnostic.h"
79784 +#include "plugin-version.h"
79785 +#include "tm.h"
79786 +#include "function.h"
79787 +#include "basic-block.h"
79788 +#include "gimple.h"
79789 +#include "rtl.h"
79790 +#include "emit-rtl.h"
79791 +#include "tree-flow.h"
79792 +
79793 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
79794 +
79795 +int plugin_is_GPL_compatible;
79796 +
79797 +static struct plugin_info const_plugin_info = {
79798 + .version = "201111150100",
79799 + .help = "no-constify\tturn off constification\n",
79800 +};
79801 +
79802 +static void constify_type(tree type);
79803 +static bool walk_struct(tree node);
79804 +
79805 +static tree deconstify_type(tree old_type)
79806 +{
79807 + tree new_type, field;
79808 +
79809 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
79810 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
79811 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
79812 + DECL_FIELD_CONTEXT(field) = new_type;
79813 + TYPE_READONLY(new_type) = 0;
79814 + C_TYPE_FIELDS_READONLY(new_type) = 0;
79815 + return new_type;
79816 +}
79817 +
79818 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79819 +{
79820 + tree type;
79821 +
79822 + *no_add_attrs = true;
79823 + if (TREE_CODE(*node) == FUNCTION_DECL) {
79824 + error("%qE attribute does not apply to functions", name);
79825 + return NULL_TREE;
79826 + }
79827 +
79828 + if (TREE_CODE(*node) == VAR_DECL) {
79829 + error("%qE attribute does not apply to variables", name);
79830 + return NULL_TREE;
79831 + }
79832 +
79833 + if (TYPE_P(*node)) {
79834 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
79835 + *no_add_attrs = false;
79836 + else
79837 + error("%qE attribute applies to struct and union types only", name);
79838 + return NULL_TREE;
79839 + }
79840 +
79841 + type = TREE_TYPE(*node);
79842 +
79843 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
79844 + error("%qE attribute applies to struct and union types only", name);
79845 + return NULL_TREE;
79846 + }
79847 +
79848 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
79849 + error("%qE attribute is already applied to the type", name);
79850 + return NULL_TREE;
79851 + }
79852 +
79853 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
79854 + error("%qE attribute used on type that is not constified", name);
79855 + return NULL_TREE;
79856 + }
79857 +
79858 + if (TREE_CODE(*node) == TYPE_DECL) {
79859 + TREE_TYPE(*node) = deconstify_type(type);
79860 + TREE_READONLY(*node) = 0;
79861 + return NULL_TREE;
79862 + }
79863 +
79864 + return NULL_TREE;
79865 +}
79866 +
79867 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79868 +{
79869 + *no_add_attrs = true;
79870 + if (!TYPE_P(*node)) {
79871 + error("%qE attribute applies to types only", name);
79872 + return NULL_TREE;
79873 + }
79874 +
79875 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
79876 + error("%qE attribute applies to struct and union types only", name);
79877 + return NULL_TREE;
79878 + }
79879 +
79880 + *no_add_attrs = false;
79881 + constify_type(*node);
79882 + return NULL_TREE;
79883 +}
79884 +
79885 +static struct attribute_spec no_const_attr = {
79886 + .name = "no_const",
79887 + .min_length = 0,
79888 + .max_length = 0,
79889 + .decl_required = false,
79890 + .type_required = false,
79891 + .function_type_required = false,
79892 + .handler = handle_no_const_attribute,
79893 +#if BUILDING_GCC_VERSION >= 4007
79894 + .affects_type_identity = true
79895 +#endif
79896 +};
79897 +
79898 +static struct attribute_spec do_const_attr = {
79899 + .name = "do_const",
79900 + .min_length = 0,
79901 + .max_length = 0,
79902 + .decl_required = false,
79903 + .type_required = false,
79904 + .function_type_required = false,
79905 + .handler = handle_do_const_attribute,
79906 +#if BUILDING_GCC_VERSION >= 4007
79907 + .affects_type_identity = true
79908 +#endif
79909 +};
79910 +
79911 +static void register_attributes(void *event_data, void *data)
79912 +{
79913 + register_attribute(&no_const_attr);
79914 + register_attribute(&do_const_attr);
79915 +}
79916 +
79917 +static void constify_type(tree type)
79918 +{
79919 + TYPE_READONLY(type) = 1;
79920 + C_TYPE_FIELDS_READONLY(type) = 1;
79921 +}
79922 +
79923 +static bool is_fptr(tree field)
79924 +{
79925 + tree ptr = TREE_TYPE(field);
79926 +
79927 + if (TREE_CODE(ptr) != POINTER_TYPE)
79928 + return false;
79929 +
79930 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
79931 +}
79932 +
79933 +static bool walk_struct(tree node)
79934 +{
79935 + tree field;
79936 +
79937 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
79938 + return false;
79939 +
79940 + if (TYPE_FIELDS(node) == NULL_TREE)
79941 + return false;
79942 +
79943 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
79944 + tree type = TREE_TYPE(field);
79945 + enum tree_code code = TREE_CODE(type);
79946 + if (code == RECORD_TYPE || code == UNION_TYPE) {
79947 + if (!(walk_struct(type)))
79948 + return false;
79949 + } else if (!is_fptr(field) && !TREE_READONLY(field))
79950 + return false;
79951 + }
79952 + return true;
79953 +}
79954 +
79955 +static void finish_type(void *event_data, void *data)
79956 +{
79957 + tree type = (tree)event_data;
79958 +
79959 + if (type == NULL_TREE)
79960 + return;
79961 +
79962 + if (TYPE_READONLY(type))
79963 + return;
79964 +
79965 + if (walk_struct(type))
79966 + constify_type(type);
79967 +}
79968 +
79969 +static unsigned int check_local_variables(void);
79970 +
79971 +struct gimple_opt_pass pass_local_variable = {
79972 + {
79973 + .type = GIMPLE_PASS,
79974 + .name = "check_local_variables",
79975 + .gate = NULL,
79976 + .execute = check_local_variables,
79977 + .sub = NULL,
79978 + .next = NULL,
79979 + .static_pass_number = 0,
79980 + .tv_id = TV_NONE,
79981 + .properties_required = 0,
79982 + .properties_provided = 0,
79983 + .properties_destroyed = 0,
79984 + .todo_flags_start = 0,
79985 + .todo_flags_finish = 0
79986 + }
79987 +};
79988 +
79989 +static unsigned int check_local_variables(void)
79990 +{
79991 + tree var;
79992 + referenced_var_iterator rvi;
79993 +
79994 +#if BUILDING_GCC_VERSION == 4005
79995 + FOR_EACH_REFERENCED_VAR(var, rvi) {
79996 +#else
79997 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
79998 +#endif
79999 + tree type = TREE_TYPE(var);
80000 +
80001 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80002 + continue;
80003 +
80004 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80005 + continue;
80006 +
80007 + if (!TYPE_READONLY(type))
80008 + continue;
80009 +
80010 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80011 +// continue;
80012 +
80013 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80014 +// continue;
80015 +
80016 + if (walk_struct(type)) {
80017 + error("constified variable %qE cannot be local", var);
80018 + return 1;
80019 + }
80020 + }
80021 + return 0;
80022 +}
80023 +
80024 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80025 +{
80026 + const char * const plugin_name = plugin_info->base_name;
80027 + const int argc = plugin_info->argc;
80028 + const struct plugin_argument * const argv = plugin_info->argv;
80029 + int i;
80030 + bool constify = true;
80031 +
80032 + struct register_pass_info local_variable_pass_info = {
80033 + .pass = &pass_local_variable.pass,
80034 + .reference_pass_name = "*referenced_vars",
80035 + .ref_pass_instance_number = 0,
80036 + .pos_op = PASS_POS_INSERT_AFTER
80037 + };
80038 +
80039 + if (!plugin_default_version_check(version, &gcc_version)) {
80040 + error(G_("incompatible gcc/plugin versions"));
80041 + return 1;
80042 + }
80043 +
80044 + for (i = 0; i < argc; ++i) {
80045 + if (!(strcmp(argv[i].key, "no-constify"))) {
80046 + constify = false;
80047 + continue;
80048 + }
80049 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80050 + }
80051 +
80052 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80053 + if (constify) {
80054 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80055 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80056 + }
80057 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80058 +
80059 + return 0;
80060 +}
80061 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80062 new file mode 100644
80063 index 0000000..a5eabce
80064 --- /dev/null
80065 +++ b/tools/gcc/kallocstat_plugin.c
80066 @@ -0,0 +1,167 @@
80067 +/*
80068 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80069 + * Licensed under the GPL v2
80070 + *
80071 + * Note: the choice of the license means that the compilation process is
80072 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80073 + * but for the kernel it doesn't matter since it doesn't link against
80074 + * any of the gcc libraries
80075 + *
80076 + * gcc plugin to find the distribution of k*alloc sizes
80077 + *
80078 + * TODO:
80079 + *
80080 + * BUGS:
80081 + * - none known
80082 + */
80083 +#include "gcc-plugin.h"
80084 +#include "config.h"
80085 +#include "system.h"
80086 +#include "coretypes.h"
80087 +#include "tree.h"
80088 +#include "tree-pass.h"
80089 +#include "flags.h"
80090 +#include "intl.h"
80091 +#include "toplev.h"
80092 +#include "plugin.h"
80093 +//#include "expr.h" where are you...
80094 +#include "diagnostic.h"
80095 +#include "plugin-version.h"
80096 +#include "tm.h"
80097 +#include "function.h"
80098 +#include "basic-block.h"
80099 +#include "gimple.h"
80100 +#include "rtl.h"
80101 +#include "emit-rtl.h"
80102 +
80103 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80104 +
80105 +int plugin_is_GPL_compatible;
80106 +
80107 +static const char * const kalloc_functions[] = {
80108 + "__kmalloc",
80109 + "kmalloc",
80110 + "kmalloc_large",
80111 + "kmalloc_node",
80112 + "kmalloc_order",
80113 + "kmalloc_order_trace",
80114 + "kmalloc_slab",
80115 + "kzalloc",
80116 + "kzalloc_node",
80117 +};
80118 +
80119 +static struct plugin_info kallocstat_plugin_info = {
80120 + .version = "201111150100",
80121 +};
80122 +
80123 +static unsigned int execute_kallocstat(void);
80124 +
80125 +static struct gimple_opt_pass kallocstat_pass = {
80126 + .pass = {
80127 + .type = GIMPLE_PASS,
80128 + .name = "kallocstat",
80129 + .gate = NULL,
80130 + .execute = execute_kallocstat,
80131 + .sub = NULL,
80132 + .next = NULL,
80133 + .static_pass_number = 0,
80134 + .tv_id = TV_NONE,
80135 + .properties_required = 0,
80136 + .properties_provided = 0,
80137 + .properties_destroyed = 0,
80138 + .todo_flags_start = 0,
80139 + .todo_flags_finish = 0
80140 + }
80141 +};
80142 +
80143 +static bool is_kalloc(const char *fnname)
80144 +{
80145 + size_t i;
80146 +
80147 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80148 + if (!strcmp(fnname, kalloc_functions[i]))
80149 + return true;
80150 + return false;
80151 +}
80152 +
80153 +static unsigned int execute_kallocstat(void)
80154 +{
80155 + basic_block bb;
80156 +
80157 + // 1. loop through BBs and GIMPLE statements
80158 + FOR_EACH_BB(bb) {
80159 + gimple_stmt_iterator gsi;
80160 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80161 + // gimple match:
80162 + tree fndecl, size;
80163 + gimple call_stmt;
80164 + const char *fnname;
80165 +
80166 + // is it a call
80167 + call_stmt = gsi_stmt(gsi);
80168 + if (!is_gimple_call(call_stmt))
80169 + continue;
80170 + fndecl = gimple_call_fndecl(call_stmt);
80171 + if (fndecl == NULL_TREE)
80172 + continue;
80173 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80174 + continue;
80175 +
80176 + // is it a call to k*alloc
80177 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80178 + if (!is_kalloc(fnname))
80179 + continue;
80180 +
80181 + // is the size arg the result of a simple const assignment
80182 + size = gimple_call_arg(call_stmt, 0);
80183 + while (true) {
80184 + gimple def_stmt;
80185 + expanded_location xloc;
80186 + size_t size_val;
80187 +
80188 + if (TREE_CODE(size) != SSA_NAME)
80189 + break;
80190 + def_stmt = SSA_NAME_DEF_STMT(size);
80191 + if (!def_stmt || !is_gimple_assign(def_stmt))
80192 + break;
80193 + if (gimple_num_ops(def_stmt) != 2)
80194 + break;
80195 + size = gimple_assign_rhs1(def_stmt);
80196 + if (!TREE_CONSTANT(size))
80197 + continue;
80198 + xloc = expand_location(gimple_location(def_stmt));
80199 + if (!xloc.file)
80200 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80201 + size_val = TREE_INT_CST_LOW(size);
80202 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80203 + break;
80204 + }
80205 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80206 +//debug_tree(gimple_call_fn(call_stmt));
80207 +//print_node(stderr, "pax", fndecl, 4);
80208 + }
80209 + }
80210 +
80211 + return 0;
80212 +}
80213 +
80214 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80215 +{
80216 + const char * const plugin_name = plugin_info->base_name;
80217 + struct register_pass_info kallocstat_pass_info = {
80218 + .pass = &kallocstat_pass.pass,
80219 + .reference_pass_name = "ssa",
80220 + .ref_pass_instance_number = 0,
80221 + .pos_op = PASS_POS_INSERT_AFTER
80222 + };
80223 +
80224 + if (!plugin_default_version_check(version, &gcc_version)) {
80225 + error(G_("incompatible gcc/plugin versions"));
80226 + return 1;
80227 + }
80228 +
80229 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
80230 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
80231 +
80232 + return 0;
80233 +}
80234 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
80235 new file mode 100644
80236 index 0000000..008f159
80237 --- /dev/null
80238 +++ b/tools/gcc/kernexec_plugin.c
80239 @@ -0,0 +1,427 @@
80240 +/*
80241 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80242 + * Licensed under the GPL v2
80243 + *
80244 + * Note: the choice of the license means that the compilation process is
80245 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80246 + * but for the kernel it doesn't matter since it doesn't link against
80247 + * any of the gcc libraries
80248 + *
80249 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
80250 + *
80251 + * TODO:
80252 + *
80253 + * BUGS:
80254 + * - none known
80255 + */
80256 +#include "gcc-plugin.h"
80257 +#include "config.h"
80258 +#include "system.h"
80259 +#include "coretypes.h"
80260 +#include "tree.h"
80261 +#include "tree-pass.h"
80262 +#include "flags.h"
80263 +#include "intl.h"
80264 +#include "toplev.h"
80265 +#include "plugin.h"
80266 +//#include "expr.h" where are you...
80267 +#include "diagnostic.h"
80268 +#include "plugin-version.h"
80269 +#include "tm.h"
80270 +#include "function.h"
80271 +#include "basic-block.h"
80272 +#include "gimple.h"
80273 +#include "rtl.h"
80274 +#include "emit-rtl.h"
80275 +#include "tree-flow.h"
80276 +
80277 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80278 +extern rtx emit_move_insn(rtx x, rtx y);
80279 +
80280 +int plugin_is_GPL_compatible;
80281 +
80282 +static struct plugin_info kernexec_plugin_info = {
80283 + .version = "201111291120",
80284 + .help = "method=[bts|or]\tinstrumentation method\n"
80285 +};
80286 +
80287 +static unsigned int execute_kernexec_reload(void);
80288 +static unsigned int execute_kernexec_fptr(void);
80289 +static unsigned int execute_kernexec_retaddr(void);
80290 +static bool kernexec_cmodel_check(void);
80291 +
80292 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
80293 +static void (*kernexec_instrument_retaddr)(rtx);
80294 +
80295 +static struct gimple_opt_pass kernexec_reload_pass = {
80296 + .pass = {
80297 + .type = GIMPLE_PASS,
80298 + .name = "kernexec_reload",
80299 + .gate = kernexec_cmodel_check,
80300 + .execute = execute_kernexec_reload,
80301 + .sub = NULL,
80302 + .next = NULL,
80303 + .static_pass_number = 0,
80304 + .tv_id = TV_NONE,
80305 + .properties_required = 0,
80306 + .properties_provided = 0,
80307 + .properties_destroyed = 0,
80308 + .todo_flags_start = 0,
80309 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80310 + }
80311 +};
80312 +
80313 +static struct gimple_opt_pass kernexec_fptr_pass = {
80314 + .pass = {
80315 + .type = GIMPLE_PASS,
80316 + .name = "kernexec_fptr",
80317 + .gate = kernexec_cmodel_check,
80318 + .execute = execute_kernexec_fptr,
80319 + .sub = NULL,
80320 + .next = NULL,
80321 + .static_pass_number = 0,
80322 + .tv_id = TV_NONE,
80323 + .properties_required = 0,
80324 + .properties_provided = 0,
80325 + .properties_destroyed = 0,
80326 + .todo_flags_start = 0,
80327 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80328 + }
80329 +};
80330 +
80331 +static struct rtl_opt_pass kernexec_retaddr_pass = {
80332 + .pass = {
80333 + .type = RTL_PASS,
80334 + .name = "kernexec_retaddr",
80335 + .gate = kernexec_cmodel_check,
80336 + .execute = execute_kernexec_retaddr,
80337 + .sub = NULL,
80338 + .next = NULL,
80339 + .static_pass_number = 0,
80340 + .tv_id = TV_NONE,
80341 + .properties_required = 0,
80342 + .properties_provided = 0,
80343 + .properties_destroyed = 0,
80344 + .todo_flags_start = 0,
80345 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
80346 + }
80347 +};
80348 +
80349 +static bool kernexec_cmodel_check(void)
80350 +{
80351 + tree section;
80352 +
80353 + if (ix86_cmodel != CM_KERNEL)
80354 + return false;
80355 +
80356 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
80357 + if (!section || !TREE_VALUE(section))
80358 + return true;
80359 +
80360 + section = TREE_VALUE(TREE_VALUE(section));
80361 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
80362 + return true;
80363 +
80364 + return false;
80365 +}
80366 +
80367 +/*
80368 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
80369 + */
80370 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
80371 +{
80372 + gimple asm_movabs_stmt;
80373 +
80374 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
80375 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
80376 + gimple_asm_set_volatile(asm_movabs_stmt, true);
80377 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
80378 + update_stmt(asm_movabs_stmt);
80379 +}
80380 +
80381 +/*
80382 + * find all asm() stmts that clobber r10 and add a reload of r10
80383 + */
80384 +static unsigned int execute_kernexec_reload(void)
80385 +{
80386 + basic_block bb;
80387 +
80388 + // 1. loop through BBs and GIMPLE statements
80389 + FOR_EACH_BB(bb) {
80390 + gimple_stmt_iterator gsi;
80391 +
80392 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80393 + // gimple match: __asm__ ("" : : : "r10");
80394 + gimple asm_stmt;
80395 + size_t nclobbers;
80396 +
80397 + // is it an asm ...
80398 + asm_stmt = gsi_stmt(gsi);
80399 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
80400 + continue;
80401 +
80402 + // ... clobbering r10
80403 + nclobbers = gimple_asm_nclobbers(asm_stmt);
80404 + while (nclobbers--) {
80405 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
80406 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
80407 + continue;
80408 + kernexec_reload_fptr_mask(&gsi);
80409 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
80410 + break;
80411 + }
80412 + }
80413 + }
80414 +
80415 + return 0;
80416 +}
80417 +
80418 +/*
80419 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
80420 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
80421 + */
80422 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
80423 +{
80424 + gimple assign_intptr, assign_new_fptr, call_stmt;
80425 + tree intptr, old_fptr, new_fptr, kernexec_mask;
80426 +
80427 + call_stmt = gsi_stmt(*gsi);
80428 + old_fptr = gimple_call_fn(call_stmt);
80429 +
80430 + // create temporary unsigned long variable used for bitops and cast fptr to it
80431 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
80432 + add_referenced_var(intptr);
80433 + mark_sym_for_renaming(intptr);
80434 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
80435 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80436 + update_stmt(assign_intptr);
80437 +
80438 + // apply logical or to temporary unsigned long and bitmask
80439 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
80440 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
80441 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
80442 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80443 + update_stmt(assign_intptr);
80444 +
80445 + // cast temporary unsigned long back to a temporary fptr variable
80446 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
80447 + add_referenced_var(new_fptr);
80448 + mark_sym_for_renaming(new_fptr);
80449 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
80450 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
80451 + update_stmt(assign_new_fptr);
80452 +
80453 + // replace call stmt fn with the new fptr
80454 + gimple_call_set_fn(call_stmt, new_fptr);
80455 + update_stmt(call_stmt);
80456 +}
80457 +
80458 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
80459 +{
80460 + gimple asm_or_stmt, call_stmt;
80461 + tree old_fptr, new_fptr, input, output;
80462 + VEC(tree, gc) *inputs = NULL;
80463 + VEC(tree, gc) *outputs = NULL;
80464 +
80465 + call_stmt = gsi_stmt(*gsi);
80466 + old_fptr = gimple_call_fn(call_stmt);
80467 +
80468 + // create temporary fptr variable
80469 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
80470 + add_referenced_var(new_fptr);
80471 + mark_sym_for_renaming(new_fptr);
80472 +
80473 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
80474 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
80475 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
80476 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
80477 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
80478 + VEC_safe_push(tree, gc, inputs, input);
80479 + VEC_safe_push(tree, gc, outputs, output);
80480 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
80481 + gimple_asm_set_volatile(asm_or_stmt, true);
80482 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
80483 + update_stmt(asm_or_stmt);
80484 +
80485 + // replace call stmt fn with the new fptr
80486 + gimple_call_set_fn(call_stmt, new_fptr);
80487 + update_stmt(call_stmt);
80488 +}
80489 +
80490 +/*
80491 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
80492 + */
80493 +static unsigned int execute_kernexec_fptr(void)
80494 +{
80495 + basic_block bb;
80496 +
80497 + // 1. loop through BBs and GIMPLE statements
80498 + FOR_EACH_BB(bb) {
80499 + gimple_stmt_iterator gsi;
80500 +
80501 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80502 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
80503 + tree fn;
80504 + gimple call_stmt;
80505 +
80506 + // is it a call ...
80507 + call_stmt = gsi_stmt(gsi);
80508 + if (!is_gimple_call(call_stmt))
80509 + continue;
80510 + fn = gimple_call_fn(call_stmt);
80511 + if (TREE_CODE(fn) == ADDR_EXPR)
80512 + continue;
80513 + if (TREE_CODE(fn) != SSA_NAME)
80514 + gcc_unreachable();
80515 +
80516 + // ... through a function pointer
80517 + fn = SSA_NAME_VAR(fn);
80518 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
80519 + continue;
80520 + fn = TREE_TYPE(fn);
80521 + if (TREE_CODE(fn) != POINTER_TYPE)
80522 + continue;
80523 + fn = TREE_TYPE(fn);
80524 + if (TREE_CODE(fn) != FUNCTION_TYPE)
80525 + continue;
80526 +
80527 + kernexec_instrument_fptr(&gsi);
80528 +
80529 +//debug_tree(gimple_call_fn(call_stmt));
80530 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80531 + }
80532 + }
80533 +
80534 + return 0;
80535 +}
80536 +
80537 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
80538 +static void kernexec_instrument_retaddr_bts(rtx insn)
80539 +{
80540 + rtx btsq;
80541 + rtvec argvec, constraintvec, labelvec;
80542 + int line;
80543 +
80544 + // create asm volatile("btsq $63,(%%rsp)":::)
80545 + argvec = rtvec_alloc(0);
80546 + constraintvec = rtvec_alloc(0);
80547 + labelvec = rtvec_alloc(0);
80548 + line = expand_location(RTL_LOCATION(insn)).line;
80549 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80550 + MEM_VOLATILE_P(btsq) = 1;
80551 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
80552 + emit_insn_before(btsq, insn);
80553 +}
80554 +
80555 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
80556 +static void kernexec_instrument_retaddr_or(rtx insn)
80557 +{
80558 + rtx orq;
80559 + rtvec argvec, constraintvec, labelvec;
80560 + int line;
80561 +
80562 + // create asm volatile("orq %%r10,(%%rsp)":::)
80563 + argvec = rtvec_alloc(0);
80564 + constraintvec = rtvec_alloc(0);
80565 + labelvec = rtvec_alloc(0);
80566 + line = expand_location(RTL_LOCATION(insn)).line;
80567 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80568 + MEM_VOLATILE_P(orq) = 1;
80569 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
80570 + emit_insn_before(orq, insn);
80571 +}
80572 +
80573 +/*
80574 + * find all asm level function returns and forcibly set the highest bit of the return address
80575 + */
80576 +static unsigned int execute_kernexec_retaddr(void)
80577 +{
80578 + rtx insn;
80579 +
80580 + // 1. find function returns
80581 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
80582 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
80583 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
80584 + rtx body;
80585 +
80586 + // is it a retn
80587 + if (!JUMP_P(insn))
80588 + continue;
80589 + body = PATTERN(insn);
80590 + if (GET_CODE(body) == PARALLEL)
80591 + body = XVECEXP(body, 0, 0);
80592 + if (GET_CODE(body) != RETURN)
80593 + continue;
80594 + kernexec_instrument_retaddr(insn);
80595 + }
80596 +
80597 +// print_simple_rtl(stderr, get_insns());
80598 +// print_rtl(stderr, get_insns());
80599 +
80600 + return 0;
80601 +}
80602 +
80603 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80604 +{
80605 + const char * const plugin_name = plugin_info->base_name;
80606 + const int argc = plugin_info->argc;
80607 + const struct plugin_argument * const argv = plugin_info->argv;
80608 + int i;
80609 + struct register_pass_info kernexec_reload_pass_info = {
80610 + .pass = &kernexec_reload_pass.pass,
80611 + .reference_pass_name = "ssa",
80612 + .ref_pass_instance_number = 0,
80613 + .pos_op = PASS_POS_INSERT_AFTER
80614 + };
80615 + struct register_pass_info kernexec_fptr_pass_info = {
80616 + .pass = &kernexec_fptr_pass.pass,
80617 + .reference_pass_name = "ssa",
80618 + .ref_pass_instance_number = 0,
80619 + .pos_op = PASS_POS_INSERT_AFTER
80620 + };
80621 + struct register_pass_info kernexec_retaddr_pass_info = {
80622 + .pass = &kernexec_retaddr_pass.pass,
80623 + .reference_pass_name = "pro_and_epilogue",
80624 + .ref_pass_instance_number = 0,
80625 + .pos_op = PASS_POS_INSERT_AFTER
80626 + };
80627 +
80628 + if (!plugin_default_version_check(version, &gcc_version)) {
80629 + error(G_("incompatible gcc/plugin versions"));
80630 + return 1;
80631 + }
80632 +
80633 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
80634 +
80635 + if (TARGET_64BIT == 0)
80636 + return 0;
80637 +
80638 + for (i = 0; i < argc; ++i) {
80639 + if (!strcmp(argv[i].key, "method")) {
80640 + if (!argv[i].value) {
80641 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80642 + continue;
80643 + }
80644 + if (!strcmp(argv[i].value, "bts")) {
80645 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
80646 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
80647 + } else if (!strcmp(argv[i].value, "or")) {
80648 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
80649 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
80650 + fix_register("r10", 1, 1);
80651 + } else
80652 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80653 + continue;
80654 + }
80655 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80656 + }
80657 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
80658 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
80659 +
80660 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
80661 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
80662 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
80663 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
80664 +
80665 + return 0;
80666 +}
80667 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
80668 new file mode 100644
80669 index 0000000..4e82b16
80670 --- /dev/null
80671 +++ b/tools/gcc/stackleak_plugin.c
80672 @@ -0,0 +1,311 @@
80673 +/*
80674 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80675 + * Licensed under the GPL v2
80676 + *
80677 + * Note: the choice of the license means that the compilation process is
80678 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80679 + * but for the kernel it doesn't matter since it doesn't link against
80680 + * any of the gcc libraries
80681 + *
80682 + * gcc plugin to help implement various PaX features
80683 + *
80684 + * - track lowest stack pointer
80685 + *
80686 + * TODO:
80687 + * - initialize all local variables
80688 + *
80689 + * BUGS:
80690 + * - none known
80691 + */
80692 +#include "gcc-plugin.h"
80693 +#include "config.h"
80694 +#include "system.h"
80695 +#include "coretypes.h"
80696 +#include "tree.h"
80697 +#include "tree-pass.h"
80698 +#include "flags.h"
80699 +#include "intl.h"
80700 +#include "toplev.h"
80701 +#include "plugin.h"
80702 +//#include "expr.h" where are you...
80703 +#include "diagnostic.h"
80704 +#include "plugin-version.h"
80705 +#include "tm.h"
80706 +#include "function.h"
80707 +#include "basic-block.h"
80708 +#include "gimple.h"
80709 +#include "rtl.h"
80710 +#include "emit-rtl.h"
80711 +
80712 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80713 +
80714 +int plugin_is_GPL_compatible;
80715 +
80716 +static int track_frame_size = -1;
80717 +static const char track_function[] = "pax_track_stack";
80718 +static const char check_function[] = "pax_check_alloca";
80719 +static bool init_locals;
80720 +
80721 +static struct plugin_info stackleak_plugin_info = {
80722 + .version = "201203140940",
80723 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
80724 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
80725 +};
80726 +
80727 +static bool gate_stackleak_track_stack(void);
80728 +static unsigned int execute_stackleak_tree_instrument(void);
80729 +static unsigned int execute_stackleak_final(void);
80730 +
80731 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
80732 + .pass = {
80733 + .type = GIMPLE_PASS,
80734 + .name = "stackleak_tree_instrument",
80735 + .gate = gate_stackleak_track_stack,
80736 + .execute = execute_stackleak_tree_instrument,
80737 + .sub = NULL,
80738 + .next = NULL,
80739 + .static_pass_number = 0,
80740 + .tv_id = TV_NONE,
80741 + .properties_required = PROP_gimple_leh | PROP_cfg,
80742 + .properties_provided = 0,
80743 + .properties_destroyed = 0,
80744 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
80745 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
80746 + }
80747 +};
80748 +
80749 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
80750 + .pass = {
80751 + .type = RTL_PASS,
80752 + .name = "stackleak_final",
80753 + .gate = gate_stackleak_track_stack,
80754 + .execute = execute_stackleak_final,
80755 + .sub = NULL,
80756 + .next = NULL,
80757 + .static_pass_number = 0,
80758 + .tv_id = TV_NONE,
80759 + .properties_required = 0,
80760 + .properties_provided = 0,
80761 + .properties_destroyed = 0,
80762 + .todo_flags_start = 0,
80763 + .todo_flags_finish = TODO_dump_func
80764 + }
80765 +};
80766 +
80767 +static bool gate_stackleak_track_stack(void)
80768 +{
80769 + return track_frame_size >= 0;
80770 +}
80771 +
80772 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
80773 +{
80774 + gimple check_alloca;
80775 + tree fntype, fndecl, alloca_size;
80776 +
80777 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
80778 + fndecl = build_fn_decl(check_function, fntype);
80779 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
80780 +
80781 + // insert call to void pax_check_alloca(unsigned long size)
80782 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
80783 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
80784 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
80785 +}
80786 +
80787 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
80788 +{
80789 + gimple track_stack;
80790 + tree fntype, fndecl;
80791 +
80792 + fntype = build_function_type_list(void_type_node, NULL_TREE);
80793 + fndecl = build_fn_decl(track_function, fntype);
80794 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
80795 +
80796 + // insert call to void pax_track_stack(void)
80797 + track_stack = gimple_build_call(fndecl, 0);
80798 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
80799 +}
80800 +
80801 +#if BUILDING_GCC_VERSION == 4005
80802 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
80803 +{
80804 + tree fndecl;
80805 +
80806 + if (!is_gimple_call(stmt))
80807 + return false;
80808 + fndecl = gimple_call_fndecl(stmt);
80809 + if (!fndecl)
80810 + return false;
80811 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
80812 + return false;
80813 +// print_node(stderr, "pax", fndecl, 4);
80814 + return DECL_FUNCTION_CODE(fndecl) == code;
80815 +}
80816 +#endif
80817 +
80818 +static bool is_alloca(gimple stmt)
80819 +{
80820 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
80821 + return true;
80822 +
80823 +#if BUILDING_GCC_VERSION >= 4007
80824 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
80825 + return true;
80826 +#endif
80827 +
80828 + return false;
80829 +}
80830 +
80831 +static unsigned int execute_stackleak_tree_instrument(void)
80832 +{
80833 + basic_block bb, entry_bb;
80834 + bool prologue_instrumented = false, is_leaf = true;
80835 +
80836 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
80837 +
80838 + // 1. loop through BBs and GIMPLE statements
80839 + FOR_EACH_BB(bb) {
80840 + gimple_stmt_iterator gsi;
80841 +
80842 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80843 + gimple stmt;
80844 +
80845 + stmt = gsi_stmt(gsi);
80846 +
80847 + if (is_gimple_call(stmt))
80848 + is_leaf = false;
80849 +
80850 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
80851 + if (!is_alloca(stmt))
80852 + continue;
80853 +
80854 + // 2. insert stack overflow check before each __builtin_alloca call
80855 + stackleak_check_alloca(&gsi);
80856 +
80857 + // 3. insert track call after each __builtin_alloca call
80858 + stackleak_add_instrumentation(&gsi);
80859 + if (bb == entry_bb)
80860 + prologue_instrumented = true;
80861 + }
80862 + }
80863 +
80864 + // special case for some bad linux code: taking the address of static inline functions will materialize them
80865 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
80866 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
80867 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
80868 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
80869 + return 0;
80870 +
80871 + // 4. insert track call at the beginning
80872 + if (!prologue_instrumented) {
80873 + gimple_stmt_iterator gsi;
80874 +
80875 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
80876 + if (dom_info_available_p(CDI_DOMINATORS))
80877 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
80878 + gsi = gsi_start_bb(bb);
80879 + stackleak_add_instrumentation(&gsi);
80880 + }
80881 +
80882 + return 0;
80883 +}
80884 +
80885 +static unsigned int execute_stackleak_final(void)
80886 +{
80887 + rtx insn;
80888 +
80889 + if (cfun->calls_alloca)
80890 + return 0;
80891 +
80892 + // keep calls only if function frame is big enough
80893 + if (get_frame_size() >= track_frame_size)
80894 + return 0;
80895 +
80896 + // 1. find pax_track_stack calls
80897 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
80898 + // 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))
80899 + rtx body;
80900 +
80901 + if (!CALL_P(insn))
80902 + continue;
80903 + body = PATTERN(insn);
80904 + if (GET_CODE(body) != CALL)
80905 + continue;
80906 + body = XEXP(body, 0);
80907 + if (GET_CODE(body) != MEM)
80908 + continue;
80909 + body = XEXP(body, 0);
80910 + if (GET_CODE(body) != SYMBOL_REF)
80911 + continue;
80912 + if (strcmp(XSTR(body, 0), track_function))
80913 + continue;
80914 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
80915 + // 2. delete call
80916 + insn = delete_insn_and_edges(insn);
80917 +#if BUILDING_GCC_VERSION >= 4007
80918 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
80919 + insn = delete_insn_and_edges(insn);
80920 +#endif
80921 + }
80922 +
80923 +// print_simple_rtl(stderr, get_insns());
80924 +// print_rtl(stderr, get_insns());
80925 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
80926 +
80927 + return 0;
80928 +}
80929 +
80930 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80931 +{
80932 + const char * const plugin_name = plugin_info->base_name;
80933 + const int argc = plugin_info->argc;
80934 + const struct plugin_argument * const argv = plugin_info->argv;
80935 + int i;
80936 + struct register_pass_info stackleak_tree_instrument_pass_info = {
80937 + .pass = &stackleak_tree_instrument_pass.pass,
80938 +// .reference_pass_name = "tree_profile",
80939 + .reference_pass_name = "optimized",
80940 + .ref_pass_instance_number = 0,
80941 + .pos_op = PASS_POS_INSERT_BEFORE
80942 + };
80943 + struct register_pass_info stackleak_final_pass_info = {
80944 + .pass = &stackleak_final_rtl_opt_pass.pass,
80945 + .reference_pass_name = "final",
80946 + .ref_pass_instance_number = 0,
80947 + .pos_op = PASS_POS_INSERT_BEFORE
80948 + };
80949 +
80950 + if (!plugin_default_version_check(version, &gcc_version)) {
80951 + error(G_("incompatible gcc/plugin versions"));
80952 + return 1;
80953 + }
80954 +
80955 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
80956 +
80957 + for (i = 0; i < argc; ++i) {
80958 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
80959 + if (!argv[i].value) {
80960 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80961 + continue;
80962 + }
80963 + track_frame_size = atoi(argv[i].value);
80964 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
80965 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80966 + continue;
80967 + }
80968 + if (!strcmp(argv[i].key, "initialize-locals")) {
80969 + if (argv[i].value) {
80970 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80971 + continue;
80972 + }
80973 + init_locals = true;
80974 + continue;
80975 + }
80976 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80977 + }
80978 +
80979 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
80980 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
80981 +
80982 + return 0;
80983 +}
80984 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
80985 index 6789d78..4afd019 100644
80986 --- a/tools/perf/util/include/asm/alternative-asm.h
80987 +++ b/tools/perf/util/include/asm/alternative-asm.h
80988 @@ -5,4 +5,7 @@
80989
80990 #define altinstruction_entry #
80991
80992 + .macro pax_force_retaddr rip=0, reload=0
80993 + .endm
80994 +
80995 #endif
80996 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
80997 index af0f22f..9a7d479 100644
80998 --- a/usr/gen_init_cpio.c
80999 +++ b/usr/gen_init_cpio.c
81000 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
81001 int retval;
81002 int rc = -1;
81003 int namesize;
81004 - int i;
81005 + unsigned int i;
81006
81007 mode |= S_IFREG;
81008
81009 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
81010 *env_var = *expanded = '\0';
81011 strncat(env_var, start + 2, end - start - 2);
81012 strncat(expanded, new_location, start - new_location);
81013 - strncat(expanded, getenv(env_var), PATH_MAX);
81014 - strncat(expanded, end + 1, PATH_MAX);
81015 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
81016 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
81017 strncpy(new_location, expanded, PATH_MAX);
81018 + new_location[PATH_MAX] = 0;
81019 } else
81020 break;
81021 }
81022 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
81023 index d9cfb78..4f27c10 100644
81024 --- a/virt/kvm/kvm_main.c
81025 +++ b/virt/kvm/kvm_main.c
81026 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
81027
81028 static cpumask_var_t cpus_hardware_enabled;
81029 static int kvm_usage_count = 0;
81030 -static atomic_t hardware_enable_failed;
81031 +static atomic_unchecked_t hardware_enable_failed;
81032
81033 struct kmem_cache *kvm_vcpu_cache;
81034 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
81035 @@ -2268,7 +2268,7 @@ static void hardware_enable_nolock(void *junk)
81036
81037 if (r) {
81038 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
81039 - atomic_inc(&hardware_enable_failed);
81040 + atomic_inc_unchecked(&hardware_enable_failed);
81041 printk(KERN_INFO "kvm: enabling virtualization on "
81042 "CPU%d failed\n", cpu);
81043 }
81044 @@ -2322,10 +2322,10 @@ static int hardware_enable_all(void)
81045
81046 kvm_usage_count++;
81047 if (kvm_usage_count == 1) {
81048 - atomic_set(&hardware_enable_failed, 0);
81049 + atomic_set_unchecked(&hardware_enable_failed, 0);
81050 on_each_cpu(hardware_enable_nolock, NULL, 1);
81051
81052 - if (atomic_read(&hardware_enable_failed)) {
81053 + if (atomic_read_unchecked(&hardware_enable_failed)) {
81054 hardware_disable_all_nolock();
81055 r = -EBUSY;
81056 }
81057 @@ -2676,7 +2676,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
81058 kvm_arch_vcpu_put(vcpu);
81059 }
81060
81061 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81062 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81063 struct module *module)
81064 {
81065 int r;
81066 @@ -2739,7 +2739,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81067 if (!vcpu_align)
81068 vcpu_align = __alignof__(struct kvm_vcpu);
81069 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
81070 - 0, NULL);
81071 + SLAB_USERCOPY, NULL);
81072 if (!kvm_vcpu_cache) {
81073 r = -ENOMEM;
81074 goto out_free_3;
81075 @@ -2749,9 +2749,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
81076 if (r)
81077 goto out_free;
81078
81079 - kvm_chardev_ops.owner = module;
81080 - kvm_vm_fops.owner = module;
81081 - kvm_vcpu_fops.owner = module;
81082 + pax_open_kernel();
81083 + *(void **)&kvm_chardev_ops.owner = module;
81084 + *(void **)&kvm_vm_fops.owner = module;
81085 + *(void **)&kvm_vcpu_fops.owner = module;
81086 + pax_close_kernel();
81087
81088 r = misc_register(&kvm_dev);
81089 if (r) {