]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.3-201204222117.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.3-201204222117.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 0c083c5..bf13011 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,9 +51,11 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 @@ -69,6 +74,7 @@ Image
38 Module.markers
39 Module.symvers
40 PENDING
41 +PERF*
42 SCCS
43 System.map*
44 TAGS
45 @@ -92,19 +98,24 @@ bounds.h
46 bsetup
47 btfixupprep
48 build
49 +builtin-policy.h
50 bvmlinux
51 bzImage*
52 capability_names.h
53 capflags.c
54 classlist.h*
55 +clut_vga16.c
56 +common-cmds.h
57 comp*.log
58 compile.h*
59 conf
60 config
61 config-*
62 config_data.h*
63 +config.c
64 config.mak
65 config.mak.autogen
66 +config.tmp
67 conmakehash
68 consolemap_deftbl.c*
69 cpustr.h
70 @@ -115,9 +126,11 @@ devlist.h*
71 dnotify_test
72 docproc
73 dslm
74 +dtc-lexer.lex.c
75 elf2ecoff
76 elfconfig.h*
77 evergreen_reg_safe.h
78 +exception_policy.conf
79 fixdep
80 flask.h
81 fore200e_mkfirm
82 @@ -125,12 +138,15 @@ fore200e_pca_fw.c*
83 gconf
84 gconf.glade.h
85 gen-devlist
86 +gen-kdb_cmds.c
87 gen_crc32table
88 gen_init_cpio
89 generated
90 genheaders
91 genksyms
92 *_gray256.c
93 +hash
94 +hid-example
95 hpet_example
96 hugepage-mmap
97 hugepage-shm
98 @@ -145,7 +161,7 @@ int32.c
99 int4.c
100 int8.c
101 kallsyms
102 -kconfig
103 +kern_constants.h
104 keywords.c
105 ksym.c*
106 ksym.h*
107 @@ -153,7 +169,7 @@ kxgettext
108 lkc_defs.h
109 lex.c
110 lex.*.c
111 -linux
112 +lib1funcs.S
113 logo_*.c
114 logo_*_clut224.c
115 logo_*_mono.c
116 @@ -165,14 +181,15 @@ machtypes.h
117 map
118 map_hugetlb
119 maui_boot.h
120 -media
121 mconf
122 +mdp
123 miboot*
124 mk_elfconfig
125 mkboot
126 mkbugboot
127 mkcpustr
128 mkdep
129 +mkpiggy
130 mkprep
131 mkregtable
132 mktables
133 @@ -208,6 +225,7 @@ r300_reg_safe.h
134 r420_reg_safe.h
135 r600_reg_safe.h
136 recordmcount
137 +regdb.c
138 relocs
139 rlim_names.h
140 rn50_reg_safe.h
141 @@ -218,6 +236,7 @@ setup
142 setup.bin
143 setup.elf
144 sImage
145 +slabinfo
146 sm_tbl*
147 split-include
148 syscalltab.h
149 @@ -228,6 +247,7 @@ tftpboot.img
150 timeconst.h
151 times.h*
152 trix_boot.h
153 +user_constants.h
154 utsrelease.h*
155 vdso-syms.lds
156 vdso.lds
157 @@ -245,7 +265,9 @@ vmlinux
158 vmlinux-*
159 vmlinux.aout
160 vmlinux.bin.all
161 +vmlinux.bin.bz2
162 vmlinux.lds
163 +vmlinux.relocs
164 vmlinuz
165 voffset.h
166 vsyscall.lds
167 @@ -253,9 +275,11 @@ vsyscall_32.lds
168 wanxlfw.inc
169 uImage
170 unifdef
171 +utsrelease.h
172 wakeup.bin
173 wakeup.elf
174 wakeup.lds
175 zImage*
176 zconf.hash.c
177 +zconf.lex.c
178 zoffset.h
179 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
180 index d99fd9c..8689fef 100644
181 --- a/Documentation/kernel-parameters.txt
182 +++ b/Documentation/kernel-parameters.txt
183 @@ -1977,6 +1977,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
184 the specified number of seconds. This is to be used if
185 your oopses keep scrolling off the screen.
186
187 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
188 + virtualization environments that don't cope well with the
189 + expand down segment used by UDEREF on X86-32 or the frequent
190 + page table updates on X86-64.
191 +
192 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
193 +
194 pcbit= [HW,ISDN]
195
196 pcd. [PARIDE]
197 diff --git a/Makefile b/Makefile
198 index 0acd141..2026d3e 100644
199 --- a/Makefile
200 +++ b/Makefile
201 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
202
203 HOSTCC = gcc
204 HOSTCXX = g++
205 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
206 -HOSTCXXFLAGS = -O2
207 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
208 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
209 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
210
211 # Decide whether to build built-in, modular, or both.
212 # Normally, just do built-in.
213 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
214 # Rules shared between *config targets and build targets
215
216 # Basic helpers built in scripts/
217 -PHONY += scripts_basic
218 -scripts_basic:
219 +PHONY += scripts_basic gcc-plugins
220 +scripts_basic: gcc-plugins
221 $(Q)$(MAKE) $(build)=scripts/basic
222 $(Q)rm -f .tmp_quiet_recordmcount
223
224 @@ -564,6 +565,53 @@ else
225 KBUILD_CFLAGS += -O2
226 endif
227
228 +ifndef DISABLE_PAX_PLUGINS
229 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
230 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
231 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
232 +endif
233 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
234 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
235 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
236 +endif
237 +ifdef CONFIG_KALLOCSTAT_PLUGIN
238 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
239 +endif
240 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
241 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
242 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
243 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
244 +endif
245 +ifdef CONFIG_CHECKER_PLUGIN
246 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
247 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
248 +endif
249 +endif
250 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
251 +ifdef CONFIG_PAX_SIZE_OVERFLOW
252 +SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
253 +endif
254 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
255 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
256 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
257 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
258 +ifeq ($(KBUILD_EXTMOD),)
259 +gcc-plugins:
260 + $(Q)$(MAKE) $(build)=tools/gcc
261 +else
262 +gcc-plugins: ;
263 +endif
264 +else
265 +gcc-plugins:
266 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
267 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
268 +else
269 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
270 +endif
271 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
272 +endif
273 +endif
274 +
275 include $(srctree)/arch/$(SRCARCH)/Makefile
276
277 ifneq ($(CONFIG_FRAME_WARN),0)
278 @@ -708,7 +756,7 @@ export mod_strip_cmd
279
280
281 ifeq ($(KBUILD_EXTMOD),)
282 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
283 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
284
285 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
286 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
287 @@ -932,6 +980,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
288
289 # The actual objects are generated when descending,
290 # make sure no implicit rule kicks in
291 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
292 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
293 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
294
295 # Handle descending into subdirectories listed in $(vmlinux-dirs)
296 @@ -941,7 +991,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
297 # Error messages still appears in the original language
298
299 PHONY += $(vmlinux-dirs)
300 -$(vmlinux-dirs): prepare scripts
301 +$(vmlinux-dirs): gcc-plugins prepare scripts
302 $(Q)$(MAKE) $(build)=$@
303
304 # Store (new) KERNELRELASE string in include/config/kernel.release
305 @@ -985,6 +1035,7 @@ prepare0: archprepare FORCE
306 $(Q)$(MAKE) $(build)=.
307
308 # All the preparing..
309 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
310 prepare: prepare0
311
312 # Generate some files
313 @@ -1089,6 +1140,8 @@ all: modules
314 # using awk while concatenating to the final file.
315
316 PHONY += modules
317 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
318 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
319 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
320 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
321 @$(kecho) ' Building modules, stage 2.';
322 @@ -1104,7 +1157,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
323
324 # Target to prepare building external modules
325 PHONY += modules_prepare
326 -modules_prepare: prepare scripts
327 +modules_prepare: gcc-plugins prepare scripts
328
329 # Target to install modules
330 PHONY += modules_install
331 @@ -1201,6 +1254,7 @@ distclean: mrproper
332 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
333 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
334 -o -name '.*.rej' \
335 + -o -name '.*.rej' -o -name '*.so' \
336 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
337 -type f -print | xargs rm -f
338
339 @@ -1361,6 +1415,8 @@ PHONY += $(module-dirs) modules
340 $(module-dirs): crmodverdir $(objtree)/Module.symvers
341 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
342
343 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
344 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
345 modules: $(module-dirs)
346 @$(kecho) ' Building modules, stage 2.';
347 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
348 @@ -1487,17 +1543,21 @@ else
349 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
350 endif
351
352 -%.s: %.c prepare scripts FORCE
353 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
354 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
355 +%.s: %.c gcc-plugins prepare scripts FORCE
356 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
357 %.i: %.c prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 -%.o: %.c prepare scripts FORCE
360 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
361 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
362 +%.o: %.c gcc-plugins prepare scripts FORCE
363 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
364 %.lst: %.c prepare scripts FORCE
365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
366 -%.s: %.S prepare scripts FORCE
367 +%.s: %.S gcc-plugins prepare scripts FORCE
368 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
369 -%.o: %.S prepare scripts FORCE
370 +%.o: %.S gcc-plugins prepare scripts FORCE
371 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
372 %.symtypes: %.c prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 @@ -1507,11 +1567,15 @@ endif
375 $(cmd_crmodverdir)
376 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
377 $(build)=$(build-dir)
378 -%/: prepare scripts FORCE
379 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
380 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
381 +%/: gcc-plugins prepare scripts FORCE
382 $(cmd_crmodverdir)
383 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
384 $(build)=$(build-dir)
385 -%.ko: prepare scripts FORCE
386 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
387 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
388 +%.ko: gcc-plugins prepare scripts FORCE
389 $(cmd_crmodverdir)
390 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
391 $(build)=$(build-dir) $(@:.ko=.o)
392 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
393 index 640f909..48b6597 100644
394 --- a/arch/alpha/include/asm/atomic.h
395 +++ b/arch/alpha/include/asm/atomic.h
396 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
397 #define atomic_dec(v) atomic_sub(1,(v))
398 #define atomic64_dec(v) atomic64_sub(1,(v))
399
400 +#define atomic64_read_unchecked(v) atomic64_read(v)
401 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
402 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
403 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
404 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
405 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
406 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
407 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
408 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
409 +
410 #define smp_mb__before_atomic_dec() smp_mb()
411 #define smp_mb__after_atomic_dec() smp_mb()
412 #define smp_mb__before_atomic_inc() smp_mb()
413 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
414 index ad368a9..fbe0f25 100644
415 --- a/arch/alpha/include/asm/cache.h
416 +++ b/arch/alpha/include/asm/cache.h
417 @@ -4,19 +4,19 @@
418 #ifndef __ARCH_ALPHA_CACHE_H
419 #define __ARCH_ALPHA_CACHE_H
420
421 +#include <linux/const.h>
422
423 /* Bytes per L1 (data) cache line. */
424 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
425 -# define L1_CACHE_BYTES 64
426 # define L1_CACHE_SHIFT 6
427 #else
428 /* Both EV4 and EV5 are write-through, read-allocate,
429 direct-mapped, physical.
430 */
431 -# define L1_CACHE_BYTES 32
432 # define L1_CACHE_SHIFT 5
433 #endif
434
435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
436 #define SMP_CACHE_BYTES L1_CACHE_BYTES
437
438 #endif
439 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
440 index da5449e..7418343 100644
441 --- a/arch/alpha/include/asm/elf.h
442 +++ b/arch/alpha/include/asm/elf.h
443 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
444
445 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
446
447 +#ifdef CONFIG_PAX_ASLR
448 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
449 +
450 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
451 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
452 +#endif
453 +
454 /* $0 is set by ld.so to a pointer to a function which might be
455 registered using atexit. This provides a mean for the dynamic
456 linker to call DT_FINI functions for shared libraries that have
457 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
458 index de98a73..bd4f1f8 100644
459 --- a/arch/alpha/include/asm/pgtable.h
460 +++ b/arch/alpha/include/asm/pgtable.h
461 @@ -101,6 +101,17 @@ struct vm_area_struct;
462 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
463 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
464 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
465 +
466 +#ifdef CONFIG_PAX_PAGEEXEC
467 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
468 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
469 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
470 +#else
471 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
472 +# define PAGE_COPY_NOEXEC PAGE_COPY
473 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
474 +#endif
475 +
476 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
477
478 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
479 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
480 index 2fd00b7..cfd5069 100644
481 --- a/arch/alpha/kernel/module.c
482 +++ b/arch/alpha/kernel/module.c
483 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
484
485 /* The small sections were sorted to the end of the segment.
486 The following should definitely cover them. */
487 - gp = (u64)me->module_core + me->core_size - 0x8000;
488 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
489 got = sechdrs[me->arch.gotsecindex].sh_addr;
490
491 for (i = 0; i < n; i++) {
492 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
493 index 01e8715..be0e80f 100644
494 --- a/arch/alpha/kernel/osf_sys.c
495 +++ b/arch/alpha/kernel/osf_sys.c
496 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
497 /* At this point: (!vma || addr < vma->vm_end). */
498 if (limit - len < addr)
499 return -ENOMEM;
500 - if (!vma || addr + len <= vma->vm_start)
501 + if (check_heap_stack_gap(vma, addr, len))
502 return addr;
503 addr = vma->vm_end;
504 vma = vma->vm_next;
505 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
506 merely specific addresses, but regions of memory -- perhaps
507 this feature should be incorporated into all ports? */
508
509 +#ifdef CONFIG_PAX_RANDMMAP
510 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
511 +#endif
512 +
513 if (addr) {
514 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
515 if (addr != (unsigned long) -ENOMEM)
516 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
517 }
518
519 /* Next, try allocating at TASK_UNMAPPED_BASE. */
520 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
521 - len, limit);
522 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
523 +
524 if (addr != (unsigned long) -ENOMEM)
525 return addr;
526
527 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
528 index fadd5f8..904e73a 100644
529 --- a/arch/alpha/mm/fault.c
530 +++ b/arch/alpha/mm/fault.c
531 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
532 __reload_thread(pcb);
533 }
534
535 +#ifdef CONFIG_PAX_PAGEEXEC
536 +/*
537 + * PaX: decide what to do with offenders (regs->pc = fault address)
538 + *
539 + * returns 1 when task should be killed
540 + * 2 when patched PLT trampoline was detected
541 + * 3 when unpatched PLT trampoline was detected
542 + */
543 +static int pax_handle_fetch_fault(struct pt_regs *regs)
544 +{
545 +
546 +#ifdef CONFIG_PAX_EMUPLT
547 + int err;
548 +
549 + do { /* PaX: patched PLT emulation #1 */
550 + unsigned int ldah, ldq, jmp;
551 +
552 + err = get_user(ldah, (unsigned int *)regs->pc);
553 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
554 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
555 +
556 + if (err)
557 + break;
558 +
559 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
560 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
561 + jmp == 0x6BFB0000U)
562 + {
563 + unsigned long r27, addr;
564 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
565 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
566 +
567 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
568 + err = get_user(r27, (unsigned long *)addr);
569 + if (err)
570 + break;
571 +
572 + regs->r27 = r27;
573 + regs->pc = r27;
574 + return 2;
575 + }
576 + } while (0);
577 +
578 + do { /* PaX: patched PLT emulation #2 */
579 + unsigned int ldah, lda, br;
580 +
581 + err = get_user(ldah, (unsigned int *)regs->pc);
582 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
583 + err |= get_user(br, (unsigned int *)(regs->pc+8));
584 +
585 + if (err)
586 + break;
587 +
588 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
589 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
590 + (br & 0xFFE00000U) == 0xC3E00000U)
591 + {
592 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
593 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
594 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
595 +
596 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
597 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
598 + return 2;
599 + }
600 + } while (0);
601 +
602 + do { /* PaX: unpatched PLT emulation */
603 + unsigned int br;
604 +
605 + err = get_user(br, (unsigned int *)regs->pc);
606 +
607 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
608 + unsigned int br2, ldq, nop, jmp;
609 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
610 +
611 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
612 + err = get_user(br2, (unsigned int *)addr);
613 + err |= get_user(ldq, (unsigned int *)(addr+4));
614 + err |= get_user(nop, (unsigned int *)(addr+8));
615 + err |= get_user(jmp, (unsigned int *)(addr+12));
616 + err |= get_user(resolver, (unsigned long *)(addr+16));
617 +
618 + if (err)
619 + break;
620 +
621 + if (br2 == 0xC3600000U &&
622 + ldq == 0xA77B000CU &&
623 + nop == 0x47FF041FU &&
624 + jmp == 0x6B7B0000U)
625 + {
626 + regs->r28 = regs->pc+4;
627 + regs->r27 = addr+16;
628 + regs->pc = resolver;
629 + return 3;
630 + }
631 + }
632 + } while (0);
633 +#endif
634 +
635 + return 1;
636 +}
637 +
638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
639 +{
640 + unsigned long i;
641 +
642 + printk(KERN_ERR "PAX: bytes at PC: ");
643 + for (i = 0; i < 5; i++) {
644 + unsigned int c;
645 + if (get_user(c, (unsigned int *)pc+i))
646 + printk(KERN_CONT "???????? ");
647 + else
648 + printk(KERN_CONT "%08x ", c);
649 + }
650 + printk("\n");
651 +}
652 +#endif
653
654 /*
655 * This routine handles page faults. It determines the address,
656 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
657 good_area:
658 si_code = SEGV_ACCERR;
659 if (cause < 0) {
660 - if (!(vma->vm_flags & VM_EXEC))
661 + if (!(vma->vm_flags & VM_EXEC)) {
662 +
663 +#ifdef CONFIG_PAX_PAGEEXEC
664 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
665 + goto bad_area;
666 +
667 + up_read(&mm->mmap_sem);
668 + switch (pax_handle_fetch_fault(regs)) {
669 +
670 +#ifdef CONFIG_PAX_EMUPLT
671 + case 2:
672 + case 3:
673 + return;
674 +#endif
675 +
676 + }
677 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
678 + do_group_exit(SIGKILL);
679 +#else
680 goto bad_area;
681 +#endif
682 +
683 + }
684 } else if (!cause) {
685 /* Allow reads even for write-only mappings */
686 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
687 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
688 index 86976d0..8e07f84 100644
689 --- a/arch/arm/include/asm/atomic.h
690 +++ b/arch/arm/include/asm/atomic.h
691 @@ -15,6 +15,10 @@
692 #include <linux/types.h>
693 #include <asm/system.h>
694
695 +#ifdef CONFIG_GENERIC_ATOMIC64
696 +#include <asm-generic/atomic64.h>
697 +#endif
698 +
699 #define ATOMIC_INIT(i) { (i) }
700
701 #ifdef __KERNEL__
702 @@ -25,7 +29,15 @@
703 * atomic_set() is the clrex or dummy strex done on every exception return.
704 */
705 #define atomic_read(v) (*(volatile int *)&(v)->counter)
706 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
707 +{
708 + return v->counter;
709 +}
710 #define atomic_set(v,i) (((v)->counter) = (i))
711 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
712 +{
713 + v->counter = i;
714 +}
715
716 #if __LINUX_ARM_ARCH__ >= 6
717
718 @@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
719 int result;
720
721 __asm__ __volatile__("@ atomic_add\n"
722 +"1: ldrex %1, [%3]\n"
723 +" adds %0, %1, %4\n"
724 +
725 +#ifdef CONFIG_PAX_REFCOUNT
726 +" bvc 3f\n"
727 +"2: bkpt 0xf103\n"
728 +"3:\n"
729 +#endif
730 +
731 +" strex %1, %0, [%3]\n"
732 +" teq %1, #0\n"
733 +" bne 1b"
734 +
735 +#ifdef CONFIG_PAX_REFCOUNT
736 +"\n4:\n"
737 + _ASM_EXTABLE(2b, 4b)
738 +#endif
739 +
740 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
741 + : "r" (&v->counter), "Ir" (i)
742 + : "cc");
743 +}
744 +
745 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
746 +{
747 + unsigned long tmp;
748 + int result;
749 +
750 + __asm__ __volatile__("@ atomic_add_unchecked\n"
751 "1: ldrex %0, [%3]\n"
752 " add %0, %0, %4\n"
753 " strex %1, %0, [%3]\n"
754 @@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
755 smp_mb();
756
757 __asm__ __volatile__("@ atomic_add_return\n"
758 +"1: ldrex %1, [%3]\n"
759 +" adds %0, %1, %4\n"
760 +
761 +#ifdef CONFIG_PAX_REFCOUNT
762 +" bvc 3f\n"
763 +" mov %0, %1\n"
764 +"2: bkpt 0xf103\n"
765 +"3:\n"
766 +#endif
767 +
768 +" strex %1, %0, [%3]\n"
769 +" teq %1, #0\n"
770 +" bne 1b"
771 +
772 +#ifdef CONFIG_PAX_REFCOUNT
773 +"\n4:\n"
774 + _ASM_EXTABLE(2b, 4b)
775 +#endif
776 +
777 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
778 + : "r" (&v->counter), "Ir" (i)
779 + : "cc");
780 +
781 + smp_mb();
782 +
783 + return result;
784 +}
785 +
786 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
787 +{
788 + unsigned long tmp;
789 + int result;
790 +
791 + smp_mb();
792 +
793 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
794 "1: ldrex %0, [%3]\n"
795 " add %0, %0, %4\n"
796 " strex %1, %0, [%3]\n"
797 @@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
798 int result;
799
800 __asm__ __volatile__("@ atomic_sub\n"
801 +"1: ldrex %1, [%3]\n"
802 +" subs %0, %1, %4\n"
803 +
804 +#ifdef CONFIG_PAX_REFCOUNT
805 +" bvc 3f\n"
806 +"2: bkpt 0xf103\n"
807 +"3:\n"
808 +#endif
809 +
810 +" strex %1, %0, [%3]\n"
811 +" teq %1, #0\n"
812 +" bne 1b"
813 +
814 +#ifdef CONFIG_PAX_REFCOUNT
815 +"\n4:\n"
816 + _ASM_EXTABLE(2b, 4b)
817 +#endif
818 +
819 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
820 + : "r" (&v->counter), "Ir" (i)
821 + : "cc");
822 +}
823 +
824 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
825 +{
826 + unsigned long tmp;
827 + int result;
828 +
829 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
830 "1: ldrex %0, [%3]\n"
831 " sub %0, %0, %4\n"
832 " strex %1, %0, [%3]\n"
833 @@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
834 smp_mb();
835
836 __asm__ __volatile__("@ atomic_sub_return\n"
837 -"1: ldrex %0, [%3]\n"
838 -" sub %0, %0, %4\n"
839 +"1: ldrex %1, [%3]\n"
840 +" sub %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +" mov %0, %1\n"
845 +"2: bkpt 0xf103\n"
846 +"3:\n"
847 +#endif
848 +
849 " strex %1, %0, [%3]\n"
850 " teq %1, #0\n"
851 " bne 1b"
852 +
853 +#ifdef CONFIG_PAX_REFCOUNT
854 +"\n4:\n"
855 + _ASM_EXTABLE(2b, 4b)
856 +#endif
857 +
858 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
859 : "r" (&v->counter), "Ir" (i)
860 : "cc");
861 @@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
862 return oldval;
863 }
864
865 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
866 +{
867 + unsigned long oldval, res;
868 +
869 + smp_mb();
870 +
871 + do {
872 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
873 + "ldrex %1, [%3]\n"
874 + "mov %0, #0\n"
875 + "teq %1, %4\n"
876 + "strexeq %0, %5, [%3]\n"
877 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
878 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
879 + : "cc");
880 + } while (res);
881 +
882 + smp_mb();
883 +
884 + return oldval;
885 +}
886 +
887 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
888 {
889 unsigned long tmp, tmp2;
890 @@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
891
892 return val;
893 }
894 +#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
895 #define atomic_add(i, v) (void) atomic_add_return(i, v)
896 +#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
897
898 static inline int atomic_sub_return(int i, atomic_t *v)
899 {
900 @@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
901
902 return val;
903 }
904 +#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
905 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
906 +#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
907
908 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
909 {
910 @@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
911
912 return ret;
913 }
914 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
915
916 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
917 {
918 @@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
919 #endif /* __LINUX_ARM_ARCH__ */
920
921 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
922 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
923 +{
924 + return xchg(&v->counter, new);
925 +}
926
927 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
928 {
929 @@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
930 }
931
932 #define atomic_inc(v) atomic_add(1, v)
933 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
934 +{
935 + atomic_add_unchecked(1, v);
936 +}
937 #define atomic_dec(v) atomic_sub(1, v)
938 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
939 +{
940 + atomic_sub_unchecked(1, v);
941 +}
942
943 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
944 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
945 +{
946 + return atomic_add_return_unchecked(1, v) == 0;
947 +}
948 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
949 #define atomic_inc_return(v) (atomic_add_return(1, v))
950 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
951 +{
952 + return atomic_add_return_unchecked(1, v);
953 +}
954 #define atomic_dec_return(v) (atomic_sub_return(1, v))
955 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
956
957 @@ -239,6 +406,14 @@ typedef struct {
958 u64 __aligned(8) counter;
959 } atomic64_t;
960
961 +#ifdef CONFIG_PAX_REFCOUNT
962 +typedef struct {
963 + u64 __aligned(8) counter;
964 +} atomic64_unchecked_t;
965 +#else
966 +typedef atomic64_t atomic64_unchecked_t;
967 +#endif
968 +
969 #define ATOMIC64_INIT(i) { (i) }
970
971 static inline u64 atomic64_read(atomic64_t *v)
972 @@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
973 return result;
974 }
975
976 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
977 +{
978 + u64 result;
979 +
980 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
981 +" ldrexd %0, %H0, [%1]"
982 + : "=&r" (result)
983 + : "r" (&v->counter), "Qo" (v->counter)
984 + );
985 +
986 + return result;
987 +}
988 +
989 static inline void atomic64_set(atomic64_t *v, u64 i)
990 {
991 u64 tmp;
992 @@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
993 : "cc");
994 }
995
996 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
997 +{
998 + u64 tmp;
999 +
1000 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1001 +"1: ldrexd %0, %H0, [%2]\n"
1002 +" strexd %0, %3, %H3, [%2]\n"
1003 +" teq %0, #0\n"
1004 +" bne 1b"
1005 + : "=&r" (tmp), "=Qo" (v->counter)
1006 + : "r" (&v->counter), "r" (i)
1007 + : "cc");
1008 +}
1009 +
1010 static inline void atomic64_add(u64 i, atomic64_t *v)
1011 {
1012 u64 result;
1013 @@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1014 __asm__ __volatile__("@ atomic64_add\n"
1015 "1: ldrexd %0, %H0, [%3]\n"
1016 " adds %0, %0, %4\n"
1017 +" adcs %H0, %H0, %H4\n"
1018 +
1019 +#ifdef CONFIG_PAX_REFCOUNT
1020 +" bvc 3f\n"
1021 +"2: bkpt 0xf103\n"
1022 +"3:\n"
1023 +#endif
1024 +
1025 +" strexd %1, %0, %H0, [%3]\n"
1026 +" teq %1, #0\n"
1027 +" bne 1b"
1028 +
1029 +#ifdef CONFIG_PAX_REFCOUNT
1030 +"\n4:\n"
1031 + _ASM_EXTABLE(2b, 4b)
1032 +#endif
1033 +
1034 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1035 + : "r" (&v->counter), "r" (i)
1036 + : "cc");
1037 +}
1038 +
1039 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1040 +{
1041 + u64 result;
1042 + unsigned long tmp;
1043 +
1044 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1045 +"1: ldrexd %0, %H0, [%3]\n"
1046 +" adds %0, %0, %4\n"
1047 " adc %H0, %H0, %H4\n"
1048 " strexd %1, %0, %H0, [%3]\n"
1049 " teq %1, #0\n"
1050 @@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1051
1052 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1053 {
1054 - u64 result;
1055 - unsigned long tmp;
1056 + u64 result, tmp;
1057
1058 smp_mb();
1059
1060 __asm__ __volatile__("@ atomic64_add_return\n"
1061 +"1: ldrexd %1, %H1, [%3]\n"
1062 +" adds %0, %1, %4\n"
1063 +" adcs %H0, %H1, %H4\n"
1064 +
1065 +#ifdef CONFIG_PAX_REFCOUNT
1066 +" bvc 3f\n"
1067 +" mov %0, %1\n"
1068 +" mov %H0, %H1\n"
1069 +"2: bkpt 0xf103\n"
1070 +"3:\n"
1071 +#endif
1072 +
1073 +" strexd %1, %0, %H0, [%3]\n"
1074 +" teq %1, #0\n"
1075 +" bne 1b"
1076 +
1077 +#ifdef CONFIG_PAX_REFCOUNT
1078 +"\n4:\n"
1079 + _ASM_EXTABLE(2b, 4b)
1080 +#endif
1081 +
1082 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1083 + : "r" (&v->counter), "r" (i)
1084 + : "cc");
1085 +
1086 + smp_mb();
1087 +
1088 + return result;
1089 +}
1090 +
1091 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1092 +{
1093 + u64 result;
1094 + unsigned long tmp;
1095 +
1096 + smp_mb();
1097 +
1098 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1099 "1: ldrexd %0, %H0, [%3]\n"
1100 " adds %0, %0, %4\n"
1101 " adc %H0, %H0, %H4\n"
1102 @@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1103 __asm__ __volatile__("@ atomic64_sub\n"
1104 "1: ldrexd %0, %H0, [%3]\n"
1105 " subs %0, %0, %4\n"
1106 +" sbcs %H0, %H0, %H4\n"
1107 +
1108 +#ifdef CONFIG_PAX_REFCOUNT
1109 +" bvc 3f\n"
1110 +"2: bkpt 0xf103\n"
1111 +"3:\n"
1112 +#endif
1113 +
1114 +" strexd %1, %0, %H0, [%3]\n"
1115 +" teq %1, #0\n"
1116 +" bne 1b"
1117 +
1118 +#ifdef CONFIG_PAX_REFCOUNT
1119 +"\n4:\n"
1120 + _ASM_EXTABLE(2b, 4b)
1121 +#endif
1122 +
1123 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1124 + : "r" (&v->counter), "r" (i)
1125 + : "cc");
1126 +}
1127 +
1128 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1129 +{
1130 + u64 result;
1131 + unsigned long tmp;
1132 +
1133 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1134 +"1: ldrexd %0, %H0, [%3]\n"
1135 +" subs %0, %0, %4\n"
1136 " sbc %H0, %H0, %H4\n"
1137 " strexd %1, %0, %H0, [%3]\n"
1138 " teq %1, #0\n"
1139 @@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1140
1141 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1142 {
1143 - u64 result;
1144 - unsigned long tmp;
1145 + u64 result, tmp;
1146
1147 smp_mb();
1148
1149 __asm__ __volatile__("@ atomic64_sub_return\n"
1150 -"1: ldrexd %0, %H0, [%3]\n"
1151 -" subs %0, %0, %4\n"
1152 -" sbc %H0, %H0, %H4\n"
1153 +"1: ldrexd %1, %H1, [%3]\n"
1154 +" subs %0, %1, %4\n"
1155 +" sbc %H0, %H1, %H4\n"
1156 +
1157 +#ifdef CONFIG_PAX_REFCOUNT
1158 +" bvc 3f\n"
1159 +" mov %0, %1\n"
1160 +" mov %H0, %H1\n"
1161 +"2: bkpt 0xf103\n"
1162 +"3:\n"
1163 +#endif
1164 +
1165 " strexd %1, %0, %H0, [%3]\n"
1166 " teq %1, #0\n"
1167 " bne 1b"
1168 +
1169 +#ifdef CONFIG_PAX_REFCOUNT
1170 +"\n4:\n"
1171 + _ASM_EXTABLE(2b, 4b)
1172 +#endif
1173 +
1174 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1175 : "r" (&v->counter), "r" (i)
1176 : "cc");
1177 @@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1178 return oldval;
1179 }
1180
1181 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1182 +{
1183 + u64 oldval;
1184 + unsigned long res;
1185 +
1186 + smp_mb();
1187 +
1188 + do {
1189 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1190 + "ldrexd %1, %H1, [%3]\n"
1191 + "mov %0, #0\n"
1192 + "teq %1, %4\n"
1193 + "teqeq %H1, %H4\n"
1194 + "strexdeq %0, %5, %H5, [%3]"
1195 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1196 + : "r" (&ptr->counter), "r" (old), "r" (new)
1197 + : "cc");
1198 + } while (res);
1199 +
1200 + smp_mb();
1201 +
1202 + return oldval;
1203 +}
1204 +
1205 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1206 {
1207 u64 result;
1208 @@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1209
1210 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1211 {
1212 - u64 result;
1213 - unsigned long tmp;
1214 + u64 result, tmp;
1215
1216 smp_mb();
1217
1218 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1219 -"1: ldrexd %0, %H0, [%3]\n"
1220 -" subs %0, %0, #1\n"
1221 -" sbc %H0, %H0, #0\n"
1222 +"1: ldrexd %1, %H1, [%3]\n"
1223 +" subs %0, %1, #1\n"
1224 +" sbc %H0, %H1, #0\n"
1225 +
1226 +#ifdef CONFIG_PAX_REFCOUNT
1227 +" bvc 3f\n"
1228 +" mov %0, %1\n"
1229 +" mov %H0, %H1\n"
1230 +"2: bkpt 0xf103\n"
1231 +"3:\n"
1232 +#endif
1233 +
1234 " teq %H0, #0\n"
1235 -" bmi 2f\n"
1236 +" bmi 4f\n"
1237 " strexd %1, %0, %H0, [%3]\n"
1238 " teq %1, #0\n"
1239 " bne 1b\n"
1240 -"2:"
1241 +"4:\n"
1242 +
1243 +#ifdef CONFIG_PAX_REFCOUNT
1244 + _ASM_EXTABLE(2b, 4b)
1245 +#endif
1246 +
1247 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1248 : "r" (&v->counter)
1249 : "cc");
1250 @@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1251 " teq %0, %5\n"
1252 " teqeq %H0, %H5\n"
1253 " moveq %1, #0\n"
1254 -" beq 2f\n"
1255 +" beq 4f\n"
1256 " adds %0, %0, %6\n"
1257 " adc %H0, %H0, %H6\n"
1258 +
1259 +#ifdef CONFIG_PAX_REFCOUNT
1260 +" bvc 3f\n"
1261 +"2: bkpt 0xf103\n"
1262 +"3:\n"
1263 +#endif
1264 +
1265 " strexd %2, %0, %H0, [%4]\n"
1266 " teq %2, #0\n"
1267 " bne 1b\n"
1268 -"2:"
1269 +"4:\n"
1270 +
1271 +#ifdef CONFIG_PAX_REFCOUNT
1272 + _ASM_EXTABLE(2b, 4b)
1273 +#endif
1274 +
1275 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1276 : "r" (&v->counter), "r" (u), "r" (a)
1277 : "cc");
1278 @@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1279
1280 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1281 #define atomic64_inc(v) atomic64_add(1LL, (v))
1282 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1283 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1284 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1285 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1286 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1287 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1288 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1289 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1290 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1291 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1292 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1293 index 75fe66b..2255c86 100644
1294 --- a/arch/arm/include/asm/cache.h
1295 +++ b/arch/arm/include/asm/cache.h
1296 @@ -4,8 +4,10 @@
1297 #ifndef __ASMARM_CACHE_H
1298 #define __ASMARM_CACHE_H
1299
1300 +#include <linux/const.h>
1301 +
1302 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1303 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1304 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1305
1306 /*
1307 * Memory returned by kmalloc() may be used for DMA, so we must make
1308 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1309 index d5d8d5c..ad92c96 100644
1310 --- a/arch/arm/include/asm/cacheflush.h
1311 +++ b/arch/arm/include/asm/cacheflush.h
1312 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1313 void (*dma_unmap_area)(const void *, size_t, int);
1314
1315 void (*dma_flush_range)(const void *, const void *);
1316 -};
1317 +} __no_const;
1318
1319 /*
1320 * Select the calling method
1321 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1322 index 0e9ce8d..6ef1e03 100644
1323 --- a/arch/arm/include/asm/elf.h
1324 +++ b/arch/arm/include/asm/elf.h
1325 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1326 the loader. We need to make sure that it is out of the way of the program
1327 that it will "exec", and that there is sufficient room for the brk. */
1328
1329 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1330 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1331 +
1332 +#ifdef CONFIG_PAX_ASLR
1333 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1334 +
1335 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1336 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1337 +#endif
1338
1339 /* When the program starts, a1 contains a pointer to a function to be
1340 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1341 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1342 extern void elf_set_personality(const struct elf32_hdr *);
1343 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1344
1345 -struct mm_struct;
1346 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1347 -#define arch_randomize_brk arch_randomize_brk
1348 -
1349 extern int vectors_user_mapping(void);
1350 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1351 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1352 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1353 index e51b1e8..32a3113 100644
1354 --- a/arch/arm/include/asm/kmap_types.h
1355 +++ b/arch/arm/include/asm/kmap_types.h
1356 @@ -21,6 +21,7 @@ enum km_type {
1357 KM_L1_CACHE,
1358 KM_L2_CACHE,
1359 KM_KDB,
1360 + KM_CLEARPAGE,
1361 KM_TYPE_NR
1362 };
1363
1364 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1365 index 53426c6..c7baff3 100644
1366 --- a/arch/arm/include/asm/outercache.h
1367 +++ b/arch/arm/include/asm/outercache.h
1368 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1369 #endif
1370 void (*set_debug)(unsigned long);
1371 void (*resume)(void);
1372 -};
1373 +} __no_const;
1374
1375 #ifdef CONFIG_OUTER_CACHE
1376
1377 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1378 index 97b440c..b7ff179 100644
1379 --- a/arch/arm/include/asm/page.h
1380 +++ b/arch/arm/include/asm/page.h
1381 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1382 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1383 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1384 unsigned long vaddr, struct vm_area_struct *vma);
1385 -};
1386 +} __no_const;
1387
1388 #ifdef MULTI_USER
1389 extern struct cpu_user_fns cpu_user;
1390 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1391 index e4c96cc..1145653 100644
1392 --- a/arch/arm/include/asm/system.h
1393 +++ b/arch/arm/include/asm/system.h
1394 @@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1395
1396 #define xchg(ptr,x) \
1397 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1398 +#define xchg_unchecked(ptr,x) \
1399 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1400
1401 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1402
1403 @@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1404
1405 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1406
1407 +#define _ASM_EXTABLE(from, to) \
1408 +" .pushsection __ex_table,\"a\"\n"\
1409 +" .align 3\n" \
1410 +" .long " #from ", " #to"\n" \
1411 +" .popsection"
1412 +
1413 +
1414 #endif /* __ASSEMBLY__ */
1415
1416 #define arch_align_stack(x) (x)
1417 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1418 index 2958976..12ccac4 100644
1419 --- a/arch/arm/include/asm/uaccess.h
1420 +++ b/arch/arm/include/asm/uaccess.h
1421 @@ -22,6 +22,8 @@
1422 #define VERIFY_READ 0
1423 #define VERIFY_WRITE 1
1424
1425 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1426 +
1427 /*
1428 * The exception table consists of pairs of addresses: the first is the
1429 * address of an instruction that is allowed to fault, and the second is
1430 @@ -387,8 +389,23 @@ do { \
1431
1432
1433 #ifdef CONFIG_MMU
1434 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1435 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1436 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1437 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1438 +
1439 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1440 +{
1441 + if (!__builtin_constant_p(n))
1442 + check_object_size(to, n, false);
1443 + return ___copy_from_user(to, from, n);
1444 +}
1445 +
1446 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1447 +{
1448 + if (!__builtin_constant_p(n))
1449 + check_object_size(from, n, true);
1450 + return ___copy_to_user(to, from, n);
1451 +}
1452 +
1453 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1454 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1455 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1456 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1457
1458 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1459 {
1460 + if ((long)n < 0)
1461 + return n;
1462 +
1463 if (access_ok(VERIFY_READ, from, n))
1464 n = __copy_from_user(to, from, n);
1465 else /* security hole - plug it */
1466 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1467
1468 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1469 {
1470 + if ((long)n < 0)
1471 + return n;
1472 +
1473 if (access_ok(VERIFY_WRITE, to, n))
1474 n = __copy_to_user(to, from, n);
1475 return n;
1476 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1477 index 5b0bce6..becd81c 100644
1478 --- a/arch/arm/kernel/armksyms.c
1479 +++ b/arch/arm/kernel/armksyms.c
1480 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1481 #ifdef CONFIG_MMU
1482 EXPORT_SYMBOL(copy_page);
1483
1484 -EXPORT_SYMBOL(__copy_from_user);
1485 -EXPORT_SYMBOL(__copy_to_user);
1486 +EXPORT_SYMBOL(___copy_from_user);
1487 +EXPORT_SYMBOL(___copy_to_user);
1488 EXPORT_SYMBOL(__clear_user);
1489
1490 EXPORT_SYMBOL(__get_user_1);
1491 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1492 index 971d65c..cc936fb 100644
1493 --- a/arch/arm/kernel/process.c
1494 +++ b/arch/arm/kernel/process.c
1495 @@ -28,7 +28,6 @@
1496 #include <linux/tick.h>
1497 #include <linux/utsname.h>
1498 #include <linux/uaccess.h>
1499 -#include <linux/random.h>
1500 #include <linux/hw_breakpoint.h>
1501 #include <linux/cpuidle.h>
1502
1503 @@ -273,9 +272,10 @@ void machine_power_off(void)
1504 machine_shutdown();
1505 if (pm_power_off)
1506 pm_power_off();
1507 + BUG();
1508 }
1509
1510 -void machine_restart(char *cmd)
1511 +__noreturn void machine_restart(char *cmd)
1512 {
1513 machine_shutdown();
1514
1515 @@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1516 return 0;
1517 }
1518
1519 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1520 -{
1521 - unsigned long range_end = mm->brk + 0x02000000;
1522 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1523 -}
1524 -
1525 #ifdef CONFIG_MMU
1526 /*
1527 * The vectors page is always readable from user space for the
1528 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1529 index a255c39..4a19b25 100644
1530 --- a/arch/arm/kernel/setup.c
1531 +++ b/arch/arm/kernel/setup.c
1532 @@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1533 struct cpu_tlb_fns cpu_tlb __read_mostly;
1534 #endif
1535 #ifdef MULTI_USER
1536 -struct cpu_user_fns cpu_user __read_mostly;
1537 +struct cpu_user_fns cpu_user __read_only;
1538 #endif
1539 #ifdef MULTI_CACHE
1540 -struct cpu_cache_fns cpu_cache __read_mostly;
1541 +struct cpu_cache_fns cpu_cache __read_only;
1542 #endif
1543 #ifdef CONFIG_OUTER_CACHE
1544 -struct outer_cache_fns outer_cache __read_mostly;
1545 +struct outer_cache_fns outer_cache __read_only;
1546 EXPORT_SYMBOL(outer_cache);
1547 #endif
1548
1549 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1550 index f84dfe6..13e94f7 100644
1551 --- a/arch/arm/kernel/traps.c
1552 +++ b/arch/arm/kernel/traps.c
1553 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1554
1555 static DEFINE_RAW_SPINLOCK(die_lock);
1556
1557 +extern void gr_handle_kernel_exploit(void);
1558 +
1559 /*
1560 * This function is protected against re-entrancy.
1561 */
1562 @@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1563 panic("Fatal exception in interrupt");
1564 if (panic_on_oops)
1565 panic("Fatal exception");
1566 +
1567 + gr_handle_kernel_exploit();
1568 +
1569 if (ret != NOTIFY_STOP)
1570 do_exit(SIGSEGV);
1571 }
1572 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1573 index 66a477a..bee61d3 100644
1574 --- a/arch/arm/lib/copy_from_user.S
1575 +++ b/arch/arm/lib/copy_from_user.S
1576 @@ -16,7 +16,7 @@
1577 /*
1578 * Prototype:
1579 *
1580 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1581 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1582 *
1583 * Purpose:
1584 *
1585 @@ -84,11 +84,11 @@
1586
1587 .text
1588
1589 -ENTRY(__copy_from_user)
1590 +ENTRY(___copy_from_user)
1591
1592 #include "copy_template.S"
1593
1594 -ENDPROC(__copy_from_user)
1595 +ENDPROC(___copy_from_user)
1596
1597 .pushsection .fixup,"ax"
1598 .align 0
1599 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1600 index 6ee2f67..d1cce76 100644
1601 --- a/arch/arm/lib/copy_page.S
1602 +++ b/arch/arm/lib/copy_page.S
1603 @@ -10,6 +10,7 @@
1604 * ASM optimised string functions
1605 */
1606 #include <linux/linkage.h>
1607 +#include <linux/const.h>
1608 #include <asm/assembler.h>
1609 #include <asm/asm-offsets.h>
1610 #include <asm/cache.h>
1611 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1612 index d066df6..df28194 100644
1613 --- a/arch/arm/lib/copy_to_user.S
1614 +++ b/arch/arm/lib/copy_to_user.S
1615 @@ -16,7 +16,7 @@
1616 /*
1617 * Prototype:
1618 *
1619 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1620 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1621 *
1622 * Purpose:
1623 *
1624 @@ -88,11 +88,11 @@
1625 .text
1626
1627 ENTRY(__copy_to_user_std)
1628 -WEAK(__copy_to_user)
1629 +WEAK(___copy_to_user)
1630
1631 #include "copy_template.S"
1632
1633 -ENDPROC(__copy_to_user)
1634 +ENDPROC(___copy_to_user)
1635 ENDPROC(__copy_to_user_std)
1636
1637 .pushsection .fixup,"ax"
1638 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1639 index 5c908b1..e712687 100644
1640 --- a/arch/arm/lib/uaccess.S
1641 +++ b/arch/arm/lib/uaccess.S
1642 @@ -20,7 +20,7 @@
1643
1644 #define PAGE_SHIFT 12
1645
1646 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1647 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1648 * Purpose : copy a block to user memory from kernel memory
1649 * Params : to - user memory
1650 * : from - kernel memory
1651 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1652 sub r2, r2, ip
1653 b .Lc2u_dest_aligned
1654
1655 -ENTRY(__copy_to_user)
1656 +ENTRY(___copy_to_user)
1657 stmfd sp!, {r2, r4 - r7, lr}
1658 cmp r2, #4
1659 blt .Lc2u_not_enough
1660 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1661 ldrgtb r3, [r1], #0
1662 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1663 b .Lc2u_finished
1664 -ENDPROC(__copy_to_user)
1665 +ENDPROC(___copy_to_user)
1666
1667 .pushsection .fixup,"ax"
1668 .align 0
1669 9001: ldmfd sp!, {r0, r4 - r7, pc}
1670 .popsection
1671
1672 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1673 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1674 * Purpose : copy a block from user memory to kernel memory
1675 * Params : to - kernel memory
1676 * : from - user memory
1677 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1678 sub r2, r2, ip
1679 b .Lcfu_dest_aligned
1680
1681 -ENTRY(__copy_from_user)
1682 +ENTRY(___copy_from_user)
1683 stmfd sp!, {r0, r2, r4 - r7, lr}
1684 cmp r2, #4
1685 blt .Lcfu_not_enough
1686 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1687 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1688 strgtb r3, [r0], #1
1689 b .Lcfu_finished
1690 -ENDPROC(__copy_from_user)
1691 +ENDPROC(___copy_from_user)
1692
1693 .pushsection .fixup,"ax"
1694 .align 0
1695 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1696 index 025f742..8432b08 100644
1697 --- a/arch/arm/lib/uaccess_with_memcpy.c
1698 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1699 @@ -104,7 +104,7 @@ out:
1700 }
1701
1702 unsigned long
1703 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1704 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1705 {
1706 /*
1707 * This test is stubbed out of the main function above to keep
1708 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1709 index 6722627..8f97548c 100644
1710 --- a/arch/arm/mach-omap2/board-n8x0.c
1711 +++ b/arch/arm/mach-omap2/board-n8x0.c
1712 @@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1713 }
1714 #endif
1715
1716 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1717 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1718 .late_init = n8x0_menelaus_late_init,
1719 };
1720
1721 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1722 index 2b2d51c..0127490 100644
1723 --- a/arch/arm/mach-ux500/mbox-db5500.c
1724 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1725 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1726 return sprintf(buf, "0x%X\n", mbox_value);
1727 }
1728
1729 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1730 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1731
1732 static int mbox_show(struct seq_file *s, void *data)
1733 {
1734 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1735 index bb7eac3..3bade16 100644
1736 --- a/arch/arm/mm/fault.c
1737 +++ b/arch/arm/mm/fault.c
1738 @@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1739 }
1740 #endif
1741
1742 +#ifdef CONFIG_PAX_PAGEEXEC
1743 + if (fsr & FSR_LNX_PF) {
1744 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1745 + do_group_exit(SIGKILL);
1746 + }
1747 +#endif
1748 +
1749 tsk->thread.address = addr;
1750 tsk->thread.error_code = fsr;
1751 tsk->thread.trap_no = 14;
1752 @@ -393,6 +400,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1753 }
1754 #endif /* CONFIG_MMU */
1755
1756 +#ifdef CONFIG_PAX_PAGEEXEC
1757 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1758 +{
1759 + long i;
1760 +
1761 + printk(KERN_ERR "PAX: bytes at PC: ");
1762 + for (i = 0; i < 20; i++) {
1763 + unsigned char c;
1764 + if (get_user(c, (__force unsigned char __user *)pc+i))
1765 + printk(KERN_CONT "?? ");
1766 + else
1767 + printk(KERN_CONT "%02x ", c);
1768 + }
1769 + printk("\n");
1770 +
1771 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1772 + for (i = -1; i < 20; i++) {
1773 + unsigned long c;
1774 + if (get_user(c, (__force unsigned long __user *)sp+i))
1775 + printk(KERN_CONT "???????? ");
1776 + else
1777 + printk(KERN_CONT "%08lx ", c);
1778 + }
1779 + printk("\n");
1780 +}
1781 +#endif
1782 +
1783 /*
1784 * First Level Translation Fault Handler
1785 *
1786 @@ -573,6 +607,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1787 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1788 struct siginfo info;
1789
1790 +#ifdef CONFIG_PAX_REFCOUNT
1791 + if (fsr_fs(ifsr) == 2) {
1792 + unsigned int bkpt;
1793 +
1794 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1795 + current->thread.error_code = ifsr;
1796 + current->thread.trap_no = 0;
1797 + pax_report_refcount_overflow(regs);
1798 + fixup_exception(regs);
1799 + return;
1800 + }
1801 + }
1802 +#endif
1803 +
1804 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1805 return;
1806
1807 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1808 index ce8cb19..3ec539d 100644
1809 --- a/arch/arm/mm/mmap.c
1810 +++ b/arch/arm/mm/mmap.c
1811 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1812 if (len > TASK_SIZE)
1813 return -ENOMEM;
1814
1815 +#ifdef CONFIG_PAX_RANDMMAP
1816 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1817 +#endif
1818 +
1819 if (addr) {
1820 if (do_align)
1821 addr = COLOUR_ALIGN(addr, pgoff);
1822 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1823 addr = PAGE_ALIGN(addr);
1824
1825 vma = find_vma(mm, addr);
1826 - if (TASK_SIZE - len >= addr &&
1827 - (!vma || addr + len <= vma->vm_start))
1828 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1829 return addr;
1830 }
1831 if (len > mm->cached_hole_size) {
1832 - start_addr = addr = mm->free_area_cache;
1833 + start_addr = addr = mm->free_area_cache;
1834 } else {
1835 - start_addr = addr = mm->mmap_base;
1836 - mm->cached_hole_size = 0;
1837 + start_addr = addr = mm->mmap_base;
1838 + mm->cached_hole_size = 0;
1839 }
1840
1841 full_search:
1842 @@ -124,14 +127,14 @@ full_search:
1843 * Start a new search - just in case we missed
1844 * some holes.
1845 */
1846 - if (start_addr != TASK_UNMAPPED_BASE) {
1847 - start_addr = addr = TASK_UNMAPPED_BASE;
1848 + if (start_addr != mm->mmap_base) {
1849 + start_addr = addr = mm->mmap_base;
1850 mm->cached_hole_size = 0;
1851 goto full_search;
1852 }
1853 return -ENOMEM;
1854 }
1855 - if (!vma || addr + len <= vma->vm_start) {
1856 + if (check_heap_stack_gap(vma, addr, len)) {
1857 /*
1858 * Remember the place where we stopped the search:
1859 */
1860 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1861
1862 if (mmap_is_legacy()) {
1863 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1864 +
1865 +#ifdef CONFIG_PAX_RANDMMAP
1866 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1867 + mm->mmap_base += mm->delta_mmap;
1868 +#endif
1869 +
1870 mm->get_unmapped_area = arch_get_unmapped_area;
1871 mm->unmap_area = arch_unmap_area;
1872 } else {
1873 mm->mmap_base = mmap_base(random_factor);
1874 +
1875 +#ifdef CONFIG_PAX_RANDMMAP
1876 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1877 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1878 +#endif
1879 +
1880 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1881 mm->unmap_area = arch_unmap_area_topdown;
1882 }
1883 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1884 index 71a6827..e7fbc23 100644
1885 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1886 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1887 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
1888 int (*started)(unsigned ch);
1889 int (*flush)(unsigned ch);
1890 int (*stop)(unsigned ch);
1891 -};
1892 +} __no_const;
1893
1894 extern void *samsung_dmadev_get_ops(void);
1895 extern void *s3c_dma_get_ops(void);
1896 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1897 index 5f28cae..3d23723 100644
1898 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1899 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1900 @@ -14,7 +14,7 @@
1901 struct s5p_ehci_platdata {
1902 int (*phy_init)(struct platform_device *pdev, int type);
1903 int (*phy_exit)(struct platform_device *pdev, int type);
1904 -};
1905 +} __no_const;
1906
1907 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1908
1909 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1910 index c3a58a1..78fbf54 100644
1911 --- a/arch/avr32/include/asm/cache.h
1912 +++ b/arch/avr32/include/asm/cache.h
1913 @@ -1,8 +1,10 @@
1914 #ifndef __ASM_AVR32_CACHE_H
1915 #define __ASM_AVR32_CACHE_H
1916
1917 +#include <linux/const.h>
1918 +
1919 #define L1_CACHE_SHIFT 5
1920 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1921 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1922
1923 /*
1924 * Memory returned by kmalloc() may be used for DMA, so we must make
1925 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1926 index 3b3159b..425ea94 100644
1927 --- a/arch/avr32/include/asm/elf.h
1928 +++ b/arch/avr32/include/asm/elf.h
1929 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1930 the loader. We need to make sure that it is out of the way of the program
1931 that it will "exec", and that there is sufficient room for the brk. */
1932
1933 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1934 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1935
1936 +#ifdef CONFIG_PAX_ASLR
1937 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1938 +
1939 +#define PAX_DELTA_MMAP_LEN 15
1940 +#define PAX_DELTA_STACK_LEN 15
1941 +#endif
1942
1943 /* This yields a mask that user programs can use to figure out what
1944 instruction set this CPU supports. This could be done in user space,
1945 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1946 index b7f5c68..556135c 100644
1947 --- a/arch/avr32/include/asm/kmap_types.h
1948 +++ b/arch/avr32/include/asm/kmap_types.h
1949 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1950 D(11) KM_IRQ1,
1951 D(12) KM_SOFTIRQ0,
1952 D(13) KM_SOFTIRQ1,
1953 -D(14) KM_TYPE_NR
1954 +D(14) KM_CLEARPAGE,
1955 +D(15) KM_TYPE_NR
1956 };
1957
1958 #undef D
1959 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1960 index f7040a1..db9f300 100644
1961 --- a/arch/avr32/mm/fault.c
1962 +++ b/arch/avr32/mm/fault.c
1963 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1964
1965 int exception_trace = 1;
1966
1967 +#ifdef CONFIG_PAX_PAGEEXEC
1968 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1969 +{
1970 + unsigned long i;
1971 +
1972 + printk(KERN_ERR "PAX: bytes at PC: ");
1973 + for (i = 0; i < 20; i++) {
1974 + unsigned char c;
1975 + if (get_user(c, (unsigned char *)pc+i))
1976 + printk(KERN_CONT "???????? ");
1977 + else
1978 + printk(KERN_CONT "%02x ", c);
1979 + }
1980 + printk("\n");
1981 +}
1982 +#endif
1983 +
1984 /*
1985 * This routine handles page faults. It determines the address and the
1986 * problem, and then passes it off to one of the appropriate routines.
1987 @@ -156,6 +173,16 @@ bad_area:
1988 up_read(&mm->mmap_sem);
1989
1990 if (user_mode(regs)) {
1991 +
1992 +#ifdef CONFIG_PAX_PAGEEXEC
1993 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1994 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1995 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1996 + do_group_exit(SIGKILL);
1997 + }
1998 + }
1999 +#endif
2000 +
2001 if (exception_trace && printk_ratelimit())
2002 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2003 "sp %08lx ecr %lu\n",
2004 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2005 index 568885a..f8008df 100644
2006 --- a/arch/blackfin/include/asm/cache.h
2007 +++ b/arch/blackfin/include/asm/cache.h
2008 @@ -7,6 +7,7 @@
2009 #ifndef __ARCH_BLACKFIN_CACHE_H
2010 #define __ARCH_BLACKFIN_CACHE_H
2011
2012 +#include <linux/const.h>
2013 #include <linux/linkage.h> /* for asmlinkage */
2014
2015 /*
2016 @@ -14,7 +15,7 @@
2017 * Blackfin loads 32 bytes for cache
2018 */
2019 #define L1_CACHE_SHIFT 5
2020 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2021 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2022 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2023
2024 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2025 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2026 index aea2718..3639a60 100644
2027 --- a/arch/cris/include/arch-v10/arch/cache.h
2028 +++ b/arch/cris/include/arch-v10/arch/cache.h
2029 @@ -1,8 +1,9 @@
2030 #ifndef _ASM_ARCH_CACHE_H
2031 #define _ASM_ARCH_CACHE_H
2032
2033 +#include <linux/const.h>
2034 /* Etrax 100LX have 32-byte cache-lines. */
2035 -#define L1_CACHE_BYTES 32
2036 #define L1_CACHE_SHIFT 5
2037 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2038
2039 #endif /* _ASM_ARCH_CACHE_H */
2040 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2041 index 1de779f..336fad3 100644
2042 --- a/arch/cris/include/arch-v32/arch/cache.h
2043 +++ b/arch/cris/include/arch-v32/arch/cache.h
2044 @@ -1,11 +1,12 @@
2045 #ifndef _ASM_CRIS_ARCH_CACHE_H
2046 #define _ASM_CRIS_ARCH_CACHE_H
2047
2048 +#include <linux/const.h>
2049 #include <arch/hwregs/dma.h>
2050
2051 /* A cache-line is 32 bytes. */
2052 -#define L1_CACHE_BYTES 32
2053 #define L1_CACHE_SHIFT 5
2054 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2055
2056 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2057
2058 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2059 index 0d8a7d6..d0c9ff5 100644
2060 --- a/arch/frv/include/asm/atomic.h
2061 +++ b/arch/frv/include/asm/atomic.h
2062 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2063 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2064 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2065
2066 +#define atomic64_read_unchecked(v) atomic64_read(v)
2067 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2068 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2069 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2070 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2071 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2072 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2073 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2074 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2075 +
2076 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2077 {
2078 int c, old;
2079 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2080 index 2797163..c2a401d 100644
2081 --- a/arch/frv/include/asm/cache.h
2082 +++ b/arch/frv/include/asm/cache.h
2083 @@ -12,10 +12,11 @@
2084 #ifndef __ASM_CACHE_H
2085 #define __ASM_CACHE_H
2086
2087 +#include <linux/const.h>
2088
2089 /* bytes per L1 cache line */
2090 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2091 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2092 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2093
2094 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2095 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2096 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2097 index f8e16b2..c73ff79 100644
2098 --- a/arch/frv/include/asm/kmap_types.h
2099 +++ b/arch/frv/include/asm/kmap_types.h
2100 @@ -23,6 +23,7 @@ enum km_type {
2101 KM_IRQ1,
2102 KM_SOFTIRQ0,
2103 KM_SOFTIRQ1,
2104 + KM_CLEARPAGE,
2105 KM_TYPE_NR
2106 };
2107
2108 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2109 index 385fd30..6c3d97e 100644
2110 --- a/arch/frv/mm/elf-fdpic.c
2111 +++ b/arch/frv/mm/elf-fdpic.c
2112 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2113 if (addr) {
2114 addr = PAGE_ALIGN(addr);
2115 vma = find_vma(current->mm, addr);
2116 - if (TASK_SIZE - len >= addr &&
2117 - (!vma || addr + len <= vma->vm_start))
2118 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2119 goto success;
2120 }
2121
2122 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2123 for (; vma; vma = vma->vm_next) {
2124 if (addr > limit)
2125 break;
2126 - if (addr + len <= vma->vm_start)
2127 + if (check_heap_stack_gap(vma, addr, len))
2128 goto success;
2129 addr = vma->vm_end;
2130 }
2131 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2132 for (; vma; vma = vma->vm_next) {
2133 if (addr > limit)
2134 break;
2135 - if (addr + len <= vma->vm_start)
2136 + if (check_heap_stack_gap(vma, addr, len))
2137 goto success;
2138 addr = vma->vm_end;
2139 }
2140 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2141 index c635028..6d9445a 100644
2142 --- a/arch/h8300/include/asm/cache.h
2143 +++ b/arch/h8300/include/asm/cache.h
2144 @@ -1,8 +1,10 @@
2145 #ifndef __ARCH_H8300_CACHE_H
2146 #define __ARCH_H8300_CACHE_H
2147
2148 +#include <linux/const.h>
2149 +
2150 /* bytes per L1 cache line */
2151 -#define L1_CACHE_BYTES 4
2152 +#define L1_CACHE_BYTES _AC(4,UL)
2153
2154 /* m68k-elf-gcc 2.95.2 doesn't like these */
2155
2156 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2157 index 0f01de2..d37d309 100644
2158 --- a/arch/hexagon/include/asm/cache.h
2159 +++ b/arch/hexagon/include/asm/cache.h
2160 @@ -21,9 +21,11 @@
2161 #ifndef __ASM_CACHE_H
2162 #define __ASM_CACHE_H
2163
2164 +#include <linux/const.h>
2165 +
2166 /* Bytes per L1 cache line */
2167 -#define L1_CACHE_SHIFT (5)
2168 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2169 +#define L1_CACHE_SHIFT 5
2170 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2171
2172 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2173 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2174 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2175 index 3fad89e..3047da5 100644
2176 --- a/arch/ia64/include/asm/atomic.h
2177 +++ b/arch/ia64/include/asm/atomic.h
2178 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2179 #define atomic64_inc(v) atomic64_add(1, (v))
2180 #define atomic64_dec(v) atomic64_sub(1, (v))
2181
2182 +#define atomic64_read_unchecked(v) atomic64_read(v)
2183 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2184 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2185 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2186 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2187 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2188 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2189 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2190 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2191 +
2192 /* Atomic operations are already serializing */
2193 #define smp_mb__before_atomic_dec() barrier()
2194 #define smp_mb__after_atomic_dec() barrier()
2195 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2196 index 988254a..e1ee885 100644
2197 --- a/arch/ia64/include/asm/cache.h
2198 +++ b/arch/ia64/include/asm/cache.h
2199 @@ -1,6 +1,7 @@
2200 #ifndef _ASM_IA64_CACHE_H
2201 #define _ASM_IA64_CACHE_H
2202
2203 +#include <linux/const.h>
2204
2205 /*
2206 * Copyright (C) 1998-2000 Hewlett-Packard Co
2207 @@ -9,7 +10,7 @@
2208
2209 /* Bytes per L1 (data) cache line. */
2210 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2211 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2212 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2213
2214 #ifdef CONFIG_SMP
2215 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2216 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2217 index b5298eb..67c6e62 100644
2218 --- a/arch/ia64/include/asm/elf.h
2219 +++ b/arch/ia64/include/asm/elf.h
2220 @@ -42,6 +42,13 @@
2221 */
2222 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2223
2224 +#ifdef CONFIG_PAX_ASLR
2225 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2226 +
2227 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2228 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2229 +#endif
2230 +
2231 #define PT_IA_64_UNWIND 0x70000001
2232
2233 /* IA-64 relocations: */
2234 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2235 index 1a97af3..7529d31 100644
2236 --- a/arch/ia64/include/asm/pgtable.h
2237 +++ b/arch/ia64/include/asm/pgtable.h
2238 @@ -12,7 +12,7 @@
2239 * David Mosberger-Tang <davidm@hpl.hp.com>
2240 */
2241
2242 -
2243 +#include <linux/const.h>
2244 #include <asm/mman.h>
2245 #include <asm/page.h>
2246 #include <asm/processor.h>
2247 @@ -143,6 +143,17 @@
2248 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2249 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2250 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2251 +
2252 +#ifdef CONFIG_PAX_PAGEEXEC
2253 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2254 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2255 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2256 +#else
2257 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2258 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2259 +# define PAGE_COPY_NOEXEC PAGE_COPY
2260 +#endif
2261 +
2262 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2263 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2264 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2265 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2266 index b77768d..e0795eb 100644
2267 --- a/arch/ia64/include/asm/spinlock.h
2268 +++ b/arch/ia64/include/asm/spinlock.h
2269 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2270 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2271
2272 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2273 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2274 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2275 }
2276
2277 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2278 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2279 index 449c8c0..432a3d2 100644
2280 --- a/arch/ia64/include/asm/uaccess.h
2281 +++ b/arch/ia64/include/asm/uaccess.h
2282 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2283 const void *__cu_from = (from); \
2284 long __cu_len = (n); \
2285 \
2286 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2287 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2288 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2289 __cu_len; \
2290 })
2291 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2292 long __cu_len = (n); \
2293 \
2294 __chk_user_ptr(__cu_from); \
2295 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2296 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2297 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2298 __cu_len; \
2299 })
2300 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2301 index 24603be..948052d 100644
2302 --- a/arch/ia64/kernel/module.c
2303 +++ b/arch/ia64/kernel/module.c
2304 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2305 void
2306 module_free (struct module *mod, void *module_region)
2307 {
2308 - if (mod && mod->arch.init_unw_table &&
2309 - module_region == mod->module_init) {
2310 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2311 unw_remove_unwind_table(mod->arch.init_unw_table);
2312 mod->arch.init_unw_table = NULL;
2313 }
2314 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2315 }
2316
2317 static inline int
2318 +in_init_rx (const struct module *mod, uint64_t addr)
2319 +{
2320 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2321 +}
2322 +
2323 +static inline int
2324 +in_init_rw (const struct module *mod, uint64_t addr)
2325 +{
2326 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2327 +}
2328 +
2329 +static inline int
2330 in_init (const struct module *mod, uint64_t addr)
2331 {
2332 - return addr - (uint64_t) mod->module_init < mod->init_size;
2333 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2334 +}
2335 +
2336 +static inline int
2337 +in_core_rx (const struct module *mod, uint64_t addr)
2338 +{
2339 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2340 +}
2341 +
2342 +static inline int
2343 +in_core_rw (const struct module *mod, uint64_t addr)
2344 +{
2345 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2346 }
2347
2348 static inline int
2349 in_core (const struct module *mod, uint64_t addr)
2350 {
2351 - return addr - (uint64_t) mod->module_core < mod->core_size;
2352 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2353 }
2354
2355 static inline int
2356 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2357 break;
2358
2359 case RV_BDREL:
2360 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2361 + if (in_init_rx(mod, val))
2362 + val -= (uint64_t) mod->module_init_rx;
2363 + else if (in_init_rw(mod, val))
2364 + val -= (uint64_t) mod->module_init_rw;
2365 + else if (in_core_rx(mod, val))
2366 + val -= (uint64_t) mod->module_core_rx;
2367 + else if (in_core_rw(mod, val))
2368 + val -= (uint64_t) mod->module_core_rw;
2369 break;
2370
2371 case RV_LTV:
2372 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2373 * addresses have been selected...
2374 */
2375 uint64_t gp;
2376 - if (mod->core_size > MAX_LTOFF)
2377 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2378 /*
2379 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2380 * at the end of the module.
2381 */
2382 - gp = mod->core_size - MAX_LTOFF / 2;
2383 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2384 else
2385 - gp = mod->core_size / 2;
2386 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2387 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2388 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2389 mod->arch.gp = gp;
2390 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2391 }
2392 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2393 index 609d500..7dde2a8 100644
2394 --- a/arch/ia64/kernel/sys_ia64.c
2395 +++ b/arch/ia64/kernel/sys_ia64.c
2396 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2397 if (REGION_NUMBER(addr) == RGN_HPAGE)
2398 addr = 0;
2399 #endif
2400 +
2401 +#ifdef CONFIG_PAX_RANDMMAP
2402 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2403 + addr = mm->free_area_cache;
2404 + else
2405 +#endif
2406 +
2407 if (!addr)
2408 addr = mm->free_area_cache;
2409
2410 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2411 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2412 /* At this point: (!vma || addr < vma->vm_end). */
2413 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2414 - if (start_addr != TASK_UNMAPPED_BASE) {
2415 + if (start_addr != mm->mmap_base) {
2416 /* Start a new search --- just in case we missed some holes. */
2417 - addr = TASK_UNMAPPED_BASE;
2418 + addr = mm->mmap_base;
2419 goto full_search;
2420 }
2421 return -ENOMEM;
2422 }
2423 - if (!vma || addr + len <= vma->vm_start) {
2424 + if (check_heap_stack_gap(vma, addr, len)) {
2425 /* Remember the address where we stopped this search: */
2426 mm->free_area_cache = addr + len;
2427 return addr;
2428 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2429 index 53c0ba0..2accdde 100644
2430 --- a/arch/ia64/kernel/vmlinux.lds.S
2431 +++ b/arch/ia64/kernel/vmlinux.lds.S
2432 @@ -199,7 +199,7 @@ SECTIONS {
2433 /* Per-cpu data: */
2434 . = ALIGN(PERCPU_PAGE_SIZE);
2435 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2436 - __phys_per_cpu_start = __per_cpu_load;
2437 + __phys_per_cpu_start = per_cpu_load;
2438 /*
2439 * ensure percpu data fits
2440 * into percpu page size
2441 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2442 index 20b3593..1ce77f0 100644
2443 --- a/arch/ia64/mm/fault.c
2444 +++ b/arch/ia64/mm/fault.c
2445 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2446 return pte_present(pte);
2447 }
2448
2449 +#ifdef CONFIG_PAX_PAGEEXEC
2450 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2451 +{
2452 + unsigned long i;
2453 +
2454 + printk(KERN_ERR "PAX: bytes at PC: ");
2455 + for (i = 0; i < 8; i++) {
2456 + unsigned int c;
2457 + if (get_user(c, (unsigned int *)pc+i))
2458 + printk(KERN_CONT "???????? ");
2459 + else
2460 + printk(KERN_CONT "%08x ", c);
2461 + }
2462 + printk("\n");
2463 +}
2464 +#endif
2465 +
2466 void __kprobes
2467 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2468 {
2469 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2470 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2471 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2472
2473 - if ((vma->vm_flags & mask) != mask)
2474 + if ((vma->vm_flags & mask) != mask) {
2475 +
2476 +#ifdef CONFIG_PAX_PAGEEXEC
2477 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2478 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2479 + goto bad_area;
2480 +
2481 + up_read(&mm->mmap_sem);
2482 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2483 + do_group_exit(SIGKILL);
2484 + }
2485 +#endif
2486 +
2487 goto bad_area;
2488
2489 + }
2490 +
2491 /*
2492 * If for any reason at all we couldn't handle the fault, make
2493 * sure we exit gracefully rather than endlessly redo the
2494 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2495 index 5ca674b..e0e1b70 100644
2496 --- a/arch/ia64/mm/hugetlbpage.c
2497 +++ b/arch/ia64/mm/hugetlbpage.c
2498 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2499 /* At this point: (!vmm || addr < vmm->vm_end). */
2500 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2501 return -ENOMEM;
2502 - if (!vmm || (addr + len) <= vmm->vm_start)
2503 + if (check_heap_stack_gap(vmm, addr, len))
2504 return addr;
2505 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2506 }
2507 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2508 index 13df239d..cb52116 100644
2509 --- a/arch/ia64/mm/init.c
2510 +++ b/arch/ia64/mm/init.c
2511 @@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2512 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2513 vma->vm_end = vma->vm_start + PAGE_SIZE;
2514 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2515 +
2516 +#ifdef CONFIG_PAX_PAGEEXEC
2517 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2518 + vma->vm_flags &= ~VM_EXEC;
2519 +
2520 +#ifdef CONFIG_PAX_MPROTECT
2521 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2522 + vma->vm_flags &= ~VM_MAYEXEC;
2523 +#endif
2524 +
2525 + }
2526 +#endif
2527 +
2528 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2529 down_write(&current->mm->mmap_sem);
2530 if (insert_vm_struct(current->mm, vma)) {
2531 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2532 index 40b3ee9..8c2c112 100644
2533 --- a/arch/m32r/include/asm/cache.h
2534 +++ b/arch/m32r/include/asm/cache.h
2535 @@ -1,8 +1,10 @@
2536 #ifndef _ASM_M32R_CACHE_H
2537 #define _ASM_M32R_CACHE_H
2538
2539 +#include <linux/const.h>
2540 +
2541 /* L1 cache line size */
2542 #define L1_CACHE_SHIFT 4
2543 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2544 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2545
2546 #endif /* _ASM_M32R_CACHE_H */
2547 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2548 index 82abd15..d95ae5d 100644
2549 --- a/arch/m32r/lib/usercopy.c
2550 +++ b/arch/m32r/lib/usercopy.c
2551 @@ -14,6 +14,9 @@
2552 unsigned long
2553 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2554 {
2555 + if ((long)n < 0)
2556 + return n;
2557 +
2558 prefetch(from);
2559 if (access_ok(VERIFY_WRITE, to, n))
2560 __copy_user(to,from,n);
2561 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2562 unsigned long
2563 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2564 {
2565 + if ((long)n < 0)
2566 + return n;
2567 +
2568 prefetchw(to);
2569 if (access_ok(VERIFY_READ, from, n))
2570 __copy_user_zeroing(to,from,n);
2571 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2572 index 0395c51..5f26031 100644
2573 --- a/arch/m68k/include/asm/cache.h
2574 +++ b/arch/m68k/include/asm/cache.h
2575 @@ -4,9 +4,11 @@
2576 #ifndef __ARCH_M68K_CACHE_H
2577 #define __ARCH_M68K_CACHE_H
2578
2579 +#include <linux/const.h>
2580 +
2581 /* bytes per L1 cache line */
2582 #define L1_CACHE_SHIFT 4
2583 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2584 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2585
2586 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2587
2588 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2589 index 4efe96a..60e8699 100644
2590 --- a/arch/microblaze/include/asm/cache.h
2591 +++ b/arch/microblaze/include/asm/cache.h
2592 @@ -13,11 +13,12 @@
2593 #ifndef _ASM_MICROBLAZE_CACHE_H
2594 #define _ASM_MICROBLAZE_CACHE_H
2595
2596 +#include <linux/const.h>
2597 #include <asm/registers.h>
2598
2599 #define L1_CACHE_SHIFT 5
2600 /* word-granular cache in microblaze */
2601 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2602 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2603
2604 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2605
2606 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2607 index 1d93f81..67794d0 100644
2608 --- a/arch/mips/include/asm/atomic.h
2609 +++ b/arch/mips/include/asm/atomic.h
2610 @@ -21,6 +21,10 @@
2611 #include <asm/war.h>
2612 #include <asm/system.h>
2613
2614 +#ifdef CONFIG_GENERIC_ATOMIC64
2615 +#include <asm-generic/atomic64.h>
2616 +#endif
2617 +
2618 #define ATOMIC_INIT(i) { (i) }
2619
2620 /*
2621 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2622 */
2623 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2624
2625 +#define atomic64_read_unchecked(v) atomic64_read(v)
2626 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2627 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2628 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2629 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2630 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2631 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2632 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2633 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2634 +
2635 #endif /* CONFIG_64BIT */
2636
2637 /*
2638 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2639 index b4db69f..8f3b093 100644
2640 --- a/arch/mips/include/asm/cache.h
2641 +++ b/arch/mips/include/asm/cache.h
2642 @@ -9,10 +9,11 @@
2643 #ifndef _ASM_CACHE_H
2644 #define _ASM_CACHE_H
2645
2646 +#include <linux/const.h>
2647 #include <kmalloc.h>
2648
2649 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2650 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2651 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2652
2653 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2654 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2655 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2656 index 455c0ac..ad65fbe 100644
2657 --- a/arch/mips/include/asm/elf.h
2658 +++ b/arch/mips/include/asm/elf.h
2659 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2660 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2661 #endif
2662
2663 +#ifdef CONFIG_PAX_ASLR
2664 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2665 +
2666 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2667 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2668 +#endif
2669 +
2670 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2671 struct linux_binprm;
2672 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2673 int uses_interp);
2674
2675 -struct mm_struct;
2676 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2677 -#define arch_randomize_brk arch_randomize_brk
2678 -
2679 #endif /* _ASM_ELF_H */
2680 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2681 index da9bd7d..91aa7ab 100644
2682 --- a/arch/mips/include/asm/page.h
2683 +++ b/arch/mips/include/asm/page.h
2684 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2685 #ifdef CONFIG_CPU_MIPS32
2686 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2687 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2688 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2689 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2690 #else
2691 typedef struct { unsigned long long pte; } pte_t;
2692 #define pte_val(x) ((x).pte)
2693 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2694 index 6018c80..7c37203 100644
2695 --- a/arch/mips/include/asm/system.h
2696 +++ b/arch/mips/include/asm/system.h
2697 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2698 */
2699 #define __ARCH_WANT_UNLOCKED_CTXSW
2700
2701 -extern unsigned long arch_align_stack(unsigned long sp);
2702 +#define arch_align_stack(x) ((x) & ~0xfUL)
2703
2704 #endif /* _ASM_SYSTEM_H */
2705 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2706 index 9fdd8bc..4bd7f1a 100644
2707 --- a/arch/mips/kernel/binfmt_elfn32.c
2708 +++ b/arch/mips/kernel/binfmt_elfn32.c
2709 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2710 #undef ELF_ET_DYN_BASE
2711 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2712
2713 +#ifdef CONFIG_PAX_ASLR
2714 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2715 +
2716 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2717 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2718 +#endif
2719 +
2720 #include <asm/processor.h>
2721 #include <linux/module.h>
2722 #include <linux/elfcore.h>
2723 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2724 index ff44823..97f8906 100644
2725 --- a/arch/mips/kernel/binfmt_elfo32.c
2726 +++ b/arch/mips/kernel/binfmt_elfo32.c
2727 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2728 #undef ELF_ET_DYN_BASE
2729 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2730
2731 +#ifdef CONFIG_PAX_ASLR
2732 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2733 +
2734 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2735 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2736 +#endif
2737 +
2738 #include <asm/processor.h>
2739
2740 /*
2741 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2742 index 7955409..ceaea7c 100644
2743 --- a/arch/mips/kernel/process.c
2744 +++ b/arch/mips/kernel/process.c
2745 @@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2746 out:
2747 return pc;
2748 }
2749 -
2750 -/*
2751 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2752 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2753 - */
2754 -unsigned long arch_align_stack(unsigned long sp)
2755 -{
2756 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2757 - sp -= get_random_int() & ~PAGE_MASK;
2758 -
2759 - return sp & ALMASK;
2760 -}
2761 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2762 index 69ebd58..e4bff83 100644
2763 --- a/arch/mips/mm/fault.c
2764 +++ b/arch/mips/mm/fault.c
2765 @@ -28,6 +28,23 @@
2766 #include <asm/highmem.h> /* For VMALLOC_END */
2767 #include <linux/kdebug.h>
2768
2769 +#ifdef CONFIG_PAX_PAGEEXEC
2770 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2771 +{
2772 + unsigned long i;
2773 +
2774 + printk(KERN_ERR "PAX: bytes at PC: ");
2775 + for (i = 0; i < 5; i++) {
2776 + unsigned int c;
2777 + if (get_user(c, (unsigned int *)pc+i))
2778 + printk(KERN_CONT "???????? ");
2779 + else
2780 + printk(KERN_CONT "%08x ", c);
2781 + }
2782 + printk("\n");
2783 +}
2784 +#endif
2785 +
2786 /*
2787 * This routine handles page faults. It determines the address,
2788 * and the problem, and then passes it off to one of the appropriate
2789 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2790 index 302d779..7d35bf8 100644
2791 --- a/arch/mips/mm/mmap.c
2792 +++ b/arch/mips/mm/mmap.c
2793 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2794 do_color_align = 1;
2795
2796 /* requesting a specific address */
2797 +
2798 +#ifdef CONFIG_PAX_RANDMMAP
2799 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2800 +#endif
2801 +
2802 if (addr) {
2803 if (do_color_align)
2804 addr = COLOUR_ALIGN(addr, pgoff);
2805 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2806 addr = PAGE_ALIGN(addr);
2807
2808 vma = find_vma(mm, addr);
2809 - if (TASK_SIZE - len >= addr &&
2810 - (!vma || addr + len <= vma->vm_start))
2811 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2812 return addr;
2813 }
2814
2815 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2816 /* At this point: (!vma || addr < vma->vm_end). */
2817 if (TASK_SIZE - len < addr)
2818 return -ENOMEM;
2819 - if (!vma || addr + len <= vma->vm_start)
2820 + if (check_heap_stack_gap(vmm, addr, len))
2821 return addr;
2822 addr = vma->vm_end;
2823 if (do_color_align)
2824 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2825 /* make sure it can fit in the remaining address space */
2826 if (likely(addr > len)) {
2827 vma = find_vma(mm, addr - len);
2828 - if (!vma || addr <= vma->vm_start) {
2829 + if (check_heap_stack_gap(vmm, addr - len, len))
2830 /* cache the address as a hint for next time */
2831 return mm->free_area_cache = addr - len;
2832 }
2833 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2834 * return with success:
2835 */
2836 vma = find_vma(mm, addr);
2837 - if (likely(!vma || addr + len <= vma->vm_start)) {
2838 + if (check_heap_stack_gap(vmm, addr, len)) {
2839 /* cache the address as a hint for next time */
2840 return mm->free_area_cache = addr;
2841 }
2842 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2843 mm->unmap_area = arch_unmap_area_topdown;
2844 }
2845 }
2846 -
2847 -static inline unsigned long brk_rnd(void)
2848 -{
2849 - unsigned long rnd = get_random_int();
2850 -
2851 - rnd = rnd << PAGE_SHIFT;
2852 - /* 8MB for 32bit, 256MB for 64bit */
2853 - if (TASK_IS_32BIT_ADDR)
2854 - rnd = rnd & 0x7ffffful;
2855 - else
2856 - rnd = rnd & 0xffffffful;
2857 -
2858 - return rnd;
2859 -}
2860 -
2861 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2862 -{
2863 - unsigned long base = mm->brk;
2864 - unsigned long ret;
2865 -
2866 - ret = PAGE_ALIGN(base + brk_rnd());
2867 -
2868 - if (ret < mm->brk)
2869 - return mm->brk;
2870 -
2871 - return ret;
2872 -}
2873 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2874 index 967d144..db12197 100644
2875 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2876 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2877 @@ -11,12 +11,14 @@
2878 #ifndef _ASM_PROC_CACHE_H
2879 #define _ASM_PROC_CACHE_H
2880
2881 +#include <linux/const.h>
2882 +
2883 /* L1 cache */
2884
2885 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2886 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2887 -#define L1_CACHE_BYTES 16 /* bytes per entry */
2888 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2889 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2890 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2891
2892 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2893 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2894 index bcb5df2..84fabd2 100644
2895 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2896 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2897 @@ -16,13 +16,15 @@
2898 #ifndef _ASM_PROC_CACHE_H
2899 #define _ASM_PROC_CACHE_H
2900
2901 +#include <linux/const.h>
2902 +
2903 /*
2904 * L1 cache
2905 */
2906 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2907 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2908 -#define L1_CACHE_BYTES 32 /* bytes per entry */
2909 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2910 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2911 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
2912
2913 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2914 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
2915 index 4ce7a01..449202a 100644
2916 --- a/arch/openrisc/include/asm/cache.h
2917 +++ b/arch/openrisc/include/asm/cache.h
2918 @@ -19,11 +19,13 @@
2919 #ifndef __ASM_OPENRISC_CACHE_H
2920 #define __ASM_OPENRISC_CACHE_H
2921
2922 +#include <linux/const.h>
2923 +
2924 /* FIXME: How can we replace these with values from the CPU...
2925 * they shouldn't be hard-coded!
2926 */
2927
2928 -#define L1_CACHE_BYTES 16
2929 #define L1_CACHE_SHIFT 4
2930 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2931
2932 #endif /* __ASM_OPENRISC_CACHE_H */
2933 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
2934 index 4054b31..a10c105 100644
2935 --- a/arch/parisc/include/asm/atomic.h
2936 +++ b/arch/parisc/include/asm/atomic.h
2937 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2938
2939 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2940
2941 +#define atomic64_read_unchecked(v) atomic64_read(v)
2942 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2943 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2944 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2945 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2946 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2947 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2948 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2949 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2950 +
2951 #endif /* !CONFIG_64BIT */
2952
2953
2954 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
2955 index 47f11c7..3420df2 100644
2956 --- a/arch/parisc/include/asm/cache.h
2957 +++ b/arch/parisc/include/asm/cache.h
2958 @@ -5,6 +5,7 @@
2959 #ifndef __ARCH_PARISC_CACHE_H
2960 #define __ARCH_PARISC_CACHE_H
2961
2962 +#include <linux/const.h>
2963
2964 /*
2965 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
2966 @@ -15,13 +16,13 @@
2967 * just ruin performance.
2968 */
2969 #ifdef CONFIG_PA20
2970 -#define L1_CACHE_BYTES 64
2971 #define L1_CACHE_SHIFT 6
2972 #else
2973 -#define L1_CACHE_BYTES 32
2974 #define L1_CACHE_SHIFT 5
2975 #endif
2976
2977 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2978 +
2979 #ifndef __ASSEMBLY__
2980
2981 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2982 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2983 index 19f6cb1..6c78cf2 100644
2984 --- a/arch/parisc/include/asm/elf.h
2985 +++ b/arch/parisc/include/asm/elf.h
2986 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
2987
2988 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2989
2990 +#ifdef CONFIG_PAX_ASLR
2991 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2992 +
2993 +#define PAX_DELTA_MMAP_LEN 16
2994 +#define PAX_DELTA_STACK_LEN 16
2995 +#endif
2996 +
2997 /* This yields a mask that user programs can use to figure out what
2998 instruction set this CPU supports. This could be done in user space,
2999 but it's not easy, and we've already done it here. */
3000 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3001 index 22dadeb..f6c2be4 100644
3002 --- a/arch/parisc/include/asm/pgtable.h
3003 +++ b/arch/parisc/include/asm/pgtable.h
3004 @@ -210,6 +210,17 @@ struct vm_area_struct;
3005 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3006 #define PAGE_COPY PAGE_EXECREAD
3007 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3008 +
3009 +#ifdef CONFIG_PAX_PAGEEXEC
3010 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3011 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3012 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3013 +#else
3014 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3015 +# define PAGE_COPY_NOEXEC PAGE_COPY
3016 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3017 +#endif
3018 +
3019 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3020 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3021 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3022 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3023 index 5e34ccf..672bc9c 100644
3024 --- a/arch/parisc/kernel/module.c
3025 +++ b/arch/parisc/kernel/module.c
3026 @@ -98,16 +98,38 @@
3027
3028 /* three functions to determine where in the module core
3029 * or init pieces the location is */
3030 +static inline int in_init_rx(struct module *me, void *loc)
3031 +{
3032 + return (loc >= me->module_init_rx &&
3033 + loc < (me->module_init_rx + me->init_size_rx));
3034 +}
3035 +
3036 +static inline int in_init_rw(struct module *me, void *loc)
3037 +{
3038 + return (loc >= me->module_init_rw &&
3039 + loc < (me->module_init_rw + me->init_size_rw));
3040 +}
3041 +
3042 static inline int in_init(struct module *me, void *loc)
3043 {
3044 - return (loc >= me->module_init &&
3045 - loc <= (me->module_init + me->init_size));
3046 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3047 +}
3048 +
3049 +static inline int in_core_rx(struct module *me, void *loc)
3050 +{
3051 + return (loc >= me->module_core_rx &&
3052 + loc < (me->module_core_rx + me->core_size_rx));
3053 +}
3054 +
3055 +static inline int in_core_rw(struct module *me, void *loc)
3056 +{
3057 + return (loc >= me->module_core_rw &&
3058 + loc < (me->module_core_rw + me->core_size_rw));
3059 }
3060
3061 static inline int in_core(struct module *me, void *loc)
3062 {
3063 - return (loc >= me->module_core &&
3064 - loc <= (me->module_core + me->core_size));
3065 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3066 }
3067
3068 static inline int in_local(struct module *me, void *loc)
3069 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3070 }
3071
3072 /* align things a bit */
3073 - me->core_size = ALIGN(me->core_size, 16);
3074 - me->arch.got_offset = me->core_size;
3075 - me->core_size += gots * sizeof(struct got_entry);
3076 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3077 + me->arch.got_offset = me->core_size_rw;
3078 + me->core_size_rw += gots * sizeof(struct got_entry);
3079
3080 - me->core_size = ALIGN(me->core_size, 16);
3081 - me->arch.fdesc_offset = me->core_size;
3082 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3083 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3084 + me->arch.fdesc_offset = me->core_size_rw;
3085 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3086
3087 me->arch.got_max = gots;
3088 me->arch.fdesc_max = fdescs;
3089 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3090
3091 BUG_ON(value == 0);
3092
3093 - got = me->module_core + me->arch.got_offset;
3094 + got = me->module_core_rw + me->arch.got_offset;
3095 for (i = 0; got[i].addr; i++)
3096 if (got[i].addr == value)
3097 goto out;
3098 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3099 #ifdef CONFIG_64BIT
3100 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3101 {
3102 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3103 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3104
3105 if (!value) {
3106 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3107 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3108
3109 /* Create new one */
3110 fdesc->addr = value;
3111 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3112 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3113 return (Elf_Addr)fdesc;
3114 }
3115 #endif /* CONFIG_64BIT */
3116 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3117
3118 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3119 end = table + sechdrs[me->arch.unwind_section].sh_size;
3120 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3121 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3122
3123 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3124 me->arch.unwind_section, table, end, gp);
3125 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3126 index c9b9322..02d8940 100644
3127 --- a/arch/parisc/kernel/sys_parisc.c
3128 +++ b/arch/parisc/kernel/sys_parisc.c
3129 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3130 /* At this point: (!vma || addr < vma->vm_end). */
3131 if (TASK_SIZE - len < addr)
3132 return -ENOMEM;
3133 - if (!vma || addr + len <= vma->vm_start)
3134 + if (check_heap_stack_gap(vma, addr, len))
3135 return addr;
3136 addr = vma->vm_end;
3137 }
3138 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3139 /* At this point: (!vma || addr < vma->vm_end). */
3140 if (TASK_SIZE - len < addr)
3141 return -ENOMEM;
3142 - if (!vma || addr + len <= vma->vm_start)
3143 + if (check_heap_stack_gap(vma, addr, len))
3144 return addr;
3145 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3146 if (addr < vma->vm_end) /* handle wraparound */
3147 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3148 if (flags & MAP_FIXED)
3149 return addr;
3150 if (!addr)
3151 - addr = TASK_UNMAPPED_BASE;
3152 + addr = current->mm->mmap_base;
3153
3154 if (filp) {
3155 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3156 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3157 index f19e660..414fe24 100644
3158 --- a/arch/parisc/kernel/traps.c
3159 +++ b/arch/parisc/kernel/traps.c
3160 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3161
3162 down_read(&current->mm->mmap_sem);
3163 vma = find_vma(current->mm,regs->iaoq[0]);
3164 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3165 - && (vma->vm_flags & VM_EXEC)) {
3166 -
3167 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3168 fault_address = regs->iaoq[0];
3169 fault_space = regs->iasq[0];
3170
3171 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3172 index 18162ce..94de376 100644
3173 --- a/arch/parisc/mm/fault.c
3174 +++ b/arch/parisc/mm/fault.c
3175 @@ -15,6 +15,7 @@
3176 #include <linux/sched.h>
3177 #include <linux/interrupt.h>
3178 #include <linux/module.h>
3179 +#include <linux/unistd.h>
3180
3181 #include <asm/uaccess.h>
3182 #include <asm/traps.h>
3183 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3184 static unsigned long
3185 parisc_acctyp(unsigned long code, unsigned int inst)
3186 {
3187 - if (code == 6 || code == 16)
3188 + if (code == 6 || code == 7 || code == 16)
3189 return VM_EXEC;
3190
3191 switch (inst & 0xf0000000) {
3192 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3193 }
3194 #endif
3195
3196 +#ifdef CONFIG_PAX_PAGEEXEC
3197 +/*
3198 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3199 + *
3200 + * returns 1 when task should be killed
3201 + * 2 when rt_sigreturn trampoline was detected
3202 + * 3 when unpatched PLT trampoline was detected
3203 + */
3204 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3205 +{
3206 +
3207 +#ifdef CONFIG_PAX_EMUPLT
3208 + int err;
3209 +
3210 + do { /* PaX: unpatched PLT emulation */
3211 + unsigned int bl, depwi;
3212 +
3213 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3214 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3215 +
3216 + if (err)
3217 + break;
3218 +
3219 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3220 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3221 +
3222 + err = get_user(ldw, (unsigned int *)addr);
3223 + err |= get_user(bv, (unsigned int *)(addr+4));
3224 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3225 +
3226 + if (err)
3227 + break;
3228 +
3229 + if (ldw == 0x0E801096U &&
3230 + bv == 0xEAC0C000U &&
3231 + ldw2 == 0x0E881095U)
3232 + {
3233 + unsigned int resolver, map;
3234 +
3235 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3236 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3237 + if (err)
3238 + break;
3239 +
3240 + regs->gr[20] = instruction_pointer(regs)+8;
3241 + regs->gr[21] = map;
3242 + regs->gr[22] = resolver;
3243 + regs->iaoq[0] = resolver | 3UL;
3244 + regs->iaoq[1] = regs->iaoq[0] + 4;
3245 + return 3;
3246 + }
3247 + }
3248 + } while (0);
3249 +#endif
3250 +
3251 +#ifdef CONFIG_PAX_EMUTRAMP
3252 +
3253 +#ifndef CONFIG_PAX_EMUSIGRT
3254 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3255 + return 1;
3256 +#endif
3257 +
3258 + do { /* PaX: rt_sigreturn emulation */
3259 + unsigned int ldi1, ldi2, bel, nop;
3260 +
3261 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3262 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3263 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3264 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3265 +
3266 + if (err)
3267 + break;
3268 +
3269 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3270 + ldi2 == 0x3414015AU &&
3271 + bel == 0xE4008200U &&
3272 + nop == 0x08000240U)
3273 + {
3274 + regs->gr[25] = (ldi1 & 2) >> 1;
3275 + regs->gr[20] = __NR_rt_sigreturn;
3276 + regs->gr[31] = regs->iaoq[1] + 16;
3277 + regs->sr[0] = regs->iasq[1];
3278 + regs->iaoq[0] = 0x100UL;
3279 + regs->iaoq[1] = regs->iaoq[0] + 4;
3280 + regs->iasq[0] = regs->sr[2];
3281 + regs->iasq[1] = regs->sr[2];
3282 + return 2;
3283 + }
3284 + } while (0);
3285 +#endif
3286 +
3287 + return 1;
3288 +}
3289 +
3290 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3291 +{
3292 + unsigned long i;
3293 +
3294 + printk(KERN_ERR "PAX: bytes at PC: ");
3295 + for (i = 0; i < 5; i++) {
3296 + unsigned int c;
3297 + if (get_user(c, (unsigned int *)pc+i))
3298 + printk(KERN_CONT "???????? ");
3299 + else
3300 + printk(KERN_CONT "%08x ", c);
3301 + }
3302 + printk("\n");
3303 +}
3304 +#endif
3305 +
3306 int fixup_exception(struct pt_regs *regs)
3307 {
3308 const struct exception_table_entry *fix;
3309 @@ -192,8 +303,33 @@ good_area:
3310
3311 acc_type = parisc_acctyp(code,regs->iir);
3312
3313 - if ((vma->vm_flags & acc_type) != acc_type)
3314 + if ((vma->vm_flags & acc_type) != acc_type) {
3315 +
3316 +#ifdef CONFIG_PAX_PAGEEXEC
3317 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3318 + (address & ~3UL) == instruction_pointer(regs))
3319 + {
3320 + up_read(&mm->mmap_sem);
3321 + switch (pax_handle_fetch_fault(regs)) {
3322 +
3323 +#ifdef CONFIG_PAX_EMUPLT
3324 + case 3:
3325 + return;
3326 +#endif
3327 +
3328 +#ifdef CONFIG_PAX_EMUTRAMP
3329 + case 2:
3330 + return;
3331 +#endif
3332 +
3333 + }
3334 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3335 + do_group_exit(SIGKILL);
3336 + }
3337 +#endif
3338 +
3339 goto bad_area;
3340 + }
3341
3342 /*
3343 * If for any reason at all we couldn't handle the fault, make
3344 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3345 index 02e41b5..ec6e26c 100644
3346 --- a/arch/powerpc/include/asm/atomic.h
3347 +++ b/arch/powerpc/include/asm/atomic.h
3348 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3349
3350 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3351
3352 +#define atomic64_read_unchecked(v) atomic64_read(v)
3353 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3354 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3355 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3356 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3357 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3358 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3359 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3360 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3361 +
3362 #endif /* __powerpc64__ */
3363
3364 #endif /* __KERNEL__ */
3365 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3366 index 4b50941..5605819 100644
3367 --- a/arch/powerpc/include/asm/cache.h
3368 +++ b/arch/powerpc/include/asm/cache.h
3369 @@ -3,6 +3,7 @@
3370
3371 #ifdef __KERNEL__
3372
3373 +#include <linux/const.h>
3374
3375 /* bytes per L1 cache line */
3376 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3377 @@ -22,7 +23,7 @@
3378 #define L1_CACHE_SHIFT 7
3379 #endif
3380
3381 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3382 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3383
3384 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3385
3386 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3387 index 3bf9cca..e7457d0 100644
3388 --- a/arch/powerpc/include/asm/elf.h
3389 +++ b/arch/powerpc/include/asm/elf.h
3390 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3391 the loader. We need to make sure that it is out of the way of the program
3392 that it will "exec", and that there is sufficient room for the brk. */
3393
3394 -extern unsigned long randomize_et_dyn(unsigned long base);
3395 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3396 +#define ELF_ET_DYN_BASE (0x20000000)
3397 +
3398 +#ifdef CONFIG_PAX_ASLR
3399 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3400 +
3401 +#ifdef __powerpc64__
3402 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3403 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3404 +#else
3405 +#define PAX_DELTA_MMAP_LEN 15
3406 +#define PAX_DELTA_STACK_LEN 15
3407 +#endif
3408 +#endif
3409
3410 /*
3411 * Our registers are always unsigned longs, whether we're a 32 bit
3412 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3413 (0x7ff >> (PAGE_SHIFT - 12)) : \
3414 (0x3ffff >> (PAGE_SHIFT - 12)))
3415
3416 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3417 -#define arch_randomize_brk arch_randomize_brk
3418 -
3419 #endif /* __KERNEL__ */
3420
3421 /*
3422 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3423 index bca8fdc..61e9580 100644
3424 --- a/arch/powerpc/include/asm/kmap_types.h
3425 +++ b/arch/powerpc/include/asm/kmap_types.h
3426 @@ -27,6 +27,7 @@ enum km_type {
3427 KM_PPC_SYNC_PAGE,
3428 KM_PPC_SYNC_ICACHE,
3429 KM_KDB,
3430 + KM_CLEARPAGE,
3431 KM_TYPE_NR
3432 };
3433
3434 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3435 index d4a7f64..451de1c 100644
3436 --- a/arch/powerpc/include/asm/mman.h
3437 +++ b/arch/powerpc/include/asm/mman.h
3438 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3439 }
3440 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3441
3442 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3443 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3444 {
3445 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3446 }
3447 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3448 index f072e97..b436dee 100644
3449 --- a/arch/powerpc/include/asm/page.h
3450 +++ b/arch/powerpc/include/asm/page.h
3451 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3452 * and needs to be executable. This means the whole heap ends
3453 * up being executable.
3454 */
3455 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3456 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3457 +#define VM_DATA_DEFAULT_FLAGS32 \
3458 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3459 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3460
3461 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3462 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3463 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3464 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3465 #endif
3466
3467 +#define ktla_ktva(addr) (addr)
3468 +#define ktva_ktla(addr) (addr)
3469 +
3470 /*
3471 * Use the top bit of the higher-level page table entries to indicate whether
3472 * the entries we point to contain hugepages. This works because we know that
3473 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3474 index fed85e6..da5c71b 100644
3475 --- a/arch/powerpc/include/asm/page_64.h
3476 +++ b/arch/powerpc/include/asm/page_64.h
3477 @@ -146,15 +146,18 @@ do { \
3478 * stack by default, so in the absence of a PT_GNU_STACK program header
3479 * we turn execute permission off.
3480 */
3481 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3482 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3483 +#define VM_STACK_DEFAULT_FLAGS32 \
3484 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3485 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3486
3487 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3488 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3489
3490 +#ifndef CONFIG_PAX_PAGEEXEC
3491 #define VM_STACK_DEFAULT_FLAGS \
3492 (is_32bit_task() ? \
3493 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3494 +#endif
3495
3496 #include <asm-generic/getorder.h>
3497
3498 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3499 index 2e0e411..7899c68 100644
3500 --- a/arch/powerpc/include/asm/pgtable.h
3501 +++ b/arch/powerpc/include/asm/pgtable.h
3502 @@ -2,6 +2,7 @@
3503 #define _ASM_POWERPC_PGTABLE_H
3504 #ifdef __KERNEL__
3505
3506 +#include <linux/const.h>
3507 #ifndef __ASSEMBLY__
3508 #include <asm/processor.h> /* For TASK_SIZE */
3509 #include <asm/mmu.h>
3510 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3511 index 4aad413..85d86bf 100644
3512 --- a/arch/powerpc/include/asm/pte-hash32.h
3513 +++ b/arch/powerpc/include/asm/pte-hash32.h
3514 @@ -21,6 +21,7 @@
3515 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3516 #define _PAGE_USER 0x004 /* usermode access allowed */
3517 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3518 +#define _PAGE_EXEC _PAGE_GUARDED
3519 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3520 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3521 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3522 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3523 index 7fdc2c0..e47a9b02d3 100644
3524 --- a/arch/powerpc/include/asm/reg.h
3525 +++ b/arch/powerpc/include/asm/reg.h
3526 @@ -212,6 +212,7 @@
3527 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3528 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3529 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3530 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3531 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3532 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3533 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3534 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3535 index c377457..3c69fbc 100644
3536 --- a/arch/powerpc/include/asm/system.h
3537 +++ b/arch/powerpc/include/asm/system.h
3538 @@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3539 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3540 #endif
3541
3542 -extern unsigned long arch_align_stack(unsigned long sp);
3543 +#define arch_align_stack(x) ((x) & ~0xfUL)
3544
3545 /* Used in very early kernel initialization. */
3546 extern unsigned long reloc_offset(void);
3547 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3548 index bd0fb84..a42a14b 100644
3549 --- a/arch/powerpc/include/asm/uaccess.h
3550 +++ b/arch/powerpc/include/asm/uaccess.h
3551 @@ -13,6 +13,8 @@
3552 #define VERIFY_READ 0
3553 #define VERIFY_WRITE 1
3554
3555 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3556 +
3557 /*
3558 * The fs value determines whether argument validity checking should be
3559 * performed or not. If get_fs() == USER_DS, checking is performed, with
3560 @@ -327,52 +329,6 @@ do { \
3561 extern unsigned long __copy_tofrom_user(void __user *to,
3562 const void __user *from, unsigned long size);
3563
3564 -#ifndef __powerpc64__
3565 -
3566 -static inline unsigned long copy_from_user(void *to,
3567 - const void __user *from, unsigned long n)
3568 -{
3569 - unsigned long over;
3570 -
3571 - if (access_ok(VERIFY_READ, from, n))
3572 - return __copy_tofrom_user((__force void __user *)to, from, n);
3573 - if ((unsigned long)from < TASK_SIZE) {
3574 - over = (unsigned long)from + n - TASK_SIZE;
3575 - return __copy_tofrom_user((__force void __user *)to, from,
3576 - n - over) + over;
3577 - }
3578 - return n;
3579 -}
3580 -
3581 -static inline unsigned long copy_to_user(void __user *to,
3582 - const void *from, unsigned long n)
3583 -{
3584 - unsigned long over;
3585 -
3586 - if (access_ok(VERIFY_WRITE, to, n))
3587 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3588 - if ((unsigned long)to < TASK_SIZE) {
3589 - over = (unsigned long)to + n - TASK_SIZE;
3590 - return __copy_tofrom_user(to, (__force void __user *)from,
3591 - n - over) + over;
3592 - }
3593 - return n;
3594 -}
3595 -
3596 -#else /* __powerpc64__ */
3597 -
3598 -#define __copy_in_user(to, from, size) \
3599 - __copy_tofrom_user((to), (from), (size))
3600 -
3601 -extern unsigned long copy_from_user(void *to, const void __user *from,
3602 - unsigned long n);
3603 -extern unsigned long copy_to_user(void __user *to, const void *from,
3604 - unsigned long n);
3605 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3606 - unsigned long n);
3607 -
3608 -#endif /* __powerpc64__ */
3609 -
3610 static inline unsigned long __copy_from_user_inatomic(void *to,
3611 const void __user *from, unsigned long n)
3612 {
3613 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3614 if (ret == 0)
3615 return 0;
3616 }
3617 +
3618 + if (!__builtin_constant_p(n))
3619 + check_object_size(to, n, false);
3620 +
3621 return __copy_tofrom_user((__force void __user *)to, from, n);
3622 }
3623
3624 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3625 if (ret == 0)
3626 return 0;
3627 }
3628 +
3629 + if (!__builtin_constant_p(n))
3630 + check_object_size(from, n, true);
3631 +
3632 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3633 }
3634
3635 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3636 return __copy_to_user_inatomic(to, from, size);
3637 }
3638
3639 +#ifndef __powerpc64__
3640 +
3641 +static inline unsigned long __must_check copy_from_user(void *to,
3642 + const void __user *from, unsigned long n)
3643 +{
3644 + unsigned long over;
3645 +
3646 + if ((long)n < 0)
3647 + return n;
3648 +
3649 + if (access_ok(VERIFY_READ, from, n)) {
3650 + if (!__builtin_constant_p(n))
3651 + check_object_size(to, n, false);
3652 + return __copy_tofrom_user((__force void __user *)to, from, n);
3653 + }
3654 + if ((unsigned long)from < TASK_SIZE) {
3655 + over = (unsigned long)from + n - TASK_SIZE;
3656 + if (!__builtin_constant_p(n - over))
3657 + check_object_size(to, n - over, false);
3658 + return __copy_tofrom_user((__force void __user *)to, from,
3659 + n - over) + over;
3660 + }
3661 + return n;
3662 +}
3663 +
3664 +static inline unsigned long __must_check copy_to_user(void __user *to,
3665 + const void *from, unsigned long n)
3666 +{
3667 + unsigned long over;
3668 +
3669 + if ((long)n < 0)
3670 + return n;
3671 +
3672 + if (access_ok(VERIFY_WRITE, to, n)) {
3673 + if (!__builtin_constant_p(n))
3674 + check_object_size(from, n, true);
3675 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3676 + }
3677 + if ((unsigned long)to < TASK_SIZE) {
3678 + over = (unsigned long)to + n - TASK_SIZE;
3679 + if (!__builtin_constant_p(n))
3680 + check_object_size(from, n - over, true);
3681 + return __copy_tofrom_user(to, (__force void __user *)from,
3682 + n - over) + over;
3683 + }
3684 + return n;
3685 +}
3686 +
3687 +#else /* __powerpc64__ */
3688 +
3689 +#define __copy_in_user(to, from, size) \
3690 + __copy_tofrom_user((to), (from), (size))
3691 +
3692 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3693 +{
3694 + if ((long)n < 0 || n > INT_MAX)
3695 + return n;
3696 +
3697 + if (!__builtin_constant_p(n))
3698 + check_object_size(to, n, false);
3699 +
3700 + if (likely(access_ok(VERIFY_READ, from, n)))
3701 + n = __copy_from_user(to, from, n);
3702 + else
3703 + memset(to, 0, n);
3704 + return n;
3705 +}
3706 +
3707 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3708 +{
3709 + if ((long)n < 0 || n > INT_MAX)
3710 + return n;
3711 +
3712 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3713 + if (!__builtin_constant_p(n))
3714 + check_object_size(from, n, true);
3715 + n = __copy_to_user(to, from, n);
3716 + }
3717 + return n;
3718 +}
3719 +
3720 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3721 + unsigned long n);
3722 +
3723 +#endif /* __powerpc64__ */
3724 +
3725 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3726
3727 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3728 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3729 index 429983c..7af363b 100644
3730 --- a/arch/powerpc/kernel/exceptions-64e.S
3731 +++ b/arch/powerpc/kernel/exceptions-64e.S
3732 @@ -587,6 +587,7 @@ storage_fault_common:
3733 std r14,_DAR(r1)
3734 std r15,_DSISR(r1)
3735 addi r3,r1,STACK_FRAME_OVERHEAD
3736 + bl .save_nvgprs
3737 mr r4,r14
3738 mr r5,r15
3739 ld r14,PACA_EXGEN+EX_R14(r13)
3740 @@ -596,8 +597,7 @@ storage_fault_common:
3741 cmpdi r3,0
3742 bne- 1f
3743 b .ret_from_except_lite
3744 -1: bl .save_nvgprs
3745 - mr r5,r3
3746 +1: mr r5,r3
3747 addi r3,r1,STACK_FRAME_OVERHEAD
3748 ld r4,_DAR(r1)
3749 bl .bad_page_fault
3750 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3751 index 15c5a4f..22a4000 100644
3752 --- a/arch/powerpc/kernel/exceptions-64s.S
3753 +++ b/arch/powerpc/kernel/exceptions-64s.S
3754 @@ -1004,10 +1004,10 @@ handle_page_fault:
3755 11: ld r4,_DAR(r1)
3756 ld r5,_DSISR(r1)
3757 addi r3,r1,STACK_FRAME_OVERHEAD
3758 + bl .save_nvgprs
3759 bl .do_page_fault
3760 cmpdi r3,0
3761 beq+ 13f
3762 - bl .save_nvgprs
3763 mr r5,r3
3764 addi r3,r1,STACK_FRAME_OVERHEAD
3765 lwz r4,_DAR(r1)
3766 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3767 index 01e2877..a1ba360 100644
3768 --- a/arch/powerpc/kernel/irq.c
3769 +++ b/arch/powerpc/kernel/irq.c
3770 @@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3771 host->ops = ops;
3772 host->of_node = of_node_get(of_node);
3773
3774 - if (host->ops->match == NULL)
3775 - host->ops->match = default_irq_host_match;
3776 -
3777 raw_spin_lock_irqsave(&irq_big_lock, flags);
3778
3779 /* If it's a legacy controller, check for duplicates and
3780 @@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3781 */
3782 raw_spin_lock_irqsave(&irq_big_lock, flags);
3783 list_for_each_entry(h, &irq_hosts, link)
3784 - if (h->ops->match(h, node)) {
3785 + if (h->ops->match) {
3786 + if (h->ops->match(h, node)) {
3787 + found = h;
3788 + break;
3789 + }
3790 + } else if (default_irq_host_match(h, node)) {
3791 found = h;
3792 break;
3793 }
3794 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3795 index 0b6d796..d760ddb 100644
3796 --- a/arch/powerpc/kernel/module_32.c
3797 +++ b/arch/powerpc/kernel/module_32.c
3798 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3799 me->arch.core_plt_section = i;
3800 }
3801 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3802 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3803 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3804 return -ENOEXEC;
3805 }
3806
3807 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3808
3809 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3810 /* Init, or core PLT? */
3811 - if (location >= mod->module_core
3812 - && location < mod->module_core + mod->core_size)
3813 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3814 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3815 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3816 - else
3817 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3818 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3819 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3820 + else {
3821 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3822 + return ~0UL;
3823 + }
3824
3825 /* Find this entry, or if that fails, the next avail. entry */
3826 while (entry->jump[0]) {
3827 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3828 index d817ab0..b23b18e 100644
3829 --- a/arch/powerpc/kernel/process.c
3830 +++ b/arch/powerpc/kernel/process.c
3831 @@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
3832 * Lookup NIP late so we have the best change of getting the
3833 * above info out without failing
3834 */
3835 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3836 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3837 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3838 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3839 #endif
3840 show_stack(current, (unsigned long *) regs->gpr[1]);
3841 if (!user_mode(regs))
3842 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3843 newsp = stack[0];
3844 ip = stack[STACK_FRAME_LR_SAVE];
3845 if (!firstframe || ip != lr) {
3846 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3847 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3848 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3849 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3850 - printk(" (%pS)",
3851 + printk(" (%pA)",
3852 (void *)current->ret_stack[curr_frame].ret);
3853 curr_frame--;
3854 }
3855 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3856 struct pt_regs *regs = (struct pt_regs *)
3857 (sp + STACK_FRAME_OVERHEAD);
3858 lr = regs->link;
3859 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3860 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3861 regs->trap, (void *)regs->nip, (void *)lr);
3862 firstframe = 1;
3863 }
3864 @@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
3865 }
3866
3867 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3868 -
3869 -unsigned long arch_align_stack(unsigned long sp)
3870 -{
3871 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3872 - sp -= get_random_int() & ~PAGE_MASK;
3873 - return sp & ~0xf;
3874 -}
3875 -
3876 -static inline unsigned long brk_rnd(void)
3877 -{
3878 - unsigned long rnd = 0;
3879 -
3880 - /* 8MB for 32bit, 1GB for 64bit */
3881 - if (is_32bit_task())
3882 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3883 - else
3884 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3885 -
3886 - return rnd << PAGE_SHIFT;
3887 -}
3888 -
3889 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3890 -{
3891 - unsigned long base = mm->brk;
3892 - unsigned long ret;
3893 -
3894 -#ifdef CONFIG_PPC_STD_MMU_64
3895 - /*
3896 - * If we are using 1TB segments and we are allowed to randomise
3897 - * the heap, we can put it above 1TB so it is backed by a 1TB
3898 - * segment. Otherwise the heap will be in the bottom 1TB
3899 - * which always uses 256MB segments and this may result in a
3900 - * performance penalty.
3901 - */
3902 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3903 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3904 -#endif
3905 -
3906 - ret = PAGE_ALIGN(base + brk_rnd());
3907 -
3908 - if (ret < mm->brk)
3909 - return mm->brk;
3910 -
3911 - return ret;
3912 -}
3913 -
3914 -unsigned long randomize_et_dyn(unsigned long base)
3915 -{
3916 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3917 -
3918 - if (ret < base)
3919 - return base;
3920 -
3921 - return ret;
3922 -}
3923 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3924 index 836a5a1..27289a3 100644
3925 --- a/arch/powerpc/kernel/signal_32.c
3926 +++ b/arch/powerpc/kernel/signal_32.c
3927 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3928 /* Save user registers on the stack */
3929 frame = &rt_sf->uc.uc_mcontext;
3930 addr = frame;
3931 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3932 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3933 if (save_user_regs(regs, frame, 0, 1))
3934 goto badframe;
3935 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3936 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3937 index a50b5ec..547078a 100644
3938 --- a/arch/powerpc/kernel/signal_64.c
3939 +++ b/arch/powerpc/kernel/signal_64.c
3940 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3941 current->thread.fpscr.val = 0;
3942
3943 /* Set up to return from userspace. */
3944 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3945 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3946 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3947 } else {
3948 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3949 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3950 index c091527..5592625 100644
3951 --- a/arch/powerpc/kernel/traps.c
3952 +++ b/arch/powerpc/kernel/traps.c
3953 @@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
3954 return flags;
3955 }
3956
3957 +extern void gr_handle_kernel_exploit(void);
3958 +
3959 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3960 int signr)
3961 {
3962 @@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3963 panic("Fatal exception in interrupt");
3964 if (panic_on_oops)
3965 panic("Fatal exception");
3966 +
3967 + gr_handle_kernel_exploit();
3968 +
3969 do_exit(signr);
3970 }
3971
3972 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3973 index 7d14bb6..1305601 100644
3974 --- a/arch/powerpc/kernel/vdso.c
3975 +++ b/arch/powerpc/kernel/vdso.c
3976 @@ -35,6 +35,7 @@
3977 #include <asm/firmware.h>
3978 #include <asm/vdso.h>
3979 #include <asm/vdso_datapage.h>
3980 +#include <asm/mman.h>
3981
3982 #include "setup.h"
3983
3984 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3985 vdso_base = VDSO32_MBASE;
3986 #endif
3987
3988 - current->mm->context.vdso_base = 0;
3989 + current->mm->context.vdso_base = ~0UL;
3990
3991 /* vDSO has a problem and was disabled, just don't "enable" it for the
3992 * process
3993 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3994 vdso_base = get_unmapped_area(NULL, vdso_base,
3995 (vdso_pages << PAGE_SHIFT) +
3996 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3997 - 0, 0);
3998 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3999 if (IS_ERR_VALUE(vdso_base)) {
4000 rc = vdso_base;
4001 goto fail_mmapsem;
4002 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4003 index 5eea6f3..5d10396 100644
4004 --- a/arch/powerpc/lib/usercopy_64.c
4005 +++ b/arch/powerpc/lib/usercopy_64.c
4006 @@ -9,22 +9,6 @@
4007 #include <linux/module.h>
4008 #include <asm/uaccess.h>
4009
4010 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4011 -{
4012 - if (likely(access_ok(VERIFY_READ, from, n)))
4013 - n = __copy_from_user(to, from, n);
4014 - else
4015 - memset(to, 0, n);
4016 - return n;
4017 -}
4018 -
4019 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4020 -{
4021 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4022 - n = __copy_to_user(to, from, n);
4023 - return n;
4024 -}
4025 -
4026 unsigned long copy_in_user(void __user *to, const void __user *from,
4027 unsigned long n)
4028 {
4029 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4030 return n;
4031 }
4032
4033 -EXPORT_SYMBOL(copy_from_user);
4034 -EXPORT_SYMBOL(copy_to_user);
4035 EXPORT_SYMBOL(copy_in_user);
4036
4037 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4038 index 2f0d1b0..36fb5cc 100644
4039 --- a/arch/powerpc/mm/fault.c
4040 +++ b/arch/powerpc/mm/fault.c
4041 @@ -32,6 +32,10 @@
4042 #include <linux/perf_event.h>
4043 #include <linux/magic.h>
4044 #include <linux/ratelimit.h>
4045 +#include <linux/slab.h>
4046 +#include <linux/pagemap.h>
4047 +#include <linux/compiler.h>
4048 +#include <linux/unistd.h>
4049
4050 #include <asm/firmware.h>
4051 #include <asm/page.h>
4052 @@ -43,6 +47,7 @@
4053 #include <asm/tlbflush.h>
4054 #include <asm/siginfo.h>
4055 #include <mm/mmu_decl.h>
4056 +#include <asm/ptrace.h>
4057
4058 #include "icswx.h"
4059
4060 @@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4061 }
4062 #endif
4063
4064 +#ifdef CONFIG_PAX_PAGEEXEC
4065 +/*
4066 + * PaX: decide what to do with offenders (regs->nip = fault address)
4067 + *
4068 + * returns 1 when task should be killed
4069 + */
4070 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4071 +{
4072 + return 1;
4073 +}
4074 +
4075 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4076 +{
4077 + unsigned long i;
4078 +
4079 + printk(KERN_ERR "PAX: bytes at PC: ");
4080 + for (i = 0; i < 5; i++) {
4081 + unsigned int c;
4082 + if (get_user(c, (unsigned int __user *)pc+i))
4083 + printk(KERN_CONT "???????? ");
4084 + else
4085 + printk(KERN_CONT "%08x ", c);
4086 + }
4087 + printk("\n");
4088 +}
4089 +#endif
4090 +
4091 /*
4092 * Check whether the instruction at regs->nip is a store using
4093 * an update addressing form which will update r1.
4094 @@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4095 * indicate errors in DSISR but can validly be set in SRR1.
4096 */
4097 if (trap == 0x400)
4098 - error_code &= 0x48200000;
4099 + error_code &= 0x58200000;
4100 else
4101 is_write = error_code & DSISR_ISSTORE;
4102 #else
4103 @@ -276,7 +308,7 @@ good_area:
4104 * "undefined". Of those that can be set, this is the only
4105 * one which seems bad.
4106 */
4107 - if (error_code & 0x10000000)
4108 + if (error_code & DSISR_GUARDED)
4109 /* Guarded storage error. */
4110 goto bad_area;
4111 #endif /* CONFIG_8xx */
4112 @@ -291,7 +323,7 @@ good_area:
4113 * processors use the same I/D cache coherency mechanism
4114 * as embedded.
4115 */
4116 - if (error_code & DSISR_PROTFAULT)
4117 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4118 goto bad_area;
4119 #endif /* CONFIG_PPC_STD_MMU */
4120
4121 @@ -360,6 +392,23 @@ bad_area:
4122 bad_area_nosemaphore:
4123 /* User mode accesses cause a SIGSEGV */
4124 if (user_mode(regs)) {
4125 +
4126 +#ifdef CONFIG_PAX_PAGEEXEC
4127 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4128 +#ifdef CONFIG_PPC_STD_MMU
4129 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4130 +#else
4131 + if (is_exec && regs->nip == address) {
4132 +#endif
4133 + switch (pax_handle_fetch_fault(regs)) {
4134 + }
4135 +
4136 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4137 + do_group_exit(SIGKILL);
4138 + }
4139 + }
4140 +#endif
4141 +
4142 _exception(SIGSEGV, regs, code, address);
4143 return 0;
4144 }
4145 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4146 index 67a42ed..1c7210c 100644
4147 --- a/arch/powerpc/mm/mmap_64.c
4148 +++ b/arch/powerpc/mm/mmap_64.c
4149 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4150 */
4151 if (mmap_is_legacy()) {
4152 mm->mmap_base = TASK_UNMAPPED_BASE;
4153 +
4154 +#ifdef CONFIG_PAX_RANDMMAP
4155 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4156 + mm->mmap_base += mm->delta_mmap;
4157 +#endif
4158 +
4159 mm->get_unmapped_area = arch_get_unmapped_area;
4160 mm->unmap_area = arch_unmap_area;
4161 } else {
4162 mm->mmap_base = mmap_base();
4163 +
4164 +#ifdef CONFIG_PAX_RANDMMAP
4165 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4166 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4167 +#endif
4168 +
4169 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4170 mm->unmap_area = arch_unmap_area_topdown;
4171 }
4172 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4173 index 73709f7..6b90313 100644
4174 --- a/arch/powerpc/mm/slice.c
4175 +++ b/arch/powerpc/mm/slice.c
4176 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4177 if ((mm->task_size - len) < addr)
4178 return 0;
4179 vma = find_vma(mm, addr);
4180 - return (!vma || (addr + len) <= vma->vm_start);
4181 + return check_heap_stack_gap(vma, addr, len);
4182 }
4183
4184 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4185 @@ -256,7 +256,7 @@ full_search:
4186 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4187 continue;
4188 }
4189 - if (!vma || addr + len <= vma->vm_start) {
4190 + if (check_heap_stack_gap(vma, addr, len)) {
4191 /*
4192 * Remember the place where we stopped the search:
4193 */
4194 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4195 }
4196 }
4197
4198 - addr = mm->mmap_base;
4199 - while (addr > len) {
4200 + if (mm->mmap_base < len)
4201 + addr = -ENOMEM;
4202 + else
4203 + addr = mm->mmap_base - len;
4204 +
4205 + while (!IS_ERR_VALUE(addr)) {
4206 /* Go down by chunk size */
4207 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4208 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4209
4210 /* Check for hit with different page size */
4211 mask = slice_range_to_mask(addr, len);
4212 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4213 * return with success:
4214 */
4215 vma = find_vma(mm, addr);
4216 - if (!vma || (addr + len) <= vma->vm_start) {
4217 + if (check_heap_stack_gap(vma, addr, len)) {
4218 /* remember the address as a hint for next time */
4219 if (use_cache)
4220 mm->free_area_cache = addr;
4221 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4222 mm->cached_hole_size = vma->vm_start - addr;
4223
4224 /* try just below the current vma->vm_start */
4225 - addr = vma->vm_start;
4226 + addr = skip_heap_stack_gap(vma, len);
4227 }
4228
4229 /*
4230 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4231 if (fixed && addr > (mm->task_size - len))
4232 return -EINVAL;
4233
4234 +#ifdef CONFIG_PAX_RANDMMAP
4235 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4236 + addr = 0;
4237 +#endif
4238 +
4239 /* If hint, make sure it matches our alignment restrictions */
4240 if (!fixed && addr) {
4241 addr = _ALIGN_UP(addr, 1ul << pshift);
4242 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4243 index 8517d2a..d2738d4 100644
4244 --- a/arch/s390/include/asm/atomic.h
4245 +++ b/arch/s390/include/asm/atomic.h
4246 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4247 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4248 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4249
4250 +#define atomic64_read_unchecked(v) atomic64_read(v)
4251 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4252 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4253 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4254 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4255 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4256 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4257 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4258 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4259 +
4260 #define smp_mb__before_atomic_dec() smp_mb()
4261 #define smp_mb__after_atomic_dec() smp_mb()
4262 #define smp_mb__before_atomic_inc() smp_mb()
4263 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4264 index 2a30d5a..5e5586f 100644
4265 --- a/arch/s390/include/asm/cache.h
4266 +++ b/arch/s390/include/asm/cache.h
4267 @@ -11,8 +11,10 @@
4268 #ifndef __ARCH_S390_CACHE_H
4269 #define __ARCH_S390_CACHE_H
4270
4271 -#define L1_CACHE_BYTES 256
4272 +#include <linux/const.h>
4273 +
4274 #define L1_CACHE_SHIFT 8
4275 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4276 #define NET_SKB_PAD 32
4277
4278 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4279 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4280 index 547f1a6..0b22b53 100644
4281 --- a/arch/s390/include/asm/elf.h
4282 +++ b/arch/s390/include/asm/elf.h
4283 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4284 the loader. We need to make sure that it is out of the way of the program
4285 that it will "exec", and that there is sufficient room for the brk. */
4286
4287 -extern unsigned long randomize_et_dyn(unsigned long base);
4288 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4289 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4290 +
4291 +#ifdef CONFIG_PAX_ASLR
4292 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4293 +
4294 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4295 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4296 +#endif
4297
4298 /* This yields a mask that user programs can use to figure out what
4299 instruction set this CPU supports. */
4300 @@ -211,7 +217,4 @@ struct linux_binprm;
4301 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4302 int arch_setup_additional_pages(struct linux_binprm *, int);
4303
4304 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4305 -#define arch_randomize_brk arch_randomize_brk
4306 -
4307 #endif
4308 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4309 index d73cc6b..1a296ad 100644
4310 --- a/arch/s390/include/asm/system.h
4311 +++ b/arch/s390/include/asm/system.h
4312 @@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4313 extern void (*_machine_halt)(void);
4314 extern void (*_machine_power_off)(void);
4315
4316 -extern unsigned long arch_align_stack(unsigned long sp);
4317 +#define arch_align_stack(x) ((x) & ~0xfUL)
4318
4319 static inline int tprot(unsigned long addr)
4320 {
4321 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4322 index 2b23885..e136e31 100644
4323 --- a/arch/s390/include/asm/uaccess.h
4324 +++ b/arch/s390/include/asm/uaccess.h
4325 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4326 copy_to_user(void __user *to, const void *from, unsigned long n)
4327 {
4328 might_fault();
4329 +
4330 + if ((long)n < 0)
4331 + return n;
4332 +
4333 if (access_ok(VERIFY_WRITE, to, n))
4334 n = __copy_to_user(to, from, n);
4335 return n;
4336 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4337 static inline unsigned long __must_check
4338 __copy_from_user(void *to, const void __user *from, unsigned long n)
4339 {
4340 + if ((long)n < 0)
4341 + return n;
4342 +
4343 if (__builtin_constant_p(n) && (n <= 256))
4344 return uaccess.copy_from_user_small(n, from, to);
4345 else
4346 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4347 unsigned int sz = __compiletime_object_size(to);
4348
4349 might_fault();
4350 +
4351 + if ((long)n < 0)
4352 + return n;
4353 +
4354 if (unlikely(sz != -1 && sz < n)) {
4355 copy_from_user_overflow();
4356 return n;
4357 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4358 index dfcb343..eda788a 100644
4359 --- a/arch/s390/kernel/module.c
4360 +++ b/arch/s390/kernel/module.c
4361 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4362
4363 /* Increase core size by size of got & plt and set start
4364 offsets for got and plt. */
4365 - me->core_size = ALIGN(me->core_size, 4);
4366 - me->arch.got_offset = me->core_size;
4367 - me->core_size += me->arch.got_size;
4368 - me->arch.plt_offset = me->core_size;
4369 - me->core_size += me->arch.plt_size;
4370 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4371 + me->arch.got_offset = me->core_size_rw;
4372 + me->core_size_rw += me->arch.got_size;
4373 + me->arch.plt_offset = me->core_size_rx;
4374 + me->core_size_rx += me->arch.plt_size;
4375 return 0;
4376 }
4377
4378 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4379 if (info->got_initialized == 0) {
4380 Elf_Addr *gotent;
4381
4382 - gotent = me->module_core + me->arch.got_offset +
4383 + gotent = me->module_core_rw + me->arch.got_offset +
4384 info->got_offset;
4385 *gotent = val;
4386 info->got_initialized = 1;
4387 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4388 else if (r_type == R_390_GOTENT ||
4389 r_type == R_390_GOTPLTENT)
4390 *(unsigned int *) loc =
4391 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4392 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4393 else if (r_type == R_390_GOT64 ||
4394 r_type == R_390_GOTPLT64)
4395 *(unsigned long *) loc = val;
4396 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4397 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4398 if (info->plt_initialized == 0) {
4399 unsigned int *ip;
4400 - ip = me->module_core + me->arch.plt_offset +
4401 + ip = me->module_core_rx + me->arch.plt_offset +
4402 info->plt_offset;
4403 #ifndef CONFIG_64BIT
4404 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4405 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4406 val - loc + 0xffffUL < 0x1ffffeUL) ||
4407 (r_type == R_390_PLT32DBL &&
4408 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4409 - val = (Elf_Addr) me->module_core +
4410 + val = (Elf_Addr) me->module_core_rx +
4411 me->arch.plt_offset +
4412 info->plt_offset;
4413 val += rela->r_addend - loc;
4414 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4415 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4416 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4417 val = val + rela->r_addend -
4418 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4419 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4420 if (r_type == R_390_GOTOFF16)
4421 *(unsigned short *) loc = val;
4422 else if (r_type == R_390_GOTOFF32)
4423 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4424 break;
4425 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4426 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4427 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4428 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4429 rela->r_addend - loc;
4430 if (r_type == R_390_GOTPC)
4431 *(unsigned int *) loc = val;
4432 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4433 index e795933..b32563c 100644
4434 --- a/arch/s390/kernel/process.c
4435 +++ b/arch/s390/kernel/process.c
4436 @@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4437 }
4438 return 0;
4439 }
4440 -
4441 -unsigned long arch_align_stack(unsigned long sp)
4442 -{
4443 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4444 - sp -= get_random_int() & ~PAGE_MASK;
4445 - return sp & ~0xf;
4446 -}
4447 -
4448 -static inline unsigned long brk_rnd(void)
4449 -{
4450 - /* 8MB for 32bit, 1GB for 64bit */
4451 - if (is_32bit_task())
4452 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4453 - else
4454 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4455 -}
4456 -
4457 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4458 -{
4459 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4460 -
4461 - if (ret < mm->brk)
4462 - return mm->brk;
4463 - return ret;
4464 -}
4465 -
4466 -unsigned long randomize_et_dyn(unsigned long base)
4467 -{
4468 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4469 -
4470 - if (!(current->flags & PF_RANDOMIZE))
4471 - return base;
4472 - if (ret < base)
4473 - return base;
4474 - return ret;
4475 -}
4476 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4477 index a0155c0..34cc491 100644
4478 --- a/arch/s390/mm/mmap.c
4479 +++ b/arch/s390/mm/mmap.c
4480 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4481 */
4482 if (mmap_is_legacy()) {
4483 mm->mmap_base = TASK_UNMAPPED_BASE;
4484 +
4485 +#ifdef CONFIG_PAX_RANDMMAP
4486 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4487 + mm->mmap_base += mm->delta_mmap;
4488 +#endif
4489 +
4490 mm->get_unmapped_area = arch_get_unmapped_area;
4491 mm->unmap_area = arch_unmap_area;
4492 } else {
4493 mm->mmap_base = mmap_base();
4494 +
4495 +#ifdef CONFIG_PAX_RANDMMAP
4496 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4497 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4498 +#endif
4499 +
4500 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4501 mm->unmap_area = arch_unmap_area_topdown;
4502 }
4503 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4504 */
4505 if (mmap_is_legacy()) {
4506 mm->mmap_base = TASK_UNMAPPED_BASE;
4507 +
4508 +#ifdef CONFIG_PAX_RANDMMAP
4509 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4510 + mm->mmap_base += mm->delta_mmap;
4511 +#endif
4512 +
4513 mm->get_unmapped_area = s390_get_unmapped_area;
4514 mm->unmap_area = arch_unmap_area;
4515 } else {
4516 mm->mmap_base = mmap_base();
4517 +
4518 +#ifdef CONFIG_PAX_RANDMMAP
4519 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4520 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4521 +#endif
4522 +
4523 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4524 mm->unmap_area = arch_unmap_area_topdown;
4525 }
4526 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4527 index ae3d59f..f65f075 100644
4528 --- a/arch/score/include/asm/cache.h
4529 +++ b/arch/score/include/asm/cache.h
4530 @@ -1,7 +1,9 @@
4531 #ifndef _ASM_SCORE_CACHE_H
4532 #define _ASM_SCORE_CACHE_H
4533
4534 +#include <linux/const.h>
4535 +
4536 #define L1_CACHE_SHIFT 4
4537 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4538 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4539
4540 #endif /* _ASM_SCORE_CACHE_H */
4541 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4542 index 589d5c7..669e274 100644
4543 --- a/arch/score/include/asm/system.h
4544 +++ b/arch/score/include/asm/system.h
4545 @@ -17,7 +17,7 @@ do { \
4546 #define finish_arch_switch(prev) do {} while (0)
4547
4548 typedef void (*vi_handler_t)(void);
4549 -extern unsigned long arch_align_stack(unsigned long sp);
4550 +#define arch_align_stack(x) (x)
4551
4552 #define mb() barrier()
4553 #define rmb() barrier()
4554 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4555 index 25d0803..d6c8e36 100644
4556 --- a/arch/score/kernel/process.c
4557 +++ b/arch/score/kernel/process.c
4558 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4559
4560 return task_pt_regs(task)->cp0_epc;
4561 }
4562 -
4563 -unsigned long arch_align_stack(unsigned long sp)
4564 -{
4565 - return sp;
4566 -}
4567 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4568 index ef9e555..331bd29 100644
4569 --- a/arch/sh/include/asm/cache.h
4570 +++ b/arch/sh/include/asm/cache.h
4571 @@ -9,10 +9,11 @@
4572 #define __ASM_SH_CACHE_H
4573 #ifdef __KERNEL__
4574
4575 +#include <linux/const.h>
4576 #include <linux/init.h>
4577 #include <cpu/cache.h>
4578
4579 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4580 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4581
4582 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4583
4584 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4585 index afeb710..d1d1289 100644
4586 --- a/arch/sh/mm/mmap.c
4587 +++ b/arch/sh/mm/mmap.c
4588 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4589 addr = PAGE_ALIGN(addr);
4590
4591 vma = find_vma(mm, addr);
4592 - if (TASK_SIZE - len >= addr &&
4593 - (!vma || addr + len <= vma->vm_start))
4594 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4595 return addr;
4596 }
4597
4598 @@ -106,7 +105,7 @@ full_search:
4599 }
4600 return -ENOMEM;
4601 }
4602 - if (likely(!vma || addr + len <= vma->vm_start)) {
4603 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4604 /*
4605 * Remember the place where we stopped the search:
4606 */
4607 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4608 addr = PAGE_ALIGN(addr);
4609
4610 vma = find_vma(mm, addr);
4611 - if (TASK_SIZE - len >= addr &&
4612 - (!vma || addr + len <= vma->vm_start))
4613 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4614 return addr;
4615 }
4616
4617 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4618 /* make sure it can fit in the remaining address space */
4619 if (likely(addr > len)) {
4620 vma = find_vma(mm, addr-len);
4621 - if (!vma || addr <= vma->vm_start) {
4622 + if (check_heap_stack_gap(vma, addr - len, len)) {
4623 /* remember the address as a hint for next time */
4624 return (mm->free_area_cache = addr-len);
4625 }
4626 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4627 if (unlikely(mm->mmap_base < len))
4628 goto bottomup;
4629
4630 - addr = mm->mmap_base-len;
4631 - if (do_colour_align)
4632 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4633 + addr = mm->mmap_base - len;
4634
4635 do {
4636 + if (do_colour_align)
4637 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4638 /*
4639 * Lookup failure means no vma is above this address,
4640 * else if new region fits below vma->vm_start,
4641 * return with success:
4642 */
4643 vma = find_vma(mm, addr);
4644 - if (likely(!vma || addr+len <= vma->vm_start)) {
4645 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4646 /* remember the address as a hint for next time */
4647 return (mm->free_area_cache = addr);
4648 }
4649 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4650 mm->cached_hole_size = vma->vm_start - addr;
4651
4652 /* try just below the current vma->vm_start */
4653 - addr = vma->vm_start-len;
4654 - if (do_colour_align)
4655 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4656 - } while (likely(len < vma->vm_start));
4657 + addr = skip_heap_stack_gap(vma, len);
4658 + } while (!IS_ERR_VALUE(addr));
4659
4660 bottomup:
4661 /*
4662 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4663 index eddcfb3..b117d90 100644
4664 --- a/arch/sparc/Makefile
4665 +++ b/arch/sparc/Makefile
4666 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4667 # Export what is needed by arch/sparc/boot/Makefile
4668 export VMLINUX_INIT VMLINUX_MAIN
4669 VMLINUX_INIT := $(head-y) $(init-y)
4670 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4671 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4672 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4673 VMLINUX_MAIN += $(drivers-y) $(net-y)
4674
4675 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4676 index 9f421df..b81fc12 100644
4677 --- a/arch/sparc/include/asm/atomic_64.h
4678 +++ b/arch/sparc/include/asm/atomic_64.h
4679 @@ -14,18 +14,40 @@
4680 #define ATOMIC64_INIT(i) { (i) }
4681
4682 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4683 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4684 +{
4685 + return v->counter;
4686 +}
4687 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4688 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4689 +{
4690 + return v->counter;
4691 +}
4692
4693 #define atomic_set(v, i) (((v)->counter) = i)
4694 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4695 +{
4696 + v->counter = i;
4697 +}
4698 #define atomic64_set(v, i) (((v)->counter) = i)
4699 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4700 +{
4701 + v->counter = i;
4702 +}
4703
4704 extern void atomic_add(int, atomic_t *);
4705 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4706 extern void atomic64_add(long, atomic64_t *);
4707 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4708 extern void atomic_sub(int, atomic_t *);
4709 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4710 extern void atomic64_sub(long, atomic64_t *);
4711 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4712
4713 extern int atomic_add_ret(int, atomic_t *);
4714 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4715 extern long atomic64_add_ret(long, atomic64_t *);
4716 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4717 extern int atomic_sub_ret(int, atomic_t *);
4718 extern long atomic64_sub_ret(long, atomic64_t *);
4719
4720 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4721 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4722
4723 #define atomic_inc_return(v) atomic_add_ret(1, v)
4724 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4725 +{
4726 + return atomic_add_ret_unchecked(1, v);
4727 +}
4728 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4729 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4730 +{
4731 + return atomic64_add_ret_unchecked(1, v);
4732 +}
4733
4734 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4735 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4736
4737 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4738 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4739 +{
4740 + return atomic_add_ret_unchecked(i, v);
4741 +}
4742 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4743 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4744 +{
4745 + return atomic64_add_ret_unchecked(i, v);
4746 +}
4747
4748 /*
4749 * atomic_inc_and_test - increment and test
4750 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4751 * other cases.
4752 */
4753 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4754 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4755 +{
4756 + return atomic_inc_return_unchecked(v) == 0;
4757 +}
4758 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4759
4760 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4761 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4762 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4763
4764 #define atomic_inc(v) atomic_add(1, v)
4765 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4766 +{
4767 + atomic_add_unchecked(1, v);
4768 +}
4769 #define atomic64_inc(v) atomic64_add(1, v)
4770 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4771 +{
4772 + atomic64_add_unchecked(1, v);
4773 +}
4774
4775 #define atomic_dec(v) atomic_sub(1, v)
4776 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4777 +{
4778 + atomic_sub_unchecked(1, v);
4779 +}
4780 #define atomic64_dec(v) atomic64_sub(1, v)
4781 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4782 +{
4783 + atomic64_sub_unchecked(1, v);
4784 +}
4785
4786 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4787 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4788
4789 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4790 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4791 +{
4792 + return cmpxchg(&v->counter, old, new);
4793 +}
4794 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4795 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4796 +{
4797 + return xchg(&v->counter, new);
4798 +}
4799
4800 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4801 {
4802 - int c, old;
4803 + int c, old, new;
4804 c = atomic_read(v);
4805 for (;;) {
4806 - if (unlikely(c == (u)))
4807 + if (unlikely(c == u))
4808 break;
4809 - old = atomic_cmpxchg((v), c, c + (a));
4810 +
4811 + asm volatile("addcc %2, %0, %0\n"
4812 +
4813 +#ifdef CONFIG_PAX_REFCOUNT
4814 + "tvs %%icc, 6\n"
4815 +#endif
4816 +
4817 + : "=r" (new)
4818 + : "0" (c), "ir" (a)
4819 + : "cc");
4820 +
4821 + old = atomic_cmpxchg(v, c, new);
4822 if (likely(old == c))
4823 break;
4824 c = old;
4825 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4826 #define atomic64_cmpxchg(v, o, n) \
4827 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4828 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4829 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4830 +{
4831 + return xchg(&v->counter, new);
4832 +}
4833
4834 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4835 {
4836 - long c, old;
4837 + long c, old, new;
4838 c = atomic64_read(v);
4839 for (;;) {
4840 - if (unlikely(c == (u)))
4841 + if (unlikely(c == u))
4842 break;
4843 - old = atomic64_cmpxchg((v), c, c + (a));
4844 +
4845 + asm volatile("addcc %2, %0, %0\n"
4846 +
4847 +#ifdef CONFIG_PAX_REFCOUNT
4848 + "tvs %%xcc, 6\n"
4849 +#endif
4850 +
4851 + : "=r" (new)
4852 + : "0" (c), "ir" (a)
4853 + : "cc");
4854 +
4855 + old = atomic64_cmpxchg(v, c, new);
4856 if (likely(old == c))
4857 break;
4858 c = old;
4859 }
4860 - return c != (u);
4861 + return c != u;
4862 }
4863
4864 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4865 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4866 index 69358b5..9d0d492 100644
4867 --- a/arch/sparc/include/asm/cache.h
4868 +++ b/arch/sparc/include/asm/cache.h
4869 @@ -7,10 +7,12 @@
4870 #ifndef _SPARC_CACHE_H
4871 #define _SPARC_CACHE_H
4872
4873 +#include <linux/const.h>
4874 +
4875 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
4876
4877 #define L1_CACHE_SHIFT 5
4878 -#define L1_CACHE_BYTES 32
4879 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4880
4881 #ifdef CONFIG_SPARC32
4882 #define SMP_CACHE_BYTES_SHIFT 5
4883 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4884 index 4269ca6..e3da77f 100644
4885 --- a/arch/sparc/include/asm/elf_32.h
4886 +++ b/arch/sparc/include/asm/elf_32.h
4887 @@ -114,6 +114,13 @@ typedef struct {
4888
4889 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4890
4891 +#ifdef CONFIG_PAX_ASLR
4892 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4893 +
4894 +#define PAX_DELTA_MMAP_LEN 16
4895 +#define PAX_DELTA_STACK_LEN 16
4896 +#endif
4897 +
4898 /* This yields a mask that user programs can use to figure out what
4899 instruction set this cpu supports. This can NOT be done in userspace
4900 on Sparc. */
4901 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4902 index 7df8b7f..4946269 100644
4903 --- a/arch/sparc/include/asm/elf_64.h
4904 +++ b/arch/sparc/include/asm/elf_64.h
4905 @@ -180,6 +180,13 @@ typedef struct {
4906 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4907 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4908
4909 +#ifdef CONFIG_PAX_ASLR
4910 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4911 +
4912 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4913 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4914 +#endif
4915 +
4916 extern unsigned long sparc64_elf_hwcap;
4917 #define ELF_HWCAP sparc64_elf_hwcap
4918
4919 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4920 index a790cc6..091ed94 100644
4921 --- a/arch/sparc/include/asm/pgtable_32.h
4922 +++ b/arch/sparc/include/asm/pgtable_32.h
4923 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4924 BTFIXUPDEF_INT(page_none)
4925 BTFIXUPDEF_INT(page_copy)
4926 BTFIXUPDEF_INT(page_readonly)
4927 +
4928 +#ifdef CONFIG_PAX_PAGEEXEC
4929 +BTFIXUPDEF_INT(page_shared_noexec)
4930 +BTFIXUPDEF_INT(page_copy_noexec)
4931 +BTFIXUPDEF_INT(page_readonly_noexec)
4932 +#endif
4933 +
4934 BTFIXUPDEF_INT(page_kernel)
4935
4936 #define PMD_SHIFT SUN4C_PMD_SHIFT
4937 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
4938 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4939 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4940
4941 +#ifdef CONFIG_PAX_PAGEEXEC
4942 +extern pgprot_t PAGE_SHARED_NOEXEC;
4943 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4944 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4945 +#else
4946 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4947 +# define PAGE_COPY_NOEXEC PAGE_COPY
4948 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4949 +#endif
4950 +
4951 extern unsigned long page_kernel;
4952
4953 #ifdef MODULE
4954 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4955 index f6ae2b2..b03ffc7 100644
4956 --- a/arch/sparc/include/asm/pgtsrmmu.h
4957 +++ b/arch/sparc/include/asm/pgtsrmmu.h
4958 @@ -115,6 +115,13 @@
4959 SRMMU_EXEC | SRMMU_REF)
4960 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4961 SRMMU_EXEC | SRMMU_REF)
4962 +
4963 +#ifdef CONFIG_PAX_PAGEEXEC
4964 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4965 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4966 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4967 +#endif
4968 +
4969 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4970 SRMMU_DIRTY | SRMMU_REF)
4971
4972 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4973 index 9689176..63c18ea 100644
4974 --- a/arch/sparc/include/asm/spinlock_64.h
4975 +++ b/arch/sparc/include/asm/spinlock_64.h
4976 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
4977
4978 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4979
4980 -static void inline arch_read_lock(arch_rwlock_t *lock)
4981 +static inline void arch_read_lock(arch_rwlock_t *lock)
4982 {
4983 unsigned long tmp1, tmp2;
4984
4985 __asm__ __volatile__ (
4986 "1: ldsw [%2], %0\n"
4987 " brlz,pn %0, 2f\n"
4988 -"4: add %0, 1, %1\n"
4989 +"4: addcc %0, 1, %1\n"
4990 +
4991 +#ifdef CONFIG_PAX_REFCOUNT
4992 +" tvs %%icc, 6\n"
4993 +#endif
4994 +
4995 " cas [%2], %0, %1\n"
4996 " cmp %0, %1\n"
4997 " bne,pn %%icc, 1b\n"
4998 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
4999 " .previous"
5000 : "=&r" (tmp1), "=&r" (tmp2)
5001 : "r" (lock)
5002 - : "memory");
5003 + : "memory", "cc");
5004 }
5005
5006 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5007 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5008 {
5009 int tmp1, tmp2;
5010
5011 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5012 "1: ldsw [%2], %0\n"
5013 " brlz,a,pn %0, 2f\n"
5014 " mov 0, %0\n"
5015 -" add %0, 1, %1\n"
5016 +" addcc %0, 1, %1\n"
5017 +
5018 +#ifdef CONFIG_PAX_REFCOUNT
5019 +" tvs %%icc, 6\n"
5020 +#endif
5021 +
5022 " cas [%2], %0, %1\n"
5023 " cmp %0, %1\n"
5024 " bne,pn %%icc, 1b\n"
5025 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5026 return tmp1;
5027 }
5028
5029 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5030 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5031 {
5032 unsigned long tmp1, tmp2;
5033
5034 __asm__ __volatile__(
5035 "1: lduw [%2], %0\n"
5036 -" sub %0, 1, %1\n"
5037 +" subcc %0, 1, %1\n"
5038 +
5039 +#ifdef CONFIG_PAX_REFCOUNT
5040 +" tvs %%icc, 6\n"
5041 +#endif
5042 +
5043 " cas [%2], %0, %1\n"
5044 " cmp %0, %1\n"
5045 " bne,pn %%xcc, 1b\n"
5046 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5047 : "memory");
5048 }
5049
5050 -static void inline arch_write_lock(arch_rwlock_t *lock)
5051 +static inline void arch_write_lock(arch_rwlock_t *lock)
5052 {
5053 unsigned long mask, tmp1, tmp2;
5054
5055 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5056 : "memory");
5057 }
5058
5059 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5060 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5061 {
5062 __asm__ __volatile__(
5063 " stw %%g0, [%0]"
5064 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5065 : "memory");
5066 }
5067
5068 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5069 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5070 {
5071 unsigned long mask, tmp1, tmp2, result;
5072
5073 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5074 index c2a1080..21ed218 100644
5075 --- a/arch/sparc/include/asm/thread_info_32.h
5076 +++ b/arch/sparc/include/asm/thread_info_32.h
5077 @@ -50,6 +50,8 @@ struct thread_info {
5078 unsigned long w_saved;
5079
5080 struct restart_block restart_block;
5081 +
5082 + unsigned long lowest_stack;
5083 };
5084
5085 /*
5086 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5087 index 01d057f..0a02f7e 100644
5088 --- a/arch/sparc/include/asm/thread_info_64.h
5089 +++ b/arch/sparc/include/asm/thread_info_64.h
5090 @@ -63,6 +63,8 @@ struct thread_info {
5091 struct pt_regs *kern_una_regs;
5092 unsigned int kern_una_insn;
5093
5094 + unsigned long lowest_stack;
5095 +
5096 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5097 };
5098
5099 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5100 index e88fbe5..96b0ce5 100644
5101 --- a/arch/sparc/include/asm/uaccess.h
5102 +++ b/arch/sparc/include/asm/uaccess.h
5103 @@ -1,5 +1,13 @@
5104 #ifndef ___ASM_SPARC_UACCESS_H
5105 #define ___ASM_SPARC_UACCESS_H
5106 +
5107 +#ifdef __KERNEL__
5108 +#ifndef __ASSEMBLY__
5109 +#include <linux/types.h>
5110 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5111 +#endif
5112 +#endif
5113 +
5114 #if defined(__sparc__) && defined(__arch64__)
5115 #include <asm/uaccess_64.h>
5116 #else
5117 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5118 index 8303ac4..07f333d 100644
5119 --- a/arch/sparc/include/asm/uaccess_32.h
5120 +++ b/arch/sparc/include/asm/uaccess_32.h
5121 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5122
5123 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5124 {
5125 - if (n && __access_ok((unsigned long) to, n))
5126 + if ((long)n < 0)
5127 + return n;
5128 +
5129 + if (n && __access_ok((unsigned long) to, n)) {
5130 + if (!__builtin_constant_p(n))
5131 + check_object_size(from, n, true);
5132 return __copy_user(to, (__force void __user *) from, n);
5133 - else
5134 + } else
5135 return n;
5136 }
5137
5138 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5139 {
5140 + if ((long)n < 0)
5141 + return n;
5142 +
5143 + if (!__builtin_constant_p(n))
5144 + check_object_size(from, n, true);
5145 +
5146 return __copy_user(to, (__force void __user *) from, n);
5147 }
5148
5149 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5150 {
5151 - if (n && __access_ok((unsigned long) from, n))
5152 + if ((long)n < 0)
5153 + return n;
5154 +
5155 + if (n && __access_ok((unsigned long) from, n)) {
5156 + if (!__builtin_constant_p(n))
5157 + check_object_size(to, n, false);
5158 return __copy_user((__force void __user *) to, from, n);
5159 - else
5160 + } else
5161 return n;
5162 }
5163
5164 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5165 {
5166 + if ((long)n < 0)
5167 + return n;
5168 +
5169 return __copy_user((__force void __user *) to, from, n);
5170 }
5171
5172 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5173 index 3e1449f..5293a0e 100644
5174 --- a/arch/sparc/include/asm/uaccess_64.h
5175 +++ b/arch/sparc/include/asm/uaccess_64.h
5176 @@ -10,6 +10,7 @@
5177 #include <linux/compiler.h>
5178 #include <linux/string.h>
5179 #include <linux/thread_info.h>
5180 +#include <linux/kernel.h>
5181 #include <asm/asi.h>
5182 #include <asm/system.h>
5183 #include <asm/spitfire.h>
5184 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5185 static inline unsigned long __must_check
5186 copy_from_user(void *to, const void __user *from, unsigned long size)
5187 {
5188 - unsigned long ret = ___copy_from_user(to, from, size);
5189 + unsigned long ret;
5190
5191 + if ((long)size < 0 || size > INT_MAX)
5192 + return size;
5193 +
5194 + if (!__builtin_constant_p(size))
5195 + check_object_size(to, size, false);
5196 +
5197 + ret = ___copy_from_user(to, from, size);
5198 if (unlikely(ret))
5199 ret = copy_from_user_fixup(to, from, size);
5200
5201 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5202 static inline unsigned long __must_check
5203 copy_to_user(void __user *to, const void *from, unsigned long size)
5204 {
5205 - unsigned long ret = ___copy_to_user(to, from, size);
5206 + unsigned long ret;
5207
5208 + if ((long)size < 0 || size > INT_MAX)
5209 + return size;
5210 +
5211 + if (!__builtin_constant_p(size))
5212 + check_object_size(from, size, true);
5213 +
5214 + ret = ___copy_to_user(to, from, size);
5215 if (unlikely(ret))
5216 ret = copy_to_user_fixup(to, from, size);
5217 return ret;
5218 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5219 index cb85458..e063f17 100644
5220 --- a/arch/sparc/kernel/Makefile
5221 +++ b/arch/sparc/kernel/Makefile
5222 @@ -3,7 +3,7 @@
5223 #
5224
5225 asflags-y := -ansi
5226 -ccflags-y := -Werror
5227 +#ccflags-y := -Werror
5228
5229 extra-y := head_$(BITS).o
5230 extra-y += init_task.o
5231 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5232 index f793742..4d880af 100644
5233 --- a/arch/sparc/kernel/process_32.c
5234 +++ b/arch/sparc/kernel/process_32.c
5235 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5236 rw->ins[4], rw->ins[5],
5237 rw->ins[6],
5238 rw->ins[7]);
5239 - printk("%pS\n", (void *) rw->ins[7]);
5240 + printk("%pA\n", (void *) rw->ins[7]);
5241 rw = (struct reg_window32 *) rw->ins[6];
5242 }
5243 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5244 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5245
5246 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5247 r->psr, r->pc, r->npc, r->y, print_tainted());
5248 - printk("PC: <%pS>\n", (void *) r->pc);
5249 + printk("PC: <%pA>\n", (void *) r->pc);
5250 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5251 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5252 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5253 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5254 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5255 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5256 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5257 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5258
5259 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5260 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5261 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5262 rw = (struct reg_window32 *) fp;
5263 pc = rw->ins[7];
5264 printk("[%08lx : ", pc);
5265 - printk("%pS ] ", (void *) pc);
5266 + printk("%pA ] ", (void *) pc);
5267 fp = rw->ins[6];
5268 } while (++count < 16);
5269 printk("\n");
5270 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5271 index 39d8b05..d1a7d90 100644
5272 --- a/arch/sparc/kernel/process_64.c
5273 +++ b/arch/sparc/kernel/process_64.c
5274 @@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5275 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5276 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5277 if (regs->tstate & TSTATE_PRIV)
5278 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5279 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5280 }
5281
5282 void show_regs(struct pt_regs *regs)
5283 {
5284 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5285 regs->tpc, regs->tnpc, regs->y, print_tainted());
5286 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5287 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5288 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5289 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5290 regs->u_regs[3]);
5291 @@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5292 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5293 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5294 regs->u_regs[15]);
5295 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5296 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5297 show_regwindow(regs);
5298 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5299 }
5300 @@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5301 ((tp && tp->task) ? tp->task->pid : -1));
5302
5303 if (gp->tstate & TSTATE_PRIV) {
5304 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5305 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5306 (void *) gp->tpc,
5307 (void *) gp->o7,
5308 (void *) gp->i7,
5309 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5310 index 42b282f..28ce9f2 100644
5311 --- a/arch/sparc/kernel/sys_sparc_32.c
5312 +++ b/arch/sparc/kernel/sys_sparc_32.c
5313 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5314 if (ARCH_SUN4C && len > 0x20000000)
5315 return -ENOMEM;
5316 if (!addr)
5317 - addr = TASK_UNMAPPED_BASE;
5318 + addr = current->mm->mmap_base;
5319
5320 if (flags & MAP_SHARED)
5321 addr = COLOUR_ALIGN(addr);
5322 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5323 }
5324 if (TASK_SIZE - PAGE_SIZE - len < addr)
5325 return -ENOMEM;
5326 - if (!vmm || addr + len <= vmm->vm_start)
5327 + if (check_heap_stack_gap(vmm, addr, len))
5328 return addr;
5329 addr = vmm->vm_end;
5330 if (flags & MAP_SHARED)
5331 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5332 index 232df99..cee1f9c 100644
5333 --- a/arch/sparc/kernel/sys_sparc_64.c
5334 +++ b/arch/sparc/kernel/sys_sparc_64.c
5335 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5336 /* We do not accept a shared mapping if it would violate
5337 * cache aliasing constraints.
5338 */
5339 - if ((flags & MAP_SHARED) &&
5340 + if ((filp || (flags & MAP_SHARED)) &&
5341 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5342 return -EINVAL;
5343 return addr;
5344 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5345 if (filp || (flags & MAP_SHARED))
5346 do_color_align = 1;
5347
5348 +#ifdef CONFIG_PAX_RANDMMAP
5349 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5350 +#endif
5351 +
5352 if (addr) {
5353 if (do_color_align)
5354 addr = COLOUR_ALIGN(addr, pgoff);
5355 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5356 addr = PAGE_ALIGN(addr);
5357
5358 vma = find_vma(mm, addr);
5359 - if (task_size - len >= addr &&
5360 - (!vma || addr + len <= vma->vm_start))
5361 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5362 return addr;
5363 }
5364
5365 if (len > mm->cached_hole_size) {
5366 - start_addr = addr = mm->free_area_cache;
5367 + start_addr = addr = mm->free_area_cache;
5368 } else {
5369 - start_addr = addr = TASK_UNMAPPED_BASE;
5370 + start_addr = addr = mm->mmap_base;
5371 mm->cached_hole_size = 0;
5372 }
5373
5374 @@ -174,14 +177,14 @@ full_search:
5375 vma = find_vma(mm, VA_EXCLUDE_END);
5376 }
5377 if (unlikely(task_size < addr)) {
5378 - if (start_addr != TASK_UNMAPPED_BASE) {
5379 - start_addr = addr = TASK_UNMAPPED_BASE;
5380 + if (start_addr != mm->mmap_base) {
5381 + start_addr = addr = mm->mmap_base;
5382 mm->cached_hole_size = 0;
5383 goto full_search;
5384 }
5385 return -ENOMEM;
5386 }
5387 - if (likely(!vma || addr + len <= vma->vm_start)) {
5388 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5389 /*
5390 * Remember the place where we stopped the search:
5391 */
5392 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5393 /* We do not accept a shared mapping if it would violate
5394 * cache aliasing constraints.
5395 */
5396 - if ((flags & MAP_SHARED) &&
5397 + if ((filp || (flags & MAP_SHARED)) &&
5398 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5399 return -EINVAL;
5400 return addr;
5401 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5402 addr = PAGE_ALIGN(addr);
5403
5404 vma = find_vma(mm, addr);
5405 - if (task_size - len >= addr &&
5406 - (!vma || addr + len <= vma->vm_start))
5407 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5408 return addr;
5409 }
5410
5411 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5412 /* make sure it can fit in the remaining address space */
5413 if (likely(addr > len)) {
5414 vma = find_vma(mm, addr-len);
5415 - if (!vma || addr <= vma->vm_start) {
5416 + if (check_heap_stack_gap(vma, addr - len, len)) {
5417 /* remember the address as a hint for next time */
5418 return (mm->free_area_cache = addr-len);
5419 }
5420 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5421 if (unlikely(mm->mmap_base < len))
5422 goto bottomup;
5423
5424 - addr = mm->mmap_base-len;
5425 - if (do_color_align)
5426 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5427 + addr = mm->mmap_base - len;
5428
5429 do {
5430 + if (do_color_align)
5431 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5432 /*
5433 * Lookup failure means no vma is above this address,
5434 * else if new region fits below vma->vm_start,
5435 * return with success:
5436 */
5437 vma = find_vma(mm, addr);
5438 - if (likely(!vma || addr+len <= vma->vm_start)) {
5439 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5440 /* remember the address as a hint for next time */
5441 return (mm->free_area_cache = addr);
5442 }
5443 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5444 mm->cached_hole_size = vma->vm_start - addr;
5445
5446 /* try just below the current vma->vm_start */
5447 - addr = vma->vm_start-len;
5448 - if (do_color_align)
5449 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5450 - } while (likely(len < vma->vm_start));
5451 + addr = skip_heap_stack_gap(vma, len);
5452 + } while (!IS_ERR_VALUE(addr));
5453
5454 bottomup:
5455 /*
5456 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5457 gap == RLIM_INFINITY ||
5458 sysctl_legacy_va_layout) {
5459 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5460 +
5461 +#ifdef CONFIG_PAX_RANDMMAP
5462 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5463 + mm->mmap_base += mm->delta_mmap;
5464 +#endif
5465 +
5466 mm->get_unmapped_area = arch_get_unmapped_area;
5467 mm->unmap_area = arch_unmap_area;
5468 } else {
5469 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5470 gap = (task_size / 6 * 5);
5471
5472 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5473 +
5474 +#ifdef CONFIG_PAX_RANDMMAP
5475 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5476 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5477 +#endif
5478 +
5479 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5480 mm->unmap_area = arch_unmap_area_topdown;
5481 }
5482 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5483 index 591f20c..0f1b925 100644
5484 --- a/arch/sparc/kernel/traps_32.c
5485 +++ b/arch/sparc/kernel/traps_32.c
5486 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5487 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5488 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5489
5490 +extern void gr_handle_kernel_exploit(void);
5491 +
5492 void die_if_kernel(char *str, struct pt_regs *regs)
5493 {
5494 static int die_counter;
5495 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5496 count++ < 30 &&
5497 (((unsigned long) rw) >= PAGE_OFFSET) &&
5498 !(((unsigned long) rw) & 0x7)) {
5499 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5500 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5501 (void *) rw->ins[7]);
5502 rw = (struct reg_window32 *)rw->ins[6];
5503 }
5504 }
5505 printk("Instruction DUMP:");
5506 instruction_dump ((unsigned long *) regs->pc);
5507 - if(regs->psr & PSR_PS)
5508 + if(regs->psr & PSR_PS) {
5509 + gr_handle_kernel_exploit();
5510 do_exit(SIGKILL);
5511 + }
5512 do_exit(SIGSEGV);
5513 }
5514
5515 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5516 index 0cbdaa4..438e4c9 100644
5517 --- a/arch/sparc/kernel/traps_64.c
5518 +++ b/arch/sparc/kernel/traps_64.c
5519 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5520 i + 1,
5521 p->trapstack[i].tstate, p->trapstack[i].tpc,
5522 p->trapstack[i].tnpc, p->trapstack[i].tt);
5523 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5524 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5525 }
5526 }
5527
5528 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5529
5530 lvl -= 0x100;
5531 if (regs->tstate & TSTATE_PRIV) {
5532 +
5533 +#ifdef CONFIG_PAX_REFCOUNT
5534 + if (lvl == 6)
5535 + pax_report_refcount_overflow(regs);
5536 +#endif
5537 +
5538 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5539 die_if_kernel(buffer, regs);
5540 }
5541 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5542 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5543 {
5544 char buffer[32];
5545 -
5546 +
5547 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5548 0, lvl, SIGTRAP) == NOTIFY_STOP)
5549 return;
5550
5551 +#ifdef CONFIG_PAX_REFCOUNT
5552 + if (lvl == 6)
5553 + pax_report_refcount_overflow(regs);
5554 +#endif
5555 +
5556 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5557
5558 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5559 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5560 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5561 printk("%s" "ERROR(%d): ",
5562 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5563 - printk("TPC<%pS>\n", (void *) regs->tpc);
5564 + printk("TPC<%pA>\n", (void *) regs->tpc);
5565 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5566 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5567 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5568 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5569 smp_processor_id(),
5570 (type & 0x1) ? 'I' : 'D',
5571 regs->tpc);
5572 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5573 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5574 panic("Irrecoverable Cheetah+ parity error.");
5575 }
5576
5577 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5578 smp_processor_id(),
5579 (type & 0x1) ? 'I' : 'D',
5580 regs->tpc);
5581 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5582 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5583 }
5584
5585 struct sun4v_error_entry {
5586 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5587
5588 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5589 regs->tpc, tl);
5590 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5591 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5592 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5593 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5594 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5595 (void *) regs->u_regs[UREG_I7]);
5596 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5597 "pte[%lx] error[%lx]\n",
5598 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5599
5600 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5601 regs->tpc, tl);
5602 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5603 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5604 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5605 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5606 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5607 (void *) regs->u_regs[UREG_I7]);
5608 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5609 "pte[%lx] error[%lx]\n",
5610 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5611 fp = (unsigned long)sf->fp + STACK_BIAS;
5612 }
5613
5614 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5615 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5616 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5617 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5618 int index = tsk->curr_ret_stack;
5619 if (tsk->ret_stack && index >= graph) {
5620 pc = tsk->ret_stack[index - graph].ret;
5621 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5622 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5623 graph++;
5624 }
5625 }
5626 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5627 return (struct reg_window *) (fp + STACK_BIAS);
5628 }
5629
5630 +extern void gr_handle_kernel_exploit(void);
5631 +
5632 void die_if_kernel(char *str, struct pt_regs *regs)
5633 {
5634 static int die_counter;
5635 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5636 while (rw &&
5637 count++ < 30 &&
5638 kstack_valid(tp, (unsigned long) rw)) {
5639 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5640 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5641 (void *) rw->ins[7]);
5642
5643 rw = kernel_stack_up(rw);
5644 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5645 }
5646 user_instruction_dump ((unsigned int __user *) regs->tpc);
5647 }
5648 - if (regs->tstate & TSTATE_PRIV)
5649 + if (regs->tstate & TSTATE_PRIV) {
5650 + gr_handle_kernel_exploit();
5651 do_exit(SIGKILL);
5652 + }
5653 do_exit(SIGSEGV);
5654 }
5655 EXPORT_SYMBOL(die_if_kernel);
5656 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5657 index 76e4ac1..78f8bb1 100644
5658 --- a/arch/sparc/kernel/unaligned_64.c
5659 +++ b/arch/sparc/kernel/unaligned_64.c
5660 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5661 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5662
5663 if (__ratelimit(&ratelimit)) {
5664 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5665 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5666 regs->tpc, (void *) regs->tpc);
5667 }
5668 }
5669 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5670 index a3fc437..fea9957 100644
5671 --- a/arch/sparc/lib/Makefile
5672 +++ b/arch/sparc/lib/Makefile
5673 @@ -2,7 +2,7 @@
5674 #
5675
5676 asflags-y := -ansi -DST_DIV0=0x02
5677 -ccflags-y := -Werror
5678 +#ccflags-y := -Werror
5679
5680 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5681 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5682 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5683 index 59186e0..f747d7a 100644
5684 --- a/arch/sparc/lib/atomic_64.S
5685 +++ b/arch/sparc/lib/atomic_64.S
5686 @@ -18,7 +18,12 @@
5687 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5688 BACKOFF_SETUP(%o2)
5689 1: lduw [%o1], %g1
5690 - add %g1, %o0, %g7
5691 + addcc %g1, %o0, %g7
5692 +
5693 +#ifdef CONFIG_PAX_REFCOUNT
5694 + tvs %icc, 6
5695 +#endif
5696 +
5697 cas [%o1], %g1, %g7
5698 cmp %g1, %g7
5699 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5700 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5701 2: BACKOFF_SPIN(%o2, %o3, 1b)
5702 .size atomic_add, .-atomic_add
5703
5704 + .globl atomic_add_unchecked
5705 + .type atomic_add_unchecked,#function
5706 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5707 + BACKOFF_SETUP(%o2)
5708 +1: lduw [%o1], %g1
5709 + add %g1, %o0, %g7
5710 + cas [%o1], %g1, %g7
5711 + cmp %g1, %g7
5712 + bne,pn %icc, 2f
5713 + nop
5714 + retl
5715 + nop
5716 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5717 + .size atomic_add_unchecked, .-atomic_add_unchecked
5718 +
5719 .globl atomic_sub
5720 .type atomic_sub,#function
5721 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5722 BACKOFF_SETUP(%o2)
5723 1: lduw [%o1], %g1
5724 - sub %g1, %o0, %g7
5725 + subcc %g1, %o0, %g7
5726 +
5727 +#ifdef CONFIG_PAX_REFCOUNT
5728 + tvs %icc, 6
5729 +#endif
5730 +
5731 cas [%o1], %g1, %g7
5732 cmp %g1, %g7
5733 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5734 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5735 2: BACKOFF_SPIN(%o2, %o3, 1b)
5736 .size atomic_sub, .-atomic_sub
5737
5738 + .globl atomic_sub_unchecked
5739 + .type atomic_sub_unchecked,#function
5740 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5741 + BACKOFF_SETUP(%o2)
5742 +1: lduw [%o1], %g1
5743 + sub %g1, %o0, %g7
5744 + cas [%o1], %g1, %g7
5745 + cmp %g1, %g7
5746 + bne,pn %icc, 2f
5747 + nop
5748 + retl
5749 + nop
5750 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5751 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5752 +
5753 .globl atomic_add_ret
5754 .type atomic_add_ret,#function
5755 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5756 BACKOFF_SETUP(%o2)
5757 1: lduw [%o1], %g1
5758 - add %g1, %o0, %g7
5759 + addcc %g1, %o0, %g7
5760 +
5761 +#ifdef CONFIG_PAX_REFCOUNT
5762 + tvs %icc, 6
5763 +#endif
5764 +
5765 cas [%o1], %g1, %g7
5766 cmp %g1, %g7
5767 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5768 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5769 2: BACKOFF_SPIN(%o2, %o3, 1b)
5770 .size atomic_add_ret, .-atomic_add_ret
5771
5772 + .globl atomic_add_ret_unchecked
5773 + .type atomic_add_ret_unchecked,#function
5774 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5775 + BACKOFF_SETUP(%o2)
5776 +1: lduw [%o1], %g1
5777 + addcc %g1, %o0, %g7
5778 + cas [%o1], %g1, %g7
5779 + cmp %g1, %g7
5780 + bne,pn %icc, 2f
5781 + add %g7, %o0, %g7
5782 + sra %g7, 0, %o0
5783 + retl
5784 + nop
5785 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5786 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5787 +
5788 .globl atomic_sub_ret
5789 .type atomic_sub_ret,#function
5790 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5791 BACKOFF_SETUP(%o2)
5792 1: lduw [%o1], %g1
5793 - sub %g1, %o0, %g7
5794 + subcc %g1, %o0, %g7
5795 +
5796 +#ifdef CONFIG_PAX_REFCOUNT
5797 + tvs %icc, 6
5798 +#endif
5799 +
5800 cas [%o1], %g1, %g7
5801 cmp %g1, %g7
5802 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5803 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5804 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5805 BACKOFF_SETUP(%o2)
5806 1: ldx [%o1], %g1
5807 - add %g1, %o0, %g7
5808 + addcc %g1, %o0, %g7
5809 +
5810 +#ifdef CONFIG_PAX_REFCOUNT
5811 + tvs %xcc, 6
5812 +#endif
5813 +
5814 casx [%o1], %g1, %g7
5815 cmp %g1, %g7
5816 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5817 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5818 2: BACKOFF_SPIN(%o2, %o3, 1b)
5819 .size atomic64_add, .-atomic64_add
5820
5821 + .globl atomic64_add_unchecked
5822 + .type atomic64_add_unchecked,#function
5823 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5824 + BACKOFF_SETUP(%o2)
5825 +1: ldx [%o1], %g1
5826 + addcc %g1, %o0, %g7
5827 + casx [%o1], %g1, %g7
5828 + cmp %g1, %g7
5829 + bne,pn %xcc, 2f
5830 + nop
5831 + retl
5832 + nop
5833 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5834 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5835 +
5836 .globl atomic64_sub
5837 .type atomic64_sub,#function
5838 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5839 BACKOFF_SETUP(%o2)
5840 1: ldx [%o1], %g1
5841 - sub %g1, %o0, %g7
5842 + subcc %g1, %o0, %g7
5843 +
5844 +#ifdef CONFIG_PAX_REFCOUNT
5845 + tvs %xcc, 6
5846 +#endif
5847 +
5848 casx [%o1], %g1, %g7
5849 cmp %g1, %g7
5850 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5851 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5852 2: BACKOFF_SPIN(%o2, %o3, 1b)
5853 .size atomic64_sub, .-atomic64_sub
5854
5855 + .globl atomic64_sub_unchecked
5856 + .type atomic64_sub_unchecked,#function
5857 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5858 + BACKOFF_SETUP(%o2)
5859 +1: ldx [%o1], %g1
5860 + subcc %g1, %o0, %g7
5861 + casx [%o1], %g1, %g7
5862 + cmp %g1, %g7
5863 + bne,pn %xcc, 2f
5864 + nop
5865 + retl
5866 + nop
5867 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5868 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5869 +
5870 .globl atomic64_add_ret
5871 .type atomic64_add_ret,#function
5872 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5873 BACKOFF_SETUP(%o2)
5874 1: ldx [%o1], %g1
5875 - add %g1, %o0, %g7
5876 + addcc %g1, %o0, %g7
5877 +
5878 +#ifdef CONFIG_PAX_REFCOUNT
5879 + tvs %xcc, 6
5880 +#endif
5881 +
5882 casx [%o1], %g1, %g7
5883 cmp %g1, %g7
5884 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5885 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5886 2: BACKOFF_SPIN(%o2, %o3, 1b)
5887 .size atomic64_add_ret, .-atomic64_add_ret
5888
5889 + .globl atomic64_add_ret_unchecked
5890 + .type atomic64_add_ret_unchecked,#function
5891 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5892 + BACKOFF_SETUP(%o2)
5893 +1: ldx [%o1], %g1
5894 + addcc %g1, %o0, %g7
5895 + casx [%o1], %g1, %g7
5896 + cmp %g1, %g7
5897 + bne,pn %xcc, 2f
5898 + add %g7, %o0, %g7
5899 + mov %g7, %o0
5900 + retl
5901 + nop
5902 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5903 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5904 +
5905 .globl atomic64_sub_ret
5906 .type atomic64_sub_ret,#function
5907 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5908 BACKOFF_SETUP(%o2)
5909 1: ldx [%o1], %g1
5910 - sub %g1, %o0, %g7
5911 + subcc %g1, %o0, %g7
5912 +
5913 +#ifdef CONFIG_PAX_REFCOUNT
5914 + tvs %xcc, 6
5915 +#endif
5916 +
5917 casx [%o1], %g1, %g7
5918 cmp %g1, %g7
5919 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5920 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5921 index f73c224..662af10 100644
5922 --- a/arch/sparc/lib/ksyms.c
5923 +++ b/arch/sparc/lib/ksyms.c
5924 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
5925
5926 /* Atomic counter implementation. */
5927 EXPORT_SYMBOL(atomic_add);
5928 +EXPORT_SYMBOL(atomic_add_unchecked);
5929 EXPORT_SYMBOL(atomic_add_ret);
5930 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5931 EXPORT_SYMBOL(atomic_sub);
5932 +EXPORT_SYMBOL(atomic_sub_unchecked);
5933 EXPORT_SYMBOL(atomic_sub_ret);
5934 EXPORT_SYMBOL(atomic64_add);
5935 +EXPORT_SYMBOL(atomic64_add_unchecked);
5936 EXPORT_SYMBOL(atomic64_add_ret);
5937 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5938 EXPORT_SYMBOL(atomic64_sub);
5939 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5940 EXPORT_SYMBOL(atomic64_sub_ret);
5941
5942 /* Atomic bit operations. */
5943 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5944 index 301421c..e2535d1 100644
5945 --- a/arch/sparc/mm/Makefile
5946 +++ b/arch/sparc/mm/Makefile
5947 @@ -2,7 +2,7 @@
5948 #
5949
5950 asflags-y := -ansi
5951 -ccflags-y := -Werror
5952 +#ccflags-y := -Werror
5953
5954 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
5955 obj-y += fault_$(BITS).o
5956 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5957 index 8023fd7..c8e89e9 100644
5958 --- a/arch/sparc/mm/fault_32.c
5959 +++ b/arch/sparc/mm/fault_32.c
5960 @@ -21,6 +21,9 @@
5961 #include <linux/perf_event.h>
5962 #include <linux/interrupt.h>
5963 #include <linux/kdebug.h>
5964 +#include <linux/slab.h>
5965 +#include <linux/pagemap.h>
5966 +#include <linux/compiler.h>
5967
5968 #include <asm/system.h>
5969 #include <asm/page.h>
5970 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5971 return safe_compute_effective_address(regs, insn);
5972 }
5973
5974 +#ifdef CONFIG_PAX_PAGEEXEC
5975 +#ifdef CONFIG_PAX_DLRESOLVE
5976 +static void pax_emuplt_close(struct vm_area_struct *vma)
5977 +{
5978 + vma->vm_mm->call_dl_resolve = 0UL;
5979 +}
5980 +
5981 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5982 +{
5983 + unsigned int *kaddr;
5984 +
5985 + vmf->page = alloc_page(GFP_HIGHUSER);
5986 + if (!vmf->page)
5987 + return VM_FAULT_OOM;
5988 +
5989 + kaddr = kmap(vmf->page);
5990 + memset(kaddr, 0, PAGE_SIZE);
5991 + kaddr[0] = 0x9DE3BFA8U; /* save */
5992 + flush_dcache_page(vmf->page);
5993 + kunmap(vmf->page);
5994 + return VM_FAULT_MAJOR;
5995 +}
5996 +
5997 +static const struct vm_operations_struct pax_vm_ops = {
5998 + .close = pax_emuplt_close,
5999 + .fault = pax_emuplt_fault
6000 +};
6001 +
6002 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6003 +{
6004 + int ret;
6005 +
6006 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6007 + vma->vm_mm = current->mm;
6008 + vma->vm_start = addr;
6009 + vma->vm_end = addr + PAGE_SIZE;
6010 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6011 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6012 + vma->vm_ops = &pax_vm_ops;
6013 +
6014 + ret = insert_vm_struct(current->mm, vma);
6015 + if (ret)
6016 + return ret;
6017 +
6018 + ++current->mm->total_vm;
6019 + return 0;
6020 +}
6021 +#endif
6022 +
6023 +/*
6024 + * PaX: decide what to do with offenders (regs->pc = fault address)
6025 + *
6026 + * returns 1 when task should be killed
6027 + * 2 when patched PLT trampoline was detected
6028 + * 3 when unpatched PLT trampoline was detected
6029 + */
6030 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6031 +{
6032 +
6033 +#ifdef CONFIG_PAX_EMUPLT
6034 + int err;
6035 +
6036 + do { /* PaX: patched PLT emulation #1 */
6037 + unsigned int sethi1, sethi2, jmpl;
6038 +
6039 + err = get_user(sethi1, (unsigned int *)regs->pc);
6040 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6041 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6042 +
6043 + if (err)
6044 + break;
6045 +
6046 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6047 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6048 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6049 + {
6050 + unsigned int addr;
6051 +
6052 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6053 + addr = regs->u_regs[UREG_G1];
6054 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6055 + regs->pc = addr;
6056 + regs->npc = addr+4;
6057 + return 2;
6058 + }
6059 + } while (0);
6060 +
6061 + { /* PaX: patched PLT emulation #2 */
6062 + unsigned int ba;
6063 +
6064 + err = get_user(ba, (unsigned int *)regs->pc);
6065 +
6066 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6067 + unsigned int addr;
6068 +
6069 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6070 + regs->pc = addr;
6071 + regs->npc = addr+4;
6072 + return 2;
6073 + }
6074 + }
6075 +
6076 + do { /* PaX: patched PLT emulation #3 */
6077 + unsigned int sethi, jmpl, nop;
6078 +
6079 + err = get_user(sethi, (unsigned int *)regs->pc);
6080 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6081 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6082 +
6083 + if (err)
6084 + break;
6085 +
6086 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6087 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6088 + nop == 0x01000000U)
6089 + {
6090 + unsigned int addr;
6091 +
6092 + addr = (sethi & 0x003FFFFFU) << 10;
6093 + regs->u_regs[UREG_G1] = addr;
6094 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6095 + regs->pc = addr;
6096 + regs->npc = addr+4;
6097 + return 2;
6098 + }
6099 + } while (0);
6100 +
6101 + do { /* PaX: unpatched PLT emulation step 1 */
6102 + unsigned int sethi, ba, nop;
6103 +
6104 + err = get_user(sethi, (unsigned int *)regs->pc);
6105 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6106 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6107 +
6108 + if (err)
6109 + break;
6110 +
6111 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6112 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6113 + nop == 0x01000000U)
6114 + {
6115 + unsigned int addr, save, call;
6116 +
6117 + if ((ba & 0xFFC00000U) == 0x30800000U)
6118 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6119 + else
6120 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6121 +
6122 + err = get_user(save, (unsigned int *)addr);
6123 + err |= get_user(call, (unsigned int *)(addr+4));
6124 + err |= get_user(nop, (unsigned int *)(addr+8));
6125 + if (err)
6126 + break;
6127 +
6128 +#ifdef CONFIG_PAX_DLRESOLVE
6129 + if (save == 0x9DE3BFA8U &&
6130 + (call & 0xC0000000U) == 0x40000000U &&
6131 + nop == 0x01000000U)
6132 + {
6133 + struct vm_area_struct *vma;
6134 + unsigned long call_dl_resolve;
6135 +
6136 + down_read(&current->mm->mmap_sem);
6137 + call_dl_resolve = current->mm->call_dl_resolve;
6138 + up_read(&current->mm->mmap_sem);
6139 + if (likely(call_dl_resolve))
6140 + goto emulate;
6141 +
6142 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6143 +
6144 + down_write(&current->mm->mmap_sem);
6145 + if (current->mm->call_dl_resolve) {
6146 + call_dl_resolve = current->mm->call_dl_resolve;
6147 + up_write(&current->mm->mmap_sem);
6148 + if (vma)
6149 + kmem_cache_free(vm_area_cachep, vma);
6150 + goto emulate;
6151 + }
6152 +
6153 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6154 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6155 + up_write(&current->mm->mmap_sem);
6156 + if (vma)
6157 + kmem_cache_free(vm_area_cachep, vma);
6158 + return 1;
6159 + }
6160 +
6161 + if (pax_insert_vma(vma, call_dl_resolve)) {
6162 + up_write(&current->mm->mmap_sem);
6163 + kmem_cache_free(vm_area_cachep, vma);
6164 + return 1;
6165 + }
6166 +
6167 + current->mm->call_dl_resolve = call_dl_resolve;
6168 + up_write(&current->mm->mmap_sem);
6169 +
6170 +emulate:
6171 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6172 + regs->pc = call_dl_resolve;
6173 + regs->npc = addr+4;
6174 + return 3;
6175 + }
6176 +#endif
6177 +
6178 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6179 + if ((save & 0xFFC00000U) == 0x05000000U &&
6180 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6181 + nop == 0x01000000U)
6182 + {
6183 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6184 + regs->u_regs[UREG_G2] = addr + 4;
6185 + addr = (save & 0x003FFFFFU) << 10;
6186 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6187 + regs->pc = addr;
6188 + regs->npc = addr+4;
6189 + return 3;
6190 + }
6191 + }
6192 + } while (0);
6193 +
6194 + do { /* PaX: unpatched PLT emulation step 2 */
6195 + unsigned int save, call, nop;
6196 +
6197 + err = get_user(save, (unsigned int *)(regs->pc-4));
6198 + err |= get_user(call, (unsigned int *)regs->pc);
6199 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6200 + if (err)
6201 + break;
6202 +
6203 + if (save == 0x9DE3BFA8U &&
6204 + (call & 0xC0000000U) == 0x40000000U &&
6205 + nop == 0x01000000U)
6206 + {
6207 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6208 +
6209 + regs->u_regs[UREG_RETPC] = regs->pc;
6210 + regs->pc = dl_resolve;
6211 + regs->npc = dl_resolve+4;
6212 + return 3;
6213 + }
6214 + } while (0);
6215 +#endif
6216 +
6217 + return 1;
6218 +}
6219 +
6220 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6221 +{
6222 + unsigned long i;
6223 +
6224 + printk(KERN_ERR "PAX: bytes at PC: ");
6225 + for (i = 0; i < 8; i++) {
6226 + unsigned int c;
6227 + if (get_user(c, (unsigned int *)pc+i))
6228 + printk(KERN_CONT "???????? ");
6229 + else
6230 + printk(KERN_CONT "%08x ", c);
6231 + }
6232 + printk("\n");
6233 +}
6234 +#endif
6235 +
6236 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6237 int text_fault)
6238 {
6239 @@ -280,6 +545,24 @@ good_area:
6240 if(!(vma->vm_flags & VM_WRITE))
6241 goto bad_area;
6242 } else {
6243 +
6244 +#ifdef CONFIG_PAX_PAGEEXEC
6245 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6246 + up_read(&mm->mmap_sem);
6247 + switch (pax_handle_fetch_fault(regs)) {
6248 +
6249 +#ifdef CONFIG_PAX_EMUPLT
6250 + case 2:
6251 + case 3:
6252 + return;
6253 +#endif
6254 +
6255 + }
6256 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6257 + do_group_exit(SIGKILL);
6258 + }
6259 +#endif
6260 +
6261 /* Allow reads even for write-only mappings */
6262 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6263 goto bad_area;
6264 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6265 index 504c062..6fcb9c6 100644
6266 --- a/arch/sparc/mm/fault_64.c
6267 +++ b/arch/sparc/mm/fault_64.c
6268 @@ -21,6 +21,9 @@
6269 #include <linux/kprobes.h>
6270 #include <linux/kdebug.h>
6271 #include <linux/percpu.h>
6272 +#include <linux/slab.h>
6273 +#include <linux/pagemap.h>
6274 +#include <linux/compiler.h>
6275
6276 #include <asm/page.h>
6277 #include <asm/pgtable.h>
6278 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6279 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6280 regs->tpc);
6281 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6282 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6283 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6284 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6285 dump_stack();
6286 unhandled_fault(regs->tpc, current, regs);
6287 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6288 show_regs(regs);
6289 }
6290
6291 +#ifdef CONFIG_PAX_PAGEEXEC
6292 +#ifdef CONFIG_PAX_DLRESOLVE
6293 +static void pax_emuplt_close(struct vm_area_struct *vma)
6294 +{
6295 + vma->vm_mm->call_dl_resolve = 0UL;
6296 +}
6297 +
6298 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6299 +{
6300 + unsigned int *kaddr;
6301 +
6302 + vmf->page = alloc_page(GFP_HIGHUSER);
6303 + if (!vmf->page)
6304 + return VM_FAULT_OOM;
6305 +
6306 + kaddr = kmap(vmf->page);
6307 + memset(kaddr, 0, PAGE_SIZE);
6308 + kaddr[0] = 0x9DE3BFA8U; /* save */
6309 + flush_dcache_page(vmf->page);
6310 + kunmap(vmf->page);
6311 + return VM_FAULT_MAJOR;
6312 +}
6313 +
6314 +static const struct vm_operations_struct pax_vm_ops = {
6315 + .close = pax_emuplt_close,
6316 + .fault = pax_emuplt_fault
6317 +};
6318 +
6319 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6320 +{
6321 + int ret;
6322 +
6323 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6324 + vma->vm_mm = current->mm;
6325 + vma->vm_start = addr;
6326 + vma->vm_end = addr + PAGE_SIZE;
6327 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6328 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6329 + vma->vm_ops = &pax_vm_ops;
6330 +
6331 + ret = insert_vm_struct(current->mm, vma);
6332 + if (ret)
6333 + return ret;
6334 +
6335 + ++current->mm->total_vm;
6336 + return 0;
6337 +}
6338 +#endif
6339 +
6340 +/*
6341 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6342 + *
6343 + * returns 1 when task should be killed
6344 + * 2 when patched PLT trampoline was detected
6345 + * 3 when unpatched PLT trampoline was detected
6346 + */
6347 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6348 +{
6349 +
6350 +#ifdef CONFIG_PAX_EMUPLT
6351 + int err;
6352 +
6353 + do { /* PaX: patched PLT emulation #1 */
6354 + unsigned int sethi1, sethi2, jmpl;
6355 +
6356 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6357 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6358 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6359 +
6360 + if (err)
6361 + break;
6362 +
6363 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6364 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6365 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6366 + {
6367 + unsigned long addr;
6368 +
6369 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6370 + addr = regs->u_regs[UREG_G1];
6371 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6372 +
6373 + if (test_thread_flag(TIF_32BIT))
6374 + addr &= 0xFFFFFFFFUL;
6375 +
6376 + regs->tpc = addr;
6377 + regs->tnpc = addr+4;
6378 + return 2;
6379 + }
6380 + } while (0);
6381 +
6382 + { /* PaX: patched PLT emulation #2 */
6383 + unsigned int ba;
6384 +
6385 + err = get_user(ba, (unsigned int *)regs->tpc);
6386 +
6387 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6388 + unsigned long addr;
6389 +
6390 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6391 +
6392 + if (test_thread_flag(TIF_32BIT))
6393 + addr &= 0xFFFFFFFFUL;
6394 +
6395 + regs->tpc = addr;
6396 + regs->tnpc = addr+4;
6397 + return 2;
6398 + }
6399 + }
6400 +
6401 + do { /* PaX: patched PLT emulation #3 */
6402 + unsigned int sethi, jmpl, nop;
6403 +
6404 + err = get_user(sethi, (unsigned int *)regs->tpc);
6405 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6406 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6407 +
6408 + if (err)
6409 + break;
6410 +
6411 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6412 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6413 + nop == 0x01000000U)
6414 + {
6415 + unsigned long addr;
6416 +
6417 + addr = (sethi & 0x003FFFFFU) << 10;
6418 + regs->u_regs[UREG_G1] = addr;
6419 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6420 +
6421 + if (test_thread_flag(TIF_32BIT))
6422 + addr &= 0xFFFFFFFFUL;
6423 +
6424 + regs->tpc = addr;
6425 + regs->tnpc = addr+4;
6426 + return 2;
6427 + }
6428 + } while (0);
6429 +
6430 + do { /* PaX: patched PLT emulation #4 */
6431 + unsigned int sethi, mov1, call, mov2;
6432 +
6433 + err = get_user(sethi, (unsigned int *)regs->tpc);
6434 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6435 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6436 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6437 +
6438 + if (err)
6439 + break;
6440 +
6441 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6442 + mov1 == 0x8210000FU &&
6443 + (call & 0xC0000000U) == 0x40000000U &&
6444 + mov2 == 0x9E100001U)
6445 + {
6446 + unsigned long addr;
6447 +
6448 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6449 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6450 +
6451 + if (test_thread_flag(TIF_32BIT))
6452 + addr &= 0xFFFFFFFFUL;
6453 +
6454 + regs->tpc = addr;
6455 + regs->tnpc = addr+4;
6456 + return 2;
6457 + }
6458 + } while (0);
6459 +
6460 + do { /* PaX: patched PLT emulation #5 */
6461 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6462 +
6463 + err = get_user(sethi, (unsigned int *)regs->tpc);
6464 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6465 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6466 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6467 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6468 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6469 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6470 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6471 +
6472 + if (err)
6473 + break;
6474 +
6475 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6476 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6477 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6478 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6479 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6480 + sllx == 0x83287020U &&
6481 + jmpl == 0x81C04005U &&
6482 + nop == 0x01000000U)
6483 + {
6484 + unsigned long addr;
6485 +
6486 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6487 + regs->u_regs[UREG_G1] <<= 32;
6488 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6489 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6490 + regs->tpc = addr;
6491 + regs->tnpc = addr+4;
6492 + return 2;
6493 + }
6494 + } while (0);
6495 +
6496 + do { /* PaX: patched PLT emulation #6 */
6497 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6498 +
6499 + err = get_user(sethi, (unsigned int *)regs->tpc);
6500 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6501 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6502 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6503 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6504 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6505 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6506 +
6507 + if (err)
6508 + break;
6509 +
6510 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6511 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6512 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6513 + sllx == 0x83287020U &&
6514 + (or & 0xFFFFE000U) == 0x8A116000U &&
6515 + jmpl == 0x81C04005U &&
6516 + nop == 0x01000000U)
6517 + {
6518 + unsigned long addr;
6519 +
6520 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6521 + regs->u_regs[UREG_G1] <<= 32;
6522 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6523 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6524 + regs->tpc = addr;
6525 + regs->tnpc = addr+4;
6526 + return 2;
6527 + }
6528 + } while (0);
6529 +
6530 + do { /* PaX: unpatched PLT emulation step 1 */
6531 + unsigned int sethi, ba, nop;
6532 +
6533 + err = get_user(sethi, (unsigned int *)regs->tpc);
6534 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6535 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6536 +
6537 + if (err)
6538 + break;
6539 +
6540 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6541 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6542 + nop == 0x01000000U)
6543 + {
6544 + unsigned long addr;
6545 + unsigned int save, call;
6546 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6547 +
6548 + if ((ba & 0xFFC00000U) == 0x30800000U)
6549 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6550 + else
6551 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6552 +
6553 + if (test_thread_flag(TIF_32BIT))
6554 + addr &= 0xFFFFFFFFUL;
6555 +
6556 + err = get_user(save, (unsigned int *)addr);
6557 + err |= get_user(call, (unsigned int *)(addr+4));
6558 + err |= get_user(nop, (unsigned int *)(addr+8));
6559 + if (err)
6560 + break;
6561 +
6562 +#ifdef CONFIG_PAX_DLRESOLVE
6563 + if (save == 0x9DE3BFA8U &&
6564 + (call & 0xC0000000U) == 0x40000000U &&
6565 + nop == 0x01000000U)
6566 + {
6567 + struct vm_area_struct *vma;
6568 + unsigned long call_dl_resolve;
6569 +
6570 + down_read(&current->mm->mmap_sem);
6571 + call_dl_resolve = current->mm->call_dl_resolve;
6572 + up_read(&current->mm->mmap_sem);
6573 + if (likely(call_dl_resolve))
6574 + goto emulate;
6575 +
6576 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6577 +
6578 + down_write(&current->mm->mmap_sem);
6579 + if (current->mm->call_dl_resolve) {
6580 + call_dl_resolve = current->mm->call_dl_resolve;
6581 + up_write(&current->mm->mmap_sem);
6582 + if (vma)
6583 + kmem_cache_free(vm_area_cachep, vma);
6584 + goto emulate;
6585 + }
6586 +
6587 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6588 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6589 + up_write(&current->mm->mmap_sem);
6590 + if (vma)
6591 + kmem_cache_free(vm_area_cachep, vma);
6592 + return 1;
6593 + }
6594 +
6595 + if (pax_insert_vma(vma, call_dl_resolve)) {
6596 + up_write(&current->mm->mmap_sem);
6597 + kmem_cache_free(vm_area_cachep, vma);
6598 + return 1;
6599 + }
6600 +
6601 + current->mm->call_dl_resolve = call_dl_resolve;
6602 + up_write(&current->mm->mmap_sem);
6603 +
6604 +emulate:
6605 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6606 + regs->tpc = call_dl_resolve;
6607 + regs->tnpc = addr+4;
6608 + return 3;
6609 + }
6610 +#endif
6611 +
6612 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6613 + if ((save & 0xFFC00000U) == 0x05000000U &&
6614 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6615 + nop == 0x01000000U)
6616 + {
6617 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6618 + regs->u_regs[UREG_G2] = addr + 4;
6619 + addr = (save & 0x003FFFFFU) << 10;
6620 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6621 +
6622 + if (test_thread_flag(TIF_32BIT))
6623 + addr &= 0xFFFFFFFFUL;
6624 +
6625 + regs->tpc = addr;
6626 + regs->tnpc = addr+4;
6627 + return 3;
6628 + }
6629 +
6630 + /* PaX: 64-bit PLT stub */
6631 + err = get_user(sethi1, (unsigned int *)addr);
6632 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6633 + err |= get_user(or1, (unsigned int *)(addr+8));
6634 + err |= get_user(or2, (unsigned int *)(addr+12));
6635 + err |= get_user(sllx, (unsigned int *)(addr+16));
6636 + err |= get_user(add, (unsigned int *)(addr+20));
6637 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6638 + err |= get_user(nop, (unsigned int *)(addr+28));
6639 + if (err)
6640 + break;
6641 +
6642 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6643 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6644 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6645 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6646 + sllx == 0x89293020U &&
6647 + add == 0x8A010005U &&
6648 + jmpl == 0x89C14000U &&
6649 + nop == 0x01000000U)
6650 + {
6651 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6652 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6653 + regs->u_regs[UREG_G4] <<= 32;
6654 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6655 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6656 + regs->u_regs[UREG_G4] = addr + 24;
6657 + addr = regs->u_regs[UREG_G5];
6658 + regs->tpc = addr;
6659 + regs->tnpc = addr+4;
6660 + return 3;
6661 + }
6662 + }
6663 + } while (0);
6664 +
6665 +#ifdef CONFIG_PAX_DLRESOLVE
6666 + do { /* PaX: unpatched PLT emulation step 2 */
6667 + unsigned int save, call, nop;
6668 +
6669 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6670 + err |= get_user(call, (unsigned int *)regs->tpc);
6671 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6672 + if (err)
6673 + break;
6674 +
6675 + if (save == 0x9DE3BFA8U &&
6676 + (call & 0xC0000000U) == 0x40000000U &&
6677 + nop == 0x01000000U)
6678 + {
6679 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6680 +
6681 + if (test_thread_flag(TIF_32BIT))
6682 + dl_resolve &= 0xFFFFFFFFUL;
6683 +
6684 + regs->u_regs[UREG_RETPC] = regs->tpc;
6685 + regs->tpc = dl_resolve;
6686 + regs->tnpc = dl_resolve+4;
6687 + return 3;
6688 + }
6689 + } while (0);
6690 +#endif
6691 +
6692 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6693 + unsigned int sethi, ba, nop;
6694 +
6695 + err = get_user(sethi, (unsigned int *)regs->tpc);
6696 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6697 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6698 +
6699 + if (err)
6700 + break;
6701 +
6702 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6703 + (ba & 0xFFF00000U) == 0x30600000U &&
6704 + nop == 0x01000000U)
6705 + {
6706 + unsigned long addr;
6707 +
6708 + addr = (sethi & 0x003FFFFFU) << 10;
6709 + regs->u_regs[UREG_G1] = addr;
6710 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6711 +
6712 + if (test_thread_flag(TIF_32BIT))
6713 + addr &= 0xFFFFFFFFUL;
6714 +
6715 + regs->tpc = addr;
6716 + regs->tnpc = addr+4;
6717 + return 2;
6718 + }
6719 + } while (0);
6720 +
6721 +#endif
6722 +
6723 + return 1;
6724 +}
6725 +
6726 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6727 +{
6728 + unsigned long i;
6729 +
6730 + printk(KERN_ERR "PAX: bytes at PC: ");
6731 + for (i = 0; i < 8; i++) {
6732 + unsigned int c;
6733 + if (get_user(c, (unsigned int *)pc+i))
6734 + printk(KERN_CONT "???????? ");
6735 + else
6736 + printk(KERN_CONT "%08x ", c);
6737 + }
6738 + printk("\n");
6739 +}
6740 +#endif
6741 +
6742 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6743 {
6744 struct mm_struct *mm = current->mm;
6745 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6746 if (!vma)
6747 goto bad_area;
6748
6749 +#ifdef CONFIG_PAX_PAGEEXEC
6750 + /* PaX: detect ITLB misses on non-exec pages */
6751 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6752 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6753 + {
6754 + if (address != regs->tpc)
6755 + goto good_area;
6756 +
6757 + up_read(&mm->mmap_sem);
6758 + switch (pax_handle_fetch_fault(regs)) {
6759 +
6760 +#ifdef CONFIG_PAX_EMUPLT
6761 + case 2:
6762 + case 3:
6763 + return;
6764 +#endif
6765 +
6766 + }
6767 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6768 + do_group_exit(SIGKILL);
6769 + }
6770 +#endif
6771 +
6772 /* Pure DTLB misses do not tell us whether the fault causing
6773 * load/store/atomic was a write or not, it only says that there
6774 * was no match. So in such a case we (carefully) read the
6775 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6776 index 07e1453..0a7d9e9 100644
6777 --- a/arch/sparc/mm/hugetlbpage.c
6778 +++ b/arch/sparc/mm/hugetlbpage.c
6779 @@ -67,7 +67,7 @@ full_search:
6780 }
6781 return -ENOMEM;
6782 }
6783 - if (likely(!vma || addr + len <= vma->vm_start)) {
6784 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6785 /*
6786 * Remember the place where we stopped the search:
6787 */
6788 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6789 /* make sure it can fit in the remaining address space */
6790 if (likely(addr > len)) {
6791 vma = find_vma(mm, addr-len);
6792 - if (!vma || addr <= vma->vm_start) {
6793 + if (check_heap_stack_gap(vma, addr - len, len)) {
6794 /* remember the address as a hint for next time */
6795 return (mm->free_area_cache = addr-len);
6796 }
6797 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6798 if (unlikely(mm->mmap_base < len))
6799 goto bottomup;
6800
6801 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6802 + addr = mm->mmap_base - len;
6803
6804 do {
6805 + addr &= HPAGE_MASK;
6806 /*
6807 * Lookup failure means no vma is above this address,
6808 * else if new region fits below vma->vm_start,
6809 * return with success:
6810 */
6811 vma = find_vma(mm, addr);
6812 - if (likely(!vma || addr+len <= vma->vm_start)) {
6813 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6814 /* remember the address as a hint for next time */
6815 return (mm->free_area_cache = addr);
6816 }
6817 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6818 mm->cached_hole_size = vma->vm_start - addr;
6819
6820 /* try just below the current vma->vm_start */
6821 - addr = (vma->vm_start-len) & HPAGE_MASK;
6822 - } while (likely(len < vma->vm_start));
6823 + addr = skip_heap_stack_gap(vma, len);
6824 + } while (!IS_ERR_VALUE(addr));
6825
6826 bottomup:
6827 /*
6828 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6829 if (addr) {
6830 addr = ALIGN(addr, HPAGE_SIZE);
6831 vma = find_vma(mm, addr);
6832 - if (task_size - len >= addr &&
6833 - (!vma || addr + len <= vma->vm_start))
6834 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6835 return addr;
6836 }
6837 if (mm->get_unmapped_area == arch_get_unmapped_area)
6838 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6839 index 7b00de6..78239f4 100644
6840 --- a/arch/sparc/mm/init_32.c
6841 +++ b/arch/sparc/mm/init_32.c
6842 @@ -316,6 +316,9 @@ extern void device_scan(void);
6843 pgprot_t PAGE_SHARED __read_mostly;
6844 EXPORT_SYMBOL(PAGE_SHARED);
6845
6846 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6847 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6848 +
6849 void __init paging_init(void)
6850 {
6851 switch(sparc_cpu_model) {
6852 @@ -344,17 +347,17 @@ void __init paging_init(void)
6853
6854 /* Initialize the protection map with non-constant, MMU dependent values. */
6855 protection_map[0] = PAGE_NONE;
6856 - protection_map[1] = PAGE_READONLY;
6857 - protection_map[2] = PAGE_COPY;
6858 - protection_map[3] = PAGE_COPY;
6859 + protection_map[1] = PAGE_READONLY_NOEXEC;
6860 + protection_map[2] = PAGE_COPY_NOEXEC;
6861 + protection_map[3] = PAGE_COPY_NOEXEC;
6862 protection_map[4] = PAGE_READONLY;
6863 protection_map[5] = PAGE_READONLY;
6864 protection_map[6] = PAGE_COPY;
6865 protection_map[7] = PAGE_COPY;
6866 protection_map[8] = PAGE_NONE;
6867 - protection_map[9] = PAGE_READONLY;
6868 - protection_map[10] = PAGE_SHARED;
6869 - protection_map[11] = PAGE_SHARED;
6870 + protection_map[9] = PAGE_READONLY_NOEXEC;
6871 + protection_map[10] = PAGE_SHARED_NOEXEC;
6872 + protection_map[11] = PAGE_SHARED_NOEXEC;
6873 protection_map[12] = PAGE_READONLY;
6874 protection_map[13] = PAGE_READONLY;
6875 protection_map[14] = PAGE_SHARED;
6876 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6877 index cbef74e..c38fead 100644
6878 --- a/arch/sparc/mm/srmmu.c
6879 +++ b/arch/sparc/mm/srmmu.c
6880 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6881 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6882 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6883 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6884 +
6885 +#ifdef CONFIG_PAX_PAGEEXEC
6886 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6887 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6888 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6889 +#endif
6890 +
6891 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6892 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6893
6894 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
6895 index 27fe667..36d474c 100644
6896 --- a/arch/tile/include/asm/atomic_64.h
6897 +++ b/arch/tile/include/asm/atomic_64.h
6898 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6899
6900 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6901
6902 +#define atomic64_read_unchecked(v) atomic64_read(v)
6903 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6904 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6905 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6906 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6907 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6908 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6909 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6910 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6911 +
6912 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
6913 #define smp_mb__before_atomic_dec() smp_mb()
6914 #define smp_mb__after_atomic_dec() smp_mb()
6915 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
6916 index 392e533..536b092 100644
6917 --- a/arch/tile/include/asm/cache.h
6918 +++ b/arch/tile/include/asm/cache.h
6919 @@ -15,11 +15,12 @@
6920 #ifndef _ASM_TILE_CACHE_H
6921 #define _ASM_TILE_CACHE_H
6922
6923 +#include <linux/const.h>
6924 #include <arch/chip.h>
6925
6926 /* bytes per L1 data cache line */
6927 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
6928 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6929 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6930
6931 /* bytes per L2 cache line */
6932 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
6933 diff --git a/arch/um/Makefile b/arch/um/Makefile
6934 index 28688e6..4c0aa1c 100644
6935 --- a/arch/um/Makefile
6936 +++ b/arch/um/Makefile
6937 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6938 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6939 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
6940
6941 +ifdef CONSTIFY_PLUGIN
6942 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6943 +endif
6944 +
6945 #This will adjust *FLAGS accordingly to the platform.
6946 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
6947
6948 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
6949 index 19e1bdd..3665b77 100644
6950 --- a/arch/um/include/asm/cache.h
6951 +++ b/arch/um/include/asm/cache.h
6952 @@ -1,6 +1,7 @@
6953 #ifndef __UM_CACHE_H
6954 #define __UM_CACHE_H
6955
6956 +#include <linux/const.h>
6957
6958 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
6959 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6960 @@ -12,6 +13,6 @@
6961 # define L1_CACHE_SHIFT 5
6962 #endif
6963
6964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6966
6967 #endif
6968 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6969 index 6c03acd..a5e0215 100644
6970 --- a/arch/um/include/asm/kmap_types.h
6971 +++ b/arch/um/include/asm/kmap_types.h
6972 @@ -23,6 +23,7 @@ enum km_type {
6973 KM_IRQ1,
6974 KM_SOFTIRQ0,
6975 KM_SOFTIRQ1,
6976 + KM_CLEARPAGE,
6977 KM_TYPE_NR
6978 };
6979
6980 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6981 index 7cfc3ce..cbd1a58 100644
6982 --- a/arch/um/include/asm/page.h
6983 +++ b/arch/um/include/asm/page.h
6984 @@ -14,6 +14,9 @@
6985 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6986 #define PAGE_MASK (~(PAGE_SIZE-1))
6987
6988 +#define ktla_ktva(addr) (addr)
6989 +#define ktva_ktla(addr) (addr)
6990 +
6991 #ifndef __ASSEMBLY__
6992
6993 struct page;
6994 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6995 index 69f2490..2634831 100644
6996 --- a/arch/um/kernel/process.c
6997 +++ b/arch/um/kernel/process.c
6998 @@ -408,22 +408,6 @@ int singlestepping(void * t)
6999 return 2;
7000 }
7001
7002 -/*
7003 - * Only x86 and x86_64 have an arch_align_stack().
7004 - * All other arches have "#define arch_align_stack(x) (x)"
7005 - * in their asm/system.h
7006 - * As this is included in UML from asm-um/system-generic.h,
7007 - * we can use it to behave as the subarch does.
7008 - */
7009 -#ifndef arch_align_stack
7010 -unsigned long arch_align_stack(unsigned long sp)
7011 -{
7012 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7013 - sp -= get_random_int() % 8192;
7014 - return sp & ~0xf;
7015 -}
7016 -#endif
7017 -
7018 unsigned long get_wchan(struct task_struct *p)
7019 {
7020 unsigned long stack_page, sp, ip;
7021 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7022 index ad8f795..2c7eec6 100644
7023 --- a/arch/unicore32/include/asm/cache.h
7024 +++ b/arch/unicore32/include/asm/cache.h
7025 @@ -12,8 +12,10 @@
7026 #ifndef __UNICORE_CACHE_H__
7027 #define __UNICORE_CACHE_H__
7028
7029 -#define L1_CACHE_SHIFT (5)
7030 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7031 +#include <linux/const.h>
7032 +
7033 +#define L1_CACHE_SHIFT 5
7034 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7035
7036 /*
7037 * Memory returned by kmalloc() may be used for DMA, so we must make
7038 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7039 index 5bed94e..fbcf200 100644
7040 --- a/arch/x86/Kconfig
7041 +++ b/arch/x86/Kconfig
7042 @@ -226,7 +226,7 @@ config X86_HT
7043
7044 config X86_32_LAZY_GS
7045 def_bool y
7046 - depends on X86_32 && !CC_STACKPROTECTOR
7047 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7048
7049 config ARCH_HWEIGHT_CFLAGS
7050 string
7051 @@ -1058,7 +1058,7 @@ choice
7052
7053 config NOHIGHMEM
7054 bool "off"
7055 - depends on !X86_NUMAQ
7056 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7057 ---help---
7058 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7059 However, the address space of 32-bit x86 processors is only 4
7060 @@ -1095,7 +1095,7 @@ config NOHIGHMEM
7061
7062 config HIGHMEM4G
7063 bool "4GB"
7064 - depends on !X86_NUMAQ
7065 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7066 ---help---
7067 Select this if you have a 32-bit processor and between 1 and 4
7068 gigabytes of physical RAM.
7069 @@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7070 hex
7071 default 0xB0000000 if VMSPLIT_3G_OPT
7072 default 0x80000000 if VMSPLIT_2G
7073 - default 0x78000000 if VMSPLIT_2G_OPT
7074 + default 0x70000000 if VMSPLIT_2G_OPT
7075 default 0x40000000 if VMSPLIT_1G
7076 default 0xC0000000
7077 depends on X86_32
7078 @@ -1539,6 +1539,7 @@ config SECCOMP
7079
7080 config CC_STACKPROTECTOR
7081 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7082 + depends on X86_64 || !PAX_MEMORY_UDEREF
7083 ---help---
7084 This option turns on the -fstack-protector GCC feature. This
7085 feature puts, at the beginning of functions, a canary value on
7086 @@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7087 config PHYSICAL_START
7088 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7089 default "0x1000000"
7090 + range 0x400000 0x40000000
7091 ---help---
7092 This gives the physical address where the kernel is loaded.
7093
7094 @@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7095 config PHYSICAL_ALIGN
7096 hex "Alignment value to which kernel should be aligned" if X86_32
7097 default "0x1000000"
7098 + range 0x400000 0x1000000 if PAX_KERNEXEC
7099 range 0x2000 0x1000000
7100 ---help---
7101 This value puts the alignment restrictions on physical address
7102 @@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7103 Say N if you want to disable CPU hotplug.
7104
7105 config COMPAT_VDSO
7106 - def_bool y
7107 + def_bool n
7108 prompt "Compat VDSO support"
7109 depends on X86_32 || IA32_EMULATION
7110 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7111 ---help---
7112 Map the 32-bit VDSO to the predictable old-style address too.
7113
7114 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7115 index 3c57033..22d44aa 100644
7116 --- a/arch/x86/Kconfig.cpu
7117 +++ b/arch/x86/Kconfig.cpu
7118 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7119
7120 config X86_F00F_BUG
7121 def_bool y
7122 - depends on M586MMX || M586TSC || M586 || M486 || M386
7123 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7124
7125 config X86_INVD_BUG
7126 def_bool y
7127 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7128
7129 config X86_ALIGNMENT_16
7130 def_bool y
7131 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7132 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7133
7134 config X86_INTEL_USERCOPY
7135 def_bool y
7136 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7137 # generates cmov.
7138 config X86_CMOV
7139 def_bool y
7140 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7141 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7142
7143 config X86_MINIMUM_CPU_FAMILY
7144 int
7145 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7146 index e46c214..7c72b55 100644
7147 --- a/arch/x86/Kconfig.debug
7148 +++ b/arch/x86/Kconfig.debug
7149 @@ -84,7 +84,7 @@ config X86_PTDUMP
7150 config DEBUG_RODATA
7151 bool "Write protect kernel read-only data structures"
7152 default y
7153 - depends on DEBUG_KERNEL
7154 + depends on DEBUG_KERNEL && BROKEN
7155 ---help---
7156 Mark the kernel read-only data as write-protected in the pagetables,
7157 in order to catch accidental (and incorrect) writes to such const
7158 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7159
7160 config DEBUG_SET_MODULE_RONX
7161 bool "Set loadable kernel module data as NX and text as RO"
7162 - depends on MODULES
7163 + depends on MODULES && BROKEN
7164 ---help---
7165 This option helps catch unintended modifications to loadable
7166 kernel module's text and read-only data. It also prevents execution
7167 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7168 index 209ba12..15140db 100644
7169 --- a/arch/x86/Makefile
7170 +++ b/arch/x86/Makefile
7171 @@ -46,6 +46,7 @@ else
7172 UTS_MACHINE := x86_64
7173 CHECKFLAGS += -D__x86_64__ -m64
7174
7175 + biarch := $(call cc-option,-m64)
7176 KBUILD_AFLAGS += -m64
7177 KBUILD_CFLAGS += -m64
7178
7179 @@ -201,3 +202,12 @@ define archhelp
7180 echo ' FDARGS="..." arguments for the booted kernel'
7181 echo ' FDINITRD=file initrd for the booted kernel'
7182 endef
7183 +
7184 +define OLD_LD
7185 +
7186 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7187 +*** Please upgrade your binutils to 2.18 or newer
7188 +endef
7189 +
7190 +archprepare:
7191 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7192 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7193 index 95365a8..52f857b 100644
7194 --- a/arch/x86/boot/Makefile
7195 +++ b/arch/x86/boot/Makefile
7196 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7197 $(call cc-option, -fno-stack-protector) \
7198 $(call cc-option, -mpreferred-stack-boundary=2)
7199 KBUILD_CFLAGS += $(call cc-option, -m32)
7200 +ifdef CONSTIFY_PLUGIN
7201 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7202 +endif
7203 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7204 GCOV_PROFILE := n
7205
7206 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7207 index 878e4b9..20537ab 100644
7208 --- a/arch/x86/boot/bitops.h
7209 +++ b/arch/x86/boot/bitops.h
7210 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7211 u8 v;
7212 const u32 *p = (const u32 *)addr;
7213
7214 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7215 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7216 return v;
7217 }
7218
7219 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7220
7221 static inline void set_bit(int nr, void *addr)
7222 {
7223 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7224 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7225 }
7226
7227 #endif /* BOOT_BITOPS_H */
7228 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7229 index c7093bd..d4247ffe0 100644
7230 --- a/arch/x86/boot/boot.h
7231 +++ b/arch/x86/boot/boot.h
7232 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7233 static inline u16 ds(void)
7234 {
7235 u16 seg;
7236 - asm("movw %%ds,%0" : "=rm" (seg));
7237 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7238 return seg;
7239 }
7240
7241 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7242 static inline int memcmp(const void *s1, const void *s2, size_t len)
7243 {
7244 u8 diff;
7245 - asm("repe; cmpsb; setnz %0"
7246 + asm volatile("repe; cmpsb; setnz %0"
7247 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7248 return diff;
7249 }
7250 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7251 index b123b9a..2cf2f23 100644
7252 --- a/arch/x86/boot/compressed/Makefile
7253 +++ b/arch/x86/boot/compressed/Makefile
7254 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7255 KBUILD_CFLAGS += $(cflags-y)
7256 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7257 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7258 +ifdef CONSTIFY_PLUGIN
7259 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7260 +endif
7261
7262 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7263 GCOV_PROFILE := n
7264 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7265 index a055993..47e126c 100644
7266 --- a/arch/x86/boot/compressed/head_32.S
7267 +++ b/arch/x86/boot/compressed/head_32.S
7268 @@ -98,7 +98,7 @@ preferred_addr:
7269 notl %eax
7270 andl %eax, %ebx
7271 #else
7272 - movl $LOAD_PHYSICAL_ADDR, %ebx
7273 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7274 #endif
7275
7276 /* Target address to relocate to for decompression */
7277 @@ -184,7 +184,7 @@ relocated:
7278 * and where it was actually loaded.
7279 */
7280 movl %ebp, %ebx
7281 - subl $LOAD_PHYSICAL_ADDR, %ebx
7282 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7283 jz 2f /* Nothing to be done if loaded at compiled addr. */
7284 /*
7285 * Process relocations.
7286 @@ -192,8 +192,7 @@ relocated:
7287
7288 1: subl $4, %edi
7289 movl (%edi), %ecx
7290 - testl %ecx, %ecx
7291 - jz 2f
7292 + jecxz 2f
7293 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7294 jmp 1b
7295 2:
7296 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7297 index 558d76c..606aa24 100644
7298 --- a/arch/x86/boot/compressed/head_64.S
7299 +++ b/arch/x86/boot/compressed/head_64.S
7300 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7301 notl %eax
7302 andl %eax, %ebx
7303 #else
7304 - movl $LOAD_PHYSICAL_ADDR, %ebx
7305 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7306 #endif
7307
7308 /* Target address to relocate to for decompression */
7309 @@ -253,7 +253,7 @@ preferred_addr:
7310 notq %rax
7311 andq %rax, %rbp
7312 #else
7313 - movq $LOAD_PHYSICAL_ADDR, %rbp
7314 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7315 #endif
7316
7317 /* Target address to relocate to for decompression */
7318 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7319 index 7116dcb..d9ae1d7 100644
7320 --- a/arch/x86/boot/compressed/misc.c
7321 +++ b/arch/x86/boot/compressed/misc.c
7322 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7323 case PT_LOAD:
7324 #ifdef CONFIG_RELOCATABLE
7325 dest = output;
7326 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7327 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7328 #else
7329 dest = (void *)(phdr->p_paddr);
7330 #endif
7331 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7332 error("Destination address too large");
7333 #endif
7334 #ifndef CONFIG_RELOCATABLE
7335 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7336 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7337 error("Wrong destination address");
7338 #endif
7339
7340 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7341 index 89bbf4e..869908e 100644
7342 --- a/arch/x86/boot/compressed/relocs.c
7343 +++ b/arch/x86/boot/compressed/relocs.c
7344 @@ -13,8 +13,11 @@
7345
7346 static void die(char *fmt, ...);
7347
7348 +#include "../../../../include/generated/autoconf.h"
7349 +
7350 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7351 static Elf32_Ehdr ehdr;
7352 +static Elf32_Phdr *phdr;
7353 static unsigned long reloc_count, reloc_idx;
7354 static unsigned long *relocs;
7355
7356 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7357 }
7358 }
7359
7360 +static void read_phdrs(FILE *fp)
7361 +{
7362 + unsigned int i;
7363 +
7364 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7365 + if (!phdr) {
7366 + die("Unable to allocate %d program headers\n",
7367 + ehdr.e_phnum);
7368 + }
7369 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7370 + die("Seek to %d failed: %s\n",
7371 + ehdr.e_phoff, strerror(errno));
7372 + }
7373 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7374 + die("Cannot read ELF program headers: %s\n",
7375 + strerror(errno));
7376 + }
7377 + for(i = 0; i < ehdr.e_phnum; i++) {
7378 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7379 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7380 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7381 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7382 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7383 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7384 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7385 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7386 + }
7387 +
7388 +}
7389 +
7390 static void read_shdrs(FILE *fp)
7391 {
7392 - int i;
7393 + unsigned int i;
7394 Elf32_Shdr shdr;
7395
7396 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7397 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7398
7399 static void read_strtabs(FILE *fp)
7400 {
7401 - int i;
7402 + unsigned int i;
7403 for (i = 0; i < ehdr.e_shnum; i++) {
7404 struct section *sec = &secs[i];
7405 if (sec->shdr.sh_type != SHT_STRTAB) {
7406 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7407
7408 static void read_symtabs(FILE *fp)
7409 {
7410 - int i,j;
7411 + unsigned int i,j;
7412 for (i = 0; i < ehdr.e_shnum; i++) {
7413 struct section *sec = &secs[i];
7414 if (sec->shdr.sh_type != SHT_SYMTAB) {
7415 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7416
7417 static void read_relocs(FILE *fp)
7418 {
7419 - int i,j;
7420 + unsigned int i,j;
7421 + uint32_t base;
7422 +
7423 for (i = 0; i < ehdr.e_shnum; i++) {
7424 struct section *sec = &secs[i];
7425 if (sec->shdr.sh_type != SHT_REL) {
7426 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7427 die("Cannot read symbol table: %s\n",
7428 strerror(errno));
7429 }
7430 + base = 0;
7431 + for (j = 0; j < ehdr.e_phnum; j++) {
7432 + if (phdr[j].p_type != PT_LOAD )
7433 + continue;
7434 + 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)
7435 + continue;
7436 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7437 + break;
7438 + }
7439 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7440 Elf32_Rel *rel = &sec->reltab[j];
7441 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7442 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7443 rel->r_info = elf32_to_cpu(rel->r_info);
7444 }
7445 }
7446 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7447
7448 static void print_absolute_symbols(void)
7449 {
7450 - int i;
7451 + unsigned int i;
7452 printf("Absolute symbols\n");
7453 printf(" Num: Value Size Type Bind Visibility Name\n");
7454 for (i = 0; i < ehdr.e_shnum; i++) {
7455 struct section *sec = &secs[i];
7456 char *sym_strtab;
7457 Elf32_Sym *sh_symtab;
7458 - int j;
7459 + unsigned int j;
7460
7461 if (sec->shdr.sh_type != SHT_SYMTAB) {
7462 continue;
7463 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7464
7465 static void print_absolute_relocs(void)
7466 {
7467 - int i, printed = 0;
7468 + unsigned int i, printed = 0;
7469
7470 for (i = 0; i < ehdr.e_shnum; i++) {
7471 struct section *sec = &secs[i];
7472 struct section *sec_applies, *sec_symtab;
7473 char *sym_strtab;
7474 Elf32_Sym *sh_symtab;
7475 - int j;
7476 + unsigned int j;
7477 if (sec->shdr.sh_type != SHT_REL) {
7478 continue;
7479 }
7480 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7481
7482 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7483 {
7484 - int i;
7485 + unsigned int i;
7486 /* Walk through the relocations */
7487 for (i = 0; i < ehdr.e_shnum; i++) {
7488 char *sym_strtab;
7489 Elf32_Sym *sh_symtab;
7490 struct section *sec_applies, *sec_symtab;
7491 - int j;
7492 + unsigned int j;
7493 struct section *sec = &secs[i];
7494
7495 if (sec->shdr.sh_type != SHT_REL) {
7496 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7497 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7498 continue;
7499 }
7500 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7501 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7502 + continue;
7503 +
7504 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7505 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7506 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7507 + continue;
7508 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7509 + continue;
7510 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7511 + continue;
7512 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7513 + continue;
7514 +#endif
7515 +
7516 switch (r_type) {
7517 case R_386_NONE:
7518 case R_386_PC32:
7519 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7520
7521 static void emit_relocs(int as_text)
7522 {
7523 - int i;
7524 + unsigned int i;
7525 /* Count how many relocations I have and allocate space for them. */
7526 reloc_count = 0;
7527 walk_relocs(count_reloc);
7528 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7529 fname, strerror(errno));
7530 }
7531 read_ehdr(fp);
7532 + read_phdrs(fp);
7533 read_shdrs(fp);
7534 read_strtabs(fp);
7535 read_symtabs(fp);
7536 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7537 index 4d3ff03..e4972ff 100644
7538 --- a/arch/x86/boot/cpucheck.c
7539 +++ b/arch/x86/boot/cpucheck.c
7540 @@ -74,7 +74,7 @@ static int has_fpu(void)
7541 u16 fcw = -1, fsw = -1;
7542 u32 cr0;
7543
7544 - asm("movl %%cr0,%0" : "=r" (cr0));
7545 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7546 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7547 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7548 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7549 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7550 {
7551 u32 f0, f1;
7552
7553 - asm("pushfl ; "
7554 + asm volatile("pushfl ; "
7555 "pushfl ; "
7556 "popl %0 ; "
7557 "movl %0,%1 ; "
7558 @@ -115,7 +115,7 @@ static void get_flags(void)
7559 set_bit(X86_FEATURE_FPU, cpu.flags);
7560
7561 if (has_eflag(X86_EFLAGS_ID)) {
7562 - asm("cpuid"
7563 + asm volatile("cpuid"
7564 : "=a" (max_intel_level),
7565 "=b" (cpu_vendor[0]),
7566 "=d" (cpu_vendor[1]),
7567 @@ -124,7 +124,7 @@ static void get_flags(void)
7568
7569 if (max_intel_level >= 0x00000001 &&
7570 max_intel_level <= 0x0000ffff) {
7571 - asm("cpuid"
7572 + asm volatile("cpuid"
7573 : "=a" (tfms),
7574 "=c" (cpu.flags[4]),
7575 "=d" (cpu.flags[0])
7576 @@ -136,7 +136,7 @@ static void get_flags(void)
7577 cpu.model += ((tfms >> 16) & 0xf) << 4;
7578 }
7579
7580 - asm("cpuid"
7581 + asm volatile("cpuid"
7582 : "=a" (max_amd_level)
7583 : "a" (0x80000000)
7584 : "ebx", "ecx", "edx");
7585 @@ -144,7 +144,7 @@ static void get_flags(void)
7586 if (max_amd_level >= 0x80000001 &&
7587 max_amd_level <= 0x8000ffff) {
7588 u32 eax = 0x80000001;
7589 - asm("cpuid"
7590 + asm volatile("cpuid"
7591 : "+a" (eax),
7592 "=c" (cpu.flags[6]),
7593 "=d" (cpu.flags[1])
7594 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7595 u32 ecx = MSR_K7_HWCR;
7596 u32 eax, edx;
7597
7598 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7599 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7600 eax &= ~(1 << 15);
7601 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7602 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7603
7604 get_flags(); /* Make sure it really did something */
7605 err = check_flags();
7606 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7607 u32 ecx = MSR_VIA_FCR;
7608 u32 eax, edx;
7609
7610 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7611 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7612 eax |= (1<<1)|(1<<7);
7613 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7614 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7615
7616 set_bit(X86_FEATURE_CX8, cpu.flags);
7617 err = check_flags();
7618 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7619 u32 eax, edx;
7620 u32 level = 1;
7621
7622 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7623 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7624 - asm("cpuid"
7625 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7626 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7627 + asm volatile("cpuid"
7628 : "+a" (level), "=d" (cpu.flags[0])
7629 : : "ecx", "ebx");
7630 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7631 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7632
7633 err = check_flags();
7634 }
7635 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7636 index f1bbeeb..aff09cb 100644
7637 --- a/arch/x86/boot/header.S
7638 +++ b/arch/x86/boot/header.S
7639 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7640 # single linked list of
7641 # struct setup_data
7642
7643 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7644 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7645
7646 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7647 #define VO_INIT_SIZE (VO__end - VO__text)
7648 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7649 index db75d07..8e6d0af 100644
7650 --- a/arch/x86/boot/memory.c
7651 +++ b/arch/x86/boot/memory.c
7652 @@ -19,7 +19,7 @@
7653
7654 static int detect_memory_e820(void)
7655 {
7656 - int count = 0;
7657 + unsigned int count = 0;
7658 struct biosregs ireg, oreg;
7659 struct e820entry *desc = boot_params.e820_map;
7660 static struct e820entry buf; /* static so it is zeroed */
7661 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7662 index 11e8c6e..fdbb1ed 100644
7663 --- a/arch/x86/boot/video-vesa.c
7664 +++ b/arch/x86/boot/video-vesa.c
7665 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7666
7667 boot_params.screen_info.vesapm_seg = oreg.es;
7668 boot_params.screen_info.vesapm_off = oreg.di;
7669 + boot_params.screen_info.vesapm_size = oreg.cx;
7670 }
7671
7672 /*
7673 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7674 index 43eda28..5ab5fdb 100644
7675 --- a/arch/x86/boot/video.c
7676 +++ b/arch/x86/boot/video.c
7677 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7678 static unsigned int get_entry(void)
7679 {
7680 char entry_buf[4];
7681 - int i, len = 0;
7682 + unsigned int i, len = 0;
7683 int key;
7684 unsigned int v;
7685
7686 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7687 index 5b577d5..3c1fed4 100644
7688 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7689 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7690 @@ -8,6 +8,8 @@
7691 * including this sentence is retained in full.
7692 */
7693
7694 +#include <asm/alternative-asm.h>
7695 +
7696 .extern crypto_ft_tab
7697 .extern crypto_it_tab
7698 .extern crypto_fl_tab
7699 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7700 je B192; \
7701 leaq 32(r9),r9;
7702
7703 +#define ret pax_force_retaddr 0, 1; ret
7704 +
7705 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7706 movq r1,r2; \
7707 movq r3,r4; \
7708 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7709 index be6d9e3..21fbbca 100644
7710 --- a/arch/x86/crypto/aesni-intel_asm.S
7711 +++ b/arch/x86/crypto/aesni-intel_asm.S
7712 @@ -31,6 +31,7 @@
7713
7714 #include <linux/linkage.h>
7715 #include <asm/inst.h>
7716 +#include <asm/alternative-asm.h>
7717
7718 #ifdef __x86_64__
7719 .data
7720 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7721 pop %r14
7722 pop %r13
7723 pop %r12
7724 + pax_force_retaddr 0, 1
7725 ret
7726 +ENDPROC(aesni_gcm_dec)
7727
7728
7729 /*****************************************************************************
7730 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7731 pop %r14
7732 pop %r13
7733 pop %r12
7734 + pax_force_retaddr 0, 1
7735 ret
7736 +ENDPROC(aesni_gcm_enc)
7737
7738 #endif
7739
7740 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
7741 pxor %xmm1, %xmm0
7742 movaps %xmm0, (TKEYP)
7743 add $0x10, TKEYP
7744 + pax_force_retaddr_bts
7745 ret
7746
7747 .align 4
7748 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
7749 shufps $0b01001110, %xmm2, %xmm1
7750 movaps %xmm1, 0x10(TKEYP)
7751 add $0x20, TKEYP
7752 + pax_force_retaddr_bts
7753 ret
7754
7755 .align 4
7756 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
7757
7758 movaps %xmm0, (TKEYP)
7759 add $0x10, TKEYP
7760 + pax_force_retaddr_bts
7761 ret
7762
7763 .align 4
7764 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
7765 pxor %xmm1, %xmm2
7766 movaps %xmm2, (TKEYP)
7767 add $0x10, TKEYP
7768 + pax_force_retaddr_bts
7769 ret
7770
7771 /*
7772 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7773 #ifndef __x86_64__
7774 popl KEYP
7775 #endif
7776 + pax_force_retaddr 0, 1
7777 ret
7778 +ENDPROC(aesni_set_key)
7779
7780 /*
7781 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7782 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7783 popl KLEN
7784 popl KEYP
7785 #endif
7786 + pax_force_retaddr 0, 1
7787 ret
7788 +ENDPROC(aesni_enc)
7789
7790 /*
7791 * _aesni_enc1: internal ABI
7792 @@ -1959,6 +1972,7 @@ _aesni_enc1:
7793 AESENC KEY STATE
7794 movaps 0x70(TKEYP), KEY
7795 AESENCLAST KEY STATE
7796 + pax_force_retaddr_bts
7797 ret
7798
7799 /*
7800 @@ -2067,6 +2081,7 @@ _aesni_enc4:
7801 AESENCLAST KEY STATE2
7802 AESENCLAST KEY STATE3
7803 AESENCLAST KEY STATE4
7804 + pax_force_retaddr_bts
7805 ret
7806
7807 /*
7808 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7809 popl KLEN
7810 popl KEYP
7811 #endif
7812 + pax_force_retaddr 0, 1
7813 ret
7814 +ENDPROC(aesni_dec)
7815
7816 /*
7817 * _aesni_dec1: internal ABI
7818 @@ -2146,6 +2163,7 @@ _aesni_dec1:
7819 AESDEC KEY STATE
7820 movaps 0x70(TKEYP), KEY
7821 AESDECLAST KEY STATE
7822 + pax_force_retaddr_bts
7823 ret
7824
7825 /*
7826 @@ -2254,6 +2272,7 @@ _aesni_dec4:
7827 AESDECLAST KEY STATE2
7828 AESDECLAST KEY STATE3
7829 AESDECLAST KEY STATE4
7830 + pax_force_retaddr_bts
7831 ret
7832
7833 /*
7834 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
7835 popl KEYP
7836 popl LEN
7837 #endif
7838 + pax_force_retaddr 0, 1
7839 ret
7840 +ENDPROC(aesni_ecb_enc)
7841
7842 /*
7843 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7844 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
7845 popl KEYP
7846 popl LEN
7847 #endif
7848 + pax_force_retaddr 0, 1
7849 ret
7850 +ENDPROC(aesni_ecb_dec)
7851
7852 /*
7853 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7854 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
7855 popl LEN
7856 popl IVP
7857 #endif
7858 + pax_force_retaddr 0, 1
7859 ret
7860 +ENDPROC(aesni_cbc_enc)
7861
7862 /*
7863 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7864 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
7865 popl LEN
7866 popl IVP
7867 #endif
7868 + pax_force_retaddr 0, 1
7869 ret
7870 +ENDPROC(aesni_cbc_dec)
7871
7872 #ifdef __x86_64__
7873 .align 16
7874 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
7875 mov $1, TCTR_LOW
7876 MOVQ_R64_XMM TCTR_LOW INC
7877 MOVQ_R64_XMM CTR TCTR_LOW
7878 + pax_force_retaddr_bts
7879 ret
7880
7881 /*
7882 @@ -2552,6 +2580,7 @@ _aesni_inc:
7883 .Linc_low:
7884 movaps CTR, IV
7885 PSHUFB_XMM BSWAP_MASK IV
7886 + pax_force_retaddr_bts
7887 ret
7888
7889 /*
7890 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
7891 .Lctr_enc_ret:
7892 movups IV, (IVP)
7893 .Lctr_enc_just_ret:
7894 + pax_force_retaddr 0, 1
7895 ret
7896 +ENDPROC(aesni_ctr_enc)
7897 #endif
7898 diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
7899 index 545d0ce..14841a6 100644
7900 --- a/arch/x86/crypto/aesni-intel_glue.c
7901 +++ b/arch/x86/crypto/aesni-intel_glue.c
7902 @@ -929,6 +929,8 @@ out_free_ablkcipher:
7903 }
7904
7905 static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
7906 + unsigned int key_len) __size_overflow(3);
7907 +static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
7908 unsigned int key_len)
7909 {
7910 int ret = 0;
7911 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7912 index 391d245..67f35c2 100644
7913 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
7914 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7915 @@ -20,6 +20,8 @@
7916 *
7917 */
7918
7919 +#include <asm/alternative-asm.h>
7920 +
7921 .file "blowfish-x86_64-asm.S"
7922 .text
7923
7924 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
7925 jnz __enc_xor;
7926
7927 write_block();
7928 + pax_force_retaddr 0, 1
7929 ret;
7930 __enc_xor:
7931 xor_block();
7932 + pax_force_retaddr 0, 1
7933 ret;
7934
7935 .align 8
7936 @@ -188,6 +192,7 @@ blowfish_dec_blk:
7937
7938 movq %r11, %rbp;
7939
7940 + pax_force_retaddr 0, 1
7941 ret;
7942
7943 /**********************************************************************
7944 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
7945
7946 popq %rbx;
7947 popq %rbp;
7948 + pax_force_retaddr 0, 1
7949 ret;
7950
7951 __enc_xor4:
7952 @@ -349,6 +355,7 @@ __enc_xor4:
7953
7954 popq %rbx;
7955 popq %rbp;
7956 + pax_force_retaddr 0, 1
7957 ret;
7958
7959 .align 8
7960 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
7961 popq %rbx;
7962 popq %rbp;
7963
7964 + pax_force_retaddr 0, 1
7965 ret;
7966
7967 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7968 index 6214a9b..1f4fc9a 100644
7969 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7970 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7971 @@ -1,3 +1,5 @@
7972 +#include <asm/alternative-asm.h>
7973 +
7974 # enter ECRYPT_encrypt_bytes
7975 .text
7976 .p2align 5
7977 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7978 add %r11,%rsp
7979 mov %rdi,%rax
7980 mov %rsi,%rdx
7981 + pax_force_retaddr 0, 1
7982 ret
7983 # bytesatleast65:
7984 ._bytesatleast65:
7985 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
7986 add %r11,%rsp
7987 mov %rdi,%rax
7988 mov %rsi,%rdx
7989 + pax_force_retaddr
7990 ret
7991 # enter ECRYPT_ivsetup
7992 .text
7993 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7994 add %r11,%rsp
7995 mov %rdi,%rax
7996 mov %rsi,%rdx
7997 + pax_force_retaddr
7998 ret
7999 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8000 index 7f24a15..9cd3ffe 100644
8001 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8002 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8003 @@ -24,6 +24,8 @@
8004 *
8005 */
8006
8007 +#include <asm/alternative-asm.h>
8008 +
8009 .file "serpent-sse2-x86_64-asm_64.S"
8010 .text
8011
8012 @@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
8013 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8014 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8015
8016 + pax_force_retaddr
8017 ret;
8018
8019 __enc_xor8:
8020 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8021 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8022
8023 + pax_force_retaddr
8024 ret;
8025
8026 .align 8
8027 @@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8028 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8029 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8030
8031 + pax_force_retaddr
8032 ret;
8033 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8034 index b2c2f57..8470cab 100644
8035 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8036 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8037 @@ -28,6 +28,8 @@
8038 * (at your option) any later version.
8039 */
8040
8041 +#include <asm/alternative-asm.h>
8042 +
8043 #define CTX %rdi // arg1
8044 #define BUF %rsi // arg2
8045 #define CNT %rdx // arg3
8046 @@ -104,6 +106,7 @@
8047 pop %r12
8048 pop %rbp
8049 pop %rbx
8050 + pax_force_retaddr 0, 1
8051 ret
8052
8053 .size \name, .-\name
8054 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8055 index 5b012a2..36d5364 100644
8056 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8057 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8058 @@ -20,6 +20,8 @@
8059 *
8060 */
8061
8062 +#include <asm/alternative-asm.h>
8063 +
8064 .file "twofish-x86_64-asm-3way.S"
8065 .text
8066
8067 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8068 popq %r13;
8069 popq %r14;
8070 popq %r15;
8071 + pax_force_retaddr 0, 1
8072 ret;
8073
8074 __enc_xor3:
8075 @@ -271,6 +274,7 @@ __enc_xor3:
8076 popq %r13;
8077 popq %r14;
8078 popq %r15;
8079 + pax_force_retaddr 0, 1
8080 ret;
8081
8082 .global twofish_dec_blk_3way
8083 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8084 popq %r13;
8085 popq %r14;
8086 popq %r15;
8087 + pax_force_retaddr 0, 1
8088 ret;
8089
8090 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8091 index 7bcf3fc..f53832f 100644
8092 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8093 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8094 @@ -21,6 +21,7 @@
8095 .text
8096
8097 #include <asm/asm-offsets.h>
8098 +#include <asm/alternative-asm.h>
8099
8100 #define a_offset 0
8101 #define b_offset 4
8102 @@ -268,6 +269,7 @@ twofish_enc_blk:
8103
8104 popq R1
8105 movq $1,%rax
8106 + pax_force_retaddr 0, 1
8107 ret
8108
8109 twofish_dec_blk:
8110 @@ -319,4 +321,5 @@ twofish_dec_blk:
8111
8112 popq R1
8113 movq $1,%rax
8114 + pax_force_retaddr 0, 1
8115 ret
8116 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8117 index 39e4909..887aa7e 100644
8118 --- a/arch/x86/ia32/ia32_aout.c
8119 +++ b/arch/x86/ia32/ia32_aout.c
8120 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8121 unsigned long dump_start, dump_size;
8122 struct user32 dump;
8123
8124 + memset(&dump, 0, sizeof(dump));
8125 +
8126 fs = get_fs();
8127 set_fs(KERNEL_DS);
8128 has_dumped = 1;
8129 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8130 index 6557769..ef6ae89 100644
8131 --- a/arch/x86/ia32/ia32_signal.c
8132 +++ b/arch/x86/ia32/ia32_signal.c
8133 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8134 }
8135 seg = get_fs();
8136 set_fs(KERNEL_DS);
8137 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8138 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8139 set_fs(seg);
8140 if (ret >= 0 && uoss_ptr) {
8141 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8142 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8143 */
8144 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8145 size_t frame_size,
8146 - void **fpstate)
8147 + void __user **fpstate)
8148 {
8149 unsigned long sp;
8150
8151 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8152
8153 if (used_math()) {
8154 sp = sp - sig_xstate_ia32_size;
8155 - *fpstate = (struct _fpstate_ia32 *) sp;
8156 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8157 if (save_i387_xstate_ia32(*fpstate) < 0)
8158 return (void __user *) -1L;
8159 }
8160 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8161 sp -= frame_size;
8162 /* Align the stack pointer according to the i386 ABI,
8163 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8164 - sp = ((sp + 4) & -16ul) - 4;
8165 + sp = ((sp - 12) & -16ul) - 4;
8166 return (void __user *) sp;
8167 }
8168
8169 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8170 * These are actually not used anymore, but left because some
8171 * gdb versions depend on them as a marker.
8172 */
8173 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8174 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8175 } put_user_catch(err);
8176
8177 if (err)
8178 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8179 0xb8,
8180 __NR_ia32_rt_sigreturn,
8181 0x80cd,
8182 - 0,
8183 + 0
8184 };
8185
8186 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8187 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8188
8189 if (ka->sa.sa_flags & SA_RESTORER)
8190 restorer = ka->sa.sa_restorer;
8191 + else if (current->mm->context.vdso)
8192 + /* Return stub is in 32bit vsyscall page */
8193 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8194 else
8195 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8196 - rt_sigreturn);
8197 + restorer = &frame->retcode;
8198 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8199
8200 /*
8201 * Not actually used anymore, but left because some gdb
8202 * versions need it.
8203 */
8204 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8205 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8206 } put_user_catch(err);
8207
8208 if (err)
8209 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8210 index e3e7340..05ed805 100644
8211 --- a/arch/x86/ia32/ia32entry.S
8212 +++ b/arch/x86/ia32/ia32entry.S
8213 @@ -13,8 +13,10 @@
8214 #include <asm/thread_info.h>
8215 #include <asm/segment.h>
8216 #include <asm/irqflags.h>
8217 +#include <asm/pgtable.h>
8218 #include <linux/linkage.h>
8219 #include <linux/err.h>
8220 +#include <asm/alternative-asm.h>
8221
8222 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8223 #include <linux/elf-em.h>
8224 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8225 ENDPROC(native_irq_enable_sysexit)
8226 #endif
8227
8228 + .macro pax_enter_kernel_user
8229 + pax_set_fptr_mask
8230 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8231 + call pax_enter_kernel_user
8232 +#endif
8233 + .endm
8234 +
8235 + .macro pax_exit_kernel_user
8236 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8237 + call pax_exit_kernel_user
8238 +#endif
8239 +#ifdef CONFIG_PAX_RANDKSTACK
8240 + pushq %rax
8241 + pushq %r11
8242 + call pax_randomize_kstack
8243 + popq %r11
8244 + popq %rax
8245 +#endif
8246 + .endm
8247 +
8248 +.macro pax_erase_kstack
8249 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8250 + call pax_erase_kstack
8251 +#endif
8252 +.endm
8253 +
8254 /*
8255 * 32bit SYSENTER instruction entry.
8256 *
8257 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8258 CFI_REGISTER rsp,rbp
8259 SWAPGS_UNSAFE_STACK
8260 movq PER_CPU_VAR(kernel_stack), %rsp
8261 - addq $(KERNEL_STACK_OFFSET),%rsp
8262 - /*
8263 - * No need to follow this irqs on/off section: the syscall
8264 - * disabled irqs, here we enable it straight after entry:
8265 - */
8266 - ENABLE_INTERRUPTS(CLBR_NONE)
8267 movl %ebp,%ebp /* zero extension */
8268 pushq_cfi $__USER32_DS
8269 /*CFI_REL_OFFSET ss,0*/
8270 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8271 CFI_REL_OFFSET rsp,0
8272 pushfq_cfi
8273 /*CFI_REL_OFFSET rflags,0*/
8274 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8275 - CFI_REGISTER rip,r10
8276 + orl $X86_EFLAGS_IF,(%rsp)
8277 + GET_THREAD_INFO(%r11)
8278 + movl TI_sysenter_return(%r11), %r11d
8279 + CFI_REGISTER rip,r11
8280 pushq_cfi $__USER32_CS
8281 /*CFI_REL_OFFSET cs,0*/
8282 movl %eax, %eax
8283 - pushq_cfi %r10
8284 + pushq_cfi %r11
8285 CFI_REL_OFFSET rip,0
8286 pushq_cfi %rax
8287 cld
8288 SAVE_ARGS 0,1,0
8289 + pax_enter_kernel_user
8290 + /*
8291 + * No need to follow this irqs on/off section: the syscall
8292 + * disabled irqs, here we enable it straight after entry:
8293 + */
8294 + ENABLE_INTERRUPTS(CLBR_NONE)
8295 /* no need to do an access_ok check here because rbp has been
8296 32bit zero extended */
8297 +
8298 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8299 + mov $PAX_USER_SHADOW_BASE,%r11
8300 + add %r11,%rbp
8301 +#endif
8302 +
8303 1: movl (%rbp),%ebp
8304 .section __ex_table,"a"
8305 .quad 1b,ia32_badarg
8306 .previous
8307 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8308 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8309 + GET_THREAD_INFO(%r11)
8310 + orl $TS_COMPAT,TI_status(%r11)
8311 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8312 CFI_REMEMBER_STATE
8313 jnz sysenter_tracesys
8314 cmpq $(IA32_NR_syscalls-1),%rax
8315 @@ -160,12 +197,15 @@ sysenter_do_call:
8316 sysenter_dispatch:
8317 call *ia32_sys_call_table(,%rax,8)
8318 movq %rax,RAX-ARGOFFSET(%rsp)
8319 + GET_THREAD_INFO(%r11)
8320 DISABLE_INTERRUPTS(CLBR_NONE)
8321 TRACE_IRQS_OFF
8322 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8323 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8324 jnz sysexit_audit
8325 sysexit_from_sys_call:
8326 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8327 + pax_exit_kernel_user
8328 + pax_erase_kstack
8329 + andl $~TS_COMPAT,TI_status(%r11)
8330 /* clear IF, that popfq doesn't enable interrupts early */
8331 andl $~0x200,EFLAGS-R11(%rsp)
8332 movl RIP-R11(%rsp),%edx /* User %eip */
8333 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8334 movl %eax,%esi /* 2nd arg: syscall number */
8335 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8336 call __audit_syscall_entry
8337 +
8338 + pax_erase_kstack
8339 +
8340 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8341 cmpq $(IA32_NR_syscalls-1),%rax
8342 ja ia32_badsys
8343 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8344 .endm
8345
8346 .macro auditsys_exit exit
8347 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8348 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8349 jnz ia32_ret_from_sys_call
8350 TRACE_IRQS_ON
8351 sti
8352 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8353 1: setbe %al /* 1 if error, 0 if not */
8354 movzbl %al,%edi /* zero-extend that into %edi */
8355 call __audit_syscall_exit
8356 + GET_THREAD_INFO(%r11)
8357 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8358 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8359 cli
8360 TRACE_IRQS_OFF
8361 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8362 + testl %edi,TI_flags(%r11)
8363 jz \exit
8364 CLEAR_RREGS -ARGOFFSET
8365 jmp int_with_check
8366 @@ -235,7 +279,7 @@ sysexit_audit:
8367
8368 sysenter_tracesys:
8369 #ifdef CONFIG_AUDITSYSCALL
8370 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8371 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8372 jz sysenter_auditsys
8373 #endif
8374 SAVE_REST
8375 @@ -243,6 +287,9 @@ sysenter_tracesys:
8376 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8377 movq %rsp,%rdi /* &pt_regs -> arg1 */
8378 call syscall_trace_enter
8379 +
8380 + pax_erase_kstack
8381 +
8382 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8383 RESTORE_REST
8384 cmpq $(IA32_NR_syscalls-1),%rax
8385 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8386 ENTRY(ia32_cstar_target)
8387 CFI_STARTPROC32 simple
8388 CFI_SIGNAL_FRAME
8389 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8390 + CFI_DEF_CFA rsp,0
8391 CFI_REGISTER rip,rcx
8392 /*CFI_REGISTER rflags,r11*/
8393 SWAPGS_UNSAFE_STACK
8394 movl %esp,%r8d
8395 CFI_REGISTER rsp,r8
8396 movq PER_CPU_VAR(kernel_stack),%rsp
8397 + SAVE_ARGS 8*6,0,0
8398 + pax_enter_kernel_user
8399 /*
8400 * No need to follow this irqs on/off section: the syscall
8401 * disabled irqs and here we enable it straight after entry:
8402 */
8403 ENABLE_INTERRUPTS(CLBR_NONE)
8404 - SAVE_ARGS 8,0,0
8405 movl %eax,%eax /* zero extension */
8406 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8407 movq %rcx,RIP-ARGOFFSET(%rsp)
8408 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8409 /* no need to do an access_ok check here because r8 has been
8410 32bit zero extended */
8411 /* hardware stack frame is complete now */
8412 +
8413 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8414 + mov $PAX_USER_SHADOW_BASE,%r11
8415 + add %r11,%r8
8416 +#endif
8417 +
8418 1: movl (%r8),%r9d
8419 .section __ex_table,"a"
8420 .quad 1b,ia32_badarg
8421 .previous
8422 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8423 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8424 + GET_THREAD_INFO(%r11)
8425 + orl $TS_COMPAT,TI_status(%r11)
8426 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8427 CFI_REMEMBER_STATE
8428 jnz cstar_tracesys
8429 cmpq $IA32_NR_syscalls-1,%rax
8430 @@ -317,12 +372,15 @@ cstar_do_call:
8431 cstar_dispatch:
8432 call *ia32_sys_call_table(,%rax,8)
8433 movq %rax,RAX-ARGOFFSET(%rsp)
8434 + GET_THREAD_INFO(%r11)
8435 DISABLE_INTERRUPTS(CLBR_NONE)
8436 TRACE_IRQS_OFF
8437 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8438 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8439 jnz sysretl_audit
8440 sysretl_from_sys_call:
8441 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8442 + pax_exit_kernel_user
8443 + pax_erase_kstack
8444 + andl $~TS_COMPAT,TI_status(%r11)
8445 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8446 movl RIP-ARGOFFSET(%rsp),%ecx
8447 CFI_REGISTER rip,rcx
8448 @@ -350,7 +408,7 @@ sysretl_audit:
8449
8450 cstar_tracesys:
8451 #ifdef CONFIG_AUDITSYSCALL
8452 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8453 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8454 jz cstar_auditsys
8455 #endif
8456 xchgl %r9d,%ebp
8457 @@ -359,6 +417,9 @@ cstar_tracesys:
8458 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8459 movq %rsp,%rdi /* &pt_regs -> arg1 */
8460 call syscall_trace_enter
8461 +
8462 + pax_erase_kstack
8463 +
8464 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8465 RESTORE_REST
8466 xchgl %ebp,%r9d
8467 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8468 CFI_REL_OFFSET rip,RIP-RIP
8469 PARAVIRT_ADJUST_EXCEPTION_FRAME
8470 SWAPGS
8471 - /*
8472 - * No need to follow this irqs on/off section: the syscall
8473 - * disabled irqs and here we enable it straight after entry:
8474 - */
8475 - ENABLE_INTERRUPTS(CLBR_NONE)
8476 movl %eax,%eax
8477 pushq_cfi %rax
8478 cld
8479 /* note the registers are not zero extended to the sf.
8480 this could be a problem. */
8481 SAVE_ARGS 0,1,0
8482 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8483 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8484 + pax_enter_kernel_user
8485 + /*
8486 + * No need to follow this irqs on/off section: the syscall
8487 + * disabled irqs and here we enable it straight after entry:
8488 + */
8489 + ENABLE_INTERRUPTS(CLBR_NONE)
8490 + GET_THREAD_INFO(%r11)
8491 + orl $TS_COMPAT,TI_status(%r11)
8492 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8493 jnz ia32_tracesys
8494 cmpq $(IA32_NR_syscalls-1),%rax
8495 ja ia32_badsys
8496 @@ -435,6 +498,9 @@ ia32_tracesys:
8497 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8498 movq %rsp,%rdi /* &pt_regs -> arg1 */
8499 call syscall_trace_enter
8500 +
8501 + pax_erase_kstack
8502 +
8503 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8504 RESTORE_REST
8505 cmpq $(IA32_NR_syscalls-1),%rax
8506 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8507 index f6f5c53..b358b28 100644
8508 --- a/arch/x86/ia32/sys_ia32.c
8509 +++ b/arch/x86/ia32/sys_ia32.c
8510 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8511 */
8512 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8513 {
8514 - typeof(ubuf->st_uid) uid = 0;
8515 - typeof(ubuf->st_gid) gid = 0;
8516 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8517 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8518 SET_UID(uid, stat->uid);
8519 SET_GID(gid, stat->gid);
8520 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8521 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8522 }
8523 set_fs(KERNEL_DS);
8524 ret = sys_rt_sigprocmask(how,
8525 - set ? (sigset_t __user *)&s : NULL,
8526 - oset ? (sigset_t __user *)&s : NULL,
8527 + set ? (sigset_t __force_user *)&s : NULL,
8528 + oset ? (sigset_t __force_user *)&s : NULL,
8529 sigsetsize);
8530 set_fs(old_fs);
8531 if (ret)
8532 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8533 return alarm_setitimer(seconds);
8534 }
8535
8536 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8537 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8538 int options)
8539 {
8540 return compat_sys_wait4(pid, stat_addr, options, NULL);
8541 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8542 mm_segment_t old_fs = get_fs();
8543
8544 set_fs(KERNEL_DS);
8545 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8546 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8547 set_fs(old_fs);
8548 if (put_compat_timespec(&t, interval))
8549 return -EFAULT;
8550 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8551 mm_segment_t old_fs = get_fs();
8552
8553 set_fs(KERNEL_DS);
8554 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8555 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8556 set_fs(old_fs);
8557 if (!ret) {
8558 switch (_NSIG_WORDS) {
8559 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8560 if (copy_siginfo_from_user32(&info, uinfo))
8561 return -EFAULT;
8562 set_fs(KERNEL_DS);
8563 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8564 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8565 set_fs(old_fs);
8566 return ret;
8567 }
8568 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8569 return -EFAULT;
8570
8571 set_fs(KERNEL_DS);
8572 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8573 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8574 count);
8575 set_fs(old_fs);
8576
8577 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8578 index 952bd01..7692c6f 100644
8579 --- a/arch/x86/include/asm/alternative-asm.h
8580 +++ b/arch/x86/include/asm/alternative-asm.h
8581 @@ -15,6 +15,45 @@
8582 .endm
8583 #endif
8584
8585 +#ifdef KERNEXEC_PLUGIN
8586 + .macro pax_force_retaddr_bts rip=0
8587 + btsq $63,\rip(%rsp)
8588 + .endm
8589 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8590 + .macro pax_force_retaddr rip=0, reload=0
8591 + btsq $63,\rip(%rsp)
8592 + .endm
8593 + .macro pax_force_fptr ptr
8594 + btsq $63,\ptr
8595 + .endm
8596 + .macro pax_set_fptr_mask
8597 + .endm
8598 +#endif
8599 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8600 + .macro pax_force_retaddr rip=0, reload=0
8601 + .if \reload
8602 + pax_set_fptr_mask
8603 + .endif
8604 + orq %r10,\rip(%rsp)
8605 + .endm
8606 + .macro pax_force_fptr ptr
8607 + orq %r10,\ptr
8608 + .endm
8609 + .macro pax_set_fptr_mask
8610 + movabs $0x8000000000000000,%r10
8611 + .endm
8612 +#endif
8613 +#else
8614 + .macro pax_force_retaddr rip=0, reload=0
8615 + .endm
8616 + .macro pax_force_fptr ptr
8617 + .endm
8618 + .macro pax_force_retaddr_bts rip=0
8619 + .endm
8620 + .macro pax_set_fptr_mask
8621 + .endm
8622 +#endif
8623 +
8624 .macro altinstruction_entry orig alt feature orig_len alt_len
8625 .long \orig - .
8626 .long \alt - .
8627 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8628 index 37ad100..7d47faa 100644
8629 --- a/arch/x86/include/asm/alternative.h
8630 +++ b/arch/x86/include/asm/alternative.h
8631 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8632 ".section .discard,\"aw\",@progbits\n" \
8633 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8634 ".previous\n" \
8635 - ".section .altinstr_replacement, \"ax\"\n" \
8636 + ".section .altinstr_replacement, \"a\"\n" \
8637 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8638 ".previous"
8639
8640 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8641 index 3ab9bdd..238033e 100644
8642 --- a/arch/x86/include/asm/apic.h
8643 +++ b/arch/x86/include/asm/apic.h
8644 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8645
8646 #ifdef CONFIG_X86_LOCAL_APIC
8647
8648 -extern unsigned int apic_verbosity;
8649 +extern int apic_verbosity;
8650 extern int local_apic_timer_c2_ok;
8651
8652 extern int disable_apic;
8653 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8654 index 20370c6..a2eb9b0 100644
8655 --- a/arch/x86/include/asm/apm.h
8656 +++ b/arch/x86/include/asm/apm.h
8657 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8658 __asm__ __volatile__(APM_DO_ZERO_SEGS
8659 "pushl %%edi\n\t"
8660 "pushl %%ebp\n\t"
8661 - "lcall *%%cs:apm_bios_entry\n\t"
8662 + "lcall *%%ss:apm_bios_entry\n\t"
8663 "setc %%al\n\t"
8664 "popl %%ebp\n\t"
8665 "popl %%edi\n\t"
8666 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_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 %%bl\n\t"
8673 "popl %%ebp\n\t"
8674 "popl %%edi\n\t"
8675 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8676 index 58cb6d4..ca9010d 100644
8677 --- a/arch/x86/include/asm/atomic.h
8678 +++ b/arch/x86/include/asm/atomic.h
8679 @@ -22,7 +22,18 @@
8680 */
8681 static inline int atomic_read(const atomic_t *v)
8682 {
8683 - return (*(volatile int *)&(v)->counter);
8684 + return (*(volatile const int *)&(v)->counter);
8685 +}
8686 +
8687 +/**
8688 + * atomic_read_unchecked - read atomic variable
8689 + * @v: pointer of type atomic_unchecked_t
8690 + *
8691 + * Atomically reads the value of @v.
8692 + */
8693 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8694 +{
8695 + return (*(volatile const int *)&(v)->counter);
8696 }
8697
8698 /**
8699 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8700 }
8701
8702 /**
8703 + * atomic_set_unchecked - set atomic variable
8704 + * @v: pointer of type atomic_unchecked_t
8705 + * @i: required value
8706 + *
8707 + * Atomically sets the value of @v to @i.
8708 + */
8709 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8710 +{
8711 + v->counter = i;
8712 +}
8713 +
8714 +/**
8715 * atomic_add - add integer to atomic variable
8716 * @i: integer value to add
8717 * @v: pointer of type atomic_t
8718 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8719 */
8720 static inline void atomic_add(int i, atomic_t *v)
8721 {
8722 - asm volatile(LOCK_PREFIX "addl %1,%0"
8723 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8724 +
8725 +#ifdef CONFIG_PAX_REFCOUNT
8726 + "jno 0f\n"
8727 + LOCK_PREFIX "subl %1,%0\n"
8728 + "int $4\n0:\n"
8729 + _ASM_EXTABLE(0b, 0b)
8730 +#endif
8731 +
8732 + : "+m" (v->counter)
8733 + : "ir" (i));
8734 +}
8735 +
8736 +/**
8737 + * atomic_add_unchecked - add integer to atomic variable
8738 + * @i: integer value to add
8739 + * @v: pointer of type atomic_unchecked_t
8740 + *
8741 + * Atomically adds @i to @v.
8742 + */
8743 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8744 +{
8745 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8746 : "+m" (v->counter)
8747 : "ir" (i));
8748 }
8749 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8750 */
8751 static inline void atomic_sub(int i, atomic_t *v)
8752 {
8753 - asm volatile(LOCK_PREFIX "subl %1,%0"
8754 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8755 +
8756 +#ifdef CONFIG_PAX_REFCOUNT
8757 + "jno 0f\n"
8758 + LOCK_PREFIX "addl %1,%0\n"
8759 + "int $4\n0:\n"
8760 + _ASM_EXTABLE(0b, 0b)
8761 +#endif
8762 +
8763 + : "+m" (v->counter)
8764 + : "ir" (i));
8765 +}
8766 +
8767 +/**
8768 + * atomic_sub_unchecked - subtract integer from atomic variable
8769 + * @i: integer value to subtract
8770 + * @v: pointer of type atomic_unchecked_t
8771 + *
8772 + * Atomically subtracts @i from @v.
8773 + */
8774 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8775 +{
8776 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8777 : "+m" (v->counter)
8778 : "ir" (i));
8779 }
8780 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8781 {
8782 unsigned char c;
8783
8784 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8785 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8786 +
8787 +#ifdef CONFIG_PAX_REFCOUNT
8788 + "jno 0f\n"
8789 + LOCK_PREFIX "addl %2,%0\n"
8790 + "int $4\n0:\n"
8791 + _ASM_EXTABLE(0b, 0b)
8792 +#endif
8793 +
8794 + "sete %1\n"
8795 : "+m" (v->counter), "=qm" (c)
8796 : "ir" (i) : "memory");
8797 return c;
8798 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8799 */
8800 static inline void atomic_inc(atomic_t *v)
8801 {
8802 - asm volatile(LOCK_PREFIX "incl %0"
8803 + asm volatile(LOCK_PREFIX "incl %0\n"
8804 +
8805 +#ifdef CONFIG_PAX_REFCOUNT
8806 + "jno 0f\n"
8807 + LOCK_PREFIX "decl %0\n"
8808 + "int $4\n0:\n"
8809 + _ASM_EXTABLE(0b, 0b)
8810 +#endif
8811 +
8812 + : "+m" (v->counter));
8813 +}
8814 +
8815 +/**
8816 + * atomic_inc_unchecked - increment atomic variable
8817 + * @v: pointer of type atomic_unchecked_t
8818 + *
8819 + * Atomically increments @v by 1.
8820 + */
8821 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8822 +{
8823 + asm volatile(LOCK_PREFIX "incl %0\n"
8824 : "+m" (v->counter));
8825 }
8826
8827 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
8828 */
8829 static inline void atomic_dec(atomic_t *v)
8830 {
8831 - asm volatile(LOCK_PREFIX "decl %0"
8832 + asm volatile(LOCK_PREFIX "decl %0\n"
8833 +
8834 +#ifdef CONFIG_PAX_REFCOUNT
8835 + "jno 0f\n"
8836 + LOCK_PREFIX "incl %0\n"
8837 + "int $4\n0:\n"
8838 + _ASM_EXTABLE(0b, 0b)
8839 +#endif
8840 +
8841 + : "+m" (v->counter));
8842 +}
8843 +
8844 +/**
8845 + * atomic_dec_unchecked - decrement atomic variable
8846 + * @v: pointer of type atomic_unchecked_t
8847 + *
8848 + * Atomically decrements @v by 1.
8849 + */
8850 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8851 +{
8852 + asm volatile(LOCK_PREFIX "decl %0\n"
8853 : "+m" (v->counter));
8854 }
8855
8856 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8857 {
8858 unsigned char c;
8859
8860 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8861 + asm volatile(LOCK_PREFIX "decl %0\n"
8862 +
8863 +#ifdef CONFIG_PAX_REFCOUNT
8864 + "jno 0f\n"
8865 + LOCK_PREFIX "incl %0\n"
8866 + "int $4\n0:\n"
8867 + _ASM_EXTABLE(0b, 0b)
8868 +#endif
8869 +
8870 + "sete %1\n"
8871 : "+m" (v->counter), "=qm" (c)
8872 : : "memory");
8873 return c != 0;
8874 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8875 {
8876 unsigned char c;
8877
8878 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8879 + asm volatile(LOCK_PREFIX "incl %0\n"
8880 +
8881 +#ifdef CONFIG_PAX_REFCOUNT
8882 + "jno 0f\n"
8883 + LOCK_PREFIX "decl %0\n"
8884 + "int $4\n0:\n"
8885 + _ASM_EXTABLE(0b, 0b)
8886 +#endif
8887 +
8888 + "sete %1\n"
8889 + : "+m" (v->counter), "=qm" (c)
8890 + : : "memory");
8891 + return c != 0;
8892 +}
8893 +
8894 +/**
8895 + * atomic_inc_and_test_unchecked - increment and test
8896 + * @v: pointer of type atomic_unchecked_t
8897 + *
8898 + * Atomically increments @v by 1
8899 + * and returns true if the result is zero, or false for all
8900 + * other cases.
8901 + */
8902 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8903 +{
8904 + unsigned char c;
8905 +
8906 + asm volatile(LOCK_PREFIX "incl %0\n"
8907 + "sete %1\n"
8908 : "+m" (v->counter), "=qm" (c)
8909 : : "memory");
8910 return c != 0;
8911 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8912 {
8913 unsigned char c;
8914
8915 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8916 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8917 +
8918 +#ifdef CONFIG_PAX_REFCOUNT
8919 + "jno 0f\n"
8920 + LOCK_PREFIX "subl %2,%0\n"
8921 + "int $4\n0:\n"
8922 + _ASM_EXTABLE(0b, 0b)
8923 +#endif
8924 +
8925 + "sets %1\n"
8926 : "+m" (v->counter), "=qm" (c)
8927 : "ir" (i) : "memory");
8928 return c;
8929 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
8930 goto no_xadd;
8931 #endif
8932 /* Modern 486+ processor */
8933 - return i + xadd(&v->counter, i);
8934 + return i + xadd_check_overflow(&v->counter, i);
8935
8936 #ifdef CONFIG_M386
8937 no_xadd: /* Legacy 386 processor */
8938 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
8939 }
8940
8941 /**
8942 + * atomic_add_return_unchecked - add integer and return
8943 + * @i: integer value to add
8944 + * @v: pointer of type atomic_unchecked_t
8945 + *
8946 + * Atomically adds @i to @v and returns @i + @v
8947 + */
8948 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8949 +{
8950 +#ifdef CONFIG_M386
8951 + int __i;
8952 + unsigned long flags;
8953 + if (unlikely(boot_cpu_data.x86 <= 3))
8954 + goto no_xadd;
8955 +#endif
8956 + /* Modern 486+ processor */
8957 + return i + xadd(&v->counter, i);
8958 +
8959 +#ifdef CONFIG_M386
8960 +no_xadd: /* Legacy 386 processor */
8961 + raw_local_irq_save(flags);
8962 + __i = atomic_read_unchecked(v);
8963 + atomic_set_unchecked(v, i + __i);
8964 + raw_local_irq_restore(flags);
8965 + return i + __i;
8966 +#endif
8967 +}
8968 +
8969 +/**
8970 * atomic_sub_return - subtract integer and return
8971 * @v: pointer of type atomic_t
8972 * @i: integer value to subtract
8973 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
8974 }
8975
8976 #define atomic_inc_return(v) (atomic_add_return(1, v))
8977 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8978 +{
8979 + return atomic_add_return_unchecked(1, v);
8980 +}
8981 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8982
8983 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8984 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8985 return cmpxchg(&v->counter, old, new);
8986 }
8987
8988 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8989 +{
8990 + return cmpxchg(&v->counter, old, new);
8991 +}
8992 +
8993 static inline int atomic_xchg(atomic_t *v, int new)
8994 {
8995 return xchg(&v->counter, new);
8996 }
8997
8998 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8999 +{
9000 + return xchg(&v->counter, new);
9001 +}
9002 +
9003 /**
9004 * __atomic_add_unless - add unless the number is already a given value
9005 * @v: pointer of type atomic_t
9006 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9007 */
9008 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9009 {
9010 - int c, old;
9011 + int c, old, new;
9012 c = atomic_read(v);
9013 for (;;) {
9014 - if (unlikely(c == (u)))
9015 + if (unlikely(c == u))
9016 break;
9017 - old = atomic_cmpxchg((v), c, c + (a));
9018 +
9019 + asm volatile("addl %2,%0\n"
9020 +
9021 +#ifdef CONFIG_PAX_REFCOUNT
9022 + "jno 0f\n"
9023 + "subl %2,%0\n"
9024 + "int $4\n0:\n"
9025 + _ASM_EXTABLE(0b, 0b)
9026 +#endif
9027 +
9028 + : "=r" (new)
9029 + : "0" (c), "ir" (a));
9030 +
9031 + old = atomic_cmpxchg(v, c, new);
9032 if (likely(old == c))
9033 break;
9034 c = old;
9035 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9036 return c;
9037 }
9038
9039 +/**
9040 + * atomic_inc_not_zero_hint - increment if not null
9041 + * @v: pointer of type atomic_t
9042 + * @hint: probable value of the atomic before the increment
9043 + *
9044 + * This version of atomic_inc_not_zero() gives a hint of probable
9045 + * value of the atomic. This helps processor to not read the memory
9046 + * before doing the atomic read/modify/write cycle, lowering
9047 + * number of bus transactions on some arches.
9048 + *
9049 + * Returns: 0 if increment was not done, 1 otherwise.
9050 + */
9051 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9052 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9053 +{
9054 + int val, c = hint, new;
9055 +
9056 + /* sanity test, should be removed by compiler if hint is a constant */
9057 + if (!hint)
9058 + return __atomic_add_unless(v, 1, 0);
9059 +
9060 + do {
9061 + asm volatile("incl %0\n"
9062 +
9063 +#ifdef CONFIG_PAX_REFCOUNT
9064 + "jno 0f\n"
9065 + "decl %0\n"
9066 + "int $4\n0:\n"
9067 + _ASM_EXTABLE(0b, 0b)
9068 +#endif
9069 +
9070 + : "=r" (new)
9071 + : "0" (c));
9072 +
9073 + val = atomic_cmpxchg(v, c, new);
9074 + if (val == c)
9075 + return 1;
9076 + c = val;
9077 + } while (c);
9078 +
9079 + return 0;
9080 +}
9081
9082 /*
9083 * atomic_dec_if_positive - decrement by 1 if old value positive
9084 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9085 index fa13f0e..27c2e08 100644
9086 --- a/arch/x86/include/asm/atomic64_32.h
9087 +++ b/arch/x86/include/asm/atomic64_32.h
9088 @@ -12,6 +12,14 @@ typedef struct {
9089 u64 __aligned(8) counter;
9090 } atomic64_t;
9091
9092 +#ifdef CONFIG_PAX_REFCOUNT
9093 +typedef struct {
9094 + u64 __aligned(8) counter;
9095 +} atomic64_unchecked_t;
9096 +#else
9097 +typedef atomic64_t atomic64_unchecked_t;
9098 +#endif
9099 +
9100 #define ATOMIC64_INIT(val) { (val) }
9101
9102 #ifdef CONFIG_X86_CMPXCHG64
9103 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9104 }
9105
9106 /**
9107 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9108 + * @p: pointer to type atomic64_unchecked_t
9109 + * @o: expected value
9110 + * @n: new value
9111 + *
9112 + * Atomically sets @v to @n if it was equal to @o and returns
9113 + * the old value.
9114 + */
9115 +
9116 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9117 +{
9118 + return cmpxchg64(&v->counter, o, n);
9119 +}
9120 +
9121 +/**
9122 * atomic64_xchg - xchg atomic64 variable
9123 * @v: pointer to type atomic64_t
9124 * @n: value to assign
9125 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9126 }
9127
9128 /**
9129 + * atomic64_set_unchecked - set atomic64 variable
9130 + * @v: pointer to type atomic64_unchecked_t
9131 + * @n: value to assign
9132 + *
9133 + * Atomically sets the value of @v to @n.
9134 + */
9135 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9136 +{
9137 + unsigned high = (unsigned)(i >> 32);
9138 + unsigned low = (unsigned)i;
9139 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9140 + : "+b" (low), "+c" (high)
9141 + : "S" (v)
9142 + : "eax", "edx", "memory"
9143 + );
9144 +}
9145 +
9146 +/**
9147 * atomic64_read - read atomic64 variable
9148 * @v: pointer to type atomic64_t
9149 *
9150 @@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9151 }
9152
9153 /**
9154 + * atomic64_read_unchecked - read atomic64 variable
9155 + * @v: pointer to type atomic64_unchecked_t
9156 + *
9157 + * Atomically reads the value of @v and returns it.
9158 + */
9159 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9160 +{
9161 + long long r;
9162 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9163 + : "=A" (r), "+c" (v)
9164 + : : "memory"
9165 + );
9166 + return r;
9167 + }
9168 +
9169 +/**
9170 * atomic64_add_return - add and return
9171 * @i: integer value to add
9172 * @v: pointer to type atomic64_t
9173 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9174 return i;
9175 }
9176
9177 +/**
9178 + * atomic64_add_return_unchecked - add and return
9179 + * @i: integer value to add
9180 + * @v: pointer to type atomic64_unchecked_t
9181 + *
9182 + * Atomically adds @i to @v and returns @i + *@v
9183 + */
9184 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9185 +{
9186 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9187 + : "+A" (i), "+c" (v)
9188 + : : "memory"
9189 + );
9190 + return i;
9191 +}
9192 +
9193 /*
9194 * Other variants with different arithmetic operators:
9195 */
9196 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9197 return a;
9198 }
9199
9200 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9201 +{
9202 + long long a;
9203 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9204 + : "=A" (a)
9205 + : "S" (v)
9206 + : "memory", "ecx"
9207 + );
9208 + return a;
9209 +}
9210 +
9211 static inline long long atomic64_dec_return(atomic64_t *v)
9212 {
9213 long long a;
9214 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9215 }
9216
9217 /**
9218 + * atomic64_add_unchecked - add integer to atomic64 variable
9219 + * @i: integer value to add
9220 + * @v: pointer to type atomic64_unchecked_t
9221 + *
9222 + * Atomically adds @i to @v.
9223 + */
9224 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9225 +{
9226 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9227 + : "+A" (i), "+c" (v)
9228 + : : "memory"
9229 + );
9230 + return i;
9231 +}
9232 +
9233 +/**
9234 * atomic64_sub - subtract the atomic64 variable
9235 * @i: integer value to subtract
9236 * @v: pointer to type atomic64_t
9237 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9238 index 0e1cbfc..5623683 100644
9239 --- a/arch/x86/include/asm/atomic64_64.h
9240 +++ b/arch/x86/include/asm/atomic64_64.h
9241 @@ -18,7 +18,19 @@
9242 */
9243 static inline long atomic64_read(const atomic64_t *v)
9244 {
9245 - return (*(volatile long *)&(v)->counter);
9246 + return (*(volatile const long *)&(v)->counter);
9247 +}
9248 +
9249 +/**
9250 + * atomic64_read_unchecked - read atomic64 variable
9251 + * @v: pointer of type atomic64_unchecked_t
9252 + *
9253 + * Atomically reads the value of @v.
9254 + * Doesn't imply a read memory barrier.
9255 + */
9256 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9257 +{
9258 + return (*(volatile const long *)&(v)->counter);
9259 }
9260
9261 /**
9262 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9263 }
9264
9265 /**
9266 + * atomic64_set_unchecked - set atomic64 variable
9267 + * @v: pointer to type atomic64_unchecked_t
9268 + * @i: required value
9269 + *
9270 + * Atomically sets the value of @v to @i.
9271 + */
9272 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9273 +{
9274 + v->counter = i;
9275 +}
9276 +
9277 +/**
9278 * atomic64_add - add integer to atomic64 variable
9279 * @i: integer value to add
9280 * @v: pointer to type atomic64_t
9281 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9282 */
9283 static inline void atomic64_add(long i, atomic64_t *v)
9284 {
9285 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9286 +
9287 +#ifdef CONFIG_PAX_REFCOUNT
9288 + "jno 0f\n"
9289 + LOCK_PREFIX "subq %1,%0\n"
9290 + "int $4\n0:\n"
9291 + _ASM_EXTABLE(0b, 0b)
9292 +#endif
9293 +
9294 + : "=m" (v->counter)
9295 + : "er" (i), "m" (v->counter));
9296 +}
9297 +
9298 +/**
9299 + * atomic64_add_unchecked - add integer to atomic64 variable
9300 + * @i: integer value to add
9301 + * @v: pointer to type atomic64_unchecked_t
9302 + *
9303 + * Atomically adds @i to @v.
9304 + */
9305 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9306 +{
9307 asm volatile(LOCK_PREFIX "addq %1,%0"
9308 : "=m" (v->counter)
9309 : "er" (i), "m" (v->counter));
9310 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9311 */
9312 static inline void atomic64_sub(long i, atomic64_t *v)
9313 {
9314 - asm volatile(LOCK_PREFIX "subq %1,%0"
9315 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9316 +
9317 +#ifdef CONFIG_PAX_REFCOUNT
9318 + "jno 0f\n"
9319 + LOCK_PREFIX "addq %1,%0\n"
9320 + "int $4\n0:\n"
9321 + _ASM_EXTABLE(0b, 0b)
9322 +#endif
9323 +
9324 + : "=m" (v->counter)
9325 + : "er" (i), "m" (v->counter));
9326 +}
9327 +
9328 +/**
9329 + * atomic64_sub_unchecked - subtract the atomic64 variable
9330 + * @i: integer value to subtract
9331 + * @v: pointer to type atomic64_unchecked_t
9332 + *
9333 + * Atomically subtracts @i from @v.
9334 + */
9335 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9336 +{
9337 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9338 : "=m" (v->counter)
9339 : "er" (i), "m" (v->counter));
9340 }
9341 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9342 {
9343 unsigned char c;
9344
9345 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9346 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9347 +
9348 +#ifdef CONFIG_PAX_REFCOUNT
9349 + "jno 0f\n"
9350 + LOCK_PREFIX "addq %2,%0\n"
9351 + "int $4\n0:\n"
9352 + _ASM_EXTABLE(0b, 0b)
9353 +#endif
9354 +
9355 + "sete %1\n"
9356 : "=m" (v->counter), "=qm" (c)
9357 : "er" (i), "m" (v->counter) : "memory");
9358 return c;
9359 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9360 */
9361 static inline void atomic64_inc(atomic64_t *v)
9362 {
9363 + asm volatile(LOCK_PREFIX "incq %0\n"
9364 +
9365 +#ifdef CONFIG_PAX_REFCOUNT
9366 + "jno 0f\n"
9367 + LOCK_PREFIX "decq %0\n"
9368 + "int $4\n0:\n"
9369 + _ASM_EXTABLE(0b, 0b)
9370 +#endif
9371 +
9372 + : "=m" (v->counter)
9373 + : "m" (v->counter));
9374 +}
9375 +
9376 +/**
9377 + * atomic64_inc_unchecked - increment atomic64 variable
9378 + * @v: pointer to type atomic64_unchecked_t
9379 + *
9380 + * Atomically increments @v by 1.
9381 + */
9382 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9383 +{
9384 asm volatile(LOCK_PREFIX "incq %0"
9385 : "=m" (v->counter)
9386 : "m" (v->counter));
9387 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9388 */
9389 static inline void atomic64_dec(atomic64_t *v)
9390 {
9391 - asm volatile(LOCK_PREFIX "decq %0"
9392 + asm volatile(LOCK_PREFIX "decq %0\n"
9393 +
9394 +#ifdef CONFIG_PAX_REFCOUNT
9395 + "jno 0f\n"
9396 + LOCK_PREFIX "incq %0\n"
9397 + "int $4\n0:\n"
9398 + _ASM_EXTABLE(0b, 0b)
9399 +#endif
9400 +
9401 + : "=m" (v->counter)
9402 + : "m" (v->counter));
9403 +}
9404 +
9405 +/**
9406 + * atomic64_dec_unchecked - decrement atomic64 variable
9407 + * @v: pointer to type atomic64_t
9408 + *
9409 + * Atomically decrements @v by 1.
9410 + */
9411 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9412 +{
9413 + asm volatile(LOCK_PREFIX "decq %0\n"
9414 : "=m" (v->counter)
9415 : "m" (v->counter));
9416 }
9417 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9418 {
9419 unsigned char c;
9420
9421 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9422 + asm volatile(LOCK_PREFIX "decq %0\n"
9423 +
9424 +#ifdef CONFIG_PAX_REFCOUNT
9425 + "jno 0f\n"
9426 + LOCK_PREFIX "incq %0\n"
9427 + "int $4\n0:\n"
9428 + _ASM_EXTABLE(0b, 0b)
9429 +#endif
9430 +
9431 + "sete %1\n"
9432 : "=m" (v->counter), "=qm" (c)
9433 : "m" (v->counter) : "memory");
9434 return c != 0;
9435 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9436 {
9437 unsigned char c;
9438
9439 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9440 + asm volatile(LOCK_PREFIX "incq %0\n"
9441 +
9442 +#ifdef CONFIG_PAX_REFCOUNT
9443 + "jno 0f\n"
9444 + LOCK_PREFIX "decq %0\n"
9445 + "int $4\n0:\n"
9446 + _ASM_EXTABLE(0b, 0b)
9447 +#endif
9448 +
9449 + "sete %1\n"
9450 : "=m" (v->counter), "=qm" (c)
9451 : "m" (v->counter) : "memory");
9452 return c != 0;
9453 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9454 {
9455 unsigned char c;
9456
9457 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9458 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9459 +
9460 +#ifdef CONFIG_PAX_REFCOUNT
9461 + "jno 0f\n"
9462 + LOCK_PREFIX "subq %2,%0\n"
9463 + "int $4\n0:\n"
9464 + _ASM_EXTABLE(0b, 0b)
9465 +#endif
9466 +
9467 + "sets %1\n"
9468 : "=m" (v->counter), "=qm" (c)
9469 : "er" (i), "m" (v->counter) : "memory");
9470 return c;
9471 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9472 */
9473 static inline long atomic64_add_return(long i, atomic64_t *v)
9474 {
9475 + return i + xadd_check_overflow(&v->counter, i);
9476 +}
9477 +
9478 +/**
9479 + * atomic64_add_return_unchecked - add and return
9480 + * @i: integer value to add
9481 + * @v: pointer to type atomic64_unchecked_t
9482 + *
9483 + * Atomically adds @i to @v and returns @i + @v
9484 + */
9485 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9486 +{
9487 return i + xadd(&v->counter, i);
9488 }
9489
9490 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9491 }
9492
9493 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9494 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9495 +{
9496 + return atomic64_add_return_unchecked(1, v);
9497 +}
9498 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9499
9500 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9501 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9502 return cmpxchg(&v->counter, old, new);
9503 }
9504
9505 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9506 +{
9507 + return cmpxchg(&v->counter, old, new);
9508 +}
9509 +
9510 static inline long atomic64_xchg(atomic64_t *v, long new)
9511 {
9512 return xchg(&v->counter, new);
9513 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9514 */
9515 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9516 {
9517 - long c, old;
9518 + long c, old, new;
9519 c = atomic64_read(v);
9520 for (;;) {
9521 - if (unlikely(c == (u)))
9522 + if (unlikely(c == u))
9523 break;
9524 - old = atomic64_cmpxchg((v), c, c + (a));
9525 +
9526 + asm volatile("add %2,%0\n"
9527 +
9528 +#ifdef CONFIG_PAX_REFCOUNT
9529 + "jno 0f\n"
9530 + "sub %2,%0\n"
9531 + "int $4\n0:\n"
9532 + _ASM_EXTABLE(0b, 0b)
9533 +#endif
9534 +
9535 + : "=r" (new)
9536 + : "0" (c), "ir" (a));
9537 +
9538 + old = atomic64_cmpxchg(v, c, new);
9539 if (likely(old == c))
9540 break;
9541 c = old;
9542 }
9543 - return c != (u);
9544 + return c != u;
9545 }
9546
9547 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9548 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9549 index b97596e..9bd48b06 100644
9550 --- a/arch/x86/include/asm/bitops.h
9551 +++ b/arch/x86/include/asm/bitops.h
9552 @@ -38,7 +38,7 @@
9553 * a mask operation on a byte.
9554 */
9555 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9556 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9557 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9558 #define CONST_MASK(nr) (1 << ((nr) & 7))
9559
9560 /**
9561 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9562 index 5e1a2ee..c9f9533 100644
9563 --- a/arch/x86/include/asm/boot.h
9564 +++ b/arch/x86/include/asm/boot.h
9565 @@ -11,10 +11,15 @@
9566 #include <asm/pgtable_types.h>
9567
9568 /* Physical address where kernel should be loaded. */
9569 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9570 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9571 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9572 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9573
9574 +#ifndef __ASSEMBLY__
9575 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9576 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9577 +#endif
9578 +
9579 /* Minimum kernel alignment, as a power of two */
9580 #ifdef CONFIG_X86_64
9581 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9582 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9583 index 48f99f1..d78ebf9 100644
9584 --- a/arch/x86/include/asm/cache.h
9585 +++ b/arch/x86/include/asm/cache.h
9586 @@ -5,12 +5,13 @@
9587
9588 /* L1 cache line size */
9589 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9590 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9591 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9592
9593 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9594 +#define __read_only __attribute__((__section__(".data..read_only")))
9595
9596 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9597 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9598 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9599
9600 #ifdef CONFIG_X86_VSMP
9601 #ifdef CONFIG_SMP
9602 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9603 index 4e12668..501d239 100644
9604 --- a/arch/x86/include/asm/cacheflush.h
9605 +++ b/arch/x86/include/asm/cacheflush.h
9606 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9607 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9608
9609 if (pg_flags == _PGMT_DEFAULT)
9610 - return -1;
9611 + return ~0UL;
9612 else if (pg_flags == _PGMT_WC)
9613 return _PAGE_CACHE_WC;
9614 else if (pg_flags == _PGMT_UC_MINUS)
9615 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9616 index 46fc474..b02b0f9 100644
9617 --- a/arch/x86/include/asm/checksum_32.h
9618 +++ b/arch/x86/include/asm/checksum_32.h
9619 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9620 int len, __wsum sum,
9621 int *src_err_ptr, int *dst_err_ptr);
9622
9623 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9624 + int len, __wsum sum,
9625 + int *src_err_ptr, int *dst_err_ptr);
9626 +
9627 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9628 + int len, __wsum sum,
9629 + int *src_err_ptr, int *dst_err_ptr);
9630 +
9631 /*
9632 * Note: when you get a NULL pointer exception here this means someone
9633 * passed in an incorrect kernel address to one of these functions.
9634 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9635 int *err_ptr)
9636 {
9637 might_sleep();
9638 - return csum_partial_copy_generic((__force void *)src, dst,
9639 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9640 len, sum, err_ptr, NULL);
9641 }
9642
9643 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9644 {
9645 might_sleep();
9646 if (access_ok(VERIFY_WRITE, dst, len))
9647 - return csum_partial_copy_generic(src, (__force void *)dst,
9648 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9649 len, sum, NULL, err_ptr);
9650
9651 if (len)
9652 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9653 index 99480e5..d81165b 100644
9654 --- a/arch/x86/include/asm/cmpxchg.h
9655 +++ b/arch/x86/include/asm/cmpxchg.h
9656 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
9657 __compiletime_error("Bad argument size for cmpxchg");
9658 extern void __xadd_wrong_size(void)
9659 __compiletime_error("Bad argument size for xadd");
9660 +extern void __xadd_check_overflow_wrong_size(void)
9661 + __compiletime_error("Bad argument size for xadd_check_overflow");
9662 extern void __add_wrong_size(void)
9663 __compiletime_error("Bad argument size for add");
9664 +extern void __add_check_overflow_wrong_size(void)
9665 + __compiletime_error("Bad argument size for add_check_overflow");
9666
9667 /*
9668 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9669 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
9670 __ret; \
9671 })
9672
9673 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
9674 + ({ \
9675 + __typeof__ (*(ptr)) __ret = (arg); \
9676 + switch (sizeof(*(ptr))) { \
9677 + case __X86_CASE_L: \
9678 + asm volatile (lock #op "l %0, %1\n" \
9679 + "jno 0f\n" \
9680 + "mov %0,%1\n" \
9681 + "int $4\n0:\n" \
9682 + _ASM_EXTABLE(0b, 0b) \
9683 + : "+r" (__ret), "+m" (*(ptr)) \
9684 + : : "memory", "cc"); \
9685 + break; \
9686 + case __X86_CASE_Q: \
9687 + asm volatile (lock #op "q %q0, %1\n" \
9688 + "jno 0f\n" \
9689 + "mov %0,%1\n" \
9690 + "int $4\n0:\n" \
9691 + _ASM_EXTABLE(0b, 0b) \
9692 + : "+r" (__ret), "+m" (*(ptr)) \
9693 + : : "memory", "cc"); \
9694 + break; \
9695 + default: \
9696 + __ ## op ## _check_overflow_wrong_size(); \
9697 + } \
9698 + __ret; \
9699 + })
9700 +
9701 /*
9702 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
9703 * Since this is generally used to protect other memory information, we
9704 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
9705 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9706 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9707
9708 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
9709 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9710 +
9711 #define __add(ptr, inc, lock) \
9712 ({ \
9713 __typeof__ (*(ptr)) __ret = (inc); \
9714 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9715 index 8d67d42..183d0eb 100644
9716 --- a/arch/x86/include/asm/cpufeature.h
9717 +++ b/arch/x86/include/asm/cpufeature.h
9718 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9719 ".section .discard,\"aw\",@progbits\n"
9720 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9721 ".previous\n"
9722 - ".section .altinstr_replacement,\"ax\"\n"
9723 + ".section .altinstr_replacement,\"a\"\n"
9724 "3: movb $1,%0\n"
9725 "4:\n"
9726 ".previous\n"
9727 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9728 index e95822d..a90010e 100644
9729 --- a/arch/x86/include/asm/desc.h
9730 +++ b/arch/x86/include/asm/desc.h
9731 @@ -4,6 +4,7 @@
9732 #include <asm/desc_defs.h>
9733 #include <asm/ldt.h>
9734 #include <asm/mmu.h>
9735 +#include <asm/pgtable.h>
9736
9737 #include <linux/smp.h>
9738
9739 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9740
9741 desc->type = (info->read_exec_only ^ 1) << 1;
9742 desc->type |= info->contents << 2;
9743 + desc->type |= info->seg_not_present ^ 1;
9744
9745 desc->s = 1;
9746 desc->dpl = 0x3;
9747 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9748 }
9749
9750 extern struct desc_ptr idt_descr;
9751 -extern gate_desc idt_table[];
9752 extern struct desc_ptr nmi_idt_descr;
9753 -extern gate_desc nmi_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 +extern gate_desc nmi_idt_table[256];
9762
9763 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9764 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9765 {
9766 - return per_cpu(gdt_page, cpu).gdt;
9767 + return cpu_gdt_table[cpu];
9768 }
9769
9770 #ifdef CONFIG_X86_64
9771 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9772 unsigned long base, unsigned dpl, unsigned flags,
9773 unsigned short seg)
9774 {
9775 - gate->a = (seg << 16) | (base & 0xffff);
9776 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9777 + gate->gate.offset_low = base;
9778 + gate->gate.seg = seg;
9779 + gate->gate.reserved = 0;
9780 + gate->gate.type = type;
9781 + gate->gate.s = 0;
9782 + gate->gate.dpl = dpl;
9783 + gate->gate.p = 1;
9784 + gate->gate.offset_high = base >> 16;
9785 }
9786
9787 #endif
9788 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9789
9790 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9791 {
9792 + pax_open_kernel();
9793 memcpy(&idt[entry], gate, sizeof(*gate));
9794 + pax_close_kernel();
9795 }
9796
9797 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9798 {
9799 + pax_open_kernel();
9800 memcpy(&ldt[entry], desc, 8);
9801 + pax_close_kernel();
9802 }
9803
9804 static inline void
9805 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9806 default: size = sizeof(*gdt); break;
9807 }
9808
9809 + pax_open_kernel();
9810 memcpy(&gdt[entry], desc, size);
9811 + pax_close_kernel();
9812 }
9813
9814 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9815 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9816
9817 static inline void native_load_tr_desc(void)
9818 {
9819 + pax_open_kernel();
9820 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9821 + pax_close_kernel();
9822 }
9823
9824 static inline void native_load_gdt(const struct desc_ptr *dtr)
9825 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9826 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9827 unsigned int i;
9828
9829 + pax_open_kernel();
9830 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9831 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9832 + pax_close_kernel();
9833 }
9834
9835 #define _LDT_empty(info) \
9836 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9837 }
9838
9839 #ifdef CONFIG_X86_64
9840 -static inline void set_nmi_gate(int gate, void *addr)
9841 +static inline void set_nmi_gate(int gate, const void *addr)
9842 {
9843 gate_desc s;
9844
9845 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
9846 }
9847 #endif
9848
9849 -static inline void _set_gate(int gate, unsigned type, void *addr,
9850 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9851 unsigned dpl, unsigned ist, unsigned seg)
9852 {
9853 gate_desc s;
9854 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9855 * Pentium F0 0F bugfix can have resulted in the mapped
9856 * IDT being write-protected.
9857 */
9858 -static inline void set_intr_gate(unsigned int n, void *addr)
9859 +static inline void set_intr_gate(unsigned int n, const void *addr)
9860 {
9861 BUG_ON((unsigned)n > 0xFF);
9862 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9863 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9864 /*
9865 * This routine sets up an interrupt gate at directory privilege level 3.
9866 */
9867 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9868 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9869 {
9870 BUG_ON((unsigned)n > 0xFF);
9871 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9872 }
9873
9874 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9875 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9876 {
9877 BUG_ON((unsigned)n > 0xFF);
9878 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9879 }
9880
9881 -static inline void set_trap_gate(unsigned int n, void *addr)
9882 +static inline void set_trap_gate(unsigned int n, const void *addr)
9883 {
9884 BUG_ON((unsigned)n > 0xFF);
9885 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9886 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9887 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9888 {
9889 BUG_ON((unsigned)n > 0xFF);
9890 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9891 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9892 }
9893
9894 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9895 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9896 {
9897 BUG_ON((unsigned)n > 0xFF);
9898 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9899 }
9900
9901 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9902 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9903 {
9904 BUG_ON((unsigned)n > 0xFF);
9905 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9906 }
9907
9908 +#ifdef CONFIG_X86_32
9909 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9910 +{
9911 + struct desc_struct d;
9912 +
9913 + if (likely(limit))
9914 + limit = (limit - 1UL) >> PAGE_SHIFT;
9915 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9916 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9917 +}
9918 +#endif
9919 +
9920 #endif /* _ASM_X86_DESC_H */
9921 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9922 index 278441f..b95a174 100644
9923 --- a/arch/x86/include/asm/desc_defs.h
9924 +++ b/arch/x86/include/asm/desc_defs.h
9925 @@ -31,6 +31,12 @@ struct desc_struct {
9926 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9927 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9928 };
9929 + struct {
9930 + u16 offset_low;
9931 + u16 seg;
9932 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9933 + unsigned offset_high: 16;
9934 + } gate;
9935 };
9936 } __attribute__((packed));
9937
9938 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9939 index 3778256..c5d4fce 100644
9940 --- a/arch/x86/include/asm/e820.h
9941 +++ b/arch/x86/include/asm/e820.h
9942 @@ -69,7 +69,7 @@ struct e820map {
9943 #define ISA_START_ADDRESS 0xa0000
9944 #define ISA_END_ADDRESS 0x100000
9945
9946 -#define BIOS_BEGIN 0x000a0000
9947 +#define BIOS_BEGIN 0x000c0000
9948 #define BIOS_END 0x00100000
9949
9950 #define BIOS_ROM_BASE 0xffe00000
9951 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9952 index 5f962df..7289f09 100644
9953 --- a/arch/x86/include/asm/elf.h
9954 +++ b/arch/x86/include/asm/elf.h
9955 @@ -238,7 +238,25 @@ extern int force_personality32;
9956 the loader. We need to make sure that it is out of the way of the program
9957 that it will "exec", and that there is sufficient room for the brk. */
9958
9959 +#ifdef CONFIG_PAX_SEGMEXEC
9960 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9961 +#else
9962 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9963 +#endif
9964 +
9965 +#ifdef CONFIG_PAX_ASLR
9966 +#ifdef CONFIG_X86_32
9967 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9968 +
9969 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9970 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9971 +#else
9972 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9973 +
9974 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9975 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9976 +#endif
9977 +#endif
9978
9979 /* This yields a mask that user programs can use to figure out what
9980 instruction set this CPU supports. This could be done in user space,
9981 @@ -291,9 +309,7 @@ do { \
9982
9983 #define ARCH_DLINFO \
9984 do { \
9985 - if (vdso_enabled) \
9986 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9987 - (unsigned long)current->mm->context.vdso); \
9988 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9989 } while (0)
9990
9991 #define AT_SYSINFO 32
9992 @@ -304,7 +320,7 @@ do { \
9993
9994 #endif /* !CONFIG_X86_32 */
9995
9996 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9997 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9998
9999 #define VDSO_ENTRY \
10000 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10001 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10002 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10003 #define compat_arch_setup_additional_pages syscall32_setup_pages
10004
10005 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10006 -#define arch_randomize_brk arch_randomize_brk
10007 -
10008 /*
10009 * True on X86_32 or when emulating IA32 on X86_64
10010 */
10011 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10012 index cc70c1c..d96d011 100644
10013 --- a/arch/x86/include/asm/emergency-restart.h
10014 +++ b/arch/x86/include/asm/emergency-restart.h
10015 @@ -15,6 +15,6 @@ enum reboot_type {
10016
10017 extern enum reboot_type reboot_type;
10018
10019 -extern void machine_emergency_restart(void);
10020 +extern void machine_emergency_restart(void) __noreturn;
10021
10022 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10023 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
10024 index dbe82a5..c6d8a00 100644
10025 --- a/arch/x86/include/asm/floppy.h
10026 +++ b/arch/x86/include/asm/floppy.h
10027 @@ -157,6 +157,7 @@ static unsigned long dma_mem_alloc(unsigned long size)
10028 }
10029
10030
10031 +static unsigned long vdma_mem_alloc(unsigned long size) __size_overflow(1);
10032 static unsigned long vdma_mem_alloc(unsigned long size)
10033 {
10034 return (unsigned long)vmalloc(size);
10035 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10036 index d09bb03..4ea4194 100644
10037 --- a/arch/x86/include/asm/futex.h
10038 +++ b/arch/x86/include/asm/futex.h
10039 @@ -12,16 +12,18 @@
10040 #include <asm/system.h>
10041
10042 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10043 + typecheck(u32 __user *, uaddr); \
10044 asm volatile("1:\t" insn "\n" \
10045 "2:\t.section .fixup,\"ax\"\n" \
10046 "3:\tmov\t%3, %1\n" \
10047 "\tjmp\t2b\n" \
10048 "\t.previous\n" \
10049 _ASM_EXTABLE(1b, 3b) \
10050 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10051 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10052 : "i" (-EFAULT), "0" (oparg), "1" (0))
10053
10054 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10055 + typecheck(u32 __user *, uaddr); \
10056 asm volatile("1:\tmovl %2, %0\n" \
10057 "\tmovl\t%0, %3\n" \
10058 "\t" insn "\n" \
10059 @@ -34,7 +36,7 @@
10060 _ASM_EXTABLE(1b, 4b) \
10061 _ASM_EXTABLE(2b, 4b) \
10062 : "=&a" (oldval), "=&r" (ret), \
10063 - "+m" (*uaddr), "=&r" (tem) \
10064 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10065 : "r" (oparg), "i" (-EFAULT), "1" (0))
10066
10067 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10068 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10069
10070 switch (op) {
10071 case FUTEX_OP_SET:
10072 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10073 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10074 break;
10075 case FUTEX_OP_ADD:
10076 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10077 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10078 uaddr, oparg);
10079 break;
10080 case FUTEX_OP_OR:
10081 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10082 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10083 return -EFAULT;
10084
10085 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10086 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10087 "2:\t.section .fixup, \"ax\"\n"
10088 "3:\tmov %3, %0\n"
10089 "\tjmp 2b\n"
10090 "\t.previous\n"
10091 _ASM_EXTABLE(1b, 3b)
10092 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10093 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10094 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10095 : "memory"
10096 );
10097 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10098 index eb92a6e..b98b2f4 100644
10099 --- a/arch/x86/include/asm/hw_irq.h
10100 +++ b/arch/x86/include/asm/hw_irq.h
10101 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10102 extern void enable_IO_APIC(void);
10103
10104 /* Statistics */
10105 -extern atomic_t irq_err_count;
10106 -extern atomic_t irq_mis_count;
10107 +extern atomic_unchecked_t irq_err_count;
10108 +extern atomic_unchecked_t irq_mis_count;
10109
10110 /* EISA */
10111 extern void eisa_set_level_irq(unsigned int irq);
10112 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10113 index 2479049..3fb9795 100644
10114 --- a/arch/x86/include/asm/i387.h
10115 +++ b/arch/x86/include/asm/i387.h
10116 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10117 {
10118 int err;
10119
10120 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10121 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10122 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10123 +#endif
10124 +
10125 /* See comment in fxsave() below. */
10126 #ifdef CONFIG_AS_FXSAVEQ
10127 asm volatile("1: fxrstorq %[fx]\n\t"
10128 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10129 {
10130 int err;
10131
10132 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10133 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10134 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10135 +#endif
10136 +
10137 /*
10138 * Clear the bytes not touched by the fxsave and reserved
10139 * for the SW usage.
10140 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10141 "emms\n\t" /* clear stack tags */
10142 "fildl %P[addr]", /* set F?P to defined value */
10143 X86_FEATURE_FXSAVE_LEAK,
10144 - [addr] "m" (tsk->thread.fpu.has_fpu));
10145 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10146
10147 return fpu_restore_checking(&tsk->thread.fpu);
10148 }
10149 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10150 static inline bool interrupted_user_mode(void)
10151 {
10152 struct pt_regs *regs = get_irq_regs();
10153 - return regs && user_mode_vm(regs);
10154 + return regs && user_mode(regs);
10155 }
10156
10157 /*
10158 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10159 index d8e8eef..99f81ae 100644
10160 --- a/arch/x86/include/asm/io.h
10161 +++ b/arch/x86/include/asm/io.h
10162 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10163
10164 #include <linux/vmalloc.h>
10165
10166 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10167 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10168 +{
10169 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10170 +}
10171 +
10172 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10173 +{
10174 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10175 +}
10176 +
10177 /*
10178 * Convert a virtual cached pointer to an uncached pointer
10179 */
10180 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10181 index bba3cf8..06bc8da 100644
10182 --- a/arch/x86/include/asm/irqflags.h
10183 +++ b/arch/x86/include/asm/irqflags.h
10184 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10185 sti; \
10186 sysexit
10187
10188 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10189 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10190 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10191 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10192 +
10193 #else
10194 #define INTERRUPT_RETURN iret
10195 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10196 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10197 index 5478825..839e88c 100644
10198 --- a/arch/x86/include/asm/kprobes.h
10199 +++ b/arch/x86/include/asm/kprobes.h
10200 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10201 #define RELATIVEJUMP_SIZE 5
10202 #define RELATIVECALL_OPCODE 0xe8
10203 #define RELATIVE_ADDR_SIZE 4
10204 -#define MAX_STACK_SIZE 64
10205 -#define MIN_STACK_SIZE(ADDR) \
10206 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10207 - THREAD_SIZE - (unsigned long)(ADDR))) \
10208 - ? (MAX_STACK_SIZE) \
10209 - : (((unsigned long)current_thread_info()) + \
10210 - THREAD_SIZE - (unsigned long)(ADDR)))
10211 +#define MAX_STACK_SIZE 64UL
10212 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10213
10214 #define flush_insn_slot(p) do { } while (0)
10215
10216 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10217 index 52d6640..136b3bd 100644
10218 --- a/arch/x86/include/asm/kvm_host.h
10219 +++ b/arch/x86/include/asm/kvm_host.h
10220 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10221 int (*check_intercept)(struct kvm_vcpu *vcpu,
10222 struct x86_instruction_info *info,
10223 enum x86_intercept_stage stage);
10224 -};
10225 +} __do_const;
10226
10227 struct kvm_arch_async_pf {
10228 u32 token;
10229 @@ -694,7 +694,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
10230 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
10231
10232 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
10233 - const void *val, int bytes);
10234 + const void *val, int bytes) __size_overflow(2);
10235 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
10236
10237 extern bool tdp_enabled;
10238 @@ -781,7 +781,7 @@ int fx_init(struct kvm_vcpu *vcpu);
10239
10240 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
10241 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
10242 - const u8 *new, int bytes);
10243 + const u8 *new, int bytes) __size_overflow(2);
10244 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
10245 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
10246 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
10247 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10248 index 9cdae5d..300d20f 100644
10249 --- a/arch/x86/include/asm/local.h
10250 +++ b/arch/x86/include/asm/local.h
10251 @@ -18,26 +18,58 @@ typedef struct {
10252
10253 static inline void local_inc(local_t *l)
10254 {
10255 - asm volatile(_ASM_INC "%0"
10256 + asm volatile(_ASM_INC "%0\n"
10257 +
10258 +#ifdef CONFIG_PAX_REFCOUNT
10259 + "jno 0f\n"
10260 + _ASM_DEC "%0\n"
10261 + "int $4\n0:\n"
10262 + _ASM_EXTABLE(0b, 0b)
10263 +#endif
10264 +
10265 : "+m" (l->a.counter));
10266 }
10267
10268 static inline void local_dec(local_t *l)
10269 {
10270 - asm volatile(_ASM_DEC "%0"
10271 + asm volatile(_ASM_DEC "%0\n"
10272 +
10273 +#ifdef CONFIG_PAX_REFCOUNT
10274 + "jno 0f\n"
10275 + _ASM_INC "%0\n"
10276 + "int $4\n0:\n"
10277 + _ASM_EXTABLE(0b, 0b)
10278 +#endif
10279 +
10280 : "+m" (l->a.counter));
10281 }
10282
10283 static inline void local_add(long i, local_t *l)
10284 {
10285 - asm volatile(_ASM_ADD "%1,%0"
10286 + asm volatile(_ASM_ADD "%1,%0\n"
10287 +
10288 +#ifdef CONFIG_PAX_REFCOUNT
10289 + "jno 0f\n"
10290 + _ASM_SUB "%1,%0\n"
10291 + "int $4\n0:\n"
10292 + _ASM_EXTABLE(0b, 0b)
10293 +#endif
10294 +
10295 : "+m" (l->a.counter)
10296 : "ir" (i));
10297 }
10298
10299 static inline void local_sub(long i, local_t *l)
10300 {
10301 - asm volatile(_ASM_SUB "%1,%0"
10302 + asm volatile(_ASM_SUB "%1,%0\n"
10303 +
10304 +#ifdef CONFIG_PAX_REFCOUNT
10305 + "jno 0f\n"
10306 + _ASM_ADD "%1,%0\n"
10307 + "int $4\n0:\n"
10308 + _ASM_EXTABLE(0b, 0b)
10309 +#endif
10310 +
10311 : "+m" (l->a.counter)
10312 : "ir" (i));
10313 }
10314 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10315 {
10316 unsigned char c;
10317
10318 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10319 + asm volatile(_ASM_SUB "%2,%0\n"
10320 +
10321 +#ifdef CONFIG_PAX_REFCOUNT
10322 + "jno 0f\n"
10323 + _ASM_ADD "%2,%0\n"
10324 + "int $4\n0:\n"
10325 + _ASM_EXTABLE(0b, 0b)
10326 +#endif
10327 +
10328 + "sete %1\n"
10329 : "+m" (l->a.counter), "=qm" (c)
10330 : "ir" (i) : "memory");
10331 return c;
10332 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10333 {
10334 unsigned char c;
10335
10336 - asm volatile(_ASM_DEC "%0; sete %1"
10337 + asm volatile(_ASM_DEC "%0\n"
10338 +
10339 +#ifdef CONFIG_PAX_REFCOUNT
10340 + "jno 0f\n"
10341 + _ASM_INC "%0\n"
10342 + "int $4\n0:\n"
10343 + _ASM_EXTABLE(0b, 0b)
10344 +#endif
10345 +
10346 + "sete %1\n"
10347 : "+m" (l->a.counter), "=qm" (c)
10348 : : "memory");
10349 return c != 0;
10350 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10351 {
10352 unsigned char c;
10353
10354 - asm volatile(_ASM_INC "%0; sete %1"
10355 + asm volatile(_ASM_INC "%0\n"
10356 +
10357 +#ifdef CONFIG_PAX_REFCOUNT
10358 + "jno 0f\n"
10359 + _ASM_DEC "%0\n"
10360 + "int $4\n0:\n"
10361 + _ASM_EXTABLE(0b, 0b)
10362 +#endif
10363 +
10364 + "sete %1\n"
10365 : "+m" (l->a.counter), "=qm" (c)
10366 : : "memory");
10367 return c != 0;
10368 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10369 {
10370 unsigned char c;
10371
10372 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10373 + asm volatile(_ASM_ADD "%2,%0\n"
10374 +
10375 +#ifdef CONFIG_PAX_REFCOUNT
10376 + "jno 0f\n"
10377 + _ASM_SUB "%2,%0\n"
10378 + "int $4\n0:\n"
10379 + _ASM_EXTABLE(0b, 0b)
10380 +#endif
10381 +
10382 + "sets %1\n"
10383 : "+m" (l->a.counter), "=qm" (c)
10384 : "ir" (i) : "memory");
10385 return c;
10386 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10387 #endif
10388 /* Modern 486+ processor */
10389 __i = i;
10390 - asm volatile(_ASM_XADD "%0, %1;"
10391 + asm volatile(_ASM_XADD "%0, %1\n"
10392 +
10393 +#ifdef CONFIG_PAX_REFCOUNT
10394 + "jno 0f\n"
10395 + _ASM_MOV "%0,%1\n"
10396 + "int $4\n0:\n"
10397 + _ASM_EXTABLE(0b, 0b)
10398 +#endif
10399 +
10400 : "+r" (i), "+m" (l->a.counter)
10401 : : "memory");
10402 return i + __i;
10403 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10404 index 593e51d..fa69c9a 100644
10405 --- a/arch/x86/include/asm/mman.h
10406 +++ b/arch/x86/include/asm/mman.h
10407 @@ -5,4 +5,14 @@
10408
10409 #include <asm-generic/mman.h>
10410
10411 +#ifdef __KERNEL__
10412 +#ifndef __ASSEMBLY__
10413 +#ifdef CONFIG_X86_32
10414 +#define arch_mmap_check i386_mmap_check
10415 +int i386_mmap_check(unsigned long addr, unsigned long len,
10416 + unsigned long flags);
10417 +#endif
10418 +#endif
10419 +#endif
10420 +
10421 #endif /* _ASM_X86_MMAN_H */
10422 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10423 index 5f55e69..e20bfb1 100644
10424 --- a/arch/x86/include/asm/mmu.h
10425 +++ b/arch/x86/include/asm/mmu.h
10426 @@ -9,7 +9,7 @@
10427 * we put the segment information here.
10428 */
10429 typedef struct {
10430 - void *ldt;
10431 + struct desc_struct *ldt;
10432 int size;
10433
10434 #ifdef CONFIG_X86_64
10435 @@ -18,7 +18,19 @@ typedef struct {
10436 #endif
10437
10438 struct mutex lock;
10439 - void *vdso;
10440 + unsigned long vdso;
10441 +
10442 +#ifdef CONFIG_X86_32
10443 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10444 + unsigned long user_cs_base;
10445 + unsigned long user_cs_limit;
10446 +
10447 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10448 + cpumask_t cpu_user_cs_mask;
10449 +#endif
10450 +
10451 +#endif
10452 +#endif
10453 } mm_context_t;
10454
10455 #ifdef CONFIG_SMP
10456 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10457 index 6902152..399f3a2 100644
10458 --- a/arch/x86/include/asm/mmu_context.h
10459 +++ b/arch/x86/include/asm/mmu_context.h
10460 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10461
10462 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10463 {
10464 +
10465 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10466 + unsigned int i;
10467 + pgd_t *pgd;
10468 +
10469 + pax_open_kernel();
10470 + pgd = get_cpu_pgd(smp_processor_id());
10471 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10472 + set_pgd_batched(pgd+i, native_make_pgd(0));
10473 + pax_close_kernel();
10474 +#endif
10475 +
10476 #ifdef CONFIG_SMP
10477 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10478 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10479 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10480 struct task_struct *tsk)
10481 {
10482 unsigned cpu = smp_processor_id();
10483 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10484 + int tlbstate = TLBSTATE_OK;
10485 +#endif
10486
10487 if (likely(prev != next)) {
10488 #ifdef CONFIG_SMP
10489 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10490 + tlbstate = percpu_read(cpu_tlbstate.state);
10491 +#endif
10492 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10493 percpu_write(cpu_tlbstate.active_mm, next);
10494 #endif
10495 cpumask_set_cpu(cpu, mm_cpumask(next));
10496
10497 /* Re-load page tables */
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 +#else
10505 load_cr3(next->pgd);
10506 +#endif
10507
10508 /* stop flush ipis for the previous mm */
10509 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10510 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10511 */
10512 if (unlikely(prev->context.ldt != next->context.ldt))
10513 load_LDT_nolock(&next->context);
10514 - }
10515 +
10516 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10517 + if (!(__supported_pte_mask & _PAGE_NX)) {
10518 + smp_mb__before_clear_bit();
10519 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10520 + smp_mb__after_clear_bit();
10521 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10522 + }
10523 +#endif
10524 +
10525 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10526 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10527 + prev->context.user_cs_limit != next->context.user_cs_limit))
10528 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10529 #ifdef CONFIG_SMP
10530 + else if (unlikely(tlbstate != TLBSTATE_OK))
10531 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10532 +#endif
10533 +#endif
10534 +
10535 + }
10536 else {
10537 +
10538 +#ifdef CONFIG_PAX_PER_CPU_PGD
10539 + pax_open_kernel();
10540 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10541 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10542 + pax_close_kernel();
10543 + load_cr3(get_cpu_pgd(cpu));
10544 +#endif
10545 +
10546 +#ifdef CONFIG_SMP
10547 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10548 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10549
10550 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10551 * tlb flush IPI delivery. We must reload CR3
10552 * to make sure to use no freed page tables.
10553 */
10554 +
10555 +#ifndef CONFIG_PAX_PER_CPU_PGD
10556 load_cr3(next->pgd);
10557 +#endif
10558 +
10559 load_LDT_nolock(&next->context);
10560 +
10561 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10562 + if (!(__supported_pte_mask & _PAGE_NX))
10563 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10564 +#endif
10565 +
10566 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10567 +#ifdef CONFIG_PAX_PAGEEXEC
10568 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10569 +#endif
10570 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10571 +#endif
10572 +
10573 }
10574 +#endif
10575 }
10576 -#endif
10577 }
10578
10579 #define activate_mm(prev, next) \
10580 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10581 index 9eae775..c914fea 100644
10582 --- a/arch/x86/include/asm/module.h
10583 +++ b/arch/x86/include/asm/module.h
10584 @@ -5,6 +5,7 @@
10585
10586 #ifdef CONFIG_X86_64
10587 /* X86_64 does not define MODULE_PROC_FAMILY */
10588 +#define MODULE_PROC_FAMILY ""
10589 #elif defined CONFIG_M386
10590 #define MODULE_PROC_FAMILY "386 "
10591 #elif defined CONFIG_M486
10592 @@ -59,8 +60,20 @@
10593 #error unknown processor family
10594 #endif
10595
10596 -#ifdef CONFIG_X86_32
10597 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10598 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10599 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10600 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10601 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10602 +#else
10603 +#define MODULE_PAX_KERNEXEC ""
10604 #endif
10605
10606 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10607 +#define MODULE_PAX_UDEREF "UDEREF "
10608 +#else
10609 +#define MODULE_PAX_UDEREF ""
10610 +#endif
10611 +
10612 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10613 +
10614 #endif /* _ASM_X86_MODULE_H */
10615 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10616 index 7639dbf..e08a58c 100644
10617 --- a/arch/x86/include/asm/page_64_types.h
10618 +++ b/arch/x86/include/asm/page_64_types.h
10619 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10620
10621 /* duplicated to the one in bootmem.h */
10622 extern unsigned long max_pfn;
10623 -extern unsigned long phys_base;
10624 +extern const unsigned long phys_base;
10625
10626 extern unsigned long __phys_addr(unsigned long);
10627 #define __phys_reloc_hide(x) (x)
10628 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10629 index a7d2db9..edb023e 100644
10630 --- a/arch/x86/include/asm/paravirt.h
10631 +++ b/arch/x86/include/asm/paravirt.h
10632 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10633 val);
10634 }
10635
10636 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10637 +{
10638 + pgdval_t val = native_pgd_val(pgd);
10639 +
10640 + if (sizeof(pgdval_t) > sizeof(long))
10641 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10642 + val, (u64)val >> 32);
10643 + else
10644 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10645 + val);
10646 +}
10647 +
10648 static inline void pgd_clear(pgd_t *pgdp)
10649 {
10650 set_pgd(pgdp, __pgd(0));
10651 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10652 pv_mmu_ops.set_fixmap(idx, phys, flags);
10653 }
10654
10655 +#ifdef CONFIG_PAX_KERNEXEC
10656 +static inline unsigned long pax_open_kernel(void)
10657 +{
10658 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10659 +}
10660 +
10661 +static inline unsigned long pax_close_kernel(void)
10662 +{
10663 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10664 +}
10665 +#else
10666 +static inline unsigned long pax_open_kernel(void) { return 0; }
10667 +static inline unsigned long pax_close_kernel(void) { return 0; }
10668 +#endif
10669 +
10670 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10671
10672 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10673 @@ -964,7 +991,7 @@ extern void default_banner(void);
10674
10675 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10676 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10677 -#define PARA_INDIRECT(addr) *%cs:addr
10678 +#define PARA_INDIRECT(addr) *%ss:addr
10679 #endif
10680
10681 #define INTERRUPT_RETURN \
10682 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10683 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10684 CLBR_NONE, \
10685 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10686 +
10687 +#define GET_CR0_INTO_RDI \
10688 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10689 + mov %rax,%rdi
10690 +
10691 +#define SET_RDI_INTO_CR0 \
10692 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10693 +
10694 +#define GET_CR3_INTO_RDI \
10695 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10696 + mov %rax,%rdi
10697 +
10698 +#define SET_RDI_INTO_CR3 \
10699 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10700 +
10701 #endif /* CONFIG_X86_32 */
10702
10703 #endif /* __ASSEMBLY__ */
10704 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10705 index 8e8b9a4..f07d725 100644
10706 --- a/arch/x86/include/asm/paravirt_types.h
10707 +++ b/arch/x86/include/asm/paravirt_types.h
10708 @@ -84,20 +84,20 @@ struct pv_init_ops {
10709 */
10710 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10711 unsigned long addr, unsigned len);
10712 -};
10713 +} __no_const;
10714
10715
10716 struct pv_lazy_ops {
10717 /* Set deferred update mode, used for batching operations. */
10718 void (*enter)(void);
10719 void (*leave)(void);
10720 -};
10721 +} __no_const;
10722
10723 struct pv_time_ops {
10724 unsigned long long (*sched_clock)(void);
10725 unsigned long long (*steal_clock)(int cpu);
10726 unsigned long (*get_tsc_khz)(void);
10727 -};
10728 +} __no_const;
10729
10730 struct pv_cpu_ops {
10731 /* hooks for various privileged instructions */
10732 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10733
10734 void (*start_context_switch)(struct task_struct *prev);
10735 void (*end_context_switch)(struct task_struct *next);
10736 -};
10737 +} __no_const;
10738
10739 struct pv_irq_ops {
10740 /*
10741 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10742 unsigned long start_eip,
10743 unsigned long start_esp);
10744 #endif
10745 -};
10746 +} __no_const;
10747
10748 struct pv_mmu_ops {
10749 unsigned long (*read_cr2)(void);
10750 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10751 struct paravirt_callee_save make_pud;
10752
10753 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10754 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10755 #endif /* PAGETABLE_LEVELS == 4 */
10756 #endif /* PAGETABLE_LEVELS >= 3 */
10757
10758 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10759 an mfn. We can tell which is which from the index. */
10760 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10761 phys_addr_t phys, pgprot_t flags);
10762 +
10763 +#ifdef CONFIG_PAX_KERNEXEC
10764 + unsigned long (*pax_open_kernel)(void);
10765 + unsigned long (*pax_close_kernel)(void);
10766 +#endif
10767 +
10768 };
10769
10770 struct arch_spinlock;
10771 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10772 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10773 int (*spin_trylock)(struct arch_spinlock *lock);
10774 void (*spin_unlock)(struct arch_spinlock *lock);
10775 -};
10776 +} __no_const;
10777
10778 /* This contains all the paravirt structures: we get a convenient
10779 * number for each function using the offset which we use to indicate
10780 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10781 index b4389a4..b7ff22c 100644
10782 --- a/arch/x86/include/asm/pgalloc.h
10783 +++ b/arch/x86/include/asm/pgalloc.h
10784 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10785 pmd_t *pmd, pte_t *pte)
10786 {
10787 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10788 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10789 +}
10790 +
10791 +static inline void pmd_populate_user(struct mm_struct *mm,
10792 + pmd_t *pmd, pte_t *pte)
10793 +{
10794 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10795 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10796 }
10797
10798 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10799 index 98391db..8f6984e 100644
10800 --- a/arch/x86/include/asm/pgtable-2level.h
10801 +++ b/arch/x86/include/asm/pgtable-2level.h
10802 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10803
10804 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10805 {
10806 + pax_open_kernel();
10807 *pmdp = pmd;
10808 + pax_close_kernel();
10809 }
10810
10811 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10812 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10813 index effff47..f9e4035 100644
10814 --- a/arch/x86/include/asm/pgtable-3level.h
10815 +++ b/arch/x86/include/asm/pgtable-3level.h
10816 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10817
10818 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10819 {
10820 + pax_open_kernel();
10821 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10822 + pax_close_kernel();
10823 }
10824
10825 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10826 {
10827 + pax_open_kernel();
10828 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10829 + pax_close_kernel();
10830 }
10831
10832 /*
10833 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10834 index 49afb3f..ed14d07 100644
10835 --- a/arch/x86/include/asm/pgtable.h
10836 +++ b/arch/x86/include/asm/pgtable.h
10837 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10838
10839 #ifndef __PAGETABLE_PUD_FOLDED
10840 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10841 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10842 #define pgd_clear(pgd) native_pgd_clear(pgd)
10843 #endif
10844
10845 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10846
10847 #define arch_end_context_switch(prev) do {} while(0)
10848
10849 +#define pax_open_kernel() native_pax_open_kernel()
10850 +#define pax_close_kernel() native_pax_close_kernel()
10851 #endif /* CONFIG_PARAVIRT */
10852
10853 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10854 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10855 +
10856 +#ifdef CONFIG_PAX_KERNEXEC
10857 +static inline unsigned long native_pax_open_kernel(void)
10858 +{
10859 + unsigned long cr0;
10860 +
10861 + preempt_disable();
10862 + barrier();
10863 + cr0 = read_cr0() ^ X86_CR0_WP;
10864 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10865 + write_cr0(cr0);
10866 + return cr0 ^ X86_CR0_WP;
10867 +}
10868 +
10869 +static inline unsigned long native_pax_close_kernel(void)
10870 +{
10871 + unsigned long cr0;
10872 +
10873 + cr0 = read_cr0() ^ X86_CR0_WP;
10874 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10875 + write_cr0(cr0);
10876 + barrier();
10877 + preempt_enable_no_resched();
10878 + return cr0 ^ X86_CR0_WP;
10879 +}
10880 +#else
10881 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10882 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10883 +#endif
10884 +
10885 /*
10886 * The following only work if pte_present() is true.
10887 * Undefined behaviour if not..
10888 */
10889 +static inline int pte_user(pte_t pte)
10890 +{
10891 + return pte_val(pte) & _PAGE_USER;
10892 +}
10893 +
10894 static inline int pte_dirty(pte_t pte)
10895 {
10896 return pte_flags(pte) & _PAGE_DIRTY;
10897 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10898 return pte_clear_flags(pte, _PAGE_RW);
10899 }
10900
10901 +static inline pte_t pte_mkread(pte_t pte)
10902 +{
10903 + return __pte(pte_val(pte) | _PAGE_USER);
10904 +}
10905 +
10906 static inline pte_t pte_mkexec(pte_t pte)
10907 {
10908 - return pte_clear_flags(pte, _PAGE_NX);
10909 +#ifdef CONFIG_X86_PAE
10910 + if (__supported_pte_mask & _PAGE_NX)
10911 + return pte_clear_flags(pte, _PAGE_NX);
10912 + else
10913 +#endif
10914 + return pte_set_flags(pte, _PAGE_USER);
10915 +}
10916 +
10917 +static inline pte_t pte_exprotect(pte_t pte)
10918 +{
10919 +#ifdef CONFIG_X86_PAE
10920 + if (__supported_pte_mask & _PAGE_NX)
10921 + return pte_set_flags(pte, _PAGE_NX);
10922 + else
10923 +#endif
10924 + return pte_clear_flags(pte, _PAGE_USER);
10925 }
10926
10927 static inline pte_t pte_mkdirty(pte_t pte)
10928 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10929 #endif
10930
10931 #ifndef __ASSEMBLY__
10932 +
10933 +#ifdef CONFIG_PAX_PER_CPU_PGD
10934 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10935 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10936 +{
10937 + return cpu_pgd[cpu];
10938 +}
10939 +#endif
10940 +
10941 #include <linux/mm_types.h>
10942
10943 static inline int pte_none(pte_t pte)
10944 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10945
10946 static inline int pgd_bad(pgd_t pgd)
10947 {
10948 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10949 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10950 }
10951
10952 static inline int pgd_none(pgd_t pgd)
10953 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10954 * pgd_offset() returns a (pgd_t *)
10955 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10956 */
10957 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10958 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10959 +
10960 +#ifdef CONFIG_PAX_PER_CPU_PGD
10961 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10962 +#endif
10963 +
10964 /*
10965 * a shortcut which implies the use of the kernel's pgd, instead
10966 * of a process's
10967 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10968 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10969 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10970
10971 +#ifdef CONFIG_X86_32
10972 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10973 +#else
10974 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10975 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10976 +
10977 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10978 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10979 +#else
10980 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10981 +#endif
10982 +
10983 +#endif
10984 +
10985 #ifndef __ASSEMBLY__
10986
10987 extern int direct_gbpages;
10988 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
10989 * dst and src can be on the same page, but the range must not overlap,
10990 * and must not cross a page boundary.
10991 */
10992 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10993 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10994 {
10995 - memcpy(dst, src, count * sizeof(pgd_t));
10996 + pax_open_kernel();
10997 + while (count--)
10998 + *dst++ = *src++;
10999 + pax_close_kernel();
11000 }
11001
11002 +#ifdef CONFIG_PAX_PER_CPU_PGD
11003 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11004 +#endif
11005 +
11006 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11007 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11008 +#else
11009 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11010 +#endif
11011
11012 #include <asm-generic/pgtable.h>
11013 #endif /* __ASSEMBLY__ */
11014 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11015 index 0c92113..34a77c6 100644
11016 --- a/arch/x86/include/asm/pgtable_32.h
11017 +++ b/arch/x86/include/asm/pgtable_32.h
11018 @@ -25,9 +25,6 @@
11019 struct mm_struct;
11020 struct vm_area_struct;
11021
11022 -extern pgd_t swapper_pg_dir[1024];
11023 -extern pgd_t initial_page_table[1024];
11024 -
11025 static inline void pgtable_cache_init(void) { }
11026 static inline void check_pgt_cache(void) { }
11027 void paging_init(void);
11028 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11029 # include <asm/pgtable-2level.h>
11030 #endif
11031
11032 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11033 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11034 +#ifdef CONFIG_X86_PAE
11035 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11036 +#endif
11037 +
11038 #if defined(CONFIG_HIGHPTE)
11039 #define pte_offset_map(dir, address) \
11040 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11041 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11042 /* Clear a kernel PTE and flush it from the TLB */
11043 #define kpte_clear_flush(ptep, vaddr) \
11044 do { \
11045 + pax_open_kernel(); \
11046 pte_clear(&init_mm, (vaddr), (ptep)); \
11047 + pax_close_kernel(); \
11048 __flush_tlb_one((vaddr)); \
11049 } while (0)
11050
11051 @@ -74,6 +79,9 @@ do { \
11052
11053 #endif /* !__ASSEMBLY__ */
11054
11055 +#define HAVE_ARCH_UNMAPPED_AREA
11056 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11057 +
11058 /*
11059 * kern_addr_valid() is (1) for FLATMEM and (0) for
11060 * SPARSEMEM and DISCONTIGMEM
11061 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11062 index ed5903b..c7fe163 100644
11063 --- a/arch/x86/include/asm/pgtable_32_types.h
11064 +++ b/arch/x86/include/asm/pgtable_32_types.h
11065 @@ -8,7 +8,7 @@
11066 */
11067 #ifdef CONFIG_X86_PAE
11068 # include <asm/pgtable-3level_types.h>
11069 -# define PMD_SIZE (1UL << PMD_SHIFT)
11070 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11071 # define PMD_MASK (~(PMD_SIZE - 1))
11072 #else
11073 # include <asm/pgtable-2level_types.h>
11074 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11075 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11076 #endif
11077
11078 +#ifdef CONFIG_PAX_KERNEXEC
11079 +#ifndef __ASSEMBLY__
11080 +extern unsigned char MODULES_EXEC_VADDR[];
11081 +extern unsigned char MODULES_EXEC_END[];
11082 +#endif
11083 +#include <asm/boot.h>
11084 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11085 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11086 +#else
11087 +#define ktla_ktva(addr) (addr)
11088 +#define ktva_ktla(addr) (addr)
11089 +#endif
11090 +
11091 #define MODULES_VADDR VMALLOC_START
11092 #define MODULES_END VMALLOC_END
11093 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11094 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11095 index 975f709..107976d 100644
11096 --- a/arch/x86/include/asm/pgtable_64.h
11097 +++ b/arch/x86/include/asm/pgtable_64.h
11098 @@ -16,10 +16,14 @@
11099
11100 extern pud_t level3_kernel_pgt[512];
11101 extern pud_t level3_ident_pgt[512];
11102 +extern pud_t level3_vmalloc_start_pgt[512];
11103 +extern pud_t level3_vmalloc_end_pgt[512];
11104 +extern pud_t level3_vmemmap_pgt[512];
11105 +extern pud_t level2_vmemmap_pgt[512];
11106 extern pmd_t level2_kernel_pgt[512];
11107 extern pmd_t level2_fixmap_pgt[512];
11108 -extern pmd_t level2_ident_pgt[512];
11109 -extern pgd_t init_level4_pgt[];
11110 +extern pmd_t level2_ident_pgt[512*2];
11111 +extern pgd_t init_level4_pgt[512];
11112
11113 #define swapper_pg_dir init_level4_pgt
11114
11115 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11116
11117 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11118 {
11119 + pax_open_kernel();
11120 *pmdp = pmd;
11121 + pax_close_kernel();
11122 }
11123
11124 static inline void native_pmd_clear(pmd_t *pmd)
11125 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11126
11127 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11128 {
11129 + pax_open_kernel();
11130 + *pgdp = pgd;
11131 + pax_close_kernel();
11132 +}
11133 +
11134 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11135 +{
11136 *pgdp = pgd;
11137 }
11138
11139 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11140 index 766ea16..5b96cb3 100644
11141 --- a/arch/x86/include/asm/pgtable_64_types.h
11142 +++ b/arch/x86/include/asm/pgtable_64_types.h
11143 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11144 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11145 #define MODULES_END _AC(0xffffffffff000000, UL)
11146 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11147 +#define MODULES_EXEC_VADDR MODULES_VADDR
11148 +#define MODULES_EXEC_END MODULES_END
11149 +
11150 +#define ktla_ktva(addr) (addr)
11151 +#define ktva_ktla(addr) (addr)
11152
11153 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11154 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11155 index 013286a..8b42f4f 100644
11156 --- a/arch/x86/include/asm/pgtable_types.h
11157 +++ b/arch/x86/include/asm/pgtable_types.h
11158 @@ -16,13 +16,12 @@
11159 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11160 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11161 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11162 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11163 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11164 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11165 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11166 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11167 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11168 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11169 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11170 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11171 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11172 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11173
11174 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11175 @@ -40,7 +39,6 @@
11176 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11177 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11178 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11179 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11180 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11181 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11182 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11183 @@ -57,8 +55,10 @@
11184
11185 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11186 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11187 -#else
11188 +#elif defined(CONFIG_KMEMCHECK)
11189 #define _PAGE_NX (_AT(pteval_t, 0))
11190 +#else
11191 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11192 #endif
11193
11194 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11195 @@ -96,6 +96,9 @@
11196 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11197 _PAGE_ACCESSED)
11198
11199 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11200 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11201 +
11202 #define __PAGE_KERNEL_EXEC \
11203 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11204 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11205 @@ -106,7 +109,7 @@
11206 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11207 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11208 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11209 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11210 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11211 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11212 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11213 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11214 @@ -168,8 +171,8 @@
11215 * bits are combined, this will alow user to access the high address mapped
11216 * VDSO in the presence of CONFIG_COMPAT_VDSO
11217 */
11218 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11219 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11220 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11221 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11222 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11223 #endif
11224
11225 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11226 {
11227 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11228 }
11229 +#endif
11230
11231 +#if PAGETABLE_LEVELS == 3
11232 +#include <asm-generic/pgtable-nopud.h>
11233 +#endif
11234 +
11235 +#if PAGETABLE_LEVELS == 2
11236 +#include <asm-generic/pgtable-nopmd.h>
11237 +#endif
11238 +
11239 +#ifndef __ASSEMBLY__
11240 #if PAGETABLE_LEVELS > 3
11241 typedef struct { pudval_t pud; } pud_t;
11242
11243 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11244 return pud.pud;
11245 }
11246 #else
11247 -#include <asm-generic/pgtable-nopud.h>
11248 -
11249 static inline pudval_t native_pud_val(pud_t pud)
11250 {
11251 return native_pgd_val(pud.pgd);
11252 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11253 return pmd.pmd;
11254 }
11255 #else
11256 -#include <asm-generic/pgtable-nopmd.h>
11257 -
11258 static inline pmdval_t native_pmd_val(pmd_t pmd)
11259 {
11260 return native_pgd_val(pmd.pud.pgd);
11261 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11262
11263 extern pteval_t __supported_pte_mask;
11264 extern void set_nx(void);
11265 -extern int nx_enabled;
11266
11267 #define pgprot_writecombine pgprot_writecombine
11268 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11269 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11270 index 58545c9..fe6fc38e 100644
11271 --- a/arch/x86/include/asm/processor.h
11272 +++ b/arch/x86/include/asm/processor.h
11273 @@ -266,7 +266,7 @@ struct tss_struct {
11274
11275 } ____cacheline_aligned;
11276
11277 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11278 +extern struct tss_struct init_tss[NR_CPUS];
11279
11280 /*
11281 * Save the original ist values for checking stack pointers during debugging
11282 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11283 */
11284 #define TASK_SIZE PAGE_OFFSET
11285 #define TASK_SIZE_MAX TASK_SIZE
11286 +
11287 +#ifdef CONFIG_PAX_SEGMEXEC
11288 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11289 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11290 +#else
11291 #define STACK_TOP TASK_SIZE
11292 -#define STACK_TOP_MAX STACK_TOP
11293 +#endif
11294 +
11295 +#define STACK_TOP_MAX TASK_SIZE
11296
11297 #define INIT_THREAD { \
11298 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11299 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11300 .vm86_info = NULL, \
11301 .sysenter_cs = __KERNEL_CS, \
11302 .io_bitmap_ptr = NULL, \
11303 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11304 */
11305 #define INIT_TSS { \
11306 .x86_tss = { \
11307 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11308 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11309 .ss0 = __KERNEL_DS, \
11310 .ss1 = __KERNEL_CS, \
11311 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11312 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11313 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11314
11315 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11316 -#define KSTK_TOP(info) \
11317 -({ \
11318 - unsigned long *__ptr = (unsigned long *)(info); \
11319 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11320 -})
11321 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11322
11323 /*
11324 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11325 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11326 #define task_pt_regs(task) \
11327 ({ \
11328 struct pt_regs *__regs__; \
11329 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11330 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11331 __regs__ - 1; \
11332 })
11333
11334 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11335 /*
11336 * User space process size. 47bits minus one guard page.
11337 */
11338 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11339 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11340
11341 /* This decides where the kernel will search for a free chunk of vm
11342 * space during mmap's.
11343 */
11344 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11345 - 0xc0000000 : 0xFFFFe000)
11346 + 0xc0000000 : 0xFFFFf000)
11347
11348 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11349 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11350 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11351 #define STACK_TOP_MAX TASK_SIZE_MAX
11352
11353 #define INIT_THREAD { \
11354 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11355 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11356 }
11357
11358 #define INIT_TSS { \
11359 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11360 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11361 }
11362
11363 /*
11364 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11365 */
11366 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11367
11368 +#ifdef CONFIG_PAX_SEGMEXEC
11369 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11370 +#endif
11371 +
11372 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11373
11374 /* Get/set a process' ability to use the timestamp counter instruction */
11375 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11376 index 3566454..4bdfb8c 100644
11377 --- a/arch/x86/include/asm/ptrace.h
11378 +++ b/arch/x86/include/asm/ptrace.h
11379 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11380 }
11381
11382 /*
11383 - * user_mode_vm(regs) determines whether a register set came from user mode.
11384 + * user_mode(regs) determines whether a register set came from user mode.
11385 * This is true if V8086 mode was enabled OR if the register set was from
11386 * protected mode with RPL-3 CS value. This tricky test checks that with
11387 * one comparison. Many places in the kernel can bypass this full check
11388 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11389 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11390 + * be used.
11391 */
11392 -static inline int user_mode(struct pt_regs *regs)
11393 +static inline int user_mode_novm(struct pt_regs *regs)
11394 {
11395 #ifdef CONFIG_X86_32
11396 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11397 #else
11398 - return !!(regs->cs & 3);
11399 + return !!(regs->cs & SEGMENT_RPL_MASK);
11400 #endif
11401 }
11402
11403 -static inline int user_mode_vm(struct pt_regs *regs)
11404 +static inline int user_mode(struct pt_regs *regs)
11405 {
11406 #ifdef CONFIG_X86_32
11407 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11408 USER_RPL;
11409 #else
11410 - return user_mode(regs);
11411 + return user_mode_novm(regs);
11412 #endif
11413 }
11414
11415 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11416 #ifdef CONFIG_X86_64
11417 static inline bool user_64bit_mode(struct pt_regs *regs)
11418 {
11419 + unsigned long cs = regs->cs & 0xffff;
11420 #ifndef CONFIG_PARAVIRT
11421 /*
11422 * On non-paravirt systems, this is the only long mode CPL 3
11423 * selector. We do not allow long mode selectors in the LDT.
11424 */
11425 - return regs->cs == __USER_CS;
11426 + return cs == __USER_CS;
11427 #else
11428 /* Headers are too twisted for this to go in paravirt.h. */
11429 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11430 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11431 #endif
11432 }
11433 #endif
11434 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11435 index 92f29706..a79cbbb 100644
11436 --- a/arch/x86/include/asm/reboot.h
11437 +++ b/arch/x86/include/asm/reboot.h
11438 @@ -6,19 +6,19 @@
11439 struct pt_regs;
11440
11441 struct machine_ops {
11442 - void (*restart)(char *cmd);
11443 - void (*halt)(void);
11444 - void (*power_off)(void);
11445 + void (* __noreturn restart)(char *cmd);
11446 + void (* __noreturn halt)(void);
11447 + void (* __noreturn power_off)(void);
11448 void (*shutdown)(void);
11449 void (*crash_shutdown)(struct pt_regs *);
11450 - void (*emergency_restart)(void);
11451 -};
11452 + void (* __noreturn emergency_restart)(void);
11453 +} __no_const;
11454
11455 extern struct machine_ops machine_ops;
11456
11457 void native_machine_crash_shutdown(struct pt_regs *regs);
11458 void native_machine_shutdown(void);
11459 -void machine_real_restart(unsigned int type);
11460 +void machine_real_restart(unsigned int type) __noreturn;
11461 /* These must match dispatch_table in reboot_32.S */
11462 #define MRR_BIOS 0
11463 #define MRR_APM 1
11464 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11465 index 2dbe4a7..ce1db00 100644
11466 --- a/arch/x86/include/asm/rwsem.h
11467 +++ b/arch/x86/include/asm/rwsem.h
11468 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11469 {
11470 asm volatile("# beginning down_read\n\t"
11471 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11472 +
11473 +#ifdef CONFIG_PAX_REFCOUNT
11474 + "jno 0f\n"
11475 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11476 + "int $4\n0:\n"
11477 + _ASM_EXTABLE(0b, 0b)
11478 +#endif
11479 +
11480 /* adds 0x00000001 */
11481 " jns 1f\n"
11482 " call call_rwsem_down_read_failed\n"
11483 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11484 "1:\n\t"
11485 " mov %1,%2\n\t"
11486 " add %3,%2\n\t"
11487 +
11488 +#ifdef CONFIG_PAX_REFCOUNT
11489 + "jno 0f\n"
11490 + "sub %3,%2\n"
11491 + "int $4\n0:\n"
11492 + _ASM_EXTABLE(0b, 0b)
11493 +#endif
11494 +
11495 " jle 2f\n\t"
11496 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11497 " jnz 1b\n\t"
11498 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11499 long tmp;
11500 asm volatile("# beginning down_write\n\t"
11501 LOCK_PREFIX " xadd %1,(%2)\n\t"
11502 +
11503 +#ifdef CONFIG_PAX_REFCOUNT
11504 + "jno 0f\n"
11505 + "mov %1,(%2)\n"
11506 + "int $4\n0:\n"
11507 + _ASM_EXTABLE(0b, 0b)
11508 +#endif
11509 +
11510 /* adds 0xffff0001, returns the old value */
11511 " test %1,%1\n\t"
11512 /* was the count 0 before? */
11513 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11514 long tmp;
11515 asm volatile("# beginning __up_read\n\t"
11516 LOCK_PREFIX " xadd %1,(%2)\n\t"
11517 +
11518 +#ifdef CONFIG_PAX_REFCOUNT
11519 + "jno 0f\n"
11520 + "mov %1,(%2)\n"
11521 + "int $4\n0:\n"
11522 + _ASM_EXTABLE(0b, 0b)
11523 +#endif
11524 +
11525 /* subtracts 1, returns the old value */
11526 " jns 1f\n\t"
11527 " call call_rwsem_wake\n" /* expects old value in %edx */
11528 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11529 long tmp;
11530 asm volatile("# beginning __up_write\n\t"
11531 LOCK_PREFIX " xadd %1,(%2)\n\t"
11532 +
11533 +#ifdef CONFIG_PAX_REFCOUNT
11534 + "jno 0f\n"
11535 + "mov %1,(%2)\n"
11536 + "int $4\n0:\n"
11537 + _ASM_EXTABLE(0b, 0b)
11538 +#endif
11539 +
11540 /* subtracts 0xffff0001, returns the old value */
11541 " jns 1f\n\t"
11542 " call call_rwsem_wake\n" /* expects old value in %edx */
11543 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11544 {
11545 asm volatile("# beginning __downgrade_write\n\t"
11546 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11547 +
11548 +#ifdef CONFIG_PAX_REFCOUNT
11549 + "jno 0f\n"
11550 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11551 + "int $4\n0:\n"
11552 + _ASM_EXTABLE(0b, 0b)
11553 +#endif
11554 +
11555 /*
11556 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11557 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11558 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11559 */
11560 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11561 {
11562 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11563 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11564 +
11565 +#ifdef CONFIG_PAX_REFCOUNT
11566 + "jno 0f\n"
11567 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11568 + "int $4\n0:\n"
11569 + _ASM_EXTABLE(0b, 0b)
11570 +#endif
11571 +
11572 : "+m" (sem->count)
11573 : "er" (delta));
11574 }
11575 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11576 */
11577 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11578 {
11579 - return delta + xadd(&sem->count, delta);
11580 + return delta + xadd_check_overflow(&sem->count, delta);
11581 }
11582
11583 #endif /* __KERNEL__ */
11584 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11585 index 5e64171..f58957e 100644
11586 --- a/arch/x86/include/asm/segment.h
11587 +++ b/arch/x86/include/asm/segment.h
11588 @@ -64,10 +64,15 @@
11589 * 26 - ESPFIX small SS
11590 * 27 - per-cpu [ offset to per-cpu data area ]
11591 * 28 - stack_canary-20 [ for stack protector ]
11592 - * 29 - unused
11593 - * 30 - unused
11594 + * 29 - PCI BIOS CS
11595 + * 30 - PCI BIOS DS
11596 * 31 - TSS for double fault handler
11597 */
11598 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11599 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11600 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11601 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11602 +
11603 #define GDT_ENTRY_TLS_MIN 6
11604 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11605
11606 @@ -79,6 +84,8 @@
11607
11608 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11609
11610 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11611 +
11612 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11613
11614 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11615 @@ -104,6 +111,12 @@
11616 #define __KERNEL_STACK_CANARY 0
11617 #endif
11618
11619 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11620 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11621 +
11622 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11623 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11624 +
11625 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11626
11627 /*
11628 @@ -141,7 +154,7 @@
11629 */
11630
11631 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11632 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11633 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11634
11635
11636 #else
11637 @@ -165,6 +178,8 @@
11638 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11639 #define __USER32_DS __USER_DS
11640
11641 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11642 +
11643 #define GDT_ENTRY_TSS 8 /* needs two entries */
11644 #define GDT_ENTRY_LDT 10 /* needs two entries */
11645 #define GDT_ENTRY_TLS_MIN 12
11646 @@ -185,6 +200,7 @@
11647 #endif
11648
11649 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11650 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11651 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11652 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11653 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11654 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11655 index 0434c40..1714bf0 100644
11656 --- a/arch/x86/include/asm/smp.h
11657 +++ b/arch/x86/include/asm/smp.h
11658 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11659 /* cpus sharing the last level cache: */
11660 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11661 DECLARE_PER_CPU(u16, cpu_llc_id);
11662 -DECLARE_PER_CPU(int, cpu_number);
11663 +DECLARE_PER_CPU(unsigned int, cpu_number);
11664
11665 static inline struct cpumask *cpu_sibling_mask(int cpu)
11666 {
11667 @@ -77,7 +77,7 @@ struct smp_ops {
11668
11669 void (*send_call_func_ipi)(const struct cpumask *mask);
11670 void (*send_call_func_single_ipi)(int cpu);
11671 -};
11672 +} __no_const;
11673
11674 /* Globals due to paravirt */
11675 extern void set_cpu_sibling_map(int cpu);
11676 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11677 extern int safe_smp_processor_id(void);
11678
11679 #elif defined(CONFIG_X86_64_SMP)
11680 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11681 -
11682 -#define stack_smp_processor_id() \
11683 -({ \
11684 - struct thread_info *ti; \
11685 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11686 - ti->cpu; \
11687 -})
11688 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11689 +#define stack_smp_processor_id() raw_smp_processor_id()
11690 #define safe_smp_processor_id() smp_processor_id()
11691
11692 #endif
11693 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11694 index a82c2bf..2198f61 100644
11695 --- a/arch/x86/include/asm/spinlock.h
11696 +++ b/arch/x86/include/asm/spinlock.h
11697 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11698 static inline void arch_read_lock(arch_rwlock_t *rw)
11699 {
11700 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11701 +
11702 +#ifdef CONFIG_PAX_REFCOUNT
11703 + "jno 0f\n"
11704 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11705 + "int $4\n0:\n"
11706 + _ASM_EXTABLE(0b, 0b)
11707 +#endif
11708 +
11709 "jns 1f\n"
11710 "call __read_lock_failed\n\t"
11711 "1:\n"
11712 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11713 static inline void arch_write_lock(arch_rwlock_t *rw)
11714 {
11715 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11716 +
11717 +#ifdef CONFIG_PAX_REFCOUNT
11718 + "jno 0f\n"
11719 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11720 + "int $4\n0:\n"
11721 + _ASM_EXTABLE(0b, 0b)
11722 +#endif
11723 +
11724 "jz 1f\n"
11725 "call __write_lock_failed\n\t"
11726 "1:\n"
11727 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11728
11729 static inline void arch_read_unlock(arch_rwlock_t *rw)
11730 {
11731 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11732 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11733 +
11734 +#ifdef CONFIG_PAX_REFCOUNT
11735 + "jno 0f\n"
11736 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11737 + "int $4\n0:\n"
11738 + _ASM_EXTABLE(0b, 0b)
11739 +#endif
11740 +
11741 :"+m" (rw->lock) : : "memory");
11742 }
11743
11744 static inline void arch_write_unlock(arch_rwlock_t *rw)
11745 {
11746 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11747 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11748 +
11749 +#ifdef CONFIG_PAX_REFCOUNT
11750 + "jno 0f\n"
11751 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11752 + "int $4\n0:\n"
11753 + _ASM_EXTABLE(0b, 0b)
11754 +#endif
11755 +
11756 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11757 }
11758
11759 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11760 index 1575177..cb23f52 100644
11761 --- a/arch/x86/include/asm/stackprotector.h
11762 +++ b/arch/x86/include/asm/stackprotector.h
11763 @@ -48,7 +48,7 @@
11764 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11765 */
11766 #define GDT_STACK_CANARY_INIT \
11767 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11768 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11769
11770 /*
11771 * Initialize the stackprotector canary value.
11772 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11773
11774 static inline void load_stack_canary_segment(void)
11775 {
11776 -#ifdef CONFIG_X86_32
11777 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11778 asm volatile ("mov %0, %%gs" : : "r" (0));
11779 #endif
11780 }
11781 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11782 index 70bbe39..4ae2bd4 100644
11783 --- a/arch/x86/include/asm/stacktrace.h
11784 +++ b/arch/x86/include/asm/stacktrace.h
11785 @@ -11,28 +11,20 @@
11786
11787 extern int kstack_depth_to_print;
11788
11789 -struct thread_info;
11790 +struct task_struct;
11791 struct stacktrace_ops;
11792
11793 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11794 - unsigned long *stack,
11795 - unsigned long bp,
11796 - const struct stacktrace_ops *ops,
11797 - void *data,
11798 - unsigned long *end,
11799 - int *graph);
11800 +typedef unsigned long walk_stack_t(struct task_struct *task,
11801 + void *stack_start,
11802 + unsigned long *stack,
11803 + unsigned long bp,
11804 + const struct stacktrace_ops *ops,
11805 + void *data,
11806 + unsigned long *end,
11807 + int *graph);
11808
11809 -extern unsigned long
11810 -print_context_stack(struct thread_info *tinfo,
11811 - unsigned long *stack, unsigned long bp,
11812 - const struct stacktrace_ops *ops, void *data,
11813 - unsigned long *end, int *graph);
11814 -
11815 -extern unsigned long
11816 -print_context_stack_bp(struct thread_info *tinfo,
11817 - unsigned long *stack, unsigned long bp,
11818 - const struct stacktrace_ops *ops, void *data,
11819 - unsigned long *end, int *graph);
11820 +extern walk_stack_t print_context_stack;
11821 +extern walk_stack_t print_context_stack_bp;
11822
11823 /* Generic stack tracer with callbacks */
11824
11825 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11826 void (*address)(void *data, unsigned long address, int reliable);
11827 /* On negative return stop dumping */
11828 int (*stack)(void *data, char *name);
11829 - walk_stack_t walk_stack;
11830 + walk_stack_t *walk_stack;
11831 };
11832
11833 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11834 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11835 index cb23852..2dde194 100644
11836 --- a/arch/x86/include/asm/sys_ia32.h
11837 +++ b/arch/x86/include/asm/sys_ia32.h
11838 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11839 compat_sigset_t __user *, unsigned int);
11840 asmlinkage long sys32_alarm(unsigned int);
11841
11842 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11843 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11844 asmlinkage long sys32_sysfs(int, u32, u32);
11845
11846 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11847 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
11848 index f1d8b44..a4de8b7 100644
11849 --- a/arch/x86/include/asm/syscalls.h
11850 +++ b/arch/x86/include/asm/syscalls.h
11851 @@ -30,7 +30,7 @@ long sys_clone(unsigned long, unsigned long, void __user *,
11852 void __user *, struct pt_regs *);
11853
11854 /* kernel/ldt.c */
11855 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
11856 +asmlinkage int sys_modify_ldt(int, void __user *, unsigned long) __size_overflow(3);
11857
11858 /* kernel/signal.c */
11859 long sys_rt_sigreturn(struct pt_regs *);
11860 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11861 index 2d2f01c..f985723 100644
11862 --- a/arch/x86/include/asm/system.h
11863 +++ b/arch/x86/include/asm/system.h
11864 @@ -129,7 +129,7 @@ do { \
11865 "call __switch_to\n\t" \
11866 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11867 __switch_canary \
11868 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11869 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11870 "movq %%rax,%%rdi\n\t" \
11871 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11872 "jnz ret_from_fork\n\t" \
11873 @@ -140,7 +140,7 @@ do { \
11874 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11875 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11876 [_tif_fork] "i" (_TIF_FORK), \
11877 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11878 + [thread_info] "m" (current_tinfo), \
11879 [current_task] "m" (current_task) \
11880 __switch_canary_iparam \
11881 : "memory", "cc" __EXTRA_CLOBBER)
11882 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11883 {
11884 unsigned long __limit;
11885 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11886 - return __limit + 1;
11887 + return __limit;
11888 }
11889
11890 static inline void native_clts(void)
11891 @@ -397,13 +397,13 @@ void enable_hlt(void);
11892
11893 void cpu_idle_wait(void);
11894
11895 -extern unsigned long arch_align_stack(unsigned long sp);
11896 +#define arch_align_stack(x) ((x) & ~0xfUL)
11897 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11898
11899 void default_idle(void);
11900 bool set_pm_idle_to_default(void);
11901
11902 -void stop_this_cpu(void *dummy);
11903 +void stop_this_cpu(void *dummy) __noreturn;
11904
11905 /*
11906 * Force strict CPU ordering.
11907 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11908 index cfd8144..1b1127d 100644
11909 --- a/arch/x86/include/asm/thread_info.h
11910 +++ b/arch/x86/include/asm/thread_info.h
11911 @@ -10,6 +10,7 @@
11912 #include <linux/compiler.h>
11913 #include <asm/page.h>
11914 #include <asm/types.h>
11915 +#include <asm/percpu.h>
11916
11917 /*
11918 * low level task data that entry.S needs immediate access to
11919 @@ -24,7 +25,6 @@ struct exec_domain;
11920 #include <linux/atomic.h>
11921
11922 struct thread_info {
11923 - struct task_struct *task; /* main task structure */
11924 struct exec_domain *exec_domain; /* execution domain */
11925 __u32 flags; /* low level flags */
11926 __u32 status; /* thread synchronous flags */
11927 @@ -34,19 +34,13 @@ struct thread_info {
11928 mm_segment_t addr_limit;
11929 struct restart_block restart_block;
11930 void __user *sysenter_return;
11931 -#ifdef CONFIG_X86_32
11932 - unsigned long previous_esp; /* ESP of the previous stack in
11933 - case of nested (IRQ) stacks
11934 - */
11935 - __u8 supervisor_stack[0];
11936 -#endif
11937 + unsigned long lowest_stack;
11938 unsigned int sig_on_uaccess_error:1;
11939 unsigned int uaccess_err:1; /* uaccess failed */
11940 };
11941
11942 -#define INIT_THREAD_INFO(tsk) \
11943 +#define INIT_THREAD_INFO \
11944 { \
11945 - .task = &tsk, \
11946 .exec_domain = &default_exec_domain, \
11947 .flags = 0, \
11948 .cpu = 0, \
11949 @@ -57,7 +51,7 @@ struct thread_info {
11950 }, \
11951 }
11952
11953 -#define init_thread_info (init_thread_union.thread_info)
11954 +#define init_thread_info (init_thread_union.stack)
11955 #define init_stack (init_thread_union.stack)
11956
11957 #else /* !__ASSEMBLY__ */
11958 @@ -169,45 +163,40 @@ struct thread_info {
11959 ret; \
11960 })
11961
11962 -#ifdef CONFIG_X86_32
11963 -
11964 -#define STACK_WARN (THREAD_SIZE/8)
11965 -/*
11966 - * macros/functions for gaining access to the thread information structure
11967 - *
11968 - * preempt_count needs to be 1 initially, until the scheduler is functional.
11969 - */
11970 -#ifndef __ASSEMBLY__
11971 -
11972 -
11973 -/* how to get the current stack pointer from C */
11974 -register unsigned long current_stack_pointer asm("esp") __used;
11975 -
11976 -/* how to get the thread information struct from C */
11977 -static inline struct thread_info *current_thread_info(void)
11978 -{
11979 - return (struct thread_info *)
11980 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11981 -}
11982 -
11983 -#else /* !__ASSEMBLY__ */
11984 -
11985 +#ifdef __ASSEMBLY__
11986 /* how to get the thread information struct from ASM */
11987 #define GET_THREAD_INFO(reg) \
11988 - movl $-THREAD_SIZE, reg; \
11989 - andl %esp, reg
11990 + mov PER_CPU_VAR(current_tinfo), reg
11991
11992 /* use this one if reg already contains %esp */
11993 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11994 - andl $-THREAD_SIZE, reg
11995 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11996 +#else
11997 +/* how to get the thread information struct from C */
11998 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11999 +
12000 +static __always_inline struct thread_info *current_thread_info(void)
12001 +{
12002 + return percpu_read_stable(current_tinfo);
12003 +}
12004 +#endif
12005 +
12006 +#ifdef CONFIG_X86_32
12007 +
12008 +#define STACK_WARN (THREAD_SIZE/8)
12009 +/*
12010 + * macros/functions for gaining access to the thread information structure
12011 + *
12012 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12013 + */
12014 +#ifndef __ASSEMBLY__
12015 +
12016 +/* how to get the current stack pointer from C */
12017 +register unsigned long current_stack_pointer asm("esp") __used;
12018
12019 #endif
12020
12021 #else /* X86_32 */
12022
12023 -#include <asm/percpu.h>
12024 -#define KERNEL_STACK_OFFSET (5*8)
12025 -
12026 /*
12027 * macros/functions for gaining access to the thread information structure
12028 * preempt_count needs to be 1 initially, until the scheduler is functional.
12029 @@ -215,27 +204,8 @@ static inline struct thread_info *current_thread_info(void)
12030 #ifndef __ASSEMBLY__
12031 DECLARE_PER_CPU(unsigned long, kernel_stack);
12032
12033 -static inline struct thread_info *current_thread_info(void)
12034 -{
12035 - struct thread_info *ti;
12036 - ti = (void *)(percpu_read_stable(kernel_stack) +
12037 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12038 - return ti;
12039 -}
12040 -
12041 -#else /* !__ASSEMBLY__ */
12042 -
12043 -/* how to get the thread information struct from ASM */
12044 -#define GET_THREAD_INFO(reg) \
12045 - movq PER_CPU_VAR(kernel_stack),reg ; \
12046 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12047 -
12048 -/*
12049 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12050 - * a certain register (to be used in assembler memory operands).
12051 - */
12052 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12053 -
12054 +/* how to get the current stack pointer from C */
12055 +register unsigned long current_stack_pointer asm("rsp") __used;
12056 #endif
12057
12058 #endif /* !X86_32 */
12059 @@ -269,5 +239,16 @@ extern void arch_task_cache_init(void);
12060 extern void free_thread_info(struct thread_info *ti);
12061 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12062 #define arch_task_cache_init arch_task_cache_init
12063 +
12064 +#define __HAVE_THREAD_FUNCTIONS
12065 +#define task_thread_info(task) (&(task)->tinfo)
12066 +#define task_stack_page(task) ((task)->stack)
12067 +#define setup_thread_stack(p, org) do {} while (0)
12068 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12069 +
12070 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12071 +extern struct task_struct *alloc_task_struct_node(int node);
12072 +extern void free_task_struct(struct task_struct *);
12073 +
12074 #endif
12075 #endif /* _ASM_X86_THREAD_INFO_H */
12076 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12077 index 8be5f54..7ae826d 100644
12078 --- a/arch/x86/include/asm/uaccess.h
12079 +++ b/arch/x86/include/asm/uaccess.h
12080 @@ -7,12 +7,15 @@
12081 #include <linux/compiler.h>
12082 #include <linux/thread_info.h>
12083 #include <linux/string.h>
12084 +#include <linux/sched.h>
12085 #include <asm/asm.h>
12086 #include <asm/page.h>
12087
12088 #define VERIFY_READ 0
12089 #define VERIFY_WRITE 1
12090
12091 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12092 +
12093 /*
12094 * The fs value determines whether argument validity checking should be
12095 * performed or not. If get_fs() == USER_DS, checking is performed, with
12096 @@ -28,7 +31,12 @@
12097
12098 #define get_ds() (KERNEL_DS)
12099 #define get_fs() (current_thread_info()->addr_limit)
12100 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12101 +void __set_fs(mm_segment_t x);
12102 +void set_fs(mm_segment_t x);
12103 +#else
12104 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12105 +#endif
12106
12107 #define segment_eq(a, b) ((a).seg == (b).seg)
12108
12109 @@ -76,7 +84,33 @@
12110 * checks that the pointer is in the user space range - after calling
12111 * this function, memory access functions may still return -EFAULT.
12112 */
12113 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12114 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12115 +#define access_ok(type, addr, size) \
12116 +({ \
12117 + long __size = size; \
12118 + unsigned long __addr = (unsigned long)addr; \
12119 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12120 + unsigned long __end_ao = __addr + __size - 1; \
12121 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12122 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12123 + while(__addr_ao <= __end_ao) { \
12124 + char __c_ao; \
12125 + __addr_ao += PAGE_SIZE; \
12126 + if (__size > PAGE_SIZE) \
12127 + cond_resched(); \
12128 + if (__get_user(__c_ao, (char __user *)__addr)) \
12129 + break; \
12130 + if (type != VERIFY_WRITE) { \
12131 + __addr = __addr_ao; \
12132 + continue; \
12133 + } \
12134 + if (__put_user(__c_ao, (char __user *)__addr)) \
12135 + break; \
12136 + __addr = __addr_ao; \
12137 + } \
12138 + } \
12139 + __ret_ao; \
12140 +})
12141
12142 /*
12143 * The exception table consists of pairs of addresses: the first is the
12144 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12145 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12146 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12147
12148 -
12149 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12150 +#define __copyuser_seg "gs;"
12151 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12152 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12153 +#else
12154 +#define __copyuser_seg
12155 +#define __COPYUSER_SET_ES
12156 +#define __COPYUSER_RESTORE_ES
12157 +#endif
12158
12159 #ifdef CONFIG_X86_32
12160 #define __put_user_asm_u64(x, addr, err, errret) \
12161 - asm volatile("1: movl %%eax,0(%2)\n" \
12162 - "2: movl %%edx,4(%2)\n" \
12163 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12164 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12165 "3:\n" \
12166 ".section .fixup,\"ax\"\n" \
12167 "4: movl %3,%0\n" \
12168 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12169 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12170
12171 #define __put_user_asm_ex_u64(x, addr) \
12172 - asm volatile("1: movl %%eax,0(%1)\n" \
12173 - "2: movl %%edx,4(%1)\n" \
12174 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12175 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12176 "3:\n" \
12177 _ASM_EXTABLE(1b, 2b - 1b) \
12178 _ASM_EXTABLE(2b, 3b - 2b) \
12179 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12180 __typeof__(*(ptr)) __pu_val; \
12181 __chk_user_ptr(ptr); \
12182 might_fault(); \
12183 - __pu_val = x; \
12184 + __pu_val = (x); \
12185 switch (sizeof(*(ptr))) { \
12186 case 1: \
12187 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12188 @@ -373,7 +415,7 @@ do { \
12189 } while (0)
12190
12191 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12192 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12193 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12194 "2:\n" \
12195 ".section .fixup,\"ax\"\n" \
12196 "3: mov %3,%0\n" \
12197 @@ -381,7 +423,7 @@ do { \
12198 " jmp 2b\n" \
12199 ".previous\n" \
12200 _ASM_EXTABLE(1b, 3b) \
12201 - : "=r" (err), ltype(x) \
12202 + : "=r" (err), ltype (x) \
12203 : "m" (__m(addr)), "i" (errret), "0" (err))
12204
12205 #define __get_user_size_ex(x, ptr, size) \
12206 @@ -406,7 +448,7 @@ do { \
12207 } while (0)
12208
12209 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12210 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12211 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12212 "2:\n" \
12213 _ASM_EXTABLE(1b, 2b - 1b) \
12214 : ltype(x) : "m" (__m(addr)))
12215 @@ -423,13 +465,24 @@ do { \
12216 int __gu_err; \
12217 unsigned long __gu_val; \
12218 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12219 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12220 + (x) = (__typeof__(*(ptr)))__gu_val; \
12221 __gu_err; \
12222 })
12223
12224 /* FIXME: this hack is definitely wrong -AK */
12225 struct __large_struct { unsigned long buf[100]; };
12226 -#define __m(x) (*(struct __large_struct __user *)(x))
12227 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12228 +#define ____m(x) \
12229 +({ \
12230 + unsigned long ____x = (unsigned long)(x); \
12231 + if (____x < PAX_USER_SHADOW_BASE) \
12232 + ____x += PAX_USER_SHADOW_BASE; \
12233 + (void __user *)____x; \
12234 +})
12235 +#else
12236 +#define ____m(x) (x)
12237 +#endif
12238 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12239
12240 /*
12241 * Tell gcc we read from memory instead of writing: this is because
12242 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12243 * aliasing issues.
12244 */
12245 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12246 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12247 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12248 "2:\n" \
12249 ".section .fixup,\"ax\"\n" \
12250 "3: mov %3,%0\n" \
12251 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12252 ".previous\n" \
12253 _ASM_EXTABLE(1b, 3b) \
12254 : "=r"(err) \
12255 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12256 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12257
12258 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12259 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12260 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12261 "2:\n" \
12262 _ASM_EXTABLE(1b, 2b - 1b) \
12263 : : ltype(x), "m" (__m(addr)))
12264 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12265 * On error, the variable @x is set to zero.
12266 */
12267
12268 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12269 +#define __get_user(x, ptr) get_user((x), (ptr))
12270 +#else
12271 #define __get_user(x, ptr) \
12272 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12273 +#endif
12274
12275 /**
12276 * __put_user: - Write a simple value into user space, with less checking.
12277 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12278 * Returns zero on success, or -EFAULT on error.
12279 */
12280
12281 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12282 +#define __put_user(x, ptr) put_user((x), (ptr))
12283 +#else
12284 #define __put_user(x, ptr) \
12285 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12286 +#endif
12287
12288 #define __get_user_unaligned __get_user
12289 #define __put_user_unaligned __put_user
12290 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12291 #define get_user_ex(x, ptr) do { \
12292 unsigned long __gue_val; \
12293 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12294 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12295 + (x) = (__typeof__(*(ptr)))__gue_val; \
12296 } while (0)
12297
12298 #ifdef CONFIG_X86_WP_WORKS_OK
12299 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12300 index 566e803..7183d0b 100644
12301 --- a/arch/x86/include/asm/uaccess_32.h
12302 +++ b/arch/x86/include/asm/uaccess_32.h
12303 @@ -11,15 +11,15 @@
12304 #include <asm/page.h>
12305
12306 unsigned long __must_check __copy_to_user_ll
12307 - (void __user *to, const void *from, unsigned long n);
12308 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12309 unsigned long __must_check __copy_from_user_ll
12310 - (void *to, const void __user *from, unsigned long n);
12311 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12312 unsigned long __must_check __copy_from_user_ll_nozero
12313 - (void *to, const void __user *from, unsigned long n);
12314 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12315 unsigned long __must_check __copy_from_user_ll_nocache
12316 - (void *to, const void __user *from, unsigned long n);
12317 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12318 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12319 - (void *to, const void __user *from, unsigned long n);
12320 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12321
12322 /**
12323 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12324 @@ -41,8 +41,13 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12325 */
12326
12327 static __always_inline unsigned long __must_check
12328 +__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12329 +static __always_inline unsigned long __must_check
12330 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12331 {
12332 + if ((long)n < 0)
12333 + return n;
12334 +
12335 if (__builtin_constant_p(n)) {
12336 unsigned long ret;
12337
12338 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12339 return ret;
12340 }
12341 }
12342 + if (!__builtin_constant_p(n))
12343 + check_object_size(from, n, true);
12344 return __copy_to_user_ll(to, from, n);
12345 }
12346
12347 @@ -79,15 +86,23 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12348 * On success, this will be zero.
12349 */
12350 static __always_inline unsigned long __must_check
12351 +__copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12352 +static __always_inline unsigned long __must_check
12353 __copy_to_user(void __user *to, const void *from, unsigned long n)
12354 {
12355 might_fault();
12356 +
12357 return __copy_to_user_inatomic(to, from, n);
12358 }
12359
12360 static __always_inline unsigned long
12361 +__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12362 +static __always_inline unsigned long
12363 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12364 {
12365 + if ((long)n < 0)
12366 + return n;
12367 +
12368 /* Avoid zeroing the tail if the copy fails..
12369 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12370 * but as the zeroing behaviour is only significant when n is not
12371 @@ -134,9 +149,15 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12372 * for explanation of why this is needed.
12373 */
12374 static __always_inline unsigned long
12375 +__copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12376 +static __always_inline unsigned long
12377 __copy_from_user(void *to, const void __user *from, unsigned long n)
12378 {
12379 might_fault();
12380 +
12381 + if ((long)n < 0)
12382 + return n;
12383 +
12384 if (__builtin_constant_p(n)) {
12385 unsigned long ret;
12386
12387 @@ -152,13 +173,21 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12388 return ret;
12389 }
12390 }
12391 + if (!__builtin_constant_p(n))
12392 + check_object_size(to, n, false);
12393 return __copy_from_user_ll(to, from, n);
12394 }
12395
12396 static __always_inline unsigned long __copy_from_user_nocache(void *to,
12397 + const void __user *from, unsigned long n) __size_overflow(3);
12398 +static __always_inline unsigned long __copy_from_user_nocache(void *to,
12399 const void __user *from, unsigned long n)
12400 {
12401 might_fault();
12402 +
12403 + if ((long)n < 0)
12404 + return n;
12405 +
12406 if (__builtin_constant_p(n)) {
12407 unsigned long ret;
12408
12409 @@ -179,17 +208,24 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12410
12411 static __always_inline unsigned long
12412 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12413 + unsigned long n) __size_overflow(3);
12414 +static __always_inline unsigned long
12415 +__copy_from_user_inatomic_nocache(void *to, const void __user *from,
12416 unsigned long n)
12417 {
12418 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12419 + if ((long)n < 0)
12420 + return n;
12421 +
12422 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12423 }
12424
12425 -unsigned long __must_check copy_to_user(void __user *to,
12426 - const void *from, unsigned long n);
12427 -unsigned long __must_check _copy_from_user(void *to,
12428 - const void __user *from,
12429 - unsigned long n);
12430 -
12431 +extern void copy_to_user_overflow(void)
12432 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12433 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12434 +#else
12435 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12436 +#endif
12437 +;
12438
12439 extern void copy_from_user_overflow(void)
12440 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12441 @@ -199,17 +235,65 @@ extern void copy_from_user_overflow(void)
12442 #endif
12443 ;
12444
12445 -static inline unsigned long __must_check copy_from_user(void *to,
12446 - const void __user *from,
12447 - unsigned long n)
12448 +/**
12449 + * copy_to_user: - Copy a block of data into user space.
12450 + * @to: Destination address, in user space.
12451 + * @from: Source address, in kernel space.
12452 + * @n: Number of bytes to copy.
12453 + *
12454 + * Context: User context only. This function may sleep.
12455 + *
12456 + * Copy data from kernel space to user space.
12457 + *
12458 + * Returns number of bytes that could not be copied.
12459 + * On success, this will be zero.
12460 + */
12461 +static inline unsigned long __must_check
12462 +copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12463 +static inline unsigned long __must_check
12464 +copy_to_user(void __user *to, const void *from, unsigned long n)
12465 +{
12466 + int sz = __compiletime_object_size(from);
12467 +
12468 + if (unlikely(sz != -1 && sz < n))
12469 + copy_to_user_overflow();
12470 + else if (access_ok(VERIFY_WRITE, to, n))
12471 + n = __copy_to_user(to, from, n);
12472 + return n;
12473 +}
12474 +
12475 +/**
12476 + * copy_from_user: - Copy a block of data from user space.
12477 + * @to: Destination address, in kernel space.
12478 + * @from: Source address, in user space.
12479 + * @n: Number of bytes to copy.
12480 + *
12481 + * Context: User context only. This function may sleep.
12482 + *
12483 + * Copy data from user space to kernel space.
12484 + *
12485 + * Returns number of bytes that could not be copied.
12486 + * On success, this will be zero.
12487 + *
12488 + * If some data could not be copied, this function will pad the copied
12489 + * data to the requested size using zero bytes.
12490 + */
12491 +static inline unsigned long __must_check
12492 +copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12493 +static inline unsigned long __must_check
12494 +copy_from_user(void *to, const void __user *from, unsigned long n)
12495 {
12496 int sz = __compiletime_object_size(to);
12497
12498 - if (likely(sz == -1 || sz >= n))
12499 - n = _copy_from_user(to, from, n);
12500 - else
12501 + if (unlikely(sz != -1 && sz < n))
12502 copy_from_user_overflow();
12503 -
12504 + else if (access_ok(VERIFY_READ, from, n))
12505 + n = __copy_from_user(to, from, n);
12506 + else if ((long)n > 0) {
12507 + if (!__builtin_constant_p(n))
12508 + check_object_size(to, n, false);
12509 + memset(to, 0, n);
12510 + }
12511 return n;
12512 }
12513
12514 @@ -235,7 +319,7 @@ long __must_check __strncpy_from_user(char *dst,
12515 #define strlen_user(str) strnlen_user(str, LONG_MAX)
12516
12517 long strnlen_user(const char __user *str, long n);
12518 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12519 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12520 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12521 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12522
12523 #endif /* _ASM_X86_UACCESS_32_H */
12524 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12525 index 1c66d30..e294b5f 100644
12526 --- a/arch/x86/include/asm/uaccess_64.h
12527 +++ b/arch/x86/include/asm/uaccess_64.h
12528 @@ -10,6 +10,9 @@
12529 #include <asm/alternative.h>
12530 #include <asm/cpufeature.h>
12531 #include <asm/page.h>
12532 +#include <asm/pgtable.h>
12533 +
12534 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12535
12536 /*
12537 * Copy To/From Userspace
12538 @@ -17,12 +20,14 @@
12539
12540 /* Handles exceptions in both to and from, but doesn't do access_ok */
12541 __must_check unsigned long
12542 -copy_user_generic_string(void *to, const void *from, unsigned len);
12543 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
12544 __must_check unsigned long
12545 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12546 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
12547
12548 static __always_inline __must_check unsigned long
12549 -copy_user_generic(void *to, const void *from, unsigned len)
12550 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
12551 +static __always_inline __must_check unsigned long
12552 +copy_user_generic(void *to, const void *from, unsigned long len)
12553 {
12554 unsigned ret;
12555
12556 @@ -32,142 +37,237 @@ copy_user_generic(void *to, const void *from, unsigned len)
12557 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12558 "=d" (len)),
12559 "1" (to), "2" (from), "3" (len)
12560 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12561 + : "memory", "rcx", "r8", "r9", "r11");
12562 return ret;
12563 }
12564
12565 +static __always_inline __must_check unsigned long
12566 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
12567 +static __always_inline __must_check unsigned long
12568 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
12569 __must_check unsigned long
12570 -_copy_to_user(void __user *to, const void *from, unsigned len);
12571 -__must_check unsigned long
12572 -_copy_from_user(void *to, const void __user *from, unsigned len);
12573 -__must_check unsigned long
12574 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12575 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
12576
12577 static inline unsigned long __must_check copy_from_user(void *to,
12578 const void __user *from,
12579 + unsigned long n) __size_overflow(3);
12580 +static inline unsigned long __must_check copy_from_user(void *to,
12581 + const void __user *from,
12582 unsigned long n)
12583 {
12584 - int sz = __compiletime_object_size(to);
12585 -
12586 might_fault();
12587 - if (likely(sz == -1 || sz >= n))
12588 - n = _copy_from_user(to, from, n);
12589 -#ifdef CONFIG_DEBUG_VM
12590 - else
12591 - WARN(1, "Buffer overflow detected!\n");
12592 -#endif
12593 +
12594 + if (access_ok(VERIFY_READ, from, n))
12595 + n = __copy_from_user(to, from, n);
12596 + else if (n < INT_MAX) {
12597 + if (!__builtin_constant_p(n))
12598 + check_object_size(to, n, false);
12599 + memset(to, 0, n);
12600 + }
12601 return n;
12602 }
12603
12604 static __always_inline __must_check
12605 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12606 +int copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12607 +static __always_inline __must_check
12608 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12609 {
12610 might_fault();
12611
12612 - return _copy_to_user(dst, src, size);
12613 + if (access_ok(VERIFY_WRITE, dst, size))
12614 + size = __copy_to_user(dst, src, size);
12615 + return size;
12616 }
12617
12618 static __always_inline __must_check
12619 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12620 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12621 +static __always_inline __must_check
12622 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12623 {
12624 - int ret = 0;
12625 + int sz = __compiletime_object_size(dst);
12626 + unsigned ret = 0;
12627
12628 might_fault();
12629 - if (!__builtin_constant_p(size))
12630 - return copy_user_generic(dst, (__force void *)src, size);
12631 +
12632 + if (size > INT_MAX)
12633 + return size;
12634 +
12635 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12636 + if (!__access_ok(VERIFY_READ, src, size))
12637 + return size;
12638 +#endif
12639 +
12640 + if (unlikely(sz != -1 && sz < size)) {
12641 +#ifdef CONFIG_DEBUG_VM
12642 + WARN(1, "Buffer overflow detected!\n");
12643 +#endif
12644 + return size;
12645 + }
12646 +
12647 + if (!__builtin_constant_p(size)) {
12648 + check_object_size(dst, size, false);
12649 +
12650 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12651 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12652 + src += PAX_USER_SHADOW_BASE;
12653 +#endif
12654 +
12655 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12656 + }
12657 switch (size) {
12658 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12659 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12660 ret, "b", "b", "=q", 1);
12661 return ret;
12662 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12663 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12664 ret, "w", "w", "=r", 2);
12665 return ret;
12666 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12667 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12668 ret, "l", "k", "=r", 4);
12669 return ret;
12670 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12671 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12672 ret, "q", "", "=r", 8);
12673 return ret;
12674 case 10:
12675 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12676 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12677 ret, "q", "", "=r", 10);
12678 if (unlikely(ret))
12679 return ret;
12680 __get_user_asm(*(u16 *)(8 + (char *)dst),
12681 - (u16 __user *)(8 + (char __user *)src),
12682 + (const u16 __user *)(8 + (const char __user *)src),
12683 ret, "w", "w", "=r", 2);
12684 return ret;
12685 case 16:
12686 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12687 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12688 ret, "q", "", "=r", 16);
12689 if (unlikely(ret))
12690 return ret;
12691 __get_user_asm(*(u64 *)(8 + (char *)dst),
12692 - (u64 __user *)(8 + (char __user *)src),
12693 + (const u64 __user *)(8 + (const char __user *)src),
12694 ret, "q", "", "=r", 8);
12695 return ret;
12696 default:
12697 - return copy_user_generic(dst, (__force void *)src, size);
12698 +
12699 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12700 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12701 + src += PAX_USER_SHADOW_BASE;
12702 +#endif
12703 +
12704 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12705 }
12706 }
12707
12708 static __always_inline __must_check
12709 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12710 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12711 +static __always_inline __must_check
12712 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12713 {
12714 - int ret = 0;
12715 + int sz = __compiletime_object_size(src);
12716 + unsigned ret = 0;
12717
12718 might_fault();
12719 - if (!__builtin_constant_p(size))
12720 - return copy_user_generic((__force void *)dst, src, size);
12721 +
12722 + if (size > INT_MAX)
12723 + return size;
12724 +
12725 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12726 + if (!__access_ok(VERIFY_WRITE, dst, size))
12727 + return size;
12728 +#endif
12729 +
12730 + if (unlikely(sz != -1 && sz < size)) {
12731 +#ifdef CONFIG_DEBUG_VM
12732 + WARN(1, "Buffer overflow detected!\n");
12733 +#endif
12734 + return size;
12735 + }
12736 +
12737 + if (!__builtin_constant_p(size)) {
12738 + check_object_size(src, size, true);
12739 +
12740 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12741 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12742 + dst += PAX_USER_SHADOW_BASE;
12743 +#endif
12744 +
12745 + return copy_user_generic((__force_kernel void *)dst, src, size);
12746 + }
12747 switch (size) {
12748 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12749 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12750 ret, "b", "b", "iq", 1);
12751 return ret;
12752 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12753 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12754 ret, "w", "w", "ir", 2);
12755 return ret;
12756 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12757 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12758 ret, "l", "k", "ir", 4);
12759 return ret;
12760 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12761 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12762 ret, "q", "", "er", 8);
12763 return ret;
12764 case 10:
12765 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12766 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12767 ret, "q", "", "er", 10);
12768 if (unlikely(ret))
12769 return ret;
12770 asm("":::"memory");
12771 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12772 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12773 ret, "w", "w", "ir", 2);
12774 return ret;
12775 case 16:
12776 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12777 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12778 ret, "q", "", "er", 16);
12779 if (unlikely(ret))
12780 return ret;
12781 asm("":::"memory");
12782 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12783 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12784 ret, "q", "", "er", 8);
12785 return ret;
12786 default:
12787 - return copy_user_generic((__force void *)dst, src, size);
12788 +
12789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12790 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12791 + dst += PAX_USER_SHADOW_BASE;
12792 +#endif
12793 +
12794 + return copy_user_generic((__force_kernel void *)dst, src, size);
12795 }
12796 }
12797
12798 static __always_inline __must_check
12799 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12800 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size) __size_overflow(3);
12801 +static __always_inline __must_check
12802 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12803 {
12804 - int ret = 0;
12805 + unsigned ret = 0;
12806
12807 might_fault();
12808 - if (!__builtin_constant_p(size))
12809 - return copy_user_generic((__force void *)dst,
12810 - (__force void *)src, size);
12811 +
12812 + if (size > INT_MAX)
12813 + return size;
12814 +
12815 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12816 + if (!__access_ok(VERIFY_READ, src, size))
12817 + return size;
12818 + if (!__access_ok(VERIFY_WRITE, dst, size))
12819 + return size;
12820 +#endif
12821 +
12822 + if (!__builtin_constant_p(size)) {
12823 +
12824 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12825 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12826 + src += PAX_USER_SHADOW_BASE;
12827 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12828 + dst += PAX_USER_SHADOW_BASE;
12829 +#endif
12830 +
12831 + return copy_user_generic((__force_kernel void *)dst,
12832 + (__force_kernel const void *)src, size);
12833 + }
12834 switch (size) {
12835 case 1: {
12836 u8 tmp;
12837 - __get_user_asm(tmp, (u8 __user *)src,
12838 + __get_user_asm(tmp, (const u8 __user *)src,
12839 ret, "b", "b", "=q", 1);
12840 if (likely(!ret))
12841 __put_user_asm(tmp, (u8 __user *)dst,
12842 @@ -176,7 +276,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12843 }
12844 case 2: {
12845 u16 tmp;
12846 - __get_user_asm(tmp, (u16 __user *)src,
12847 + __get_user_asm(tmp, (const u16 __user *)src,
12848 ret, "w", "w", "=r", 2);
12849 if (likely(!ret))
12850 __put_user_asm(tmp, (u16 __user *)dst,
12851 @@ -186,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12852
12853 case 4: {
12854 u32 tmp;
12855 - __get_user_asm(tmp, (u32 __user *)src,
12856 + __get_user_asm(tmp, (const u32 __user *)src,
12857 ret, "l", "k", "=r", 4);
12858 if (likely(!ret))
12859 __put_user_asm(tmp, (u32 __user *)dst,
12860 @@ -195,7 +295,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12861 }
12862 case 8: {
12863 u64 tmp;
12864 - __get_user_asm(tmp, (u64 __user *)src,
12865 + __get_user_asm(tmp, (const u64 __user *)src,
12866 ret, "q", "", "=r", 8);
12867 if (likely(!ret))
12868 __put_user_asm(tmp, (u64 __user *)dst,
12869 @@ -203,8 +303,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12870 return ret;
12871 }
12872 default:
12873 - return copy_user_generic((__force void *)dst,
12874 - (__force void *)src, size);
12875 +
12876 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12877 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12878 + src += PAX_USER_SHADOW_BASE;
12879 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12880 + dst += PAX_USER_SHADOW_BASE;
12881 +#endif
12882 +
12883 + return copy_user_generic((__force_kernel void *)dst,
12884 + (__force_kernel const void *)src, size);
12885 }
12886 }
12887
12888 @@ -215,39 +323,83 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
12889 __must_check long strnlen_user(const char __user *str, long n);
12890 __must_check long __strnlen_user(const char __user *str, long n);
12891 __must_check long strlen_user(const char __user *str);
12892 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
12893 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12894 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12895 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12896
12897 static __must_check __always_inline int
12898 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12899 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12900 +static __must_check __always_inline int
12901 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12902 {
12903 - return copy_user_generic(dst, (__force const void *)src, size);
12904 + if (size > INT_MAX)
12905 + return size;
12906 +
12907 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12908 + if (!__access_ok(VERIFY_READ, src, size))
12909 + return size;
12910 +
12911 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12912 + src += PAX_USER_SHADOW_BASE;
12913 +#endif
12914 +
12915 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12916 }
12917
12918 -static __must_check __always_inline int
12919 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12920 +static __must_check __always_inline unsigned long
12921 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12922 +static __must_check __always_inline unsigned long
12923 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12924 {
12925 - return copy_user_generic((__force void *)dst, src, size);
12926 + if (size > INT_MAX)
12927 + return size;
12928 +
12929 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12930 + if (!__access_ok(VERIFY_WRITE, dst, size))
12931 + return size;
12932 +
12933 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12934 + dst += PAX_USER_SHADOW_BASE;
12935 +#endif
12936 +
12937 + return copy_user_generic((__force_kernel void *)dst, src, size);
12938 }
12939
12940 -extern long __copy_user_nocache(void *dst, const void __user *src,
12941 - unsigned size, int zerorest);
12942 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12943 + unsigned long size, int zerorest) __size_overflow(3);
12944
12945 -static inline int
12946 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12947 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12948 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12949 {
12950 might_sleep();
12951 +
12952 + if (size > INT_MAX)
12953 + return size;
12954 +
12955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12956 + if (!__access_ok(VERIFY_READ, src, size))
12957 + return size;
12958 +#endif
12959 +
12960 return __copy_user_nocache(dst, src, size, 1);
12961 }
12962
12963 -static inline int
12964 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12965 - unsigned size)
12966 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12967 + unsigned long size) __size_overflow(3);
12968 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12969 + unsigned long size)
12970 {
12971 + if (size > INT_MAX)
12972 + return size;
12973 +
12974 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12975 + if (!__access_ok(VERIFY_READ, src, size))
12976 + return size;
12977 +#endif
12978 +
12979 return __copy_user_nocache(dst, src, size, 0);
12980 }
12981
12982 -unsigned long
12983 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12984 +extern unsigned long
12985 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
12986
12987 #endif /* _ASM_X86_UACCESS_64_H */
12988 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12989 index bb05228..d763d5b 100644
12990 --- a/arch/x86/include/asm/vdso.h
12991 +++ b/arch/x86/include/asm/vdso.h
12992 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
12993 #define VDSO32_SYMBOL(base, name) \
12994 ({ \
12995 extern const char VDSO32_##name[]; \
12996 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12997 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12998 })
12999 #endif
13000
13001 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13002 index 517d476..a1cb4d9 100644
13003 --- a/arch/x86/include/asm/x86_init.h
13004 +++ b/arch/x86/include/asm/x86_init.h
13005 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13006 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13007 void (*find_smp_config)(void);
13008 void (*get_smp_config)(unsigned int early);
13009 -};
13010 +} __no_const;
13011
13012 /**
13013 * struct x86_init_resources - platform specific resource related ops
13014 @@ -43,7 +43,7 @@ struct x86_init_resources {
13015 void (*probe_roms)(void);
13016 void (*reserve_resources)(void);
13017 char *(*memory_setup)(void);
13018 -};
13019 +} __no_const;
13020
13021 /**
13022 * struct x86_init_irqs - platform specific interrupt setup
13023 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13024 void (*pre_vector_init)(void);
13025 void (*intr_init)(void);
13026 void (*trap_init)(void);
13027 -};
13028 +} __no_const;
13029
13030 /**
13031 * struct x86_init_oem - oem platform specific customizing functions
13032 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13033 struct x86_init_oem {
13034 void (*arch_setup)(void);
13035 void (*banner)(void);
13036 -};
13037 +} __no_const;
13038
13039 /**
13040 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13041 @@ -77,7 +77,7 @@ struct x86_init_oem {
13042 */
13043 struct x86_init_mapping {
13044 void (*pagetable_reserve)(u64 start, u64 end);
13045 -};
13046 +} __no_const;
13047
13048 /**
13049 * struct x86_init_paging - platform specific paging functions
13050 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13051 struct x86_init_paging {
13052 void (*pagetable_setup_start)(pgd_t *base);
13053 void (*pagetable_setup_done)(pgd_t *base);
13054 -};
13055 +} __no_const;
13056
13057 /**
13058 * struct x86_init_timers - platform specific timer setup
13059 @@ -102,7 +102,7 @@ struct x86_init_timers {
13060 void (*tsc_pre_init)(void);
13061 void (*timer_init)(void);
13062 void (*wallclock_init)(void);
13063 -};
13064 +} __no_const;
13065
13066 /**
13067 * struct x86_init_iommu - platform specific iommu setup
13068 @@ -110,7 +110,7 @@ struct x86_init_timers {
13069 */
13070 struct x86_init_iommu {
13071 int (*iommu_init)(void);
13072 -};
13073 +} __no_const;
13074
13075 /**
13076 * struct x86_init_pci - platform specific pci init functions
13077 @@ -124,7 +124,7 @@ struct x86_init_pci {
13078 int (*init)(void);
13079 void (*init_irq)(void);
13080 void (*fixup_irqs)(void);
13081 -};
13082 +} __no_const;
13083
13084 /**
13085 * struct x86_init_ops - functions for platform specific setup
13086 @@ -140,7 +140,7 @@ struct x86_init_ops {
13087 struct x86_init_timers timers;
13088 struct x86_init_iommu iommu;
13089 struct x86_init_pci pci;
13090 -};
13091 +} __no_const;
13092
13093 /**
13094 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13095 @@ -149,7 +149,7 @@ struct x86_init_ops {
13096 struct x86_cpuinit_ops {
13097 void (*setup_percpu_clockev)(void);
13098 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13099 -};
13100 +} __no_const;
13101
13102 /**
13103 * struct x86_platform_ops - platform specific runtime functions
13104 @@ -171,7 +171,7 @@ struct x86_platform_ops {
13105 void (*nmi_init)(void);
13106 unsigned char (*get_nmi_reason)(void);
13107 int (*i8042_detect)(void);
13108 -};
13109 +} __no_const;
13110
13111 struct pci_dev;
13112
13113 @@ -180,7 +180,7 @@ struct x86_msi_ops {
13114 void (*teardown_msi_irq)(unsigned int irq);
13115 void (*teardown_msi_irqs)(struct pci_dev *dev);
13116 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13117 -};
13118 +} __no_const;
13119
13120 extern struct x86_init_ops x86_init;
13121 extern struct x86_cpuinit_ops x86_cpuinit;
13122 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13123 index c6ce245..ffbdab7 100644
13124 --- a/arch/x86/include/asm/xsave.h
13125 +++ b/arch/x86/include/asm/xsave.h
13126 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13127 {
13128 int err;
13129
13130 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13131 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13132 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13133 +#endif
13134 +
13135 /*
13136 * Clear the xsave header first, so that reserved fields are
13137 * initialized to zero.
13138 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13139 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13140 {
13141 int err;
13142 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13143 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13144 u32 lmask = mask;
13145 u32 hmask = mask >> 32;
13146
13147 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13148 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13149 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13150 +#endif
13151 +
13152 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13153 "2:\n"
13154 ".section .fixup,\"ax\"\n"
13155 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13156 index 6a564ac..9b1340c 100644
13157 --- a/arch/x86/kernel/acpi/realmode/Makefile
13158 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13159 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13160 $(call cc-option, -fno-stack-protector) \
13161 $(call cc-option, -mpreferred-stack-boundary=2)
13162 KBUILD_CFLAGS += $(call cc-option, -m32)
13163 +ifdef CONSTIFY_PLUGIN
13164 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13165 +endif
13166 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13167 GCOV_PROFILE := n
13168
13169 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13170 index b4fd836..4358fe3 100644
13171 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13172 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13173 @@ -108,6 +108,9 @@ wakeup_code:
13174 /* Do any other stuff... */
13175
13176 #ifndef CONFIG_64BIT
13177 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13178 + call verify_cpu
13179 +
13180 /* This could also be done in C code... */
13181 movl pmode_cr3, %eax
13182 movl %eax, %cr3
13183 @@ -131,6 +134,7 @@ wakeup_code:
13184 movl pmode_cr0, %eax
13185 movl %eax, %cr0
13186 jmp pmode_return
13187 +# include "../../verify_cpu.S"
13188 #else
13189 pushw $0
13190 pushw trampoline_segment
13191 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13192 index 103b6ab..2004d0a 100644
13193 --- a/arch/x86/kernel/acpi/sleep.c
13194 +++ b/arch/x86/kernel/acpi/sleep.c
13195 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13196 header->trampoline_segment = trampoline_address() >> 4;
13197 #ifdef CONFIG_SMP
13198 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13199 +
13200 + pax_open_kernel();
13201 early_gdt_descr.address =
13202 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13203 + pax_close_kernel();
13204 +
13205 initial_gs = per_cpu_offset(smp_processor_id());
13206 #endif
13207 initial_code = (unsigned long)wakeup_long64;
13208 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13209 index 13ab720..95d5442 100644
13210 --- a/arch/x86/kernel/acpi/wakeup_32.S
13211 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13212 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13213 # and restore the stack ... but you need gdt for this to work
13214 movl saved_context_esp, %esp
13215
13216 - movl %cs:saved_magic, %eax
13217 - cmpl $0x12345678, %eax
13218 + cmpl $0x12345678, saved_magic
13219 jne bogus_magic
13220
13221 # jump to place where we left off
13222 - movl saved_eip, %eax
13223 - jmp *%eax
13224 + jmp *(saved_eip)
13225
13226 bogus_magic:
13227 jmp bogus_magic
13228 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13229 index 1f84794..e23f862 100644
13230 --- a/arch/x86/kernel/alternative.c
13231 +++ b/arch/x86/kernel/alternative.c
13232 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13233 */
13234 for (a = start; a < end; a++) {
13235 instr = (u8 *)&a->instr_offset + a->instr_offset;
13236 +
13237 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13238 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13239 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13240 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13241 +#endif
13242 +
13243 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13244 BUG_ON(a->replacementlen > a->instrlen);
13245 BUG_ON(a->instrlen > sizeof(insnbuf));
13246 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13247 for (poff = start; poff < end; poff++) {
13248 u8 *ptr = (u8 *)poff + *poff;
13249
13250 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13251 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13252 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13253 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13254 +#endif
13255 +
13256 if (!*poff || ptr < text || ptr >= text_end)
13257 continue;
13258 /* turn DS segment override prefix into lock prefix */
13259 - if (*ptr == 0x3e)
13260 + if (*ktla_ktva(ptr) == 0x3e)
13261 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13262 };
13263 mutex_unlock(&text_mutex);
13264 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13265 for (poff = start; poff < end; poff++) {
13266 u8 *ptr = (u8 *)poff + *poff;
13267
13268 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13269 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13270 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13271 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13272 +#endif
13273 +
13274 if (!*poff || ptr < text || ptr >= text_end)
13275 continue;
13276 /* turn lock prefix into DS segment override prefix */
13277 - if (*ptr == 0xf0)
13278 + if (*ktla_ktva(ptr) == 0xf0)
13279 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13280 };
13281 mutex_unlock(&text_mutex);
13282 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13283
13284 BUG_ON(p->len > MAX_PATCH_LEN);
13285 /* prep the buffer with the original instructions */
13286 - memcpy(insnbuf, p->instr, p->len);
13287 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13288 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13289 (unsigned long)p->instr, p->len);
13290
13291 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13292 if (smp_alt_once)
13293 free_init_pages("SMP alternatives",
13294 (unsigned long)__smp_locks,
13295 - (unsigned long)__smp_locks_end);
13296 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13297
13298 restart_nmi();
13299 }
13300 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13301 * instructions. And on the local CPU you need to be protected again NMI or MCE
13302 * handlers seeing an inconsistent instruction while you patch.
13303 */
13304 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13305 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13306 size_t len)
13307 {
13308 unsigned long flags;
13309 local_irq_save(flags);
13310 - memcpy(addr, opcode, len);
13311 +
13312 + pax_open_kernel();
13313 + memcpy(ktla_ktva(addr), opcode, len);
13314 sync_core();
13315 + pax_close_kernel();
13316 +
13317 local_irq_restore(flags);
13318 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13319 that causes hangs on some VIA CPUs. */
13320 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13321 */
13322 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13323 {
13324 - unsigned long flags;
13325 - char *vaddr;
13326 + unsigned char *vaddr = ktla_ktva(addr);
13327 struct page *pages[2];
13328 - int i;
13329 + size_t i;
13330
13331 if (!core_kernel_text((unsigned long)addr)) {
13332 - pages[0] = vmalloc_to_page(addr);
13333 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13334 + pages[0] = vmalloc_to_page(vaddr);
13335 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13336 } else {
13337 - pages[0] = virt_to_page(addr);
13338 + pages[0] = virt_to_page(vaddr);
13339 WARN_ON(!PageReserved(pages[0]));
13340 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13341 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13342 }
13343 BUG_ON(!pages[0]);
13344 - local_irq_save(flags);
13345 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13346 - if (pages[1])
13347 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13348 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13349 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13350 - clear_fixmap(FIX_TEXT_POKE0);
13351 - if (pages[1])
13352 - clear_fixmap(FIX_TEXT_POKE1);
13353 - local_flush_tlb();
13354 - sync_core();
13355 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13356 - that causes hangs on some VIA CPUs. */
13357 + text_poke_early(addr, opcode, len);
13358 for (i = 0; i < len; i++)
13359 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13360 - local_irq_restore(flags);
13361 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13362 return addr;
13363 }
13364
13365 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13366 index 2eec05b..fef012b 100644
13367 --- a/arch/x86/kernel/apic/apic.c
13368 +++ b/arch/x86/kernel/apic/apic.c
13369 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13370 /*
13371 * Debug level, exported for io_apic.c
13372 */
13373 -unsigned int apic_verbosity;
13374 +int apic_verbosity;
13375
13376 int pic_mode;
13377
13378 @@ -1908,7 +1908,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13379 apic_write(APIC_ESR, 0);
13380 v1 = apic_read(APIC_ESR);
13381 ack_APIC_irq();
13382 - atomic_inc(&irq_err_count);
13383 + atomic_inc_unchecked(&irq_err_count);
13384
13385 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13386 smp_processor_id(), v0 , v1);
13387 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13388 index fb07275..e06bb59 100644
13389 --- a/arch/x86/kernel/apic/io_apic.c
13390 +++ b/arch/x86/kernel/apic/io_apic.c
13391 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13392 }
13393 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13394
13395 -void lock_vector_lock(void)
13396 +void lock_vector_lock(void) __acquires(vector_lock)
13397 {
13398 /* Used to the online set of cpus does not change
13399 * during assign_irq_vector.
13400 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13401 raw_spin_lock(&vector_lock);
13402 }
13403
13404 -void unlock_vector_lock(void)
13405 +void unlock_vector_lock(void) __releases(vector_lock)
13406 {
13407 raw_spin_unlock(&vector_lock);
13408 }
13409 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13410 ack_APIC_irq();
13411 }
13412
13413 -atomic_t irq_mis_count;
13414 +atomic_unchecked_t irq_mis_count;
13415
13416 static void ack_apic_level(struct irq_data *data)
13417 {
13418 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13419 * at the cpu.
13420 */
13421 if (!(v & (1 << (i & 0x1f)))) {
13422 - atomic_inc(&irq_mis_count);
13423 + atomic_inc_unchecked(&irq_mis_count);
13424
13425 eoi_ioapic_irq(irq, cfg);
13426 }
13427 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13428 index f76623c..aab694f 100644
13429 --- a/arch/x86/kernel/apm_32.c
13430 +++ b/arch/x86/kernel/apm_32.c
13431 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13432 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13433 * even though they are called in protected mode.
13434 */
13435 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13436 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13437 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13438
13439 static const char driver_version[] = "1.16ac"; /* no spaces */
13440 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13441 BUG_ON(cpu != 0);
13442 gdt = get_cpu_gdt_table(cpu);
13443 save_desc_40 = gdt[0x40 / 8];
13444 +
13445 + pax_open_kernel();
13446 gdt[0x40 / 8] = bad_bios_desc;
13447 + pax_close_kernel();
13448
13449 apm_irq_save(flags);
13450 APM_DO_SAVE_SEGS;
13451 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13452 &call->esi);
13453 APM_DO_RESTORE_SEGS;
13454 apm_irq_restore(flags);
13455 +
13456 + pax_open_kernel();
13457 gdt[0x40 / 8] = save_desc_40;
13458 + pax_close_kernel();
13459 +
13460 put_cpu();
13461
13462 return call->eax & 0xff;
13463 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13464 BUG_ON(cpu != 0);
13465 gdt = get_cpu_gdt_table(cpu);
13466 save_desc_40 = gdt[0x40 / 8];
13467 +
13468 + pax_open_kernel();
13469 gdt[0x40 / 8] = bad_bios_desc;
13470 + pax_close_kernel();
13471
13472 apm_irq_save(flags);
13473 APM_DO_SAVE_SEGS;
13474 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13475 &call->eax);
13476 APM_DO_RESTORE_SEGS;
13477 apm_irq_restore(flags);
13478 +
13479 + pax_open_kernel();
13480 gdt[0x40 / 8] = save_desc_40;
13481 + pax_close_kernel();
13482 +
13483 put_cpu();
13484 return error;
13485 }
13486 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13487 * code to that CPU.
13488 */
13489 gdt = get_cpu_gdt_table(0);
13490 +
13491 + pax_open_kernel();
13492 set_desc_base(&gdt[APM_CS >> 3],
13493 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13494 set_desc_base(&gdt[APM_CS_16 >> 3],
13495 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13496 set_desc_base(&gdt[APM_DS >> 3],
13497 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13498 + pax_close_kernel();
13499
13500 proc_create("apm", 0, NULL, &apm_file_ops);
13501
13502 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13503 index 68de2dc..1f3c720 100644
13504 --- a/arch/x86/kernel/asm-offsets.c
13505 +++ b/arch/x86/kernel/asm-offsets.c
13506 @@ -33,6 +33,8 @@ void common(void) {
13507 OFFSET(TI_status, thread_info, status);
13508 OFFSET(TI_addr_limit, thread_info, addr_limit);
13509 OFFSET(TI_preempt_count, thread_info, preempt_count);
13510 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13511 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13512
13513 BLANK();
13514 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13515 @@ -53,8 +55,26 @@ void common(void) {
13516 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13517 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13518 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13519 +
13520 +#ifdef CONFIG_PAX_KERNEXEC
13521 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13522 #endif
13523
13524 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13525 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13526 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13527 +#ifdef CONFIG_X86_64
13528 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13529 +#endif
13530 +#endif
13531 +
13532 +#endif
13533 +
13534 + BLANK();
13535 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13536 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13537 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13538 +
13539 #ifdef CONFIG_XEN
13540 BLANK();
13541 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13542 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13543 index 834e897..dacddc8 100644
13544 --- a/arch/x86/kernel/asm-offsets_64.c
13545 +++ b/arch/x86/kernel/asm-offsets_64.c
13546 @@ -70,6 +70,7 @@ int main(void)
13547 BLANK();
13548 #undef ENTRY
13549
13550 + DEFINE(TSS_size, sizeof(struct tss_struct));
13551 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13552 BLANK();
13553
13554 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13555 index 25f24dc..4094a7f 100644
13556 --- a/arch/x86/kernel/cpu/Makefile
13557 +++ b/arch/x86/kernel/cpu/Makefile
13558 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13559 CFLAGS_REMOVE_perf_event.o = -pg
13560 endif
13561
13562 -# Make sure load_percpu_segment has no stackprotector
13563 -nostackp := $(call cc-option, -fno-stack-protector)
13564 -CFLAGS_common.o := $(nostackp)
13565 -
13566 obj-y := intel_cacheinfo.o scattered.o topology.o
13567 obj-y += proc.o capflags.o powerflags.o common.o
13568 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13569 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13570 index f4773f4..b3fb13c 100644
13571 --- a/arch/x86/kernel/cpu/amd.c
13572 +++ b/arch/x86/kernel/cpu/amd.c
13573 @@ -669,7 +669,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13574 unsigned int size)
13575 {
13576 /* AMD errata T13 (order #21922) */
13577 - if ((c->x86 == 6)) {
13578 + if (c->x86 == 6) {
13579 /* Duron Rev A0 */
13580 if (c->x86_model == 3 && c->x86_mask == 0)
13581 size = 64;
13582 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13583 index c0f7d68..aa418f9 100644
13584 --- a/arch/x86/kernel/cpu/common.c
13585 +++ b/arch/x86/kernel/cpu/common.c
13586 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13587
13588 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13589
13590 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13591 -#ifdef CONFIG_X86_64
13592 - /*
13593 - * We need valid kernel segments for data and code in long mode too
13594 - * IRET will check the segment types kkeil 2000/10/28
13595 - * Also sysret mandates a special GDT layout
13596 - *
13597 - * TLS descriptors are currently at a different place compared to i386.
13598 - * Hopefully nobody expects them at a fixed place (Wine?)
13599 - */
13600 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13601 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13602 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13603 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13604 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13605 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13606 -#else
13607 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13608 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13609 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13610 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13611 - /*
13612 - * Segments used for calling PnP BIOS have byte granularity.
13613 - * They code segments and data segments have fixed 64k limits,
13614 - * the transfer segment sizes are set at run time.
13615 - */
13616 - /* 32-bit code */
13617 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13618 - /* 16-bit code */
13619 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13620 - /* 16-bit data */
13621 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13622 - /* 16-bit data */
13623 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13624 - /* 16-bit data */
13625 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13626 - /*
13627 - * The APM segments have byte granularity and their bases
13628 - * are set at run time. All have 64k limits.
13629 - */
13630 - /* 32-bit code */
13631 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13632 - /* 16-bit code */
13633 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13634 - /* data */
13635 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13636 -
13637 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13638 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13639 - GDT_STACK_CANARY_INIT
13640 -#endif
13641 -} };
13642 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13643 -
13644 static int __init x86_xsave_setup(char *s)
13645 {
13646 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13647 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13648 {
13649 struct desc_ptr gdt_descr;
13650
13651 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13652 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13653 gdt_descr.size = GDT_SIZE - 1;
13654 load_gdt(&gdt_descr);
13655 /* Reload the per-cpu base */
13656 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13657 /* Filter out anything that depends on CPUID levels we don't have */
13658 filter_cpuid_features(c, true);
13659
13660 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13661 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13662 +#endif
13663 +
13664 /* If the model name is still unset, do table lookup. */
13665 if (!c->x86_model_id[0]) {
13666 const char *p;
13667 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
13668 }
13669 __setup("clearcpuid=", setup_disablecpuid);
13670
13671 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13672 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13673 +
13674 #ifdef CONFIG_X86_64
13675 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13676 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
13677 - (unsigned long) nmi_idt_table };
13678 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
13679
13680 DEFINE_PER_CPU_FIRST(union irq_stack_union,
13681 irq_stack_union) __aligned(PAGE_SIZE);
13682 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13683 EXPORT_PER_CPU_SYMBOL(current_task);
13684
13685 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13686 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13687 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13688 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13689
13690 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13691 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13692 {
13693 memset(regs, 0, sizeof(struct pt_regs));
13694 regs->fs = __KERNEL_PERCPU;
13695 - regs->gs = __KERNEL_STACK_CANARY;
13696 + savesegment(gs, regs->gs);
13697
13698 return regs;
13699 }
13700 @@ -1190,7 +1142,7 @@ void __cpuinit cpu_init(void)
13701 int i;
13702
13703 cpu = stack_smp_processor_id();
13704 - t = &per_cpu(init_tss, cpu);
13705 + t = init_tss + cpu;
13706 oist = &per_cpu(orig_ist, cpu);
13707
13708 #ifdef CONFIG_NUMA
13709 @@ -1216,7 +1168,7 @@ void __cpuinit cpu_init(void)
13710 switch_to_new_gdt(cpu);
13711 loadsegment(fs, 0);
13712
13713 - load_idt((const struct desc_ptr *)&idt_descr);
13714 + load_idt(&idt_descr);
13715
13716 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13717 syscall_init();
13718 @@ -1225,7 +1177,6 @@ void __cpuinit cpu_init(void)
13719 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13720 barrier();
13721
13722 - x86_configure_nx();
13723 if (cpu != 0)
13724 enable_x2apic();
13725
13726 @@ -1281,7 +1232,7 @@ void __cpuinit cpu_init(void)
13727 {
13728 int cpu = smp_processor_id();
13729 struct task_struct *curr = current;
13730 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13731 + struct tss_struct *t = init_tss + cpu;
13732 struct thread_struct *thread = &curr->thread;
13733
13734 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13735 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13736 index 3e6ff6c..54b4992 100644
13737 --- a/arch/x86/kernel/cpu/intel.c
13738 +++ b/arch/x86/kernel/cpu/intel.c
13739 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13740 * Update the IDT descriptor and reload the IDT so that
13741 * it uses the read-only mapped virtual address.
13742 */
13743 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13744 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13745 load_idt(&idt_descr);
13746 }
13747 #endif
13748 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13749 index fc4beb3..f20a5a7 100644
13750 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13751 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13752 @@ -199,6 +199,8 @@ static void raise_mce(struct mce *m)
13753
13754 /* Error injection interface */
13755 static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13756 + size_t usize, loff_t *off) __size_overflow(3);
13757 +static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13758 size_t usize, loff_t *off)
13759 {
13760 struct mce m;
13761 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13762 index 5a11ae2..a1a1c8a 100644
13763 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13764 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13765 @@ -42,6 +42,7 @@
13766 #include <asm/processor.h>
13767 #include <asm/mce.h>
13768 #include <asm/msr.h>
13769 +#include <asm/local.h>
13770
13771 #include "mce-internal.h"
13772
13773 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
13774 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13775 m->cs, m->ip);
13776
13777 - if (m->cs == __KERNEL_CS)
13778 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13779 print_symbol("{%s}", m->ip);
13780 pr_cont("\n");
13781 }
13782 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
13783
13784 #define PANIC_TIMEOUT 5 /* 5 seconds */
13785
13786 -static atomic_t mce_paniced;
13787 +static atomic_unchecked_t mce_paniced;
13788
13789 static int fake_panic;
13790 -static atomic_t mce_fake_paniced;
13791 +static atomic_unchecked_t mce_fake_paniced;
13792
13793 /* Panic in progress. Enable interrupts and wait for final IPI */
13794 static void wait_for_panic(void)
13795 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13796 /*
13797 * Make sure only one CPU runs in machine check panic
13798 */
13799 - if (atomic_inc_return(&mce_paniced) > 1)
13800 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13801 wait_for_panic();
13802 barrier();
13803
13804 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13805 console_verbose();
13806 } else {
13807 /* Don't log too much for fake panic */
13808 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13809 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13810 return;
13811 }
13812 /* First print corrected ones that are still unlogged */
13813 @@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
13814 * might have been modified by someone else.
13815 */
13816 rmb();
13817 - if (atomic_read(&mce_paniced))
13818 + if (atomic_read_unchecked(&mce_paniced))
13819 wait_for_panic();
13820 if (!monarch_timeout)
13821 goto out;
13822 @@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13823 }
13824
13825 /* Call the installed machine check handler for this CPU setup. */
13826 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13827 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13828 unexpected_machine_check;
13829
13830 /*
13831 @@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13832 return;
13833 }
13834
13835 + pax_open_kernel();
13836 machine_check_vector = do_machine_check;
13837 + pax_close_kernel();
13838
13839 __mcheck_cpu_init_generic();
13840 __mcheck_cpu_init_vendor(c);
13841 @@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13842 */
13843
13844 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13845 -static int mce_chrdev_open_count; /* #times opened */
13846 +static local_t mce_chrdev_open_count; /* #times opened */
13847 static int mce_chrdev_open_exclu; /* already open exclusive? */
13848
13849 static int mce_chrdev_open(struct inode *inode, struct file *file)
13850 @@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13851 spin_lock(&mce_chrdev_state_lock);
13852
13853 if (mce_chrdev_open_exclu ||
13854 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13855 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13856 spin_unlock(&mce_chrdev_state_lock);
13857
13858 return -EBUSY;
13859 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13860
13861 if (file->f_flags & O_EXCL)
13862 mce_chrdev_open_exclu = 1;
13863 - mce_chrdev_open_count++;
13864 + local_inc(&mce_chrdev_open_count);
13865
13866 spin_unlock(&mce_chrdev_state_lock);
13867
13868 @@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13869 {
13870 spin_lock(&mce_chrdev_state_lock);
13871
13872 - mce_chrdev_open_count--;
13873 + local_dec(&mce_chrdev_open_count);
13874 mce_chrdev_open_exclu = 0;
13875
13876 spin_unlock(&mce_chrdev_state_lock);
13877 @@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
13878 static void mce_reset(void)
13879 {
13880 cpu_missing = 0;
13881 - atomic_set(&mce_fake_paniced, 0);
13882 + atomic_set_unchecked(&mce_fake_paniced, 0);
13883 atomic_set(&mce_executing, 0);
13884 atomic_set(&mce_callin, 0);
13885 atomic_set(&global_nwo, 0);
13886 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13887 index 5c0e653..0882b0a 100644
13888 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13889 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13890 @@ -12,6 +12,7 @@
13891 #include <asm/system.h>
13892 #include <asm/mce.h>
13893 #include <asm/msr.h>
13894 +#include <asm/pgtable.h>
13895
13896 /* By default disabled */
13897 int mce_p5_enabled __read_mostly;
13898 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13899 if (!cpu_has(c, X86_FEATURE_MCE))
13900 return;
13901
13902 + pax_open_kernel();
13903 machine_check_vector = pentium_machine_check;
13904 + pax_close_kernel();
13905 /* Make sure the vector pointer is visible before we enable MCEs: */
13906 wmb();
13907
13908 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13909 index 54060f5..c1a7577 100644
13910 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13911 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13912 @@ -11,6 +11,7 @@
13913 #include <asm/system.h>
13914 #include <asm/mce.h>
13915 #include <asm/msr.h>
13916 +#include <asm/pgtable.h>
13917
13918 /* Machine check handler for WinChip C6: */
13919 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13920 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13921 {
13922 u32 lo, hi;
13923
13924 + pax_open_kernel();
13925 machine_check_vector = winchip_machine_check;
13926 + pax_close_kernel();
13927 /* Make sure the vector pointer is visible before we enable MCEs: */
13928 wmb();
13929
13930 diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
13931 index 7928963..1b16001 100644
13932 --- a/arch/x86/kernel/cpu/mtrr/if.c
13933 +++ b/arch/x86/kernel/cpu/mtrr/if.c
13934 @@ -91,6 +91,8 @@ mtrr_file_del(unsigned long base, unsigned long size,
13935 * "base=%Lx size=%Lx type=%s" or "disable=%d"
13936 */
13937 static ssize_t
13938 +mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) __size_overflow(3);
13939 +static ssize_t
13940 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
13941 {
13942 int i, err;
13943 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13944 index 6b96110..0da73eb 100644
13945 --- a/arch/x86/kernel/cpu/mtrr/main.c
13946 +++ b/arch/x86/kernel/cpu/mtrr/main.c
13947 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13948 u64 size_or_mask, size_and_mask;
13949 static bool mtrr_aps_delayed_init;
13950
13951 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13952 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13953
13954 const struct mtrr_ops *mtrr_if;
13955
13956 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13957 index df5e41f..816c719 100644
13958 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13959 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13960 @@ -25,7 +25,7 @@ struct mtrr_ops {
13961 int (*validate_add_page)(unsigned long base, unsigned long size,
13962 unsigned int type);
13963 int (*have_wrcomb)(void);
13964 -};
13965 +} __do_const;
13966
13967 extern int generic_get_free_region(unsigned long base, unsigned long size,
13968 int replace_reg);
13969 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13970 index 5adce10..99284ec 100644
13971 --- a/arch/x86/kernel/cpu/perf_event.c
13972 +++ b/arch/x86/kernel/cpu/perf_event.c
13973 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13974 break;
13975
13976 perf_callchain_store(entry, frame.return_address);
13977 - fp = frame.next_frame;
13978 + fp = (const void __force_user *)frame.next_frame;
13979 }
13980 }
13981
13982 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
13983 index 13ad899..f642b9a 100644
13984 --- a/arch/x86/kernel/crash.c
13985 +++ b/arch/x86/kernel/crash.c
13986 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
13987 {
13988 #ifdef CONFIG_X86_32
13989 struct pt_regs fixed_regs;
13990 -#endif
13991
13992 -#ifdef CONFIG_X86_32
13993 - if (!user_mode_vm(regs)) {
13994 + if (!user_mode(regs)) {
13995 crash_fixup_ss_esp(&fixed_regs, regs);
13996 regs = &fixed_regs;
13997 }
13998 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
13999 index 37250fe..bf2ec74 100644
14000 --- a/arch/x86/kernel/doublefault_32.c
14001 +++ b/arch/x86/kernel/doublefault_32.c
14002 @@ -11,7 +11,7 @@
14003
14004 #define DOUBLEFAULT_STACKSIZE (1024)
14005 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14006 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14007 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14008
14009 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14010
14011 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14012 unsigned long gdt, tss;
14013
14014 store_gdt(&gdt_desc);
14015 - gdt = gdt_desc.address;
14016 + gdt = (unsigned long)gdt_desc.address;
14017
14018 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14019
14020 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14021 /* 0x2 bit is always set */
14022 .flags = X86_EFLAGS_SF | 0x2,
14023 .sp = STACK_START,
14024 - .es = __USER_DS,
14025 + .es = __KERNEL_DS,
14026 .cs = __KERNEL_CS,
14027 .ss = __KERNEL_DS,
14028 - .ds = __USER_DS,
14029 + .ds = __KERNEL_DS,
14030 .fs = __KERNEL_PERCPU,
14031
14032 .__cr3 = __pa_nodebug(swapper_pg_dir),
14033 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14034 index 4025fe4..d8451c6 100644
14035 --- a/arch/x86/kernel/dumpstack.c
14036 +++ b/arch/x86/kernel/dumpstack.c
14037 @@ -2,6 +2,9 @@
14038 * Copyright (C) 1991, 1992 Linus Torvalds
14039 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14040 */
14041 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14042 +#define __INCLUDED_BY_HIDESYM 1
14043 +#endif
14044 #include <linux/kallsyms.h>
14045 #include <linux/kprobes.h>
14046 #include <linux/uaccess.h>
14047 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14048 static void
14049 print_ftrace_graph_addr(unsigned long addr, void *data,
14050 const struct stacktrace_ops *ops,
14051 - struct thread_info *tinfo, int *graph)
14052 + struct task_struct *task, int *graph)
14053 {
14054 - struct task_struct *task = tinfo->task;
14055 unsigned long ret_addr;
14056 int index = task->curr_ret_stack;
14057
14058 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14059 static inline void
14060 print_ftrace_graph_addr(unsigned long addr, void *data,
14061 const struct stacktrace_ops *ops,
14062 - struct thread_info *tinfo, int *graph)
14063 + struct task_struct *task, int *graph)
14064 { }
14065 #endif
14066
14067 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14068 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14069 */
14070
14071 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14072 - void *p, unsigned int size, void *end)
14073 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14074 {
14075 - void *t = tinfo;
14076 if (end) {
14077 if (p < end && p >= (end-THREAD_SIZE))
14078 return 1;
14079 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14080 }
14081
14082 unsigned long
14083 -print_context_stack(struct thread_info *tinfo,
14084 +print_context_stack(struct task_struct *task, void *stack_start,
14085 unsigned long *stack, unsigned long bp,
14086 const struct stacktrace_ops *ops, void *data,
14087 unsigned long *end, int *graph)
14088 {
14089 struct stack_frame *frame = (struct stack_frame *)bp;
14090
14091 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14092 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14093 unsigned long addr;
14094
14095 addr = *stack;
14096 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14097 } else {
14098 ops->address(data, addr, 0);
14099 }
14100 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14101 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14102 }
14103 stack++;
14104 }
14105 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14106 EXPORT_SYMBOL_GPL(print_context_stack);
14107
14108 unsigned long
14109 -print_context_stack_bp(struct thread_info *tinfo,
14110 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14111 unsigned long *stack, unsigned long bp,
14112 const struct stacktrace_ops *ops, void *data,
14113 unsigned long *end, int *graph)
14114 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14115 struct stack_frame *frame = (struct stack_frame *)bp;
14116 unsigned long *ret_addr = &frame->return_address;
14117
14118 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14119 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14120 unsigned long addr = *ret_addr;
14121
14122 if (!__kernel_text_address(addr))
14123 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14124 ops->address(data, addr, 1);
14125 frame = frame->next_frame;
14126 ret_addr = &frame->return_address;
14127 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14128 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14129 }
14130
14131 return (unsigned long)frame;
14132 @@ -186,7 +186,7 @@ void dump_stack(void)
14133
14134 bp = stack_frame(current, NULL);
14135 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14136 - current->pid, current->comm, print_tainted(),
14137 + task_pid_nr(current), current->comm, print_tainted(),
14138 init_utsname()->release,
14139 (int)strcspn(init_utsname()->version, " "),
14140 init_utsname()->version);
14141 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14142 }
14143 EXPORT_SYMBOL_GPL(oops_begin);
14144
14145 +extern void gr_handle_kernel_exploit(void);
14146 +
14147 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14148 {
14149 if (regs && kexec_should_crash(current))
14150 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14151 panic("Fatal exception in interrupt");
14152 if (panic_on_oops)
14153 panic("Fatal exception");
14154 - do_exit(signr);
14155 +
14156 + gr_handle_kernel_exploit();
14157 +
14158 + do_group_exit(signr);
14159 }
14160
14161 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14162 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14163
14164 show_registers(regs);
14165 #ifdef CONFIG_X86_32
14166 - if (user_mode_vm(regs)) {
14167 + if (user_mode(regs)) {
14168 sp = regs->sp;
14169 ss = regs->ss & 0xffff;
14170 } else {
14171 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14172 unsigned long flags = oops_begin();
14173 int sig = SIGSEGV;
14174
14175 - if (!user_mode_vm(regs))
14176 + if (!user_mode(regs))
14177 report_bug(regs->ip, regs);
14178
14179 if (__die(str, regs, err))
14180 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14181 index c99f9ed..2a15d80 100644
14182 --- a/arch/x86/kernel/dumpstack_32.c
14183 +++ b/arch/x86/kernel/dumpstack_32.c
14184 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14185 bp = stack_frame(task, regs);
14186
14187 for (;;) {
14188 - struct thread_info *context;
14189 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14190
14191 - context = (struct thread_info *)
14192 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14193 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14194 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14195
14196 - stack = (unsigned long *)context->previous_esp;
14197 - if (!stack)
14198 + if (stack_start == task_stack_page(task))
14199 break;
14200 + stack = *(unsigned long **)stack_start;
14201 if (ops->stack(data, "IRQ") < 0)
14202 break;
14203 touch_nmi_watchdog();
14204 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14205 * When in-kernel, we also print out the stack and code at the
14206 * time of the fault..
14207 */
14208 - if (!user_mode_vm(regs)) {
14209 + if (!user_mode(regs)) {
14210 unsigned int code_prologue = code_bytes * 43 / 64;
14211 unsigned int code_len = code_bytes;
14212 unsigned char c;
14213 u8 *ip;
14214 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14215
14216 printk(KERN_EMERG "Stack:\n");
14217 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14218
14219 printk(KERN_EMERG "Code: ");
14220
14221 - ip = (u8 *)regs->ip - code_prologue;
14222 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14223 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14224 /* try starting at IP */
14225 - ip = (u8 *)regs->ip;
14226 + ip = (u8 *)regs->ip + cs_base;
14227 code_len = code_len - code_prologue + 1;
14228 }
14229 for (i = 0; i < code_len; i++, ip++) {
14230 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14231 printk(KERN_CONT " Bad EIP value.");
14232 break;
14233 }
14234 - if (ip == (u8 *)regs->ip)
14235 + if (ip == (u8 *)regs->ip + cs_base)
14236 printk(KERN_CONT "<%02x> ", c);
14237 else
14238 printk(KERN_CONT "%02x ", c);
14239 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14240 {
14241 unsigned short ud2;
14242
14243 + ip = ktla_ktva(ip);
14244 if (ip < PAGE_OFFSET)
14245 return 0;
14246 if (probe_kernel_address((unsigned short *)ip, ud2))
14247 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14248
14249 return ud2 == 0x0b0f;
14250 }
14251 +
14252 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14253 +void pax_check_alloca(unsigned long size)
14254 +{
14255 + unsigned long sp = (unsigned long)&sp, stack_left;
14256 +
14257 + /* all kernel stacks are of the same size */
14258 + stack_left = sp & (THREAD_SIZE - 1);
14259 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14260 +}
14261 +EXPORT_SYMBOL(pax_check_alloca);
14262 +#endif
14263 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14264 index 17107bd..b2deecf 100644
14265 --- a/arch/x86/kernel/dumpstack_64.c
14266 +++ b/arch/x86/kernel/dumpstack_64.c
14267 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14268 unsigned long *irq_stack_end =
14269 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14270 unsigned used = 0;
14271 - struct thread_info *tinfo;
14272 int graph = 0;
14273 unsigned long dummy;
14274 + void *stack_start;
14275
14276 if (!task)
14277 task = current;
14278 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14279 * current stack address. If the stacks consist of nested
14280 * exceptions
14281 */
14282 - tinfo = task_thread_info(task);
14283 for (;;) {
14284 char *id;
14285 unsigned long *estack_end;
14286 +
14287 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14288 &used, &id);
14289
14290 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14291 if (ops->stack(data, id) < 0)
14292 break;
14293
14294 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14295 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14296 data, estack_end, &graph);
14297 ops->stack(data, "<EOE>");
14298 /*
14299 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14300 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14301 if (ops->stack(data, "IRQ") < 0)
14302 break;
14303 - bp = ops->walk_stack(tinfo, stack, bp,
14304 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14305 ops, data, irq_stack_end, &graph);
14306 /*
14307 * We link to the next stack (which would be
14308 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14309 /*
14310 * This handles the process stack:
14311 */
14312 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14313 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14314 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14315 put_cpu();
14316 }
14317 EXPORT_SYMBOL(dump_trace);
14318 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14319
14320 return ud2 == 0x0b0f;
14321 }
14322 +
14323 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14324 +void pax_check_alloca(unsigned long size)
14325 +{
14326 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14327 + unsigned cpu, used;
14328 + char *id;
14329 +
14330 + /* check the process stack first */
14331 + stack_start = (unsigned long)task_stack_page(current);
14332 + stack_end = stack_start + THREAD_SIZE;
14333 + if (likely(stack_start <= sp && sp < stack_end)) {
14334 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14335 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14336 + return;
14337 + }
14338 +
14339 + cpu = get_cpu();
14340 +
14341 + /* check the irq stacks */
14342 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14343 + stack_start = stack_end - IRQ_STACK_SIZE;
14344 + if (stack_start <= sp && sp < stack_end) {
14345 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14346 + put_cpu();
14347 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14348 + return;
14349 + }
14350 +
14351 + /* check the exception stacks */
14352 + used = 0;
14353 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14354 + stack_start = stack_end - EXCEPTION_STKSZ;
14355 + if (stack_end && stack_start <= sp && sp < stack_end) {
14356 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14357 + put_cpu();
14358 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14359 + return;
14360 + }
14361 +
14362 + put_cpu();
14363 +
14364 + /* unknown stack */
14365 + BUG();
14366 +}
14367 +EXPORT_SYMBOL(pax_check_alloca);
14368 +#endif
14369 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14370 index 9b9f18b..9fcaa04 100644
14371 --- a/arch/x86/kernel/early_printk.c
14372 +++ b/arch/x86/kernel/early_printk.c
14373 @@ -7,6 +7,7 @@
14374 #include <linux/pci_regs.h>
14375 #include <linux/pci_ids.h>
14376 #include <linux/errno.h>
14377 +#include <linux/sched.h>
14378 #include <asm/io.h>
14379 #include <asm/processor.h>
14380 #include <asm/fcntl.h>
14381 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14382 index 7b784f4..76aaad7 100644
14383 --- a/arch/x86/kernel/entry_32.S
14384 +++ b/arch/x86/kernel/entry_32.S
14385 @@ -179,13 +179,146 @@
14386 /*CFI_REL_OFFSET gs, PT_GS*/
14387 .endm
14388 .macro SET_KERNEL_GS reg
14389 +
14390 +#ifdef CONFIG_CC_STACKPROTECTOR
14391 movl $(__KERNEL_STACK_CANARY), \reg
14392 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14393 + movl $(__USER_DS), \reg
14394 +#else
14395 + xorl \reg, \reg
14396 +#endif
14397 +
14398 movl \reg, %gs
14399 .endm
14400
14401 #endif /* CONFIG_X86_32_LAZY_GS */
14402
14403 -.macro SAVE_ALL
14404 +.macro pax_enter_kernel
14405 +#ifdef CONFIG_PAX_KERNEXEC
14406 + call pax_enter_kernel
14407 +#endif
14408 +.endm
14409 +
14410 +.macro pax_exit_kernel
14411 +#ifdef CONFIG_PAX_KERNEXEC
14412 + call pax_exit_kernel
14413 +#endif
14414 +.endm
14415 +
14416 +#ifdef CONFIG_PAX_KERNEXEC
14417 +ENTRY(pax_enter_kernel)
14418 +#ifdef CONFIG_PARAVIRT
14419 + pushl %eax
14420 + pushl %ecx
14421 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14422 + mov %eax, %esi
14423 +#else
14424 + mov %cr0, %esi
14425 +#endif
14426 + bts $16, %esi
14427 + jnc 1f
14428 + mov %cs, %esi
14429 + cmp $__KERNEL_CS, %esi
14430 + jz 3f
14431 + ljmp $__KERNEL_CS, $3f
14432 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14433 +2:
14434 +#ifdef CONFIG_PARAVIRT
14435 + mov %esi, %eax
14436 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14437 +#else
14438 + mov %esi, %cr0
14439 +#endif
14440 +3:
14441 +#ifdef CONFIG_PARAVIRT
14442 + popl %ecx
14443 + popl %eax
14444 +#endif
14445 + ret
14446 +ENDPROC(pax_enter_kernel)
14447 +
14448 +ENTRY(pax_exit_kernel)
14449 +#ifdef CONFIG_PARAVIRT
14450 + pushl %eax
14451 + pushl %ecx
14452 +#endif
14453 + mov %cs, %esi
14454 + cmp $__KERNEXEC_KERNEL_CS, %esi
14455 + jnz 2f
14456 +#ifdef CONFIG_PARAVIRT
14457 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14458 + mov %eax, %esi
14459 +#else
14460 + mov %cr0, %esi
14461 +#endif
14462 + btr $16, %esi
14463 + ljmp $__KERNEL_CS, $1f
14464 +1:
14465 +#ifdef CONFIG_PARAVIRT
14466 + mov %esi, %eax
14467 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14468 +#else
14469 + mov %esi, %cr0
14470 +#endif
14471 +2:
14472 +#ifdef CONFIG_PARAVIRT
14473 + popl %ecx
14474 + popl %eax
14475 +#endif
14476 + ret
14477 +ENDPROC(pax_exit_kernel)
14478 +#endif
14479 +
14480 +.macro pax_erase_kstack
14481 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14482 + call pax_erase_kstack
14483 +#endif
14484 +.endm
14485 +
14486 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14487 +/*
14488 + * ebp: thread_info
14489 + * ecx, edx: can be clobbered
14490 + */
14491 +ENTRY(pax_erase_kstack)
14492 + pushl %edi
14493 + pushl %eax
14494 +
14495 + mov TI_lowest_stack(%ebp), %edi
14496 + mov $-0xBEEF, %eax
14497 + std
14498 +
14499 +1: mov %edi, %ecx
14500 + and $THREAD_SIZE_asm - 1, %ecx
14501 + shr $2, %ecx
14502 + repne scasl
14503 + jecxz 2f
14504 +
14505 + cmp $2*16, %ecx
14506 + jc 2f
14507 +
14508 + mov $2*16, %ecx
14509 + repe scasl
14510 + jecxz 2f
14511 + jne 1b
14512 +
14513 +2: cld
14514 + mov %esp, %ecx
14515 + sub %edi, %ecx
14516 + shr $2, %ecx
14517 + rep stosl
14518 +
14519 + mov TI_task_thread_sp0(%ebp), %edi
14520 + sub $128, %edi
14521 + mov %edi, TI_lowest_stack(%ebp)
14522 +
14523 + popl %eax
14524 + popl %edi
14525 + ret
14526 +ENDPROC(pax_erase_kstack)
14527 +#endif
14528 +
14529 +.macro __SAVE_ALL _DS
14530 cld
14531 PUSH_GS
14532 pushl_cfi %fs
14533 @@ -208,7 +341,7 @@
14534 CFI_REL_OFFSET ecx, 0
14535 pushl_cfi %ebx
14536 CFI_REL_OFFSET ebx, 0
14537 - movl $(__USER_DS), %edx
14538 + movl $\_DS, %edx
14539 movl %edx, %ds
14540 movl %edx, %es
14541 movl $(__KERNEL_PERCPU), %edx
14542 @@ -216,6 +349,15 @@
14543 SET_KERNEL_GS %edx
14544 .endm
14545
14546 +.macro SAVE_ALL
14547 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14548 + __SAVE_ALL __KERNEL_DS
14549 + pax_enter_kernel
14550 +#else
14551 + __SAVE_ALL __USER_DS
14552 +#endif
14553 +.endm
14554 +
14555 .macro RESTORE_INT_REGS
14556 popl_cfi %ebx
14557 CFI_RESTORE ebx
14558 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14559 popfl_cfi
14560 jmp syscall_exit
14561 CFI_ENDPROC
14562 -END(ret_from_fork)
14563 +ENDPROC(ret_from_fork)
14564
14565 /*
14566 * Interrupt exit functions should be protected against kprobes
14567 @@ -335,7 +477,15 @@ resume_userspace_sig:
14568 andl $SEGMENT_RPL_MASK, %eax
14569 #endif
14570 cmpl $USER_RPL, %eax
14571 +
14572 +#ifdef CONFIG_PAX_KERNEXEC
14573 + jae resume_userspace
14574 +
14575 + PAX_EXIT_KERNEL
14576 + jmp resume_kernel
14577 +#else
14578 jb resume_kernel # not returning to v8086 or userspace
14579 +#endif
14580
14581 ENTRY(resume_userspace)
14582 LOCKDEP_SYS_EXIT
14583 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14584 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14585 # int/exception return?
14586 jne work_pending
14587 - jmp restore_all
14588 -END(ret_from_exception)
14589 + jmp restore_all_pax
14590 +ENDPROC(ret_from_exception)
14591
14592 #ifdef CONFIG_PREEMPT
14593 ENTRY(resume_kernel)
14594 @@ -363,7 +513,7 @@ need_resched:
14595 jz restore_all
14596 call preempt_schedule_irq
14597 jmp need_resched
14598 -END(resume_kernel)
14599 +ENDPROC(resume_kernel)
14600 #endif
14601 CFI_ENDPROC
14602 /*
14603 @@ -397,23 +547,34 @@ sysenter_past_esp:
14604 /*CFI_REL_OFFSET cs, 0*/
14605 /*
14606 * Push current_thread_info()->sysenter_return to the stack.
14607 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14608 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14609 */
14610 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14611 + pushl_cfi $0
14612 CFI_REL_OFFSET eip, 0
14613
14614 pushl_cfi %eax
14615 SAVE_ALL
14616 + GET_THREAD_INFO(%ebp)
14617 + movl TI_sysenter_return(%ebp),%ebp
14618 + movl %ebp,PT_EIP(%esp)
14619 ENABLE_INTERRUPTS(CLBR_NONE)
14620
14621 /*
14622 * Load the potential sixth argument from user stack.
14623 * Careful about security.
14624 */
14625 + movl PT_OLDESP(%esp),%ebp
14626 +
14627 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14628 + mov PT_OLDSS(%esp),%ds
14629 +1: movl %ds:(%ebp),%ebp
14630 + push %ss
14631 + pop %ds
14632 +#else
14633 cmpl $__PAGE_OFFSET-3,%ebp
14634 jae syscall_fault
14635 1: movl (%ebp),%ebp
14636 +#endif
14637 +
14638 movl %ebp,PT_EBP(%esp)
14639 .section __ex_table,"a"
14640 .align 4
14641 @@ -436,12 +597,24 @@ sysenter_do_call:
14642 testl $_TIF_ALLWORK_MASK, %ecx
14643 jne sysexit_audit
14644 sysenter_exit:
14645 +
14646 +#ifdef CONFIG_PAX_RANDKSTACK
14647 + pushl_cfi %eax
14648 + movl %esp, %eax
14649 + call pax_randomize_kstack
14650 + popl_cfi %eax
14651 +#endif
14652 +
14653 + pax_erase_kstack
14654 +
14655 /* if something modifies registers it must also disable sysexit */
14656 movl PT_EIP(%esp), %edx
14657 movl PT_OLDESP(%esp), %ecx
14658 xorl %ebp,%ebp
14659 TRACE_IRQS_ON
14660 1: mov PT_FS(%esp), %fs
14661 +2: mov PT_DS(%esp), %ds
14662 +3: mov PT_ES(%esp), %es
14663 PTGS_TO_GS
14664 ENABLE_INTERRUPTS_SYSEXIT
14665
14666 @@ -458,6 +631,9 @@ sysenter_audit:
14667 movl %eax,%edx /* 2nd arg: syscall number */
14668 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14669 call __audit_syscall_entry
14670 +
14671 + pax_erase_kstack
14672 +
14673 pushl_cfi %ebx
14674 movl PT_EAX(%esp),%eax /* reload syscall number */
14675 jmp sysenter_do_call
14676 @@ -483,11 +659,17 @@ sysexit_audit:
14677
14678 CFI_ENDPROC
14679 .pushsection .fixup,"ax"
14680 -2: movl $0,PT_FS(%esp)
14681 +4: movl $0,PT_FS(%esp)
14682 + jmp 1b
14683 +5: movl $0,PT_DS(%esp)
14684 + jmp 1b
14685 +6: movl $0,PT_ES(%esp)
14686 jmp 1b
14687 .section __ex_table,"a"
14688 .align 4
14689 - .long 1b,2b
14690 + .long 1b,4b
14691 + .long 2b,5b
14692 + .long 3b,6b
14693 .popsection
14694 PTGS_TO_GS_EX
14695 ENDPROC(ia32_sysenter_target)
14696 @@ -520,6 +702,15 @@ syscall_exit:
14697 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14698 jne syscall_exit_work
14699
14700 +restore_all_pax:
14701 +
14702 +#ifdef CONFIG_PAX_RANDKSTACK
14703 + movl %esp, %eax
14704 + call pax_randomize_kstack
14705 +#endif
14706 +
14707 + pax_erase_kstack
14708 +
14709 restore_all:
14710 TRACE_IRQS_IRET
14711 restore_all_notrace:
14712 @@ -579,14 +770,34 @@ ldt_ss:
14713 * compensating for the offset by changing to the ESPFIX segment with
14714 * a base address that matches for the difference.
14715 */
14716 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14717 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14718 mov %esp, %edx /* load kernel esp */
14719 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14720 mov %dx, %ax /* eax: new kernel esp */
14721 sub %eax, %edx /* offset (low word is 0) */
14722 +#ifdef CONFIG_SMP
14723 + movl PER_CPU_VAR(cpu_number), %ebx
14724 + shll $PAGE_SHIFT_asm, %ebx
14725 + addl $cpu_gdt_table, %ebx
14726 +#else
14727 + movl $cpu_gdt_table, %ebx
14728 +#endif
14729 shr $16, %edx
14730 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14731 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14732 +
14733 +#ifdef CONFIG_PAX_KERNEXEC
14734 + mov %cr0, %esi
14735 + btr $16, %esi
14736 + mov %esi, %cr0
14737 +#endif
14738 +
14739 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14740 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14741 +
14742 +#ifdef CONFIG_PAX_KERNEXEC
14743 + bts $16, %esi
14744 + mov %esi, %cr0
14745 +#endif
14746 +
14747 pushl_cfi $__ESPFIX_SS
14748 pushl_cfi %eax /* new kernel esp */
14749 /* Disable interrupts, but do not irqtrace this section: we
14750 @@ -615,38 +826,30 @@ work_resched:
14751 movl TI_flags(%ebp), %ecx
14752 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14753 # than syscall tracing?
14754 - jz restore_all
14755 + jz restore_all_pax
14756 testb $_TIF_NEED_RESCHED, %cl
14757 jnz work_resched
14758
14759 work_notifysig: # deal with pending signals and
14760 # notify-resume requests
14761 + movl %esp, %eax
14762 #ifdef CONFIG_VM86
14763 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14764 - movl %esp, %eax
14765 - jne work_notifysig_v86 # returning to kernel-space or
14766 + jz 1f # returning to kernel-space or
14767 # vm86-space
14768 - TRACE_IRQS_ON
14769 - ENABLE_INTERRUPTS(CLBR_NONE)
14770 - xorl %edx, %edx
14771 - call do_notify_resume
14772 - jmp resume_userspace_sig
14773
14774 - ALIGN
14775 -work_notifysig_v86:
14776 pushl_cfi %ecx # save ti_flags for do_notify_resume
14777 call save_v86_state # %eax contains pt_regs pointer
14778 popl_cfi %ecx
14779 movl %eax, %esp
14780 -#else
14781 - movl %esp, %eax
14782 +1:
14783 #endif
14784 TRACE_IRQS_ON
14785 ENABLE_INTERRUPTS(CLBR_NONE)
14786 xorl %edx, %edx
14787 call do_notify_resume
14788 jmp resume_userspace_sig
14789 -END(work_pending)
14790 +ENDPROC(work_pending)
14791
14792 # perform syscall exit tracing
14793 ALIGN
14794 @@ -654,11 +857,14 @@ syscall_trace_entry:
14795 movl $-ENOSYS,PT_EAX(%esp)
14796 movl %esp, %eax
14797 call syscall_trace_enter
14798 +
14799 + pax_erase_kstack
14800 +
14801 /* What it returned is what we'll actually use. */
14802 cmpl $(NR_syscalls), %eax
14803 jnae syscall_call
14804 jmp syscall_exit
14805 -END(syscall_trace_entry)
14806 +ENDPROC(syscall_trace_entry)
14807
14808 # perform syscall exit tracing
14809 ALIGN
14810 @@ -671,20 +877,24 @@ syscall_exit_work:
14811 movl %esp, %eax
14812 call syscall_trace_leave
14813 jmp resume_userspace
14814 -END(syscall_exit_work)
14815 +ENDPROC(syscall_exit_work)
14816 CFI_ENDPROC
14817
14818 RING0_INT_FRAME # can't unwind into user space anyway
14819 syscall_fault:
14820 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14821 + push %ss
14822 + pop %ds
14823 +#endif
14824 GET_THREAD_INFO(%ebp)
14825 movl $-EFAULT,PT_EAX(%esp)
14826 jmp resume_userspace
14827 -END(syscall_fault)
14828 +ENDPROC(syscall_fault)
14829
14830 syscall_badsys:
14831 movl $-ENOSYS,PT_EAX(%esp)
14832 jmp resume_userspace
14833 -END(syscall_badsys)
14834 +ENDPROC(syscall_badsys)
14835 CFI_ENDPROC
14836 /*
14837 * End of kprobes section
14838 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
14839 CFI_ENDPROC
14840 ENDPROC(ptregs_clone)
14841
14842 + ALIGN;
14843 +ENTRY(kernel_execve)
14844 + CFI_STARTPROC
14845 + pushl_cfi %ebp
14846 + sub $PT_OLDSS+4,%esp
14847 + pushl_cfi %edi
14848 + pushl_cfi %ecx
14849 + pushl_cfi %eax
14850 + lea 3*4(%esp),%edi
14851 + mov $PT_OLDSS/4+1,%ecx
14852 + xorl %eax,%eax
14853 + rep stosl
14854 + popl_cfi %eax
14855 + popl_cfi %ecx
14856 + popl_cfi %edi
14857 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14858 + pushl_cfi %esp
14859 + call sys_execve
14860 + add $4,%esp
14861 + CFI_ADJUST_CFA_OFFSET -4
14862 + GET_THREAD_INFO(%ebp)
14863 + test %eax,%eax
14864 + jz syscall_exit
14865 + add $PT_OLDSS+4,%esp
14866 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14867 + popl_cfi %ebp
14868 + ret
14869 + CFI_ENDPROC
14870 +ENDPROC(kernel_execve)
14871 +
14872 .macro FIXUP_ESPFIX_STACK
14873 /*
14874 * Switch back for ESPFIX stack to the normal zerobased stack
14875 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
14876 * normal stack and adjusts ESP with the matching offset.
14877 */
14878 /* fixup the stack */
14879 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14880 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14881 +#ifdef CONFIG_SMP
14882 + movl PER_CPU_VAR(cpu_number), %ebx
14883 + shll $PAGE_SHIFT_asm, %ebx
14884 + addl $cpu_gdt_table, %ebx
14885 +#else
14886 + movl $cpu_gdt_table, %ebx
14887 +#endif
14888 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14889 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14890 shl $16, %eax
14891 addl %esp, %eax /* the adjusted stack pointer */
14892 pushl_cfi $__KERNEL_DS
14893 @@ -819,7 +1066,7 @@ vector=vector+1
14894 .endr
14895 2: jmp common_interrupt
14896 .endr
14897 -END(irq_entries_start)
14898 +ENDPROC(irq_entries_start)
14899
14900 .previous
14901 END(interrupt)
14902 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
14903 pushl_cfi $do_coprocessor_error
14904 jmp error_code
14905 CFI_ENDPROC
14906 -END(coprocessor_error)
14907 +ENDPROC(coprocessor_error)
14908
14909 ENTRY(simd_coprocessor_error)
14910 RING0_INT_FRAME
14911 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
14912 #endif
14913 jmp error_code
14914 CFI_ENDPROC
14915 -END(simd_coprocessor_error)
14916 +ENDPROC(simd_coprocessor_error)
14917
14918 ENTRY(device_not_available)
14919 RING0_INT_FRAME
14920 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
14921 pushl_cfi $do_device_not_available
14922 jmp error_code
14923 CFI_ENDPROC
14924 -END(device_not_available)
14925 +ENDPROC(device_not_available)
14926
14927 #ifdef CONFIG_PARAVIRT
14928 ENTRY(native_iret)
14929 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
14930 .align 4
14931 .long native_iret, iret_exc
14932 .previous
14933 -END(native_iret)
14934 +ENDPROC(native_iret)
14935
14936 ENTRY(native_irq_enable_sysexit)
14937 sti
14938 sysexit
14939 -END(native_irq_enable_sysexit)
14940 +ENDPROC(native_irq_enable_sysexit)
14941 #endif
14942
14943 ENTRY(overflow)
14944 @@ -919,7 +1166,7 @@ ENTRY(overflow)
14945 pushl_cfi $do_overflow
14946 jmp error_code
14947 CFI_ENDPROC
14948 -END(overflow)
14949 +ENDPROC(overflow)
14950
14951 ENTRY(bounds)
14952 RING0_INT_FRAME
14953 @@ -927,7 +1174,7 @@ ENTRY(bounds)
14954 pushl_cfi $do_bounds
14955 jmp error_code
14956 CFI_ENDPROC
14957 -END(bounds)
14958 +ENDPROC(bounds)
14959
14960 ENTRY(invalid_op)
14961 RING0_INT_FRAME
14962 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
14963 pushl_cfi $do_invalid_op
14964 jmp error_code
14965 CFI_ENDPROC
14966 -END(invalid_op)
14967 +ENDPROC(invalid_op)
14968
14969 ENTRY(coprocessor_segment_overrun)
14970 RING0_INT_FRAME
14971 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
14972 pushl_cfi $do_coprocessor_segment_overrun
14973 jmp error_code
14974 CFI_ENDPROC
14975 -END(coprocessor_segment_overrun)
14976 +ENDPROC(coprocessor_segment_overrun)
14977
14978 ENTRY(invalid_TSS)
14979 RING0_EC_FRAME
14980 pushl_cfi $do_invalid_TSS
14981 jmp error_code
14982 CFI_ENDPROC
14983 -END(invalid_TSS)
14984 +ENDPROC(invalid_TSS)
14985
14986 ENTRY(segment_not_present)
14987 RING0_EC_FRAME
14988 pushl_cfi $do_segment_not_present
14989 jmp error_code
14990 CFI_ENDPROC
14991 -END(segment_not_present)
14992 +ENDPROC(segment_not_present)
14993
14994 ENTRY(stack_segment)
14995 RING0_EC_FRAME
14996 pushl_cfi $do_stack_segment
14997 jmp error_code
14998 CFI_ENDPROC
14999 -END(stack_segment)
15000 +ENDPROC(stack_segment)
15001
15002 ENTRY(alignment_check)
15003 RING0_EC_FRAME
15004 pushl_cfi $do_alignment_check
15005 jmp error_code
15006 CFI_ENDPROC
15007 -END(alignment_check)
15008 +ENDPROC(alignment_check)
15009
15010 ENTRY(divide_error)
15011 RING0_INT_FRAME
15012 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15013 pushl_cfi $do_divide_error
15014 jmp error_code
15015 CFI_ENDPROC
15016 -END(divide_error)
15017 +ENDPROC(divide_error)
15018
15019 #ifdef CONFIG_X86_MCE
15020 ENTRY(machine_check)
15021 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15022 pushl_cfi machine_check_vector
15023 jmp error_code
15024 CFI_ENDPROC
15025 -END(machine_check)
15026 +ENDPROC(machine_check)
15027 #endif
15028
15029 ENTRY(spurious_interrupt_bug)
15030 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15031 pushl_cfi $do_spurious_interrupt_bug
15032 jmp error_code
15033 CFI_ENDPROC
15034 -END(spurious_interrupt_bug)
15035 +ENDPROC(spurious_interrupt_bug)
15036 /*
15037 * End of kprobes section
15038 */
15039 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15040
15041 ENTRY(mcount)
15042 ret
15043 -END(mcount)
15044 +ENDPROC(mcount)
15045
15046 ENTRY(ftrace_caller)
15047 cmpl $0, function_trace_stop
15048 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15049 .globl ftrace_stub
15050 ftrace_stub:
15051 ret
15052 -END(ftrace_caller)
15053 +ENDPROC(ftrace_caller)
15054
15055 #else /* ! CONFIG_DYNAMIC_FTRACE */
15056
15057 @@ -1177,7 +1424,7 @@ trace:
15058 popl %ecx
15059 popl %eax
15060 jmp ftrace_stub
15061 -END(mcount)
15062 +ENDPROC(mcount)
15063 #endif /* CONFIG_DYNAMIC_FTRACE */
15064 #endif /* CONFIG_FUNCTION_TRACER */
15065
15066 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15067 popl %ecx
15068 popl %eax
15069 ret
15070 -END(ftrace_graph_caller)
15071 +ENDPROC(ftrace_graph_caller)
15072
15073 .globl return_to_handler
15074 return_to_handler:
15075 @@ -1253,15 +1500,18 @@ error_code:
15076 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15077 REG_TO_PTGS %ecx
15078 SET_KERNEL_GS %ecx
15079 - movl $(__USER_DS), %ecx
15080 + movl $(__KERNEL_DS), %ecx
15081 movl %ecx, %ds
15082 movl %ecx, %es
15083 +
15084 + pax_enter_kernel
15085 +
15086 TRACE_IRQS_OFF
15087 movl %esp,%eax # pt_regs pointer
15088 call *%edi
15089 jmp ret_from_exception
15090 CFI_ENDPROC
15091 -END(page_fault)
15092 +ENDPROC(page_fault)
15093
15094 /*
15095 * Debug traps and NMI can happen at the one SYSENTER instruction
15096 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15097 call do_debug
15098 jmp ret_from_exception
15099 CFI_ENDPROC
15100 -END(debug)
15101 +ENDPROC(debug)
15102
15103 /*
15104 * NMI is doubly nasty. It can happen _while_ we're handling
15105 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15106 xorl %edx,%edx # zero error code
15107 movl %esp,%eax # pt_regs pointer
15108 call do_nmi
15109 +
15110 + pax_exit_kernel
15111 +
15112 jmp restore_all_notrace
15113 CFI_ENDPROC
15114
15115 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15116 FIXUP_ESPFIX_STACK # %eax == %esp
15117 xorl %edx,%edx # zero error code
15118 call do_nmi
15119 +
15120 + pax_exit_kernel
15121 +
15122 RESTORE_REGS
15123 lss 12+4(%esp), %esp # back to espfix stack
15124 CFI_ADJUST_CFA_OFFSET -24
15125 jmp irq_return
15126 CFI_ENDPROC
15127 -END(nmi)
15128 +ENDPROC(nmi)
15129
15130 ENTRY(int3)
15131 RING0_INT_FRAME
15132 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15133 call do_int3
15134 jmp ret_from_exception
15135 CFI_ENDPROC
15136 -END(int3)
15137 +ENDPROC(int3)
15138
15139 ENTRY(general_protection)
15140 RING0_EC_FRAME
15141 pushl_cfi $do_general_protection
15142 jmp error_code
15143 CFI_ENDPROC
15144 -END(general_protection)
15145 +ENDPROC(general_protection)
15146
15147 #ifdef CONFIG_KVM_GUEST
15148 ENTRY(async_page_fault)
15149 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15150 pushl_cfi $do_async_page_fault
15151 jmp error_code
15152 CFI_ENDPROC
15153 -END(async_page_fault)
15154 +ENDPROC(async_page_fault)
15155 #endif
15156
15157 /*
15158 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15159 index 1333d98..b340ca2 100644
15160 --- a/arch/x86/kernel/entry_64.S
15161 +++ b/arch/x86/kernel/entry_64.S
15162 @@ -56,6 +56,8 @@
15163 #include <asm/ftrace.h>
15164 #include <asm/percpu.h>
15165 #include <linux/err.h>
15166 +#include <asm/pgtable.h>
15167 +#include <asm/alternative-asm.h>
15168
15169 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15170 #include <linux/elf-em.h>
15171 @@ -69,8 +71,9 @@
15172 #ifdef CONFIG_FUNCTION_TRACER
15173 #ifdef CONFIG_DYNAMIC_FTRACE
15174 ENTRY(mcount)
15175 + pax_force_retaddr
15176 retq
15177 -END(mcount)
15178 +ENDPROC(mcount)
15179
15180 ENTRY(ftrace_caller)
15181 cmpl $0, function_trace_stop
15182 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15183 #endif
15184
15185 GLOBAL(ftrace_stub)
15186 + pax_force_retaddr
15187 retq
15188 -END(ftrace_caller)
15189 +ENDPROC(ftrace_caller)
15190
15191 #else /* ! CONFIG_DYNAMIC_FTRACE */
15192 ENTRY(mcount)
15193 @@ -113,6 +117,7 @@ ENTRY(mcount)
15194 #endif
15195
15196 GLOBAL(ftrace_stub)
15197 + pax_force_retaddr
15198 retq
15199
15200 trace:
15201 @@ -122,12 +127,13 @@ trace:
15202 movq 8(%rbp), %rsi
15203 subq $MCOUNT_INSN_SIZE, %rdi
15204
15205 + pax_force_fptr ftrace_trace_function
15206 call *ftrace_trace_function
15207
15208 MCOUNT_RESTORE_FRAME
15209
15210 jmp ftrace_stub
15211 -END(mcount)
15212 +ENDPROC(mcount)
15213 #endif /* CONFIG_DYNAMIC_FTRACE */
15214 #endif /* CONFIG_FUNCTION_TRACER */
15215
15216 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15217
15218 MCOUNT_RESTORE_FRAME
15219
15220 + pax_force_retaddr
15221 retq
15222 -END(ftrace_graph_caller)
15223 +ENDPROC(ftrace_graph_caller)
15224
15225 GLOBAL(return_to_handler)
15226 subq $24, %rsp
15227 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15228 movq 8(%rsp), %rdx
15229 movq (%rsp), %rax
15230 addq $24, %rsp
15231 + pax_force_fptr %rdi
15232 jmp *%rdi
15233 #endif
15234
15235 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15236 ENDPROC(native_usergs_sysret64)
15237 #endif /* CONFIG_PARAVIRT */
15238
15239 + .macro ljmpq sel, off
15240 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15241 + .byte 0x48; ljmp *1234f(%rip)
15242 + .pushsection .rodata
15243 + .align 16
15244 + 1234: .quad \off; .word \sel
15245 + .popsection
15246 +#else
15247 + pushq $\sel
15248 + pushq $\off
15249 + lretq
15250 +#endif
15251 + .endm
15252 +
15253 + .macro pax_enter_kernel
15254 + pax_set_fptr_mask
15255 +#ifdef CONFIG_PAX_KERNEXEC
15256 + call pax_enter_kernel
15257 +#endif
15258 + .endm
15259 +
15260 + .macro pax_exit_kernel
15261 +#ifdef CONFIG_PAX_KERNEXEC
15262 + call pax_exit_kernel
15263 +#endif
15264 + .endm
15265 +
15266 +#ifdef CONFIG_PAX_KERNEXEC
15267 +ENTRY(pax_enter_kernel)
15268 + pushq %rdi
15269 +
15270 +#ifdef CONFIG_PARAVIRT
15271 + PV_SAVE_REGS(CLBR_RDI)
15272 +#endif
15273 +
15274 + GET_CR0_INTO_RDI
15275 + bts $16,%rdi
15276 + jnc 3f
15277 + mov %cs,%edi
15278 + cmp $__KERNEL_CS,%edi
15279 + jnz 2f
15280 +1:
15281 +
15282 +#ifdef CONFIG_PARAVIRT
15283 + PV_RESTORE_REGS(CLBR_RDI)
15284 +#endif
15285 +
15286 + popq %rdi
15287 + pax_force_retaddr
15288 + retq
15289 +
15290 +2: ljmpq __KERNEL_CS,1f
15291 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15292 +4: SET_RDI_INTO_CR0
15293 + jmp 1b
15294 +ENDPROC(pax_enter_kernel)
15295 +
15296 +ENTRY(pax_exit_kernel)
15297 + pushq %rdi
15298 +
15299 +#ifdef CONFIG_PARAVIRT
15300 + PV_SAVE_REGS(CLBR_RDI)
15301 +#endif
15302 +
15303 + mov %cs,%rdi
15304 + cmp $__KERNEXEC_KERNEL_CS,%edi
15305 + jz 2f
15306 +1:
15307 +
15308 +#ifdef CONFIG_PARAVIRT
15309 + PV_RESTORE_REGS(CLBR_RDI);
15310 +#endif
15311 +
15312 + popq %rdi
15313 + pax_force_retaddr
15314 + retq
15315 +
15316 +2: GET_CR0_INTO_RDI
15317 + btr $16,%rdi
15318 + ljmpq __KERNEL_CS,3f
15319 +3: SET_RDI_INTO_CR0
15320 + jmp 1b
15321 +#ifdef CONFIG_PARAVIRT
15322 + PV_RESTORE_REGS(CLBR_RDI);
15323 +#endif
15324 +
15325 + popq %rdi
15326 + pax_force_retaddr
15327 + retq
15328 +ENDPROC(pax_exit_kernel)
15329 +#endif
15330 +
15331 + .macro pax_enter_kernel_user
15332 + pax_set_fptr_mask
15333 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15334 + call pax_enter_kernel_user
15335 +#endif
15336 + .endm
15337 +
15338 + .macro pax_exit_kernel_user
15339 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15340 + call pax_exit_kernel_user
15341 +#endif
15342 +#ifdef CONFIG_PAX_RANDKSTACK
15343 + pushq %rax
15344 + call pax_randomize_kstack
15345 + popq %rax
15346 +#endif
15347 + .endm
15348 +
15349 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15350 +ENTRY(pax_enter_kernel_user)
15351 + pushq %rdi
15352 + pushq %rbx
15353 +
15354 +#ifdef CONFIG_PARAVIRT
15355 + PV_SAVE_REGS(CLBR_RDI)
15356 +#endif
15357 +
15358 + GET_CR3_INTO_RDI
15359 + mov %rdi,%rbx
15360 + add $__START_KERNEL_map,%rbx
15361 + sub phys_base(%rip),%rbx
15362 +
15363 +#ifdef CONFIG_PARAVIRT
15364 + pushq %rdi
15365 + cmpl $0, pv_info+PARAVIRT_enabled
15366 + jz 1f
15367 + i = 0
15368 + .rept USER_PGD_PTRS
15369 + mov i*8(%rbx),%rsi
15370 + mov $0,%sil
15371 + lea i*8(%rbx),%rdi
15372 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15373 + i = i + 1
15374 + .endr
15375 + jmp 2f
15376 +1:
15377 +#endif
15378 +
15379 + i = 0
15380 + .rept USER_PGD_PTRS
15381 + movb $0,i*8(%rbx)
15382 + i = i + 1
15383 + .endr
15384 +
15385 +#ifdef CONFIG_PARAVIRT
15386 +2: popq %rdi
15387 +#endif
15388 + SET_RDI_INTO_CR3
15389 +
15390 +#ifdef CONFIG_PAX_KERNEXEC
15391 + GET_CR0_INTO_RDI
15392 + bts $16,%rdi
15393 + SET_RDI_INTO_CR0
15394 +#endif
15395 +
15396 +#ifdef CONFIG_PARAVIRT
15397 + PV_RESTORE_REGS(CLBR_RDI)
15398 +#endif
15399 +
15400 + popq %rbx
15401 + popq %rdi
15402 + pax_force_retaddr
15403 + retq
15404 +ENDPROC(pax_enter_kernel_user)
15405 +
15406 +ENTRY(pax_exit_kernel_user)
15407 + push %rdi
15408 +
15409 +#ifdef CONFIG_PARAVIRT
15410 + pushq %rbx
15411 + PV_SAVE_REGS(CLBR_RDI)
15412 +#endif
15413 +
15414 +#ifdef CONFIG_PAX_KERNEXEC
15415 + GET_CR0_INTO_RDI
15416 + btr $16,%rdi
15417 + SET_RDI_INTO_CR0
15418 +#endif
15419 +
15420 + GET_CR3_INTO_RDI
15421 + add $__START_KERNEL_map,%rdi
15422 + sub phys_base(%rip),%rdi
15423 +
15424 +#ifdef CONFIG_PARAVIRT
15425 + cmpl $0, pv_info+PARAVIRT_enabled
15426 + jz 1f
15427 + mov %rdi,%rbx
15428 + i = 0
15429 + .rept USER_PGD_PTRS
15430 + mov i*8(%rbx),%rsi
15431 + mov $0x67,%sil
15432 + lea i*8(%rbx),%rdi
15433 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15434 + i = i + 1
15435 + .endr
15436 + jmp 2f
15437 +1:
15438 +#endif
15439 +
15440 + i = 0
15441 + .rept USER_PGD_PTRS
15442 + movb $0x67,i*8(%rdi)
15443 + i = i + 1
15444 + .endr
15445 +
15446 +#ifdef CONFIG_PARAVIRT
15447 +2: PV_RESTORE_REGS(CLBR_RDI)
15448 + popq %rbx
15449 +#endif
15450 +
15451 + popq %rdi
15452 + pax_force_retaddr
15453 + retq
15454 +ENDPROC(pax_exit_kernel_user)
15455 +#endif
15456 +
15457 +.macro pax_erase_kstack
15458 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15459 + call pax_erase_kstack
15460 +#endif
15461 +.endm
15462 +
15463 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15464 +/*
15465 + * r11: thread_info
15466 + * rcx, rdx: can be clobbered
15467 + */
15468 +ENTRY(pax_erase_kstack)
15469 + pushq %rdi
15470 + pushq %rax
15471 + pushq %r11
15472 +
15473 + GET_THREAD_INFO(%r11)
15474 + mov TI_lowest_stack(%r11), %rdi
15475 + mov $-0xBEEF, %rax
15476 + std
15477 +
15478 +1: mov %edi, %ecx
15479 + and $THREAD_SIZE_asm - 1, %ecx
15480 + shr $3, %ecx
15481 + repne scasq
15482 + jecxz 2f
15483 +
15484 + cmp $2*8, %ecx
15485 + jc 2f
15486 +
15487 + mov $2*8, %ecx
15488 + repe scasq
15489 + jecxz 2f
15490 + jne 1b
15491 +
15492 +2: cld
15493 + mov %esp, %ecx
15494 + sub %edi, %ecx
15495 +
15496 + cmp $THREAD_SIZE_asm, %rcx
15497 + jb 3f
15498 + ud2
15499 +3:
15500 +
15501 + shr $3, %ecx
15502 + rep stosq
15503 +
15504 + mov TI_task_thread_sp0(%r11), %rdi
15505 + sub $256, %rdi
15506 + mov %rdi, TI_lowest_stack(%r11)
15507 +
15508 + popq %r11
15509 + popq %rax
15510 + popq %rdi
15511 + pax_force_retaddr
15512 + ret
15513 +ENDPROC(pax_erase_kstack)
15514 +#endif
15515
15516 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15517 #ifdef CONFIG_TRACE_IRQFLAGS
15518 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15519 .endm
15520
15521 .macro UNFAKE_STACK_FRAME
15522 - addq $8*6, %rsp
15523 - CFI_ADJUST_CFA_OFFSET -(6*8)
15524 + addq $8*6 + ARG_SKIP, %rsp
15525 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15526 .endm
15527
15528 /*
15529 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15530 movq %rsp, %rsi
15531
15532 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15533 - testl $3, CS(%rdi)
15534 + testb $3, CS(%rdi)
15535 je 1f
15536 SWAPGS
15537 /*
15538 @@ -356,9 +640,10 @@ ENTRY(save_rest)
15539 movq_cfi r15, R15+16
15540 movq %r11, 8(%rsp) /* return address */
15541 FIXUP_TOP_OF_STACK %r11, 16
15542 + pax_force_retaddr
15543 ret
15544 CFI_ENDPROC
15545 -END(save_rest)
15546 +ENDPROC(save_rest)
15547
15548 /* save complete stack frame */
15549 .pushsection .kprobes.text, "ax"
15550 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15551 js 1f /* negative -> in kernel */
15552 SWAPGS
15553 xorl %ebx,%ebx
15554 -1: ret
15555 +1: pax_force_retaddr_bts
15556 + ret
15557 CFI_ENDPROC
15558 -END(save_paranoid)
15559 +ENDPROC(save_paranoid)
15560 .popsection
15561
15562 /*
15563 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15564
15565 RESTORE_REST
15566
15567 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15568 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15569 jz retint_restore_args
15570
15571 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15572 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15573 jmp ret_from_sys_call # go to the SYSRET fastpath
15574
15575 CFI_ENDPROC
15576 -END(ret_from_fork)
15577 +ENDPROC(ret_from_fork)
15578
15579 /*
15580 * System call entry. Up to 6 arguments in registers are supported.
15581 @@ -457,7 +743,7 @@ END(ret_from_fork)
15582 ENTRY(system_call)
15583 CFI_STARTPROC simple
15584 CFI_SIGNAL_FRAME
15585 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15586 + CFI_DEF_CFA rsp,0
15587 CFI_REGISTER rip,rcx
15588 /*CFI_REGISTER rflags,r11*/
15589 SWAPGS_UNSAFE_STACK
15590 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15591
15592 movq %rsp,PER_CPU_VAR(old_rsp)
15593 movq PER_CPU_VAR(kernel_stack),%rsp
15594 + SAVE_ARGS 8*6,0
15595 + pax_enter_kernel_user
15596 /*
15597 * No need to follow this irqs off/on section - it's straight
15598 * and short:
15599 */
15600 ENABLE_INTERRUPTS(CLBR_NONE)
15601 - SAVE_ARGS 8,0
15602 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15603 movq %rcx,RIP-ARGOFFSET(%rsp)
15604 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15605 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15606 + GET_THREAD_INFO(%rcx)
15607 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15608 jnz tracesys
15609 system_call_fastpath:
15610 cmpq $__NR_syscall_max,%rax
15611 ja badsys
15612 - movq %r10,%rcx
15613 + movq R10-ARGOFFSET(%rsp),%rcx
15614 call *sys_call_table(,%rax,8) # XXX: rip relative
15615 movq %rax,RAX-ARGOFFSET(%rsp)
15616 /*
15617 @@ -498,10 +786,13 @@ sysret_check:
15618 LOCKDEP_SYS_EXIT
15619 DISABLE_INTERRUPTS(CLBR_NONE)
15620 TRACE_IRQS_OFF
15621 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
15622 + GET_THREAD_INFO(%rcx)
15623 + movl TI_flags(%rcx),%edx
15624 andl %edi,%edx
15625 jnz sysret_careful
15626 CFI_REMEMBER_STATE
15627 + pax_exit_kernel_user
15628 + pax_erase_kstack
15629 /*
15630 * sysretq will re-enable interrupts:
15631 */
15632 @@ -553,14 +844,18 @@ badsys:
15633 * jump back to the normal fast path.
15634 */
15635 auditsys:
15636 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15637 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15638 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15639 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15640 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15641 movq %rax,%rsi /* 2nd arg: syscall number */
15642 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15643 call __audit_syscall_entry
15644 +
15645 + pax_erase_kstack
15646 +
15647 LOAD_ARGS 0 /* reload call-clobbered registers */
15648 + pax_set_fptr_mask
15649 jmp system_call_fastpath
15650
15651 /*
15652 @@ -581,7 +876,7 @@ sysret_audit:
15653 /* Do syscall tracing */
15654 tracesys:
15655 #ifdef CONFIG_AUDITSYSCALL
15656 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15657 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
15658 jz auditsys
15659 #endif
15660 SAVE_REST
15661 @@ -589,16 +884,20 @@ tracesys:
15662 FIXUP_TOP_OF_STACK %rdi
15663 movq %rsp,%rdi
15664 call syscall_trace_enter
15665 +
15666 + pax_erase_kstack
15667 +
15668 /*
15669 * Reload arg registers from stack in case ptrace changed them.
15670 * We don't reload %rax because syscall_trace_enter() returned
15671 * the value it wants us to use in the table lookup.
15672 */
15673 LOAD_ARGS ARGOFFSET, 1
15674 + pax_set_fptr_mask
15675 RESTORE_REST
15676 cmpq $__NR_syscall_max,%rax
15677 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15678 - movq %r10,%rcx /* fixup for C */
15679 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15680 call *sys_call_table(,%rax,8)
15681 movq %rax,RAX-ARGOFFSET(%rsp)
15682 /* Use IRET because user could have changed frame */
15683 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
15684 andl %edi,%edx
15685 jnz int_careful
15686 andl $~TS_COMPAT,TI_status(%rcx)
15687 + pax_erase_kstack
15688 jmp retint_swapgs
15689
15690 /* Either reschedule or signal or syscall exit tracking needed. */
15691 @@ -665,7 +965,7 @@ int_restore_rest:
15692 TRACE_IRQS_OFF
15693 jmp int_with_check
15694 CFI_ENDPROC
15695 -END(system_call)
15696 +ENDPROC(system_call)
15697
15698 /*
15699 * Certain special system calls that need to save a complete full stack frame.
15700 @@ -681,7 +981,7 @@ ENTRY(\label)
15701 call \func
15702 jmp ptregscall_common
15703 CFI_ENDPROC
15704 -END(\label)
15705 +ENDPROC(\label)
15706 .endm
15707
15708 PTREGSCALL stub_clone, sys_clone, %r8
15709 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
15710 movq_cfi_restore R12+8, r12
15711 movq_cfi_restore RBP+8, rbp
15712 movq_cfi_restore RBX+8, rbx
15713 + pax_force_retaddr
15714 ret $REST_SKIP /* pop extended registers */
15715 CFI_ENDPROC
15716 -END(ptregscall_common)
15717 +ENDPROC(ptregscall_common)
15718
15719 ENTRY(stub_execve)
15720 CFI_STARTPROC
15721 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
15722 RESTORE_REST
15723 jmp int_ret_from_sys_call
15724 CFI_ENDPROC
15725 -END(stub_execve)
15726 +ENDPROC(stub_execve)
15727
15728 /*
15729 * sigreturn is special because it needs to restore all registers on return.
15730 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
15731 RESTORE_REST
15732 jmp int_ret_from_sys_call
15733 CFI_ENDPROC
15734 -END(stub_rt_sigreturn)
15735 +ENDPROC(stub_rt_sigreturn)
15736
15737 /*
15738 * Build the entry stubs and pointer table with some assembler magic.
15739 @@ -769,7 +1070,7 @@ vector=vector+1
15740 2: jmp common_interrupt
15741 .endr
15742 CFI_ENDPROC
15743 -END(irq_entries_start)
15744 +ENDPROC(irq_entries_start)
15745
15746 .previous
15747 END(interrupt)
15748 @@ -789,6 +1090,16 @@ END(interrupt)
15749 subq $ORIG_RAX-RBP, %rsp
15750 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15751 SAVE_ARGS_IRQ
15752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15753 + testb $3, CS(%rdi)
15754 + jnz 1f
15755 + pax_enter_kernel
15756 + jmp 2f
15757 +1: pax_enter_kernel_user
15758 +2:
15759 +#else
15760 + pax_enter_kernel
15761 +#endif
15762 call \func
15763 .endm
15764
15765 @@ -820,7 +1131,7 @@ ret_from_intr:
15766
15767 exit_intr:
15768 GET_THREAD_INFO(%rcx)
15769 - testl $3,CS-ARGOFFSET(%rsp)
15770 + testb $3,CS-ARGOFFSET(%rsp)
15771 je retint_kernel
15772
15773 /* Interrupt came from user space */
15774 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
15775 * The iretq could re-enable interrupts:
15776 */
15777 DISABLE_INTERRUPTS(CLBR_ANY)
15778 + pax_exit_kernel_user
15779 TRACE_IRQS_IRETQ
15780 SWAPGS
15781 jmp restore_args
15782
15783 retint_restore_args: /* return to kernel space */
15784 DISABLE_INTERRUPTS(CLBR_ANY)
15785 + pax_exit_kernel
15786 + pax_force_retaddr RIP-ARGOFFSET
15787 /*
15788 * The iretq could re-enable interrupts:
15789 */
15790 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
15791 #endif
15792
15793 CFI_ENDPROC
15794 -END(common_interrupt)
15795 +ENDPROC(common_interrupt)
15796 /*
15797 * End of kprobes section
15798 */
15799 @@ -953,7 +1267,7 @@ ENTRY(\sym)
15800 interrupt \do_sym
15801 jmp ret_from_intr
15802 CFI_ENDPROC
15803 -END(\sym)
15804 +ENDPROC(\sym)
15805 .endm
15806
15807 #ifdef CONFIG_SMP
15808 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
15809 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15810 call error_entry
15811 DEFAULT_FRAME 0
15812 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15813 + testb $3, CS(%rsp)
15814 + jnz 1f
15815 + pax_enter_kernel
15816 + jmp 2f
15817 +1: pax_enter_kernel_user
15818 +2:
15819 +#else
15820 + pax_enter_kernel
15821 +#endif
15822 movq %rsp,%rdi /* pt_regs pointer */
15823 xorl %esi,%esi /* no error code */
15824 call \do_sym
15825 jmp error_exit /* %ebx: no swapgs flag */
15826 CFI_ENDPROC
15827 -END(\sym)
15828 +ENDPROC(\sym)
15829 .endm
15830
15831 .macro paranoidzeroentry sym do_sym
15832 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
15833 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15834 call save_paranoid
15835 TRACE_IRQS_OFF
15836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15837 + testb $3, CS(%rsp)
15838 + jnz 1f
15839 + pax_enter_kernel
15840 + jmp 2f
15841 +1: pax_enter_kernel_user
15842 +2:
15843 +#else
15844 + pax_enter_kernel
15845 +#endif
15846 movq %rsp,%rdi /* pt_regs pointer */
15847 xorl %esi,%esi /* no error code */
15848 call \do_sym
15849 jmp paranoid_exit /* %ebx: no swapgs flag */
15850 CFI_ENDPROC
15851 -END(\sym)
15852 +ENDPROC(\sym)
15853 .endm
15854
15855 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15856 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15857 .macro paranoidzeroentry_ist sym do_sym ist
15858 ENTRY(\sym)
15859 INTR_FRAME
15860 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
15861 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15862 call save_paranoid
15863 TRACE_IRQS_OFF
15864 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15865 + testb $3, CS(%rsp)
15866 + jnz 1f
15867 + pax_enter_kernel
15868 + jmp 2f
15869 +1: pax_enter_kernel_user
15870 +2:
15871 +#else
15872 + pax_enter_kernel
15873 +#endif
15874 movq %rsp,%rdi /* pt_regs pointer */
15875 xorl %esi,%esi /* no error code */
15876 +#ifdef CONFIG_SMP
15877 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15878 + lea init_tss(%r12), %r12
15879 +#else
15880 + lea init_tss(%rip), %r12
15881 +#endif
15882 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15883 call \do_sym
15884 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15885 jmp paranoid_exit /* %ebx: no swapgs flag */
15886 CFI_ENDPROC
15887 -END(\sym)
15888 +ENDPROC(\sym)
15889 .endm
15890
15891 .macro errorentry sym do_sym
15892 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
15893 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15894 call error_entry
15895 DEFAULT_FRAME 0
15896 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15897 + testb $3, CS(%rsp)
15898 + jnz 1f
15899 + pax_enter_kernel
15900 + jmp 2f
15901 +1: pax_enter_kernel_user
15902 +2:
15903 +#else
15904 + pax_enter_kernel
15905 +#endif
15906 movq %rsp,%rdi /* pt_regs pointer */
15907 movq ORIG_RAX(%rsp),%rsi /* get error code */
15908 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15909 call \do_sym
15910 jmp error_exit /* %ebx: no swapgs flag */
15911 CFI_ENDPROC
15912 -END(\sym)
15913 +ENDPROC(\sym)
15914 .endm
15915
15916 /* error code is on the stack already */
15917 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
15918 call save_paranoid
15919 DEFAULT_FRAME 0
15920 TRACE_IRQS_OFF
15921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15922 + testb $3, CS(%rsp)
15923 + jnz 1f
15924 + pax_enter_kernel
15925 + jmp 2f
15926 +1: pax_enter_kernel_user
15927 +2:
15928 +#else
15929 + pax_enter_kernel
15930 +#endif
15931 movq %rsp,%rdi /* pt_regs pointer */
15932 movq ORIG_RAX(%rsp),%rsi /* get error code */
15933 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15934 call \do_sym
15935 jmp paranoid_exit /* %ebx: no swapgs flag */
15936 CFI_ENDPROC
15937 -END(\sym)
15938 +ENDPROC(\sym)
15939 .endm
15940
15941 zeroentry divide_error do_divide_error
15942 @@ -1134,9 +1504,10 @@ gs_change:
15943 2: mfence /* workaround */
15944 SWAPGS
15945 popfq_cfi
15946 + pax_force_retaddr
15947 ret
15948 CFI_ENDPROC
15949 -END(native_load_gs_index)
15950 +ENDPROC(native_load_gs_index)
15951
15952 .section __ex_table,"a"
15953 .align 8
15954 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
15955 * Here we are in the child and the registers are set as they were
15956 * at kernel_thread() invocation in the parent.
15957 */
15958 + pax_force_fptr %rsi
15959 call *%rsi
15960 # exit
15961 mov %eax, %edi
15962 call do_exit
15963 ud2 # padding for call trace
15964 CFI_ENDPROC
15965 -END(kernel_thread_helper)
15966 +ENDPROC(kernel_thread_helper)
15967
15968 /*
15969 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15970 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
15971 RESTORE_REST
15972 testq %rax,%rax
15973 je int_ret_from_sys_call
15974 - RESTORE_ARGS
15975 UNFAKE_STACK_FRAME
15976 + pax_force_retaddr
15977 ret
15978 CFI_ENDPROC
15979 -END(kernel_execve)
15980 +ENDPROC(kernel_execve)
15981
15982 /* Call softirq on interrupt stack. Interrupts are off. */
15983 ENTRY(call_softirq)
15984 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
15985 CFI_DEF_CFA_REGISTER rsp
15986 CFI_ADJUST_CFA_OFFSET -8
15987 decl PER_CPU_VAR(irq_count)
15988 + pax_force_retaddr
15989 ret
15990 CFI_ENDPROC
15991 -END(call_softirq)
15992 +ENDPROC(call_softirq)
15993
15994 #ifdef CONFIG_XEN
15995 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
15996 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
15997 decl PER_CPU_VAR(irq_count)
15998 jmp error_exit
15999 CFI_ENDPROC
16000 -END(xen_do_hypervisor_callback)
16001 +ENDPROC(xen_do_hypervisor_callback)
16002
16003 /*
16004 * Hypervisor uses this for application faults while it executes.
16005 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16006 SAVE_ALL
16007 jmp error_exit
16008 CFI_ENDPROC
16009 -END(xen_failsafe_callback)
16010 +ENDPROC(xen_failsafe_callback)
16011
16012 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16013 xen_hvm_callback_vector xen_evtchn_do_upcall
16014 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16015 TRACE_IRQS_OFF
16016 testl %ebx,%ebx /* swapgs needed? */
16017 jnz paranoid_restore
16018 - testl $3,CS(%rsp)
16019 + testb $3,CS(%rsp)
16020 jnz paranoid_userspace
16021 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16022 + pax_exit_kernel
16023 + TRACE_IRQS_IRETQ 0
16024 + SWAPGS_UNSAFE_STACK
16025 + RESTORE_ALL 8
16026 + pax_force_retaddr_bts
16027 + jmp irq_return
16028 +#endif
16029 paranoid_swapgs:
16030 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16031 + pax_exit_kernel_user
16032 +#else
16033 + pax_exit_kernel
16034 +#endif
16035 TRACE_IRQS_IRETQ 0
16036 SWAPGS_UNSAFE_STACK
16037 RESTORE_ALL 8
16038 jmp irq_return
16039 paranoid_restore:
16040 + pax_exit_kernel
16041 TRACE_IRQS_IRETQ 0
16042 RESTORE_ALL 8
16043 + pax_force_retaddr_bts
16044 jmp irq_return
16045 paranoid_userspace:
16046 GET_THREAD_INFO(%rcx)
16047 @@ -1399,7 +1787,7 @@ paranoid_schedule:
16048 TRACE_IRQS_OFF
16049 jmp paranoid_userspace
16050 CFI_ENDPROC
16051 -END(paranoid_exit)
16052 +ENDPROC(paranoid_exit)
16053
16054 /*
16055 * Exception entry point. This expects an error code/orig_rax on the stack.
16056 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16057 movq_cfi r14, R14+8
16058 movq_cfi r15, R15+8
16059 xorl %ebx,%ebx
16060 - testl $3,CS+8(%rsp)
16061 + testb $3,CS+8(%rsp)
16062 je error_kernelspace
16063 error_swapgs:
16064 SWAPGS
16065 error_sti:
16066 TRACE_IRQS_OFF
16067 + pax_force_retaddr_bts
16068 ret
16069
16070 /*
16071 @@ -1458,7 +1847,7 @@ bstep_iret:
16072 movq %rcx,RIP+8(%rsp)
16073 jmp error_swapgs
16074 CFI_ENDPROC
16075 -END(error_entry)
16076 +ENDPROC(error_entry)
16077
16078
16079 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16080 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16081 jnz retint_careful
16082 jmp retint_swapgs
16083 CFI_ENDPROC
16084 -END(error_exit)
16085 +ENDPROC(error_exit)
16086
16087 /*
16088 * Test if a given stack is an NMI stack or not.
16089 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
16090 * If %cs was not the kernel segment, then the NMI triggered in user
16091 * space, which means it is definitely not nested.
16092 */
16093 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16094 + je 1f
16095 cmpl $__KERNEL_CS, 16(%rsp)
16096 jne first_nmi
16097 -
16098 +1:
16099 /*
16100 * Check the special variable on the stack to see if NMIs are
16101 * executing.
16102 @@ -1659,6 +2050,16 @@ restart_nmi:
16103 */
16104 call save_paranoid
16105 DEFAULT_FRAME 0
16106 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16107 + testb $3, CS(%rsp)
16108 + jnz 1f
16109 + pax_enter_kernel
16110 + jmp 2f
16111 +1: pax_enter_kernel_user
16112 +2:
16113 +#else
16114 + pax_enter_kernel
16115 +#endif
16116 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16117 movq %rsp,%rdi
16118 movq $-1,%rsi
16119 @@ -1666,14 +2067,25 @@ restart_nmi:
16120 testl %ebx,%ebx /* swapgs needed? */
16121 jnz nmi_restore
16122 nmi_swapgs:
16123 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16124 + pax_exit_kernel_user
16125 +#else
16126 + pax_exit_kernel
16127 +#endif
16128 SWAPGS_UNSAFE_STACK
16129 + RESTORE_ALL 8
16130 + /* Clear the NMI executing stack variable */
16131 + movq $0, 10*8(%rsp)
16132 + jmp irq_return
16133 nmi_restore:
16134 + pax_exit_kernel
16135 RESTORE_ALL 8
16136 + pax_force_retaddr_bts
16137 /* Clear the NMI executing stack variable */
16138 movq $0, 10*8(%rsp)
16139 jmp irq_return
16140 CFI_ENDPROC
16141 -END(nmi)
16142 +ENDPROC(nmi)
16143
16144 /*
16145 * If an NMI hit an iret because of an exception or breakpoint,
16146 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16147 mov $-ENOSYS,%eax
16148 sysret
16149 CFI_ENDPROC
16150 -END(ignore_sysret)
16151 +ENDPROC(ignore_sysret)
16152
16153 /*
16154 * End of kprobes section
16155 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16156 index c9a281f..ce2f317 100644
16157 --- a/arch/x86/kernel/ftrace.c
16158 +++ b/arch/x86/kernel/ftrace.c
16159 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16160 static const void *mod_code_newcode; /* holds the text to write to the IP */
16161
16162 static unsigned nmi_wait_count;
16163 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16164 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16165
16166 int ftrace_arch_read_dyn_info(char *buf, int size)
16167 {
16168 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16169
16170 r = snprintf(buf, size, "%u %u",
16171 nmi_wait_count,
16172 - atomic_read(&nmi_update_count));
16173 + atomic_read_unchecked(&nmi_update_count));
16174 return r;
16175 }
16176
16177 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16178
16179 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16180 smp_rmb();
16181 + pax_open_kernel();
16182 ftrace_mod_code();
16183 - atomic_inc(&nmi_update_count);
16184 + pax_close_kernel();
16185 + atomic_inc_unchecked(&nmi_update_count);
16186 }
16187 /* Must have previous changes seen before executions */
16188 smp_mb();
16189 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16190 {
16191 unsigned char replaced[MCOUNT_INSN_SIZE];
16192
16193 + ip = ktla_ktva(ip);
16194 +
16195 /*
16196 * Note: Due to modules and __init, code can
16197 * disappear and change, we need to protect against faulting
16198 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16199 unsigned char old[MCOUNT_INSN_SIZE], *new;
16200 int ret;
16201
16202 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16203 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16204 new = ftrace_call_replace(ip, (unsigned long)func);
16205 ret = ftrace_modify_code(ip, old, new);
16206
16207 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16208 {
16209 unsigned char code[MCOUNT_INSN_SIZE];
16210
16211 + ip = ktla_ktva(ip);
16212 +
16213 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16214 return -EFAULT;
16215
16216 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16217 index 51ff186..9e77418 100644
16218 --- a/arch/x86/kernel/head32.c
16219 +++ b/arch/x86/kernel/head32.c
16220 @@ -19,6 +19,7 @@
16221 #include <asm/io_apic.h>
16222 #include <asm/bios_ebda.h>
16223 #include <asm/tlbflush.h>
16224 +#include <asm/boot.h>
16225
16226 static void __init i386_default_early_setup(void)
16227 {
16228 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16229
16230 void __init i386_start_kernel(void)
16231 {
16232 - memblock_reserve(__pa_symbol(&_text),
16233 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16234 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16235
16236 #ifdef CONFIG_BLK_DEV_INITRD
16237 /* Reserve INITRD */
16238 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16239 index ce0be7c..c41476e 100644
16240 --- a/arch/x86/kernel/head_32.S
16241 +++ b/arch/x86/kernel/head_32.S
16242 @@ -25,6 +25,12 @@
16243 /* Physical address */
16244 #define pa(X) ((X) - __PAGE_OFFSET)
16245
16246 +#ifdef CONFIG_PAX_KERNEXEC
16247 +#define ta(X) (X)
16248 +#else
16249 +#define ta(X) ((X) - __PAGE_OFFSET)
16250 +#endif
16251 +
16252 /*
16253 * References to members of the new_cpu_data structure.
16254 */
16255 @@ -54,11 +60,7 @@
16256 * and small than max_low_pfn, otherwise will waste some page table entries
16257 */
16258
16259 -#if PTRS_PER_PMD > 1
16260 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16261 -#else
16262 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16263 -#endif
16264 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16265
16266 /* Number of possible pages in the lowmem region */
16267 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16268 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16269 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16270
16271 /*
16272 + * Real beginning of normal "text" segment
16273 + */
16274 +ENTRY(stext)
16275 +ENTRY(_stext)
16276 +
16277 +/*
16278 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16279 * %esi points to the real-mode code as a 32-bit pointer.
16280 * CS and DS must be 4 GB flat segments, but we don't depend on
16281 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16282 * can.
16283 */
16284 __HEAD
16285 +
16286 +#ifdef CONFIG_PAX_KERNEXEC
16287 + jmp startup_32
16288 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16289 +.fill PAGE_SIZE-5,1,0xcc
16290 +#endif
16291 +
16292 ENTRY(startup_32)
16293 movl pa(stack_start),%ecx
16294
16295 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16296 2:
16297 leal -__PAGE_OFFSET(%ecx),%esp
16298
16299 +#ifdef CONFIG_SMP
16300 + movl $pa(cpu_gdt_table),%edi
16301 + movl $__per_cpu_load,%eax
16302 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16303 + rorl $16,%eax
16304 + movb %al,__KERNEL_PERCPU + 4(%edi)
16305 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16306 + movl $__per_cpu_end - 1,%eax
16307 + subl $__per_cpu_start,%eax
16308 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16309 +#endif
16310 +
16311 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16312 + movl $NR_CPUS,%ecx
16313 + movl $pa(cpu_gdt_table),%edi
16314 +1:
16315 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16316 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16317 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16318 + addl $PAGE_SIZE_asm,%edi
16319 + loop 1b
16320 +#endif
16321 +
16322 +#ifdef CONFIG_PAX_KERNEXEC
16323 + movl $pa(boot_gdt),%edi
16324 + movl $__LOAD_PHYSICAL_ADDR,%eax
16325 + movw %ax,__BOOT_CS + 2(%edi)
16326 + rorl $16,%eax
16327 + movb %al,__BOOT_CS + 4(%edi)
16328 + movb %ah,__BOOT_CS + 7(%edi)
16329 + rorl $16,%eax
16330 +
16331 + ljmp $(__BOOT_CS),$1f
16332 +1:
16333 +
16334 + movl $NR_CPUS,%ecx
16335 + movl $pa(cpu_gdt_table),%edi
16336 + addl $__PAGE_OFFSET,%eax
16337 +1:
16338 + movw %ax,__KERNEL_CS + 2(%edi)
16339 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16340 + rorl $16,%eax
16341 + movb %al,__KERNEL_CS + 4(%edi)
16342 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16343 + movb %ah,__KERNEL_CS + 7(%edi)
16344 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16345 + rorl $16,%eax
16346 + addl $PAGE_SIZE_asm,%edi
16347 + loop 1b
16348 +#endif
16349 +
16350 /*
16351 * Clear BSS first so that there are no surprises...
16352 */
16353 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16354 movl %eax, pa(max_pfn_mapped)
16355
16356 /* Do early initialization of the fixmap area */
16357 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16358 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16359 +#ifdef CONFIG_COMPAT_VDSO
16360 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16361 +#else
16362 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16363 +#endif
16364 #else /* Not PAE */
16365
16366 page_pde_offset = (__PAGE_OFFSET >> 20);
16367 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16368 movl %eax, pa(max_pfn_mapped)
16369
16370 /* Do early initialization of the fixmap area */
16371 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16372 - movl %eax,pa(initial_page_table+0xffc)
16373 +#ifdef CONFIG_COMPAT_VDSO
16374 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16375 +#else
16376 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16377 +#endif
16378 #endif
16379
16380 #ifdef CONFIG_PARAVIRT
16381 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16382 cmpl $num_subarch_entries, %eax
16383 jae bad_subarch
16384
16385 - movl pa(subarch_entries)(,%eax,4), %eax
16386 - subl $__PAGE_OFFSET, %eax
16387 - jmp *%eax
16388 + jmp *pa(subarch_entries)(,%eax,4)
16389
16390 bad_subarch:
16391 WEAK(lguest_entry)
16392 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16393 __INITDATA
16394
16395 subarch_entries:
16396 - .long default_entry /* normal x86/PC */
16397 - .long lguest_entry /* lguest hypervisor */
16398 - .long xen_entry /* Xen hypervisor */
16399 - .long default_entry /* Moorestown MID */
16400 + .long ta(default_entry) /* normal x86/PC */
16401 + .long ta(lguest_entry) /* lguest hypervisor */
16402 + .long ta(xen_entry) /* Xen hypervisor */
16403 + .long ta(default_entry) /* Moorestown MID */
16404 num_subarch_entries = (. - subarch_entries) / 4
16405 .previous
16406 #else
16407 @@ -312,6 +382,7 @@ default_entry:
16408 orl %edx,%eax
16409 movl %eax,%cr4
16410
16411 +#ifdef CONFIG_X86_PAE
16412 testb $X86_CR4_PAE, %al # check if PAE is enabled
16413 jz 6f
16414
16415 @@ -340,6 +411,9 @@ default_entry:
16416 /* Make changes effective */
16417 wrmsr
16418
16419 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16420 +#endif
16421 +
16422 6:
16423
16424 /*
16425 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16426 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16427 movl %eax,%ss # after changing gdt.
16428
16429 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16430 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16431 movl %eax,%ds
16432 movl %eax,%es
16433
16434 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16435 */
16436 cmpb $0,ready
16437 jne 1f
16438 - movl $gdt_page,%eax
16439 + movl $cpu_gdt_table,%eax
16440 movl $stack_canary,%ecx
16441 +#ifdef CONFIG_SMP
16442 + addl $__per_cpu_load,%ecx
16443 +#endif
16444 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16445 shrl $16, %ecx
16446 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16447 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16448 1:
16449 -#endif
16450 movl $(__KERNEL_STACK_CANARY),%eax
16451 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16452 + movl $(__USER_DS),%eax
16453 +#else
16454 + xorl %eax,%eax
16455 +#endif
16456 movl %eax,%gs
16457
16458 xorl %eax,%eax # Clear LDT
16459 @@ -558,22 +639,22 @@ early_page_fault:
16460 jmp early_fault
16461
16462 early_fault:
16463 - cld
16464 #ifdef CONFIG_PRINTK
16465 + cmpl $1,%ss:early_recursion_flag
16466 + je hlt_loop
16467 + incl %ss:early_recursion_flag
16468 + cld
16469 pusha
16470 movl $(__KERNEL_DS),%eax
16471 movl %eax,%ds
16472 movl %eax,%es
16473 - cmpl $2,early_recursion_flag
16474 - je hlt_loop
16475 - incl early_recursion_flag
16476 movl %cr2,%eax
16477 pushl %eax
16478 pushl %edx /* trapno */
16479 pushl $fault_msg
16480 call printk
16481 +; call dump_stack
16482 #endif
16483 - call dump_stack
16484 hlt_loop:
16485 hlt
16486 jmp hlt_loop
16487 @@ -581,8 +662,11 @@ hlt_loop:
16488 /* This is the default interrupt "handler" :-) */
16489 ALIGN
16490 ignore_int:
16491 - cld
16492 #ifdef CONFIG_PRINTK
16493 + cmpl $2,%ss:early_recursion_flag
16494 + je hlt_loop
16495 + incl %ss:early_recursion_flag
16496 + cld
16497 pushl %eax
16498 pushl %ecx
16499 pushl %edx
16500 @@ -591,9 +675,6 @@ ignore_int:
16501 movl $(__KERNEL_DS),%eax
16502 movl %eax,%ds
16503 movl %eax,%es
16504 - cmpl $2,early_recursion_flag
16505 - je hlt_loop
16506 - incl early_recursion_flag
16507 pushl 16(%esp)
16508 pushl 24(%esp)
16509 pushl 32(%esp)
16510 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16511 /*
16512 * BSS section
16513 */
16514 -__PAGE_ALIGNED_BSS
16515 - .align PAGE_SIZE
16516 #ifdef CONFIG_X86_PAE
16517 +.section .initial_pg_pmd,"a",@progbits
16518 initial_pg_pmd:
16519 .fill 1024*KPMDS,4,0
16520 #else
16521 +.section .initial_page_table,"a",@progbits
16522 ENTRY(initial_page_table)
16523 .fill 1024,4,0
16524 #endif
16525 +.section .initial_pg_fixmap,"a",@progbits
16526 initial_pg_fixmap:
16527 .fill 1024,4,0
16528 +.section .empty_zero_page,"a",@progbits
16529 ENTRY(empty_zero_page)
16530 .fill 4096,1,0
16531 +.section .swapper_pg_dir,"a",@progbits
16532 ENTRY(swapper_pg_dir)
16533 +#ifdef CONFIG_X86_PAE
16534 + .fill 4,8,0
16535 +#else
16536 .fill 1024,4,0
16537 +#endif
16538 +
16539 +/*
16540 + * The IDT has to be page-aligned to simplify the Pentium
16541 + * F0 0F bug workaround.. We have a special link segment
16542 + * for this.
16543 + */
16544 +.section .idt,"a",@progbits
16545 +ENTRY(idt_table)
16546 + .fill 256,8,0
16547
16548 /*
16549 * This starts the data section.
16550 */
16551 #ifdef CONFIG_X86_PAE
16552 -__PAGE_ALIGNED_DATA
16553 - /* Page-aligned for the benefit of paravirt? */
16554 - .align PAGE_SIZE
16555 +.section .initial_page_table,"a",@progbits
16556 ENTRY(initial_page_table)
16557 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16558 # if KPMDS == 3
16559 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16560 # error "Kernel PMDs should be 1, 2 or 3"
16561 # endif
16562 .align PAGE_SIZE /* needs to be page-sized too */
16563 +
16564 +#ifdef CONFIG_PAX_PER_CPU_PGD
16565 +ENTRY(cpu_pgd)
16566 + .rept NR_CPUS
16567 + .fill 4,8,0
16568 + .endr
16569 +#endif
16570 +
16571 #endif
16572
16573 .data
16574 .balign 4
16575 ENTRY(stack_start)
16576 - .long init_thread_union+THREAD_SIZE
16577 + .long init_thread_union+THREAD_SIZE-8
16578
16579 +ready: .byte 0
16580 +
16581 +.section .rodata,"a",@progbits
16582 early_recursion_flag:
16583 .long 0
16584
16585 -ready: .byte 0
16586 -
16587 int_msg:
16588 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16589
16590 @@ -707,7 +811,7 @@ fault_msg:
16591 .word 0 # 32 bit align gdt_desc.address
16592 boot_gdt_descr:
16593 .word __BOOT_DS+7
16594 - .long boot_gdt - __PAGE_OFFSET
16595 + .long pa(boot_gdt)
16596
16597 .word 0 # 32-bit align idt_desc.address
16598 idt_descr:
16599 @@ -718,7 +822,7 @@ idt_descr:
16600 .word 0 # 32 bit align gdt_desc.address
16601 ENTRY(early_gdt_descr)
16602 .word GDT_ENTRIES*8-1
16603 - .long gdt_page /* Overwritten for secondary CPUs */
16604 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16605
16606 /*
16607 * The boot_gdt must mirror the equivalent in setup.S and is
16608 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16609 .align L1_CACHE_BYTES
16610 ENTRY(boot_gdt)
16611 .fill GDT_ENTRY_BOOT_CS,8,0
16612 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16613 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16614 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16615 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16616 +
16617 + .align PAGE_SIZE_asm
16618 +ENTRY(cpu_gdt_table)
16619 + .rept NR_CPUS
16620 + .quad 0x0000000000000000 /* NULL descriptor */
16621 + .quad 0x0000000000000000 /* 0x0b reserved */
16622 + .quad 0x0000000000000000 /* 0x13 reserved */
16623 + .quad 0x0000000000000000 /* 0x1b reserved */
16624 +
16625 +#ifdef CONFIG_PAX_KERNEXEC
16626 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16627 +#else
16628 + .quad 0x0000000000000000 /* 0x20 unused */
16629 +#endif
16630 +
16631 + .quad 0x0000000000000000 /* 0x28 unused */
16632 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16633 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16634 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16635 + .quad 0x0000000000000000 /* 0x4b reserved */
16636 + .quad 0x0000000000000000 /* 0x53 reserved */
16637 + .quad 0x0000000000000000 /* 0x5b reserved */
16638 +
16639 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16640 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16641 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16642 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16643 +
16644 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16645 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16646 +
16647 + /*
16648 + * Segments used for calling PnP BIOS have byte granularity.
16649 + * The code segments and data segments have fixed 64k limits,
16650 + * the transfer segment sizes are set at run time.
16651 + */
16652 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16653 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16654 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16655 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16656 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16657 +
16658 + /*
16659 + * The APM segments have byte granularity and their bases
16660 + * are set at run time. All have 64k limits.
16661 + */
16662 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16663 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16664 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16665 +
16666 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16667 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16668 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16669 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16670 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16671 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16672 +
16673 + /* Be sure this is zeroed to avoid false validations in Xen */
16674 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16675 + .endr
16676 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16677 index 40f4eb3..6d24d9d 100644
16678 --- a/arch/x86/kernel/head_64.S
16679 +++ b/arch/x86/kernel/head_64.S
16680 @@ -19,6 +19,8 @@
16681 #include <asm/cache.h>
16682 #include <asm/processor-flags.h>
16683 #include <asm/percpu.h>
16684 +#include <asm/cpufeature.h>
16685 +#include <asm/alternative-asm.h>
16686
16687 #ifdef CONFIG_PARAVIRT
16688 #include <asm/asm-offsets.h>
16689 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16690 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16691 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16692 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16693 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16694 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16695 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16696 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16697 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16698 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16699
16700 .text
16701 __HEAD
16702 @@ -85,35 +93,23 @@ startup_64:
16703 */
16704 addq %rbp, init_level4_pgt + 0(%rip)
16705 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16706 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16707 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16708 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16709 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16710
16711 addq %rbp, level3_ident_pgt + 0(%rip)
16712 +#ifndef CONFIG_XEN
16713 + addq %rbp, level3_ident_pgt + 8(%rip)
16714 +#endif
16715
16716 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16717 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16718 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16719 +
16720 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16721 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16722
16723 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16724 -
16725 - /* Add an Identity mapping if I am above 1G */
16726 - leaq _text(%rip), %rdi
16727 - andq $PMD_PAGE_MASK, %rdi
16728 -
16729 - movq %rdi, %rax
16730 - shrq $PUD_SHIFT, %rax
16731 - andq $(PTRS_PER_PUD - 1), %rax
16732 - jz ident_complete
16733 -
16734 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16735 - leaq level3_ident_pgt(%rip), %rbx
16736 - movq %rdx, 0(%rbx, %rax, 8)
16737 -
16738 - movq %rdi, %rax
16739 - shrq $PMD_SHIFT, %rax
16740 - andq $(PTRS_PER_PMD - 1), %rax
16741 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16742 - leaq level2_spare_pgt(%rip), %rbx
16743 - movq %rdx, 0(%rbx, %rax, 8)
16744 -ident_complete:
16745 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16746
16747 /*
16748 * Fixup the kernel text+data virtual addresses. Note that
16749 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16750 * after the boot processor executes this code.
16751 */
16752
16753 - /* Enable PAE mode and PGE */
16754 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16755 + /* Enable PAE mode and PSE/PGE */
16756 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16757 movq %rax, %cr4
16758
16759 /* Setup early boot stage 4 level pagetables. */
16760 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16761 movl $MSR_EFER, %ecx
16762 rdmsr
16763 btsl $_EFER_SCE, %eax /* Enable System Call */
16764 - btl $20,%edi /* No Execute supported? */
16765 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16766 jnc 1f
16767 btsl $_EFER_NX, %eax
16768 + leaq init_level4_pgt(%rip), %rdi
16769 +#ifndef CONFIG_EFI
16770 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16771 +#endif
16772 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16773 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16774 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16775 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16776 1: wrmsr /* Make changes effective */
16777
16778 /* Setup cr0 */
16779 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16780 * jump. In addition we need to ensure %cs is set so we make this
16781 * a far return.
16782 */
16783 + pax_set_fptr_mask
16784 movq initial_code(%rip),%rax
16785 pushq $0 # fake return address to stop unwinder
16786 pushq $__KERNEL_CS # set correct cs
16787 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16788 bad_address:
16789 jmp bad_address
16790
16791 - .section ".init.text","ax"
16792 + __INIT
16793 #ifdef CONFIG_EARLY_PRINTK
16794 .globl early_idt_handlers
16795 early_idt_handlers:
16796 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16797 #endif /* EARLY_PRINTK */
16798 1: hlt
16799 jmp 1b
16800 + .previous
16801
16802 #ifdef CONFIG_EARLY_PRINTK
16803 + __INITDATA
16804 early_recursion_flag:
16805 .long 0
16806 + .previous
16807
16808 + .section .rodata,"a",@progbits
16809 early_idt_msg:
16810 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16811 early_idt_ripmsg:
16812 .asciz "RIP %s\n"
16813 + .previous
16814 #endif /* CONFIG_EARLY_PRINTK */
16815 - .previous
16816
16817 + .section .rodata,"a",@progbits
16818 #define NEXT_PAGE(name) \
16819 .balign PAGE_SIZE; \
16820 ENTRY(name)
16821 @@ -338,7 +348,6 @@ ENTRY(name)
16822 i = i + 1 ; \
16823 .endr
16824
16825 - .data
16826 /*
16827 * This default setting generates an ident mapping at address 0x100000
16828 * and a mapping for the kernel that precisely maps virtual address
16829 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16830 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16831 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16832 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16833 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16834 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16835 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16836 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16837 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16838 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16839 .org init_level4_pgt + L4_START_KERNEL*8, 0
16840 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16841 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16842
16843 +#ifdef CONFIG_PAX_PER_CPU_PGD
16844 +NEXT_PAGE(cpu_pgd)
16845 + .rept NR_CPUS
16846 + .fill 512,8,0
16847 + .endr
16848 +#endif
16849 +
16850 NEXT_PAGE(level3_ident_pgt)
16851 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16852 +#ifdef CONFIG_XEN
16853 .fill 511,8,0
16854 +#else
16855 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16856 + .fill 510,8,0
16857 +#endif
16858 +
16859 +NEXT_PAGE(level3_vmalloc_start_pgt)
16860 + .fill 512,8,0
16861 +
16862 +NEXT_PAGE(level3_vmalloc_end_pgt)
16863 + .fill 512,8,0
16864 +
16865 +NEXT_PAGE(level3_vmemmap_pgt)
16866 + .fill L3_VMEMMAP_START,8,0
16867 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16868
16869 NEXT_PAGE(level3_kernel_pgt)
16870 .fill L3_START_KERNEL,8,0
16871 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16872 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16873 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16874
16875 +NEXT_PAGE(level2_vmemmap_pgt)
16876 + .fill 512,8,0
16877 +
16878 NEXT_PAGE(level2_fixmap_pgt)
16879 - .fill 506,8,0
16880 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16881 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16882 - .fill 5,8,0
16883 + .fill 507,8,0
16884 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16885 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16886 + .fill 4,8,0
16887
16888 -NEXT_PAGE(level1_fixmap_pgt)
16889 +NEXT_PAGE(level1_vsyscall_pgt)
16890 .fill 512,8,0
16891
16892 -NEXT_PAGE(level2_ident_pgt)
16893 - /* Since I easily can, map the first 1G.
16894 + /* Since I easily can, map the first 2G.
16895 * Don't set NX because code runs from these pages.
16896 */
16897 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16898 +NEXT_PAGE(level2_ident_pgt)
16899 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16900
16901 NEXT_PAGE(level2_kernel_pgt)
16902 /*
16903 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
16904 * If you want to increase this then increase MODULES_VADDR
16905 * too.)
16906 */
16907 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16908 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16909 -
16910 -NEXT_PAGE(level2_spare_pgt)
16911 - .fill 512, 8, 0
16912 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16913
16914 #undef PMDS
16915 #undef NEXT_PAGE
16916
16917 - .data
16918 + .align PAGE_SIZE
16919 +ENTRY(cpu_gdt_table)
16920 + .rept NR_CPUS
16921 + .quad 0x0000000000000000 /* NULL descriptor */
16922 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16923 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16924 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16925 + .quad 0x00cffb000000ffff /* __USER32_CS */
16926 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16927 + .quad 0x00affb000000ffff /* __USER_CS */
16928 +
16929 +#ifdef CONFIG_PAX_KERNEXEC
16930 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16931 +#else
16932 + .quad 0x0 /* unused */
16933 +#endif
16934 +
16935 + .quad 0,0 /* TSS */
16936 + .quad 0,0 /* LDT */
16937 + .quad 0,0,0 /* three TLS descriptors */
16938 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16939 + /* asm/segment.h:GDT_ENTRIES must match this */
16940 +
16941 + /* zero the remaining page */
16942 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16943 + .endr
16944 +
16945 .align 16
16946 .globl early_gdt_descr
16947 early_gdt_descr:
16948 .word GDT_ENTRIES*8-1
16949 early_gdt_descr_base:
16950 - .quad INIT_PER_CPU_VAR(gdt_page)
16951 + .quad cpu_gdt_table
16952
16953 ENTRY(phys_base)
16954 /* This must match the first entry in level2_kernel_pgt */
16955 .quad 0x0000000000000000
16956
16957 #include "../../x86/xen/xen-head.S"
16958 -
16959 - .section .bss, "aw", @nobits
16960 +
16961 + .section .rodata,"a",@progbits
16962 .align L1_CACHE_BYTES
16963 ENTRY(idt_table)
16964 - .skip IDT_ENTRIES * 16
16965 + .fill 512,8,0
16966
16967 .align L1_CACHE_BYTES
16968 ENTRY(nmi_idt_table)
16969 - .skip IDT_ENTRIES * 16
16970 + .fill 512,8,0
16971
16972 __PAGE_ALIGNED_BSS
16973 .align PAGE_SIZE
16974 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16975 index 9c3bd4a..e1d9b35 100644
16976 --- a/arch/x86/kernel/i386_ksyms_32.c
16977 +++ b/arch/x86/kernel/i386_ksyms_32.c
16978 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16979 EXPORT_SYMBOL(cmpxchg8b_emu);
16980 #endif
16981
16982 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
16983 +
16984 /* Networking helper routines. */
16985 EXPORT_SYMBOL(csum_partial_copy_generic);
16986 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16987 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16988
16989 EXPORT_SYMBOL(__get_user_1);
16990 EXPORT_SYMBOL(__get_user_2);
16991 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
16992
16993 EXPORT_SYMBOL(csum_partial);
16994 EXPORT_SYMBOL(empty_zero_page);
16995 +
16996 +#ifdef CONFIG_PAX_KERNEXEC
16997 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
16998 +#endif
16999 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17000 index 739d859..d1d6be7 100644
17001 --- a/arch/x86/kernel/i387.c
17002 +++ b/arch/x86/kernel/i387.c
17003 @@ -188,6 +188,9 @@ int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
17004
17005 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17006 unsigned int pos, unsigned int count,
17007 + void *kbuf, void __user *ubuf) __size_overflow(4);
17008 +int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17009 + unsigned int pos, unsigned int count,
17010 void *kbuf, void __user *ubuf)
17011 {
17012 int ret;
17013 @@ -207,6 +210,9 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17014
17015 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17016 unsigned int pos, unsigned int count,
17017 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17018 +int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17019 + unsigned int pos, unsigned int count,
17020 const void *kbuf, const void __user *ubuf)
17021 {
17022 int ret;
17023 @@ -240,6 +246,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17024
17025 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17026 unsigned int pos, unsigned int count,
17027 + void *kbuf, void __user *ubuf) __size_overflow(4);
17028 +int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17029 + unsigned int pos, unsigned int count,
17030 void *kbuf, void __user *ubuf)
17031 {
17032 int ret;
17033 @@ -269,6 +278,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17034
17035 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17036 unsigned int pos, unsigned int count,
17037 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17038 +int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17039 + unsigned int pos, unsigned int count,
17040 const void *kbuf, const void __user *ubuf)
17041 {
17042 int ret;
17043 @@ -439,6 +451,9 @@ static void convert_to_fxsr(struct task_struct *tsk,
17044
17045 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17046 unsigned int pos, unsigned int count,
17047 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
17048 +int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17049 + unsigned int pos, unsigned int count,
17050 void *kbuf, void __user *ubuf)
17051 {
17052 struct user_i387_ia32_struct env;
17053 @@ -471,6 +486,9 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17054
17055 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17056 unsigned int pos, unsigned int count,
17057 + const void *kbuf, const void __user *ubuf) __size_overflow(3,4);
17058 +int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17059 + unsigned int pos, unsigned int count,
17060 const void *kbuf, const void __user *ubuf)
17061 {
17062 struct user_i387_ia32_struct env;
17063 @@ -619,6 +637,8 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
17064 }
17065
17066 static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17067 + unsigned int size) __size_overflow(2);
17068 +static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17069 unsigned int size)
17070 {
17071 struct task_struct *tsk = current;
17072 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17073 index 6104852..6114160 100644
17074 --- a/arch/x86/kernel/i8259.c
17075 +++ b/arch/x86/kernel/i8259.c
17076 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17077 "spurious 8259A interrupt: IRQ%d.\n", irq);
17078 spurious_irq_mask |= irqmask;
17079 }
17080 - atomic_inc(&irq_err_count);
17081 + atomic_inc_unchecked(&irq_err_count);
17082 /*
17083 * Theoretically we do not have to handle this IRQ,
17084 * but in Linux this does not cause problems and is
17085 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17086 index 43e9ccf..44ccf6f 100644
17087 --- a/arch/x86/kernel/init_task.c
17088 +++ b/arch/x86/kernel/init_task.c
17089 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17090 * way process stacks are handled. This is done by having a special
17091 * "init_task" linker map entry..
17092 */
17093 -union thread_union init_thread_union __init_task_data =
17094 - { INIT_THREAD_INFO(init_task) };
17095 +union thread_union init_thread_union __init_task_data;
17096
17097 /*
17098 * Initial task structure.
17099 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17100 * section. Since TSS's are completely CPU-local, we want them
17101 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17102 */
17103 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17104 -
17105 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17106 +EXPORT_SYMBOL(init_tss);
17107 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17108 index 8c96897..be66bfa 100644
17109 --- a/arch/x86/kernel/ioport.c
17110 +++ b/arch/x86/kernel/ioport.c
17111 @@ -6,6 +6,7 @@
17112 #include <linux/sched.h>
17113 #include <linux/kernel.h>
17114 #include <linux/capability.h>
17115 +#include <linux/security.h>
17116 #include <linux/errno.h>
17117 #include <linux/types.h>
17118 #include <linux/ioport.h>
17119 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17120
17121 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17122 return -EINVAL;
17123 +#ifdef CONFIG_GRKERNSEC_IO
17124 + if (turn_on && grsec_disable_privio) {
17125 + gr_handle_ioperm();
17126 + return -EPERM;
17127 + }
17128 +#endif
17129 if (turn_on && !capable(CAP_SYS_RAWIO))
17130 return -EPERM;
17131
17132 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17133 * because the ->io_bitmap_max value must match the bitmap
17134 * contents:
17135 */
17136 - tss = &per_cpu(init_tss, get_cpu());
17137 + tss = init_tss + get_cpu();
17138
17139 if (turn_on)
17140 bitmap_clear(t->io_bitmap_ptr, from, num);
17141 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17142 return -EINVAL;
17143 /* Trying to gain more privileges? */
17144 if (level > old) {
17145 +#ifdef CONFIG_GRKERNSEC_IO
17146 + if (grsec_disable_privio) {
17147 + gr_handle_iopl();
17148 + return -EPERM;
17149 + }
17150 +#endif
17151 if (!capable(CAP_SYS_RAWIO))
17152 return -EPERM;
17153 }
17154 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17155 index 7943e0c..dd32c5c 100644
17156 --- a/arch/x86/kernel/irq.c
17157 +++ b/arch/x86/kernel/irq.c
17158 @@ -18,7 +18,7 @@
17159 #include <asm/mce.h>
17160 #include <asm/hw_irq.h>
17161
17162 -atomic_t irq_err_count;
17163 +atomic_unchecked_t irq_err_count;
17164
17165 /* Function pointer for generic interrupt vector handling */
17166 void (*x86_platform_ipi_callback)(void) = NULL;
17167 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17168 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17169 seq_printf(p, " Machine check polls\n");
17170 #endif
17171 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17172 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17173 #if defined(CONFIG_X86_IO_APIC)
17174 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17175 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17176 #endif
17177 return 0;
17178 }
17179 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17180
17181 u64 arch_irq_stat(void)
17182 {
17183 - u64 sum = atomic_read(&irq_err_count);
17184 + u64 sum = atomic_read_unchecked(&irq_err_count);
17185
17186 #ifdef CONFIG_X86_IO_APIC
17187 - sum += atomic_read(&irq_mis_count);
17188 + sum += atomic_read_unchecked(&irq_mis_count);
17189 #endif
17190 return sum;
17191 }
17192 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17193 index 40fc861..9b8739b 100644
17194 --- a/arch/x86/kernel/irq_32.c
17195 +++ b/arch/x86/kernel/irq_32.c
17196 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17197 __asm__ __volatile__("andl %%esp,%0" :
17198 "=r" (sp) : "0" (THREAD_SIZE - 1));
17199
17200 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17201 + return sp < STACK_WARN;
17202 }
17203
17204 static void print_stack_overflow(void)
17205 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17206 * per-CPU IRQ handling contexts (thread information and stack)
17207 */
17208 union irq_ctx {
17209 - struct thread_info tinfo;
17210 - u32 stack[THREAD_SIZE/sizeof(u32)];
17211 + unsigned long previous_esp;
17212 + u32 stack[THREAD_SIZE/sizeof(u32)];
17213 } __attribute__((aligned(THREAD_SIZE)));
17214
17215 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17216 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17217 static inline int
17218 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17219 {
17220 - union irq_ctx *curctx, *irqctx;
17221 + union irq_ctx *irqctx;
17222 u32 *isp, arg1, arg2;
17223
17224 - curctx = (union irq_ctx *) current_thread_info();
17225 irqctx = __this_cpu_read(hardirq_ctx);
17226
17227 /*
17228 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17229 * handler) we can't do that and just have to keep using the
17230 * current stack (which is the irq stack already after all)
17231 */
17232 - if (unlikely(curctx == irqctx))
17233 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17234 return 0;
17235
17236 /* build the stack frame on the IRQ stack */
17237 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17238 - irqctx->tinfo.task = curctx->tinfo.task;
17239 - irqctx->tinfo.previous_esp = current_stack_pointer;
17240 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17241 + irqctx->previous_esp = current_stack_pointer;
17242
17243 - /*
17244 - * Copy the softirq bits in preempt_count so that the
17245 - * softirq checks work in the hardirq context.
17246 - */
17247 - irqctx->tinfo.preempt_count =
17248 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17249 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17250 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17251 + __set_fs(MAKE_MM_SEG(0));
17252 +#endif
17253
17254 if (unlikely(overflow))
17255 call_on_stack(print_stack_overflow, isp);
17256 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17257 : "0" (irq), "1" (desc), "2" (isp),
17258 "D" (desc->handle_irq)
17259 : "memory", "cc", "ecx");
17260 +
17261 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17262 + __set_fs(current_thread_info()->addr_limit);
17263 +#endif
17264 +
17265 return 1;
17266 }
17267
17268 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17269 */
17270 void __cpuinit irq_ctx_init(int cpu)
17271 {
17272 - union irq_ctx *irqctx;
17273 -
17274 if (per_cpu(hardirq_ctx, cpu))
17275 return;
17276
17277 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17278 - THREAD_FLAGS,
17279 - THREAD_ORDER));
17280 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17281 - irqctx->tinfo.cpu = cpu;
17282 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17283 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17284 -
17285 - per_cpu(hardirq_ctx, cpu) = irqctx;
17286 -
17287 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17288 - THREAD_FLAGS,
17289 - THREAD_ORDER));
17290 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17291 - irqctx->tinfo.cpu = cpu;
17292 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17293 -
17294 - per_cpu(softirq_ctx, cpu) = irqctx;
17295 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17296 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17297
17298 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17299 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17300 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17301 asmlinkage void do_softirq(void)
17302 {
17303 unsigned long flags;
17304 - struct thread_info *curctx;
17305 union irq_ctx *irqctx;
17306 u32 *isp;
17307
17308 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17309 local_irq_save(flags);
17310
17311 if (local_softirq_pending()) {
17312 - curctx = current_thread_info();
17313 irqctx = __this_cpu_read(softirq_ctx);
17314 - irqctx->tinfo.task = curctx->task;
17315 - irqctx->tinfo.previous_esp = current_stack_pointer;
17316 + irqctx->previous_esp = current_stack_pointer;
17317
17318 /* build the stack frame on the softirq stack */
17319 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17320 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17321 +
17322 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17323 + __set_fs(MAKE_MM_SEG(0));
17324 +#endif
17325
17326 call_on_stack(__do_softirq, isp);
17327 +
17328 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17329 + __set_fs(current_thread_info()->addr_limit);
17330 +#endif
17331 +
17332 /*
17333 * Shouldn't happen, we returned above if in_interrupt():
17334 */
17335 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17336 index d04d3ec..ea4b374 100644
17337 --- a/arch/x86/kernel/irq_64.c
17338 +++ b/arch/x86/kernel/irq_64.c
17339 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17340 u64 estack_top, estack_bottom;
17341 u64 curbase = (u64)task_stack_page(current);
17342
17343 - if (user_mode_vm(regs))
17344 + if (user_mode(regs))
17345 return;
17346
17347 if (regs->sp >= curbase + sizeof(struct thread_info) +
17348 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17349 index 90fcf62..e682cdd 100644
17350 --- a/arch/x86/kernel/kdebugfs.c
17351 +++ b/arch/x86/kernel/kdebugfs.c
17352 @@ -28,6 +28,8 @@ struct setup_data_node {
17353 };
17354
17355 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17356 + size_t count, loff_t *ppos) __size_overflow(3);
17357 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17358 size_t count, loff_t *ppos)
17359 {
17360 struct setup_data_node *node = file->private_data;
17361 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17362 index 2f45c4c..d95504f 100644
17363 --- a/arch/x86/kernel/kgdb.c
17364 +++ b/arch/x86/kernel/kgdb.c
17365 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17366 #ifdef CONFIG_X86_32
17367 switch (regno) {
17368 case GDB_SS:
17369 - if (!user_mode_vm(regs))
17370 + if (!user_mode(regs))
17371 *(unsigned long *)mem = __KERNEL_DS;
17372 break;
17373 case GDB_SP:
17374 - if (!user_mode_vm(regs))
17375 + if (!user_mode(regs))
17376 *(unsigned long *)mem = kernel_stack_pointer(regs);
17377 break;
17378 case GDB_GS:
17379 @@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17380 case 'k':
17381 /* clear the trace bit */
17382 linux_regs->flags &= ~X86_EFLAGS_TF;
17383 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17384 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17385
17386 /* set the trace bit if we're stepping */
17387 if (remcomInBuffer[0] == 's') {
17388 linux_regs->flags |= X86_EFLAGS_TF;
17389 - atomic_set(&kgdb_cpu_doing_single_step,
17390 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17391 raw_smp_processor_id());
17392 }
17393
17394 @@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17395
17396 switch (cmd) {
17397 case DIE_DEBUG:
17398 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17399 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17400 if (user_mode(regs))
17401 return single_step_cont(regs, args);
17402 break;
17403 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17404 index 7da647d..56fe348 100644
17405 --- a/arch/x86/kernel/kprobes.c
17406 +++ b/arch/x86/kernel/kprobes.c
17407 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17408 } __attribute__((packed)) *insn;
17409
17410 insn = (struct __arch_relative_insn *)from;
17411 +
17412 + pax_open_kernel();
17413 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17414 insn->op = op;
17415 + pax_close_kernel();
17416 }
17417
17418 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17419 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17420 kprobe_opcode_t opcode;
17421 kprobe_opcode_t *orig_opcodes = opcodes;
17422
17423 - if (search_exception_tables((unsigned long)opcodes))
17424 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17425 return 0; /* Page fault may occur on this address. */
17426
17427 retry:
17428 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17429 }
17430 }
17431 insn_get_length(&insn);
17432 + pax_open_kernel();
17433 memcpy(dest, insn.kaddr, insn.length);
17434 + pax_close_kernel();
17435
17436 #ifdef CONFIG_X86_64
17437 if (insn_rip_relative(&insn)) {
17438 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17439 (u8 *) dest;
17440 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17441 disp = (u8 *) dest + insn_offset_displacement(&insn);
17442 + pax_open_kernel();
17443 *(s32 *) disp = (s32) newdisp;
17444 + pax_close_kernel();
17445 }
17446 #endif
17447 return insn.length;
17448 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17449 */
17450 __copy_instruction(p->ainsn.insn, p->addr, 0);
17451
17452 - if (can_boost(p->addr))
17453 + if (can_boost(ktla_ktva(p->addr)))
17454 p->ainsn.boostable = 0;
17455 else
17456 p->ainsn.boostable = -1;
17457
17458 - p->opcode = *p->addr;
17459 + p->opcode = *(ktla_ktva(p->addr));
17460 }
17461
17462 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17463 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17464 * nor set current_kprobe, because it doesn't use single
17465 * stepping.
17466 */
17467 - regs->ip = (unsigned long)p->ainsn.insn;
17468 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17469 preempt_enable_no_resched();
17470 return;
17471 }
17472 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17473 if (p->opcode == BREAKPOINT_INSTRUCTION)
17474 regs->ip = (unsigned long)p->addr;
17475 else
17476 - regs->ip = (unsigned long)p->ainsn.insn;
17477 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17478 }
17479
17480 /*
17481 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17482 setup_singlestep(p, regs, kcb, 0);
17483 return 1;
17484 }
17485 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17486 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17487 /*
17488 * The breakpoint instruction was removed right
17489 * after we hit it. Another cpu has removed
17490 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17491 " movq %rax, 152(%rsp)\n"
17492 RESTORE_REGS_STRING
17493 " popfq\n"
17494 +#ifdef KERNEXEC_PLUGIN
17495 + " btsq $63,(%rsp)\n"
17496 +#endif
17497 #else
17498 " pushf\n"
17499 SAVE_REGS_STRING
17500 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17501 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17502 {
17503 unsigned long *tos = stack_addr(regs);
17504 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17505 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17506 unsigned long orig_ip = (unsigned long)p->addr;
17507 kprobe_opcode_t *insn = p->ainsn.insn;
17508
17509 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17510 struct die_args *args = data;
17511 int ret = NOTIFY_DONE;
17512
17513 - if (args->regs && user_mode_vm(args->regs))
17514 + if (args->regs && user_mode(args->regs))
17515 return ret;
17516
17517 switch (val) {
17518 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17519 * Verify if the address gap is in 2GB range, because this uses
17520 * a relative jump.
17521 */
17522 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17523 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17524 if (abs(rel) > 0x7fffffff)
17525 return -ERANGE;
17526
17527 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17528 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17529
17530 /* Set probe function call */
17531 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17532 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17533
17534 /* Set returning jmp instruction at the tail of out-of-line buffer */
17535 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17536 - (u8 *)op->kp.addr + op->optinsn.size);
17537 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17538
17539 flush_icache_range((unsigned long) buf,
17540 (unsigned long) buf + TMPL_END_IDX +
17541 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17542 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17543
17544 /* Backup instructions which will be replaced by jump address */
17545 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17546 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17547 RELATIVE_ADDR_SIZE);
17548
17549 insn_buf[0] = RELATIVEJUMP_OPCODE;
17550 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17551 index ea69726..a305f16 100644
17552 --- a/arch/x86/kernel/ldt.c
17553 +++ b/arch/x86/kernel/ldt.c
17554 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17555 if (reload) {
17556 #ifdef CONFIG_SMP
17557 preempt_disable();
17558 - load_LDT(pc);
17559 + load_LDT_nolock(pc);
17560 if (!cpumask_equal(mm_cpumask(current->mm),
17561 cpumask_of(smp_processor_id())))
17562 smp_call_function(flush_ldt, current->mm, 1);
17563 preempt_enable();
17564 #else
17565 - load_LDT(pc);
17566 + load_LDT_nolock(pc);
17567 #endif
17568 }
17569 if (oldsize) {
17570 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17571 return err;
17572
17573 for (i = 0; i < old->size; i++)
17574 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17575 + write_ldt_entry(new->ldt, i, old->ldt + i);
17576 return 0;
17577 }
17578
17579 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17580 retval = copy_ldt(&mm->context, &old_mm->context);
17581 mutex_unlock(&old_mm->context.lock);
17582 }
17583 +
17584 + if (tsk == current) {
17585 + mm->context.vdso = 0;
17586 +
17587 +#ifdef CONFIG_X86_32
17588 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17589 + mm->context.user_cs_base = 0UL;
17590 + mm->context.user_cs_limit = ~0UL;
17591 +
17592 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17593 + cpus_clear(mm->context.cpu_user_cs_mask);
17594 +#endif
17595 +
17596 +#endif
17597 +#endif
17598 +
17599 + }
17600 +
17601 return retval;
17602 }
17603
17604 @@ -141,6 +159,7 @@ void destroy_context(struct mm_struct *mm)
17605 }
17606 }
17607
17608 +static int read_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17609 static int read_ldt(void __user *ptr, unsigned long bytecount)
17610 {
17611 int err;
17612 @@ -175,6 +194,7 @@ error_return:
17613 return err;
17614 }
17615
17616 +static int read_default_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17617 static int read_default_ldt(void __user *ptr, unsigned long bytecount)
17618 {
17619 /* CHECKME: Can we use _one_ random number ? */
17620 @@ -230,6 +250,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17621 }
17622 }
17623
17624 +#ifdef CONFIG_PAX_SEGMEXEC
17625 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17626 + error = -EINVAL;
17627 + goto out_unlock;
17628 + }
17629 +#endif
17630 +
17631 fill_ldt(&ldt, &ldt_info);
17632 if (oldmode)
17633 ldt.avl = 0;
17634 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17635 index a3fa43b..8966f4c 100644
17636 --- a/arch/x86/kernel/machine_kexec_32.c
17637 +++ b/arch/x86/kernel/machine_kexec_32.c
17638 @@ -27,7 +27,7 @@
17639 #include <asm/cacheflush.h>
17640 #include <asm/debugreg.h>
17641
17642 -static void set_idt(void *newidt, __u16 limit)
17643 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17644 {
17645 struct desc_ptr curidt;
17646
17647 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17648 }
17649
17650
17651 -static void set_gdt(void *newgdt, __u16 limit)
17652 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17653 {
17654 struct desc_ptr curgdt;
17655
17656 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17657 }
17658
17659 control_page = page_address(image->control_code_page);
17660 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17661 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17662
17663 relocate_kernel_ptr = control_page;
17664 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17665 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17666 index 3ca42d0..79d24cd 100644
17667 --- a/arch/x86/kernel/microcode_intel.c
17668 +++ b/arch/x86/kernel/microcode_intel.c
17669 @@ -434,15 +434,16 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17670 return ret;
17671 }
17672
17673 +static int get_ucode_user(void *to, const void *from, size_t n) __size_overflow(3);
17674 static int get_ucode_user(void *to, const void *from, size_t n)
17675 {
17676 - return copy_from_user(to, from, n);
17677 + return copy_from_user(to, (const void __force_user *)from, n);
17678 }
17679
17680 static enum ucode_state
17681 request_microcode_user(int cpu, const void __user *buf, size_t size)
17682 {
17683 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17684 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17685 }
17686
17687 static void microcode_fini_cpu(int cpu)
17688 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17689 index 925179f..1f0d561 100644
17690 --- a/arch/x86/kernel/module.c
17691 +++ b/arch/x86/kernel/module.c
17692 @@ -36,15 +36,61 @@
17693 #define DEBUGP(fmt...)
17694 #endif
17695
17696 -void *module_alloc(unsigned long size)
17697 +static inline void *__module_alloc(unsigned long size, pgprot_t prot) __size_overflow(1);
17698 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17699 {
17700 - if (PAGE_ALIGN(size) > MODULES_LEN)
17701 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17702 return NULL;
17703 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17704 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17705 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17706 -1, __builtin_return_address(0));
17707 }
17708
17709 +void *module_alloc(unsigned long size)
17710 +{
17711 +
17712 +#ifdef CONFIG_PAX_KERNEXEC
17713 + return __module_alloc(size, PAGE_KERNEL);
17714 +#else
17715 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17716 +#endif
17717 +
17718 +}
17719 +
17720 +#ifdef CONFIG_PAX_KERNEXEC
17721 +#ifdef CONFIG_X86_32
17722 +void *module_alloc_exec(unsigned long size)
17723 +{
17724 + struct vm_struct *area;
17725 +
17726 + if (size == 0)
17727 + return NULL;
17728 +
17729 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17730 + return area ? area->addr : NULL;
17731 +}
17732 +EXPORT_SYMBOL(module_alloc_exec);
17733 +
17734 +void module_free_exec(struct module *mod, void *module_region)
17735 +{
17736 + vunmap(module_region);
17737 +}
17738 +EXPORT_SYMBOL(module_free_exec);
17739 +#else
17740 +void module_free_exec(struct module *mod, void *module_region)
17741 +{
17742 + module_free(mod, module_region);
17743 +}
17744 +EXPORT_SYMBOL(module_free_exec);
17745 +
17746 +void *module_alloc_exec(unsigned long size)
17747 +{
17748 + return __module_alloc(size, PAGE_KERNEL_RX);
17749 +}
17750 +EXPORT_SYMBOL(module_alloc_exec);
17751 +#endif
17752 +#endif
17753 +
17754 #ifdef CONFIG_X86_32
17755 int apply_relocate(Elf32_Shdr *sechdrs,
17756 const char *strtab,
17757 @@ -55,14 +101,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17758 unsigned int i;
17759 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17760 Elf32_Sym *sym;
17761 - uint32_t *location;
17762 + uint32_t *plocation, location;
17763
17764 DEBUGP("Applying relocate section %u to %u\n", relsec,
17765 sechdrs[relsec].sh_info);
17766 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17767 /* This is where to make the change */
17768 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17769 - + rel[i].r_offset;
17770 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17771 + location = (uint32_t)plocation;
17772 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17773 + plocation = ktla_ktva((void *)plocation);
17774 /* This is the symbol it is referring to. Note that all
17775 undefined symbols have been resolved. */
17776 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17777 @@ -71,11 +119,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17778 switch (ELF32_R_TYPE(rel[i].r_info)) {
17779 case R_386_32:
17780 /* We add the value into the location given */
17781 - *location += sym->st_value;
17782 + pax_open_kernel();
17783 + *plocation += sym->st_value;
17784 + pax_close_kernel();
17785 break;
17786 case R_386_PC32:
17787 /* Add the value, subtract its postition */
17788 - *location += sym->st_value - (uint32_t)location;
17789 + pax_open_kernel();
17790 + *plocation += sym->st_value - location;
17791 + pax_close_kernel();
17792 break;
17793 default:
17794 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17795 @@ -120,21 +172,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17796 case R_X86_64_NONE:
17797 break;
17798 case R_X86_64_64:
17799 + pax_open_kernel();
17800 *(u64 *)loc = val;
17801 + pax_close_kernel();
17802 break;
17803 case R_X86_64_32:
17804 + pax_open_kernel();
17805 *(u32 *)loc = val;
17806 + pax_close_kernel();
17807 if (val != *(u32 *)loc)
17808 goto overflow;
17809 break;
17810 case R_X86_64_32S:
17811 + pax_open_kernel();
17812 *(s32 *)loc = val;
17813 + pax_close_kernel();
17814 if ((s64)val != *(s32 *)loc)
17815 goto overflow;
17816 break;
17817 case R_X86_64_PC32:
17818 val -= (u64)loc;
17819 + pax_open_kernel();
17820 *(u32 *)loc = val;
17821 + pax_close_kernel();
17822 +
17823 #if 0
17824 if ((s64)val != *(s32 *)loc)
17825 goto overflow;
17826 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17827 index 47acaf3..ec48ab6 100644
17828 --- a/arch/x86/kernel/nmi.c
17829 +++ b/arch/x86/kernel/nmi.c
17830 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
17831 dotraplinkage notrace __kprobes void
17832 do_nmi(struct pt_regs *regs, long error_code)
17833 {
17834 +
17835 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17836 + if (!user_mode(regs)) {
17837 + unsigned long cs = regs->cs & 0xFFFF;
17838 + unsigned long ip = ktva_ktla(regs->ip);
17839 +
17840 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17841 + regs->ip = ip;
17842 + }
17843 +#endif
17844 +
17845 nmi_nesting_preprocess(regs);
17846
17847 nmi_enter();
17848 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17849 index 676b8c7..870ba04 100644
17850 --- a/arch/x86/kernel/paravirt-spinlocks.c
17851 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17852 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17853 arch_spin_lock(lock);
17854 }
17855
17856 -struct pv_lock_ops pv_lock_ops = {
17857 +struct pv_lock_ops pv_lock_ops __read_only = {
17858 #ifdef CONFIG_SMP
17859 .spin_is_locked = __ticket_spin_is_locked,
17860 .spin_is_contended = __ticket_spin_is_contended,
17861 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17862 index d90272e..6bb013b 100644
17863 --- a/arch/x86/kernel/paravirt.c
17864 +++ b/arch/x86/kernel/paravirt.c
17865 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17866 {
17867 return x;
17868 }
17869 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17870 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17871 +#endif
17872
17873 void __init default_banner(void)
17874 {
17875 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17876 if (opfunc == NULL)
17877 /* If there's no function, patch it with a ud2a (BUG) */
17878 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17879 - else if (opfunc == _paravirt_nop)
17880 + else if (opfunc == (void *)_paravirt_nop)
17881 /* If the operation is a nop, then nop the callsite */
17882 ret = paravirt_patch_nop();
17883
17884 /* identity functions just return their single argument */
17885 - else if (opfunc == _paravirt_ident_32)
17886 + else if (opfunc == (void *)_paravirt_ident_32)
17887 ret = paravirt_patch_ident_32(insnbuf, len);
17888 - else if (opfunc == _paravirt_ident_64)
17889 + else if (opfunc == (void *)_paravirt_ident_64)
17890 ret = paravirt_patch_ident_64(insnbuf, len);
17891 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17892 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17893 + ret = paravirt_patch_ident_64(insnbuf, len);
17894 +#endif
17895
17896 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17897 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17898 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17899 if (insn_len > len || start == NULL)
17900 insn_len = len;
17901 else
17902 - memcpy(insnbuf, start, insn_len);
17903 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17904
17905 return insn_len;
17906 }
17907 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17908 preempt_enable();
17909 }
17910
17911 -struct pv_info pv_info = {
17912 +struct pv_info pv_info __read_only = {
17913 .name = "bare hardware",
17914 .paravirt_enabled = 0,
17915 .kernel_rpl = 0,
17916 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17917 #endif
17918 };
17919
17920 -struct pv_init_ops pv_init_ops = {
17921 +struct pv_init_ops pv_init_ops __read_only = {
17922 .patch = native_patch,
17923 };
17924
17925 -struct pv_time_ops pv_time_ops = {
17926 +struct pv_time_ops pv_time_ops __read_only = {
17927 .sched_clock = native_sched_clock,
17928 .steal_clock = native_steal_clock,
17929 };
17930
17931 -struct pv_irq_ops pv_irq_ops = {
17932 +struct pv_irq_ops pv_irq_ops __read_only = {
17933 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17934 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17935 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17936 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17937 #endif
17938 };
17939
17940 -struct pv_cpu_ops pv_cpu_ops = {
17941 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17942 .cpuid = native_cpuid,
17943 .get_debugreg = native_get_debugreg,
17944 .set_debugreg = native_set_debugreg,
17945 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17946 .end_context_switch = paravirt_nop,
17947 };
17948
17949 -struct pv_apic_ops pv_apic_ops = {
17950 +struct pv_apic_ops pv_apic_ops __read_only = {
17951 #ifdef CONFIG_X86_LOCAL_APIC
17952 .startup_ipi_hook = paravirt_nop,
17953 #endif
17954 };
17955
17956 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17957 +#ifdef CONFIG_X86_32
17958 +#ifdef CONFIG_X86_PAE
17959 +/* 64-bit pagetable entries */
17960 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17961 +#else
17962 /* 32-bit pagetable entries */
17963 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17964 +#endif
17965 #else
17966 /* 64-bit pagetable entries */
17967 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17968 #endif
17969
17970 -struct pv_mmu_ops pv_mmu_ops = {
17971 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17972
17973 .read_cr2 = native_read_cr2,
17974 .write_cr2 = native_write_cr2,
17975 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17976 .make_pud = PTE_IDENT,
17977
17978 .set_pgd = native_set_pgd,
17979 + .set_pgd_batched = native_set_pgd_batched,
17980 #endif
17981 #endif /* PAGETABLE_LEVELS >= 3 */
17982
17983 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17984 },
17985
17986 .set_fixmap = native_set_fixmap,
17987 +
17988 +#ifdef CONFIG_PAX_KERNEXEC
17989 + .pax_open_kernel = native_pax_open_kernel,
17990 + .pax_close_kernel = native_pax_close_kernel,
17991 +#endif
17992 +
17993 };
17994
17995 EXPORT_SYMBOL_GPL(pv_time_ops);
17996 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
17997 index 35ccf75..7a15747 100644
17998 --- a/arch/x86/kernel/pci-iommu_table.c
17999 +++ b/arch/x86/kernel/pci-iommu_table.c
18000 @@ -2,7 +2,7 @@
18001 #include <asm/iommu_table.h>
18002 #include <linux/string.h>
18003 #include <linux/kallsyms.h>
18004 -
18005 +#include <linux/sched.h>
18006
18007 #define DEBUG 1
18008
18009 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18010 index 15763af..da59ada 100644
18011 --- a/arch/x86/kernel/process.c
18012 +++ b/arch/x86/kernel/process.c
18013 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18014
18015 void free_thread_info(struct thread_info *ti)
18016 {
18017 - free_thread_xstate(ti->task);
18018 free_pages((unsigned long)ti, THREAD_ORDER);
18019 }
18020
18021 +static struct kmem_cache *task_struct_cachep;
18022 +
18023 void arch_task_cache_init(void)
18024 {
18025 - task_xstate_cachep =
18026 - kmem_cache_create("task_xstate", xstate_size,
18027 + /* create a slab on which task_structs can be allocated */
18028 + task_struct_cachep =
18029 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18030 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18031 +
18032 + task_xstate_cachep =
18033 + kmem_cache_create("task_xstate", xstate_size,
18034 __alignof__(union thread_xstate),
18035 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18036 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18037 +}
18038 +
18039 +struct task_struct *alloc_task_struct_node(int node)
18040 +{
18041 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18042 +}
18043 +
18044 +void free_task_struct(struct task_struct *task)
18045 +{
18046 + free_thread_xstate(task);
18047 + kmem_cache_free(task_struct_cachep, task);
18048 }
18049
18050 /*
18051 @@ -70,7 +87,7 @@ void exit_thread(void)
18052 unsigned long *bp = t->io_bitmap_ptr;
18053
18054 if (bp) {
18055 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18056 + struct tss_struct *tss = init_tss + get_cpu();
18057
18058 t->io_bitmap_ptr = NULL;
18059 clear_thread_flag(TIF_IO_BITMAP);
18060 @@ -106,7 +123,7 @@ void show_regs_common(void)
18061
18062 printk(KERN_CONT "\n");
18063 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18064 - current->pid, current->comm, print_tainted(),
18065 + task_pid_nr(current), current->comm, print_tainted(),
18066 init_utsname()->release,
18067 (int)strcspn(init_utsname()->version, " "),
18068 init_utsname()->version);
18069 @@ -120,6 +137,9 @@ void flush_thread(void)
18070 {
18071 struct task_struct *tsk = current;
18072
18073 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18074 + loadsegment(gs, 0);
18075 +#endif
18076 flush_ptrace_hw_breakpoint(tsk);
18077 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18078 /*
18079 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18080 regs.di = (unsigned long) arg;
18081
18082 #ifdef CONFIG_X86_32
18083 - regs.ds = __USER_DS;
18084 - regs.es = __USER_DS;
18085 + regs.ds = __KERNEL_DS;
18086 + regs.es = __KERNEL_DS;
18087 regs.fs = __KERNEL_PERCPU;
18088 - regs.gs = __KERNEL_STACK_CANARY;
18089 + savesegment(gs, regs.gs);
18090 #else
18091 regs.ss = __KERNEL_DS;
18092 #endif
18093 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18094
18095 return ret;
18096 }
18097 -void stop_this_cpu(void *dummy)
18098 +__noreturn void stop_this_cpu(void *dummy)
18099 {
18100 local_irq_disable();
18101 /*
18102 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18103 }
18104 early_param("idle", idle_setup);
18105
18106 -unsigned long arch_align_stack(unsigned long sp)
18107 +#ifdef CONFIG_PAX_RANDKSTACK
18108 +void pax_randomize_kstack(struct pt_regs *regs)
18109 {
18110 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18111 - sp -= get_random_int() % 8192;
18112 - return sp & ~0xf;
18113 -}
18114 + struct thread_struct *thread = &current->thread;
18115 + unsigned long time;
18116
18117 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18118 -{
18119 - unsigned long range_end = mm->brk + 0x02000000;
18120 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18121 -}
18122 + if (!randomize_va_space)
18123 + return;
18124 +
18125 + if (v8086_mode(regs))
18126 + return;
18127
18128 + rdtscl(time);
18129 +
18130 + /* P4 seems to return a 0 LSB, ignore it */
18131 +#ifdef CONFIG_MPENTIUM4
18132 + time &= 0x3EUL;
18133 + time <<= 2;
18134 +#elif defined(CONFIG_X86_64)
18135 + time &= 0xFUL;
18136 + time <<= 4;
18137 +#else
18138 + time &= 0x1FUL;
18139 + time <<= 3;
18140 +#endif
18141 +
18142 + thread->sp0 ^= time;
18143 + load_sp0(init_tss + smp_processor_id(), thread);
18144 +
18145 +#ifdef CONFIG_X86_64
18146 + percpu_write(kernel_stack, thread->sp0);
18147 +#endif
18148 +}
18149 +#endif
18150 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18151 index c08d1ff..6ae1c81 100644
18152 --- a/arch/x86/kernel/process_32.c
18153 +++ b/arch/x86/kernel/process_32.c
18154 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18155 unsigned long thread_saved_pc(struct task_struct *tsk)
18156 {
18157 return ((unsigned long *)tsk->thread.sp)[3];
18158 +//XXX return tsk->thread.eip;
18159 }
18160
18161 #ifndef CONFIG_SMP
18162 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18163 unsigned long sp;
18164 unsigned short ss, gs;
18165
18166 - if (user_mode_vm(regs)) {
18167 + if (user_mode(regs)) {
18168 sp = regs->sp;
18169 ss = regs->ss & 0xffff;
18170 - gs = get_user_gs(regs);
18171 } else {
18172 sp = kernel_stack_pointer(regs);
18173 savesegment(ss, ss);
18174 - savesegment(gs, gs);
18175 }
18176 + gs = get_user_gs(regs);
18177
18178 show_regs_common();
18179
18180 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18181 struct task_struct *tsk;
18182 int err;
18183
18184 - childregs = task_pt_regs(p);
18185 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18186 *childregs = *regs;
18187 childregs->ax = 0;
18188 childregs->sp = sp;
18189
18190 p->thread.sp = (unsigned long) childregs;
18191 p->thread.sp0 = (unsigned long) (childregs+1);
18192 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18193
18194 p->thread.ip = (unsigned long) ret_from_fork;
18195
18196 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18197 struct thread_struct *prev = &prev_p->thread,
18198 *next = &next_p->thread;
18199 int cpu = smp_processor_id();
18200 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18201 + struct tss_struct *tss = init_tss + cpu;
18202 fpu_switch_t fpu;
18203
18204 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18205 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18206 */
18207 lazy_save_gs(prev->gs);
18208
18209 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18210 + __set_fs(task_thread_info(next_p)->addr_limit);
18211 +#endif
18212 +
18213 /*
18214 * Load the per-thread Thread-Local Storage descriptor.
18215 */
18216 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18217 */
18218 arch_end_context_switch(next_p);
18219
18220 + percpu_write(current_task, next_p);
18221 + percpu_write(current_tinfo, &next_p->tinfo);
18222 +
18223 /*
18224 * Restore %gs if needed (which is common)
18225 */
18226 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18227
18228 switch_fpu_finish(next_p, fpu);
18229
18230 - percpu_write(current_task, next_p);
18231 -
18232 return prev_p;
18233 }
18234
18235 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18236 } while (count++ < 16);
18237 return 0;
18238 }
18239 -
18240 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18241 index cfa5c90..4facd28 100644
18242 --- a/arch/x86/kernel/process_64.c
18243 +++ b/arch/x86/kernel/process_64.c
18244 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18245 void exit_idle(void)
18246 {
18247 /* idle loop has pid 0 */
18248 - if (current->pid)
18249 + if (task_pid_nr(current))
18250 return;
18251 __exit_idle();
18252 }
18253 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18254 struct pt_regs *childregs;
18255 struct task_struct *me = current;
18256
18257 - childregs = ((struct pt_regs *)
18258 - (THREAD_SIZE + task_stack_page(p))) - 1;
18259 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18260 *childregs = *regs;
18261
18262 childregs->ax = 0;
18263 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18264 p->thread.sp = (unsigned long) childregs;
18265 p->thread.sp0 = (unsigned long) (childregs+1);
18266 p->thread.usersp = me->thread.usersp;
18267 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18268
18269 set_tsk_thread_flag(p, TIF_FORK);
18270
18271 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18272 struct thread_struct *prev = &prev_p->thread;
18273 struct thread_struct *next = &next_p->thread;
18274 int cpu = smp_processor_id();
18275 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18276 + struct tss_struct *tss = init_tss + cpu;
18277 unsigned fsindex, gsindex;
18278 fpu_switch_t fpu;
18279
18280 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18281 prev->usersp = percpu_read(old_rsp);
18282 percpu_write(old_rsp, next->usersp);
18283 percpu_write(current_task, next_p);
18284 + percpu_write(current_tinfo, &next_p->tinfo);
18285
18286 - percpu_write(kernel_stack,
18287 - (unsigned long)task_stack_page(next_p) +
18288 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18289 + percpu_write(kernel_stack, next->sp0);
18290
18291 /*
18292 * Now maybe reload the debug registers and handle I/O bitmaps
18293 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18294 if (!p || p == current || p->state == TASK_RUNNING)
18295 return 0;
18296 stack = (unsigned long)task_stack_page(p);
18297 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18298 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18299 return 0;
18300 fp = *(u64 *)(p->thread.sp);
18301 do {
18302 - if (fp < (unsigned long)stack ||
18303 - fp >= (unsigned long)stack+THREAD_SIZE)
18304 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18305 return 0;
18306 ip = *(u64 *)(fp+8);
18307 if (!in_sched_functions(ip))
18308 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18309 index 5026738..e1b5aa8 100644
18310 --- a/arch/x86/kernel/ptrace.c
18311 +++ b/arch/x86/kernel/ptrace.c
18312 @@ -792,6 +792,10 @@ static int ioperm_active(struct task_struct *target,
18313 static int ioperm_get(struct task_struct *target,
18314 const struct user_regset *regset,
18315 unsigned int pos, unsigned int count,
18316 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
18317 +static int ioperm_get(struct task_struct *target,
18318 + const struct user_regset *regset,
18319 + unsigned int pos, unsigned int count,
18320 void *kbuf, void __user *ubuf)
18321 {
18322 if (!target->thread.io_bitmap_ptr)
18323 @@ -823,7 +827,7 @@ long arch_ptrace(struct task_struct *child, long request,
18324 unsigned long addr, unsigned long data)
18325 {
18326 int ret;
18327 - unsigned long __user *datap = (unsigned long __user *)data;
18328 + unsigned long __user *datap = (__force unsigned long __user *)data;
18329
18330 switch (request) {
18331 /* read the word at location addr in the USER area. */
18332 @@ -908,14 +912,14 @@ long arch_ptrace(struct task_struct *child, long request,
18333 if ((int) addr < 0)
18334 return -EIO;
18335 ret = do_get_thread_area(child, addr,
18336 - (struct user_desc __user *)data);
18337 + (__force struct user_desc __user *) data);
18338 break;
18339
18340 case PTRACE_SET_THREAD_AREA:
18341 if ((int) addr < 0)
18342 return -EIO;
18343 ret = do_set_thread_area(child, addr,
18344 - (struct user_desc __user *)data, 0);
18345 + (__force struct user_desc __user *) data, 0);
18346 break;
18347 #endif
18348
18349 @@ -1332,7 +1336,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18350 memset(info, 0, sizeof(*info));
18351 info->si_signo = SIGTRAP;
18352 info->si_code = si_code;
18353 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18354 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18355 }
18356
18357 void user_single_step_siginfo(struct task_struct *tsk,
18358 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18359 index 42eb330..139955c 100644
18360 --- a/arch/x86/kernel/pvclock.c
18361 +++ b/arch/x86/kernel/pvclock.c
18362 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18363 return pv_tsc_khz;
18364 }
18365
18366 -static atomic64_t last_value = ATOMIC64_INIT(0);
18367 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18368
18369 void pvclock_resume(void)
18370 {
18371 - atomic64_set(&last_value, 0);
18372 + atomic64_set_unchecked(&last_value, 0);
18373 }
18374
18375 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18376 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18377 * updating at the same time, and one of them could be slightly behind,
18378 * making the assumption that last_value always go forward fail to hold.
18379 */
18380 - last = atomic64_read(&last_value);
18381 + last = atomic64_read_unchecked(&last_value);
18382 do {
18383 if (ret < last)
18384 return last;
18385 - last = atomic64_cmpxchg(&last_value, last, ret);
18386 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18387 } while (unlikely(last != ret));
18388
18389 return ret;
18390 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18391 index d840e69..98e9581 100644
18392 --- a/arch/x86/kernel/reboot.c
18393 +++ b/arch/x86/kernel/reboot.c
18394 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18395 EXPORT_SYMBOL(pm_power_off);
18396
18397 static const struct desc_ptr no_idt = {};
18398 -static int reboot_mode;
18399 +static unsigned short reboot_mode;
18400 enum reboot_type reboot_type = BOOT_ACPI;
18401 int reboot_force;
18402
18403 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18404 extern const unsigned char machine_real_restart_asm[];
18405 extern const u64 machine_real_restart_gdt[3];
18406
18407 -void machine_real_restart(unsigned int type)
18408 +__noreturn void machine_real_restart(unsigned int type)
18409 {
18410 void *restart_va;
18411 unsigned long restart_pa;
18412 - void (*restart_lowmem)(unsigned int);
18413 + void (* __noreturn restart_lowmem)(unsigned int);
18414 u64 *lowmem_gdt;
18415
18416 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18417 + struct desc_struct *gdt;
18418 +#endif
18419 +
18420 local_irq_disable();
18421
18422 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18423 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18424 boot)". This seems like a fairly standard thing that gets set by
18425 REBOOT.COM programs, and the previous reset routine did this
18426 too. */
18427 - *((unsigned short *)0x472) = reboot_mode;
18428 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18429
18430 /* Patch the GDT in the low memory trampoline */
18431 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18432
18433 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18434 restart_pa = virt_to_phys(restart_va);
18435 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18436 + restart_lowmem = (void *)restart_pa;
18437
18438 /* GDT[0]: GDT self-pointer */
18439 lowmem_gdt[0] =
18440 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18441 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18442
18443 /* Jump to the identity-mapped low memory code */
18444 +
18445 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18446 + gdt = get_cpu_gdt_table(smp_processor_id());
18447 + pax_open_kernel();
18448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18449 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18450 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18451 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18452 +#endif
18453 +#ifdef CONFIG_PAX_KERNEXEC
18454 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18455 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18456 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18457 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18458 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18459 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18460 +#endif
18461 + pax_close_kernel();
18462 +#endif
18463 +
18464 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18465 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18466 + unreachable();
18467 +#else
18468 restart_lowmem(type);
18469 +#endif
18470 +
18471 }
18472 #ifdef CONFIG_APM_MODULE
18473 EXPORT_SYMBOL(machine_real_restart);
18474 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18475 * try to force a triple fault and then cycle between hitting the keyboard
18476 * controller and doing that
18477 */
18478 -static void native_machine_emergency_restart(void)
18479 +__noreturn static void native_machine_emergency_restart(void)
18480 {
18481 int i;
18482 int attempt = 0;
18483 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18484 #endif
18485 }
18486
18487 -static void __machine_emergency_restart(int emergency)
18488 +static __noreturn void __machine_emergency_restart(int emergency)
18489 {
18490 reboot_emergency = emergency;
18491 machine_ops.emergency_restart();
18492 }
18493
18494 -static void native_machine_restart(char *__unused)
18495 +static __noreturn void native_machine_restart(char *__unused)
18496 {
18497 printk("machine restart\n");
18498
18499 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18500 __machine_emergency_restart(0);
18501 }
18502
18503 -static void native_machine_halt(void)
18504 +static __noreturn void native_machine_halt(void)
18505 {
18506 /* stop other cpus and apics */
18507 machine_shutdown();
18508 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
18509 stop_this_cpu(NULL);
18510 }
18511
18512 -static void native_machine_power_off(void)
18513 +__noreturn static void native_machine_power_off(void)
18514 {
18515 if (pm_power_off) {
18516 if (!reboot_force)
18517 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18518 }
18519 /* a fallback in case there is no PM info available */
18520 tboot_shutdown(TB_SHUTDOWN_HALT);
18521 + unreachable();
18522 }
18523
18524 struct machine_ops machine_ops = {
18525 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18526 index 7a6f3b3..bed145d7 100644
18527 --- a/arch/x86/kernel/relocate_kernel_64.S
18528 +++ b/arch/x86/kernel/relocate_kernel_64.S
18529 @@ -11,6 +11,7 @@
18530 #include <asm/kexec.h>
18531 #include <asm/processor-flags.h>
18532 #include <asm/pgtable_types.h>
18533 +#include <asm/alternative-asm.h>
18534
18535 /*
18536 * Must be relocatable PIC code callable as a C function
18537 @@ -160,13 +161,14 @@ identity_mapped:
18538 xorq %rbp, %rbp
18539 xorq %r8, %r8
18540 xorq %r9, %r9
18541 - xorq %r10, %r9
18542 + xorq %r10, %r10
18543 xorq %r11, %r11
18544 xorq %r12, %r12
18545 xorq %r13, %r13
18546 xorq %r14, %r14
18547 xorq %r15, %r15
18548
18549 + pax_force_retaddr 0, 1
18550 ret
18551
18552 1:
18553 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18554 index d7d5099..28555d0 100644
18555 --- a/arch/x86/kernel/setup.c
18556 +++ b/arch/x86/kernel/setup.c
18557 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18558
18559 switch (data->type) {
18560 case SETUP_E820_EXT:
18561 - parse_e820_ext(data);
18562 + parse_e820_ext((struct setup_data __force_kernel *)data);
18563 break;
18564 case SETUP_DTB:
18565 add_dtb(pa_data);
18566 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18567 * area (640->1Mb) as ram even though it is not.
18568 * take them out.
18569 */
18570 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18571 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18572 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18573 }
18574
18575 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18576
18577 if (!boot_params.hdr.root_flags)
18578 root_mountflags &= ~MS_RDONLY;
18579 - init_mm.start_code = (unsigned long) _text;
18580 - init_mm.end_code = (unsigned long) _etext;
18581 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18582 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18583 init_mm.end_data = (unsigned long) _edata;
18584 init_mm.brk = _brk_end;
18585
18586 - code_resource.start = virt_to_phys(_text);
18587 - code_resource.end = virt_to_phys(_etext)-1;
18588 - data_resource.start = virt_to_phys(_etext);
18589 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18590 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18591 + data_resource.start = virt_to_phys(_sdata);
18592 data_resource.end = virt_to_phys(_edata)-1;
18593 bss_resource.start = virt_to_phys(&__bss_start);
18594 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18595 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18596 index 71f4727..217419b 100644
18597 --- a/arch/x86/kernel/setup_percpu.c
18598 +++ b/arch/x86/kernel/setup_percpu.c
18599 @@ -21,19 +21,17 @@
18600 #include <asm/cpu.h>
18601 #include <asm/stackprotector.h>
18602
18603 -DEFINE_PER_CPU(int, cpu_number);
18604 +#ifdef CONFIG_SMP
18605 +DEFINE_PER_CPU(unsigned int, cpu_number);
18606 EXPORT_PER_CPU_SYMBOL(cpu_number);
18607 +#endif
18608
18609 -#ifdef CONFIG_X86_64
18610 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18611 -#else
18612 -#define BOOT_PERCPU_OFFSET 0
18613 -#endif
18614
18615 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18616 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18617
18618 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18619 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18620 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18621 };
18622 EXPORT_SYMBOL(__per_cpu_offset);
18623 @@ -96,6 +94,8 @@ static bool __init pcpu_need_numa(void)
18624 * Pointer to the allocated area on success, NULL on failure.
18625 */
18626 static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18627 + unsigned long align) __size_overflow(2);
18628 +static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18629 unsigned long align)
18630 {
18631 const unsigned long goal = __pa(MAX_DMA_ADDRESS);
18632 @@ -124,6 +124,8 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18633 /*
18634 * Helpers for first chunk memory allocation
18635 */
18636 +static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align) __size_overflow(2);
18637 +
18638 static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
18639 {
18640 return pcpu_alloc_bootmem(cpu, size, align);
18641 @@ -155,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
18642 {
18643 #ifdef CONFIG_X86_32
18644 struct desc_struct gdt;
18645 + unsigned long base = per_cpu_offset(cpu);
18646
18647 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18648 - 0x2 | DESCTYPE_S, 0x8);
18649 - gdt.s = 1;
18650 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18651 + 0x83 | DESCTYPE_S, 0xC);
18652 write_gdt_entry(get_cpu_gdt_table(cpu),
18653 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18654 #endif
18655 @@ -207,6 +209,11 @@ void __init setup_per_cpu_areas(void)
18656 /* alrighty, percpu areas up and running */
18657 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18658 for_each_possible_cpu(cpu) {
18659 +#ifdef CONFIG_CC_STACKPROTECTOR
18660 +#ifdef CONFIG_X86_32
18661 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18662 +#endif
18663 +#endif
18664 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18665 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18666 per_cpu(cpu_number, cpu) = cpu;
18667 @@ -247,6 +254,12 @@ void __init setup_per_cpu_areas(void)
18668 */
18669 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18670 #endif
18671 +#ifdef CONFIG_CC_STACKPROTECTOR
18672 +#ifdef CONFIG_X86_32
18673 + if (!cpu)
18674 + per_cpu(stack_canary.canary, cpu) = canary;
18675 +#endif
18676 +#endif
18677 /*
18678 * Up to this point, the boot CPU has been using .init.data
18679 * area. Reload any changed state for the boot CPU.
18680 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18681 index 46a01bd..2e88e6d 100644
18682 --- a/arch/x86/kernel/signal.c
18683 +++ b/arch/x86/kernel/signal.c
18684 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18685 * Align the stack pointer according to the i386 ABI,
18686 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18687 */
18688 - sp = ((sp + 4) & -16ul) - 4;
18689 + sp = ((sp - 12) & -16ul) - 4;
18690 #else /* !CONFIG_X86_32 */
18691 sp = round_down(sp, 16) - 8;
18692 #endif
18693 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18694 * Return an always-bogus address instead so we will die with SIGSEGV.
18695 */
18696 if (onsigstack && !likely(on_sig_stack(sp)))
18697 - return (void __user *)-1L;
18698 + return (__force void __user *)-1L;
18699
18700 /* save i387 state */
18701 if (used_math() && save_i387_xstate(*fpstate) < 0)
18702 - return (void __user *)-1L;
18703 + return (__force void __user *)-1L;
18704
18705 return (void __user *)sp;
18706 }
18707 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18708 }
18709
18710 if (current->mm->context.vdso)
18711 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18712 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18713 else
18714 - restorer = &frame->retcode;
18715 + restorer = (void __user *)&frame->retcode;
18716 if (ka->sa.sa_flags & SA_RESTORER)
18717 restorer = ka->sa.sa_restorer;
18718
18719 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18720 * reasons and because gdb uses it as a signature to notice
18721 * signal handler stack frames.
18722 */
18723 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18724 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18725
18726 if (err)
18727 return -EFAULT;
18728 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18729 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18730
18731 /* Set up to return from userspace. */
18732 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18733 + if (current->mm->context.vdso)
18734 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18735 + else
18736 + restorer = (void __user *)&frame->retcode;
18737 if (ka->sa.sa_flags & SA_RESTORER)
18738 restorer = ka->sa.sa_restorer;
18739 put_user_ex(restorer, &frame->pretcode);
18740 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18741 * reasons and because gdb uses it as a signature to notice
18742 * signal handler stack frames.
18743 */
18744 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18745 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18746 } put_user_catch(err);
18747
18748 if (err)
18749 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
18750 * X86_32: vm86 regs switched out by assembly code before reaching
18751 * here, so testing against kernel CS suffices.
18752 */
18753 - if (!user_mode(regs))
18754 + if (!user_mode_novm(regs))
18755 return;
18756
18757 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18758 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18759 index 66d250c..f1b10bd 100644
18760 --- a/arch/x86/kernel/smpboot.c
18761 +++ b/arch/x86/kernel/smpboot.c
18762 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18763 set_idle_for_cpu(cpu, c_idle.idle);
18764 do_rest:
18765 per_cpu(current_task, cpu) = c_idle.idle;
18766 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18767 #ifdef CONFIG_X86_32
18768 /* Stack for startup_32 can be just as for start_secondary onwards */
18769 irq_ctx_init(cpu);
18770 #else
18771 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18772 initial_gs = per_cpu_offset(cpu);
18773 - per_cpu(kernel_stack, cpu) =
18774 - (unsigned long)task_stack_page(c_idle.idle) -
18775 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18776 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18777 #endif
18778 +
18779 + pax_open_kernel();
18780 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18781 + pax_close_kernel();
18782 +
18783 initial_code = (unsigned long)start_secondary;
18784 stack_start = c_idle.idle->thread.sp;
18785
18786 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18787
18788 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18789
18790 +#ifdef CONFIG_PAX_PER_CPU_PGD
18791 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18792 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18793 + KERNEL_PGD_PTRS);
18794 +#endif
18795 +
18796 err = do_boot_cpu(apicid, cpu);
18797 if (err) {
18798 pr_debug("do_boot_cpu failed %d\n", err);
18799 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18800 index c346d11..d43b163 100644
18801 --- a/arch/x86/kernel/step.c
18802 +++ b/arch/x86/kernel/step.c
18803 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18804 struct desc_struct *desc;
18805 unsigned long base;
18806
18807 - seg &= ~7UL;
18808 + seg >>= 3;
18809
18810 mutex_lock(&child->mm->context.lock);
18811 - if (unlikely((seg >> 3) >= child->mm->context.size))
18812 + if (unlikely(seg >= child->mm->context.size))
18813 addr = -1L; /* bogus selector, access would fault */
18814 else {
18815 desc = child->mm->context.ldt + seg;
18816 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18817 addr += base;
18818 }
18819 mutex_unlock(&child->mm->context.lock);
18820 - }
18821 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18822 + addr = ktla_ktva(addr);
18823
18824 return addr;
18825 }
18826 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18827 unsigned char opcode[15];
18828 unsigned long addr = convert_ip_to_linear(child, regs);
18829
18830 + if (addr == -EINVAL)
18831 + return 0;
18832 +
18833 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18834 for (i = 0; i < copied; i++) {
18835 switch (opcode[i]) {
18836 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18837 index 0b0cb5f..db6b9ed 100644
18838 --- a/arch/x86/kernel/sys_i386_32.c
18839 +++ b/arch/x86/kernel/sys_i386_32.c
18840 @@ -24,17 +24,224 @@
18841
18842 #include <asm/syscalls.h>
18843
18844 -/*
18845 - * Do a system call from kernel instead of calling sys_execve so we
18846 - * end up with proper pt_regs.
18847 - */
18848 -int kernel_execve(const char *filename,
18849 - const char *const argv[],
18850 - const char *const envp[])
18851 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18852 {
18853 - long __res;
18854 - asm volatile ("int $0x80"
18855 - : "=a" (__res)
18856 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18857 - return __res;
18858 + unsigned long pax_task_size = TASK_SIZE;
18859 +
18860 +#ifdef CONFIG_PAX_SEGMEXEC
18861 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18862 + pax_task_size = SEGMEXEC_TASK_SIZE;
18863 +#endif
18864 +
18865 + if (len > pax_task_size || addr > pax_task_size - len)
18866 + return -EINVAL;
18867 +
18868 + return 0;
18869 +}
18870 +
18871 +unsigned long
18872 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18873 + unsigned long len, unsigned long pgoff, unsigned long flags)
18874 +{
18875 + struct mm_struct *mm = current->mm;
18876 + struct vm_area_struct *vma;
18877 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18878 +
18879 +#ifdef CONFIG_PAX_SEGMEXEC
18880 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18881 + pax_task_size = SEGMEXEC_TASK_SIZE;
18882 +#endif
18883 +
18884 + pax_task_size -= PAGE_SIZE;
18885 +
18886 + if (len > pax_task_size)
18887 + return -ENOMEM;
18888 +
18889 + if (flags & MAP_FIXED)
18890 + return addr;
18891 +
18892 +#ifdef CONFIG_PAX_RANDMMAP
18893 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18894 +#endif
18895 +
18896 + if (addr) {
18897 + addr = PAGE_ALIGN(addr);
18898 + if (pax_task_size - len >= addr) {
18899 + vma = find_vma(mm, addr);
18900 + if (check_heap_stack_gap(vma, addr, len))
18901 + return addr;
18902 + }
18903 + }
18904 + if (len > mm->cached_hole_size) {
18905 + start_addr = addr = mm->free_area_cache;
18906 + } else {
18907 + start_addr = addr = mm->mmap_base;
18908 + mm->cached_hole_size = 0;
18909 + }
18910 +
18911 +#ifdef CONFIG_PAX_PAGEEXEC
18912 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18913 + start_addr = 0x00110000UL;
18914 +
18915 +#ifdef CONFIG_PAX_RANDMMAP
18916 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18917 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18918 +#endif
18919 +
18920 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18921 + start_addr = addr = mm->mmap_base;
18922 + else
18923 + addr = start_addr;
18924 + }
18925 +#endif
18926 +
18927 +full_search:
18928 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18929 + /* At this point: (!vma || addr < vma->vm_end). */
18930 + if (pax_task_size - len < addr) {
18931 + /*
18932 + * Start a new search - just in case we missed
18933 + * some holes.
18934 + */
18935 + if (start_addr != mm->mmap_base) {
18936 + start_addr = addr = mm->mmap_base;
18937 + mm->cached_hole_size = 0;
18938 + goto full_search;
18939 + }
18940 + return -ENOMEM;
18941 + }
18942 + if (check_heap_stack_gap(vma, addr, len))
18943 + break;
18944 + if (addr + mm->cached_hole_size < vma->vm_start)
18945 + mm->cached_hole_size = vma->vm_start - addr;
18946 + addr = vma->vm_end;
18947 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18948 + start_addr = addr = mm->mmap_base;
18949 + mm->cached_hole_size = 0;
18950 + goto full_search;
18951 + }
18952 + }
18953 +
18954 + /*
18955 + * Remember the place where we stopped the search:
18956 + */
18957 + mm->free_area_cache = addr + len;
18958 + return addr;
18959 +}
18960 +
18961 +unsigned long
18962 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18963 + const unsigned long len, const unsigned long pgoff,
18964 + const unsigned long flags)
18965 +{
18966 + struct vm_area_struct *vma;
18967 + struct mm_struct *mm = current->mm;
18968 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18969 +
18970 +#ifdef CONFIG_PAX_SEGMEXEC
18971 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18972 + pax_task_size = SEGMEXEC_TASK_SIZE;
18973 +#endif
18974 +
18975 + pax_task_size -= PAGE_SIZE;
18976 +
18977 + /* requested length too big for entire address space */
18978 + if (len > pax_task_size)
18979 + return -ENOMEM;
18980 +
18981 + if (flags & MAP_FIXED)
18982 + return addr;
18983 +
18984 +#ifdef CONFIG_PAX_PAGEEXEC
18985 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18986 + goto bottomup;
18987 +#endif
18988 +
18989 +#ifdef CONFIG_PAX_RANDMMAP
18990 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18991 +#endif
18992 +
18993 + /* requesting a specific address */
18994 + if (addr) {
18995 + addr = PAGE_ALIGN(addr);
18996 + if (pax_task_size - len >= addr) {
18997 + vma = find_vma(mm, addr);
18998 + if (check_heap_stack_gap(vma, addr, len))
18999 + return addr;
19000 + }
19001 + }
19002 +
19003 + /* check if free_area_cache is useful for us */
19004 + if (len <= mm->cached_hole_size) {
19005 + mm->cached_hole_size = 0;
19006 + mm->free_area_cache = mm->mmap_base;
19007 + }
19008 +
19009 + /* either no address requested or can't fit in requested address hole */
19010 + addr = mm->free_area_cache;
19011 +
19012 + /* make sure it can fit in the remaining address space */
19013 + if (addr > len) {
19014 + vma = find_vma(mm, addr-len);
19015 + if (check_heap_stack_gap(vma, addr - len, len))
19016 + /* remember the address as a hint for next time */
19017 + return (mm->free_area_cache = addr-len);
19018 + }
19019 +
19020 + if (mm->mmap_base < len)
19021 + goto bottomup;
19022 +
19023 + addr = mm->mmap_base-len;
19024 +
19025 + do {
19026 + /*
19027 + * Lookup failure means no vma is above this address,
19028 + * else if new region fits below vma->vm_start,
19029 + * return with success:
19030 + */
19031 + vma = find_vma(mm, addr);
19032 + if (check_heap_stack_gap(vma, addr, len))
19033 + /* remember the address as a hint for next time */
19034 + return (mm->free_area_cache = addr);
19035 +
19036 + /* remember the largest hole we saw so far */
19037 + if (addr + mm->cached_hole_size < vma->vm_start)
19038 + mm->cached_hole_size = vma->vm_start - addr;
19039 +
19040 + /* try just below the current vma->vm_start */
19041 + addr = skip_heap_stack_gap(vma, len);
19042 + } while (!IS_ERR_VALUE(addr));
19043 +
19044 +bottomup:
19045 + /*
19046 + * A failed mmap() very likely causes application failure,
19047 + * so fall back to the bottom-up function here. This scenario
19048 + * can happen with large stack limits and large mmap()
19049 + * allocations.
19050 + */
19051 +
19052 +#ifdef CONFIG_PAX_SEGMEXEC
19053 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19054 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19055 + else
19056 +#endif
19057 +
19058 + mm->mmap_base = TASK_UNMAPPED_BASE;
19059 +
19060 +#ifdef CONFIG_PAX_RANDMMAP
19061 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19062 + mm->mmap_base += mm->delta_mmap;
19063 +#endif
19064 +
19065 + mm->free_area_cache = mm->mmap_base;
19066 + mm->cached_hole_size = ~0UL;
19067 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19068 + /*
19069 + * Restore the topdown base:
19070 + */
19071 + mm->mmap_base = base;
19072 + mm->free_area_cache = base;
19073 + mm->cached_hole_size = ~0UL;
19074 +
19075 + return addr;
19076 }
19077 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19078 index 0514890..3dbebce 100644
19079 --- a/arch/x86/kernel/sys_x86_64.c
19080 +++ b/arch/x86/kernel/sys_x86_64.c
19081 @@ -95,8 +95,8 @@ out:
19082 return error;
19083 }
19084
19085 -static void find_start_end(unsigned long flags, unsigned long *begin,
19086 - unsigned long *end)
19087 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19088 + unsigned long *begin, unsigned long *end)
19089 {
19090 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19091 unsigned long new_begin;
19092 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19093 *begin = new_begin;
19094 }
19095 } else {
19096 - *begin = TASK_UNMAPPED_BASE;
19097 + *begin = mm->mmap_base;
19098 *end = TASK_SIZE;
19099 }
19100 }
19101 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19102 if (flags & MAP_FIXED)
19103 return addr;
19104
19105 - find_start_end(flags, &begin, &end);
19106 + find_start_end(mm, flags, &begin, &end);
19107
19108 if (len > end)
19109 return -ENOMEM;
19110
19111 +#ifdef CONFIG_PAX_RANDMMAP
19112 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19113 +#endif
19114 +
19115 if (addr) {
19116 addr = PAGE_ALIGN(addr);
19117 vma = find_vma(mm, addr);
19118 - if (end - len >= addr &&
19119 - (!vma || addr + len <= vma->vm_start))
19120 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19121 return addr;
19122 }
19123 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19124 @@ -172,7 +175,7 @@ full_search:
19125 }
19126 return -ENOMEM;
19127 }
19128 - if (!vma || addr + len <= vma->vm_start) {
19129 + if (check_heap_stack_gap(vma, addr, len)) {
19130 /*
19131 * Remember the place where we stopped the search:
19132 */
19133 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19134 {
19135 struct vm_area_struct *vma;
19136 struct mm_struct *mm = current->mm;
19137 - unsigned long addr = addr0;
19138 + unsigned long base = mm->mmap_base, addr = addr0;
19139
19140 /* requested length too big for entire address space */
19141 if (len > TASK_SIZE)
19142 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19143 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19144 goto bottomup;
19145
19146 +#ifdef CONFIG_PAX_RANDMMAP
19147 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19148 +#endif
19149 +
19150 /* requesting a specific address */
19151 if (addr) {
19152 addr = PAGE_ALIGN(addr);
19153 - vma = find_vma(mm, addr);
19154 - if (TASK_SIZE - len >= addr &&
19155 - (!vma || addr + len <= vma->vm_start))
19156 - return addr;
19157 + if (TASK_SIZE - len >= addr) {
19158 + vma = find_vma(mm, addr);
19159 + if (check_heap_stack_gap(vma, addr, len))
19160 + return addr;
19161 + }
19162 }
19163
19164 /* check if free_area_cache is useful for us */
19165 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19166 ALIGN_TOPDOWN);
19167
19168 vma = find_vma(mm, tmp_addr);
19169 - if (!vma || tmp_addr + len <= vma->vm_start)
19170 + if (check_heap_stack_gap(vma, tmp_addr, len))
19171 /* remember the address as a hint for next time */
19172 return mm->free_area_cache = tmp_addr;
19173 }
19174 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19175 * return with success:
19176 */
19177 vma = find_vma(mm, addr);
19178 - if (!vma || addr+len <= vma->vm_start)
19179 + if (check_heap_stack_gap(vma, addr, len))
19180 /* remember the address as a hint for next time */
19181 return mm->free_area_cache = addr;
19182
19183 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19184 mm->cached_hole_size = vma->vm_start - addr;
19185
19186 /* try just below the current vma->vm_start */
19187 - addr = vma->vm_start-len;
19188 - } while (len < vma->vm_start);
19189 + addr = skip_heap_stack_gap(vma, len);
19190 + } while (!IS_ERR_VALUE(addr));
19191
19192 bottomup:
19193 /*
19194 @@ -270,13 +278,21 @@ bottomup:
19195 * can happen with large stack limits and large mmap()
19196 * allocations.
19197 */
19198 + mm->mmap_base = TASK_UNMAPPED_BASE;
19199 +
19200 +#ifdef CONFIG_PAX_RANDMMAP
19201 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19202 + mm->mmap_base += mm->delta_mmap;
19203 +#endif
19204 +
19205 + mm->free_area_cache = mm->mmap_base;
19206 mm->cached_hole_size = ~0UL;
19207 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19208 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19209 /*
19210 * Restore the topdown base:
19211 */
19212 - mm->free_area_cache = mm->mmap_base;
19213 + mm->mmap_base = base;
19214 + mm->free_area_cache = base;
19215 mm->cached_hole_size = ~0UL;
19216
19217 return addr;
19218 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19219 index e2410e2..4fe3fbc 100644
19220 --- a/arch/x86/kernel/tboot.c
19221 +++ b/arch/x86/kernel/tboot.c
19222 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19223
19224 void tboot_shutdown(u32 shutdown_type)
19225 {
19226 - void (*shutdown)(void);
19227 + void (* __noreturn shutdown)(void);
19228
19229 if (!tboot_enabled())
19230 return;
19231 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19232
19233 switch_to_tboot_pt();
19234
19235 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19236 + shutdown = (void *)tboot->shutdown_entry;
19237 shutdown();
19238
19239 /* should not reach here */
19240 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19241 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19242 }
19243
19244 -static atomic_t ap_wfs_count;
19245 +static atomic_unchecked_t ap_wfs_count;
19246
19247 static int tboot_wait_for_aps(int num_aps)
19248 {
19249 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19250 {
19251 switch (action) {
19252 case CPU_DYING:
19253 - atomic_inc(&ap_wfs_count);
19254 + atomic_inc_unchecked(&ap_wfs_count);
19255 if (num_online_cpus() == 1)
19256 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19257 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19258 return NOTIFY_BAD;
19259 break;
19260 }
19261 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19262
19263 tboot_create_trampoline();
19264
19265 - atomic_set(&ap_wfs_count, 0);
19266 + atomic_set_unchecked(&ap_wfs_count, 0);
19267 register_hotcpu_notifier(&tboot_cpu_notifier);
19268 return 0;
19269 }
19270 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19271 index dd5fbf4..b7f2232 100644
19272 --- a/arch/x86/kernel/time.c
19273 +++ b/arch/x86/kernel/time.c
19274 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19275 {
19276 unsigned long pc = instruction_pointer(regs);
19277
19278 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19279 + if (!user_mode(regs) && in_lock_functions(pc)) {
19280 #ifdef CONFIG_FRAME_POINTER
19281 - return *(unsigned long *)(regs->bp + sizeof(long));
19282 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19283 #else
19284 unsigned long *sp =
19285 (unsigned long *)kernel_stack_pointer(regs);
19286 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19287 * or above a saved flags. Eflags has bits 22-31 zero,
19288 * kernel addresses don't.
19289 */
19290 +
19291 +#ifdef CONFIG_PAX_KERNEXEC
19292 + return ktla_ktva(sp[0]);
19293 +#else
19294 if (sp[0] >> 22)
19295 return sp[0];
19296 if (sp[1] >> 22)
19297 return sp[1];
19298 #endif
19299 +
19300 +#endif
19301 }
19302 return pc;
19303 }
19304 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19305 index bcfec2d..8f88b4a 100644
19306 --- a/arch/x86/kernel/tls.c
19307 +++ b/arch/x86/kernel/tls.c
19308 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19309 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19310 return -EINVAL;
19311
19312 +#ifdef CONFIG_PAX_SEGMEXEC
19313 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19314 + return -EINVAL;
19315 +#endif
19316 +
19317 set_tls_desc(p, idx, &info, 1);
19318
19319 return 0;
19320 diff --git a/arch/x86/kernel/tls.h b/arch/x86/kernel/tls.h
19321 index 2f083a2..7d3fecc 100644
19322 --- a/arch/x86/kernel/tls.h
19323 +++ b/arch/x86/kernel/tls.h
19324 @@ -16,6 +16,6 @@
19325
19326 extern user_regset_active_fn regset_tls_active;
19327 extern user_regset_get_fn regset_tls_get;
19328 -extern user_regset_set_fn regset_tls_set;
19329 +extern user_regset_set_fn regset_tls_set __size_overflow(4);
19330
19331 #endif /* _ARCH_X86_KERNEL_TLS_H */
19332 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19333 index 451c0a7..e57f551 100644
19334 --- a/arch/x86/kernel/trampoline_32.S
19335 +++ b/arch/x86/kernel/trampoline_32.S
19336 @@ -32,6 +32,12 @@
19337 #include <asm/segment.h>
19338 #include <asm/page_types.h>
19339
19340 +#ifdef CONFIG_PAX_KERNEXEC
19341 +#define ta(X) (X)
19342 +#else
19343 +#define ta(X) ((X) - __PAGE_OFFSET)
19344 +#endif
19345 +
19346 #ifdef CONFIG_SMP
19347
19348 .section ".x86_trampoline","a"
19349 @@ -62,7 +68,7 @@ r_base = .
19350 inc %ax # protected mode (PE) bit
19351 lmsw %ax # into protected mode
19352 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19353 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19354 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19355
19356 # These need to be in the same 64K segment as the above;
19357 # hence we don't use the boot_gdt_descr defined in head.S
19358 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19359 index 09ff517..df19fbff 100644
19360 --- a/arch/x86/kernel/trampoline_64.S
19361 +++ b/arch/x86/kernel/trampoline_64.S
19362 @@ -90,7 +90,7 @@ startup_32:
19363 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19364 movl %eax, %ds
19365
19366 - movl $X86_CR4_PAE, %eax
19367 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19368 movl %eax, %cr4 # Enable PAE mode
19369
19370 # Setup trampoline 4 level pagetables
19371 @@ -138,7 +138,7 @@ tidt:
19372 # so the kernel can live anywhere
19373 .balign 4
19374 tgdt:
19375 - .short tgdt_end - tgdt # gdt limit
19376 + .short tgdt_end - tgdt - 1 # gdt limit
19377 .long tgdt - r_base
19378 .short 0
19379 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19380 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19381 index 4bbe04d..41d0943 100644
19382 --- a/arch/x86/kernel/traps.c
19383 +++ b/arch/x86/kernel/traps.c
19384 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19385
19386 /* Do we ignore FPU interrupts ? */
19387 char ignore_fpu_irq;
19388 -
19389 -/*
19390 - * The IDT has to be page-aligned to simplify the Pentium
19391 - * F0 0F bug workaround.
19392 - */
19393 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19394 #endif
19395
19396 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19397 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19398 }
19399
19400 static void __kprobes
19401 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19402 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19403 long error_code, siginfo_t *info)
19404 {
19405 struct task_struct *tsk = current;
19406
19407 #ifdef CONFIG_X86_32
19408 - if (regs->flags & X86_VM_MASK) {
19409 + if (v8086_mode(regs)) {
19410 /*
19411 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19412 * On nmi (interrupt 2), do_trap should not be called.
19413 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19414 }
19415 #endif
19416
19417 - if (!user_mode(regs))
19418 + if (!user_mode_novm(regs))
19419 goto kernel_trap;
19420
19421 #ifdef CONFIG_X86_32
19422 @@ -148,7 +142,7 @@ trap_signal:
19423 printk_ratelimit()) {
19424 printk(KERN_INFO
19425 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19426 - tsk->comm, tsk->pid, str,
19427 + tsk->comm, task_pid_nr(tsk), str,
19428 regs->ip, regs->sp, error_code);
19429 print_vma_addr(" in ", regs->ip);
19430 printk("\n");
19431 @@ -165,8 +159,20 @@ kernel_trap:
19432 if (!fixup_exception(regs)) {
19433 tsk->thread.error_code = error_code;
19434 tsk->thread.trap_no = trapnr;
19435 +
19436 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19437 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19438 + str = "PAX: suspicious stack segment fault";
19439 +#endif
19440 +
19441 die(str, regs, error_code);
19442 }
19443 +
19444 +#ifdef CONFIG_PAX_REFCOUNT
19445 + if (trapnr == 4)
19446 + pax_report_refcount_overflow(regs);
19447 +#endif
19448 +
19449 return;
19450
19451 #ifdef CONFIG_X86_32
19452 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19453 conditional_sti(regs);
19454
19455 #ifdef CONFIG_X86_32
19456 - if (regs->flags & X86_VM_MASK)
19457 + if (v8086_mode(regs))
19458 goto gp_in_vm86;
19459 #endif
19460
19461 tsk = current;
19462 - if (!user_mode(regs))
19463 + if (!user_mode_novm(regs))
19464 goto gp_in_kernel;
19465
19466 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19467 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19468 + struct mm_struct *mm = tsk->mm;
19469 + unsigned long limit;
19470 +
19471 + down_write(&mm->mmap_sem);
19472 + limit = mm->context.user_cs_limit;
19473 + if (limit < TASK_SIZE) {
19474 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19475 + up_write(&mm->mmap_sem);
19476 + return;
19477 + }
19478 + up_write(&mm->mmap_sem);
19479 + }
19480 +#endif
19481 +
19482 tsk->thread.error_code = error_code;
19483 tsk->thread.trap_no = 13;
19484
19485 @@ -295,6 +317,13 @@ gp_in_kernel:
19486 if (notify_die(DIE_GPF, "general protection fault", regs,
19487 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19488 return;
19489 +
19490 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19491 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19492 + die("PAX: suspicious general protection fault", regs, error_code);
19493 + else
19494 +#endif
19495 +
19496 die("general protection fault", regs, error_code);
19497 }
19498
19499 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19500 /* It's safe to allow irq's after DR6 has been saved */
19501 preempt_conditional_sti(regs);
19502
19503 - if (regs->flags & X86_VM_MASK) {
19504 + if (v8086_mode(regs)) {
19505 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19506 error_code, 1);
19507 preempt_conditional_cli(regs);
19508 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19509 * We already checked v86 mode above, so we can check for kernel mode
19510 * by just checking the CPL of CS.
19511 */
19512 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19513 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19514 tsk->thread.debugreg6 &= ~DR_STEP;
19515 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19516 regs->flags &= ~X86_EFLAGS_TF;
19517 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19518 return;
19519 conditional_sti(regs);
19520
19521 - if (!user_mode_vm(regs))
19522 + if (!user_mode(regs))
19523 {
19524 if (!fixup_exception(regs)) {
19525 task->thread.error_code = error_code;
19526 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19527 index b9242ba..50c5edd 100644
19528 --- a/arch/x86/kernel/verify_cpu.S
19529 +++ b/arch/x86/kernel/verify_cpu.S
19530 @@ -20,6 +20,7 @@
19531 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19532 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19533 * arch/x86/kernel/head_32.S: processor startup
19534 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19535 *
19536 * verify_cpu, returns the status of longmode and SSE in register %eax.
19537 * 0: Success 1: Failure
19538 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19539 index 328cb37..f37fee1 100644
19540 --- a/arch/x86/kernel/vm86_32.c
19541 +++ b/arch/x86/kernel/vm86_32.c
19542 @@ -41,6 +41,7 @@
19543 #include <linux/ptrace.h>
19544 #include <linux/audit.h>
19545 #include <linux/stddef.h>
19546 +#include <linux/grsecurity.h>
19547
19548 #include <asm/uaccess.h>
19549 #include <asm/io.h>
19550 @@ -109,6 +110,9 @@ static int copy_vm86_regs_to_user(struct vm86_regs __user *user,
19551 /* convert vm86_regs to kernel_vm86_regs */
19552 static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19553 const struct vm86_regs __user *user,
19554 + unsigned extra) __size_overflow(3);
19555 +static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
19556 + const struct vm86_regs __user *user,
19557 unsigned extra)
19558 {
19559 int ret = 0;
19560 @@ -148,7 +152,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19561 do_exit(SIGSEGV);
19562 }
19563
19564 - tss = &per_cpu(init_tss, get_cpu());
19565 + tss = init_tss + get_cpu();
19566 current->thread.sp0 = current->thread.saved_sp0;
19567 current->thread.sysenter_cs = __KERNEL_CS;
19568 load_sp0(tss, &current->thread);
19569 @@ -210,6 +214,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19570 struct task_struct *tsk;
19571 int tmp, ret = -EPERM;
19572
19573 +#ifdef CONFIG_GRKERNSEC_VM86
19574 + if (!capable(CAP_SYS_RAWIO)) {
19575 + gr_handle_vm86();
19576 + goto out;
19577 + }
19578 +#endif
19579 +
19580 tsk = current;
19581 if (tsk->thread.saved_sp0)
19582 goto out;
19583 @@ -240,6 +251,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19584 int tmp, ret;
19585 struct vm86plus_struct __user *v86;
19586
19587 +#ifdef CONFIG_GRKERNSEC_VM86
19588 + if (!capable(CAP_SYS_RAWIO)) {
19589 + gr_handle_vm86();
19590 + ret = -EPERM;
19591 + goto out;
19592 + }
19593 +#endif
19594 +
19595 tsk = current;
19596 switch (cmd) {
19597 case VM86_REQUEST_IRQ:
19598 @@ -326,7 +345,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19599 tsk->thread.saved_fs = info->regs32->fs;
19600 tsk->thread.saved_gs = get_user_gs(info->regs32);
19601
19602 - tss = &per_cpu(init_tss, get_cpu());
19603 + tss = init_tss + get_cpu();
19604 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19605 if (cpu_has_sep)
19606 tsk->thread.sysenter_cs = 0;
19607 @@ -533,7 +552,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19608 goto cannot_handle;
19609 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19610 goto cannot_handle;
19611 - intr_ptr = (unsigned long __user *) (i << 2);
19612 + intr_ptr = (__force unsigned long __user *) (i << 2);
19613 if (get_user(segoffs, intr_ptr))
19614 goto cannot_handle;
19615 if ((segoffs >> 16) == BIOSSEG)
19616 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19617 index 0f703f1..9e15f64 100644
19618 --- a/arch/x86/kernel/vmlinux.lds.S
19619 +++ b/arch/x86/kernel/vmlinux.lds.S
19620 @@ -26,6 +26,13 @@
19621 #include <asm/page_types.h>
19622 #include <asm/cache.h>
19623 #include <asm/boot.h>
19624 +#include <asm/segment.h>
19625 +
19626 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19627 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19628 +#else
19629 +#define __KERNEL_TEXT_OFFSET 0
19630 +#endif
19631
19632 #undef i386 /* in case the preprocessor is a 32bit one */
19633
19634 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19635
19636 PHDRS {
19637 text PT_LOAD FLAGS(5); /* R_E */
19638 +#ifdef CONFIG_X86_32
19639 + module PT_LOAD FLAGS(5); /* R_E */
19640 +#endif
19641 +#ifdef CONFIG_XEN
19642 + rodata PT_LOAD FLAGS(5); /* R_E */
19643 +#else
19644 + rodata PT_LOAD FLAGS(4); /* R__ */
19645 +#endif
19646 data PT_LOAD FLAGS(6); /* RW_ */
19647 -#ifdef CONFIG_X86_64
19648 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19649 #ifdef CONFIG_SMP
19650 percpu PT_LOAD FLAGS(6); /* RW_ */
19651 #endif
19652 + text.init PT_LOAD FLAGS(5); /* R_E */
19653 + text.exit PT_LOAD FLAGS(5); /* R_E */
19654 init PT_LOAD FLAGS(7); /* RWE */
19655 -#endif
19656 note PT_NOTE FLAGS(0); /* ___ */
19657 }
19658
19659 SECTIONS
19660 {
19661 #ifdef CONFIG_X86_32
19662 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19663 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19664 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19665 #else
19666 - . = __START_KERNEL;
19667 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19668 + . = __START_KERNEL;
19669 #endif
19670
19671 /* Text and read-only data */
19672 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19673 - _text = .;
19674 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19675 /* bootstrapping code */
19676 +#ifdef CONFIG_X86_32
19677 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19678 +#else
19679 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19680 +#endif
19681 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19682 + _text = .;
19683 HEAD_TEXT
19684 #ifdef CONFIG_X86_32
19685 . = ALIGN(PAGE_SIZE);
19686 @@ -108,13 +128,47 @@ SECTIONS
19687 IRQENTRY_TEXT
19688 *(.fixup)
19689 *(.gnu.warning)
19690 - /* End of text section */
19691 - _etext = .;
19692 } :text = 0x9090
19693
19694 - NOTES :text :note
19695 + . += __KERNEL_TEXT_OFFSET;
19696
19697 - EXCEPTION_TABLE(16) :text = 0x9090
19698 +#ifdef CONFIG_X86_32
19699 + . = ALIGN(PAGE_SIZE);
19700 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19701 +
19702 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19703 + MODULES_EXEC_VADDR = .;
19704 + BYTE(0)
19705 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19706 + . = ALIGN(HPAGE_SIZE);
19707 + MODULES_EXEC_END = . - 1;
19708 +#endif
19709 +
19710 + } :module
19711 +#endif
19712 +
19713 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19714 + /* End of text section */
19715 + _etext = . - __KERNEL_TEXT_OFFSET;
19716 + }
19717 +
19718 +#ifdef CONFIG_X86_32
19719 + . = ALIGN(PAGE_SIZE);
19720 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19721 + *(.idt)
19722 + . = ALIGN(PAGE_SIZE);
19723 + *(.empty_zero_page)
19724 + *(.initial_pg_fixmap)
19725 + *(.initial_pg_pmd)
19726 + *(.initial_page_table)
19727 + *(.swapper_pg_dir)
19728 + } :rodata
19729 +#endif
19730 +
19731 + . = ALIGN(PAGE_SIZE);
19732 + NOTES :rodata :note
19733 +
19734 + EXCEPTION_TABLE(16) :rodata
19735
19736 #if defined(CONFIG_DEBUG_RODATA)
19737 /* .text should occupy whole number of pages */
19738 @@ -126,16 +180,20 @@ SECTIONS
19739
19740 /* Data */
19741 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19742 +
19743 +#ifdef CONFIG_PAX_KERNEXEC
19744 + . = ALIGN(HPAGE_SIZE);
19745 +#else
19746 + . = ALIGN(PAGE_SIZE);
19747 +#endif
19748 +
19749 /* Start of data section */
19750 _sdata = .;
19751
19752 /* init_task */
19753 INIT_TASK_DATA(THREAD_SIZE)
19754
19755 -#ifdef CONFIG_X86_32
19756 - /* 32 bit has nosave before _edata */
19757 NOSAVE_DATA
19758 -#endif
19759
19760 PAGE_ALIGNED_DATA(PAGE_SIZE)
19761
19762 @@ -176,12 +234,19 @@ SECTIONS
19763 #endif /* CONFIG_X86_64 */
19764
19765 /* Init code and data - will be freed after init */
19766 - . = ALIGN(PAGE_SIZE);
19767 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19768 + BYTE(0)
19769 +
19770 +#ifdef CONFIG_PAX_KERNEXEC
19771 + . = ALIGN(HPAGE_SIZE);
19772 +#else
19773 + . = ALIGN(PAGE_SIZE);
19774 +#endif
19775 +
19776 __init_begin = .; /* paired with __init_end */
19777 - }
19778 + } :init.begin
19779
19780 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19781 +#ifdef CONFIG_SMP
19782 /*
19783 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19784 * output PHDR, so the next output section - .init.text - should
19785 @@ -190,12 +255,27 @@ SECTIONS
19786 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19787 #endif
19788
19789 - INIT_TEXT_SECTION(PAGE_SIZE)
19790 -#ifdef CONFIG_X86_64
19791 - :init
19792 -#endif
19793 + . = ALIGN(PAGE_SIZE);
19794 + init_begin = .;
19795 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19796 + VMLINUX_SYMBOL(_sinittext) = .;
19797 + INIT_TEXT
19798 + VMLINUX_SYMBOL(_einittext) = .;
19799 + . = ALIGN(PAGE_SIZE);
19800 + } :text.init
19801
19802 - INIT_DATA_SECTION(16)
19803 + /*
19804 + * .exit.text is discard at runtime, not link time, to deal with
19805 + * references from .altinstructions and .eh_frame
19806 + */
19807 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19808 + EXIT_TEXT
19809 + . = ALIGN(16);
19810 + } :text.exit
19811 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19812 +
19813 + . = ALIGN(PAGE_SIZE);
19814 + INIT_DATA_SECTION(16) :init
19815
19816 /*
19817 * Code and data for a variety of lowlevel trampolines, to be
19818 @@ -269,19 +349,12 @@ SECTIONS
19819 }
19820
19821 . = ALIGN(8);
19822 - /*
19823 - * .exit.text is discard at runtime, not link time, to deal with
19824 - * references from .altinstructions and .eh_frame
19825 - */
19826 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19827 - EXIT_TEXT
19828 - }
19829
19830 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19831 EXIT_DATA
19832 }
19833
19834 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19835 +#ifndef CONFIG_SMP
19836 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19837 #endif
19838
19839 @@ -300,16 +373,10 @@ SECTIONS
19840 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19841 __smp_locks = .;
19842 *(.smp_locks)
19843 - . = ALIGN(PAGE_SIZE);
19844 __smp_locks_end = .;
19845 + . = ALIGN(PAGE_SIZE);
19846 }
19847
19848 -#ifdef CONFIG_X86_64
19849 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19850 - NOSAVE_DATA
19851 - }
19852 -#endif
19853 -
19854 /* BSS */
19855 . = ALIGN(PAGE_SIZE);
19856 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19857 @@ -325,6 +392,7 @@ SECTIONS
19858 __brk_base = .;
19859 . += 64 * 1024; /* 64k alignment slop space */
19860 *(.brk_reservation) /* areas brk users have reserved */
19861 + . = ALIGN(HPAGE_SIZE);
19862 __brk_limit = .;
19863 }
19864
19865 @@ -351,13 +419,12 @@ SECTIONS
19866 * for the boot processor.
19867 */
19868 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19869 -INIT_PER_CPU(gdt_page);
19870 INIT_PER_CPU(irq_stack_union);
19871
19872 /*
19873 * Build-time check on the image size:
19874 */
19875 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19876 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19877 "kernel image bigger than KERNEL_IMAGE_SIZE");
19878
19879 #ifdef CONFIG_SMP
19880 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19881 index b07ba93..a212969 100644
19882 --- a/arch/x86/kernel/vsyscall_64.c
19883 +++ b/arch/x86/kernel/vsyscall_64.c
19884 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19885 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19886 };
19887
19888 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
19889 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19890
19891 static int __init vsyscall_setup(char *str)
19892 {
19893 if (str) {
19894 if (!strcmp("emulate", str))
19895 vsyscall_mode = EMULATE;
19896 - else if (!strcmp("native", str))
19897 - vsyscall_mode = NATIVE;
19898 else if (!strcmp("none", str))
19899 vsyscall_mode = NONE;
19900 else
19901 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19902
19903 tsk = current;
19904 if (seccomp_mode(&tsk->seccomp))
19905 - do_exit(SIGKILL);
19906 + do_group_exit(SIGKILL);
19907
19908 /*
19909 * With a real vsyscall, page faults cause SIGSEGV. We want to
19910 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19911 return true;
19912
19913 sigsegv:
19914 - force_sig(SIGSEGV, current);
19915 - return true;
19916 + do_group_exit(SIGKILL);
19917 }
19918
19919 /*
19920 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
19921 extern char __vvar_page;
19922 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19923
19924 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19925 - vsyscall_mode == NATIVE
19926 - ? PAGE_KERNEL_VSYSCALL
19927 - : PAGE_KERNEL_VVAR);
19928 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19929 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19930 (unsigned long)VSYSCALL_START);
19931
19932 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19933 index 9796c2f..f686fbf 100644
19934 --- a/arch/x86/kernel/x8664_ksyms_64.c
19935 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19936 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19937 EXPORT_SYMBOL(copy_user_generic_string);
19938 EXPORT_SYMBOL(copy_user_generic_unrolled);
19939 EXPORT_SYMBOL(__copy_user_nocache);
19940 -EXPORT_SYMBOL(_copy_from_user);
19941 -EXPORT_SYMBOL(_copy_to_user);
19942
19943 EXPORT_SYMBOL(copy_page);
19944 EXPORT_SYMBOL(clear_page);
19945 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19946 index 7110911..e8cdee5 100644
19947 --- a/arch/x86/kernel/xsave.c
19948 +++ b/arch/x86/kernel/xsave.c
19949 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19950 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19951 return -EINVAL;
19952
19953 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19954 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19955 fx_sw_user->extended_size -
19956 FP_XSTATE_MAGIC2_SIZE));
19957 if (err)
19958 @@ -266,7 +266,7 @@ fx_only:
19959 * the other extended state.
19960 */
19961 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19962 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19963 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19964 }
19965
19966 /*
19967 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19968 if (use_xsave())
19969 err = restore_user_xstate(buf);
19970 else
19971 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19972 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19973 buf);
19974 if (unlikely(err)) {
19975 /*
19976 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
19977 index 89b02bf..0f6511d 100644
19978 --- a/arch/x86/kvm/cpuid.c
19979 +++ b/arch/x86/kvm/cpuid.c
19980 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
19981 struct kvm_cpuid2 *cpuid,
19982 struct kvm_cpuid_entry2 __user *entries)
19983 {
19984 - int r;
19985 + int r, i;
19986
19987 r = -E2BIG;
19988 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
19989 goto out;
19990 r = -EFAULT;
19991 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
19992 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19993 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19994 goto out;
19995 + for (i = 0; i < cpuid->nent; ++i) {
19996 + struct kvm_cpuid_entry2 cpuid_entry;
19997 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
19998 + goto out;
19999 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20000 + }
20001 vcpu->arch.cpuid_nent = cpuid->nent;
20002 kvm_apic_set_version(vcpu);
20003 kvm_x86_ops->cpuid_update(vcpu);
20004 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20005 struct kvm_cpuid2 *cpuid,
20006 struct kvm_cpuid_entry2 __user *entries)
20007 {
20008 - int r;
20009 + int r, i;
20010
20011 r = -E2BIG;
20012 if (cpuid->nent < vcpu->arch.cpuid_nent)
20013 goto out;
20014 r = -EFAULT;
20015 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20016 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20017 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20018 goto out;
20019 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20020 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20021 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20022 + goto out;
20023 + }
20024 return 0;
20025
20026 out:
20027 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20028 index 0982507..7f6d72f 100644
20029 --- a/arch/x86/kvm/emulate.c
20030 +++ b/arch/x86/kvm/emulate.c
20031 @@ -250,6 +250,7 @@ struct gprefix {
20032
20033 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20034 do { \
20035 + unsigned long _tmp; \
20036 __asm__ __volatile__ ( \
20037 _PRE_EFLAGS("0", "4", "2") \
20038 _op _suffix " %"_x"3,%1; " \
20039 @@ -264,8 +265,6 @@ struct gprefix {
20040 /* Raw emulation: instruction has two explicit operands. */
20041 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20042 do { \
20043 - unsigned long _tmp; \
20044 - \
20045 switch ((ctxt)->dst.bytes) { \
20046 case 2: \
20047 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20048 @@ -281,7 +280,6 @@ struct gprefix {
20049
20050 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20051 do { \
20052 - unsigned long _tmp; \
20053 switch ((ctxt)->dst.bytes) { \
20054 case 1: \
20055 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20056 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20057 index cfdc6e0..ab92e84 100644
20058 --- a/arch/x86/kvm/lapic.c
20059 +++ b/arch/x86/kvm/lapic.c
20060 @@ -54,7 +54,7 @@
20061 #define APIC_BUS_CYCLE_NS 1
20062
20063 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20064 -#define apic_debug(fmt, arg...)
20065 +#define apic_debug(fmt, arg...) do {} while (0)
20066
20067 #define APIC_LVT_NUM 6
20068 /* 14 is the version for Xeon and Pentium 8.4.8*/
20069 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20070 index 1561028..0ed7f14 100644
20071 --- a/arch/x86/kvm/paging_tmpl.h
20072 +++ b/arch/x86/kvm/paging_tmpl.h
20073 @@ -197,7 +197,7 @@ retry_walk:
20074 if (unlikely(kvm_is_error_hva(host_addr)))
20075 goto error;
20076
20077 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20078 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20079 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20080 goto error;
20081
20082 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20083 index e385214..029e9dd 100644
20084 --- a/arch/x86/kvm/svm.c
20085 +++ b/arch/x86/kvm/svm.c
20086 @@ -3051,6 +3051,7 @@ static int svm_set_vm_cr(struct kvm_vcpu *vcpu, u64 data)
20087 return 0;
20088 }
20089
20090 +static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) __size_overflow(3);
20091 static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
20092 {
20093 struct vcpu_svm *svm = to_svm(vcpu);
20094 @@ -3420,7 +3421,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20095 int cpu = raw_smp_processor_id();
20096
20097 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20098 +
20099 + pax_open_kernel();
20100 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20101 + pax_close_kernel();
20102 +
20103 load_TR_desc();
20104 }
20105
20106 @@ -3798,6 +3803,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20107 #endif
20108 #endif
20109
20110 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20111 + __set_fs(current_thread_info()->addr_limit);
20112 +#endif
20113 +
20114 reload_tss(vcpu);
20115
20116 local_irq_disable();
20117 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20118 index 3b4c8d8..f457b63 100644
20119 --- a/arch/x86/kvm/vmx.c
20120 +++ b/arch/x86/kvm/vmx.c
20121 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
20122 struct desc_struct *descs;
20123
20124 descs = (void *)gdt->address;
20125 +
20126 + pax_open_kernel();
20127 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20128 + pax_close_kernel();
20129 +
20130 load_TR_desc();
20131 }
20132
20133 @@ -2631,8 +2635,11 @@ static __init int hardware_setup(void)
20134 if (!cpu_has_vmx_flexpriority())
20135 flexpriority_enabled = 0;
20136
20137 - if (!cpu_has_vmx_tpr_shadow())
20138 - kvm_x86_ops->update_cr8_intercept = NULL;
20139 + if (!cpu_has_vmx_tpr_shadow()) {
20140 + pax_open_kernel();
20141 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20142 + pax_close_kernel();
20143 + }
20144
20145 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20146 kvm_disable_largepages();
20147 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
20148 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20149
20150 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20151 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20152 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20153
20154 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20155 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20156 @@ -6184,6 +6191,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20157 "jmp .Lkvm_vmx_return \n\t"
20158 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20159 ".Lkvm_vmx_return: "
20160 +
20161 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20162 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20163 + ".Lkvm_vmx_return2: "
20164 +#endif
20165 +
20166 /* Save guest registers, load host registers, keep flags */
20167 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20168 "pop %0 \n\t"
20169 @@ -6232,6 +6245,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20170 #endif
20171 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20172 [wordsize]"i"(sizeof(ulong))
20173 +
20174 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20175 + ,[cs]"i"(__KERNEL_CS)
20176 +#endif
20177 +
20178 : "cc", "memory"
20179 , R"ax", R"bx", R"di", R"si"
20180 #ifdef CONFIG_X86_64
20181 @@ -6260,7 +6278,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20182 }
20183 }
20184
20185 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20186 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20187 +
20188 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20189 + loadsegment(fs, __KERNEL_PERCPU);
20190 +#endif
20191 +
20192 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20193 + __set_fs(current_thread_info()->addr_limit);
20194 +#endif
20195 +
20196 vmx->loaded_vmcs->launched = 1;
20197
20198 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20199 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20200 index 9cbfc06..943ffa6 100644
20201 --- a/arch/x86/kvm/x86.c
20202 +++ b/arch/x86/kvm/x86.c
20203 @@ -873,6 +873,7 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
20204 return kvm_set_msr(vcpu, index, *data);
20205 }
20206
20207 +static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) __size_overflow(2);
20208 static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
20209 {
20210 int version;
20211 @@ -1307,12 +1308,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 data)
20212 return 0;
20213 }
20214
20215 +static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) __size_overflow(2);
20216 static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20217 {
20218 struct kvm *kvm = vcpu->kvm;
20219 int lm = is_long_mode(vcpu);
20220 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20221 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20222 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20223 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20224 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20225 : kvm->arch.xen_hvm_config.blob_size_32;
20226 u32 page_num = data & ~PAGE_MASK;
20227 @@ -2145,6 +2147,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20228 if (n < msr_list.nmsrs)
20229 goto out;
20230 r = -EFAULT;
20231 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20232 + goto out;
20233 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20234 num_msrs_to_save * sizeof(u32)))
20235 goto out;
20236 @@ -2266,7 +2270,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20237 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20238 struct kvm_interrupt *irq)
20239 {
20240 - if (irq->irq < 0 || irq->irq >= 256)
20241 + if (irq->irq >= 256)
20242 return -EINVAL;
20243 if (irqchip_in_kernel(vcpu->kvm))
20244 return -ENXIO;
20245 @@ -3497,6 +3501,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
20246
20247 static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20248 struct kvm_vcpu *vcpu, u32 access,
20249 + struct x86_exception *exception) __size_overflow(1,3);
20250 +static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20251 + struct kvm_vcpu *vcpu, u32 access,
20252 struct x86_exception *exception)
20253 {
20254 void *data = val;
20255 @@ -3528,6 +3535,9 @@ out:
20256 /* used for instruction fetching */
20257 static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20258 gva_t addr, void *val, unsigned int bytes,
20259 + struct x86_exception *exception) __size_overflow(2,4);
20260 +static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20261 + gva_t addr, void *val, unsigned int bytes,
20262 struct x86_exception *exception)
20263 {
20264 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20265 @@ -3552,6 +3562,9 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
20266
20267 static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20268 gva_t addr, void *val, unsigned int bytes,
20269 + struct x86_exception *exception) __size_overflow(2,4);
20270 +static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20271 + gva_t addr, void *val, unsigned int bytes,
20272 struct x86_exception *exception)
20273 {
20274 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20275 @@ -3665,12 +3678,16 @@ static int read_prepare(struct kvm_vcpu *vcpu, void *val, int bytes)
20276 }
20277
20278 static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20279 + void *val, int bytes) __size_overflow(2);
20280 +static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20281 void *val, int bytes)
20282 {
20283 return !kvm_read_guest(vcpu->kvm, gpa, val, bytes);
20284 }
20285
20286 static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20287 + void *val, int bytes) __size_overflow(2);
20288 +static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20289 void *val, int bytes)
20290 {
20291 return emulator_write_phys(vcpu, gpa, val, bytes);
20292 @@ -3821,6 +3838,12 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20293 const void *old,
20294 const void *new,
20295 unsigned int bytes,
20296 + struct x86_exception *exception) __size_overflow(5);
20297 +static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20298 + unsigned long addr,
20299 + const void *old,
20300 + const void *new,
20301 + unsigned int bytes,
20302 struct x86_exception *exception)
20303 {
20304 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20305 @@ -4780,7 +4803,7 @@ static void kvm_set_mmio_spte_mask(void)
20306 kvm_mmu_set_mmio_spte_mask(mask);
20307 }
20308
20309 -int kvm_arch_init(void *opaque)
20310 +int kvm_arch_init(const void *opaque)
20311 {
20312 int r;
20313 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20314 diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
20315 index cb80c29..aeee86c 100644
20316 --- a/arch/x86/kvm/x86.h
20317 +++ b/arch/x86/kvm/x86.h
20318 @@ -116,11 +116,11 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
20319
20320 int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
20321 gva_t addr, void *val, unsigned int bytes,
20322 - struct x86_exception *exception);
20323 + struct x86_exception *exception) __size_overflow(2,4);
20324
20325 int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20326 gva_t addr, void *val, unsigned int bytes,
20327 - struct x86_exception *exception);
20328 + struct x86_exception *exception) __size_overflow(2,4);
20329
20330 extern u64 host_xcr0;
20331
20332 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20333 index 642d880..44e0f3f 100644
20334 --- a/arch/x86/lguest/boot.c
20335 +++ b/arch/x86/lguest/boot.c
20336 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20337 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20338 * Launcher to reboot us.
20339 */
20340 -static void lguest_restart(char *reason)
20341 +static __noreturn void lguest_restart(char *reason)
20342 {
20343 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20344 + BUG();
20345 }
20346
20347 /*G:050
20348 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20349 index 042f682..c92afb6 100644
20350 --- a/arch/x86/lib/atomic64_32.c
20351 +++ b/arch/x86/lib/atomic64_32.c
20352 @@ -8,18 +8,30 @@
20353
20354 long long atomic64_read_cx8(long long, const atomic64_t *v);
20355 EXPORT_SYMBOL(atomic64_read_cx8);
20356 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20357 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20358 long long atomic64_set_cx8(long long, const atomic64_t *v);
20359 EXPORT_SYMBOL(atomic64_set_cx8);
20360 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20361 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20362 long long atomic64_xchg_cx8(long long, unsigned high);
20363 EXPORT_SYMBOL(atomic64_xchg_cx8);
20364 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20365 EXPORT_SYMBOL(atomic64_add_return_cx8);
20366 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20367 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20368 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20369 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20370 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20371 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20372 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20373 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20374 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20375 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20376 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20377 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20378 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20379 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20380 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20381 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20382 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20383 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20384 #ifndef CONFIG_X86_CMPXCHG64
20385 long long atomic64_read_386(long long, const atomic64_t *v);
20386 EXPORT_SYMBOL(atomic64_read_386);
20387 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20388 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
20389 long long atomic64_set_386(long long, const atomic64_t *v);
20390 EXPORT_SYMBOL(atomic64_set_386);
20391 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20392 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
20393 long long atomic64_xchg_386(long long, unsigned high);
20394 EXPORT_SYMBOL(atomic64_xchg_386);
20395 long long atomic64_add_return_386(long long a, atomic64_t *v);
20396 EXPORT_SYMBOL(atomic64_add_return_386);
20397 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20398 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20399 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20400 EXPORT_SYMBOL(atomic64_sub_return_386);
20401 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20402 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20403 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20404 EXPORT_SYMBOL(atomic64_inc_return_386);
20405 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20406 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20407 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20408 EXPORT_SYMBOL(atomic64_dec_return_386);
20409 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20410 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20411 long long atomic64_add_386(long long a, atomic64_t *v);
20412 EXPORT_SYMBOL(atomic64_add_386);
20413 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20414 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
20415 long long atomic64_sub_386(long long a, atomic64_t *v);
20416 EXPORT_SYMBOL(atomic64_sub_386);
20417 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20418 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20419 long long atomic64_inc_386(long long a, atomic64_t *v);
20420 EXPORT_SYMBOL(atomic64_inc_386);
20421 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20422 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20423 long long atomic64_dec_386(long long a, atomic64_t *v);
20424 EXPORT_SYMBOL(atomic64_dec_386);
20425 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20426 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20427 long long atomic64_dec_if_positive_386(atomic64_t *v);
20428 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20429 int atomic64_inc_not_zero_386(atomic64_t *v);
20430 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20431 index e8e7e0d..56fd1b0 100644
20432 --- a/arch/x86/lib/atomic64_386_32.S
20433 +++ b/arch/x86/lib/atomic64_386_32.S
20434 @@ -48,6 +48,10 @@ BEGIN(read)
20435 movl (v), %eax
20436 movl 4(v), %edx
20437 RET_ENDP
20438 +BEGIN(read_unchecked)
20439 + movl (v), %eax
20440 + movl 4(v), %edx
20441 +RET_ENDP
20442 #undef v
20443
20444 #define v %esi
20445 @@ -55,6 +59,10 @@ BEGIN(set)
20446 movl %ebx, (v)
20447 movl %ecx, 4(v)
20448 RET_ENDP
20449 +BEGIN(set_unchecked)
20450 + movl %ebx, (v)
20451 + movl %ecx, 4(v)
20452 +RET_ENDP
20453 #undef v
20454
20455 #define v %esi
20456 @@ -70,6 +78,20 @@ RET_ENDP
20457 BEGIN(add)
20458 addl %eax, (v)
20459 adcl %edx, 4(v)
20460 +
20461 +#ifdef CONFIG_PAX_REFCOUNT
20462 + jno 0f
20463 + subl %eax, (v)
20464 + sbbl %edx, 4(v)
20465 + int $4
20466 +0:
20467 + _ASM_EXTABLE(0b, 0b)
20468 +#endif
20469 +
20470 +RET_ENDP
20471 +BEGIN(add_unchecked)
20472 + addl %eax, (v)
20473 + adcl %edx, 4(v)
20474 RET_ENDP
20475 #undef v
20476
20477 @@ -77,6 +99,24 @@ RET_ENDP
20478 BEGIN(add_return)
20479 addl (v), %eax
20480 adcl 4(v), %edx
20481 +
20482 +#ifdef CONFIG_PAX_REFCOUNT
20483 + into
20484 +1234:
20485 + _ASM_EXTABLE(1234b, 2f)
20486 +#endif
20487 +
20488 + movl %eax, (v)
20489 + movl %edx, 4(v)
20490 +
20491 +#ifdef CONFIG_PAX_REFCOUNT
20492 +2:
20493 +#endif
20494 +
20495 +RET_ENDP
20496 +BEGIN(add_return_unchecked)
20497 + addl (v), %eax
20498 + adcl 4(v), %edx
20499 movl %eax, (v)
20500 movl %edx, 4(v)
20501 RET_ENDP
20502 @@ -86,6 +126,20 @@ RET_ENDP
20503 BEGIN(sub)
20504 subl %eax, (v)
20505 sbbl %edx, 4(v)
20506 +
20507 +#ifdef CONFIG_PAX_REFCOUNT
20508 + jno 0f
20509 + addl %eax, (v)
20510 + adcl %edx, 4(v)
20511 + int $4
20512 +0:
20513 + _ASM_EXTABLE(0b, 0b)
20514 +#endif
20515 +
20516 +RET_ENDP
20517 +BEGIN(sub_unchecked)
20518 + subl %eax, (v)
20519 + sbbl %edx, 4(v)
20520 RET_ENDP
20521 #undef v
20522
20523 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20524 sbbl $0, %edx
20525 addl (v), %eax
20526 adcl 4(v), %edx
20527 +
20528 +#ifdef CONFIG_PAX_REFCOUNT
20529 + into
20530 +1234:
20531 + _ASM_EXTABLE(1234b, 2f)
20532 +#endif
20533 +
20534 + movl %eax, (v)
20535 + movl %edx, 4(v)
20536 +
20537 +#ifdef CONFIG_PAX_REFCOUNT
20538 +2:
20539 +#endif
20540 +
20541 +RET_ENDP
20542 +BEGIN(sub_return_unchecked)
20543 + negl %edx
20544 + negl %eax
20545 + sbbl $0, %edx
20546 + addl (v), %eax
20547 + adcl 4(v), %edx
20548 movl %eax, (v)
20549 movl %edx, 4(v)
20550 RET_ENDP
20551 @@ -105,6 +180,20 @@ RET_ENDP
20552 BEGIN(inc)
20553 addl $1, (v)
20554 adcl $0, 4(v)
20555 +
20556 +#ifdef CONFIG_PAX_REFCOUNT
20557 + jno 0f
20558 + subl $1, (v)
20559 + sbbl $0, 4(v)
20560 + int $4
20561 +0:
20562 + _ASM_EXTABLE(0b, 0b)
20563 +#endif
20564 +
20565 +RET_ENDP
20566 +BEGIN(inc_unchecked)
20567 + addl $1, (v)
20568 + adcl $0, 4(v)
20569 RET_ENDP
20570 #undef v
20571
20572 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20573 movl 4(v), %edx
20574 addl $1, %eax
20575 adcl $0, %edx
20576 +
20577 +#ifdef CONFIG_PAX_REFCOUNT
20578 + into
20579 +1234:
20580 + _ASM_EXTABLE(1234b, 2f)
20581 +#endif
20582 +
20583 + movl %eax, (v)
20584 + movl %edx, 4(v)
20585 +
20586 +#ifdef CONFIG_PAX_REFCOUNT
20587 +2:
20588 +#endif
20589 +
20590 +RET_ENDP
20591 +BEGIN(inc_return_unchecked)
20592 + movl (v), %eax
20593 + movl 4(v), %edx
20594 + addl $1, %eax
20595 + adcl $0, %edx
20596 movl %eax, (v)
20597 movl %edx, 4(v)
20598 RET_ENDP
20599 @@ -123,6 +232,20 @@ RET_ENDP
20600 BEGIN(dec)
20601 subl $1, (v)
20602 sbbl $0, 4(v)
20603 +
20604 +#ifdef CONFIG_PAX_REFCOUNT
20605 + jno 0f
20606 + addl $1, (v)
20607 + adcl $0, 4(v)
20608 + int $4
20609 +0:
20610 + _ASM_EXTABLE(0b, 0b)
20611 +#endif
20612 +
20613 +RET_ENDP
20614 +BEGIN(dec_unchecked)
20615 + subl $1, (v)
20616 + sbbl $0, 4(v)
20617 RET_ENDP
20618 #undef v
20619
20620 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20621 movl 4(v), %edx
20622 subl $1, %eax
20623 sbbl $0, %edx
20624 +
20625 +#ifdef CONFIG_PAX_REFCOUNT
20626 + into
20627 +1234:
20628 + _ASM_EXTABLE(1234b, 2f)
20629 +#endif
20630 +
20631 + movl %eax, (v)
20632 + movl %edx, 4(v)
20633 +
20634 +#ifdef CONFIG_PAX_REFCOUNT
20635 +2:
20636 +#endif
20637 +
20638 +RET_ENDP
20639 +BEGIN(dec_return_unchecked)
20640 + movl (v), %eax
20641 + movl 4(v), %edx
20642 + subl $1, %eax
20643 + sbbl $0, %edx
20644 movl %eax, (v)
20645 movl %edx, 4(v)
20646 RET_ENDP
20647 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20648 adcl %edx, %edi
20649 addl (v), %eax
20650 adcl 4(v), %edx
20651 +
20652 +#ifdef CONFIG_PAX_REFCOUNT
20653 + into
20654 +1234:
20655 + _ASM_EXTABLE(1234b, 2f)
20656 +#endif
20657 +
20658 cmpl %eax, %esi
20659 je 3f
20660 1:
20661 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20662 1:
20663 addl $1, %eax
20664 adcl $0, %edx
20665 +
20666 +#ifdef CONFIG_PAX_REFCOUNT
20667 + into
20668 +1234:
20669 + _ASM_EXTABLE(1234b, 2f)
20670 +#endif
20671 +
20672 movl %eax, (v)
20673 movl %edx, 4(v)
20674 movl $1, %eax
20675 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20676 movl 4(v), %edx
20677 subl $1, %eax
20678 sbbl $0, %edx
20679 +
20680 +#ifdef CONFIG_PAX_REFCOUNT
20681 + into
20682 +1234:
20683 + _ASM_EXTABLE(1234b, 1f)
20684 +#endif
20685 +
20686 js 1f
20687 movl %eax, (v)
20688 movl %edx, 4(v)
20689 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20690 index 391a083..d658e9f 100644
20691 --- a/arch/x86/lib/atomic64_cx8_32.S
20692 +++ b/arch/x86/lib/atomic64_cx8_32.S
20693 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20694 CFI_STARTPROC
20695
20696 read64 %ecx
20697 + pax_force_retaddr
20698 ret
20699 CFI_ENDPROC
20700 ENDPROC(atomic64_read_cx8)
20701
20702 +ENTRY(atomic64_read_unchecked_cx8)
20703 + CFI_STARTPROC
20704 +
20705 + read64 %ecx
20706 + pax_force_retaddr
20707 + ret
20708 + CFI_ENDPROC
20709 +ENDPROC(atomic64_read_unchecked_cx8)
20710 +
20711 ENTRY(atomic64_set_cx8)
20712 CFI_STARTPROC
20713
20714 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20715 cmpxchg8b (%esi)
20716 jne 1b
20717
20718 + pax_force_retaddr
20719 ret
20720 CFI_ENDPROC
20721 ENDPROC(atomic64_set_cx8)
20722
20723 +ENTRY(atomic64_set_unchecked_cx8)
20724 + CFI_STARTPROC
20725 +
20726 +1:
20727 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20728 + * are atomic on 586 and newer */
20729 + cmpxchg8b (%esi)
20730 + jne 1b
20731 +
20732 + pax_force_retaddr
20733 + ret
20734 + CFI_ENDPROC
20735 +ENDPROC(atomic64_set_unchecked_cx8)
20736 +
20737 ENTRY(atomic64_xchg_cx8)
20738 CFI_STARTPROC
20739
20740 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20741 cmpxchg8b (%esi)
20742 jne 1b
20743
20744 + pax_force_retaddr
20745 ret
20746 CFI_ENDPROC
20747 ENDPROC(atomic64_xchg_cx8)
20748
20749 -.macro addsub_return func ins insc
20750 -ENTRY(atomic64_\func\()_return_cx8)
20751 +.macro addsub_return func ins insc unchecked=""
20752 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20753 CFI_STARTPROC
20754 SAVE ebp
20755 SAVE ebx
20756 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20757 movl %edx, %ecx
20758 \ins\()l %esi, %ebx
20759 \insc\()l %edi, %ecx
20760 +
20761 +.ifb \unchecked
20762 +#ifdef CONFIG_PAX_REFCOUNT
20763 + into
20764 +2:
20765 + _ASM_EXTABLE(2b, 3f)
20766 +#endif
20767 +.endif
20768 +
20769 LOCK_PREFIX
20770 cmpxchg8b (%ebp)
20771 jne 1b
20772 -
20773 -10:
20774 movl %ebx, %eax
20775 movl %ecx, %edx
20776 +
20777 +.ifb \unchecked
20778 +#ifdef CONFIG_PAX_REFCOUNT
20779 +3:
20780 +#endif
20781 +.endif
20782 +
20783 RESTORE edi
20784 RESTORE esi
20785 RESTORE ebx
20786 RESTORE ebp
20787 + pax_force_retaddr
20788 ret
20789 CFI_ENDPROC
20790 -ENDPROC(atomic64_\func\()_return_cx8)
20791 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20792 .endm
20793
20794 addsub_return add add adc
20795 addsub_return sub sub sbb
20796 +addsub_return add add adc _unchecked
20797 +addsub_return sub sub sbb _unchecked
20798
20799 -.macro incdec_return func ins insc
20800 -ENTRY(atomic64_\func\()_return_cx8)
20801 +.macro incdec_return func ins insc unchecked
20802 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20803 CFI_STARTPROC
20804 SAVE ebx
20805
20806 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20807 movl %edx, %ecx
20808 \ins\()l $1, %ebx
20809 \insc\()l $0, %ecx
20810 +
20811 +.ifb \unchecked
20812 +#ifdef CONFIG_PAX_REFCOUNT
20813 + into
20814 +2:
20815 + _ASM_EXTABLE(2b, 3f)
20816 +#endif
20817 +.endif
20818 +
20819 LOCK_PREFIX
20820 cmpxchg8b (%esi)
20821 jne 1b
20822
20823 -10:
20824 movl %ebx, %eax
20825 movl %ecx, %edx
20826 +
20827 +.ifb \unchecked
20828 +#ifdef CONFIG_PAX_REFCOUNT
20829 +3:
20830 +#endif
20831 +.endif
20832 +
20833 RESTORE ebx
20834 + pax_force_retaddr
20835 ret
20836 CFI_ENDPROC
20837 -ENDPROC(atomic64_\func\()_return_cx8)
20838 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20839 .endm
20840
20841 incdec_return inc add adc
20842 incdec_return dec sub sbb
20843 +incdec_return inc add adc _unchecked
20844 +incdec_return dec sub sbb _unchecked
20845
20846 ENTRY(atomic64_dec_if_positive_cx8)
20847 CFI_STARTPROC
20848 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20849 movl %edx, %ecx
20850 subl $1, %ebx
20851 sbb $0, %ecx
20852 +
20853 +#ifdef CONFIG_PAX_REFCOUNT
20854 + into
20855 +1234:
20856 + _ASM_EXTABLE(1234b, 2f)
20857 +#endif
20858 +
20859 js 2f
20860 LOCK_PREFIX
20861 cmpxchg8b (%esi)
20862 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20863 movl %ebx, %eax
20864 movl %ecx, %edx
20865 RESTORE ebx
20866 + pax_force_retaddr
20867 ret
20868 CFI_ENDPROC
20869 ENDPROC(atomic64_dec_if_positive_cx8)
20870 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20871 movl %edx, %ecx
20872 addl %esi, %ebx
20873 adcl %edi, %ecx
20874 +
20875 +#ifdef CONFIG_PAX_REFCOUNT
20876 + into
20877 +1234:
20878 + _ASM_EXTABLE(1234b, 3f)
20879 +#endif
20880 +
20881 LOCK_PREFIX
20882 cmpxchg8b (%ebp)
20883 jne 1b
20884 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20885 CFI_ADJUST_CFA_OFFSET -8
20886 RESTORE ebx
20887 RESTORE ebp
20888 + pax_force_retaddr
20889 ret
20890 4:
20891 cmpl %edx, 4(%esp)
20892 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20893 movl %edx, %ecx
20894 addl $1, %ebx
20895 adcl $0, %ecx
20896 +
20897 +#ifdef CONFIG_PAX_REFCOUNT
20898 + into
20899 +1234:
20900 + _ASM_EXTABLE(1234b, 3f)
20901 +#endif
20902 +
20903 LOCK_PREFIX
20904 cmpxchg8b (%esi)
20905 jne 1b
20906 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20907 movl $1, %eax
20908 3:
20909 RESTORE ebx
20910 + pax_force_retaddr
20911 ret
20912 4:
20913 testl %edx, %edx
20914 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20915 index 78d16a5..fbcf666 100644
20916 --- a/arch/x86/lib/checksum_32.S
20917 +++ b/arch/x86/lib/checksum_32.S
20918 @@ -28,7 +28,8 @@
20919 #include <linux/linkage.h>
20920 #include <asm/dwarf2.h>
20921 #include <asm/errno.h>
20922 -
20923 +#include <asm/segment.h>
20924 +
20925 /*
20926 * computes a partial checksum, e.g. for TCP/UDP fragments
20927 */
20928 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20929
20930 #define ARGBASE 16
20931 #define FP 12
20932 -
20933 -ENTRY(csum_partial_copy_generic)
20934 +
20935 +ENTRY(csum_partial_copy_generic_to_user)
20936 CFI_STARTPROC
20937 +
20938 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20939 + pushl_cfi %gs
20940 + popl_cfi %es
20941 + jmp csum_partial_copy_generic
20942 +#endif
20943 +
20944 +ENTRY(csum_partial_copy_generic_from_user)
20945 +
20946 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20947 + pushl_cfi %gs
20948 + popl_cfi %ds
20949 +#endif
20950 +
20951 +ENTRY(csum_partial_copy_generic)
20952 subl $4,%esp
20953 CFI_ADJUST_CFA_OFFSET 4
20954 pushl_cfi %edi
20955 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
20956 jmp 4f
20957 SRC(1: movw (%esi), %bx )
20958 addl $2, %esi
20959 -DST( movw %bx, (%edi) )
20960 +DST( movw %bx, %es:(%edi) )
20961 addl $2, %edi
20962 addw %bx, %ax
20963 adcl $0, %eax
20964 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
20965 SRC(1: movl (%esi), %ebx )
20966 SRC( movl 4(%esi), %edx )
20967 adcl %ebx, %eax
20968 -DST( movl %ebx, (%edi) )
20969 +DST( movl %ebx, %es:(%edi) )
20970 adcl %edx, %eax
20971 -DST( movl %edx, 4(%edi) )
20972 +DST( movl %edx, %es:4(%edi) )
20973
20974 SRC( movl 8(%esi), %ebx )
20975 SRC( movl 12(%esi), %edx )
20976 adcl %ebx, %eax
20977 -DST( movl %ebx, 8(%edi) )
20978 +DST( movl %ebx, %es:8(%edi) )
20979 adcl %edx, %eax
20980 -DST( movl %edx, 12(%edi) )
20981 +DST( movl %edx, %es:12(%edi) )
20982
20983 SRC( movl 16(%esi), %ebx )
20984 SRC( movl 20(%esi), %edx )
20985 adcl %ebx, %eax
20986 -DST( movl %ebx, 16(%edi) )
20987 +DST( movl %ebx, %es:16(%edi) )
20988 adcl %edx, %eax
20989 -DST( movl %edx, 20(%edi) )
20990 +DST( movl %edx, %es:20(%edi) )
20991
20992 SRC( movl 24(%esi), %ebx )
20993 SRC( movl 28(%esi), %edx )
20994 adcl %ebx, %eax
20995 -DST( movl %ebx, 24(%edi) )
20996 +DST( movl %ebx, %es:24(%edi) )
20997 adcl %edx, %eax
20998 -DST( movl %edx, 28(%edi) )
20999 +DST( movl %edx, %es:28(%edi) )
21000
21001 lea 32(%esi), %esi
21002 lea 32(%edi), %edi
21003 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21004 shrl $2, %edx # This clears CF
21005 SRC(3: movl (%esi), %ebx )
21006 adcl %ebx, %eax
21007 -DST( movl %ebx, (%edi) )
21008 +DST( movl %ebx, %es:(%edi) )
21009 lea 4(%esi), %esi
21010 lea 4(%edi), %edi
21011 dec %edx
21012 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21013 jb 5f
21014 SRC( movw (%esi), %cx )
21015 leal 2(%esi), %esi
21016 -DST( movw %cx, (%edi) )
21017 +DST( movw %cx, %es:(%edi) )
21018 leal 2(%edi), %edi
21019 je 6f
21020 shll $16,%ecx
21021 SRC(5: movb (%esi), %cl )
21022 -DST( movb %cl, (%edi) )
21023 +DST( movb %cl, %es:(%edi) )
21024 6: addl %ecx, %eax
21025 adcl $0, %eax
21026 7:
21027 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21028
21029 6001:
21030 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21031 - movl $-EFAULT, (%ebx)
21032 + movl $-EFAULT, %ss:(%ebx)
21033
21034 # zero the complete destination - computing the rest
21035 # is too much work
21036 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21037
21038 6002:
21039 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21040 - movl $-EFAULT,(%ebx)
21041 + movl $-EFAULT,%ss:(%ebx)
21042 jmp 5000b
21043
21044 .previous
21045
21046 + pushl_cfi %ss
21047 + popl_cfi %ds
21048 + pushl_cfi %ss
21049 + popl_cfi %es
21050 popl_cfi %ebx
21051 CFI_RESTORE ebx
21052 popl_cfi %esi
21053 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21054 popl_cfi %ecx # equivalent to addl $4,%esp
21055 ret
21056 CFI_ENDPROC
21057 -ENDPROC(csum_partial_copy_generic)
21058 +ENDPROC(csum_partial_copy_generic_to_user)
21059
21060 #else
21061
21062 /* Version for PentiumII/PPro */
21063
21064 #define ROUND1(x) \
21065 + nop; nop; nop; \
21066 SRC(movl x(%esi), %ebx ) ; \
21067 addl %ebx, %eax ; \
21068 - DST(movl %ebx, x(%edi) ) ;
21069 + DST(movl %ebx, %es:x(%edi)) ;
21070
21071 #define ROUND(x) \
21072 + nop; nop; nop; \
21073 SRC(movl x(%esi), %ebx ) ; \
21074 adcl %ebx, %eax ; \
21075 - DST(movl %ebx, x(%edi) ) ;
21076 + DST(movl %ebx, %es:x(%edi)) ;
21077
21078 #define ARGBASE 12
21079 -
21080 -ENTRY(csum_partial_copy_generic)
21081 +
21082 +ENTRY(csum_partial_copy_generic_to_user)
21083 CFI_STARTPROC
21084 +
21085 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21086 + pushl_cfi %gs
21087 + popl_cfi %es
21088 + jmp csum_partial_copy_generic
21089 +#endif
21090 +
21091 +ENTRY(csum_partial_copy_generic_from_user)
21092 +
21093 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21094 + pushl_cfi %gs
21095 + popl_cfi %ds
21096 +#endif
21097 +
21098 +ENTRY(csum_partial_copy_generic)
21099 pushl_cfi %ebx
21100 CFI_REL_OFFSET ebx, 0
21101 pushl_cfi %edi
21102 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21103 subl %ebx, %edi
21104 lea -1(%esi),%edx
21105 andl $-32,%edx
21106 - lea 3f(%ebx,%ebx), %ebx
21107 + lea 3f(%ebx,%ebx,2), %ebx
21108 testl %esi, %esi
21109 jmp *%ebx
21110 1: addl $64,%esi
21111 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21112 jb 5f
21113 SRC( movw (%esi), %dx )
21114 leal 2(%esi), %esi
21115 -DST( movw %dx, (%edi) )
21116 +DST( movw %dx, %es:(%edi) )
21117 leal 2(%edi), %edi
21118 je 6f
21119 shll $16,%edx
21120 5:
21121 SRC( movb (%esi), %dl )
21122 -DST( movb %dl, (%edi) )
21123 +DST( movb %dl, %es:(%edi) )
21124 6: addl %edx, %eax
21125 adcl $0, %eax
21126 7:
21127 .section .fixup, "ax"
21128 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21129 - movl $-EFAULT, (%ebx)
21130 + movl $-EFAULT, %ss:(%ebx)
21131 # zero the complete destination (computing the rest is too much work)
21132 movl ARGBASE+8(%esp),%edi # dst
21133 movl ARGBASE+12(%esp),%ecx # len
21134 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21135 rep; stosb
21136 jmp 7b
21137 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21138 - movl $-EFAULT, (%ebx)
21139 + movl $-EFAULT, %ss:(%ebx)
21140 jmp 7b
21141 .previous
21142
21143 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21144 + pushl_cfi %ss
21145 + popl_cfi %ds
21146 + pushl_cfi %ss
21147 + popl_cfi %es
21148 +#endif
21149 +
21150 popl_cfi %esi
21151 CFI_RESTORE esi
21152 popl_cfi %edi
21153 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21154 CFI_RESTORE ebx
21155 ret
21156 CFI_ENDPROC
21157 -ENDPROC(csum_partial_copy_generic)
21158 +ENDPROC(csum_partial_copy_generic_to_user)
21159
21160 #undef ROUND
21161 #undef ROUND1
21162 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21163 index f2145cf..cea889d 100644
21164 --- a/arch/x86/lib/clear_page_64.S
21165 +++ b/arch/x86/lib/clear_page_64.S
21166 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21167 movl $4096/8,%ecx
21168 xorl %eax,%eax
21169 rep stosq
21170 + pax_force_retaddr
21171 ret
21172 CFI_ENDPROC
21173 ENDPROC(clear_page_c)
21174 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21175 movl $4096,%ecx
21176 xorl %eax,%eax
21177 rep stosb
21178 + pax_force_retaddr
21179 ret
21180 CFI_ENDPROC
21181 ENDPROC(clear_page_c_e)
21182 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21183 leaq 64(%rdi),%rdi
21184 jnz .Lloop
21185 nop
21186 + pax_force_retaddr
21187 ret
21188 CFI_ENDPROC
21189 .Lclear_page_end:
21190 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21191
21192 #include <asm/cpufeature.h>
21193
21194 - .section .altinstr_replacement,"ax"
21195 + .section .altinstr_replacement,"a"
21196 1: .byte 0xeb /* jmp <disp8> */
21197 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21198 2: .byte 0xeb /* jmp <disp8> */
21199 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21200 index 1e572c5..2a162cd 100644
21201 --- a/arch/x86/lib/cmpxchg16b_emu.S
21202 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21203 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21204
21205 popf
21206 mov $1, %al
21207 + pax_force_retaddr
21208 ret
21209
21210 not_same:
21211 popf
21212 xor %al,%al
21213 + pax_force_retaddr
21214 ret
21215
21216 CFI_ENDPROC
21217 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21218 index 01c805b..dccb07f 100644
21219 --- a/arch/x86/lib/copy_page_64.S
21220 +++ b/arch/x86/lib/copy_page_64.S
21221 @@ -9,6 +9,7 @@ copy_page_c:
21222 CFI_STARTPROC
21223 movl $4096/8,%ecx
21224 rep movsq
21225 + pax_force_retaddr
21226 ret
21227 CFI_ENDPROC
21228 ENDPROC(copy_page_c)
21229 @@ -39,7 +40,7 @@ ENTRY(copy_page)
21230 movq 16 (%rsi), %rdx
21231 movq 24 (%rsi), %r8
21232 movq 32 (%rsi), %r9
21233 - movq 40 (%rsi), %r10
21234 + movq 40 (%rsi), %r13
21235 movq 48 (%rsi), %r11
21236 movq 56 (%rsi), %r12
21237
21238 @@ -50,7 +51,7 @@ ENTRY(copy_page)
21239 movq %rdx, 16 (%rdi)
21240 movq %r8, 24 (%rdi)
21241 movq %r9, 32 (%rdi)
21242 - movq %r10, 40 (%rdi)
21243 + movq %r13, 40 (%rdi)
21244 movq %r11, 48 (%rdi)
21245 movq %r12, 56 (%rdi)
21246
21247 @@ -69,7 +70,7 @@ ENTRY(copy_page)
21248 movq 16 (%rsi), %rdx
21249 movq 24 (%rsi), %r8
21250 movq 32 (%rsi), %r9
21251 - movq 40 (%rsi), %r10
21252 + movq 40 (%rsi), %r13
21253 movq 48 (%rsi), %r11
21254 movq 56 (%rsi), %r12
21255
21256 @@ -78,7 +79,7 @@ ENTRY(copy_page)
21257 movq %rdx, 16 (%rdi)
21258 movq %r8, 24 (%rdi)
21259 movq %r9, 32 (%rdi)
21260 - movq %r10, 40 (%rdi)
21261 + movq %r13, 40 (%rdi)
21262 movq %r11, 48 (%rdi)
21263 movq %r12, 56 (%rdi)
21264
21265 @@ -95,6 +96,7 @@ ENTRY(copy_page)
21266 CFI_RESTORE r13
21267 addq $3*8,%rsp
21268 CFI_ADJUST_CFA_OFFSET -3*8
21269 + pax_force_retaddr
21270 ret
21271 .Lcopy_page_end:
21272 CFI_ENDPROC
21273 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
21274
21275 #include <asm/cpufeature.h>
21276
21277 - .section .altinstr_replacement,"ax"
21278 + .section .altinstr_replacement,"a"
21279 1: .byte 0xeb /* jmp <disp8> */
21280 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21281 2:
21282 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21283 index 0248402..821c786 100644
21284 --- a/arch/x86/lib/copy_user_64.S
21285 +++ b/arch/x86/lib/copy_user_64.S
21286 @@ -16,6 +16,7 @@
21287 #include <asm/thread_info.h>
21288 #include <asm/cpufeature.h>
21289 #include <asm/alternative-asm.h>
21290 +#include <asm/pgtable.h>
21291
21292 /*
21293 * By placing feature2 after feature1 in altinstructions section, we logically
21294 @@ -29,7 +30,7 @@
21295 .byte 0xe9 /* 32bit jump */
21296 .long \orig-1f /* by default jump to orig */
21297 1:
21298 - .section .altinstr_replacement,"ax"
21299 + .section .altinstr_replacement,"a"
21300 2: .byte 0xe9 /* near jump with 32bit immediate */
21301 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21302 3: .byte 0xe9 /* near jump with 32bit immediate */
21303 @@ -71,47 +72,20 @@
21304 #endif
21305 .endm
21306
21307 -/* Standard copy_to_user with segment limit checking */
21308 -ENTRY(_copy_to_user)
21309 - CFI_STARTPROC
21310 - GET_THREAD_INFO(%rax)
21311 - movq %rdi,%rcx
21312 - addq %rdx,%rcx
21313 - jc bad_to_user
21314 - cmpq TI_addr_limit(%rax),%rcx
21315 - ja bad_to_user
21316 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21317 - copy_user_generic_unrolled,copy_user_generic_string, \
21318 - copy_user_enhanced_fast_string
21319 - CFI_ENDPROC
21320 -ENDPROC(_copy_to_user)
21321 -
21322 -/* Standard copy_from_user with segment limit checking */
21323 -ENTRY(_copy_from_user)
21324 - CFI_STARTPROC
21325 - GET_THREAD_INFO(%rax)
21326 - movq %rsi,%rcx
21327 - addq %rdx,%rcx
21328 - jc bad_from_user
21329 - cmpq TI_addr_limit(%rax),%rcx
21330 - ja bad_from_user
21331 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21332 - copy_user_generic_unrolled,copy_user_generic_string, \
21333 - copy_user_enhanced_fast_string
21334 - CFI_ENDPROC
21335 -ENDPROC(_copy_from_user)
21336 -
21337 .section .fixup,"ax"
21338 /* must zero dest */
21339 ENTRY(bad_from_user)
21340 bad_from_user:
21341 CFI_STARTPROC
21342 + testl %edx,%edx
21343 + js bad_to_user
21344 movl %edx,%ecx
21345 xorl %eax,%eax
21346 rep
21347 stosb
21348 bad_to_user:
21349 movl %edx,%eax
21350 + pax_force_retaddr
21351 ret
21352 CFI_ENDPROC
21353 ENDPROC(bad_from_user)
21354 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21355 jz 17f
21356 1: movq (%rsi),%r8
21357 2: movq 1*8(%rsi),%r9
21358 -3: movq 2*8(%rsi),%r10
21359 +3: movq 2*8(%rsi),%rax
21360 4: movq 3*8(%rsi),%r11
21361 5: movq %r8,(%rdi)
21362 6: movq %r9,1*8(%rdi)
21363 -7: movq %r10,2*8(%rdi)
21364 +7: movq %rax,2*8(%rdi)
21365 8: movq %r11,3*8(%rdi)
21366 9: movq 4*8(%rsi),%r8
21367 10: movq 5*8(%rsi),%r9
21368 -11: movq 6*8(%rsi),%r10
21369 +11: movq 6*8(%rsi),%rax
21370 12: movq 7*8(%rsi),%r11
21371 13: movq %r8,4*8(%rdi)
21372 14: movq %r9,5*8(%rdi)
21373 -15: movq %r10,6*8(%rdi)
21374 +15: movq %rax,6*8(%rdi)
21375 16: movq %r11,7*8(%rdi)
21376 leaq 64(%rsi),%rsi
21377 leaq 64(%rdi),%rdi
21378 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21379 decl %ecx
21380 jnz 21b
21381 23: xor %eax,%eax
21382 + pax_force_retaddr
21383 ret
21384
21385 .section .fixup,"ax"
21386 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21387 3: rep
21388 movsb
21389 4: xorl %eax,%eax
21390 + pax_force_retaddr
21391 ret
21392
21393 .section .fixup,"ax"
21394 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21395 1: rep
21396 movsb
21397 2: xorl %eax,%eax
21398 + pax_force_retaddr
21399 ret
21400
21401 .section .fixup,"ax"
21402 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21403 index cb0c112..e3a6895 100644
21404 --- a/arch/x86/lib/copy_user_nocache_64.S
21405 +++ b/arch/x86/lib/copy_user_nocache_64.S
21406 @@ -8,12 +8,14 @@
21407
21408 #include <linux/linkage.h>
21409 #include <asm/dwarf2.h>
21410 +#include <asm/alternative-asm.h>
21411
21412 #define FIX_ALIGNMENT 1
21413
21414 #include <asm/current.h>
21415 #include <asm/asm-offsets.h>
21416 #include <asm/thread_info.h>
21417 +#include <asm/pgtable.h>
21418
21419 .macro ALIGN_DESTINATION
21420 #ifdef FIX_ALIGNMENT
21421 @@ -50,6 +52,15 @@
21422 */
21423 ENTRY(__copy_user_nocache)
21424 CFI_STARTPROC
21425 +
21426 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21427 + mov $PAX_USER_SHADOW_BASE,%rcx
21428 + cmp %rcx,%rsi
21429 + jae 1f
21430 + add %rcx,%rsi
21431 +1:
21432 +#endif
21433 +
21434 cmpl $8,%edx
21435 jb 20f /* less then 8 bytes, go to byte copy loop */
21436 ALIGN_DESTINATION
21437 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21438 jz 17f
21439 1: movq (%rsi),%r8
21440 2: movq 1*8(%rsi),%r9
21441 -3: movq 2*8(%rsi),%r10
21442 +3: movq 2*8(%rsi),%rax
21443 4: movq 3*8(%rsi),%r11
21444 5: movnti %r8,(%rdi)
21445 6: movnti %r9,1*8(%rdi)
21446 -7: movnti %r10,2*8(%rdi)
21447 +7: movnti %rax,2*8(%rdi)
21448 8: movnti %r11,3*8(%rdi)
21449 9: movq 4*8(%rsi),%r8
21450 10: movq 5*8(%rsi),%r9
21451 -11: movq 6*8(%rsi),%r10
21452 +11: movq 6*8(%rsi),%rax
21453 12: movq 7*8(%rsi),%r11
21454 13: movnti %r8,4*8(%rdi)
21455 14: movnti %r9,5*8(%rdi)
21456 -15: movnti %r10,6*8(%rdi)
21457 +15: movnti %rax,6*8(%rdi)
21458 16: movnti %r11,7*8(%rdi)
21459 leaq 64(%rsi),%rsi
21460 leaq 64(%rdi),%rdi
21461 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21462 jnz 21b
21463 23: xorl %eax,%eax
21464 sfence
21465 + pax_force_retaddr
21466 ret
21467
21468 .section .fixup,"ax"
21469 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21470 index fb903b7..c92b7f7 100644
21471 --- a/arch/x86/lib/csum-copy_64.S
21472 +++ b/arch/x86/lib/csum-copy_64.S
21473 @@ -8,6 +8,7 @@
21474 #include <linux/linkage.h>
21475 #include <asm/dwarf2.h>
21476 #include <asm/errno.h>
21477 +#include <asm/alternative-asm.h>
21478
21479 /*
21480 * Checksum copy with exception handling.
21481 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21482 CFI_RESTORE rbp
21483 addq $7*8, %rsp
21484 CFI_ADJUST_CFA_OFFSET -7*8
21485 + pax_force_retaddr 0, 1
21486 ret
21487 CFI_RESTORE_STATE
21488
21489 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21490 index 459b58a..9570bc7 100644
21491 --- a/arch/x86/lib/csum-wrappers_64.c
21492 +++ b/arch/x86/lib/csum-wrappers_64.c
21493 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21494 len -= 2;
21495 }
21496 }
21497 - isum = csum_partial_copy_generic((__force const void *)src,
21498 +
21499 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21500 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21501 + src += PAX_USER_SHADOW_BASE;
21502 +#endif
21503 +
21504 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21505 dst, len, isum, errp, NULL);
21506 if (unlikely(*errp))
21507 goto out_err;
21508 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21509 }
21510
21511 *errp = 0;
21512 - return csum_partial_copy_generic(src, (void __force *)dst,
21513 +
21514 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21515 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21516 + dst += PAX_USER_SHADOW_BASE;
21517 +#endif
21518 +
21519 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21520 len, isum, NULL, errp);
21521 }
21522 EXPORT_SYMBOL(csum_partial_copy_to_user);
21523 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21524 index 51f1504..ddac4c1 100644
21525 --- a/arch/x86/lib/getuser.S
21526 +++ b/arch/x86/lib/getuser.S
21527 @@ -33,15 +33,38 @@
21528 #include <asm/asm-offsets.h>
21529 #include <asm/thread_info.h>
21530 #include <asm/asm.h>
21531 +#include <asm/segment.h>
21532 +#include <asm/pgtable.h>
21533 +#include <asm/alternative-asm.h>
21534 +
21535 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21536 +#define __copyuser_seg gs;
21537 +#else
21538 +#define __copyuser_seg
21539 +#endif
21540
21541 .text
21542 ENTRY(__get_user_1)
21543 CFI_STARTPROC
21544 +
21545 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21546 GET_THREAD_INFO(%_ASM_DX)
21547 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21548 jae bad_get_user
21549 -1: movzb (%_ASM_AX),%edx
21550 +
21551 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21552 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21553 + cmp %_ASM_DX,%_ASM_AX
21554 + jae 1234f
21555 + add %_ASM_DX,%_ASM_AX
21556 +1234:
21557 +#endif
21558 +
21559 +#endif
21560 +
21561 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21562 xor %eax,%eax
21563 + pax_force_retaddr
21564 ret
21565 CFI_ENDPROC
21566 ENDPROC(__get_user_1)
21567 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21568 ENTRY(__get_user_2)
21569 CFI_STARTPROC
21570 add $1,%_ASM_AX
21571 +
21572 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21573 jc bad_get_user
21574 GET_THREAD_INFO(%_ASM_DX)
21575 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21576 jae bad_get_user
21577 -2: movzwl -1(%_ASM_AX),%edx
21578 +
21579 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21580 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21581 + cmp %_ASM_DX,%_ASM_AX
21582 + jae 1234f
21583 + add %_ASM_DX,%_ASM_AX
21584 +1234:
21585 +#endif
21586 +
21587 +#endif
21588 +
21589 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21590 xor %eax,%eax
21591 + pax_force_retaddr
21592 ret
21593 CFI_ENDPROC
21594 ENDPROC(__get_user_2)
21595 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21596 ENTRY(__get_user_4)
21597 CFI_STARTPROC
21598 add $3,%_ASM_AX
21599 +
21600 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21601 jc bad_get_user
21602 GET_THREAD_INFO(%_ASM_DX)
21603 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21604 jae bad_get_user
21605 -3: mov -3(%_ASM_AX),%edx
21606 +
21607 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21608 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21609 + cmp %_ASM_DX,%_ASM_AX
21610 + jae 1234f
21611 + add %_ASM_DX,%_ASM_AX
21612 +1234:
21613 +#endif
21614 +
21615 +#endif
21616 +
21617 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21618 xor %eax,%eax
21619 + pax_force_retaddr
21620 ret
21621 CFI_ENDPROC
21622 ENDPROC(__get_user_4)
21623 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21624 GET_THREAD_INFO(%_ASM_DX)
21625 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21626 jae bad_get_user
21627 +
21628 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21629 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21630 + cmp %_ASM_DX,%_ASM_AX
21631 + jae 1234f
21632 + add %_ASM_DX,%_ASM_AX
21633 +1234:
21634 +#endif
21635 +
21636 4: movq -7(%_ASM_AX),%_ASM_DX
21637 xor %eax,%eax
21638 + pax_force_retaddr
21639 ret
21640 CFI_ENDPROC
21641 ENDPROC(__get_user_8)
21642 @@ -91,6 +152,7 @@ bad_get_user:
21643 CFI_STARTPROC
21644 xor %edx,%edx
21645 mov $(-EFAULT),%_ASM_AX
21646 + pax_force_retaddr
21647 ret
21648 CFI_ENDPROC
21649 END(bad_get_user)
21650 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21651 index 5a1f9f3..ba9f577 100644
21652 --- a/arch/x86/lib/insn.c
21653 +++ b/arch/x86/lib/insn.c
21654 @@ -21,6 +21,11 @@
21655 #include <linux/string.h>
21656 #include <asm/inat.h>
21657 #include <asm/insn.h>
21658 +#ifdef __KERNEL__
21659 +#include <asm/pgtable_types.h>
21660 +#else
21661 +#define ktla_ktva(addr) addr
21662 +#endif
21663
21664 /* Verify next sizeof(t) bytes can be on the same instruction */
21665 #define validate_next(t, insn, n) \
21666 @@ -49,8 +54,8 @@
21667 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21668 {
21669 memset(insn, 0, sizeof(*insn));
21670 - insn->kaddr = kaddr;
21671 - insn->next_byte = kaddr;
21672 + insn->kaddr = ktla_ktva(kaddr);
21673 + insn->next_byte = ktla_ktva(kaddr);
21674 insn->x86_64 = x86_64 ? 1 : 0;
21675 insn->opnd_bytes = 4;
21676 if (x86_64)
21677 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21678 index 05a95e7..326f2fa 100644
21679 --- a/arch/x86/lib/iomap_copy_64.S
21680 +++ b/arch/x86/lib/iomap_copy_64.S
21681 @@ -17,6 +17,7 @@
21682
21683 #include <linux/linkage.h>
21684 #include <asm/dwarf2.h>
21685 +#include <asm/alternative-asm.h>
21686
21687 /*
21688 * override generic version in lib/iomap_copy.c
21689 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21690 CFI_STARTPROC
21691 movl %edx,%ecx
21692 rep movsd
21693 + pax_force_retaddr
21694 ret
21695 CFI_ENDPROC
21696 ENDPROC(__iowrite32_copy)
21697 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21698 index efbf2a0..8893637 100644
21699 --- a/arch/x86/lib/memcpy_64.S
21700 +++ b/arch/x86/lib/memcpy_64.S
21701 @@ -34,6 +34,7 @@
21702 rep movsq
21703 movl %edx, %ecx
21704 rep movsb
21705 + pax_force_retaddr
21706 ret
21707 .Lmemcpy_e:
21708 .previous
21709 @@ -51,6 +52,7 @@
21710
21711 movl %edx, %ecx
21712 rep movsb
21713 + pax_force_retaddr
21714 ret
21715 .Lmemcpy_e_e:
21716 .previous
21717 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21718 */
21719 movq 0*8(%rsi), %r8
21720 movq 1*8(%rsi), %r9
21721 - movq 2*8(%rsi), %r10
21722 + movq 2*8(%rsi), %rcx
21723 movq 3*8(%rsi), %r11
21724 leaq 4*8(%rsi), %rsi
21725
21726 movq %r8, 0*8(%rdi)
21727 movq %r9, 1*8(%rdi)
21728 - movq %r10, 2*8(%rdi)
21729 + movq %rcx, 2*8(%rdi)
21730 movq %r11, 3*8(%rdi)
21731 leaq 4*8(%rdi), %rdi
21732 jae .Lcopy_forward_loop
21733 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21734 subq $0x20, %rdx
21735 movq -1*8(%rsi), %r8
21736 movq -2*8(%rsi), %r9
21737 - movq -3*8(%rsi), %r10
21738 + movq -3*8(%rsi), %rcx
21739 movq -4*8(%rsi), %r11
21740 leaq -4*8(%rsi), %rsi
21741 movq %r8, -1*8(%rdi)
21742 movq %r9, -2*8(%rdi)
21743 - movq %r10, -3*8(%rdi)
21744 + movq %rcx, -3*8(%rdi)
21745 movq %r11, -4*8(%rdi)
21746 leaq -4*8(%rdi), %rdi
21747 jae .Lcopy_backward_loop
21748 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21749 */
21750 movq 0*8(%rsi), %r8
21751 movq 1*8(%rsi), %r9
21752 - movq -2*8(%rsi, %rdx), %r10
21753 + movq -2*8(%rsi, %rdx), %rcx
21754 movq -1*8(%rsi, %rdx), %r11
21755 movq %r8, 0*8(%rdi)
21756 movq %r9, 1*8(%rdi)
21757 - movq %r10, -2*8(%rdi, %rdx)
21758 + movq %rcx, -2*8(%rdi, %rdx)
21759 movq %r11, -1*8(%rdi, %rdx)
21760 + pax_force_retaddr
21761 retq
21762 .p2align 4
21763 .Lless_16bytes:
21764 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21765 movq -1*8(%rsi, %rdx), %r9
21766 movq %r8, 0*8(%rdi)
21767 movq %r9, -1*8(%rdi, %rdx)
21768 + pax_force_retaddr
21769 retq
21770 .p2align 4
21771 .Lless_8bytes:
21772 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21773 movl -4(%rsi, %rdx), %r8d
21774 movl %ecx, (%rdi)
21775 movl %r8d, -4(%rdi, %rdx)
21776 + pax_force_retaddr
21777 retq
21778 .p2align 4
21779 .Lless_3bytes:
21780 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21781 jnz .Lloop_1
21782
21783 .Lend:
21784 + pax_force_retaddr
21785 retq
21786 CFI_ENDPROC
21787 ENDPROC(memcpy)
21788 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21789 index ee16461..c39c199 100644
21790 --- a/arch/x86/lib/memmove_64.S
21791 +++ b/arch/x86/lib/memmove_64.S
21792 @@ -61,13 +61,13 @@ ENTRY(memmove)
21793 5:
21794 sub $0x20, %rdx
21795 movq 0*8(%rsi), %r11
21796 - movq 1*8(%rsi), %r10
21797 + movq 1*8(%rsi), %rcx
21798 movq 2*8(%rsi), %r9
21799 movq 3*8(%rsi), %r8
21800 leaq 4*8(%rsi), %rsi
21801
21802 movq %r11, 0*8(%rdi)
21803 - movq %r10, 1*8(%rdi)
21804 + movq %rcx, 1*8(%rdi)
21805 movq %r9, 2*8(%rdi)
21806 movq %r8, 3*8(%rdi)
21807 leaq 4*8(%rdi), %rdi
21808 @@ -81,10 +81,10 @@ ENTRY(memmove)
21809 4:
21810 movq %rdx, %rcx
21811 movq -8(%rsi, %rdx), %r11
21812 - lea -8(%rdi, %rdx), %r10
21813 + lea -8(%rdi, %rdx), %r9
21814 shrq $3, %rcx
21815 rep movsq
21816 - movq %r11, (%r10)
21817 + movq %r11, (%r9)
21818 jmp 13f
21819 .Lmemmove_end_forward:
21820
21821 @@ -95,14 +95,14 @@ ENTRY(memmove)
21822 7:
21823 movq %rdx, %rcx
21824 movq (%rsi), %r11
21825 - movq %rdi, %r10
21826 + movq %rdi, %r9
21827 leaq -8(%rsi, %rdx), %rsi
21828 leaq -8(%rdi, %rdx), %rdi
21829 shrq $3, %rcx
21830 std
21831 rep movsq
21832 cld
21833 - movq %r11, (%r10)
21834 + movq %r11, (%r9)
21835 jmp 13f
21836
21837 /*
21838 @@ -127,13 +127,13 @@ ENTRY(memmove)
21839 8:
21840 subq $0x20, %rdx
21841 movq -1*8(%rsi), %r11
21842 - movq -2*8(%rsi), %r10
21843 + movq -2*8(%rsi), %rcx
21844 movq -3*8(%rsi), %r9
21845 movq -4*8(%rsi), %r8
21846 leaq -4*8(%rsi), %rsi
21847
21848 movq %r11, -1*8(%rdi)
21849 - movq %r10, -2*8(%rdi)
21850 + movq %rcx, -2*8(%rdi)
21851 movq %r9, -3*8(%rdi)
21852 movq %r8, -4*8(%rdi)
21853 leaq -4*8(%rdi), %rdi
21854 @@ -151,11 +151,11 @@ ENTRY(memmove)
21855 * Move data from 16 bytes to 31 bytes.
21856 */
21857 movq 0*8(%rsi), %r11
21858 - movq 1*8(%rsi), %r10
21859 + movq 1*8(%rsi), %rcx
21860 movq -2*8(%rsi, %rdx), %r9
21861 movq -1*8(%rsi, %rdx), %r8
21862 movq %r11, 0*8(%rdi)
21863 - movq %r10, 1*8(%rdi)
21864 + movq %rcx, 1*8(%rdi)
21865 movq %r9, -2*8(%rdi, %rdx)
21866 movq %r8, -1*8(%rdi, %rdx)
21867 jmp 13f
21868 @@ -167,9 +167,9 @@ ENTRY(memmove)
21869 * Move data from 8 bytes to 15 bytes.
21870 */
21871 movq 0*8(%rsi), %r11
21872 - movq -1*8(%rsi, %rdx), %r10
21873 + movq -1*8(%rsi, %rdx), %r9
21874 movq %r11, 0*8(%rdi)
21875 - movq %r10, -1*8(%rdi, %rdx)
21876 + movq %r9, -1*8(%rdi, %rdx)
21877 jmp 13f
21878 10:
21879 cmpq $4, %rdx
21880 @@ -178,9 +178,9 @@ ENTRY(memmove)
21881 * Move data from 4 bytes to 7 bytes.
21882 */
21883 movl (%rsi), %r11d
21884 - movl -4(%rsi, %rdx), %r10d
21885 + movl -4(%rsi, %rdx), %r9d
21886 movl %r11d, (%rdi)
21887 - movl %r10d, -4(%rdi, %rdx)
21888 + movl %r9d, -4(%rdi, %rdx)
21889 jmp 13f
21890 11:
21891 cmp $2, %rdx
21892 @@ -189,9 +189,9 @@ ENTRY(memmove)
21893 * Move data from 2 bytes to 3 bytes.
21894 */
21895 movw (%rsi), %r11w
21896 - movw -2(%rsi, %rdx), %r10w
21897 + movw -2(%rsi, %rdx), %r9w
21898 movw %r11w, (%rdi)
21899 - movw %r10w, -2(%rdi, %rdx)
21900 + movw %r9w, -2(%rdi, %rdx)
21901 jmp 13f
21902 12:
21903 cmp $1, %rdx
21904 @@ -202,6 +202,7 @@ ENTRY(memmove)
21905 movb (%rsi), %r11b
21906 movb %r11b, (%rdi)
21907 13:
21908 + pax_force_retaddr
21909 retq
21910 CFI_ENDPROC
21911
21912 @@ -210,6 +211,7 @@ ENTRY(memmove)
21913 /* Forward moving data. */
21914 movq %rdx, %rcx
21915 rep movsb
21916 + pax_force_retaddr
21917 retq
21918 .Lmemmove_end_forward_efs:
21919 .previous
21920 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21921 index 79bd454..dff325a 100644
21922 --- a/arch/x86/lib/memset_64.S
21923 +++ b/arch/x86/lib/memset_64.S
21924 @@ -31,6 +31,7 @@
21925 movl %r8d,%ecx
21926 rep stosb
21927 movq %r9,%rax
21928 + pax_force_retaddr
21929 ret
21930 .Lmemset_e:
21931 .previous
21932 @@ -53,6 +54,7 @@
21933 movl %edx,%ecx
21934 rep stosb
21935 movq %r9,%rax
21936 + pax_force_retaddr
21937 ret
21938 .Lmemset_e_e:
21939 .previous
21940 @@ -60,13 +62,13 @@
21941 ENTRY(memset)
21942 ENTRY(__memset)
21943 CFI_STARTPROC
21944 - movq %rdi,%r10
21945 movq %rdx,%r11
21946
21947 /* expand byte value */
21948 movzbl %sil,%ecx
21949 movabs $0x0101010101010101,%rax
21950 mul %rcx /* with rax, clobbers rdx */
21951 + movq %rdi,%rdx
21952
21953 /* align dst */
21954 movl %edi,%r9d
21955 @@ -120,7 +122,8 @@ ENTRY(__memset)
21956 jnz .Lloop_1
21957
21958 .Lende:
21959 - movq %r10,%rax
21960 + movq %rdx,%rax
21961 + pax_force_retaddr
21962 ret
21963
21964 CFI_RESTORE_STATE
21965 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21966 index c9f2d9b..e7fd2c0 100644
21967 --- a/arch/x86/lib/mmx_32.c
21968 +++ b/arch/x86/lib/mmx_32.c
21969 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21970 {
21971 void *p;
21972 int i;
21973 + unsigned long cr0;
21974
21975 if (unlikely(in_interrupt()))
21976 return __memcpy(to, from, len);
21977 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21978 kernel_fpu_begin();
21979
21980 __asm__ __volatile__ (
21981 - "1: prefetch (%0)\n" /* This set is 28 bytes */
21982 - " prefetch 64(%0)\n"
21983 - " prefetch 128(%0)\n"
21984 - " prefetch 192(%0)\n"
21985 - " prefetch 256(%0)\n"
21986 + "1: prefetch (%1)\n" /* This set is 28 bytes */
21987 + " prefetch 64(%1)\n"
21988 + " prefetch 128(%1)\n"
21989 + " prefetch 192(%1)\n"
21990 + " prefetch 256(%1)\n"
21991 "2: \n"
21992 ".section .fixup, \"ax\"\n"
21993 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21994 + "3: \n"
21995 +
21996 +#ifdef CONFIG_PAX_KERNEXEC
21997 + " movl %%cr0, %0\n"
21998 + " movl %0, %%eax\n"
21999 + " andl $0xFFFEFFFF, %%eax\n"
22000 + " movl %%eax, %%cr0\n"
22001 +#endif
22002 +
22003 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22004 +
22005 +#ifdef CONFIG_PAX_KERNEXEC
22006 + " movl %0, %%cr0\n"
22007 +#endif
22008 +
22009 " jmp 2b\n"
22010 ".previous\n"
22011 _ASM_EXTABLE(1b, 3b)
22012 - : : "r" (from));
22013 + : "=&r" (cr0) : "r" (from) : "ax");
22014
22015 for ( ; i > 5; i--) {
22016 __asm__ __volatile__ (
22017 - "1: prefetch 320(%0)\n"
22018 - "2: movq (%0), %%mm0\n"
22019 - " movq 8(%0), %%mm1\n"
22020 - " movq 16(%0), %%mm2\n"
22021 - " movq 24(%0), %%mm3\n"
22022 - " movq %%mm0, (%1)\n"
22023 - " movq %%mm1, 8(%1)\n"
22024 - " movq %%mm2, 16(%1)\n"
22025 - " movq %%mm3, 24(%1)\n"
22026 - " movq 32(%0), %%mm0\n"
22027 - " movq 40(%0), %%mm1\n"
22028 - " movq 48(%0), %%mm2\n"
22029 - " movq 56(%0), %%mm3\n"
22030 - " movq %%mm0, 32(%1)\n"
22031 - " movq %%mm1, 40(%1)\n"
22032 - " movq %%mm2, 48(%1)\n"
22033 - " movq %%mm3, 56(%1)\n"
22034 + "1: prefetch 320(%1)\n"
22035 + "2: movq (%1), %%mm0\n"
22036 + " movq 8(%1), %%mm1\n"
22037 + " movq 16(%1), %%mm2\n"
22038 + " movq 24(%1), %%mm3\n"
22039 + " movq %%mm0, (%2)\n"
22040 + " movq %%mm1, 8(%2)\n"
22041 + " movq %%mm2, 16(%2)\n"
22042 + " movq %%mm3, 24(%2)\n"
22043 + " movq 32(%1), %%mm0\n"
22044 + " movq 40(%1), %%mm1\n"
22045 + " movq 48(%1), %%mm2\n"
22046 + " movq 56(%1), %%mm3\n"
22047 + " movq %%mm0, 32(%2)\n"
22048 + " movq %%mm1, 40(%2)\n"
22049 + " movq %%mm2, 48(%2)\n"
22050 + " movq %%mm3, 56(%2)\n"
22051 ".section .fixup, \"ax\"\n"
22052 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22053 + "3:\n"
22054 +
22055 +#ifdef CONFIG_PAX_KERNEXEC
22056 + " movl %%cr0, %0\n"
22057 + " movl %0, %%eax\n"
22058 + " andl $0xFFFEFFFF, %%eax\n"
22059 + " movl %%eax, %%cr0\n"
22060 +#endif
22061 +
22062 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22063 +
22064 +#ifdef CONFIG_PAX_KERNEXEC
22065 + " movl %0, %%cr0\n"
22066 +#endif
22067 +
22068 " jmp 2b\n"
22069 ".previous\n"
22070 _ASM_EXTABLE(1b, 3b)
22071 - : : "r" (from), "r" (to) : "memory");
22072 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22073
22074 from += 64;
22075 to += 64;
22076 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22077 static void fast_copy_page(void *to, void *from)
22078 {
22079 int i;
22080 + unsigned long cr0;
22081
22082 kernel_fpu_begin();
22083
22084 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22085 * but that is for later. -AV
22086 */
22087 __asm__ __volatile__(
22088 - "1: prefetch (%0)\n"
22089 - " prefetch 64(%0)\n"
22090 - " prefetch 128(%0)\n"
22091 - " prefetch 192(%0)\n"
22092 - " prefetch 256(%0)\n"
22093 + "1: prefetch (%1)\n"
22094 + " prefetch 64(%1)\n"
22095 + " prefetch 128(%1)\n"
22096 + " prefetch 192(%1)\n"
22097 + " prefetch 256(%1)\n"
22098 "2: \n"
22099 ".section .fixup, \"ax\"\n"
22100 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22101 + "3: \n"
22102 +
22103 +#ifdef CONFIG_PAX_KERNEXEC
22104 + " movl %%cr0, %0\n"
22105 + " movl %0, %%eax\n"
22106 + " andl $0xFFFEFFFF, %%eax\n"
22107 + " movl %%eax, %%cr0\n"
22108 +#endif
22109 +
22110 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22111 +
22112 +#ifdef CONFIG_PAX_KERNEXEC
22113 + " movl %0, %%cr0\n"
22114 +#endif
22115 +
22116 " jmp 2b\n"
22117 ".previous\n"
22118 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22119 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22120
22121 for (i = 0; i < (4096-320)/64; i++) {
22122 __asm__ __volatile__ (
22123 - "1: prefetch 320(%0)\n"
22124 - "2: movq (%0), %%mm0\n"
22125 - " movntq %%mm0, (%1)\n"
22126 - " movq 8(%0), %%mm1\n"
22127 - " movntq %%mm1, 8(%1)\n"
22128 - " movq 16(%0), %%mm2\n"
22129 - " movntq %%mm2, 16(%1)\n"
22130 - " movq 24(%0), %%mm3\n"
22131 - " movntq %%mm3, 24(%1)\n"
22132 - " movq 32(%0), %%mm4\n"
22133 - " movntq %%mm4, 32(%1)\n"
22134 - " movq 40(%0), %%mm5\n"
22135 - " movntq %%mm5, 40(%1)\n"
22136 - " movq 48(%0), %%mm6\n"
22137 - " movntq %%mm6, 48(%1)\n"
22138 - " movq 56(%0), %%mm7\n"
22139 - " movntq %%mm7, 56(%1)\n"
22140 + "1: prefetch 320(%1)\n"
22141 + "2: movq (%1), %%mm0\n"
22142 + " movntq %%mm0, (%2)\n"
22143 + " movq 8(%1), %%mm1\n"
22144 + " movntq %%mm1, 8(%2)\n"
22145 + " movq 16(%1), %%mm2\n"
22146 + " movntq %%mm2, 16(%2)\n"
22147 + " movq 24(%1), %%mm3\n"
22148 + " movntq %%mm3, 24(%2)\n"
22149 + " movq 32(%1), %%mm4\n"
22150 + " movntq %%mm4, 32(%2)\n"
22151 + " movq 40(%1), %%mm5\n"
22152 + " movntq %%mm5, 40(%2)\n"
22153 + " movq 48(%1), %%mm6\n"
22154 + " movntq %%mm6, 48(%2)\n"
22155 + " movq 56(%1), %%mm7\n"
22156 + " movntq %%mm7, 56(%2)\n"
22157 ".section .fixup, \"ax\"\n"
22158 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22159 + "3:\n"
22160 +
22161 +#ifdef CONFIG_PAX_KERNEXEC
22162 + " movl %%cr0, %0\n"
22163 + " movl %0, %%eax\n"
22164 + " andl $0xFFFEFFFF, %%eax\n"
22165 + " movl %%eax, %%cr0\n"
22166 +#endif
22167 +
22168 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22169 +
22170 +#ifdef CONFIG_PAX_KERNEXEC
22171 + " movl %0, %%cr0\n"
22172 +#endif
22173 +
22174 " jmp 2b\n"
22175 ".previous\n"
22176 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22177 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22178
22179 from += 64;
22180 to += 64;
22181 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22182 static void fast_copy_page(void *to, void *from)
22183 {
22184 int i;
22185 + unsigned long cr0;
22186
22187 kernel_fpu_begin();
22188
22189 __asm__ __volatile__ (
22190 - "1: prefetch (%0)\n"
22191 - " prefetch 64(%0)\n"
22192 - " prefetch 128(%0)\n"
22193 - " prefetch 192(%0)\n"
22194 - " prefetch 256(%0)\n"
22195 + "1: prefetch (%1)\n"
22196 + " prefetch 64(%1)\n"
22197 + " prefetch 128(%1)\n"
22198 + " prefetch 192(%1)\n"
22199 + " prefetch 256(%1)\n"
22200 "2: \n"
22201 ".section .fixup, \"ax\"\n"
22202 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22203 + "3: \n"
22204 +
22205 +#ifdef CONFIG_PAX_KERNEXEC
22206 + " movl %%cr0, %0\n"
22207 + " movl %0, %%eax\n"
22208 + " andl $0xFFFEFFFF, %%eax\n"
22209 + " movl %%eax, %%cr0\n"
22210 +#endif
22211 +
22212 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22213 +
22214 +#ifdef CONFIG_PAX_KERNEXEC
22215 + " movl %0, %%cr0\n"
22216 +#endif
22217 +
22218 " jmp 2b\n"
22219 ".previous\n"
22220 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22221 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22222
22223 for (i = 0; i < 4096/64; i++) {
22224 __asm__ __volatile__ (
22225 - "1: prefetch 320(%0)\n"
22226 - "2: movq (%0), %%mm0\n"
22227 - " movq 8(%0), %%mm1\n"
22228 - " movq 16(%0), %%mm2\n"
22229 - " movq 24(%0), %%mm3\n"
22230 - " movq %%mm0, (%1)\n"
22231 - " movq %%mm1, 8(%1)\n"
22232 - " movq %%mm2, 16(%1)\n"
22233 - " movq %%mm3, 24(%1)\n"
22234 - " movq 32(%0), %%mm0\n"
22235 - " movq 40(%0), %%mm1\n"
22236 - " movq 48(%0), %%mm2\n"
22237 - " movq 56(%0), %%mm3\n"
22238 - " movq %%mm0, 32(%1)\n"
22239 - " movq %%mm1, 40(%1)\n"
22240 - " movq %%mm2, 48(%1)\n"
22241 - " movq %%mm3, 56(%1)\n"
22242 + "1: prefetch 320(%1)\n"
22243 + "2: movq (%1), %%mm0\n"
22244 + " movq 8(%1), %%mm1\n"
22245 + " movq 16(%1), %%mm2\n"
22246 + " movq 24(%1), %%mm3\n"
22247 + " movq %%mm0, (%2)\n"
22248 + " movq %%mm1, 8(%2)\n"
22249 + " movq %%mm2, 16(%2)\n"
22250 + " movq %%mm3, 24(%2)\n"
22251 + " movq 32(%1), %%mm0\n"
22252 + " movq 40(%1), %%mm1\n"
22253 + " movq 48(%1), %%mm2\n"
22254 + " movq 56(%1), %%mm3\n"
22255 + " movq %%mm0, 32(%2)\n"
22256 + " movq %%mm1, 40(%2)\n"
22257 + " movq %%mm2, 48(%2)\n"
22258 + " movq %%mm3, 56(%2)\n"
22259 ".section .fixup, \"ax\"\n"
22260 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22261 + "3:\n"
22262 +
22263 +#ifdef CONFIG_PAX_KERNEXEC
22264 + " movl %%cr0, %0\n"
22265 + " movl %0, %%eax\n"
22266 + " andl $0xFFFEFFFF, %%eax\n"
22267 + " movl %%eax, %%cr0\n"
22268 +#endif
22269 +
22270 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22271 +
22272 +#ifdef CONFIG_PAX_KERNEXEC
22273 + " movl %0, %%cr0\n"
22274 +#endif
22275 +
22276 " jmp 2b\n"
22277 ".previous\n"
22278 _ASM_EXTABLE(1b, 3b)
22279 - : : "r" (from), "r" (to) : "memory");
22280 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22281
22282 from += 64;
22283 to += 64;
22284 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22285 index 69fa106..adda88b 100644
22286 --- a/arch/x86/lib/msr-reg.S
22287 +++ b/arch/x86/lib/msr-reg.S
22288 @@ -3,6 +3,7 @@
22289 #include <asm/dwarf2.h>
22290 #include <asm/asm.h>
22291 #include <asm/msr.h>
22292 +#include <asm/alternative-asm.h>
22293
22294 #ifdef CONFIG_X86_64
22295 /*
22296 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22297 CFI_STARTPROC
22298 pushq_cfi %rbx
22299 pushq_cfi %rbp
22300 - movq %rdi, %r10 /* Save pointer */
22301 + movq %rdi, %r9 /* Save pointer */
22302 xorl %r11d, %r11d /* Return value */
22303 movl (%rdi), %eax
22304 movl 4(%rdi), %ecx
22305 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22306 movl 28(%rdi), %edi
22307 CFI_REMEMBER_STATE
22308 1: \op
22309 -2: movl %eax, (%r10)
22310 +2: movl %eax, (%r9)
22311 movl %r11d, %eax /* Return value */
22312 - movl %ecx, 4(%r10)
22313 - movl %edx, 8(%r10)
22314 - movl %ebx, 12(%r10)
22315 - movl %ebp, 20(%r10)
22316 - movl %esi, 24(%r10)
22317 - movl %edi, 28(%r10)
22318 + movl %ecx, 4(%r9)
22319 + movl %edx, 8(%r9)
22320 + movl %ebx, 12(%r9)
22321 + movl %ebp, 20(%r9)
22322 + movl %esi, 24(%r9)
22323 + movl %edi, 28(%r9)
22324 popq_cfi %rbp
22325 popq_cfi %rbx
22326 + pax_force_retaddr
22327 ret
22328 3:
22329 CFI_RESTORE_STATE
22330 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22331 index 36b0d15..d381858 100644
22332 --- a/arch/x86/lib/putuser.S
22333 +++ b/arch/x86/lib/putuser.S
22334 @@ -15,7 +15,9 @@
22335 #include <asm/thread_info.h>
22336 #include <asm/errno.h>
22337 #include <asm/asm.h>
22338 -
22339 +#include <asm/segment.h>
22340 +#include <asm/pgtable.h>
22341 +#include <asm/alternative-asm.h>
22342
22343 /*
22344 * __put_user_X
22345 @@ -29,52 +31,119 @@
22346 * as they get called from within inline assembly.
22347 */
22348
22349 -#define ENTER CFI_STARTPROC ; \
22350 - GET_THREAD_INFO(%_ASM_BX)
22351 -#define EXIT ret ; \
22352 +#define ENTER CFI_STARTPROC
22353 +#define EXIT pax_force_retaddr; ret ; \
22354 CFI_ENDPROC
22355
22356 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22357 +#define _DEST %_ASM_CX,%_ASM_BX
22358 +#else
22359 +#define _DEST %_ASM_CX
22360 +#endif
22361 +
22362 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22363 +#define __copyuser_seg gs;
22364 +#else
22365 +#define __copyuser_seg
22366 +#endif
22367 +
22368 .text
22369 ENTRY(__put_user_1)
22370 ENTER
22371 +
22372 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22373 + GET_THREAD_INFO(%_ASM_BX)
22374 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22375 jae bad_put_user
22376 -1: movb %al,(%_ASM_CX)
22377 +
22378 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22379 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22380 + cmp %_ASM_BX,%_ASM_CX
22381 + jb 1234f
22382 + xor %ebx,%ebx
22383 +1234:
22384 +#endif
22385 +
22386 +#endif
22387 +
22388 +1: __copyuser_seg movb %al,(_DEST)
22389 xor %eax,%eax
22390 EXIT
22391 ENDPROC(__put_user_1)
22392
22393 ENTRY(__put_user_2)
22394 ENTER
22395 +
22396 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22397 + GET_THREAD_INFO(%_ASM_BX)
22398 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22399 sub $1,%_ASM_BX
22400 cmp %_ASM_BX,%_ASM_CX
22401 jae bad_put_user
22402 -2: movw %ax,(%_ASM_CX)
22403 +
22404 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22405 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22406 + cmp %_ASM_BX,%_ASM_CX
22407 + jb 1234f
22408 + xor %ebx,%ebx
22409 +1234:
22410 +#endif
22411 +
22412 +#endif
22413 +
22414 +2: __copyuser_seg movw %ax,(_DEST)
22415 xor %eax,%eax
22416 EXIT
22417 ENDPROC(__put_user_2)
22418
22419 ENTRY(__put_user_4)
22420 ENTER
22421 +
22422 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22423 + GET_THREAD_INFO(%_ASM_BX)
22424 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22425 sub $3,%_ASM_BX
22426 cmp %_ASM_BX,%_ASM_CX
22427 jae bad_put_user
22428 -3: movl %eax,(%_ASM_CX)
22429 +
22430 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22431 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22432 + cmp %_ASM_BX,%_ASM_CX
22433 + jb 1234f
22434 + xor %ebx,%ebx
22435 +1234:
22436 +#endif
22437 +
22438 +#endif
22439 +
22440 +3: __copyuser_seg movl %eax,(_DEST)
22441 xor %eax,%eax
22442 EXIT
22443 ENDPROC(__put_user_4)
22444
22445 ENTRY(__put_user_8)
22446 ENTER
22447 +
22448 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22449 + GET_THREAD_INFO(%_ASM_BX)
22450 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22451 sub $7,%_ASM_BX
22452 cmp %_ASM_BX,%_ASM_CX
22453 jae bad_put_user
22454 -4: mov %_ASM_AX,(%_ASM_CX)
22455 +
22456 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22457 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22458 + cmp %_ASM_BX,%_ASM_CX
22459 + jb 1234f
22460 + xor %ebx,%ebx
22461 +1234:
22462 +#endif
22463 +
22464 +#endif
22465 +
22466 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22467 #ifdef CONFIG_X86_32
22468 -5: movl %edx,4(%_ASM_CX)
22469 +5: __copyuser_seg movl %edx,4(_DEST)
22470 #endif
22471 xor %eax,%eax
22472 EXIT
22473 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22474 index 1cad221..de671ee 100644
22475 --- a/arch/x86/lib/rwlock.S
22476 +++ b/arch/x86/lib/rwlock.S
22477 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22478 FRAME
22479 0: LOCK_PREFIX
22480 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22481 +
22482 +#ifdef CONFIG_PAX_REFCOUNT
22483 + jno 1234f
22484 + LOCK_PREFIX
22485 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22486 + int $4
22487 +1234:
22488 + _ASM_EXTABLE(1234b, 1234b)
22489 +#endif
22490 +
22491 1: rep; nop
22492 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22493 jne 1b
22494 LOCK_PREFIX
22495 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22496 +
22497 +#ifdef CONFIG_PAX_REFCOUNT
22498 + jno 1234f
22499 + LOCK_PREFIX
22500 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22501 + int $4
22502 +1234:
22503 + _ASM_EXTABLE(1234b, 1234b)
22504 +#endif
22505 +
22506 jnz 0b
22507 ENDFRAME
22508 + pax_force_retaddr
22509 ret
22510 CFI_ENDPROC
22511 END(__write_lock_failed)
22512 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22513 FRAME
22514 0: LOCK_PREFIX
22515 READ_LOCK_SIZE(inc) (%__lock_ptr)
22516 +
22517 +#ifdef CONFIG_PAX_REFCOUNT
22518 + jno 1234f
22519 + LOCK_PREFIX
22520 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22521 + int $4
22522 +1234:
22523 + _ASM_EXTABLE(1234b, 1234b)
22524 +#endif
22525 +
22526 1: rep; nop
22527 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22528 js 1b
22529 LOCK_PREFIX
22530 READ_LOCK_SIZE(dec) (%__lock_ptr)
22531 +
22532 +#ifdef CONFIG_PAX_REFCOUNT
22533 + jno 1234f
22534 + LOCK_PREFIX
22535 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22536 + int $4
22537 +1234:
22538 + _ASM_EXTABLE(1234b, 1234b)
22539 +#endif
22540 +
22541 js 0b
22542 ENDFRAME
22543 + pax_force_retaddr
22544 ret
22545 CFI_ENDPROC
22546 END(__read_lock_failed)
22547 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22548 index 5dff5f0..cadebf4 100644
22549 --- a/arch/x86/lib/rwsem.S
22550 +++ b/arch/x86/lib/rwsem.S
22551 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22552 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22553 CFI_RESTORE __ASM_REG(dx)
22554 restore_common_regs
22555 + pax_force_retaddr
22556 ret
22557 CFI_ENDPROC
22558 ENDPROC(call_rwsem_down_read_failed)
22559 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22560 movq %rax,%rdi
22561 call rwsem_down_write_failed
22562 restore_common_regs
22563 + pax_force_retaddr
22564 ret
22565 CFI_ENDPROC
22566 ENDPROC(call_rwsem_down_write_failed)
22567 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22568 movq %rax,%rdi
22569 call rwsem_wake
22570 restore_common_regs
22571 -1: ret
22572 +1: pax_force_retaddr
22573 + ret
22574 CFI_ENDPROC
22575 ENDPROC(call_rwsem_wake)
22576
22577 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22578 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22579 CFI_RESTORE __ASM_REG(dx)
22580 restore_common_regs
22581 + pax_force_retaddr
22582 ret
22583 CFI_ENDPROC
22584 ENDPROC(call_rwsem_downgrade_wake)
22585 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22586 index a63efd6..ccecad8 100644
22587 --- a/arch/x86/lib/thunk_64.S
22588 +++ b/arch/x86/lib/thunk_64.S
22589 @@ -8,6 +8,7 @@
22590 #include <linux/linkage.h>
22591 #include <asm/dwarf2.h>
22592 #include <asm/calling.h>
22593 +#include <asm/alternative-asm.h>
22594
22595 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22596 .macro THUNK name, func, put_ret_addr_in_rdi=0
22597 @@ -41,5 +42,6 @@
22598 SAVE_ARGS
22599 restore:
22600 RESTORE_ARGS
22601 + pax_force_retaddr
22602 ret
22603 CFI_ENDPROC
22604 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22605 index e218d5d..a99a1eb 100644
22606 --- a/arch/x86/lib/usercopy_32.c
22607 +++ b/arch/x86/lib/usercopy_32.c
22608 @@ -43,7 +43,7 @@ do { \
22609 __asm__ __volatile__( \
22610 " testl %1,%1\n" \
22611 " jz 2f\n" \
22612 - "0: lodsb\n" \
22613 + "0: "__copyuser_seg"lodsb\n" \
22614 " stosb\n" \
22615 " testb %%al,%%al\n" \
22616 " jz 1f\n" \
22617 @@ -128,10 +128,12 @@ do { \
22618 int __d0; \
22619 might_fault(); \
22620 __asm__ __volatile__( \
22621 + __COPYUSER_SET_ES \
22622 "0: rep; stosl\n" \
22623 " movl %2,%0\n" \
22624 "1: rep; stosb\n" \
22625 "2:\n" \
22626 + __COPYUSER_RESTORE_ES \
22627 ".section .fixup,\"ax\"\n" \
22628 "3: lea 0(%2,%0,4),%0\n" \
22629 " jmp 2b\n" \
22630 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22631 might_fault();
22632
22633 __asm__ __volatile__(
22634 + __COPYUSER_SET_ES
22635 " testl %0, %0\n"
22636 " jz 3f\n"
22637 " andl %0,%%ecx\n"
22638 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22639 " subl %%ecx,%0\n"
22640 " addl %0,%%eax\n"
22641 "1:\n"
22642 + __COPYUSER_RESTORE_ES
22643 ".section .fixup,\"ax\"\n"
22644 "2: xorl %%eax,%%eax\n"
22645 " jmp 1b\n"
22646 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22647
22648 #ifdef CONFIG_X86_INTEL_USERCOPY
22649 static unsigned long
22650 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22651 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22652 {
22653 int d0, d1;
22654 __asm__ __volatile__(
22655 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22656 " .align 2,0x90\n"
22657 "3: movl 0(%4), %%eax\n"
22658 "4: movl 4(%4), %%edx\n"
22659 - "5: movl %%eax, 0(%3)\n"
22660 - "6: movl %%edx, 4(%3)\n"
22661 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22662 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22663 "7: movl 8(%4), %%eax\n"
22664 "8: movl 12(%4),%%edx\n"
22665 - "9: movl %%eax, 8(%3)\n"
22666 - "10: movl %%edx, 12(%3)\n"
22667 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22668 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22669 "11: movl 16(%4), %%eax\n"
22670 "12: movl 20(%4), %%edx\n"
22671 - "13: movl %%eax, 16(%3)\n"
22672 - "14: movl %%edx, 20(%3)\n"
22673 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22674 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22675 "15: movl 24(%4), %%eax\n"
22676 "16: movl 28(%4), %%edx\n"
22677 - "17: movl %%eax, 24(%3)\n"
22678 - "18: movl %%edx, 28(%3)\n"
22679 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22680 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22681 "19: movl 32(%4), %%eax\n"
22682 "20: movl 36(%4), %%edx\n"
22683 - "21: movl %%eax, 32(%3)\n"
22684 - "22: movl %%edx, 36(%3)\n"
22685 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22686 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22687 "23: movl 40(%4), %%eax\n"
22688 "24: movl 44(%4), %%edx\n"
22689 - "25: movl %%eax, 40(%3)\n"
22690 - "26: movl %%edx, 44(%3)\n"
22691 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22692 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22693 "27: movl 48(%4), %%eax\n"
22694 "28: movl 52(%4), %%edx\n"
22695 - "29: movl %%eax, 48(%3)\n"
22696 - "30: movl %%edx, 52(%3)\n"
22697 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22698 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22699 "31: movl 56(%4), %%eax\n"
22700 "32: movl 60(%4), %%edx\n"
22701 - "33: movl %%eax, 56(%3)\n"
22702 - "34: movl %%edx, 60(%3)\n"
22703 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22704 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22705 " addl $-64, %0\n"
22706 " addl $64, %4\n"
22707 " addl $64, %3\n"
22708 @@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22709 " shrl $2, %0\n"
22710 " andl $3, %%eax\n"
22711 " cld\n"
22712 + __COPYUSER_SET_ES
22713 "99: rep; movsl\n"
22714 "36: movl %%eax, %0\n"
22715 "37: rep; movsb\n"
22716 "100:\n"
22717 + __COPYUSER_RESTORE_ES
22718 ".section .fixup,\"ax\"\n"
22719 "101: lea 0(%%eax,%0,4),%0\n"
22720 " jmp 100b\n"
22721 @@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22722 }
22723
22724 static unsigned long
22725 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22726 +{
22727 + int d0, d1;
22728 + __asm__ __volatile__(
22729 + " .align 2,0x90\n"
22730 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22731 + " cmpl $67, %0\n"
22732 + " jbe 3f\n"
22733 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22734 + " .align 2,0x90\n"
22735 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22736 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22737 + "5: movl %%eax, 0(%3)\n"
22738 + "6: movl %%edx, 4(%3)\n"
22739 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22740 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22741 + "9: movl %%eax, 8(%3)\n"
22742 + "10: movl %%edx, 12(%3)\n"
22743 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22744 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22745 + "13: movl %%eax, 16(%3)\n"
22746 + "14: movl %%edx, 20(%3)\n"
22747 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22748 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22749 + "17: movl %%eax, 24(%3)\n"
22750 + "18: movl %%edx, 28(%3)\n"
22751 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22752 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22753 + "21: movl %%eax, 32(%3)\n"
22754 + "22: movl %%edx, 36(%3)\n"
22755 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22756 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22757 + "25: movl %%eax, 40(%3)\n"
22758 + "26: movl %%edx, 44(%3)\n"
22759 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22760 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22761 + "29: movl %%eax, 48(%3)\n"
22762 + "30: movl %%edx, 52(%3)\n"
22763 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22764 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22765 + "33: movl %%eax, 56(%3)\n"
22766 + "34: movl %%edx, 60(%3)\n"
22767 + " addl $-64, %0\n"
22768 + " addl $64, %4\n"
22769 + " addl $64, %3\n"
22770 + " cmpl $63, %0\n"
22771 + " ja 1b\n"
22772 + "35: movl %0, %%eax\n"
22773 + " shrl $2, %0\n"
22774 + " andl $3, %%eax\n"
22775 + " cld\n"
22776 + "99: rep; "__copyuser_seg" movsl\n"
22777 + "36: movl %%eax, %0\n"
22778 + "37: rep; "__copyuser_seg" movsb\n"
22779 + "100:\n"
22780 + ".section .fixup,\"ax\"\n"
22781 + "101: lea 0(%%eax,%0,4),%0\n"
22782 + " jmp 100b\n"
22783 + ".previous\n"
22784 + ".section __ex_table,\"a\"\n"
22785 + " .align 4\n"
22786 + " .long 1b,100b\n"
22787 + " .long 2b,100b\n"
22788 + " .long 3b,100b\n"
22789 + " .long 4b,100b\n"
22790 + " .long 5b,100b\n"
22791 + " .long 6b,100b\n"
22792 + " .long 7b,100b\n"
22793 + " .long 8b,100b\n"
22794 + " .long 9b,100b\n"
22795 + " .long 10b,100b\n"
22796 + " .long 11b,100b\n"
22797 + " .long 12b,100b\n"
22798 + " .long 13b,100b\n"
22799 + " .long 14b,100b\n"
22800 + " .long 15b,100b\n"
22801 + " .long 16b,100b\n"
22802 + " .long 17b,100b\n"
22803 + " .long 18b,100b\n"
22804 + " .long 19b,100b\n"
22805 + " .long 20b,100b\n"
22806 + " .long 21b,100b\n"
22807 + " .long 22b,100b\n"
22808 + " .long 23b,100b\n"
22809 + " .long 24b,100b\n"
22810 + " .long 25b,100b\n"
22811 + " .long 26b,100b\n"
22812 + " .long 27b,100b\n"
22813 + " .long 28b,100b\n"
22814 + " .long 29b,100b\n"
22815 + " .long 30b,100b\n"
22816 + " .long 31b,100b\n"
22817 + " .long 32b,100b\n"
22818 + " .long 33b,100b\n"
22819 + " .long 34b,100b\n"
22820 + " .long 35b,100b\n"
22821 + " .long 36b,100b\n"
22822 + " .long 37b,100b\n"
22823 + " .long 99b,101b\n"
22824 + ".previous"
22825 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22826 + : "1"(to), "2"(from), "0"(size)
22827 + : "eax", "edx", "memory");
22828 + return size;
22829 +}
22830 +
22831 +static unsigned long
22832 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22833 +static unsigned long
22834 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22835 {
22836 int d0, d1;
22837 __asm__ __volatile__(
22838 " .align 2,0x90\n"
22839 - "0: movl 32(%4), %%eax\n"
22840 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22841 " cmpl $67, %0\n"
22842 " jbe 2f\n"
22843 - "1: movl 64(%4), %%eax\n"
22844 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22845 " .align 2,0x90\n"
22846 - "2: movl 0(%4), %%eax\n"
22847 - "21: movl 4(%4), %%edx\n"
22848 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22849 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22850 " movl %%eax, 0(%3)\n"
22851 " movl %%edx, 4(%3)\n"
22852 - "3: movl 8(%4), %%eax\n"
22853 - "31: movl 12(%4),%%edx\n"
22854 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22855 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22856 " movl %%eax, 8(%3)\n"
22857 " movl %%edx, 12(%3)\n"
22858 - "4: movl 16(%4), %%eax\n"
22859 - "41: movl 20(%4), %%edx\n"
22860 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22861 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22862 " movl %%eax, 16(%3)\n"
22863 " movl %%edx, 20(%3)\n"
22864 - "10: movl 24(%4), %%eax\n"
22865 - "51: movl 28(%4), %%edx\n"
22866 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22867 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22868 " movl %%eax, 24(%3)\n"
22869 " movl %%edx, 28(%3)\n"
22870 - "11: movl 32(%4), %%eax\n"
22871 - "61: movl 36(%4), %%edx\n"
22872 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22873 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22874 " movl %%eax, 32(%3)\n"
22875 " movl %%edx, 36(%3)\n"
22876 - "12: movl 40(%4), %%eax\n"
22877 - "71: movl 44(%4), %%edx\n"
22878 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22879 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22880 " movl %%eax, 40(%3)\n"
22881 " movl %%edx, 44(%3)\n"
22882 - "13: movl 48(%4), %%eax\n"
22883 - "81: movl 52(%4), %%edx\n"
22884 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22885 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22886 " movl %%eax, 48(%3)\n"
22887 " movl %%edx, 52(%3)\n"
22888 - "14: movl 56(%4), %%eax\n"
22889 - "91: movl 60(%4), %%edx\n"
22890 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22891 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22892 " movl %%eax, 56(%3)\n"
22893 " movl %%edx, 60(%3)\n"
22894 " addl $-64, %0\n"
22895 @@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22896 " shrl $2, %0\n"
22897 " andl $3, %%eax\n"
22898 " cld\n"
22899 - "6: rep; movsl\n"
22900 + "6: rep; "__copyuser_seg" movsl\n"
22901 " movl %%eax,%0\n"
22902 - "7: rep; movsb\n"
22903 + "7: rep; "__copyuser_seg" movsb\n"
22904 "8:\n"
22905 ".section .fixup,\"ax\"\n"
22906 "9: lea 0(%%eax,%0,4),%0\n"
22907 @@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22908 */
22909
22910 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22911 + const void __user *from, unsigned long size) __size_overflow(3);
22912 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22913 const void __user *from, unsigned long size)
22914 {
22915 int d0, d1;
22916
22917 __asm__ __volatile__(
22918 " .align 2,0x90\n"
22919 - "0: movl 32(%4), %%eax\n"
22920 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22921 " cmpl $67, %0\n"
22922 " jbe 2f\n"
22923 - "1: movl 64(%4), %%eax\n"
22924 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22925 " .align 2,0x90\n"
22926 - "2: movl 0(%4), %%eax\n"
22927 - "21: movl 4(%4), %%edx\n"
22928 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22929 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22930 " movnti %%eax, 0(%3)\n"
22931 " movnti %%edx, 4(%3)\n"
22932 - "3: movl 8(%4), %%eax\n"
22933 - "31: movl 12(%4),%%edx\n"
22934 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22935 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22936 " movnti %%eax, 8(%3)\n"
22937 " movnti %%edx, 12(%3)\n"
22938 - "4: movl 16(%4), %%eax\n"
22939 - "41: movl 20(%4), %%edx\n"
22940 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22941 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22942 " movnti %%eax, 16(%3)\n"
22943 " movnti %%edx, 20(%3)\n"
22944 - "10: movl 24(%4), %%eax\n"
22945 - "51: movl 28(%4), %%edx\n"
22946 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22947 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22948 " movnti %%eax, 24(%3)\n"
22949 " movnti %%edx, 28(%3)\n"
22950 - "11: movl 32(%4), %%eax\n"
22951 - "61: movl 36(%4), %%edx\n"
22952 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22953 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22954 " movnti %%eax, 32(%3)\n"
22955 " movnti %%edx, 36(%3)\n"
22956 - "12: movl 40(%4), %%eax\n"
22957 - "71: movl 44(%4), %%edx\n"
22958 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22959 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22960 " movnti %%eax, 40(%3)\n"
22961 " movnti %%edx, 44(%3)\n"
22962 - "13: movl 48(%4), %%eax\n"
22963 - "81: movl 52(%4), %%edx\n"
22964 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22965 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22966 " movnti %%eax, 48(%3)\n"
22967 " movnti %%edx, 52(%3)\n"
22968 - "14: movl 56(%4), %%eax\n"
22969 - "91: movl 60(%4), %%edx\n"
22970 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22971 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22972 " movnti %%eax, 56(%3)\n"
22973 " movnti %%edx, 60(%3)\n"
22974 " addl $-64, %0\n"
22975 @@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22976 " shrl $2, %0\n"
22977 " andl $3, %%eax\n"
22978 " cld\n"
22979 - "6: rep; movsl\n"
22980 + "6: rep; "__copyuser_seg" movsl\n"
22981 " movl %%eax,%0\n"
22982 - "7: rep; movsb\n"
22983 + "7: rep; "__copyuser_seg" movsb\n"
22984 "8:\n"
22985 ".section .fixup,\"ax\"\n"
22986 "9: lea 0(%%eax,%0,4),%0\n"
22987 @@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22988 }
22989
22990 static unsigned long __copy_user_intel_nocache(void *to,
22991 + const void __user *from, unsigned long size) __size_overflow(3);
22992 +static unsigned long __copy_user_intel_nocache(void *to,
22993 const void __user *from, unsigned long size)
22994 {
22995 int d0, d1;
22996
22997 __asm__ __volatile__(
22998 " .align 2,0x90\n"
22999 - "0: movl 32(%4), %%eax\n"
23000 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23001 " cmpl $67, %0\n"
23002 " jbe 2f\n"
23003 - "1: movl 64(%4), %%eax\n"
23004 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23005 " .align 2,0x90\n"
23006 - "2: movl 0(%4), %%eax\n"
23007 - "21: movl 4(%4), %%edx\n"
23008 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23009 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23010 " movnti %%eax, 0(%3)\n"
23011 " movnti %%edx, 4(%3)\n"
23012 - "3: movl 8(%4), %%eax\n"
23013 - "31: movl 12(%4),%%edx\n"
23014 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23015 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23016 " movnti %%eax, 8(%3)\n"
23017 " movnti %%edx, 12(%3)\n"
23018 - "4: movl 16(%4), %%eax\n"
23019 - "41: movl 20(%4), %%edx\n"
23020 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23021 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23022 " movnti %%eax, 16(%3)\n"
23023 " movnti %%edx, 20(%3)\n"
23024 - "10: movl 24(%4), %%eax\n"
23025 - "51: movl 28(%4), %%edx\n"
23026 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23027 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23028 " movnti %%eax, 24(%3)\n"
23029 " movnti %%edx, 28(%3)\n"
23030 - "11: movl 32(%4), %%eax\n"
23031 - "61: movl 36(%4), %%edx\n"
23032 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23033 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23034 " movnti %%eax, 32(%3)\n"
23035 " movnti %%edx, 36(%3)\n"
23036 - "12: movl 40(%4), %%eax\n"
23037 - "71: movl 44(%4), %%edx\n"
23038 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23039 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23040 " movnti %%eax, 40(%3)\n"
23041 " movnti %%edx, 44(%3)\n"
23042 - "13: movl 48(%4), %%eax\n"
23043 - "81: movl 52(%4), %%edx\n"
23044 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23045 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23046 " movnti %%eax, 48(%3)\n"
23047 " movnti %%edx, 52(%3)\n"
23048 - "14: movl 56(%4), %%eax\n"
23049 - "91: movl 60(%4), %%edx\n"
23050 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23051 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23052 " movnti %%eax, 56(%3)\n"
23053 " movnti %%edx, 60(%3)\n"
23054 " addl $-64, %0\n"
23055 @@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23056 " shrl $2, %0\n"
23057 " andl $3, %%eax\n"
23058 " cld\n"
23059 - "6: rep; movsl\n"
23060 + "6: rep; "__copyuser_seg" movsl\n"
23061 " movl %%eax,%0\n"
23062 - "7: rep; movsb\n"
23063 + "7: rep; "__copyuser_seg" movsb\n"
23064 "8:\n"
23065 ".section .fixup,\"ax\"\n"
23066 "9: lea 0(%%eax,%0,4),%0\n"
23067 @@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23068 */
23069 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23070 unsigned long size);
23071 -unsigned long __copy_user_intel(void __user *to, const void *from,
23072 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23073 + unsigned long size);
23074 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23075 unsigned long size);
23076 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23077 const void __user *from, unsigned long size);
23078 #endif /* CONFIG_X86_INTEL_USERCOPY */
23079
23080 /* Generic arbitrary sized copy. */
23081 -#define __copy_user(to, from, size) \
23082 +#define __copy_user(to, from, size, prefix, set, restore) \
23083 do { \
23084 int __d0, __d1, __d2; \
23085 __asm__ __volatile__( \
23086 + set \
23087 " cmp $7,%0\n" \
23088 " jbe 1f\n" \
23089 " movl %1,%0\n" \
23090 " negl %0\n" \
23091 " andl $7,%0\n" \
23092 " subl %0,%3\n" \
23093 - "4: rep; movsb\n" \
23094 + "4: rep; "prefix"movsb\n" \
23095 " movl %3,%0\n" \
23096 " shrl $2,%0\n" \
23097 " andl $3,%3\n" \
23098 " .align 2,0x90\n" \
23099 - "0: rep; movsl\n" \
23100 + "0: rep; "prefix"movsl\n" \
23101 " movl %3,%0\n" \
23102 - "1: rep; movsb\n" \
23103 + "1: rep; "prefix"movsb\n" \
23104 "2:\n" \
23105 + restore \
23106 ".section .fixup,\"ax\"\n" \
23107 "5: addl %3,%0\n" \
23108 " jmp 2b\n" \
23109 @@ -682,14 +805,14 @@ do { \
23110 " negl %0\n" \
23111 " andl $7,%0\n" \
23112 " subl %0,%3\n" \
23113 - "4: rep; movsb\n" \
23114 + "4: rep; "__copyuser_seg"movsb\n" \
23115 " movl %3,%0\n" \
23116 " shrl $2,%0\n" \
23117 " andl $3,%3\n" \
23118 " .align 2,0x90\n" \
23119 - "0: rep; movsl\n" \
23120 + "0: rep; "__copyuser_seg"movsl\n" \
23121 " movl %3,%0\n" \
23122 - "1: rep; movsb\n" \
23123 + "1: rep; "__copyuser_seg"movsb\n" \
23124 "2:\n" \
23125 ".section .fixup,\"ax\"\n" \
23126 "5: addl %3,%0\n" \
23127 @@ -775,9 +898,9 @@ survive:
23128 }
23129 #endif
23130 if (movsl_is_ok(to, from, n))
23131 - __copy_user(to, from, n);
23132 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23133 else
23134 - n = __copy_user_intel(to, from, n);
23135 + n = __generic_copy_to_user_intel(to, from, n);
23136 return n;
23137 }
23138 EXPORT_SYMBOL(__copy_to_user_ll);
23139 @@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23140 unsigned long n)
23141 {
23142 if (movsl_is_ok(to, from, n))
23143 - __copy_user(to, from, n);
23144 + __copy_user(to, from, n, __copyuser_seg, "", "");
23145 else
23146 - n = __copy_user_intel((void __user *)to,
23147 - (const void *)from, n);
23148 + n = __generic_copy_from_user_intel(to, from, n);
23149 return n;
23150 }
23151 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23152 @@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23153 if (n > 64 && cpu_has_xmm2)
23154 n = __copy_user_intel_nocache(to, from, n);
23155 else
23156 - __copy_user(to, from, n);
23157 + __copy_user(to, from, n, __copyuser_seg, "", "");
23158 #else
23159 - __copy_user(to, from, n);
23160 + __copy_user(to, from, n, __copyuser_seg, "", "");
23161 #endif
23162 return n;
23163 }
23164 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23165
23166 -/**
23167 - * copy_to_user: - Copy a block of data into user space.
23168 - * @to: Destination address, in user space.
23169 - * @from: Source address, in kernel space.
23170 - * @n: Number of bytes to copy.
23171 - *
23172 - * Context: User context only. This function may sleep.
23173 - *
23174 - * Copy data from kernel space to user space.
23175 - *
23176 - * Returns number of bytes that could not be copied.
23177 - * On success, this will be zero.
23178 - */
23179 -unsigned long
23180 -copy_to_user(void __user *to, const void *from, unsigned long n)
23181 -{
23182 - if (access_ok(VERIFY_WRITE, to, n))
23183 - n = __copy_to_user(to, from, n);
23184 - return n;
23185 -}
23186 -EXPORT_SYMBOL(copy_to_user);
23187 -
23188 -/**
23189 - * copy_from_user: - Copy a block of data from user space.
23190 - * @to: Destination address, in kernel space.
23191 - * @from: Source address, in user space.
23192 - * @n: Number of bytes to copy.
23193 - *
23194 - * Context: User context only. This function may sleep.
23195 - *
23196 - * Copy data from user space to kernel space.
23197 - *
23198 - * Returns number of bytes that could not be copied.
23199 - * On success, this will be zero.
23200 - *
23201 - * If some data could not be copied, this function will pad the copied
23202 - * data to the requested size using zero bytes.
23203 - */
23204 -unsigned long
23205 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23206 -{
23207 - if (access_ok(VERIFY_READ, from, n))
23208 - n = __copy_from_user(to, from, n);
23209 - else
23210 - memset(to, 0, n);
23211 - return n;
23212 -}
23213 -EXPORT_SYMBOL(_copy_from_user);
23214 -
23215 void copy_from_user_overflow(void)
23216 {
23217 WARN(1, "Buffer overflow detected!\n");
23218 }
23219 EXPORT_SYMBOL(copy_from_user_overflow);
23220 +
23221 +void copy_to_user_overflow(void)
23222 +{
23223 + WARN(1, "Buffer overflow detected!\n");
23224 +}
23225 +EXPORT_SYMBOL(copy_to_user_overflow);
23226 +
23227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23228 +void __set_fs(mm_segment_t x)
23229 +{
23230 + switch (x.seg) {
23231 + case 0:
23232 + loadsegment(gs, 0);
23233 + break;
23234 + case TASK_SIZE_MAX:
23235 + loadsegment(gs, __USER_DS);
23236 + break;
23237 + case -1UL:
23238 + loadsegment(gs, __KERNEL_DS);
23239 + break;
23240 + default:
23241 + BUG();
23242 + }
23243 + return;
23244 +}
23245 +EXPORT_SYMBOL(__set_fs);
23246 +
23247 +void set_fs(mm_segment_t x)
23248 +{
23249 + current_thread_info()->addr_limit = x;
23250 + __set_fs(x);
23251 +}
23252 +EXPORT_SYMBOL(set_fs);
23253 +#endif
23254 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23255 index b7c2849..8633ad8 100644
23256 --- a/arch/x86/lib/usercopy_64.c
23257 +++ b/arch/x86/lib/usercopy_64.c
23258 @@ -42,6 +42,12 @@ long
23259 __strncpy_from_user(char *dst, const char __user *src, long count)
23260 {
23261 long res;
23262 +
23263 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23264 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23265 + src += PAX_USER_SHADOW_BASE;
23266 +#endif
23267 +
23268 __do_strncpy_from_user(dst, src, count, res);
23269 return res;
23270 }
23271 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23272 {
23273 long __d0;
23274 might_fault();
23275 +
23276 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23277 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23278 + addr += PAX_USER_SHADOW_BASE;
23279 +#endif
23280 +
23281 /* no memory constraint because it doesn't change any memory gcc knows
23282 about */
23283 asm volatile(
23284 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23285 }
23286 EXPORT_SYMBOL(strlen_user);
23287
23288 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23289 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23290 {
23291 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23292 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23293 - }
23294 - return len;
23295 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23296 +
23297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23298 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23299 + to += PAX_USER_SHADOW_BASE;
23300 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23301 + from += PAX_USER_SHADOW_BASE;
23302 +#endif
23303 +
23304 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23305 + }
23306 + return len;
23307 }
23308 EXPORT_SYMBOL(copy_in_user);
23309
23310 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23311 * it is not necessary to optimize tail handling.
23312 */
23313 unsigned long
23314 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23315 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23316 {
23317 char c;
23318 unsigned zero_len;
23319 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23320 index 1fb85db..8b3540b 100644
23321 --- a/arch/x86/mm/extable.c
23322 +++ b/arch/x86/mm/extable.c
23323 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23324 const struct exception_table_entry *fixup;
23325
23326 #ifdef CONFIG_PNPBIOS
23327 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23328 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23329 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23330 extern u32 pnp_bios_is_utter_crap;
23331 pnp_bios_is_utter_crap = 1;
23332 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23333 index f0b4caf..d92fd42 100644
23334 --- a/arch/x86/mm/fault.c
23335 +++ b/arch/x86/mm/fault.c
23336 @@ -13,11 +13,18 @@
23337 #include <linux/perf_event.h> /* perf_sw_event */
23338 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23339 #include <linux/prefetch.h> /* prefetchw */
23340 +#include <linux/unistd.h>
23341 +#include <linux/compiler.h>
23342
23343 #include <asm/traps.h> /* dotraplinkage, ... */
23344 #include <asm/pgalloc.h> /* pgd_*(), ... */
23345 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23346 #include <asm/fixmap.h> /* VSYSCALL_START */
23347 +#include <asm/tlbflush.h>
23348 +
23349 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23350 +#include <asm/stacktrace.h>
23351 +#endif
23352
23353 /*
23354 * Page fault error code bits:
23355 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23356 int ret = 0;
23357
23358 /* kprobe_running() needs smp_processor_id() */
23359 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23360 + if (kprobes_built_in() && !user_mode(regs)) {
23361 preempt_disable();
23362 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23363 ret = 1;
23364 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23365 return !instr_lo || (instr_lo>>1) == 1;
23366 case 0x00:
23367 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23368 - if (probe_kernel_address(instr, opcode))
23369 + if (user_mode(regs)) {
23370 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23371 + return 0;
23372 + } else if (probe_kernel_address(instr, opcode))
23373 return 0;
23374
23375 *prefetch = (instr_lo == 0xF) &&
23376 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23377 while (instr < max_instr) {
23378 unsigned char opcode;
23379
23380 - if (probe_kernel_address(instr, opcode))
23381 + if (user_mode(regs)) {
23382 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23383 + break;
23384 + } else if (probe_kernel_address(instr, opcode))
23385 break;
23386
23387 instr++;
23388 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23389 force_sig_info(si_signo, &info, tsk);
23390 }
23391
23392 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23393 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23394 +#endif
23395 +
23396 +#ifdef CONFIG_PAX_EMUTRAMP
23397 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23398 +#endif
23399 +
23400 +#ifdef CONFIG_PAX_PAGEEXEC
23401 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23402 +{
23403 + pgd_t *pgd;
23404 + pud_t *pud;
23405 + pmd_t *pmd;
23406 +
23407 + pgd = pgd_offset(mm, address);
23408 + if (!pgd_present(*pgd))
23409 + return NULL;
23410 + pud = pud_offset(pgd, address);
23411 + if (!pud_present(*pud))
23412 + return NULL;
23413 + pmd = pmd_offset(pud, address);
23414 + if (!pmd_present(*pmd))
23415 + return NULL;
23416 + return pmd;
23417 +}
23418 +#endif
23419 +
23420 DEFINE_SPINLOCK(pgd_lock);
23421 LIST_HEAD(pgd_list);
23422
23423 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23424 for (address = VMALLOC_START & PMD_MASK;
23425 address >= TASK_SIZE && address < FIXADDR_TOP;
23426 address += PMD_SIZE) {
23427 +
23428 +#ifdef CONFIG_PAX_PER_CPU_PGD
23429 + unsigned long cpu;
23430 +#else
23431 struct page *page;
23432 +#endif
23433
23434 spin_lock(&pgd_lock);
23435 +
23436 +#ifdef CONFIG_PAX_PER_CPU_PGD
23437 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23438 + pgd_t *pgd = get_cpu_pgd(cpu);
23439 + pmd_t *ret;
23440 +#else
23441 list_for_each_entry(page, &pgd_list, lru) {
23442 + pgd_t *pgd = page_address(page);
23443 spinlock_t *pgt_lock;
23444 pmd_t *ret;
23445
23446 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23447 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23448
23449 spin_lock(pgt_lock);
23450 - ret = vmalloc_sync_one(page_address(page), address);
23451 +#endif
23452 +
23453 + ret = vmalloc_sync_one(pgd, address);
23454 +
23455 +#ifndef CONFIG_PAX_PER_CPU_PGD
23456 spin_unlock(pgt_lock);
23457 +#endif
23458
23459 if (!ret)
23460 break;
23461 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23462 * an interrupt in the middle of a task switch..
23463 */
23464 pgd_paddr = read_cr3();
23465 +
23466 +#ifdef CONFIG_PAX_PER_CPU_PGD
23467 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23468 +#endif
23469 +
23470 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23471 if (!pmd_k)
23472 return -1;
23473 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23474 * happen within a race in page table update. In the later
23475 * case just flush:
23476 */
23477 +
23478 +#ifdef CONFIG_PAX_PER_CPU_PGD
23479 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23480 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23481 +#else
23482 pgd = pgd_offset(current->active_mm, address);
23483 +#endif
23484 +
23485 pgd_ref = pgd_offset_k(address);
23486 if (pgd_none(*pgd_ref))
23487 return -1;
23488 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23489 static int is_errata100(struct pt_regs *regs, unsigned long address)
23490 {
23491 #ifdef CONFIG_X86_64
23492 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23493 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23494 return 1;
23495 #endif
23496 return 0;
23497 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23498 }
23499
23500 static const char nx_warning[] = KERN_CRIT
23501 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23502 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23503
23504 static void
23505 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23506 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23507 if (!oops_may_print())
23508 return;
23509
23510 - if (error_code & PF_INSTR) {
23511 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23512 unsigned int level;
23513
23514 pte_t *pte = lookup_address(address, &level);
23515
23516 if (pte && pte_present(*pte) && !pte_exec(*pte))
23517 - printk(nx_warning, current_uid());
23518 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23519 }
23520
23521 +#ifdef CONFIG_PAX_KERNEXEC
23522 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23523 + if (current->signal->curr_ip)
23524 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23525 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23526 + else
23527 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23528 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23529 + }
23530 +#endif
23531 +
23532 printk(KERN_ALERT "BUG: unable to handle kernel ");
23533 if (address < PAGE_SIZE)
23534 printk(KERN_CONT "NULL pointer dereference");
23535 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23536 }
23537 #endif
23538
23539 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23540 + if (pax_is_fetch_fault(regs, error_code, address)) {
23541 +
23542 +#ifdef CONFIG_PAX_EMUTRAMP
23543 + switch (pax_handle_fetch_fault(regs)) {
23544 + case 2:
23545 + return;
23546 + }
23547 +#endif
23548 +
23549 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23550 + do_group_exit(SIGKILL);
23551 + }
23552 +#endif
23553 +
23554 if (unlikely(show_unhandled_signals))
23555 show_signal_msg(regs, error_code, address, tsk);
23556
23557 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23558 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23559 printk(KERN_ERR
23560 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23561 - tsk->comm, tsk->pid, address);
23562 + tsk->comm, task_pid_nr(tsk), address);
23563 code = BUS_MCEERR_AR;
23564 }
23565 #endif
23566 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23567 return 1;
23568 }
23569
23570 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23571 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23572 +{
23573 + pte_t *pte;
23574 + pmd_t *pmd;
23575 + spinlock_t *ptl;
23576 + unsigned char pte_mask;
23577 +
23578 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23579 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23580 + return 0;
23581 +
23582 + /* PaX: it's our fault, let's handle it if we can */
23583 +
23584 + /* PaX: take a look at read faults before acquiring any locks */
23585 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23586 + /* instruction fetch attempt from a protected page in user mode */
23587 + up_read(&mm->mmap_sem);
23588 +
23589 +#ifdef CONFIG_PAX_EMUTRAMP
23590 + switch (pax_handle_fetch_fault(regs)) {
23591 + case 2:
23592 + return 1;
23593 + }
23594 +#endif
23595 +
23596 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23597 + do_group_exit(SIGKILL);
23598 + }
23599 +
23600 + pmd = pax_get_pmd(mm, address);
23601 + if (unlikely(!pmd))
23602 + return 0;
23603 +
23604 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23605 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23606 + pte_unmap_unlock(pte, ptl);
23607 + return 0;
23608 + }
23609 +
23610 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23611 + /* write attempt to a protected page in user mode */
23612 + pte_unmap_unlock(pte, ptl);
23613 + return 0;
23614 + }
23615 +
23616 +#ifdef CONFIG_SMP
23617 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23618 +#else
23619 + if (likely(address > get_limit(regs->cs)))
23620 +#endif
23621 + {
23622 + set_pte(pte, pte_mkread(*pte));
23623 + __flush_tlb_one(address);
23624 + pte_unmap_unlock(pte, ptl);
23625 + up_read(&mm->mmap_sem);
23626 + return 1;
23627 + }
23628 +
23629 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23630 +
23631 + /*
23632 + * PaX: fill DTLB with user rights and retry
23633 + */
23634 + __asm__ __volatile__ (
23635 + "orb %2,(%1)\n"
23636 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23637 +/*
23638 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23639 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23640 + * page fault when examined during a TLB load attempt. this is true not only
23641 + * for PTEs holding a non-present entry but also present entries that will
23642 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23643 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23644 + * for our target pages since their PTEs are simply not in the TLBs at all.
23645 +
23646 + * the best thing in omitting it is that we gain around 15-20% speed in the
23647 + * fast path of the page fault handler and can get rid of tracing since we
23648 + * can no longer flush unintended entries.
23649 + */
23650 + "invlpg (%0)\n"
23651 +#endif
23652 + __copyuser_seg"testb $0,(%0)\n"
23653 + "xorb %3,(%1)\n"
23654 + :
23655 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23656 + : "memory", "cc");
23657 + pte_unmap_unlock(pte, ptl);
23658 + up_read(&mm->mmap_sem);
23659 + return 1;
23660 +}
23661 +#endif
23662 +
23663 /*
23664 * Handle a spurious fault caused by a stale TLB entry.
23665 *
23666 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23667 static inline int
23668 access_error(unsigned long error_code, struct vm_area_struct *vma)
23669 {
23670 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23671 + return 1;
23672 +
23673 if (error_code & PF_WRITE) {
23674 /* write, present and write, not present: */
23675 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23676 @@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23677 {
23678 struct vm_area_struct *vma;
23679 struct task_struct *tsk;
23680 - unsigned long address;
23681 struct mm_struct *mm;
23682 int fault;
23683 int write = error_code & PF_WRITE;
23684 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23685 (write ? FAULT_FLAG_WRITE : 0);
23686
23687 - tsk = current;
23688 - mm = tsk->mm;
23689 -
23690 /* Get the faulting address: */
23691 - address = read_cr2();
23692 + unsigned long address = read_cr2();
23693 +
23694 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23695 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23696 + if (!search_exception_tables(regs->ip)) {
23697 + bad_area_nosemaphore(regs, error_code, address);
23698 + return;
23699 + }
23700 + if (address < PAX_USER_SHADOW_BASE) {
23701 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23702 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23703 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23704 + } else
23705 + address -= PAX_USER_SHADOW_BASE;
23706 + }
23707 +#endif
23708 +
23709 + tsk = current;
23710 + mm = tsk->mm;
23711
23712 /*
23713 * Detect and handle instructions that would cause a page fault for
23714 @@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23715 * User-mode registers count as a user access even for any
23716 * potential system fault or CPU buglet:
23717 */
23718 - if (user_mode_vm(regs)) {
23719 + if (user_mode(regs)) {
23720 local_irq_enable();
23721 error_code |= PF_USER;
23722 } else {
23723 @@ -1132,6 +1338,11 @@ retry:
23724 might_sleep();
23725 }
23726
23727 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23728 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23729 + return;
23730 +#endif
23731 +
23732 vma = find_vma(mm, address);
23733 if (unlikely(!vma)) {
23734 bad_area(regs, error_code, address);
23735 @@ -1143,18 +1354,24 @@ retry:
23736 bad_area(regs, error_code, address);
23737 return;
23738 }
23739 - if (error_code & PF_USER) {
23740 - /*
23741 - * Accessing the stack below %sp is always a bug.
23742 - * The large cushion allows instructions like enter
23743 - * and pusha to work. ("enter $65535, $31" pushes
23744 - * 32 pointers and then decrements %sp by 65535.)
23745 - */
23746 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23747 - bad_area(regs, error_code, address);
23748 - return;
23749 - }
23750 + /*
23751 + * Accessing the stack below %sp is always a bug.
23752 + * The large cushion allows instructions like enter
23753 + * and pusha to work. ("enter $65535, $31" pushes
23754 + * 32 pointers and then decrements %sp by 65535.)
23755 + */
23756 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23757 + bad_area(regs, error_code, address);
23758 + return;
23759 }
23760 +
23761 +#ifdef CONFIG_PAX_SEGMEXEC
23762 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23763 + bad_area(regs, error_code, address);
23764 + return;
23765 + }
23766 +#endif
23767 +
23768 if (unlikely(expand_stack(vma, address))) {
23769 bad_area(regs, error_code, address);
23770 return;
23771 @@ -1209,3 +1426,292 @@ good_area:
23772
23773 up_read(&mm->mmap_sem);
23774 }
23775 +
23776 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23777 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23778 +{
23779 + struct mm_struct *mm = current->mm;
23780 + unsigned long ip = regs->ip;
23781 +
23782 + if (v8086_mode(regs))
23783 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23784 +
23785 +#ifdef CONFIG_PAX_PAGEEXEC
23786 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23787 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23788 + return true;
23789 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23790 + return true;
23791 + return false;
23792 + }
23793 +#endif
23794 +
23795 +#ifdef CONFIG_PAX_SEGMEXEC
23796 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23797 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23798 + return true;
23799 + return false;
23800 + }
23801 +#endif
23802 +
23803 + return false;
23804 +}
23805 +#endif
23806 +
23807 +#ifdef CONFIG_PAX_EMUTRAMP
23808 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23809 +{
23810 + int err;
23811 +
23812 + do { /* PaX: libffi trampoline emulation */
23813 + unsigned char mov, jmp;
23814 + unsigned int addr1, addr2;
23815 +
23816 +#ifdef CONFIG_X86_64
23817 + if ((regs->ip + 9) >> 32)
23818 + break;
23819 +#endif
23820 +
23821 + err = get_user(mov, (unsigned char __user *)regs->ip);
23822 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23823 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23824 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23825 +
23826 + if (err)
23827 + break;
23828 +
23829 + if (mov == 0xB8 && jmp == 0xE9) {
23830 + regs->ax = addr1;
23831 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23832 + return 2;
23833 + }
23834 + } while (0);
23835 +
23836 + do { /* PaX: gcc trampoline emulation #1 */
23837 + unsigned char mov1, mov2;
23838 + unsigned short jmp;
23839 + unsigned int addr1, addr2;
23840 +
23841 +#ifdef CONFIG_X86_64
23842 + if ((regs->ip + 11) >> 32)
23843 + break;
23844 +#endif
23845 +
23846 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23847 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23848 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23849 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23850 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23851 +
23852 + if (err)
23853 + break;
23854 +
23855 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23856 + regs->cx = addr1;
23857 + regs->ax = addr2;
23858 + regs->ip = addr2;
23859 + return 2;
23860 + }
23861 + } while (0);
23862 +
23863 + do { /* PaX: gcc trampoline emulation #2 */
23864 + unsigned char mov, jmp;
23865 + unsigned int addr1, addr2;
23866 +
23867 +#ifdef CONFIG_X86_64
23868 + if ((regs->ip + 9) >> 32)
23869 + break;
23870 +#endif
23871 +
23872 + err = get_user(mov, (unsigned char __user *)regs->ip);
23873 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23874 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23875 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23876 +
23877 + if (err)
23878 + break;
23879 +
23880 + if (mov == 0xB9 && jmp == 0xE9) {
23881 + regs->cx = addr1;
23882 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23883 + return 2;
23884 + }
23885 + } while (0);
23886 +
23887 + return 1; /* PaX in action */
23888 +}
23889 +
23890 +#ifdef CONFIG_X86_64
23891 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23892 +{
23893 + int err;
23894 +
23895 + do { /* PaX: libffi trampoline emulation */
23896 + unsigned short mov1, mov2, jmp1;
23897 + unsigned char stcclc, jmp2;
23898 + unsigned long addr1, addr2;
23899 +
23900 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23901 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23902 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23903 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23904 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23905 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23906 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23907 +
23908 + if (err)
23909 + break;
23910 +
23911 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23912 + regs->r11 = addr1;
23913 + regs->r10 = addr2;
23914 + if (stcclc == 0xF8)
23915 + regs->flags &= ~X86_EFLAGS_CF;
23916 + else
23917 + regs->flags |= X86_EFLAGS_CF;
23918 + regs->ip = addr1;
23919 + return 2;
23920 + }
23921 + } while (0);
23922 +
23923 + do { /* PaX: gcc trampoline emulation #1 */
23924 + unsigned short mov1, mov2, jmp1;
23925 + unsigned char jmp2;
23926 + unsigned int addr1;
23927 + unsigned long addr2;
23928 +
23929 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23930 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23931 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23932 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23933 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23934 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23935 +
23936 + if (err)
23937 + break;
23938 +
23939 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23940 + regs->r11 = addr1;
23941 + regs->r10 = addr2;
23942 + regs->ip = addr1;
23943 + return 2;
23944 + }
23945 + } while (0);
23946 +
23947 + do { /* PaX: gcc trampoline emulation #2 */
23948 + unsigned short mov1, mov2, jmp1;
23949 + unsigned char jmp2;
23950 + unsigned long addr1, addr2;
23951 +
23952 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23953 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23954 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23955 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23956 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23957 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23958 +
23959 + if (err)
23960 + break;
23961 +
23962 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23963 + regs->r11 = addr1;
23964 + regs->r10 = addr2;
23965 + regs->ip = addr1;
23966 + return 2;
23967 + }
23968 + } while (0);
23969 +
23970 + return 1; /* PaX in action */
23971 +}
23972 +#endif
23973 +
23974 +/*
23975 + * PaX: decide what to do with offenders (regs->ip = fault address)
23976 + *
23977 + * returns 1 when task should be killed
23978 + * 2 when gcc trampoline was detected
23979 + */
23980 +static int pax_handle_fetch_fault(struct pt_regs *regs)
23981 +{
23982 + if (v8086_mode(regs))
23983 + return 1;
23984 +
23985 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
23986 + return 1;
23987 +
23988 +#ifdef CONFIG_X86_32
23989 + return pax_handle_fetch_fault_32(regs);
23990 +#else
23991 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
23992 + return pax_handle_fetch_fault_32(regs);
23993 + else
23994 + return pax_handle_fetch_fault_64(regs);
23995 +#endif
23996 +}
23997 +#endif
23998 +
23999 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24000 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24001 +{
24002 + long i;
24003 +
24004 + printk(KERN_ERR "PAX: bytes at PC: ");
24005 + for (i = 0; i < 20; i++) {
24006 + unsigned char c;
24007 + if (get_user(c, (unsigned char __force_user *)pc+i))
24008 + printk(KERN_CONT "?? ");
24009 + else
24010 + printk(KERN_CONT "%02x ", c);
24011 + }
24012 + printk("\n");
24013 +
24014 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24015 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24016 + unsigned long c;
24017 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24018 +#ifdef CONFIG_X86_32
24019 + printk(KERN_CONT "???????? ");
24020 +#else
24021 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24022 + printk(KERN_CONT "???????? ???????? ");
24023 + else
24024 + printk(KERN_CONT "???????????????? ");
24025 +#endif
24026 + } else {
24027 +#ifdef CONFIG_X86_64
24028 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24029 + printk(KERN_CONT "%08x ", (unsigned int)c);
24030 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24031 + } else
24032 +#endif
24033 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24034 + }
24035 + }
24036 + printk("\n");
24037 +}
24038 +#endif
24039 +
24040 +/**
24041 + * probe_kernel_write(): safely attempt to write to a location
24042 + * @dst: address to write to
24043 + * @src: pointer to the data that shall be written
24044 + * @size: size of the data chunk
24045 + *
24046 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24047 + * happens, handle that and return -EFAULT.
24048 + */
24049 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24050 +{
24051 + long ret;
24052 + mm_segment_t old_fs = get_fs();
24053 +
24054 + set_fs(KERNEL_DS);
24055 + pagefault_disable();
24056 + pax_open_kernel();
24057 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24058 + pax_close_kernel();
24059 + pagefault_enable();
24060 + set_fs(old_fs);
24061 +
24062 + return ret ? -EFAULT : 0;
24063 +}
24064 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24065 index dd74e46..7d26398 100644
24066 --- a/arch/x86/mm/gup.c
24067 +++ b/arch/x86/mm/gup.c
24068 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24069 addr = start;
24070 len = (unsigned long) nr_pages << PAGE_SHIFT;
24071 end = start + len;
24072 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24073 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24074 (void __user *)start, len)))
24075 return 0;
24076
24077 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24078 index f4f29b1..5cac4fb 100644
24079 --- a/arch/x86/mm/highmem_32.c
24080 +++ b/arch/x86/mm/highmem_32.c
24081 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24082 idx = type + KM_TYPE_NR*smp_processor_id();
24083 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24084 BUG_ON(!pte_none(*(kmap_pte-idx)));
24085 +
24086 + pax_open_kernel();
24087 set_pte(kmap_pte-idx, mk_pte(page, prot));
24088 + pax_close_kernel();
24089 +
24090 arch_flush_lazy_mmu_mode();
24091
24092 return (void *)vaddr;
24093 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24094 index 8ecbb4b..29efd37 100644
24095 --- a/arch/x86/mm/hugetlbpage.c
24096 +++ b/arch/x86/mm/hugetlbpage.c
24097 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24098 struct hstate *h = hstate_file(file);
24099 struct mm_struct *mm = current->mm;
24100 struct vm_area_struct *vma;
24101 - unsigned long start_addr;
24102 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24103 +
24104 +#ifdef CONFIG_PAX_SEGMEXEC
24105 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24106 + pax_task_size = SEGMEXEC_TASK_SIZE;
24107 +#endif
24108 +
24109 + pax_task_size -= PAGE_SIZE;
24110
24111 if (len > mm->cached_hole_size) {
24112 - start_addr = mm->free_area_cache;
24113 + start_addr = mm->free_area_cache;
24114 } else {
24115 - start_addr = TASK_UNMAPPED_BASE;
24116 - mm->cached_hole_size = 0;
24117 + start_addr = mm->mmap_base;
24118 + mm->cached_hole_size = 0;
24119 }
24120
24121 full_search:
24122 @@ -280,26 +287,27 @@ full_search:
24123
24124 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24125 /* At this point: (!vma || addr < vma->vm_end). */
24126 - if (TASK_SIZE - len < addr) {
24127 + if (pax_task_size - len < addr) {
24128 /*
24129 * Start a new search - just in case we missed
24130 * some holes.
24131 */
24132 - if (start_addr != TASK_UNMAPPED_BASE) {
24133 - start_addr = TASK_UNMAPPED_BASE;
24134 + if (start_addr != mm->mmap_base) {
24135 + start_addr = mm->mmap_base;
24136 mm->cached_hole_size = 0;
24137 goto full_search;
24138 }
24139 return -ENOMEM;
24140 }
24141 - if (!vma || addr + len <= vma->vm_start) {
24142 - mm->free_area_cache = addr + len;
24143 - return addr;
24144 - }
24145 + if (check_heap_stack_gap(vma, addr, len))
24146 + break;
24147 if (addr + mm->cached_hole_size < vma->vm_start)
24148 mm->cached_hole_size = vma->vm_start - addr;
24149 addr = ALIGN(vma->vm_end, huge_page_size(h));
24150 }
24151 +
24152 + mm->free_area_cache = addr + len;
24153 + return addr;
24154 }
24155
24156 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24157 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24158 {
24159 struct hstate *h = hstate_file(file);
24160 struct mm_struct *mm = current->mm;
24161 - struct vm_area_struct *vma, *prev_vma;
24162 - unsigned long base = mm->mmap_base, addr = addr0;
24163 + struct vm_area_struct *vma;
24164 + unsigned long base = mm->mmap_base, addr;
24165 unsigned long largest_hole = mm->cached_hole_size;
24166 - int first_time = 1;
24167
24168 /* don't allow allocations above current base */
24169 if (mm->free_area_cache > base)
24170 @@ -321,66 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24171 largest_hole = 0;
24172 mm->free_area_cache = base;
24173 }
24174 -try_again:
24175 +
24176 /* make sure it can fit in the remaining address space */
24177 if (mm->free_area_cache < len)
24178 goto fail;
24179
24180 /* either no address requested or can't fit in requested address hole */
24181 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24182 + addr = (mm->free_area_cache - len);
24183 do {
24184 + addr &= huge_page_mask(h);
24185 + vma = find_vma(mm, addr);
24186 /*
24187 * Lookup failure means no vma is above this address,
24188 * i.e. return with success:
24189 - */
24190 - vma = find_vma(mm, addr);
24191 - if (!vma)
24192 - return addr;
24193 -
24194 - /*
24195 * new region fits between prev_vma->vm_end and
24196 * vma->vm_start, use it:
24197 */
24198 - prev_vma = vma->vm_prev;
24199 - if (addr + len <= vma->vm_start &&
24200 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24201 + if (check_heap_stack_gap(vma, addr, len)) {
24202 /* remember the address as a hint for next time */
24203 - mm->cached_hole_size = largest_hole;
24204 - return (mm->free_area_cache = addr);
24205 - } else {
24206 - /* pull free_area_cache down to the first hole */
24207 - if (mm->free_area_cache == vma->vm_end) {
24208 - mm->free_area_cache = vma->vm_start;
24209 - mm->cached_hole_size = largest_hole;
24210 - }
24211 + mm->cached_hole_size = largest_hole;
24212 + return (mm->free_area_cache = addr);
24213 + }
24214 + /* pull free_area_cache down to the first hole */
24215 + if (mm->free_area_cache == vma->vm_end) {
24216 + mm->free_area_cache = vma->vm_start;
24217 + mm->cached_hole_size = largest_hole;
24218 }
24219
24220 /* remember the largest hole we saw so far */
24221 if (addr + largest_hole < vma->vm_start)
24222 - largest_hole = vma->vm_start - addr;
24223 + largest_hole = vma->vm_start - addr;
24224
24225 /* try just below the current vma->vm_start */
24226 - addr = (vma->vm_start - len) & huge_page_mask(h);
24227 - } while (len <= vma->vm_start);
24228 + addr = skip_heap_stack_gap(vma, len);
24229 + } while (!IS_ERR_VALUE(addr));
24230
24231 fail:
24232 /*
24233 - * if hint left us with no space for the requested
24234 - * mapping then try again:
24235 - */
24236 - if (first_time) {
24237 - mm->free_area_cache = base;
24238 - largest_hole = 0;
24239 - first_time = 0;
24240 - goto try_again;
24241 - }
24242 - /*
24243 * A failed mmap() very likely causes application failure,
24244 * so fall back to the bottom-up function here. This scenario
24245 * can happen with large stack limits and large mmap()
24246 * allocations.
24247 */
24248 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24249 +
24250 +#ifdef CONFIG_PAX_SEGMEXEC
24251 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24252 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24253 + else
24254 +#endif
24255 +
24256 + mm->mmap_base = TASK_UNMAPPED_BASE;
24257 +
24258 +#ifdef CONFIG_PAX_RANDMMAP
24259 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24260 + mm->mmap_base += mm->delta_mmap;
24261 +#endif
24262 +
24263 + mm->free_area_cache = mm->mmap_base;
24264 mm->cached_hole_size = ~0UL;
24265 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24266 len, pgoff, flags);
24267 @@ -388,6 +392,7 @@ fail:
24268 /*
24269 * Restore the topdown base:
24270 */
24271 + mm->mmap_base = base;
24272 mm->free_area_cache = base;
24273 mm->cached_hole_size = ~0UL;
24274
24275 @@ -401,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24276 struct hstate *h = hstate_file(file);
24277 struct mm_struct *mm = current->mm;
24278 struct vm_area_struct *vma;
24279 + unsigned long pax_task_size = TASK_SIZE;
24280
24281 if (len & ~huge_page_mask(h))
24282 return -EINVAL;
24283 - if (len > TASK_SIZE)
24284 +
24285 +#ifdef CONFIG_PAX_SEGMEXEC
24286 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24287 + pax_task_size = SEGMEXEC_TASK_SIZE;
24288 +#endif
24289 +
24290 + pax_task_size -= PAGE_SIZE;
24291 +
24292 + if (len > pax_task_size)
24293 return -ENOMEM;
24294
24295 if (flags & MAP_FIXED) {
24296 @@ -416,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24297 if (addr) {
24298 addr = ALIGN(addr, huge_page_size(h));
24299 vma = find_vma(mm, addr);
24300 - if (TASK_SIZE - len >= addr &&
24301 - (!vma || addr + len <= vma->vm_start))
24302 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24303 return addr;
24304 }
24305 if (mm->get_unmapped_area == arch_get_unmapped_area)
24306 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24307 index 6cabf65..77e9c1c 100644
24308 --- a/arch/x86/mm/init.c
24309 +++ b/arch/x86/mm/init.c
24310 @@ -17,6 +17,7 @@
24311 #include <asm/tlb.h>
24312 #include <asm/proto.h>
24313 #include <asm/dma.h> /* for MAX_DMA_PFN */
24314 +#include <asm/desc.h>
24315
24316 unsigned long __initdata pgt_buf_start;
24317 unsigned long __meminitdata pgt_buf_end;
24318 @@ -33,7 +34,7 @@ int direct_gbpages
24319 static void __init find_early_table_space(unsigned long end, int use_pse,
24320 int use_gbpages)
24321 {
24322 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24323 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24324 phys_addr_t base;
24325
24326 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24327 @@ -314,8 +315,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24328 */
24329 int devmem_is_allowed(unsigned long pagenr)
24330 {
24331 +#ifdef CONFIG_GRKERNSEC_KMEM
24332 + /* allow BDA */
24333 + if (!pagenr)
24334 + return 1;
24335 + /* allow EBDA */
24336 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24337 + return 1;
24338 +#else
24339 + if (!pagenr)
24340 + return 1;
24341 +#ifdef CONFIG_VM86
24342 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24343 + return 1;
24344 +#endif
24345 +#endif
24346 +
24347 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24348 + return 1;
24349 +#ifdef CONFIG_GRKERNSEC_KMEM
24350 + /* throw out everything else below 1MB */
24351 if (pagenr <= 256)
24352 - return 1;
24353 + return 0;
24354 +#endif
24355 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24356 return 0;
24357 if (!page_is_ram(pagenr))
24358 @@ -374,6 +396,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24359
24360 void free_initmem(void)
24361 {
24362 +
24363 +#ifdef CONFIG_PAX_KERNEXEC
24364 +#ifdef CONFIG_X86_32
24365 + /* PaX: limit KERNEL_CS to actual size */
24366 + unsigned long addr, limit;
24367 + struct desc_struct d;
24368 + int cpu;
24369 +
24370 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24371 + limit = (limit - 1UL) >> PAGE_SHIFT;
24372 +
24373 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24374 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24375 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24376 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24377 + }
24378 +
24379 + /* PaX: make KERNEL_CS read-only */
24380 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24381 + if (!paravirt_enabled())
24382 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24383 +/*
24384 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24385 + pgd = pgd_offset_k(addr);
24386 + pud = pud_offset(pgd, addr);
24387 + pmd = pmd_offset(pud, addr);
24388 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24389 + }
24390 +*/
24391 +#ifdef CONFIG_X86_PAE
24392 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24393 +/*
24394 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24395 + pgd = pgd_offset_k(addr);
24396 + pud = pud_offset(pgd, addr);
24397 + pmd = pmd_offset(pud, addr);
24398 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24399 + }
24400 +*/
24401 +#endif
24402 +
24403 +#ifdef CONFIG_MODULES
24404 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24405 +#endif
24406 +
24407 +#else
24408 + pgd_t *pgd;
24409 + pud_t *pud;
24410 + pmd_t *pmd;
24411 + unsigned long addr, end;
24412 +
24413 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24414 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24415 + pgd = pgd_offset_k(addr);
24416 + pud = pud_offset(pgd, addr);
24417 + pmd = pmd_offset(pud, addr);
24418 + if (!pmd_present(*pmd))
24419 + continue;
24420 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24421 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24422 + else
24423 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24424 + }
24425 +
24426 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24427 + end = addr + KERNEL_IMAGE_SIZE;
24428 + for (; addr < end; addr += PMD_SIZE) {
24429 + pgd = pgd_offset_k(addr);
24430 + pud = pud_offset(pgd, addr);
24431 + pmd = pmd_offset(pud, addr);
24432 + if (!pmd_present(*pmd))
24433 + continue;
24434 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24435 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24436 + }
24437 +#endif
24438 +
24439 + flush_tlb_all();
24440 +#endif
24441 +
24442 free_init_pages("unused kernel memory",
24443 (unsigned long)(&__init_begin),
24444 (unsigned long)(&__init_end));
24445 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24446 index 8663f6c..829ae76 100644
24447 --- a/arch/x86/mm/init_32.c
24448 +++ b/arch/x86/mm/init_32.c
24449 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24450 }
24451
24452 /*
24453 - * Creates a middle page table and puts a pointer to it in the
24454 - * given global directory entry. This only returns the gd entry
24455 - * in non-PAE compilation mode, since the middle layer is folded.
24456 - */
24457 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24458 -{
24459 - pud_t *pud;
24460 - pmd_t *pmd_table;
24461 -
24462 -#ifdef CONFIG_X86_PAE
24463 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24464 - if (after_bootmem)
24465 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24466 - else
24467 - pmd_table = (pmd_t *)alloc_low_page();
24468 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24469 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24470 - pud = pud_offset(pgd, 0);
24471 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24472 -
24473 - return pmd_table;
24474 - }
24475 -#endif
24476 - pud = pud_offset(pgd, 0);
24477 - pmd_table = pmd_offset(pud, 0);
24478 -
24479 - return pmd_table;
24480 -}
24481 -
24482 -/*
24483 * Create a page table and place a pointer to it in a middle page
24484 * directory entry:
24485 */
24486 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24487 page_table = (pte_t *)alloc_low_page();
24488
24489 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24490 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24491 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24492 +#else
24493 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24494 +#endif
24495 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24496 }
24497
24498 return pte_offset_kernel(pmd, 0);
24499 }
24500
24501 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24502 +{
24503 + pud_t *pud;
24504 + pmd_t *pmd_table;
24505 +
24506 + pud = pud_offset(pgd, 0);
24507 + pmd_table = pmd_offset(pud, 0);
24508 +
24509 + return pmd_table;
24510 +}
24511 +
24512 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24513 {
24514 int pgd_idx = pgd_index(vaddr);
24515 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24516 int pgd_idx, pmd_idx;
24517 unsigned long vaddr;
24518 pgd_t *pgd;
24519 + pud_t *pud;
24520 pmd_t *pmd;
24521 pte_t *pte = NULL;
24522
24523 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24524 pgd = pgd_base + pgd_idx;
24525
24526 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24527 - pmd = one_md_table_init(pgd);
24528 - pmd = pmd + pmd_index(vaddr);
24529 + pud = pud_offset(pgd, vaddr);
24530 + pmd = pmd_offset(pud, vaddr);
24531 +
24532 +#ifdef CONFIG_X86_PAE
24533 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24534 +#endif
24535 +
24536 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24537 pmd++, pmd_idx++) {
24538 pte = page_table_kmap_check(one_page_table_init(pmd),
24539 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24540 }
24541 }
24542
24543 -static inline int is_kernel_text(unsigned long addr)
24544 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24545 {
24546 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24547 - return 1;
24548 - return 0;
24549 + if ((start > ktla_ktva((unsigned long)_etext) ||
24550 + end <= ktla_ktva((unsigned long)_stext)) &&
24551 + (start > ktla_ktva((unsigned long)_einittext) ||
24552 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24553 +
24554 +#ifdef CONFIG_ACPI_SLEEP
24555 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24556 +#endif
24557 +
24558 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24559 + return 0;
24560 + return 1;
24561 }
24562
24563 /*
24564 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24565 unsigned long last_map_addr = end;
24566 unsigned long start_pfn, end_pfn;
24567 pgd_t *pgd_base = swapper_pg_dir;
24568 - int pgd_idx, pmd_idx, pte_ofs;
24569 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24570 unsigned long pfn;
24571 pgd_t *pgd;
24572 + pud_t *pud;
24573 pmd_t *pmd;
24574 pte_t *pte;
24575 unsigned pages_2m, pages_4k;
24576 @@ -281,8 +282,13 @@ repeat:
24577 pfn = start_pfn;
24578 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24579 pgd = pgd_base + pgd_idx;
24580 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24581 - pmd = one_md_table_init(pgd);
24582 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24583 + pud = pud_offset(pgd, 0);
24584 + pmd = pmd_offset(pud, 0);
24585 +
24586 +#ifdef CONFIG_X86_PAE
24587 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24588 +#endif
24589
24590 if (pfn >= end_pfn)
24591 continue;
24592 @@ -294,14 +300,13 @@ repeat:
24593 #endif
24594 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24595 pmd++, pmd_idx++) {
24596 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24597 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24598
24599 /*
24600 * Map with big pages if possible, otherwise
24601 * create normal page tables:
24602 */
24603 if (use_pse) {
24604 - unsigned int addr2;
24605 pgprot_t prot = PAGE_KERNEL_LARGE;
24606 /*
24607 * first pass will use the same initial
24608 @@ -311,11 +316,7 @@ repeat:
24609 __pgprot(PTE_IDENT_ATTR |
24610 _PAGE_PSE);
24611
24612 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24613 - PAGE_OFFSET + PAGE_SIZE-1;
24614 -
24615 - if (is_kernel_text(addr) ||
24616 - is_kernel_text(addr2))
24617 + if (is_kernel_text(address, address + PMD_SIZE))
24618 prot = PAGE_KERNEL_LARGE_EXEC;
24619
24620 pages_2m++;
24621 @@ -332,7 +333,7 @@ repeat:
24622 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24623 pte += pte_ofs;
24624 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24625 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24626 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24627 pgprot_t prot = PAGE_KERNEL;
24628 /*
24629 * first pass will use the same initial
24630 @@ -340,7 +341,7 @@ repeat:
24631 */
24632 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24633
24634 - if (is_kernel_text(addr))
24635 + if (is_kernel_text(address, address + PAGE_SIZE))
24636 prot = PAGE_KERNEL_EXEC;
24637
24638 pages_4k++;
24639 @@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24640
24641 pud = pud_offset(pgd, va);
24642 pmd = pmd_offset(pud, va);
24643 - if (!pmd_present(*pmd))
24644 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24645 break;
24646
24647 pte = pte_offset_kernel(pmd, va);
24648 @@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
24649
24650 static void __init pagetable_init(void)
24651 {
24652 - pgd_t *pgd_base = swapper_pg_dir;
24653 -
24654 - permanent_kmaps_init(pgd_base);
24655 + permanent_kmaps_init(swapper_pg_dir);
24656 }
24657
24658 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24659 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24660 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24661
24662 /* user-defined highmem size */
24663 @@ -735,6 +734,12 @@ void __init mem_init(void)
24664
24665 pci_iommu_alloc();
24666
24667 +#ifdef CONFIG_PAX_PER_CPU_PGD
24668 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24669 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24670 + KERNEL_PGD_PTRS);
24671 +#endif
24672 +
24673 #ifdef CONFIG_FLATMEM
24674 BUG_ON(!mem_map);
24675 #endif
24676 @@ -761,7 +766,7 @@ void __init mem_init(void)
24677 reservedpages++;
24678
24679 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24680 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24681 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24682 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24683
24684 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24685 @@ -802,10 +807,10 @@ void __init mem_init(void)
24686 ((unsigned long)&__init_end -
24687 (unsigned long)&__init_begin) >> 10,
24688
24689 - (unsigned long)&_etext, (unsigned long)&_edata,
24690 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24691 + (unsigned long)&_sdata, (unsigned long)&_edata,
24692 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24693
24694 - (unsigned long)&_text, (unsigned long)&_etext,
24695 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24696 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24697
24698 /*
24699 @@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
24700 if (!kernel_set_to_readonly)
24701 return;
24702
24703 + start = ktla_ktva(start);
24704 pr_debug("Set kernel text: %lx - %lx for read write\n",
24705 start, start+size);
24706
24707 @@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
24708 if (!kernel_set_to_readonly)
24709 return;
24710
24711 + start = ktla_ktva(start);
24712 pr_debug("Set kernel text: %lx - %lx for read only\n",
24713 start, start+size);
24714
24715 @@ -925,6 +932,7 @@ void mark_rodata_ro(void)
24716 unsigned long start = PFN_ALIGN(_text);
24717 unsigned long size = PFN_ALIGN(_etext) - start;
24718
24719 + start = ktla_ktva(start);
24720 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24721 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24722 size >> 10);
24723 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24724 index 436a030..b8596b9 100644
24725 --- a/arch/x86/mm/init_64.c
24726 +++ b/arch/x86/mm/init_64.c
24727 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24728 * around without checking the pgd every time.
24729 */
24730
24731 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24732 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24733 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24734
24735 int force_personality32;
24736 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24737
24738 for (address = start; address <= end; address += PGDIR_SIZE) {
24739 const pgd_t *pgd_ref = pgd_offset_k(address);
24740 +
24741 +#ifdef CONFIG_PAX_PER_CPU_PGD
24742 + unsigned long cpu;
24743 +#else
24744 struct page *page;
24745 +#endif
24746
24747 if (pgd_none(*pgd_ref))
24748 continue;
24749
24750 spin_lock(&pgd_lock);
24751 +
24752 +#ifdef CONFIG_PAX_PER_CPU_PGD
24753 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24754 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24755 +#else
24756 list_for_each_entry(page, &pgd_list, lru) {
24757 pgd_t *pgd;
24758 spinlock_t *pgt_lock;
24759 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24760 /* the pgt_lock only for Xen */
24761 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24762 spin_lock(pgt_lock);
24763 +#endif
24764
24765 if (pgd_none(*pgd))
24766 set_pgd(pgd, *pgd_ref);
24767 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24768 BUG_ON(pgd_page_vaddr(*pgd)
24769 != pgd_page_vaddr(*pgd_ref));
24770
24771 +#ifndef CONFIG_PAX_PER_CPU_PGD
24772 spin_unlock(pgt_lock);
24773 +#endif
24774 +
24775 }
24776 spin_unlock(&pgd_lock);
24777 }
24778 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24779 pmd = fill_pmd(pud, vaddr);
24780 pte = fill_pte(pmd, vaddr);
24781
24782 + pax_open_kernel();
24783 set_pte(pte, new_pte);
24784 + pax_close_kernel();
24785
24786 /*
24787 * It's enough to flush this one mapping.
24788 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24789 pgd = pgd_offset_k((unsigned long)__va(phys));
24790 if (pgd_none(*pgd)) {
24791 pud = (pud_t *) spp_getpage();
24792 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24793 - _PAGE_USER));
24794 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24795 }
24796 pud = pud_offset(pgd, (unsigned long)__va(phys));
24797 if (pud_none(*pud)) {
24798 pmd = (pmd_t *) spp_getpage();
24799 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24800 - _PAGE_USER));
24801 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24802 }
24803 pmd = pmd_offset(pud, phys);
24804 BUG_ON(!pmd_none(*pmd));
24805 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24806 if (pfn >= pgt_buf_top)
24807 panic("alloc_low_page: ran out of memory");
24808
24809 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24810 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24811 clear_page(adr);
24812 *phys = pfn * PAGE_SIZE;
24813 return adr;
24814 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24815
24816 phys = __pa(virt);
24817 left = phys & (PAGE_SIZE - 1);
24818 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24819 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24820 adr = (void *)(((unsigned long)adr) | left);
24821
24822 return adr;
24823 @@ -684,6 +698,12 @@ void __init mem_init(void)
24824
24825 pci_iommu_alloc();
24826
24827 +#ifdef CONFIG_PAX_PER_CPU_PGD
24828 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24829 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24830 + KERNEL_PGD_PTRS);
24831 +#endif
24832 +
24833 /* clear_bss() already clear the empty_zero_page */
24834
24835 reservedpages = 0;
24836 @@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
24837 static struct vm_area_struct gate_vma = {
24838 .vm_start = VSYSCALL_START,
24839 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24840 - .vm_page_prot = PAGE_READONLY_EXEC,
24841 - .vm_flags = VM_READ | VM_EXEC
24842 + .vm_page_prot = PAGE_READONLY,
24843 + .vm_flags = VM_READ
24844 };
24845
24846 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24847 @@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
24848
24849 const char *arch_vma_name(struct vm_area_struct *vma)
24850 {
24851 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24852 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24853 return "[vdso]";
24854 if (vma == &gate_vma)
24855 return "[vsyscall]";
24856 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24857 index 7b179b4..6bd1777 100644
24858 --- a/arch/x86/mm/iomap_32.c
24859 +++ b/arch/x86/mm/iomap_32.c
24860 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24861 type = kmap_atomic_idx_push();
24862 idx = type + KM_TYPE_NR * smp_processor_id();
24863 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24864 +
24865 + pax_open_kernel();
24866 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24867 + pax_close_kernel();
24868 +
24869 arch_flush_lazy_mmu_mode();
24870
24871 return (void *)vaddr;
24872 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24873 index be1ef57..55f0160 100644
24874 --- a/arch/x86/mm/ioremap.c
24875 +++ b/arch/x86/mm/ioremap.c
24876 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24877 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24878 int is_ram = page_is_ram(pfn);
24879
24880 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24881 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24882 return NULL;
24883 WARN_ON_ONCE(is_ram);
24884 }
24885 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24886
24887 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24888 if (page_is_ram(start >> PAGE_SHIFT))
24889 +#ifdef CONFIG_HIGHMEM
24890 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24891 +#endif
24892 return __va(phys);
24893
24894 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24895 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24896 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24897
24898 static __initdata int after_paging_init;
24899 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24900 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24901
24902 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24903 {
24904 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24905 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24906
24907 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24908 - memset(bm_pte, 0, sizeof(bm_pte));
24909 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
24910 + pmd_populate_user(&init_mm, pmd, bm_pte);
24911
24912 /*
24913 * The boot-ioremap range spans multiple pmds, for which
24914 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
24915 index d87dd6d..bf3fa66 100644
24916 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
24917 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
24918 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
24919 * memory (e.g. tracked pages)? For now, we need this to avoid
24920 * invoking kmemcheck for PnP BIOS calls.
24921 */
24922 - if (regs->flags & X86_VM_MASK)
24923 + if (v8086_mode(regs))
24924 return false;
24925 - if (regs->cs != __KERNEL_CS)
24926 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
24927 return false;
24928
24929 pte = kmemcheck_pte_lookup(address);
24930 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
24931 index 845df68..1d8d29f 100644
24932 --- a/arch/x86/mm/mmap.c
24933 +++ b/arch/x86/mm/mmap.c
24934 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
24935 * Leave an at least ~128 MB hole with possible stack randomization.
24936 */
24937 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
24938 -#define MAX_GAP (TASK_SIZE/6*5)
24939 +#define MAX_GAP (pax_task_size/6*5)
24940
24941 static int mmap_is_legacy(void)
24942 {
24943 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
24944 return rnd << PAGE_SHIFT;
24945 }
24946
24947 -static unsigned long mmap_base(void)
24948 +static unsigned long mmap_base(struct mm_struct *mm)
24949 {
24950 unsigned long gap = rlimit(RLIMIT_STACK);
24951 + unsigned long pax_task_size = TASK_SIZE;
24952 +
24953 +#ifdef CONFIG_PAX_SEGMEXEC
24954 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24955 + pax_task_size = SEGMEXEC_TASK_SIZE;
24956 +#endif
24957
24958 if (gap < MIN_GAP)
24959 gap = MIN_GAP;
24960 else if (gap > MAX_GAP)
24961 gap = MAX_GAP;
24962
24963 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
24964 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
24965 }
24966
24967 /*
24968 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
24969 * does, but not when emulating X86_32
24970 */
24971 -static unsigned long mmap_legacy_base(void)
24972 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
24973 {
24974 - if (mmap_is_ia32())
24975 + if (mmap_is_ia32()) {
24976 +
24977 +#ifdef CONFIG_PAX_SEGMEXEC
24978 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24979 + return SEGMEXEC_TASK_UNMAPPED_BASE;
24980 + else
24981 +#endif
24982 +
24983 return TASK_UNMAPPED_BASE;
24984 - else
24985 + } else
24986 return TASK_UNMAPPED_BASE + mmap_rnd();
24987 }
24988
24989 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
24990 void arch_pick_mmap_layout(struct mm_struct *mm)
24991 {
24992 if (mmap_is_legacy()) {
24993 - mm->mmap_base = mmap_legacy_base();
24994 + mm->mmap_base = mmap_legacy_base(mm);
24995 +
24996 +#ifdef CONFIG_PAX_RANDMMAP
24997 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24998 + mm->mmap_base += mm->delta_mmap;
24999 +#endif
25000 +
25001 mm->get_unmapped_area = arch_get_unmapped_area;
25002 mm->unmap_area = arch_unmap_area;
25003 } else {
25004 - mm->mmap_base = mmap_base();
25005 + mm->mmap_base = mmap_base(mm);
25006 +
25007 +#ifdef CONFIG_PAX_RANDMMAP
25008 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25009 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25010 +#endif
25011 +
25012 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25013 mm->unmap_area = arch_unmap_area_topdown;
25014 }
25015 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25016 index dc0b727..dc9d71a 100644
25017 --- a/arch/x86/mm/mmio-mod.c
25018 +++ b/arch/x86/mm/mmio-mod.c
25019 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25020 break;
25021 default:
25022 {
25023 - unsigned char *ip = (unsigned char *)instptr;
25024 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25025 my_trace->opcode = MMIO_UNKNOWN_OP;
25026 my_trace->width = 0;
25027 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25028 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25029 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25030 void __iomem *addr)
25031 {
25032 - static atomic_t next_id;
25033 + static atomic_unchecked_t next_id;
25034 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25035 /* These are page-unaligned. */
25036 struct mmiotrace_map map = {
25037 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25038 .private = trace
25039 },
25040 .phys = offset,
25041 - .id = atomic_inc_return(&next_id)
25042 + .id = atomic_inc_return_unchecked(&next_id)
25043 };
25044 map.map_id = trace->id;
25045
25046 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25047 index b008656..773eac2 100644
25048 --- a/arch/x86/mm/pageattr-test.c
25049 +++ b/arch/x86/mm/pageattr-test.c
25050 @@ -36,7 +36,7 @@ enum {
25051
25052 static int pte_testbit(pte_t pte)
25053 {
25054 - return pte_flags(pte) & _PAGE_UNUSED1;
25055 + return pte_flags(pte) & _PAGE_CPA_TEST;
25056 }
25057
25058 struct split_state {
25059 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25060 index e1ebde3..b1e1db38 100644
25061 --- a/arch/x86/mm/pageattr.c
25062 +++ b/arch/x86/mm/pageattr.c
25063 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25064 */
25065 #ifdef CONFIG_PCI_BIOS
25066 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25067 - pgprot_val(forbidden) |= _PAGE_NX;
25068 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25069 #endif
25070
25071 /*
25072 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25073 * Does not cover __inittext since that is gone later on. On
25074 * 64bit we do not enforce !NX on the low mapping
25075 */
25076 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25077 - pgprot_val(forbidden) |= _PAGE_NX;
25078 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25079 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25080
25081 +#ifdef CONFIG_DEBUG_RODATA
25082 /*
25083 * The .rodata section needs to be read-only. Using the pfn
25084 * catches all aliases.
25085 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25086 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25087 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25088 pgprot_val(forbidden) |= _PAGE_RW;
25089 +#endif
25090
25091 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25092 /*
25093 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25094 }
25095 #endif
25096
25097 +#ifdef CONFIG_PAX_KERNEXEC
25098 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25099 + pgprot_val(forbidden) |= _PAGE_RW;
25100 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25101 + }
25102 +#endif
25103 +
25104 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25105
25106 return prot;
25107 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25108 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25109 {
25110 /* change init_mm */
25111 + pax_open_kernel();
25112 set_pte_atomic(kpte, pte);
25113 +
25114 #ifdef CONFIG_X86_32
25115 if (!SHARED_KERNEL_PMD) {
25116 +
25117 +#ifdef CONFIG_PAX_PER_CPU_PGD
25118 + unsigned long cpu;
25119 +#else
25120 struct page *page;
25121 +#endif
25122
25123 +#ifdef CONFIG_PAX_PER_CPU_PGD
25124 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25125 + pgd_t *pgd = get_cpu_pgd(cpu);
25126 +#else
25127 list_for_each_entry(page, &pgd_list, lru) {
25128 - pgd_t *pgd;
25129 + pgd_t *pgd = (pgd_t *)page_address(page);
25130 +#endif
25131 +
25132 pud_t *pud;
25133 pmd_t *pmd;
25134
25135 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25136 + pgd += pgd_index(address);
25137 pud = pud_offset(pgd, address);
25138 pmd = pmd_offset(pud, address);
25139 set_pte_atomic((pte_t *)pmd, pte);
25140 }
25141 }
25142 #endif
25143 + pax_close_kernel();
25144 }
25145
25146 static int
25147 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25148 index f6ff57b..481690f 100644
25149 --- a/arch/x86/mm/pat.c
25150 +++ b/arch/x86/mm/pat.c
25151 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25152
25153 if (!entry) {
25154 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25155 - current->comm, current->pid, start, end);
25156 + current->comm, task_pid_nr(current), start, end);
25157 return -EINVAL;
25158 }
25159
25160 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25161 while (cursor < to) {
25162 if (!devmem_is_allowed(pfn)) {
25163 printk(KERN_INFO
25164 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25165 - current->comm, from, to);
25166 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25167 + current->comm, from, to, cursor);
25168 return 0;
25169 }
25170 cursor += PAGE_SIZE;
25171 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25172 printk(KERN_INFO
25173 "%s:%d ioremap_change_attr failed %s "
25174 "for %Lx-%Lx\n",
25175 - current->comm, current->pid,
25176 + current->comm, task_pid_nr(current),
25177 cattr_name(flags),
25178 base, (unsigned long long)(base + size));
25179 return -EINVAL;
25180 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25181 if (want_flags != flags) {
25182 printk(KERN_WARNING
25183 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25184 - current->comm, current->pid,
25185 + current->comm, task_pid_nr(current),
25186 cattr_name(want_flags),
25187 (unsigned long long)paddr,
25188 (unsigned long long)(paddr + size),
25189 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25190 free_memtype(paddr, paddr + size);
25191 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25192 " for %Lx-%Lx, got %s\n",
25193 - current->comm, current->pid,
25194 + current->comm, task_pid_nr(current),
25195 cattr_name(want_flags),
25196 (unsigned long long)paddr,
25197 (unsigned long long)(paddr + size),
25198 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25199 index 9f0614d..92ae64a 100644
25200 --- a/arch/x86/mm/pf_in.c
25201 +++ b/arch/x86/mm/pf_in.c
25202 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25203 int i;
25204 enum reason_type rv = OTHERS;
25205
25206 - p = (unsigned char *)ins_addr;
25207 + p = (unsigned char *)ktla_ktva(ins_addr);
25208 p += skip_prefix(p, &prf);
25209 p += get_opcode(p, &opcode);
25210
25211 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25212 struct prefix_bits prf;
25213 int i;
25214
25215 - p = (unsigned char *)ins_addr;
25216 + p = (unsigned char *)ktla_ktva(ins_addr);
25217 p += skip_prefix(p, &prf);
25218 p += get_opcode(p, &opcode);
25219
25220 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25221 struct prefix_bits prf;
25222 int i;
25223
25224 - p = (unsigned char *)ins_addr;
25225 + p = (unsigned char *)ktla_ktva(ins_addr);
25226 p += skip_prefix(p, &prf);
25227 p += get_opcode(p, &opcode);
25228
25229 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25230 struct prefix_bits prf;
25231 int i;
25232
25233 - p = (unsigned char *)ins_addr;
25234 + p = (unsigned char *)ktla_ktva(ins_addr);
25235 p += skip_prefix(p, &prf);
25236 p += get_opcode(p, &opcode);
25237 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25238 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25239 struct prefix_bits prf;
25240 int i;
25241
25242 - p = (unsigned char *)ins_addr;
25243 + p = (unsigned char *)ktla_ktva(ins_addr);
25244 p += skip_prefix(p, &prf);
25245 p += get_opcode(p, &opcode);
25246 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25247 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25248 index 8573b83..7d9628f 100644
25249 --- a/arch/x86/mm/pgtable.c
25250 +++ b/arch/x86/mm/pgtable.c
25251 @@ -84,10 +84,60 @@ static inline void pgd_list_del(pgd_t *pgd)
25252 list_del(&page->lru);
25253 }
25254
25255 -#define UNSHARED_PTRS_PER_PGD \
25256 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25257 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25258 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25259
25260 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25261 +{
25262 + while (count--)
25263 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25264 +}
25265 +#endif
25266
25267 +#ifdef CONFIG_PAX_PER_CPU_PGD
25268 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25269 +{
25270 + while (count--) {
25271 + pgd_t pgd;
25272 +
25273 +#ifdef CONFIG_X86_64
25274 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25275 +#else
25276 + pgd = *src++;
25277 +#endif
25278 +
25279 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25280 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25281 +#endif
25282 +
25283 + *dst++ = pgd;
25284 + }
25285 +
25286 +}
25287 +#endif
25288 +
25289 +#ifdef CONFIG_X86_64
25290 +#define pxd_t pud_t
25291 +#define pyd_t pgd_t
25292 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25293 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25294 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25295 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25296 +#define PYD_SIZE PGDIR_SIZE
25297 +#else
25298 +#define pxd_t pmd_t
25299 +#define pyd_t pud_t
25300 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25301 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25302 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25303 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25304 +#define PYD_SIZE PUD_SIZE
25305 +#endif
25306 +
25307 +#ifdef CONFIG_PAX_PER_CPU_PGD
25308 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25309 +static inline void pgd_dtor(pgd_t *pgd) {}
25310 +#else
25311 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25312 {
25313 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25314 @@ -128,6 +178,7 @@ static void pgd_dtor(pgd_t *pgd)
25315 pgd_list_del(pgd);
25316 spin_unlock(&pgd_lock);
25317 }
25318 +#endif
25319
25320 /*
25321 * List of all pgd's needed for non-PAE so it can invalidate entries
25322 @@ -140,7 +191,7 @@ static void pgd_dtor(pgd_t *pgd)
25323 * -- wli
25324 */
25325
25326 -#ifdef CONFIG_X86_PAE
25327 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25328 /*
25329 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25330 * updating the top-level pagetable entries to guarantee the
25331 @@ -152,7 +203,7 @@ static void pgd_dtor(pgd_t *pgd)
25332 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25333 * and initialize the kernel pmds here.
25334 */
25335 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25336 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25337
25338 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25339 {
25340 @@ -170,36 +221,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25341 */
25342 flush_tlb_mm(mm);
25343 }
25344 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25345 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25346 #else /* !CONFIG_X86_PAE */
25347
25348 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25349 -#define PREALLOCATED_PMDS 0
25350 +#define PREALLOCATED_PXDS 0
25351
25352 #endif /* CONFIG_X86_PAE */
25353
25354 -static void free_pmds(pmd_t *pmds[])
25355 +static void free_pxds(pxd_t *pxds[])
25356 {
25357 int i;
25358
25359 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25360 - if (pmds[i])
25361 - free_page((unsigned long)pmds[i]);
25362 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25363 + if (pxds[i])
25364 + free_page((unsigned long)pxds[i]);
25365 }
25366
25367 -static int preallocate_pmds(pmd_t *pmds[])
25368 +static int preallocate_pxds(pxd_t *pxds[])
25369 {
25370 int i;
25371 bool failed = false;
25372
25373 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25374 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25375 - if (pmd == NULL)
25376 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25377 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25378 + if (pxd == NULL)
25379 failed = true;
25380 - pmds[i] = pmd;
25381 + pxds[i] = pxd;
25382 }
25383
25384 if (failed) {
25385 - free_pmds(pmds);
25386 + free_pxds(pxds);
25387 return -ENOMEM;
25388 }
25389
25390 @@ -212,51 +265,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25391 * preallocate which never got a corresponding vma will need to be
25392 * freed manually.
25393 */
25394 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25395 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25396 {
25397 int i;
25398
25399 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25400 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25401 pgd_t pgd = pgdp[i];
25402
25403 if (pgd_val(pgd) != 0) {
25404 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25405 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25406
25407 - pgdp[i] = native_make_pgd(0);
25408 + set_pgd(pgdp + i, native_make_pgd(0));
25409
25410 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25411 - pmd_free(mm, pmd);
25412 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25413 + pxd_free(mm, pxd);
25414 }
25415 }
25416 }
25417
25418 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25419 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25420 {
25421 - pud_t *pud;
25422 + pyd_t *pyd;
25423 unsigned long addr;
25424 int i;
25425
25426 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25427 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25428 return;
25429
25430 - pud = pud_offset(pgd, 0);
25431 +#ifdef CONFIG_X86_64
25432 + pyd = pyd_offset(mm, 0L);
25433 +#else
25434 + pyd = pyd_offset(pgd, 0L);
25435 +#endif
25436
25437 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25438 - i++, pud++, addr += PUD_SIZE) {
25439 - pmd_t *pmd = pmds[i];
25440 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25441 + i++, pyd++, addr += PYD_SIZE) {
25442 + pxd_t *pxd = pxds[i];
25443
25444 if (i >= KERNEL_PGD_BOUNDARY)
25445 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25446 - sizeof(pmd_t) * PTRS_PER_PMD);
25447 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25448 + sizeof(pxd_t) * PTRS_PER_PMD);
25449
25450 - pud_populate(mm, pud, pmd);
25451 + pyd_populate(mm, pyd, pxd);
25452 }
25453 }
25454
25455 pgd_t *pgd_alloc(struct mm_struct *mm)
25456 {
25457 pgd_t *pgd;
25458 - pmd_t *pmds[PREALLOCATED_PMDS];
25459 + pxd_t *pxds[PREALLOCATED_PXDS];
25460
25461 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25462
25463 @@ -265,11 +322,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25464
25465 mm->pgd = pgd;
25466
25467 - if (preallocate_pmds(pmds) != 0)
25468 + if (preallocate_pxds(pxds) != 0)
25469 goto out_free_pgd;
25470
25471 if (paravirt_pgd_alloc(mm) != 0)
25472 - goto out_free_pmds;
25473 + goto out_free_pxds;
25474
25475 /*
25476 * Make sure that pre-populating the pmds is atomic with
25477 @@ -279,14 +336,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25478 spin_lock(&pgd_lock);
25479
25480 pgd_ctor(mm, pgd);
25481 - pgd_prepopulate_pmd(mm, pgd, pmds);
25482 + pgd_prepopulate_pxd(mm, pgd, pxds);
25483
25484 spin_unlock(&pgd_lock);
25485
25486 return pgd;
25487
25488 -out_free_pmds:
25489 - free_pmds(pmds);
25490 +out_free_pxds:
25491 + free_pxds(pxds);
25492 out_free_pgd:
25493 free_page((unsigned long)pgd);
25494 out:
25495 @@ -295,7 +352,7 @@ out:
25496
25497 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25498 {
25499 - pgd_mop_up_pmds(mm, pgd);
25500 + pgd_mop_up_pxds(mm, pgd);
25501 pgd_dtor(pgd);
25502 paravirt_pgd_free(mm, pgd);
25503 free_page((unsigned long)pgd);
25504 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25505 index cac7184..09a39fa 100644
25506 --- a/arch/x86/mm/pgtable_32.c
25507 +++ b/arch/x86/mm/pgtable_32.c
25508 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25509 return;
25510 }
25511 pte = pte_offset_kernel(pmd, vaddr);
25512 +
25513 + pax_open_kernel();
25514 if (pte_val(pteval))
25515 set_pte_at(&init_mm, vaddr, pte, pteval);
25516 else
25517 pte_clear(&init_mm, vaddr, pte);
25518 + pax_close_kernel();
25519
25520 /*
25521 * It's enough to flush this one mapping.
25522 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25523 index 410531d..0f16030 100644
25524 --- a/arch/x86/mm/setup_nx.c
25525 +++ b/arch/x86/mm/setup_nx.c
25526 @@ -5,8 +5,10 @@
25527 #include <asm/pgtable.h>
25528 #include <asm/proto.h>
25529
25530 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25531 static int disable_nx __cpuinitdata;
25532
25533 +#ifndef CONFIG_PAX_PAGEEXEC
25534 /*
25535 * noexec = on|off
25536 *
25537 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25538 return 0;
25539 }
25540 early_param("noexec", noexec_setup);
25541 +#endif
25542 +
25543 +#endif
25544
25545 void __cpuinit x86_configure_nx(void)
25546 {
25547 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25548 if (cpu_has_nx && !disable_nx)
25549 __supported_pte_mask |= _PAGE_NX;
25550 else
25551 +#endif
25552 __supported_pte_mask &= ~_PAGE_NX;
25553 }
25554
25555 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25556 index d6c0418..06a0ad5 100644
25557 --- a/arch/x86/mm/tlb.c
25558 +++ b/arch/x86/mm/tlb.c
25559 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25560 BUG();
25561 cpumask_clear_cpu(cpu,
25562 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25563 +
25564 +#ifndef CONFIG_PAX_PER_CPU_PGD
25565 load_cr3(swapper_pg_dir);
25566 +#endif
25567 +
25568 }
25569 EXPORT_SYMBOL_GPL(leave_mm);
25570
25571 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25572 index 6687022..ceabcfa 100644
25573 --- a/arch/x86/net/bpf_jit.S
25574 +++ b/arch/x86/net/bpf_jit.S
25575 @@ -9,6 +9,7 @@
25576 */
25577 #include <linux/linkage.h>
25578 #include <asm/dwarf2.h>
25579 +#include <asm/alternative-asm.h>
25580
25581 /*
25582 * Calling convention :
25583 @@ -35,6 +36,7 @@ sk_load_word:
25584 jle bpf_slow_path_word
25585 mov (SKBDATA,%rsi),%eax
25586 bswap %eax /* ntohl() */
25587 + pax_force_retaddr
25588 ret
25589
25590
25591 @@ -53,6 +55,7 @@ sk_load_half:
25592 jle bpf_slow_path_half
25593 movzwl (SKBDATA,%rsi),%eax
25594 rol $8,%ax # ntohs()
25595 + pax_force_retaddr
25596 ret
25597
25598 sk_load_byte_ind:
25599 @@ -66,6 +69,7 @@ sk_load_byte:
25600 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25601 jle bpf_slow_path_byte
25602 movzbl (SKBDATA,%rsi),%eax
25603 + pax_force_retaddr
25604 ret
25605
25606 /**
25607 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25608 movzbl (SKBDATA,%rsi),%ebx
25609 and $15,%bl
25610 shl $2,%bl
25611 + pax_force_retaddr
25612 ret
25613 CFI_ENDPROC
25614 ENDPROC(sk_load_byte_msh)
25615 @@ -91,6 +96,7 @@ bpf_error:
25616 xor %eax,%eax
25617 mov -8(%rbp),%rbx
25618 leaveq
25619 + pax_force_retaddr
25620 ret
25621
25622 /* rsi contains offset and can be scratched */
25623 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25624 js bpf_error
25625 mov -12(%rbp),%eax
25626 bswap %eax
25627 + pax_force_retaddr
25628 ret
25629
25630 bpf_slow_path_half:
25631 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25632 mov -12(%rbp),%ax
25633 rol $8,%ax
25634 movzwl %ax,%eax
25635 + pax_force_retaddr
25636 ret
25637
25638 bpf_slow_path_byte:
25639 bpf_slow_path_common(1)
25640 js bpf_error
25641 movzbl -12(%rbp),%eax
25642 + pax_force_retaddr
25643 ret
25644
25645 bpf_slow_path_byte_msh:
25646 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25647 and $15,%al
25648 shl $2,%al
25649 xchg %eax,%ebx
25650 + pax_force_retaddr
25651 ret
25652 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25653 index 5a5b6e4..201d42e 100644
25654 --- a/arch/x86/net/bpf_jit_comp.c
25655 +++ b/arch/x86/net/bpf_jit_comp.c
25656 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25657 set_fs(old_fs);
25658 }
25659
25660 +struct bpf_jit_work {
25661 + struct work_struct work;
25662 + void *image;
25663 +};
25664
25665 void bpf_jit_compile(struct sk_filter *fp)
25666 {
25667 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25668 if (addrs == NULL)
25669 return;
25670
25671 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25672 + if (!fp->work)
25673 + goto out;
25674 +
25675 /* Before first pass, make a rough estimation of addrs[]
25676 * each bpf instruction is translated to less than 64 bytes
25677 */
25678 @@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25679 common_load: seen |= SEEN_DATAREF;
25680 if ((int)K < 0) {
25681 /* Abort the JIT because __load_pointer() is needed. */
25682 - goto out;
25683 + goto error;
25684 }
25685 t_offset = func - (image + addrs[i]);
25686 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25687 @@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
25688 case BPF_S_LDX_B_MSH:
25689 if ((int)K < 0) {
25690 /* Abort the JIT because __load_pointer() is needed. */
25691 - goto out;
25692 + goto error;
25693 }
25694 seen |= SEEN_DATAREF | SEEN_XREG;
25695 t_offset = sk_load_byte_msh - (image + addrs[i]);
25696 @@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25697 break;
25698 default:
25699 /* hmm, too complex filter, give up with jit compiler */
25700 - goto out;
25701 + goto error;
25702 }
25703 ilen = prog - temp;
25704 if (image) {
25705 if (unlikely(proglen + ilen > oldproglen)) {
25706 pr_err("bpb_jit_compile fatal error\n");
25707 - kfree(addrs);
25708 - module_free(NULL, image);
25709 - return;
25710 + module_free_exec(NULL, image);
25711 + goto error;
25712 }
25713 + pax_open_kernel();
25714 memcpy(image + proglen, temp, ilen);
25715 + pax_close_kernel();
25716 }
25717 proglen += ilen;
25718 addrs[i] = proglen;
25719 @@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25720 break;
25721 }
25722 if (proglen == oldproglen) {
25723 - image = module_alloc(max_t(unsigned int,
25724 - proglen,
25725 - sizeof(struct work_struct)));
25726 + image = module_alloc_exec(proglen);
25727 if (!image)
25728 - goto out;
25729 + goto error;
25730 }
25731 oldproglen = proglen;
25732 }
25733 @@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25734 bpf_flush_icache(image, image + proglen);
25735
25736 fp->bpf_func = (void *)image;
25737 - }
25738 + } else
25739 +error:
25740 + kfree(fp->work);
25741 +
25742 out:
25743 kfree(addrs);
25744 return;
25745 @@ -641,18 +651,20 @@ out:
25746
25747 static void jit_free_defer(struct work_struct *arg)
25748 {
25749 - module_free(NULL, arg);
25750 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25751 + kfree(arg);
25752 }
25753
25754 /* run from softirq, we must use a work_struct to call
25755 - * module_free() from process context
25756 + * module_free_exec() from process context
25757 */
25758 void bpf_jit_free(struct sk_filter *fp)
25759 {
25760 if (fp->bpf_func != sk_run_filter) {
25761 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25762 + struct work_struct *work = &fp->work->work;
25763
25764 INIT_WORK(work, jit_free_defer);
25765 + fp->work->image = fp->bpf_func;
25766 schedule_work(work);
25767 }
25768 }
25769 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25770 index bff89df..377758a 100644
25771 --- a/arch/x86/oprofile/backtrace.c
25772 +++ b/arch/x86/oprofile/backtrace.c
25773 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25774 struct stack_frame_ia32 *fp;
25775 unsigned long bytes;
25776
25777 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25778 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25779 if (bytes != sizeof(bufhead))
25780 return NULL;
25781
25782 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25783 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25784
25785 oprofile_add_trace(bufhead[0].return_address);
25786
25787 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25788 struct stack_frame bufhead[2];
25789 unsigned long bytes;
25790
25791 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25792 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25793 if (bytes != sizeof(bufhead))
25794 return NULL;
25795
25796 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25797 {
25798 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25799
25800 - if (!user_mode_vm(regs)) {
25801 + if (!user_mode(regs)) {
25802 unsigned long stack = kernel_stack_pointer(regs);
25803 if (depth)
25804 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25805 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25806 index cb29191..036766d 100644
25807 --- a/arch/x86/pci/mrst.c
25808 +++ b/arch/x86/pci/mrst.c
25809 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25810 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25811 pci_mmcfg_late_init();
25812 pcibios_enable_irq = mrst_pci_irq_enable;
25813 - pci_root_ops = pci_mrst_ops;
25814 + pax_open_kernel();
25815 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25816 + pax_close_kernel();
25817 /* Continue with standard init */
25818 return 1;
25819 }
25820 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25821 index da8fe05..7ee6704 100644
25822 --- a/arch/x86/pci/pcbios.c
25823 +++ b/arch/x86/pci/pcbios.c
25824 @@ -79,50 +79,93 @@ union bios32 {
25825 static struct {
25826 unsigned long address;
25827 unsigned short segment;
25828 -} bios32_indirect = { 0, __KERNEL_CS };
25829 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25830
25831 /*
25832 * Returns the entry point for the given service, NULL on error
25833 */
25834
25835 -static unsigned long bios32_service(unsigned long service)
25836 +static unsigned long __devinit bios32_service(unsigned long service)
25837 {
25838 unsigned char return_code; /* %al */
25839 unsigned long address; /* %ebx */
25840 unsigned long length; /* %ecx */
25841 unsigned long entry; /* %edx */
25842 unsigned long flags;
25843 + struct desc_struct d, *gdt;
25844
25845 local_irq_save(flags);
25846 - __asm__("lcall *(%%edi); cld"
25847 +
25848 + gdt = get_cpu_gdt_table(smp_processor_id());
25849 +
25850 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25851 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25852 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25853 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25854 +
25855 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25856 : "=a" (return_code),
25857 "=b" (address),
25858 "=c" (length),
25859 "=d" (entry)
25860 : "0" (service),
25861 "1" (0),
25862 - "D" (&bios32_indirect));
25863 + "D" (&bios32_indirect),
25864 + "r"(__PCIBIOS_DS)
25865 + : "memory");
25866 +
25867 + pax_open_kernel();
25868 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25869 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25870 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25871 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25872 + pax_close_kernel();
25873 +
25874 local_irq_restore(flags);
25875
25876 switch (return_code) {
25877 - case 0:
25878 - return address + entry;
25879 - case 0x80: /* Not present */
25880 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25881 - return 0;
25882 - default: /* Shouldn't happen */
25883 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25884 - service, return_code);
25885 + case 0: {
25886 + int cpu;
25887 + unsigned char flags;
25888 +
25889 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25890 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25891 + printk(KERN_WARNING "bios32_service: not valid\n");
25892 return 0;
25893 + }
25894 + address = address + PAGE_OFFSET;
25895 + length += 16UL; /* some BIOSs underreport this... */
25896 + flags = 4;
25897 + if (length >= 64*1024*1024) {
25898 + length >>= PAGE_SHIFT;
25899 + flags |= 8;
25900 + }
25901 +
25902 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25903 + gdt = get_cpu_gdt_table(cpu);
25904 + pack_descriptor(&d, address, length, 0x9b, flags);
25905 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25906 + pack_descriptor(&d, address, length, 0x93, flags);
25907 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25908 + }
25909 + return entry;
25910 + }
25911 + case 0x80: /* Not present */
25912 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25913 + return 0;
25914 + default: /* Shouldn't happen */
25915 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25916 + service, return_code);
25917 + return 0;
25918 }
25919 }
25920
25921 static struct {
25922 unsigned long address;
25923 unsigned short segment;
25924 -} pci_indirect = { 0, __KERNEL_CS };
25925 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25926
25927 -static int pci_bios_present;
25928 +static int pci_bios_present __read_only;
25929
25930 static int __devinit check_pcibios(void)
25931 {
25932 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
25933 unsigned long flags, pcibios_entry;
25934
25935 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
25936 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
25937 + pci_indirect.address = pcibios_entry;
25938
25939 local_irq_save(flags);
25940 - __asm__(
25941 - "lcall *(%%edi); cld\n\t"
25942 + __asm__("movw %w6, %%ds\n\t"
25943 + "lcall *%%ss:(%%edi); cld\n\t"
25944 + "push %%ss\n\t"
25945 + "pop %%ds\n\t"
25946 "jc 1f\n\t"
25947 "xor %%ah, %%ah\n"
25948 "1:"
25949 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
25950 "=b" (ebx),
25951 "=c" (ecx)
25952 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
25953 - "D" (&pci_indirect)
25954 + "D" (&pci_indirect),
25955 + "r" (__PCIBIOS_DS)
25956 : "memory");
25957 local_irq_restore(flags);
25958
25959 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25960
25961 switch (len) {
25962 case 1:
25963 - __asm__("lcall *(%%esi); cld\n\t"
25964 + __asm__("movw %w6, %%ds\n\t"
25965 + "lcall *%%ss:(%%esi); cld\n\t"
25966 + "push %%ss\n\t"
25967 + "pop %%ds\n\t"
25968 "jc 1f\n\t"
25969 "xor %%ah, %%ah\n"
25970 "1:"
25971 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25972 : "1" (PCIBIOS_READ_CONFIG_BYTE),
25973 "b" (bx),
25974 "D" ((long)reg),
25975 - "S" (&pci_indirect));
25976 + "S" (&pci_indirect),
25977 + "r" (__PCIBIOS_DS));
25978 /*
25979 * Zero-extend the result beyond 8 bits, do not trust the
25980 * BIOS having done it:
25981 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25982 *value &= 0xff;
25983 break;
25984 case 2:
25985 - __asm__("lcall *(%%esi); cld\n\t"
25986 + __asm__("movw %w6, %%ds\n\t"
25987 + "lcall *%%ss:(%%esi); cld\n\t"
25988 + "push %%ss\n\t"
25989 + "pop %%ds\n\t"
25990 "jc 1f\n\t"
25991 "xor %%ah, %%ah\n"
25992 "1:"
25993 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25994 : "1" (PCIBIOS_READ_CONFIG_WORD),
25995 "b" (bx),
25996 "D" ((long)reg),
25997 - "S" (&pci_indirect));
25998 + "S" (&pci_indirect),
25999 + "r" (__PCIBIOS_DS));
26000 /*
26001 * Zero-extend the result beyond 16 bits, do not trust the
26002 * BIOS having done it:
26003 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26004 *value &= 0xffff;
26005 break;
26006 case 4:
26007 - __asm__("lcall *(%%esi); cld\n\t"
26008 + __asm__("movw %w6, %%ds\n\t"
26009 + "lcall *%%ss:(%%esi); cld\n\t"
26010 + "push %%ss\n\t"
26011 + "pop %%ds\n\t"
26012 "jc 1f\n\t"
26013 "xor %%ah, %%ah\n"
26014 "1:"
26015 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26016 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26017 "b" (bx),
26018 "D" ((long)reg),
26019 - "S" (&pci_indirect));
26020 + "S" (&pci_indirect),
26021 + "r" (__PCIBIOS_DS));
26022 break;
26023 }
26024
26025 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26026
26027 switch (len) {
26028 case 1:
26029 - __asm__("lcall *(%%esi); cld\n\t"
26030 + __asm__("movw %w6, %%ds\n\t"
26031 + "lcall *%%ss:(%%esi); cld\n\t"
26032 + "push %%ss\n\t"
26033 + "pop %%ds\n\t"
26034 "jc 1f\n\t"
26035 "xor %%ah, %%ah\n"
26036 "1:"
26037 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26038 "c" (value),
26039 "b" (bx),
26040 "D" ((long)reg),
26041 - "S" (&pci_indirect));
26042 + "S" (&pci_indirect),
26043 + "r" (__PCIBIOS_DS));
26044 break;
26045 case 2:
26046 - __asm__("lcall *(%%esi); cld\n\t"
26047 + __asm__("movw %w6, %%ds\n\t"
26048 + "lcall *%%ss:(%%esi); cld\n\t"
26049 + "push %%ss\n\t"
26050 + "pop %%ds\n\t"
26051 "jc 1f\n\t"
26052 "xor %%ah, %%ah\n"
26053 "1:"
26054 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26055 "c" (value),
26056 "b" (bx),
26057 "D" ((long)reg),
26058 - "S" (&pci_indirect));
26059 + "S" (&pci_indirect),
26060 + "r" (__PCIBIOS_DS));
26061 break;
26062 case 4:
26063 - __asm__("lcall *(%%esi); cld\n\t"
26064 + __asm__("movw %w6, %%ds\n\t"
26065 + "lcall *%%ss:(%%esi); cld\n\t"
26066 + "push %%ss\n\t"
26067 + "pop %%ds\n\t"
26068 "jc 1f\n\t"
26069 "xor %%ah, %%ah\n"
26070 "1:"
26071 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26072 "c" (value),
26073 "b" (bx),
26074 "D" ((long)reg),
26075 - "S" (&pci_indirect));
26076 + "S" (&pci_indirect),
26077 + "r" (__PCIBIOS_DS));
26078 break;
26079 }
26080
26081 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26082
26083 DBG("PCI: Fetching IRQ routing table... ");
26084 __asm__("push %%es\n\t"
26085 + "movw %w8, %%ds\n\t"
26086 "push %%ds\n\t"
26087 "pop %%es\n\t"
26088 - "lcall *(%%esi); cld\n\t"
26089 + "lcall *%%ss:(%%esi); cld\n\t"
26090 "pop %%es\n\t"
26091 + "push %%ss\n\t"
26092 + "pop %%ds\n"
26093 "jc 1f\n\t"
26094 "xor %%ah, %%ah\n"
26095 "1:"
26096 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26097 "1" (0),
26098 "D" ((long) &opt),
26099 "S" (&pci_indirect),
26100 - "m" (opt)
26101 + "m" (opt),
26102 + "r" (__PCIBIOS_DS)
26103 : "memory");
26104 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26105 if (ret & 0xff00)
26106 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26107 {
26108 int ret;
26109
26110 - __asm__("lcall *(%%esi); cld\n\t"
26111 + __asm__("movw %w5, %%ds\n\t"
26112 + "lcall *%%ss:(%%esi); cld\n\t"
26113 + "push %%ss\n\t"
26114 + "pop %%ds\n"
26115 "jc 1f\n\t"
26116 "xor %%ah, %%ah\n"
26117 "1:"
26118 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26119 : "0" (PCIBIOS_SET_PCI_HW_INT),
26120 "b" ((dev->bus->number << 8) | dev->devfn),
26121 "c" ((irq << 8) | (pin + 10)),
26122 - "S" (&pci_indirect));
26123 + "S" (&pci_indirect),
26124 + "r" (__PCIBIOS_DS));
26125 return !(ret & 0xff00);
26126 }
26127 EXPORT_SYMBOL(pcibios_set_irq_routing);
26128 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26129 index 40e4469..1ab536e 100644
26130 --- a/arch/x86/platform/efi/efi_32.c
26131 +++ b/arch/x86/platform/efi/efi_32.c
26132 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26133 {
26134 struct desc_ptr gdt_descr;
26135
26136 +#ifdef CONFIG_PAX_KERNEXEC
26137 + struct desc_struct d;
26138 +#endif
26139 +
26140 local_irq_save(efi_rt_eflags);
26141
26142 load_cr3(initial_page_table);
26143 __flush_tlb_all();
26144
26145 +#ifdef CONFIG_PAX_KERNEXEC
26146 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26147 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26148 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26149 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26150 +#endif
26151 +
26152 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26153 gdt_descr.size = GDT_SIZE - 1;
26154 load_gdt(&gdt_descr);
26155 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26156 {
26157 struct desc_ptr gdt_descr;
26158
26159 +#ifdef CONFIG_PAX_KERNEXEC
26160 + struct desc_struct d;
26161 +
26162 + memset(&d, 0, sizeof d);
26163 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26164 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26165 +#endif
26166 +
26167 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26168 gdt_descr.size = GDT_SIZE - 1;
26169 load_gdt(&gdt_descr);
26170 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26171 index fbe66e6..c5c0dd2 100644
26172 --- a/arch/x86/platform/efi/efi_stub_32.S
26173 +++ b/arch/x86/platform/efi/efi_stub_32.S
26174 @@ -6,7 +6,9 @@
26175 */
26176
26177 #include <linux/linkage.h>
26178 +#include <linux/init.h>
26179 #include <asm/page_types.h>
26180 +#include <asm/segment.h>
26181
26182 /*
26183 * efi_call_phys(void *, ...) is a function with variable parameters.
26184 @@ -20,7 +22,7 @@
26185 * service functions will comply with gcc calling convention, too.
26186 */
26187
26188 -.text
26189 +__INIT
26190 ENTRY(efi_call_phys)
26191 /*
26192 * 0. The function can only be called in Linux kernel. So CS has been
26193 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26194 * The mapping of lower virtual memory has been created in prelog and
26195 * epilog.
26196 */
26197 - movl $1f, %edx
26198 - subl $__PAGE_OFFSET, %edx
26199 - jmp *%edx
26200 + movl $(__KERNEXEC_EFI_DS), %edx
26201 + mov %edx, %ds
26202 + mov %edx, %es
26203 + mov %edx, %ss
26204 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26205 1:
26206
26207 /*
26208 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26209 * parameter 2, ..., param n. To make things easy, we save the return
26210 * address of efi_call_phys in a global variable.
26211 */
26212 - popl %edx
26213 - movl %edx, saved_return_addr
26214 - /* get the function pointer into ECX*/
26215 - popl %ecx
26216 - movl %ecx, efi_rt_function_ptr
26217 - movl $2f, %edx
26218 - subl $__PAGE_OFFSET, %edx
26219 - pushl %edx
26220 + popl (saved_return_addr)
26221 + popl (efi_rt_function_ptr)
26222
26223 /*
26224 * 3. Clear PG bit in %CR0.
26225 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26226 /*
26227 * 5. Call the physical function.
26228 */
26229 - jmp *%ecx
26230 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26231
26232 -2:
26233 /*
26234 * 6. After EFI runtime service returns, control will return to
26235 * following instruction. We'd better readjust stack pointer first.
26236 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26237 movl %cr0, %edx
26238 orl $0x80000000, %edx
26239 movl %edx, %cr0
26240 - jmp 1f
26241 -1:
26242 +
26243 /*
26244 * 8. Now restore the virtual mode from flat mode by
26245 * adding EIP with PAGE_OFFSET.
26246 */
26247 - movl $1f, %edx
26248 - jmp *%edx
26249 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26250 1:
26251 + movl $(__KERNEL_DS), %edx
26252 + mov %edx, %ds
26253 + mov %edx, %es
26254 + mov %edx, %ss
26255
26256 /*
26257 * 9. Balance the stack. And because EAX contain the return value,
26258 * we'd better not clobber it.
26259 */
26260 - leal efi_rt_function_ptr, %edx
26261 - movl (%edx), %ecx
26262 - pushl %ecx
26263 + pushl (efi_rt_function_ptr)
26264
26265 /*
26266 - * 10. Push the saved return address onto the stack and return.
26267 + * 10. Return to the saved return address.
26268 */
26269 - leal saved_return_addr, %edx
26270 - movl (%edx), %ecx
26271 - pushl %ecx
26272 - ret
26273 + jmpl *(saved_return_addr)
26274 ENDPROC(efi_call_phys)
26275 .previous
26276
26277 -.data
26278 +__INITDATA
26279 saved_return_addr:
26280 .long 0
26281 efi_rt_function_ptr:
26282 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26283 index 4c07cca..2c8427d 100644
26284 --- a/arch/x86/platform/efi/efi_stub_64.S
26285 +++ b/arch/x86/platform/efi/efi_stub_64.S
26286 @@ -7,6 +7,7 @@
26287 */
26288
26289 #include <linux/linkage.h>
26290 +#include <asm/alternative-asm.h>
26291
26292 #define SAVE_XMM \
26293 mov %rsp, %rax; \
26294 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26295 call *%rdi
26296 addq $32, %rsp
26297 RESTORE_XMM
26298 + pax_force_retaddr 0, 1
26299 ret
26300 ENDPROC(efi_call0)
26301
26302 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26303 call *%rdi
26304 addq $32, %rsp
26305 RESTORE_XMM
26306 + pax_force_retaddr 0, 1
26307 ret
26308 ENDPROC(efi_call1)
26309
26310 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26311 call *%rdi
26312 addq $32, %rsp
26313 RESTORE_XMM
26314 + pax_force_retaddr 0, 1
26315 ret
26316 ENDPROC(efi_call2)
26317
26318 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26319 call *%rdi
26320 addq $32, %rsp
26321 RESTORE_XMM
26322 + pax_force_retaddr 0, 1
26323 ret
26324 ENDPROC(efi_call3)
26325
26326 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26327 call *%rdi
26328 addq $32, %rsp
26329 RESTORE_XMM
26330 + pax_force_retaddr 0, 1
26331 ret
26332 ENDPROC(efi_call4)
26333
26334 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26335 call *%rdi
26336 addq $48, %rsp
26337 RESTORE_XMM
26338 + pax_force_retaddr 0, 1
26339 ret
26340 ENDPROC(efi_call5)
26341
26342 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26343 call *%rdi
26344 addq $48, %rsp
26345 RESTORE_XMM
26346 + pax_force_retaddr 0, 1
26347 ret
26348 ENDPROC(efi_call6)
26349 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26350 index 475e2cd..1b8e708 100644
26351 --- a/arch/x86/platform/mrst/mrst.c
26352 +++ b/arch/x86/platform/mrst/mrst.c
26353 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26354 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26355 int sfi_mrtc_num;
26356
26357 -static void mrst_power_off(void)
26358 +static __noreturn void mrst_power_off(void)
26359 {
26360 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26361 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26362 + BUG();
26363 }
26364
26365 -static void mrst_reboot(void)
26366 +static __noreturn void mrst_reboot(void)
26367 {
26368 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26369 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26370 else
26371 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26372 + BUG();
26373 }
26374
26375 /* parse all the mtimer info to a static mtimer array */
26376 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
26377 index 3ae0e61..4202d86 100644
26378 --- a/arch/x86/platform/uv/tlb_uv.c
26379 +++ b/arch/x86/platform/uv/tlb_uv.c
26380 @@ -1424,6 +1424,8 @@ static ssize_t tunables_read(struct file *file, char __user *userbuf,
26381 * 0: display meaning of the statistics
26382 */
26383 static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26384 + size_t count, loff_t *data) __size_overflow(3);
26385 +static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26386 size_t count, loff_t *data)
26387 {
26388 int cpu;
26389 @@ -1539,6 +1541,8 @@ static int parse_tunables_write(struct bau_control *bcp, char *instr,
26390 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
26391 */
26392 static ssize_t tunables_write(struct file *file, const char __user *user,
26393 + size_t count, loff_t *data) __size_overflow(3);
26394 +static ssize_t tunables_write(struct file *file, const char __user *user,
26395 size_t count, loff_t *data)
26396 {
26397 int cpu;
26398 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26399 index f10c0af..3ec1f95 100644
26400 --- a/arch/x86/power/cpu.c
26401 +++ b/arch/x86/power/cpu.c
26402 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
26403 static void fix_processor_context(void)
26404 {
26405 int cpu = smp_processor_id();
26406 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26407 + struct tss_struct *t = init_tss + cpu;
26408
26409 set_tss_desc(cpu, t); /*
26410 * This just modifies memory; should not be
26411 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
26412 */
26413
26414 #ifdef CONFIG_X86_64
26415 + pax_open_kernel();
26416 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26417 + pax_close_kernel();
26418
26419 syscall_init(); /* This sets MSR_*STAR and related */
26420 #endif
26421 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26422 index 5d17950..2253fc9 100644
26423 --- a/arch/x86/vdso/Makefile
26424 +++ b/arch/x86/vdso/Makefile
26425 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26426 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26427 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26428
26429 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26430 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26431 GCOV_PROFILE := n
26432
26433 #
26434 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26435 index 468d591..8e80a0a 100644
26436 --- a/arch/x86/vdso/vdso32-setup.c
26437 +++ b/arch/x86/vdso/vdso32-setup.c
26438 @@ -25,6 +25,7 @@
26439 #include <asm/tlbflush.h>
26440 #include <asm/vdso.h>
26441 #include <asm/proto.h>
26442 +#include <asm/mman.h>
26443
26444 enum {
26445 VDSO_DISABLED = 0,
26446 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26447 void enable_sep_cpu(void)
26448 {
26449 int cpu = get_cpu();
26450 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26451 + struct tss_struct *tss = init_tss + cpu;
26452
26453 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26454 put_cpu();
26455 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26456 gate_vma.vm_start = FIXADDR_USER_START;
26457 gate_vma.vm_end = FIXADDR_USER_END;
26458 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26459 - gate_vma.vm_page_prot = __P101;
26460 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26461 /*
26462 * Make sure the vDSO gets into every core dump.
26463 * Dumping its contents makes post-mortem fully interpretable later
26464 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26465 if (compat)
26466 addr = VDSO_HIGH_BASE;
26467 else {
26468 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26469 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26470 if (IS_ERR_VALUE(addr)) {
26471 ret = addr;
26472 goto up_fail;
26473 }
26474 }
26475
26476 - current->mm->context.vdso = (void *)addr;
26477 + current->mm->context.vdso = addr;
26478
26479 if (compat_uses_vma || !compat) {
26480 /*
26481 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26482 }
26483
26484 current_thread_info()->sysenter_return =
26485 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26486 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26487
26488 up_fail:
26489 if (ret)
26490 - current->mm->context.vdso = NULL;
26491 + current->mm->context.vdso = 0;
26492
26493 up_write(&mm->mmap_sem);
26494
26495 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26496
26497 const char *arch_vma_name(struct vm_area_struct *vma)
26498 {
26499 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26500 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26501 return "[vdso]";
26502 +
26503 +#ifdef CONFIG_PAX_SEGMEXEC
26504 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26505 + return "[vdso]";
26506 +#endif
26507 +
26508 return NULL;
26509 }
26510
26511 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26512 * Check to see if the corresponding task was created in compat vdso
26513 * mode.
26514 */
26515 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26516 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26517 return &gate_vma;
26518 return NULL;
26519 }
26520 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26521 index 153407c..611cba9 100644
26522 --- a/arch/x86/vdso/vma.c
26523 +++ b/arch/x86/vdso/vma.c
26524 @@ -16,8 +16,6 @@
26525 #include <asm/vdso.h>
26526 #include <asm/page.h>
26527
26528 -unsigned int __read_mostly vdso_enabled = 1;
26529 -
26530 extern char vdso_start[], vdso_end[];
26531 extern unsigned short vdso_sync_cpuid;
26532
26533 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26534 * unaligned here as a result of stack start randomization.
26535 */
26536 addr = PAGE_ALIGN(addr);
26537 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26538
26539 return addr;
26540 }
26541 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26542 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26543 {
26544 struct mm_struct *mm = current->mm;
26545 - unsigned long addr;
26546 + unsigned long addr = 0;
26547 int ret;
26548
26549 - if (!vdso_enabled)
26550 - return 0;
26551 -
26552 down_write(&mm->mmap_sem);
26553 +
26554 +#ifdef CONFIG_PAX_RANDMMAP
26555 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26556 +#endif
26557 +
26558 addr = vdso_addr(mm->start_stack, vdso_size);
26559 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26560 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26561 if (IS_ERR_VALUE(addr)) {
26562 ret = addr;
26563 goto up_fail;
26564 }
26565
26566 - current->mm->context.vdso = (void *)addr;
26567 + mm->context.vdso = addr;
26568
26569 ret = install_special_mapping(mm, addr, vdso_size,
26570 VM_READ|VM_EXEC|
26571 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26572 VM_ALWAYSDUMP,
26573 vdso_pages);
26574 - if (ret) {
26575 - current->mm->context.vdso = NULL;
26576 - goto up_fail;
26577 - }
26578 +
26579 + if (ret)
26580 + mm->context.vdso = 0;
26581
26582 up_fail:
26583 up_write(&mm->mmap_sem);
26584 return ret;
26585 }
26586 -
26587 -static __init int vdso_setup(char *s)
26588 -{
26589 - vdso_enabled = simple_strtoul(s, NULL, 0);
26590 - return 0;
26591 -}
26592 -__setup("vdso=", vdso_setup);
26593 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26594 index 4172af8..2c8ed7f 100644
26595 --- a/arch/x86/xen/enlighten.c
26596 +++ b/arch/x86/xen/enlighten.c
26597 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26598
26599 struct shared_info xen_dummy_shared_info;
26600
26601 -void *xen_initial_gdt;
26602 -
26603 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26604 __read_mostly int xen_have_vector_callback;
26605 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26606 @@ -1029,30 +1027,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26607 #endif
26608 };
26609
26610 -static void xen_reboot(int reason)
26611 +static __noreturn void xen_reboot(int reason)
26612 {
26613 struct sched_shutdown r = { .reason = reason };
26614
26615 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
26616 - BUG();
26617 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
26618 + BUG();
26619 }
26620
26621 -static void xen_restart(char *msg)
26622 +static __noreturn void xen_restart(char *msg)
26623 {
26624 xen_reboot(SHUTDOWN_reboot);
26625 }
26626
26627 -static void xen_emergency_restart(void)
26628 +static __noreturn void xen_emergency_restart(void)
26629 {
26630 xen_reboot(SHUTDOWN_reboot);
26631 }
26632
26633 -static void xen_machine_halt(void)
26634 +static __noreturn void xen_machine_halt(void)
26635 {
26636 xen_reboot(SHUTDOWN_poweroff);
26637 }
26638
26639 -static void xen_machine_power_off(void)
26640 +static __noreturn void xen_machine_power_off(void)
26641 {
26642 if (pm_power_off)
26643 pm_power_off();
26644 @@ -1155,7 +1153,17 @@ asmlinkage void __init xen_start_kernel(void)
26645 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26646
26647 /* Work out if we support NX */
26648 - x86_configure_nx();
26649 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26650 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26651 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26652 + unsigned l, h;
26653 +
26654 + __supported_pte_mask |= _PAGE_NX;
26655 + rdmsr(MSR_EFER, l, h);
26656 + l |= EFER_NX;
26657 + wrmsr(MSR_EFER, l, h);
26658 + }
26659 +#endif
26660
26661 xen_setup_features();
26662
26663 @@ -1186,13 +1194,6 @@ asmlinkage void __init xen_start_kernel(void)
26664
26665 machine_ops = xen_machine_ops;
26666
26667 - /*
26668 - * The only reliable way to retain the initial address of the
26669 - * percpu gdt_page is to remember it here, so we can go and
26670 - * mark it RW later, when the initial percpu area is freed.
26671 - */
26672 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26673 -
26674 xen_smp_init();
26675
26676 #ifdef CONFIG_ACPI_NUMA
26677 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26678 index 95c1cf6..4bfa5be 100644
26679 --- a/arch/x86/xen/mmu.c
26680 +++ b/arch/x86/xen/mmu.c
26681 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26682 convert_pfn_mfn(init_level4_pgt);
26683 convert_pfn_mfn(level3_ident_pgt);
26684 convert_pfn_mfn(level3_kernel_pgt);
26685 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26686 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26687 + convert_pfn_mfn(level3_vmemmap_pgt);
26688
26689 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26690 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26691 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26692 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26693 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26694 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26695 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26696 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26697 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26698 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26699 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26700 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26701 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26702
26703 @@ -1958,6 +1965,7 @@ static void __init xen_post_allocator_init(void)
26704 pv_mmu_ops.set_pud = xen_set_pud;
26705 #if PAGETABLE_LEVELS == 4
26706 pv_mmu_ops.set_pgd = xen_set_pgd;
26707 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26708 #endif
26709
26710 /* This will work as long as patching hasn't happened yet
26711 @@ -2039,6 +2047,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26712 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26713 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26714 .set_pgd = xen_set_pgd_hyper,
26715 + .set_pgd_batched = xen_set_pgd_hyper,
26716
26717 .alloc_pud = xen_alloc_pmd_init,
26718 .release_pud = xen_release_pmd_init,
26719 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26720 index 501d4e0..e877605 100644
26721 --- a/arch/x86/xen/smp.c
26722 +++ b/arch/x86/xen/smp.c
26723 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26724 {
26725 BUG_ON(smp_processor_id() != 0);
26726 native_smp_prepare_boot_cpu();
26727 -
26728 - /* We've switched to the "real" per-cpu gdt, so make sure the
26729 - old memory can be recycled */
26730 - make_lowmem_page_readwrite(xen_initial_gdt);
26731 -
26732 xen_filter_cpu_maps();
26733 xen_setup_vcpu_info_placement();
26734 }
26735 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26736 gdt = get_cpu_gdt_table(cpu);
26737
26738 ctxt->flags = VGCF_IN_KERNEL;
26739 - ctxt->user_regs.ds = __USER_DS;
26740 - ctxt->user_regs.es = __USER_DS;
26741 + ctxt->user_regs.ds = __KERNEL_DS;
26742 + ctxt->user_regs.es = __KERNEL_DS;
26743 ctxt->user_regs.ss = __KERNEL_DS;
26744 #ifdef CONFIG_X86_32
26745 ctxt->user_regs.fs = __KERNEL_PERCPU;
26746 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26747 + savesegment(gs, ctxt->user_regs.gs);
26748 #else
26749 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26750 #endif
26751 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26752 int rc;
26753
26754 per_cpu(current_task, cpu) = idle;
26755 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26756 #ifdef CONFIG_X86_32
26757 irq_ctx_init(cpu);
26758 #else
26759 clear_tsk_thread_flag(idle, TIF_FORK);
26760 - per_cpu(kernel_stack, cpu) =
26761 - (unsigned long)task_stack_page(idle) -
26762 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26763 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26764 #endif
26765 xen_setup_runstate_info(cpu);
26766 xen_setup_timer(cpu);
26767 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26768 index b040b0e..8cc4fe0 100644
26769 --- a/arch/x86/xen/xen-asm_32.S
26770 +++ b/arch/x86/xen/xen-asm_32.S
26771 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26772 ESP_OFFSET=4 # bytes pushed onto stack
26773
26774 /*
26775 - * Store vcpu_info pointer for easy access. Do it this way to
26776 - * avoid having to reload %fs
26777 + * Store vcpu_info pointer for easy access.
26778 */
26779 #ifdef CONFIG_SMP
26780 - GET_THREAD_INFO(%eax)
26781 - movl TI_cpu(%eax), %eax
26782 - movl __per_cpu_offset(,%eax,4), %eax
26783 - mov xen_vcpu(%eax), %eax
26784 + push %fs
26785 + mov $(__KERNEL_PERCPU), %eax
26786 + mov %eax, %fs
26787 + mov PER_CPU_VAR(xen_vcpu), %eax
26788 + pop %fs
26789 #else
26790 movl xen_vcpu, %eax
26791 #endif
26792 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26793 index aaa7291..3f77960 100644
26794 --- a/arch/x86/xen/xen-head.S
26795 +++ b/arch/x86/xen/xen-head.S
26796 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
26797 #ifdef CONFIG_X86_32
26798 mov %esi,xen_start_info
26799 mov $init_thread_union+THREAD_SIZE,%esp
26800 +#ifdef CONFIG_SMP
26801 + movl $cpu_gdt_table,%edi
26802 + movl $__per_cpu_load,%eax
26803 + movw %ax,__KERNEL_PERCPU + 2(%edi)
26804 + rorl $16,%eax
26805 + movb %al,__KERNEL_PERCPU + 4(%edi)
26806 + movb %ah,__KERNEL_PERCPU + 7(%edi)
26807 + movl $__per_cpu_end - 1,%eax
26808 + subl $__per_cpu_start,%eax
26809 + movw %ax,__KERNEL_PERCPU + 0(%edi)
26810 +#endif
26811 #else
26812 mov %rsi,xen_start_info
26813 mov $init_thread_union+THREAD_SIZE,%rsp
26814 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26815 index b095739..8c17bcd 100644
26816 --- a/arch/x86/xen/xen-ops.h
26817 +++ b/arch/x86/xen/xen-ops.h
26818 @@ -10,8 +10,6 @@
26819 extern const char xen_hypervisor_callback[];
26820 extern const char xen_failsafe_callback[];
26821
26822 -extern void *xen_initial_gdt;
26823 -
26824 struct trap_info;
26825 void xen_copy_trap_info(struct trap_info *traps);
26826
26827 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26828 index 525bd3d..ef888b1 100644
26829 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
26830 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26831 @@ -119,9 +119,9 @@
26832 ----------------------------------------------------------------------*/
26833
26834 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26835 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26836 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26837 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26838 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26839
26840 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26841 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26842 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26843 index 2f33760..835e50a 100644
26844 --- a/arch/xtensa/variants/fsf/include/variant/core.h
26845 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
26846 @@ -11,6 +11,7 @@
26847 #ifndef _XTENSA_CORE_H
26848 #define _XTENSA_CORE_H
26849
26850 +#include <linux/const.h>
26851
26852 /****************************************************************************
26853 Parameters Useful for Any Code, USER or PRIVILEGED
26854 @@ -112,9 +113,9 @@
26855 ----------------------------------------------------------------------*/
26856
26857 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26858 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26859 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26860 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26861 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26862
26863 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26864 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26865 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26866 index af00795..2bb8105 100644
26867 --- a/arch/xtensa/variants/s6000/include/variant/core.h
26868 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
26869 @@ -11,6 +11,7 @@
26870 #ifndef _XTENSA_CORE_CONFIGURATION_H
26871 #define _XTENSA_CORE_CONFIGURATION_H
26872
26873 +#include <linux/const.h>
26874
26875 /****************************************************************************
26876 Parameters Useful for Any Code, USER or PRIVILEGED
26877 @@ -118,9 +119,9 @@
26878 ----------------------------------------------------------------------*/
26879
26880 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26881 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26882 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26883 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26884 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26885
26886 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26887 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26888 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26889 index 58916af..9cb880b 100644
26890 --- a/block/blk-iopoll.c
26891 +++ b/block/blk-iopoll.c
26892 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26893 }
26894 EXPORT_SYMBOL(blk_iopoll_complete);
26895
26896 -static void blk_iopoll_softirq(struct softirq_action *h)
26897 +static void blk_iopoll_softirq(void)
26898 {
26899 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26900 int rearm = 0, budget = blk_iopoll_budget;
26901 diff --git a/block/blk-map.c b/block/blk-map.c
26902 index 623e1cd..ca1e109 100644
26903 --- a/block/blk-map.c
26904 +++ b/block/blk-map.c
26905 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26906 if (!len || !kbuf)
26907 return -EINVAL;
26908
26909 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26910 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26911 if (do_copy)
26912 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26913 else
26914 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26915 index 1366a89..e17f54b 100644
26916 --- a/block/blk-softirq.c
26917 +++ b/block/blk-softirq.c
26918 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26919 * Softirq action handler - move entries to local list and loop over them
26920 * while passing them to the queue registered handler.
26921 */
26922 -static void blk_done_softirq(struct softirq_action *h)
26923 +static void blk_done_softirq(void)
26924 {
26925 struct list_head *cpu_list, local_list;
26926
26927 diff --git a/block/bsg.c b/block/bsg.c
26928 index ff64ae3..593560c 100644
26929 --- a/block/bsg.c
26930 +++ b/block/bsg.c
26931 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26932 struct sg_io_v4 *hdr, struct bsg_device *bd,
26933 fmode_t has_write_perm)
26934 {
26935 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26936 + unsigned char *cmdptr;
26937 +
26938 if (hdr->request_len > BLK_MAX_CDB) {
26939 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
26940 if (!rq->cmd)
26941 return -ENOMEM;
26942 - }
26943 + cmdptr = rq->cmd;
26944 + } else
26945 + cmdptr = tmpcmd;
26946
26947 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
26948 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
26949 hdr->request_len))
26950 return -EFAULT;
26951
26952 + if (cmdptr != rq->cmd)
26953 + memcpy(rq->cmd, cmdptr, hdr->request_len);
26954 +
26955 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
26956 if (blk_verify_command(rq->cmd, has_write_perm))
26957 return -EPERM;
26958 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
26959 index 7c668c8..db3521c 100644
26960 --- a/block/compat_ioctl.c
26961 +++ b/block/compat_ioctl.c
26962 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
26963 err |= __get_user(f->spec1, &uf->spec1);
26964 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
26965 err |= __get_user(name, &uf->name);
26966 - f->name = compat_ptr(name);
26967 + f->name = (void __force_kernel *)compat_ptr(name);
26968 if (err) {
26969 err = -EFAULT;
26970 goto out;
26971 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
26972 index 6296b40..417c00f 100644
26973 --- a/block/partitions/efi.c
26974 +++ b/block/partitions/efi.c
26975 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
26976 if (!gpt)
26977 return NULL;
26978
26979 + if (!le32_to_cpu(gpt->num_partition_entries))
26980 + return NULL;
26981 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
26982 + if (!pte)
26983 + return NULL;
26984 +
26985 count = le32_to_cpu(gpt->num_partition_entries) *
26986 le32_to_cpu(gpt->sizeof_partition_entry);
26987 - if (!count)
26988 - return NULL;
26989 - pte = kzalloc(count, GFP_KERNEL);
26990 - if (!pte)
26991 - return NULL;
26992 -
26993 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
26994 (u8 *) pte,
26995 count) < count) {
26996 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
26997 index 260fa80..e8f3caf 100644
26998 --- a/block/scsi_ioctl.c
26999 +++ b/block/scsi_ioctl.c
27000 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27001 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27002 struct sg_io_hdr *hdr, fmode_t mode)
27003 {
27004 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27005 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27006 + unsigned char *cmdptr;
27007 +
27008 + if (rq->cmd != rq->__cmd)
27009 + cmdptr = rq->cmd;
27010 + else
27011 + cmdptr = tmpcmd;
27012 +
27013 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27014 return -EFAULT;
27015 +
27016 + if (cmdptr != rq->cmd)
27017 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27018 +
27019 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27020 return -EPERM;
27021
27022 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27023 int err;
27024 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27025 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27026 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27027 + unsigned char *cmdptr;
27028
27029 if (!sic)
27030 return -EINVAL;
27031 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27032 */
27033 err = -EFAULT;
27034 rq->cmd_len = cmdlen;
27035 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27036 +
27037 + if (rq->cmd != rq->__cmd)
27038 + cmdptr = rq->cmd;
27039 + else
27040 + cmdptr = tmpcmd;
27041 +
27042 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27043 goto error;
27044
27045 + if (rq->cmd != cmdptr)
27046 + memcpy(rq->cmd, cmdptr, cmdlen);
27047 +
27048 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27049 goto error;
27050
27051 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
27052 index a0f768c..1da9c73 100644
27053 --- a/crypto/ablkcipher.c
27054 +++ b/crypto/ablkcipher.c
27055 @@ -307,6 +307,8 @@ int ablkcipher_walk_phys(struct ablkcipher_request *req,
27056 EXPORT_SYMBOL_GPL(ablkcipher_walk_phys);
27057
27058 static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27059 + unsigned int keylen) __size_overflow(3);
27060 +static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27061 unsigned int keylen)
27062 {
27063 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27064 @@ -329,6 +331,8 @@ static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27065 }
27066
27067 static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27068 + unsigned int keylen) __size_overflow(3);
27069 +static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27070 unsigned int keylen)
27071 {
27072 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27073 diff --git a/crypto/aead.c b/crypto/aead.c
27074 index 04add3dc..983032f 100644
27075 --- a/crypto/aead.c
27076 +++ b/crypto/aead.c
27077 @@ -27,6 +27,8 @@
27078 #include "internal.h"
27079
27080 static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27081 + unsigned int keylen) __size_overflow(3);
27082 +static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27083 unsigned int keylen)
27084 {
27085 struct aead_alg *aead = crypto_aead_alg(tfm);
27086 @@ -48,6 +50,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27087 return ret;
27088 }
27089
27090 +static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27091 static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
27092 {
27093 struct aead_alg *aead = crypto_aead_alg(tfm);
27094 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
27095 index 1e61d1a..cf06b86 100644
27096 --- a/crypto/blkcipher.c
27097 +++ b/crypto/blkcipher.c
27098 @@ -359,6 +359,8 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc,
27099 EXPORT_SYMBOL_GPL(blkcipher_walk_virt_block);
27100
27101 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27102 + unsigned int keylen) __size_overflow(3);
27103 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27104 unsigned int keylen)
27105 {
27106 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27107 @@ -380,6 +382,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27108 return ret;
27109 }
27110
27111 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27112 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27113 {
27114 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27115 diff --git a/crypto/cipher.c b/crypto/cipher.c
27116 index 39541e0..802d956 100644
27117 --- a/crypto/cipher.c
27118 +++ b/crypto/cipher.c
27119 @@ -21,6 +21,8 @@
27120 #include "internal.h"
27121
27122 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27123 + unsigned int keylen) __size_overflow(3);
27124 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27125 unsigned int keylen)
27126 {
27127 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27128 @@ -43,6 +45,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27129
27130 }
27131
27132 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27133 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27134 {
27135 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27136 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27137 index 671d4d6..5f24030 100644
27138 --- a/crypto/cryptd.c
27139 +++ b/crypto/cryptd.c
27140 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27141
27142 struct cryptd_blkcipher_request_ctx {
27143 crypto_completion_t complete;
27144 -};
27145 +} __no_const;
27146
27147 struct cryptd_hash_ctx {
27148 struct crypto_shash *child;
27149 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27150
27151 struct cryptd_aead_request_ctx {
27152 crypto_completion_t complete;
27153 -};
27154 +} __no_const;
27155
27156 static void cryptd_queue_worker(struct work_struct *work);
27157
27158 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27159 index 5d41894..22021e4 100644
27160 --- a/drivers/acpi/apei/cper.c
27161 +++ b/drivers/acpi/apei/cper.c
27162 @@ -38,12 +38,12 @@
27163 */
27164 u64 cper_next_record_id(void)
27165 {
27166 - static atomic64_t seq;
27167 + static atomic64_unchecked_t seq;
27168
27169 - if (!atomic64_read(&seq))
27170 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27171 + if (!atomic64_read_unchecked(&seq))
27172 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27173
27174 - return atomic64_inc_return(&seq);
27175 + return atomic64_inc_return_unchecked(&seq);
27176 }
27177 EXPORT_SYMBOL_GPL(cper_next_record_id);
27178
27179 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27180 index 86933ca..5cb1a69 100644
27181 --- a/drivers/acpi/battery.c
27182 +++ b/drivers/acpi/battery.c
27183 @@ -787,6 +787,9 @@ static int acpi_battery_print_alarm(struct seq_file *seq, int result)
27184
27185 static ssize_t acpi_battery_write_alarm(struct file *file,
27186 const char __user * buffer,
27187 + size_t count, loff_t * ppos) __size_overflow(3);
27188 +static ssize_t acpi_battery_write_alarm(struct file *file,
27189 + const char __user * buffer,
27190 size_t count, loff_t * ppos)
27191 {
27192 int result = 0;
27193 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27194 index b258cab..3fb7da7 100644
27195 --- a/drivers/acpi/ec_sys.c
27196 +++ b/drivers/acpi/ec_sys.c
27197 @@ -12,6 +12,7 @@
27198 #include <linux/acpi.h>
27199 #include <linux/debugfs.h>
27200 #include <linux/module.h>
27201 +#include <linux/uaccess.h>
27202 #include "internal.h"
27203
27204 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27205 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27206 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27207 */
27208 unsigned int size = EC_SPACE_SIZE;
27209 - u8 *data = (u8 *) buf;
27210 + u8 data;
27211 loff_t init_off = *off;
27212 int err = 0;
27213
27214 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27215 size = count;
27216
27217 while (size) {
27218 - err = ec_read(*off, &data[*off - init_off]);
27219 + err = ec_read(*off, &data);
27220 if (err)
27221 return err;
27222 + if (put_user(data, &buf[*off - init_off]))
27223 + return -EFAULT;
27224 *off += 1;
27225 size--;
27226 }
27227 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27228
27229 unsigned int size = count;
27230 loff_t init_off = *off;
27231 - u8 *data = (u8 *) buf;
27232 int err = 0;
27233
27234 if (*off >= EC_SPACE_SIZE)
27235 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27236 }
27237
27238 while (size) {
27239 - u8 byte_write = data[*off - init_off];
27240 + u8 byte_write;
27241 + if (get_user(byte_write, &buf[*off - init_off]))
27242 + return -EFAULT;
27243 err = ec_write(*off, byte_write);
27244 if (err)
27245 return err;
27246 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27247 index 251c7b62..000462d 100644
27248 --- a/drivers/acpi/proc.c
27249 +++ b/drivers/acpi/proc.c
27250 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27251 size_t count, loff_t * ppos)
27252 {
27253 struct list_head *node, *next;
27254 - char strbuf[5];
27255 - char str[5] = "";
27256 - unsigned int len = count;
27257 + char strbuf[5] = {0};
27258
27259 - if (len > 4)
27260 - len = 4;
27261 - if (len < 0)
27262 + if (count > 4)
27263 + count = 4;
27264 + if (copy_from_user(strbuf, buffer, count))
27265 return -EFAULT;
27266 -
27267 - if (copy_from_user(strbuf, buffer, len))
27268 - return -EFAULT;
27269 - strbuf[len] = '\0';
27270 - sscanf(strbuf, "%s", str);
27271 + strbuf[count] = '\0';
27272
27273 mutex_lock(&acpi_device_lock);
27274 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27275 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27276 if (!dev->wakeup.flags.valid)
27277 continue;
27278
27279 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27280 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27281 if (device_can_wakeup(&dev->dev)) {
27282 bool enable = !device_may_wakeup(&dev->dev);
27283 device_set_wakeup_enable(&dev->dev, enable);
27284 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27285 index 8ae05ce..7dbbed9 100644
27286 --- a/drivers/acpi/processor_driver.c
27287 +++ b/drivers/acpi/processor_driver.c
27288 @@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27289 return 0;
27290 #endif
27291
27292 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27293 + BUG_ON(pr->id >= nr_cpu_ids);
27294
27295 /*
27296 * Buggy BIOS check
27297 diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
27298 index 6e36d0c..f319944 100644
27299 --- a/drivers/acpi/sbs.c
27300 +++ b/drivers/acpi/sbs.c
27301 @@ -655,6 +655,9 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
27302
27303 static ssize_t
27304 acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27305 + size_t count, loff_t * ppos) __size_overflow(3);
27306 +static ssize_t
27307 +acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27308 size_t count, loff_t * ppos)
27309 {
27310 struct seq_file *seq = file->private_data;
27311 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27312 index c06e0ec..a2c06ba 100644
27313 --- a/drivers/ata/libata-core.c
27314 +++ b/drivers/ata/libata-core.c
27315 @@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27316 struct ata_port *ap;
27317 unsigned int tag;
27318
27319 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27320 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27321 ap = qc->ap;
27322
27323 qc->flags = 0;
27324 @@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27325 struct ata_port *ap;
27326 struct ata_link *link;
27327
27328 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27329 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27330 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27331 ap = qc->ap;
27332 link = qc->dev->link;
27333 @@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27334 return;
27335
27336 spin_lock(&lock);
27337 + pax_open_kernel();
27338
27339 for (cur = ops->inherits; cur; cur = cur->inherits) {
27340 void **inherit = (void **)cur;
27341 @@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27342 if (IS_ERR(*pp))
27343 *pp = NULL;
27344
27345 - ops->inherits = NULL;
27346 + *(struct ata_port_operations **)&ops->inherits = NULL;
27347
27348 + pax_close_kernel();
27349 spin_unlock(&lock);
27350 }
27351
27352 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27353 index 048589f..4002b98 100644
27354 --- a/drivers/ata/pata_arasan_cf.c
27355 +++ b/drivers/ata/pata_arasan_cf.c
27356 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27357 /* Handle platform specific quirks */
27358 if (pdata->quirk) {
27359 if (pdata->quirk & CF_BROKEN_PIO) {
27360 - ap->ops->set_piomode = NULL;
27361 + pax_open_kernel();
27362 + *(void **)&ap->ops->set_piomode = NULL;
27363 + pax_close_kernel();
27364 ap->pio_mask = 0;
27365 }
27366 if (pdata->quirk & CF_BROKEN_MWDMA)
27367 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27368 index f9b983a..887b9d8 100644
27369 --- a/drivers/atm/adummy.c
27370 +++ b/drivers/atm/adummy.c
27371 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27372 vcc->pop(vcc, skb);
27373 else
27374 dev_kfree_skb_any(skb);
27375 - atomic_inc(&vcc->stats->tx);
27376 + atomic_inc_unchecked(&vcc->stats->tx);
27377
27378 return 0;
27379 }
27380 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27381 index f8f41e0..1f987dd 100644
27382 --- a/drivers/atm/ambassador.c
27383 +++ b/drivers/atm/ambassador.c
27384 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27385 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27386
27387 // VC layer stats
27388 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27389 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27390
27391 // free the descriptor
27392 kfree (tx_descr);
27393 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27394 dump_skb ("<<<", vc, skb);
27395
27396 // VC layer stats
27397 - atomic_inc(&atm_vcc->stats->rx);
27398 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27399 __net_timestamp(skb);
27400 // end of our responsibility
27401 atm_vcc->push (atm_vcc, skb);
27402 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27403 } else {
27404 PRINTK (KERN_INFO, "dropped over-size frame");
27405 // should we count this?
27406 - atomic_inc(&atm_vcc->stats->rx_drop);
27407 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27408 }
27409
27410 } else {
27411 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27412 }
27413
27414 if (check_area (skb->data, skb->len)) {
27415 - atomic_inc(&atm_vcc->stats->tx_err);
27416 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27417 return -ENOMEM; // ?
27418 }
27419
27420 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27421 index b22d71c..d6e1049 100644
27422 --- a/drivers/atm/atmtcp.c
27423 +++ b/drivers/atm/atmtcp.c
27424 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27425 if (vcc->pop) vcc->pop(vcc,skb);
27426 else dev_kfree_skb(skb);
27427 if (dev_data) return 0;
27428 - atomic_inc(&vcc->stats->tx_err);
27429 + atomic_inc_unchecked(&vcc->stats->tx_err);
27430 return -ENOLINK;
27431 }
27432 size = skb->len+sizeof(struct atmtcp_hdr);
27433 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27434 if (!new_skb) {
27435 if (vcc->pop) vcc->pop(vcc,skb);
27436 else dev_kfree_skb(skb);
27437 - atomic_inc(&vcc->stats->tx_err);
27438 + atomic_inc_unchecked(&vcc->stats->tx_err);
27439 return -ENOBUFS;
27440 }
27441 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27442 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27443 if (vcc->pop) vcc->pop(vcc,skb);
27444 else dev_kfree_skb(skb);
27445 out_vcc->push(out_vcc,new_skb);
27446 - atomic_inc(&vcc->stats->tx);
27447 - atomic_inc(&out_vcc->stats->rx);
27448 + atomic_inc_unchecked(&vcc->stats->tx);
27449 + atomic_inc_unchecked(&out_vcc->stats->rx);
27450 return 0;
27451 }
27452
27453 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27454 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27455 read_unlock(&vcc_sklist_lock);
27456 if (!out_vcc) {
27457 - atomic_inc(&vcc->stats->tx_err);
27458 + atomic_inc_unchecked(&vcc->stats->tx_err);
27459 goto done;
27460 }
27461 skb_pull(skb,sizeof(struct atmtcp_hdr));
27462 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27463 __net_timestamp(new_skb);
27464 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27465 out_vcc->push(out_vcc,new_skb);
27466 - atomic_inc(&vcc->stats->tx);
27467 - atomic_inc(&out_vcc->stats->rx);
27468 + atomic_inc_unchecked(&vcc->stats->tx);
27469 + atomic_inc_unchecked(&out_vcc->stats->rx);
27470 done:
27471 if (vcc->pop) vcc->pop(vcc,skb);
27472 else dev_kfree_skb(skb);
27473 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27474 index 956e9ac..133516d 100644
27475 --- a/drivers/atm/eni.c
27476 +++ b/drivers/atm/eni.c
27477 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27478 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27479 vcc->dev->number);
27480 length = 0;
27481 - atomic_inc(&vcc->stats->rx_err);
27482 + atomic_inc_unchecked(&vcc->stats->rx_err);
27483 }
27484 else {
27485 length = ATM_CELL_SIZE-1; /* no HEC */
27486 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27487 size);
27488 }
27489 eff = length = 0;
27490 - atomic_inc(&vcc->stats->rx_err);
27491 + atomic_inc_unchecked(&vcc->stats->rx_err);
27492 }
27493 else {
27494 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27495 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27496 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27497 vcc->dev->number,vcc->vci,length,size << 2,descr);
27498 length = eff = 0;
27499 - atomic_inc(&vcc->stats->rx_err);
27500 + atomic_inc_unchecked(&vcc->stats->rx_err);
27501 }
27502 }
27503 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27504 @@ -771,7 +771,7 @@ rx_dequeued++;
27505 vcc->push(vcc,skb);
27506 pushed++;
27507 }
27508 - atomic_inc(&vcc->stats->rx);
27509 + atomic_inc_unchecked(&vcc->stats->rx);
27510 }
27511 wake_up(&eni_dev->rx_wait);
27512 }
27513 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27514 PCI_DMA_TODEVICE);
27515 if (vcc->pop) vcc->pop(vcc,skb);
27516 else dev_kfree_skb_irq(skb);
27517 - atomic_inc(&vcc->stats->tx);
27518 + atomic_inc_unchecked(&vcc->stats->tx);
27519 wake_up(&eni_dev->tx_wait);
27520 dma_complete++;
27521 }
27522 @@ -1569,7 +1569,7 @@ tx_complete++;
27523 /*--------------------------------- entries ---------------------------------*/
27524
27525
27526 -static const char *media_name[] __devinitdata = {
27527 +static const char *media_name[] __devinitconst = {
27528 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27529 "UTP", "05?", "06?", "07?", /* 4- 7 */
27530 "TAXI","09?", "10?", "11?", /* 8-11 */
27531 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27532 index 5072f8a..fa52520d 100644
27533 --- a/drivers/atm/firestream.c
27534 +++ b/drivers/atm/firestream.c
27535 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27536 }
27537 }
27538
27539 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27540 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27541
27542 fs_dprintk (FS_DEBUG_TXMEM, "i");
27543 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27544 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27545 #endif
27546 skb_put (skb, qe->p1 & 0xffff);
27547 ATM_SKB(skb)->vcc = atm_vcc;
27548 - atomic_inc(&atm_vcc->stats->rx);
27549 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27550 __net_timestamp(skb);
27551 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27552 atm_vcc->push (atm_vcc, skb);
27553 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27554 kfree (pe);
27555 }
27556 if (atm_vcc)
27557 - atomic_inc(&atm_vcc->stats->rx_drop);
27558 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27559 break;
27560 case 0x1f: /* Reassembly abort: no buffers. */
27561 /* Silently increment error counter. */
27562 if (atm_vcc)
27563 - atomic_inc(&atm_vcc->stats->rx_drop);
27564 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27565 break;
27566 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27567 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27568 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27569 index 361f5ae..7fc552d 100644
27570 --- a/drivers/atm/fore200e.c
27571 +++ b/drivers/atm/fore200e.c
27572 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27573 #endif
27574 /* check error condition */
27575 if (*entry->status & STATUS_ERROR)
27576 - atomic_inc(&vcc->stats->tx_err);
27577 + atomic_inc_unchecked(&vcc->stats->tx_err);
27578 else
27579 - atomic_inc(&vcc->stats->tx);
27580 + atomic_inc_unchecked(&vcc->stats->tx);
27581 }
27582 }
27583
27584 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27585 if (skb == NULL) {
27586 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27587
27588 - atomic_inc(&vcc->stats->rx_drop);
27589 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27590 return -ENOMEM;
27591 }
27592
27593 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27594
27595 dev_kfree_skb_any(skb);
27596
27597 - atomic_inc(&vcc->stats->rx_drop);
27598 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27599 return -ENOMEM;
27600 }
27601
27602 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27603
27604 vcc->push(vcc, skb);
27605 - atomic_inc(&vcc->stats->rx);
27606 + atomic_inc_unchecked(&vcc->stats->rx);
27607
27608 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27609
27610 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27611 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27612 fore200e->atm_dev->number,
27613 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27614 - atomic_inc(&vcc->stats->rx_err);
27615 + atomic_inc_unchecked(&vcc->stats->rx_err);
27616 }
27617 }
27618
27619 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27620 goto retry_here;
27621 }
27622
27623 - atomic_inc(&vcc->stats->tx_err);
27624 + atomic_inc_unchecked(&vcc->stats->tx_err);
27625
27626 fore200e->tx_sat++;
27627 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27628 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27629 index b182c2f..1c6fa8a 100644
27630 --- a/drivers/atm/he.c
27631 +++ b/drivers/atm/he.c
27632 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27633
27634 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27635 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27636 - atomic_inc(&vcc->stats->rx_drop);
27637 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27638 goto return_host_buffers;
27639 }
27640
27641 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27642 RBRQ_LEN_ERR(he_dev->rbrq_head)
27643 ? "LEN_ERR" : "",
27644 vcc->vpi, vcc->vci);
27645 - atomic_inc(&vcc->stats->rx_err);
27646 + atomic_inc_unchecked(&vcc->stats->rx_err);
27647 goto return_host_buffers;
27648 }
27649
27650 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27651 vcc->push(vcc, skb);
27652 spin_lock(&he_dev->global_lock);
27653
27654 - atomic_inc(&vcc->stats->rx);
27655 + atomic_inc_unchecked(&vcc->stats->rx);
27656
27657 return_host_buffers:
27658 ++pdus_assembled;
27659 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27660 tpd->vcc->pop(tpd->vcc, tpd->skb);
27661 else
27662 dev_kfree_skb_any(tpd->skb);
27663 - atomic_inc(&tpd->vcc->stats->tx_err);
27664 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27665 }
27666 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27667 return;
27668 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27669 vcc->pop(vcc, skb);
27670 else
27671 dev_kfree_skb_any(skb);
27672 - atomic_inc(&vcc->stats->tx_err);
27673 + atomic_inc_unchecked(&vcc->stats->tx_err);
27674 return -EINVAL;
27675 }
27676
27677 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27678 vcc->pop(vcc, skb);
27679 else
27680 dev_kfree_skb_any(skb);
27681 - atomic_inc(&vcc->stats->tx_err);
27682 + atomic_inc_unchecked(&vcc->stats->tx_err);
27683 return -EINVAL;
27684 }
27685 #endif
27686 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27687 vcc->pop(vcc, skb);
27688 else
27689 dev_kfree_skb_any(skb);
27690 - atomic_inc(&vcc->stats->tx_err);
27691 + atomic_inc_unchecked(&vcc->stats->tx_err);
27692 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27693 return -ENOMEM;
27694 }
27695 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27696 vcc->pop(vcc, skb);
27697 else
27698 dev_kfree_skb_any(skb);
27699 - atomic_inc(&vcc->stats->tx_err);
27700 + atomic_inc_unchecked(&vcc->stats->tx_err);
27701 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27702 return -ENOMEM;
27703 }
27704 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27705 __enqueue_tpd(he_dev, tpd, cid);
27706 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27707
27708 - atomic_inc(&vcc->stats->tx);
27709 + atomic_inc_unchecked(&vcc->stats->tx);
27710
27711 return 0;
27712 }
27713 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27714 index b812103..e391a49 100644
27715 --- a/drivers/atm/horizon.c
27716 +++ b/drivers/atm/horizon.c
27717 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27718 {
27719 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27720 // VC layer stats
27721 - atomic_inc(&vcc->stats->rx);
27722 + atomic_inc_unchecked(&vcc->stats->rx);
27723 __net_timestamp(skb);
27724 // end of our responsibility
27725 vcc->push (vcc, skb);
27726 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27727 dev->tx_iovec = NULL;
27728
27729 // VC layer stats
27730 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27731 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27732
27733 // free the skb
27734 hrz_kfree_skb (skb);
27735 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27736 index 1c05212..c28e200 100644
27737 --- a/drivers/atm/idt77252.c
27738 +++ b/drivers/atm/idt77252.c
27739 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27740 else
27741 dev_kfree_skb(skb);
27742
27743 - atomic_inc(&vcc->stats->tx);
27744 + atomic_inc_unchecked(&vcc->stats->tx);
27745 }
27746
27747 atomic_dec(&scq->used);
27748 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27749 if ((sb = dev_alloc_skb(64)) == NULL) {
27750 printk("%s: Can't allocate buffers for aal0.\n",
27751 card->name);
27752 - atomic_add(i, &vcc->stats->rx_drop);
27753 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27754 break;
27755 }
27756 if (!atm_charge(vcc, sb->truesize)) {
27757 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27758 card->name);
27759 - atomic_add(i - 1, &vcc->stats->rx_drop);
27760 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27761 dev_kfree_skb(sb);
27762 break;
27763 }
27764 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27765 ATM_SKB(sb)->vcc = vcc;
27766 __net_timestamp(sb);
27767 vcc->push(vcc, sb);
27768 - atomic_inc(&vcc->stats->rx);
27769 + atomic_inc_unchecked(&vcc->stats->rx);
27770
27771 cell += ATM_CELL_PAYLOAD;
27772 }
27773 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27774 "(CDC: %08x)\n",
27775 card->name, len, rpp->len, readl(SAR_REG_CDC));
27776 recycle_rx_pool_skb(card, rpp);
27777 - atomic_inc(&vcc->stats->rx_err);
27778 + atomic_inc_unchecked(&vcc->stats->rx_err);
27779 return;
27780 }
27781 if (stat & SAR_RSQE_CRC) {
27782 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27783 recycle_rx_pool_skb(card, rpp);
27784 - atomic_inc(&vcc->stats->rx_err);
27785 + atomic_inc_unchecked(&vcc->stats->rx_err);
27786 return;
27787 }
27788 if (skb_queue_len(&rpp->queue) > 1) {
27789 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27790 RXPRINTK("%s: Can't alloc RX skb.\n",
27791 card->name);
27792 recycle_rx_pool_skb(card, rpp);
27793 - atomic_inc(&vcc->stats->rx_err);
27794 + atomic_inc_unchecked(&vcc->stats->rx_err);
27795 return;
27796 }
27797 if (!atm_charge(vcc, skb->truesize)) {
27798 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27799 __net_timestamp(skb);
27800
27801 vcc->push(vcc, skb);
27802 - atomic_inc(&vcc->stats->rx);
27803 + atomic_inc_unchecked(&vcc->stats->rx);
27804
27805 return;
27806 }
27807 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27808 __net_timestamp(skb);
27809
27810 vcc->push(vcc, skb);
27811 - atomic_inc(&vcc->stats->rx);
27812 + atomic_inc_unchecked(&vcc->stats->rx);
27813
27814 if (skb->truesize > SAR_FB_SIZE_3)
27815 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27816 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
27817 if (vcc->qos.aal != ATM_AAL0) {
27818 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27819 card->name, vpi, vci);
27820 - atomic_inc(&vcc->stats->rx_drop);
27821 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27822 goto drop;
27823 }
27824
27825 if ((sb = dev_alloc_skb(64)) == NULL) {
27826 printk("%s: Can't allocate buffers for AAL0.\n",
27827 card->name);
27828 - atomic_inc(&vcc->stats->rx_err);
27829 + atomic_inc_unchecked(&vcc->stats->rx_err);
27830 goto drop;
27831 }
27832
27833 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
27834 ATM_SKB(sb)->vcc = vcc;
27835 __net_timestamp(sb);
27836 vcc->push(vcc, sb);
27837 - atomic_inc(&vcc->stats->rx);
27838 + atomic_inc_unchecked(&vcc->stats->rx);
27839
27840 drop:
27841 skb_pull(queue, 64);
27842 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27843
27844 if (vc == NULL) {
27845 printk("%s: NULL connection in send().\n", card->name);
27846 - atomic_inc(&vcc->stats->tx_err);
27847 + atomic_inc_unchecked(&vcc->stats->tx_err);
27848 dev_kfree_skb(skb);
27849 return -EINVAL;
27850 }
27851 if (!test_bit(VCF_TX, &vc->flags)) {
27852 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27853 - atomic_inc(&vcc->stats->tx_err);
27854 + atomic_inc_unchecked(&vcc->stats->tx_err);
27855 dev_kfree_skb(skb);
27856 return -EINVAL;
27857 }
27858 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27859 break;
27860 default:
27861 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27862 - atomic_inc(&vcc->stats->tx_err);
27863 + atomic_inc_unchecked(&vcc->stats->tx_err);
27864 dev_kfree_skb(skb);
27865 return -EINVAL;
27866 }
27867
27868 if (skb_shinfo(skb)->nr_frags != 0) {
27869 printk("%s: No scatter-gather yet.\n", card->name);
27870 - atomic_inc(&vcc->stats->tx_err);
27871 + atomic_inc_unchecked(&vcc->stats->tx_err);
27872 dev_kfree_skb(skb);
27873 return -EINVAL;
27874 }
27875 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27876
27877 err = queue_skb(card, vc, skb, oam);
27878 if (err) {
27879 - atomic_inc(&vcc->stats->tx_err);
27880 + atomic_inc_unchecked(&vcc->stats->tx_err);
27881 dev_kfree_skb(skb);
27882 return err;
27883 }
27884 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27885 skb = dev_alloc_skb(64);
27886 if (!skb) {
27887 printk("%s: Out of memory in send_oam().\n", card->name);
27888 - atomic_inc(&vcc->stats->tx_err);
27889 + atomic_inc_unchecked(&vcc->stats->tx_err);
27890 return -ENOMEM;
27891 }
27892 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27893 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27894 index 9e373ba..cf93727 100644
27895 --- a/drivers/atm/iphase.c
27896 +++ b/drivers/atm/iphase.c
27897 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27898 status = (u_short) (buf_desc_ptr->desc_mode);
27899 if (status & (RX_CER | RX_PTE | RX_OFL))
27900 {
27901 - atomic_inc(&vcc->stats->rx_err);
27902 + atomic_inc_unchecked(&vcc->stats->rx_err);
27903 IF_ERR(printk("IA: bad packet, dropping it");)
27904 if (status & RX_CER) {
27905 IF_ERR(printk(" cause: packet CRC error\n");)
27906 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27907 len = dma_addr - buf_addr;
27908 if (len > iadev->rx_buf_sz) {
27909 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27910 - atomic_inc(&vcc->stats->rx_err);
27911 + atomic_inc_unchecked(&vcc->stats->rx_err);
27912 goto out_free_desc;
27913 }
27914
27915 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27916 ia_vcc = INPH_IA_VCC(vcc);
27917 if (ia_vcc == NULL)
27918 {
27919 - atomic_inc(&vcc->stats->rx_err);
27920 + atomic_inc_unchecked(&vcc->stats->rx_err);
27921 atm_return(vcc, skb->truesize);
27922 dev_kfree_skb_any(skb);
27923 goto INCR_DLE;
27924 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27925 if ((length > iadev->rx_buf_sz) || (length >
27926 (skb->len - sizeof(struct cpcs_trailer))))
27927 {
27928 - atomic_inc(&vcc->stats->rx_err);
27929 + atomic_inc_unchecked(&vcc->stats->rx_err);
27930 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27931 length, skb->len);)
27932 atm_return(vcc, skb->truesize);
27933 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27934
27935 IF_RX(printk("rx_dle_intr: skb push");)
27936 vcc->push(vcc,skb);
27937 - atomic_inc(&vcc->stats->rx);
27938 + atomic_inc_unchecked(&vcc->stats->rx);
27939 iadev->rx_pkt_cnt++;
27940 }
27941 INCR_DLE:
27942 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27943 {
27944 struct k_sonet_stats *stats;
27945 stats = &PRIV(_ia_dev[board])->sonet_stats;
27946 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27947 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27948 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27949 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27950 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27951 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27952 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27953 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27954 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27955 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27956 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27957 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27958 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27959 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27960 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27961 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27962 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27963 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27964 }
27965 ia_cmds.status = 0;
27966 break;
27967 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27968 if ((desc == 0) || (desc > iadev->num_tx_desc))
27969 {
27970 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27971 - atomic_inc(&vcc->stats->tx);
27972 + atomic_inc_unchecked(&vcc->stats->tx);
27973 if (vcc->pop)
27974 vcc->pop(vcc, skb);
27975 else
27976 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27977 ATM_DESC(skb) = vcc->vci;
27978 skb_queue_tail(&iadev->tx_dma_q, skb);
27979
27980 - atomic_inc(&vcc->stats->tx);
27981 + atomic_inc_unchecked(&vcc->stats->tx);
27982 iadev->tx_pkt_cnt++;
27983 /* Increment transaction counter */
27984 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27985
27986 #if 0
27987 /* add flow control logic */
27988 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27989 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27990 if (iavcc->vc_desc_cnt > 10) {
27991 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27992 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27993 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
27994 index f556969..0da15eb 100644
27995 --- a/drivers/atm/lanai.c
27996 +++ b/drivers/atm/lanai.c
27997 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
27998 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27999 lanai_endtx(lanai, lvcc);
28000 lanai_free_skb(lvcc->tx.atmvcc, skb);
28001 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28002 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28003 }
28004
28005 /* Try to fill the buffer - don't call unless there is backlog */
28006 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28007 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28008 __net_timestamp(skb);
28009 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28010 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28011 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28012 out:
28013 lvcc->rx.buf.ptr = end;
28014 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28015 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28016 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28017 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28018 lanai->stats.service_rxnotaal5++;
28019 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28020 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28021 return 0;
28022 }
28023 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28024 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28025 int bytes;
28026 read_unlock(&vcc_sklist_lock);
28027 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28028 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28029 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28030 lvcc->stats.x.aal5.service_trash++;
28031 bytes = (SERVICE_GET_END(s) * 16) -
28032 (((unsigned long) lvcc->rx.buf.ptr) -
28033 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28034 }
28035 if (s & SERVICE_STREAM) {
28036 read_unlock(&vcc_sklist_lock);
28037 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28038 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28039 lvcc->stats.x.aal5.service_stream++;
28040 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28041 "PDU on VCI %d!\n", lanai->number, vci);
28042 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28043 return 0;
28044 }
28045 DPRINTK("got rx crc error on vci %d\n", vci);
28046 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28047 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28048 lvcc->stats.x.aal5.service_rxcrc++;
28049 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28050 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28051 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28052 index 1c70c45..300718d 100644
28053 --- a/drivers/atm/nicstar.c
28054 +++ b/drivers/atm/nicstar.c
28055 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28056 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28057 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28058 card->index);
28059 - atomic_inc(&vcc->stats->tx_err);
28060 + atomic_inc_unchecked(&vcc->stats->tx_err);
28061 dev_kfree_skb_any(skb);
28062 return -EINVAL;
28063 }
28064 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28065 if (!vc->tx) {
28066 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28067 card->index);
28068 - atomic_inc(&vcc->stats->tx_err);
28069 + atomic_inc_unchecked(&vcc->stats->tx_err);
28070 dev_kfree_skb_any(skb);
28071 return -EINVAL;
28072 }
28073 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28074 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28075 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28076 card->index);
28077 - atomic_inc(&vcc->stats->tx_err);
28078 + atomic_inc_unchecked(&vcc->stats->tx_err);
28079 dev_kfree_skb_any(skb);
28080 return -EINVAL;
28081 }
28082
28083 if (skb_shinfo(skb)->nr_frags != 0) {
28084 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28085 - atomic_inc(&vcc->stats->tx_err);
28086 + atomic_inc_unchecked(&vcc->stats->tx_err);
28087 dev_kfree_skb_any(skb);
28088 return -EINVAL;
28089 }
28090 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28091 }
28092
28093 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28094 - atomic_inc(&vcc->stats->tx_err);
28095 + atomic_inc_unchecked(&vcc->stats->tx_err);
28096 dev_kfree_skb_any(skb);
28097 return -EIO;
28098 }
28099 - atomic_inc(&vcc->stats->tx);
28100 + atomic_inc_unchecked(&vcc->stats->tx);
28101
28102 return 0;
28103 }
28104 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28105 printk
28106 ("nicstar%d: Can't allocate buffers for aal0.\n",
28107 card->index);
28108 - atomic_add(i, &vcc->stats->rx_drop);
28109 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28110 break;
28111 }
28112 if (!atm_charge(vcc, sb->truesize)) {
28113 RXPRINTK
28114 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28115 card->index);
28116 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28117 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28118 dev_kfree_skb_any(sb);
28119 break;
28120 }
28121 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28122 ATM_SKB(sb)->vcc = vcc;
28123 __net_timestamp(sb);
28124 vcc->push(vcc, sb);
28125 - atomic_inc(&vcc->stats->rx);
28126 + atomic_inc_unchecked(&vcc->stats->rx);
28127 cell += ATM_CELL_PAYLOAD;
28128 }
28129
28130 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28131 if (iovb == NULL) {
28132 printk("nicstar%d: Out of iovec buffers.\n",
28133 card->index);
28134 - atomic_inc(&vcc->stats->rx_drop);
28135 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28136 recycle_rx_buf(card, skb);
28137 return;
28138 }
28139 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28140 small or large buffer itself. */
28141 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28142 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28143 - atomic_inc(&vcc->stats->rx_err);
28144 + atomic_inc_unchecked(&vcc->stats->rx_err);
28145 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28146 NS_MAX_IOVECS);
28147 NS_PRV_IOVCNT(iovb) = 0;
28148 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28149 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28150 card->index);
28151 which_list(card, skb);
28152 - atomic_inc(&vcc->stats->rx_err);
28153 + atomic_inc_unchecked(&vcc->stats->rx_err);
28154 recycle_rx_buf(card, skb);
28155 vc->rx_iov = NULL;
28156 recycle_iov_buf(card, iovb);
28157 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28158 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28159 card->index);
28160 which_list(card, skb);
28161 - atomic_inc(&vcc->stats->rx_err);
28162 + atomic_inc_unchecked(&vcc->stats->rx_err);
28163 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28164 NS_PRV_IOVCNT(iovb));
28165 vc->rx_iov = NULL;
28166 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28167 printk(" - PDU size mismatch.\n");
28168 else
28169 printk(".\n");
28170 - atomic_inc(&vcc->stats->rx_err);
28171 + atomic_inc_unchecked(&vcc->stats->rx_err);
28172 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28173 NS_PRV_IOVCNT(iovb));
28174 vc->rx_iov = NULL;
28175 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28176 /* skb points to a small buffer */
28177 if (!atm_charge(vcc, skb->truesize)) {
28178 push_rxbufs(card, skb);
28179 - atomic_inc(&vcc->stats->rx_drop);
28180 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28181 } else {
28182 skb_put(skb, len);
28183 dequeue_sm_buf(card, skb);
28184 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28185 ATM_SKB(skb)->vcc = vcc;
28186 __net_timestamp(skb);
28187 vcc->push(vcc, skb);
28188 - atomic_inc(&vcc->stats->rx);
28189 + atomic_inc_unchecked(&vcc->stats->rx);
28190 }
28191 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28192 struct sk_buff *sb;
28193 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28194 if (len <= NS_SMBUFSIZE) {
28195 if (!atm_charge(vcc, sb->truesize)) {
28196 push_rxbufs(card, sb);
28197 - atomic_inc(&vcc->stats->rx_drop);
28198 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28199 } else {
28200 skb_put(sb, len);
28201 dequeue_sm_buf(card, sb);
28202 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28203 ATM_SKB(sb)->vcc = vcc;
28204 __net_timestamp(sb);
28205 vcc->push(vcc, sb);
28206 - atomic_inc(&vcc->stats->rx);
28207 + atomic_inc_unchecked(&vcc->stats->rx);
28208 }
28209
28210 push_rxbufs(card, skb);
28211 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28212
28213 if (!atm_charge(vcc, skb->truesize)) {
28214 push_rxbufs(card, skb);
28215 - atomic_inc(&vcc->stats->rx_drop);
28216 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28217 } else {
28218 dequeue_lg_buf(card, skb);
28219 #ifdef NS_USE_DESTRUCTORS
28220 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28221 ATM_SKB(skb)->vcc = vcc;
28222 __net_timestamp(skb);
28223 vcc->push(vcc, skb);
28224 - atomic_inc(&vcc->stats->rx);
28225 + atomic_inc_unchecked(&vcc->stats->rx);
28226 }
28227
28228 push_rxbufs(card, sb);
28229 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28230 printk
28231 ("nicstar%d: Out of huge buffers.\n",
28232 card->index);
28233 - atomic_inc(&vcc->stats->rx_drop);
28234 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28235 recycle_iovec_rx_bufs(card,
28236 (struct iovec *)
28237 iovb->data,
28238 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28239 card->hbpool.count++;
28240 } else
28241 dev_kfree_skb_any(hb);
28242 - atomic_inc(&vcc->stats->rx_drop);
28243 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28244 } else {
28245 /* Copy the small buffer to the huge buffer */
28246 sb = (struct sk_buff *)iov->iov_base;
28247 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28248 #endif /* NS_USE_DESTRUCTORS */
28249 __net_timestamp(hb);
28250 vcc->push(vcc, hb);
28251 - atomic_inc(&vcc->stats->rx);
28252 + atomic_inc_unchecked(&vcc->stats->rx);
28253 }
28254 }
28255
28256 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28257 index e8cd652..bbbd1fc 100644
28258 --- a/drivers/atm/solos-pci.c
28259 +++ b/drivers/atm/solos-pci.c
28260 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28261 }
28262 atm_charge(vcc, skb->truesize);
28263 vcc->push(vcc, skb);
28264 - atomic_inc(&vcc->stats->rx);
28265 + atomic_inc_unchecked(&vcc->stats->rx);
28266 break;
28267
28268 case PKT_STATUS:
28269 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28270 vcc = SKB_CB(oldskb)->vcc;
28271
28272 if (vcc) {
28273 - atomic_inc(&vcc->stats->tx);
28274 + atomic_inc_unchecked(&vcc->stats->tx);
28275 solos_pop(vcc, oldskb);
28276 } else
28277 dev_kfree_skb_irq(oldskb);
28278 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28279 index 90f1ccc..04c4a1e 100644
28280 --- a/drivers/atm/suni.c
28281 +++ b/drivers/atm/suni.c
28282 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28283
28284
28285 #define ADD_LIMITED(s,v) \
28286 - atomic_add((v),&stats->s); \
28287 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28288 + atomic_add_unchecked((v),&stats->s); \
28289 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28290
28291
28292 static void suni_hz(unsigned long from_timer)
28293 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28294 index 5120a96..e2572bd 100644
28295 --- a/drivers/atm/uPD98402.c
28296 +++ b/drivers/atm/uPD98402.c
28297 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28298 struct sonet_stats tmp;
28299 int error = 0;
28300
28301 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28302 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28303 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28304 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28305 if (zero && !error) {
28306 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28307
28308
28309 #define ADD_LIMITED(s,v) \
28310 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28311 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28312 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28313 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28314 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28315 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28316
28317
28318 static void stat_event(struct atm_dev *dev)
28319 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28320 if (reason & uPD98402_INT_PFM) stat_event(dev);
28321 if (reason & uPD98402_INT_PCO) {
28322 (void) GET(PCOCR); /* clear interrupt cause */
28323 - atomic_add(GET(HECCT),
28324 + atomic_add_unchecked(GET(HECCT),
28325 &PRIV(dev)->sonet_stats.uncorr_hcs);
28326 }
28327 if ((reason & uPD98402_INT_RFO) &&
28328 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28329 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28330 uPD98402_INT_LOS),PIMR); /* enable them */
28331 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28332 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28333 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28334 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28335 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28336 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28337 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28338 return 0;
28339 }
28340
28341 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28342 index d889f56..17eb71e 100644
28343 --- a/drivers/atm/zatm.c
28344 +++ b/drivers/atm/zatm.c
28345 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28346 }
28347 if (!size) {
28348 dev_kfree_skb_irq(skb);
28349 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28350 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28351 continue;
28352 }
28353 if (!atm_charge(vcc,skb->truesize)) {
28354 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28355 skb->len = size;
28356 ATM_SKB(skb)->vcc = vcc;
28357 vcc->push(vcc,skb);
28358 - atomic_inc(&vcc->stats->rx);
28359 + atomic_inc_unchecked(&vcc->stats->rx);
28360 }
28361 zout(pos & 0xffff,MTA(mbx));
28362 #if 0 /* probably a stupid idea */
28363 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28364 skb_queue_head(&zatm_vcc->backlog,skb);
28365 break;
28366 }
28367 - atomic_inc(&vcc->stats->tx);
28368 + atomic_inc_unchecked(&vcc->stats->tx);
28369 wake_up(&zatm_vcc->tx_wait);
28370 }
28371
28372 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28373 index 8493536..31adee0 100644
28374 --- a/drivers/base/devtmpfs.c
28375 +++ b/drivers/base/devtmpfs.c
28376 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28377 if (!thread)
28378 return 0;
28379
28380 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28381 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28382 if (err)
28383 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28384 else
28385 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28386 index caf995f..6f76697 100644
28387 --- a/drivers/base/power/wakeup.c
28388 +++ b/drivers/base/power/wakeup.c
28389 @@ -30,14 +30,14 @@ bool events_check_enabled;
28390 * They need to be modified together atomically, so it's better to use one
28391 * atomic variable to hold them both.
28392 */
28393 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28394 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28395
28396 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28397 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28398
28399 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28400 {
28401 - unsigned int comb = atomic_read(&combined_event_count);
28402 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28403
28404 *cnt = (comb >> IN_PROGRESS_BITS);
28405 *inpr = comb & MAX_IN_PROGRESS;
28406 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28407 ws->last_time = ktime_get();
28408
28409 /* Increment the counter of events in progress. */
28410 - atomic_inc(&combined_event_count);
28411 + atomic_inc_unchecked(&combined_event_count);
28412 }
28413
28414 /**
28415 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28416 * Increment the counter of registered wakeup events and decrement the
28417 * couter of wakeup events in progress simultaneously.
28418 */
28419 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28420 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28421 }
28422
28423 /**
28424 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28425 index b0f553b..77b928b 100644
28426 --- a/drivers/block/cciss.c
28427 +++ b/drivers/block/cciss.c
28428 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28429 int err;
28430 u32 cp;
28431
28432 + memset(&arg64, 0, sizeof(arg64));
28433 +
28434 err = 0;
28435 err |=
28436 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28437 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28438 while (!list_empty(&h->reqQ)) {
28439 c = list_entry(h->reqQ.next, CommandList_struct, list);
28440 /* can't do anything if fifo is full */
28441 - if ((h->access.fifo_full(h))) {
28442 + if ((h->access->fifo_full(h))) {
28443 dev_warn(&h->pdev->dev, "fifo full\n");
28444 break;
28445 }
28446 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28447 h->Qdepth--;
28448
28449 /* Tell the controller execute command */
28450 - h->access.submit_command(h, c);
28451 + h->access->submit_command(h, c);
28452
28453 /* Put job onto the completed Q */
28454 addQ(&h->cmpQ, c);
28455 @@ -3443,17 +3445,17 @@ startio:
28456
28457 static inline unsigned long get_next_completion(ctlr_info_t *h)
28458 {
28459 - return h->access.command_completed(h);
28460 + return h->access->command_completed(h);
28461 }
28462
28463 static inline int interrupt_pending(ctlr_info_t *h)
28464 {
28465 - return h->access.intr_pending(h);
28466 + return h->access->intr_pending(h);
28467 }
28468
28469 static inline long interrupt_not_for_us(ctlr_info_t *h)
28470 {
28471 - return ((h->access.intr_pending(h) == 0) ||
28472 + return ((h->access->intr_pending(h) == 0) ||
28473 (h->interrupts_enabled == 0));
28474 }
28475
28476 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28477 u32 a;
28478
28479 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28480 - return h->access.command_completed(h);
28481 + return h->access->command_completed(h);
28482
28483 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28484 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28485 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28486 trans_support & CFGTBL_Trans_use_short_tags);
28487
28488 /* Change the access methods to the performant access methods */
28489 - h->access = SA5_performant_access;
28490 + h->access = &SA5_performant_access;
28491 h->transMethod = CFGTBL_Trans_Performant;
28492
28493 return;
28494 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28495 if (prod_index < 0)
28496 return -ENODEV;
28497 h->product_name = products[prod_index].product_name;
28498 - h->access = *(products[prod_index].access);
28499 + h->access = products[prod_index].access;
28500
28501 if (cciss_board_disabled(h)) {
28502 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28503 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28504 }
28505
28506 /* make sure the board interrupts are off */
28507 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28508 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28509 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28510 if (rc)
28511 goto clean2;
28512 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28513 * fake ones to scoop up any residual completions.
28514 */
28515 spin_lock_irqsave(&h->lock, flags);
28516 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28517 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28518 spin_unlock_irqrestore(&h->lock, flags);
28519 free_irq(h->intr[h->intr_mode], h);
28520 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28521 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28522 dev_info(&h->pdev->dev, "Board READY.\n");
28523 dev_info(&h->pdev->dev,
28524 "Waiting for stale completions to drain.\n");
28525 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28526 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28527 msleep(10000);
28528 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28529 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28530
28531 rc = controller_reset_failed(h->cfgtable);
28532 if (rc)
28533 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28534 cciss_scsi_setup(h);
28535
28536 /* Turn the interrupts on so we can service requests */
28537 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28538 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28539
28540 /* Get the firmware version */
28541 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28542 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28543 kfree(flush_buf);
28544 if (return_code != IO_OK)
28545 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28546 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28547 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28548 free_irq(h->intr[h->intr_mode], h);
28549 }
28550
28551 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28552 index 7fda30e..eb5dfe0 100644
28553 --- a/drivers/block/cciss.h
28554 +++ b/drivers/block/cciss.h
28555 @@ -101,7 +101,7 @@ struct ctlr_info
28556 /* information about each logical volume */
28557 drive_info_struct *drv[CISS_MAX_LUN];
28558
28559 - struct access_method access;
28560 + struct access_method *access;
28561
28562 /* queue and queue Info */
28563 struct list_head reqQ;
28564 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28565 index 9125bbe..eede5c8 100644
28566 --- a/drivers/block/cpqarray.c
28567 +++ b/drivers/block/cpqarray.c
28568 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28569 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28570 goto Enomem4;
28571 }
28572 - hba[i]->access.set_intr_mask(hba[i], 0);
28573 + hba[i]->access->set_intr_mask(hba[i], 0);
28574 if (request_irq(hba[i]->intr, do_ida_intr,
28575 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28576 {
28577 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28578 add_timer(&hba[i]->timer);
28579
28580 /* Enable IRQ now that spinlock and rate limit timer are set up */
28581 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28582 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28583
28584 for(j=0; j<NWD; j++) {
28585 struct gendisk *disk = ida_gendisk[i][j];
28586 @@ -694,7 +694,7 @@ DBGINFO(
28587 for(i=0; i<NR_PRODUCTS; i++) {
28588 if (board_id == products[i].board_id) {
28589 c->product_name = products[i].product_name;
28590 - c->access = *(products[i].access);
28591 + c->access = products[i].access;
28592 break;
28593 }
28594 }
28595 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28596 hba[ctlr]->intr = intr;
28597 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28598 hba[ctlr]->product_name = products[j].product_name;
28599 - hba[ctlr]->access = *(products[j].access);
28600 + hba[ctlr]->access = products[j].access;
28601 hba[ctlr]->ctlr = ctlr;
28602 hba[ctlr]->board_id = board_id;
28603 hba[ctlr]->pci_dev = NULL; /* not PCI */
28604 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28605
28606 while((c = h->reqQ) != NULL) {
28607 /* Can't do anything if we're busy */
28608 - if (h->access.fifo_full(h) == 0)
28609 + if (h->access->fifo_full(h) == 0)
28610 return;
28611
28612 /* Get the first entry from the request Q */
28613 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28614 h->Qdepth--;
28615
28616 /* Tell the controller to do our bidding */
28617 - h->access.submit_command(h, c);
28618 + h->access->submit_command(h, c);
28619
28620 /* Get onto the completion Q */
28621 addQ(&h->cmpQ, c);
28622 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28623 unsigned long flags;
28624 __u32 a,a1;
28625
28626 - istat = h->access.intr_pending(h);
28627 + istat = h->access->intr_pending(h);
28628 /* Is this interrupt for us? */
28629 if (istat == 0)
28630 return IRQ_NONE;
28631 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28632 */
28633 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28634 if (istat & FIFO_NOT_EMPTY) {
28635 - while((a = h->access.command_completed(h))) {
28636 + while((a = h->access->command_completed(h))) {
28637 a1 = a; a &= ~3;
28638 if ((c = h->cmpQ) == NULL)
28639 {
28640 @@ -1449,11 +1449,11 @@ static int sendcmd(
28641 /*
28642 * Disable interrupt
28643 */
28644 - info_p->access.set_intr_mask(info_p, 0);
28645 + info_p->access->set_intr_mask(info_p, 0);
28646 /* Make sure there is room in the command FIFO */
28647 /* Actually it should be completely empty at this time. */
28648 for (i = 200000; i > 0; i--) {
28649 - temp = info_p->access.fifo_full(info_p);
28650 + temp = info_p->access->fifo_full(info_p);
28651 if (temp != 0) {
28652 break;
28653 }
28654 @@ -1466,7 +1466,7 @@ DBG(
28655 /*
28656 * Send the cmd
28657 */
28658 - info_p->access.submit_command(info_p, c);
28659 + info_p->access->submit_command(info_p, c);
28660 complete = pollcomplete(ctlr);
28661
28662 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28663 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28664 * we check the new geometry. Then turn interrupts back on when
28665 * we're done.
28666 */
28667 - host->access.set_intr_mask(host, 0);
28668 + host->access->set_intr_mask(host, 0);
28669 getgeometry(ctlr);
28670 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28671 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28672
28673 for(i=0; i<NWD; i++) {
28674 struct gendisk *disk = ida_gendisk[ctlr][i];
28675 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28676 /* Wait (up to 2 seconds) for a command to complete */
28677
28678 for (i = 200000; i > 0; i--) {
28679 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28680 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28681 if (done == 0) {
28682 udelay(10); /* a short fixed delay */
28683 } else
28684 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28685 index be73e9d..7fbf140 100644
28686 --- a/drivers/block/cpqarray.h
28687 +++ b/drivers/block/cpqarray.h
28688 @@ -99,7 +99,7 @@ struct ctlr_info {
28689 drv_info_t drv[NWD];
28690 struct proc_dir_entry *proc;
28691
28692 - struct access_method access;
28693 + struct access_method *access;
28694
28695 cmdlist_t *reqQ;
28696 cmdlist_t *cmpQ;
28697 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28698 index 8d68056..e67050f 100644
28699 --- a/drivers/block/drbd/drbd_int.h
28700 +++ b/drivers/block/drbd/drbd_int.h
28701 @@ -736,7 +736,7 @@ struct drbd_request;
28702 struct drbd_epoch {
28703 struct list_head list;
28704 unsigned int barrier_nr;
28705 - atomic_t epoch_size; /* increased on every request added. */
28706 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28707 atomic_t active; /* increased on every req. added, and dec on every finished. */
28708 unsigned long flags;
28709 };
28710 @@ -1108,7 +1108,7 @@ struct drbd_conf {
28711 void *int_dig_in;
28712 void *int_dig_vv;
28713 wait_queue_head_t seq_wait;
28714 - atomic_t packet_seq;
28715 + atomic_unchecked_t packet_seq;
28716 unsigned int peer_seq;
28717 spinlock_t peer_seq_lock;
28718 unsigned int minor;
28719 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28720
28721 static inline void drbd_tcp_cork(struct socket *sock)
28722 {
28723 - int __user val = 1;
28724 + int val = 1;
28725 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28726 - (char __user *)&val, sizeof(val));
28727 + (char __force_user *)&val, sizeof(val));
28728 }
28729
28730 static inline void drbd_tcp_uncork(struct socket *sock)
28731 {
28732 - int __user val = 0;
28733 + int val = 0;
28734 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28735 - (char __user *)&val, sizeof(val));
28736 + (char __force_user *)&val, sizeof(val));
28737 }
28738
28739 static inline void drbd_tcp_nodelay(struct socket *sock)
28740 {
28741 - int __user val = 1;
28742 + int val = 1;
28743 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28744 - (char __user *)&val, sizeof(val));
28745 + (char __force_user *)&val, sizeof(val));
28746 }
28747
28748 static inline void drbd_tcp_quickack(struct socket *sock)
28749 {
28750 - int __user val = 2;
28751 + int val = 2;
28752 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
28753 - (char __user *)&val, sizeof(val));
28754 + (char __force_user *)&val, sizeof(val));
28755 }
28756
28757 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
28758 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
28759 index 211fc44..c5116f1 100644
28760 --- a/drivers/block/drbd/drbd_main.c
28761 +++ b/drivers/block/drbd/drbd_main.c
28762 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
28763 p.sector = sector;
28764 p.block_id = block_id;
28765 p.blksize = blksize;
28766 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
28767 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
28768
28769 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
28770 return false;
28771 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
28772 p.sector = cpu_to_be64(req->sector);
28773 p.block_id = (unsigned long)req;
28774 p.seq_num = cpu_to_be32(req->seq_num =
28775 - atomic_add_return(1, &mdev->packet_seq));
28776 + atomic_add_return_unchecked(1, &mdev->packet_seq));
28777
28778 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
28779
28780 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
28781 atomic_set(&mdev->unacked_cnt, 0);
28782 atomic_set(&mdev->local_cnt, 0);
28783 atomic_set(&mdev->net_cnt, 0);
28784 - atomic_set(&mdev->packet_seq, 0);
28785 + atomic_set_unchecked(&mdev->packet_seq, 0);
28786 atomic_set(&mdev->pp_in_use, 0);
28787 atomic_set(&mdev->pp_in_use_by_net, 0);
28788 atomic_set(&mdev->rs_sect_in, 0);
28789 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
28790 mdev->receiver.t_state);
28791
28792 /* no need to lock it, I'm the only thread alive */
28793 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
28794 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
28795 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
28796 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
28797 mdev->al_writ_cnt =
28798 mdev->bm_writ_cnt =
28799 mdev->read_cnt =
28800 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
28801 index af2a250..219c74b 100644
28802 --- a/drivers/block/drbd/drbd_nl.c
28803 +++ b/drivers/block/drbd/drbd_nl.c
28804 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
28805 module_put(THIS_MODULE);
28806 }
28807
28808 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28809 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28810
28811 static unsigned short *
28812 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
28813 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
28814 cn_reply->id.idx = CN_IDX_DRBD;
28815 cn_reply->id.val = CN_VAL_DRBD;
28816
28817 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28818 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28819 cn_reply->ack = 0; /* not used here. */
28820 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28821 (int)((char *)tl - (char *)reply->tag_list);
28822 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
28823 cn_reply->id.idx = CN_IDX_DRBD;
28824 cn_reply->id.val = CN_VAL_DRBD;
28825
28826 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28827 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28828 cn_reply->ack = 0; /* not used here. */
28829 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28830 (int)((char *)tl - (char *)reply->tag_list);
28831 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
28832 cn_reply->id.idx = CN_IDX_DRBD;
28833 cn_reply->id.val = CN_VAL_DRBD;
28834
28835 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
28836 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
28837 cn_reply->ack = 0; // not used here.
28838 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28839 (int)((char*)tl - (char*)reply->tag_list);
28840 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
28841 cn_reply->id.idx = CN_IDX_DRBD;
28842 cn_reply->id.val = CN_VAL_DRBD;
28843
28844 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28845 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28846 cn_reply->ack = 0; /* not used here. */
28847 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28848 (int)((char *)tl - (char *)reply->tag_list);
28849 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
28850 index 43beaca..4a5b1dd 100644
28851 --- a/drivers/block/drbd/drbd_receiver.c
28852 +++ b/drivers/block/drbd/drbd_receiver.c
28853 @@ -894,7 +894,7 @@ retry:
28854 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
28855 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28856
28857 - atomic_set(&mdev->packet_seq, 0);
28858 + atomic_set_unchecked(&mdev->packet_seq, 0);
28859 mdev->peer_seq = 0;
28860
28861 drbd_thread_start(&mdev->asender);
28862 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28863 do {
28864 next_epoch = NULL;
28865
28866 - epoch_size = atomic_read(&epoch->epoch_size);
28867 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28868
28869 switch (ev & ~EV_CLEANUP) {
28870 case EV_PUT:
28871 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28872 rv = FE_DESTROYED;
28873 } else {
28874 epoch->flags = 0;
28875 - atomic_set(&epoch->epoch_size, 0);
28876 + atomic_set_unchecked(&epoch->epoch_size, 0);
28877 /* atomic_set(&epoch->active, 0); is already zero */
28878 if (rv == FE_STILL_LIVE)
28879 rv = FE_RECYCLED;
28880 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28881 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28882 drbd_flush(mdev);
28883
28884 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28885 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28886 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28887 if (epoch)
28888 break;
28889 }
28890
28891 epoch = mdev->current_epoch;
28892 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28893 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28894
28895 D_ASSERT(atomic_read(&epoch->active) == 0);
28896 D_ASSERT(epoch->flags == 0);
28897 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28898 }
28899
28900 epoch->flags = 0;
28901 - atomic_set(&epoch->epoch_size, 0);
28902 + atomic_set_unchecked(&epoch->epoch_size, 0);
28903 atomic_set(&epoch->active, 0);
28904
28905 spin_lock(&mdev->epoch_lock);
28906 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28907 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28908 list_add(&epoch->list, &mdev->current_epoch->list);
28909 mdev->current_epoch = epoch;
28910 mdev->epochs++;
28911 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28912 spin_unlock(&mdev->peer_seq_lock);
28913
28914 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28915 - atomic_inc(&mdev->current_epoch->epoch_size);
28916 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28917 return drbd_drain_block(mdev, data_size);
28918 }
28919
28920 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28921
28922 spin_lock(&mdev->epoch_lock);
28923 e->epoch = mdev->current_epoch;
28924 - atomic_inc(&e->epoch->epoch_size);
28925 + atomic_inc_unchecked(&e->epoch->epoch_size);
28926 atomic_inc(&e->epoch->active);
28927 spin_unlock(&mdev->epoch_lock);
28928
28929 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28930 D_ASSERT(list_empty(&mdev->done_ee));
28931
28932 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28933 - atomic_set(&mdev->current_epoch->epoch_size, 0);
28934 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28935 D_ASSERT(list_empty(&mdev->current_epoch->list));
28936 }
28937
28938 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28939 index cd50435..ba1ffb5 100644
28940 --- a/drivers/block/loop.c
28941 +++ b/drivers/block/loop.c
28942 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
28943 mm_segment_t old_fs = get_fs();
28944
28945 set_fs(get_ds());
28946 - bw = file->f_op->write(file, buf, len, &pos);
28947 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28948 set_fs(old_fs);
28949 if (likely(bw == len))
28950 return 0;
28951 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
28952 index 4364303..9adf4ee 100644
28953 --- a/drivers/char/Kconfig
28954 +++ b/drivers/char/Kconfig
28955 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28956
28957 config DEVKMEM
28958 bool "/dev/kmem virtual device support"
28959 - default y
28960 + default n
28961 + depends on !GRKERNSEC_KMEM
28962 help
28963 Say Y here if you want to support the /dev/kmem device. The
28964 /dev/kmem device is rarely used, but can be used for certain
28965 @@ -596,6 +597,7 @@ config DEVPORT
28966 bool
28967 depends on !M68K
28968 depends on ISA || PCI
28969 + depends on !GRKERNSEC_KMEM
28970 default y
28971
28972 source "drivers/s390/char/Kconfig"
28973 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
28974 index 2e04433..22afc64 100644
28975 --- a/drivers/char/agp/frontend.c
28976 +++ b/drivers/char/agp/frontend.c
28977 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
28978 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
28979 return -EFAULT;
28980
28981 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
28982 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
28983 return -EFAULT;
28984
28985 client = agp_find_client_by_pid(reserve.pid);
28986 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
28987 index 095ab90..afad0a4 100644
28988 --- a/drivers/char/briq_panel.c
28989 +++ b/drivers/char/briq_panel.c
28990 @@ -9,6 +9,7 @@
28991 #include <linux/types.h>
28992 #include <linux/errno.h>
28993 #include <linux/tty.h>
28994 +#include <linux/mutex.h>
28995 #include <linux/timer.h>
28996 #include <linux/kernel.h>
28997 #include <linux/wait.h>
28998 @@ -34,6 +35,7 @@ static int vfd_is_open;
28999 static unsigned char vfd[40];
29000 static int vfd_cursor;
29001 static unsigned char ledpb, led;
29002 +static DEFINE_MUTEX(vfd_mutex);
29003
29004 static void update_vfd(void)
29005 {
29006 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29007 if (!vfd_is_open)
29008 return -EBUSY;
29009
29010 + mutex_lock(&vfd_mutex);
29011 for (;;) {
29012 char c;
29013 if (!indx)
29014 break;
29015 - if (get_user(c, buf))
29016 + if (get_user(c, buf)) {
29017 + mutex_unlock(&vfd_mutex);
29018 return -EFAULT;
29019 + }
29020 if (esc) {
29021 set_led(c);
29022 esc = 0;
29023 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29024 buf++;
29025 }
29026 update_vfd();
29027 + mutex_unlock(&vfd_mutex);
29028
29029 return len;
29030 }
29031 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29032 index f773a9d..65cd683 100644
29033 --- a/drivers/char/genrtc.c
29034 +++ b/drivers/char/genrtc.c
29035 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29036 switch (cmd) {
29037
29038 case RTC_PLL_GET:
29039 + memset(&pll, 0, sizeof(pll));
29040 if (get_rtc_pll(&pll))
29041 return -EINVAL;
29042 else
29043 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29044 index 0833896..cccce52 100644
29045 --- a/drivers/char/hpet.c
29046 +++ b/drivers/char/hpet.c
29047 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29048 }
29049
29050 static int
29051 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29052 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29053 struct hpet_info *info)
29054 {
29055 struct hpet_timer __iomem *timer;
29056 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29057 index 58c0e63..46c16bf 100644
29058 --- a/drivers/char/ipmi/ipmi_msghandler.c
29059 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29060 @@ -415,7 +415,7 @@ struct ipmi_smi {
29061 struct proc_dir_entry *proc_dir;
29062 char proc_dir_name[10];
29063
29064 - atomic_t stats[IPMI_NUM_STATS];
29065 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29066
29067 /*
29068 * run_to_completion duplicate of smb_info, smi_info
29069 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29070
29071
29072 #define ipmi_inc_stat(intf, stat) \
29073 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29074 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29075 #define ipmi_get_stat(intf, stat) \
29076 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29077 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29078
29079 static int is_lan_addr(struct ipmi_addr *addr)
29080 {
29081 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29082 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29083 init_waitqueue_head(&intf->waitq);
29084 for (i = 0; i < IPMI_NUM_STATS; i++)
29085 - atomic_set(&intf->stats[i], 0);
29086 + atomic_set_unchecked(&intf->stats[i], 0);
29087
29088 intf->proc_dir = NULL;
29089
29090 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29091 index 50fcf9c..91b5528 100644
29092 --- a/drivers/char/ipmi/ipmi_si_intf.c
29093 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29094 @@ -277,7 +277,7 @@ struct smi_info {
29095 unsigned char slave_addr;
29096
29097 /* Counters and things for the proc filesystem. */
29098 - atomic_t stats[SI_NUM_STATS];
29099 + atomic_unchecked_t stats[SI_NUM_STATS];
29100
29101 struct task_struct *thread;
29102
29103 @@ -286,9 +286,9 @@ struct smi_info {
29104 };
29105
29106 #define smi_inc_stat(smi, stat) \
29107 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29108 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29109 #define smi_get_stat(smi, stat) \
29110 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29111 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29112
29113 #define SI_MAX_PARMS 4
29114
29115 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29116 atomic_set(&new_smi->req_events, 0);
29117 new_smi->run_to_completion = 0;
29118 for (i = 0; i < SI_NUM_STATS; i++)
29119 - atomic_set(&new_smi->stats[i], 0);
29120 + atomic_set_unchecked(&new_smi->stats[i], 0);
29121
29122 new_smi->interrupt_disabled = 1;
29123 atomic_set(&new_smi->stop_operation, 0);
29124 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29125 index 1aeaaba..e018570 100644
29126 --- a/drivers/char/mbcs.c
29127 +++ b/drivers/char/mbcs.c
29128 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29129 return 0;
29130 }
29131
29132 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29133 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29134 {
29135 .part_num = MBCS_PART_NUM,
29136 .mfg_num = MBCS_MFG_NUM,
29137 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29138 index d6e9d08..4493e89 100644
29139 --- a/drivers/char/mem.c
29140 +++ b/drivers/char/mem.c
29141 @@ -18,6 +18,7 @@
29142 #include <linux/raw.h>
29143 #include <linux/tty.h>
29144 #include <linux/capability.h>
29145 +#include <linux/security.h>
29146 #include <linux/ptrace.h>
29147 #include <linux/device.h>
29148 #include <linux/highmem.h>
29149 @@ -35,6 +36,10 @@
29150 # include <linux/efi.h>
29151 #endif
29152
29153 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29154 +extern const struct file_operations grsec_fops;
29155 +#endif
29156 +
29157 static inline unsigned long size_inside_page(unsigned long start,
29158 unsigned long size)
29159 {
29160 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29161
29162 while (cursor < to) {
29163 if (!devmem_is_allowed(pfn)) {
29164 +#ifdef CONFIG_GRKERNSEC_KMEM
29165 + gr_handle_mem_readwrite(from, to);
29166 +#else
29167 printk(KERN_INFO
29168 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29169 current->comm, from, to);
29170 +#endif
29171 return 0;
29172 }
29173 cursor += PAGE_SIZE;
29174 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29175 }
29176 return 1;
29177 }
29178 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29179 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29180 +{
29181 + return 0;
29182 +}
29183 #else
29184 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29185 {
29186 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29187
29188 while (count > 0) {
29189 unsigned long remaining;
29190 + char *temp;
29191
29192 sz = size_inside_page(p, count);
29193
29194 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29195 if (!ptr)
29196 return -EFAULT;
29197
29198 - remaining = copy_to_user(buf, ptr, sz);
29199 +#ifdef CONFIG_PAX_USERCOPY
29200 + temp = kmalloc(sz, GFP_KERNEL);
29201 + if (!temp) {
29202 + unxlate_dev_mem_ptr(p, ptr);
29203 + return -ENOMEM;
29204 + }
29205 + memcpy(temp, ptr, sz);
29206 +#else
29207 + temp = ptr;
29208 +#endif
29209 +
29210 + remaining = copy_to_user(buf, temp, sz);
29211 +
29212 +#ifdef CONFIG_PAX_USERCOPY
29213 + kfree(temp);
29214 +#endif
29215 +
29216 unxlate_dev_mem_ptr(p, ptr);
29217 if (remaining)
29218 return -EFAULT;
29219 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29220 size_t count, loff_t *ppos)
29221 {
29222 unsigned long p = *ppos;
29223 - ssize_t low_count, read, sz;
29224 + ssize_t low_count, read, sz, err = 0;
29225 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29226 - int err = 0;
29227
29228 read = 0;
29229 if (p < (unsigned long) high_memory) {
29230 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29231 }
29232 #endif
29233 while (low_count > 0) {
29234 + char *temp;
29235 +
29236 sz = size_inside_page(p, low_count);
29237
29238 /*
29239 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29240 */
29241 kbuf = xlate_dev_kmem_ptr((char *)p);
29242
29243 - if (copy_to_user(buf, kbuf, sz))
29244 +#ifdef CONFIG_PAX_USERCOPY
29245 + temp = kmalloc(sz, GFP_KERNEL);
29246 + if (!temp)
29247 + return -ENOMEM;
29248 + memcpy(temp, kbuf, sz);
29249 +#else
29250 + temp = kbuf;
29251 +#endif
29252 +
29253 + err = copy_to_user(buf, temp, sz);
29254 +
29255 +#ifdef CONFIG_PAX_USERCOPY
29256 + kfree(temp);
29257 +#endif
29258 +
29259 + if (err)
29260 return -EFAULT;
29261 buf += sz;
29262 p += sz;
29263 @@ -867,6 +914,9 @@ static const struct memdev {
29264 #ifdef CONFIG_CRASH_DUMP
29265 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29266 #endif
29267 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29268 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29269 +#endif
29270 };
29271
29272 static int memory_open(struct inode *inode, struct file *filp)
29273 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29274 index da3cfee..a5a6606 100644
29275 --- a/drivers/char/nvram.c
29276 +++ b/drivers/char/nvram.c
29277 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29278
29279 spin_unlock_irq(&rtc_lock);
29280
29281 - if (copy_to_user(buf, contents, tmp - contents))
29282 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29283 return -EFAULT;
29284
29285 *ppos = i;
29286 diff --git a/drivers/char/random.c b/drivers/char/random.c
29287 index 54ca8b2..4a092ed 100644
29288 --- a/drivers/char/random.c
29289 +++ b/drivers/char/random.c
29290 @@ -261,8 +261,13 @@
29291 /*
29292 * Configuration information
29293 */
29294 +#ifdef CONFIG_GRKERNSEC_RANDNET
29295 +#define INPUT_POOL_WORDS 512
29296 +#define OUTPUT_POOL_WORDS 128
29297 +#else
29298 #define INPUT_POOL_WORDS 128
29299 #define OUTPUT_POOL_WORDS 32
29300 +#endif
29301 #define SEC_XFER_SIZE 512
29302 #define EXTRACT_SIZE 10
29303
29304 @@ -300,10 +305,17 @@ static struct poolinfo {
29305 int poolwords;
29306 int tap1, tap2, tap3, tap4, tap5;
29307 } poolinfo_table[] = {
29308 +#ifdef CONFIG_GRKERNSEC_RANDNET
29309 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29310 + { 512, 411, 308, 208, 104, 1 },
29311 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29312 + { 128, 103, 76, 51, 25, 1 },
29313 +#else
29314 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29315 { 128, 103, 76, 51, 25, 1 },
29316 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29317 { 32, 26, 20, 14, 7, 1 },
29318 +#endif
29319 #if 0
29320 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29321 { 2048, 1638, 1231, 819, 411, 1 },
29322 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29323
29324 extract_buf(r, tmp);
29325 i = min_t(int, nbytes, EXTRACT_SIZE);
29326 - if (copy_to_user(buf, tmp, i)) {
29327 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29328 ret = -EFAULT;
29329 break;
29330 }
29331 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29332 #include <linux/sysctl.h>
29333
29334 static int min_read_thresh = 8, min_write_thresh;
29335 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29336 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29337 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29338 static char sysctl_bootid[16];
29339
29340 @@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
29341 uuid = table->data;
29342 if (!uuid) {
29343 uuid = tmp_uuid;
29344 - uuid[8] = 0;
29345 - }
29346 - if (uuid[8] == 0)
29347 generate_random_uuid(uuid);
29348 + } else {
29349 + static DEFINE_SPINLOCK(bootid_spinlock);
29350 +
29351 + spin_lock(&bootid_spinlock);
29352 + if (!uuid[8])
29353 + generate_random_uuid(uuid);
29354 + spin_unlock(&bootid_spinlock);
29355 + }
29356
29357 sprintf(buf, "%pU", uuid);
29358
29359 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29360 index 1ee8ce7..b778bef 100644
29361 --- a/drivers/char/sonypi.c
29362 +++ b/drivers/char/sonypi.c
29363 @@ -55,6 +55,7 @@
29364 #include <asm/uaccess.h>
29365 #include <asm/io.h>
29366 #include <asm/system.h>
29367 +#include <asm/local.h>
29368
29369 #include <linux/sonypi.h>
29370
29371 @@ -491,7 +492,7 @@ static struct sonypi_device {
29372 spinlock_t fifo_lock;
29373 wait_queue_head_t fifo_proc_list;
29374 struct fasync_struct *fifo_async;
29375 - int open_count;
29376 + local_t open_count;
29377 int model;
29378 struct input_dev *input_jog_dev;
29379 struct input_dev *input_key_dev;
29380 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29381 static int sonypi_misc_release(struct inode *inode, struct file *file)
29382 {
29383 mutex_lock(&sonypi_device.lock);
29384 - sonypi_device.open_count--;
29385 + local_dec(&sonypi_device.open_count);
29386 mutex_unlock(&sonypi_device.lock);
29387 return 0;
29388 }
29389 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29390 {
29391 mutex_lock(&sonypi_device.lock);
29392 /* Flush input queue on first open */
29393 - if (!sonypi_device.open_count)
29394 + if (!local_read(&sonypi_device.open_count))
29395 kfifo_reset(&sonypi_device.fifo);
29396 - sonypi_device.open_count++;
29397 + local_inc(&sonypi_device.open_count);
29398 mutex_unlock(&sonypi_device.lock);
29399
29400 return 0;
29401 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29402 index ad7c732..5aa8054 100644
29403 --- a/drivers/char/tpm/tpm.c
29404 +++ b/drivers/char/tpm/tpm.c
29405 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29406 chip->vendor.req_complete_val)
29407 goto out_recv;
29408
29409 - if ((status == chip->vendor.req_canceled)) {
29410 + if (status == chip->vendor.req_canceled) {
29411 dev_err(chip->dev, "Operation Canceled\n");
29412 rc = -ECANCELED;
29413 goto out;
29414 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29415 index 0636520..169c1d0 100644
29416 --- a/drivers/char/tpm/tpm_bios.c
29417 +++ b/drivers/char/tpm/tpm_bios.c
29418 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29419 event = addr;
29420
29421 if ((event->event_type == 0 && event->event_size == 0) ||
29422 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29423 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29424 return NULL;
29425
29426 return addr;
29427 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29428 return NULL;
29429
29430 if ((event->event_type == 0 && event->event_size == 0) ||
29431 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29432 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29433 return NULL;
29434
29435 (*pos)++;
29436 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29437 int i;
29438
29439 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29440 - seq_putc(m, data[i]);
29441 + if (!seq_putc(m, data[i]))
29442 + return -EFAULT;
29443
29444 return 0;
29445 }
29446 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29447 log->bios_event_log_end = log->bios_event_log + len;
29448
29449 virt = acpi_os_map_memory(start, len);
29450 + if (!virt) {
29451 + kfree(log->bios_event_log);
29452 + log->bios_event_log = NULL;
29453 + return -EFAULT;
29454 + }
29455
29456 - memcpy(log->bios_event_log, virt, len);
29457 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29458
29459 acpi_os_unmap_memory(virt, len);
29460 return 0;
29461 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29462 index b58b561..c9088c8 100644
29463 --- a/drivers/char/virtio_console.c
29464 +++ b/drivers/char/virtio_console.c
29465 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29466 if (to_user) {
29467 ssize_t ret;
29468
29469 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29470 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29471 if (ret)
29472 return -EFAULT;
29473 } else {
29474 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29475 if (!port_has_data(port) && !port->host_connected)
29476 return 0;
29477
29478 - return fill_readbuf(port, ubuf, count, true);
29479 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29480 }
29481
29482 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29483 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29484 index c9eee6d..f9d5280 100644
29485 --- a/drivers/edac/amd64_edac.c
29486 +++ b/drivers/edac/amd64_edac.c
29487 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29488 * PCI core identifies what devices are on a system during boot, and then
29489 * inquiry this table to see if this driver is for a given device found.
29490 */
29491 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29492 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29493 {
29494 .vendor = PCI_VENDOR_ID_AMD,
29495 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29496 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29497 index e47e73b..348e0bd 100644
29498 --- a/drivers/edac/amd76x_edac.c
29499 +++ b/drivers/edac/amd76x_edac.c
29500 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29501 edac_mc_free(mci);
29502 }
29503
29504 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29505 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29506 {
29507 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29508 AMD762},
29509 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29510 index 1af531a..3a8ff27 100644
29511 --- a/drivers/edac/e752x_edac.c
29512 +++ b/drivers/edac/e752x_edac.c
29513 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29514 edac_mc_free(mci);
29515 }
29516
29517 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29518 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29519 {
29520 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29521 E7520},
29522 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29523 index 6ffb6d2..383d8d7 100644
29524 --- a/drivers/edac/e7xxx_edac.c
29525 +++ b/drivers/edac/e7xxx_edac.c
29526 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29527 edac_mc_free(mci);
29528 }
29529
29530 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29531 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29532 {
29533 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29534 E7205},
29535 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29536 index 97f5064..202b6e6 100644
29537 --- a/drivers/edac/edac_pci_sysfs.c
29538 +++ b/drivers/edac/edac_pci_sysfs.c
29539 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29540 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29541 static int edac_pci_poll_msec = 1000; /* one second workq period */
29542
29543 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29544 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29545 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29546 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29547
29548 static struct kobject *edac_pci_top_main_kobj;
29549 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29550 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29551 edac_printk(KERN_CRIT, EDAC_PCI,
29552 "Signaled System Error on %s\n",
29553 pci_name(dev));
29554 - atomic_inc(&pci_nonparity_count);
29555 + atomic_inc_unchecked(&pci_nonparity_count);
29556 }
29557
29558 if (status & (PCI_STATUS_PARITY)) {
29559 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29560 "Master Data Parity Error on %s\n",
29561 pci_name(dev));
29562
29563 - atomic_inc(&pci_parity_count);
29564 + atomic_inc_unchecked(&pci_parity_count);
29565 }
29566
29567 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29568 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29569 "Detected Parity Error on %s\n",
29570 pci_name(dev));
29571
29572 - atomic_inc(&pci_parity_count);
29573 + atomic_inc_unchecked(&pci_parity_count);
29574 }
29575 }
29576
29577 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29578 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29579 "Signaled System Error on %s\n",
29580 pci_name(dev));
29581 - atomic_inc(&pci_nonparity_count);
29582 + atomic_inc_unchecked(&pci_nonparity_count);
29583 }
29584
29585 if (status & (PCI_STATUS_PARITY)) {
29586 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29587 "Master Data Parity Error on "
29588 "%s\n", pci_name(dev));
29589
29590 - atomic_inc(&pci_parity_count);
29591 + atomic_inc_unchecked(&pci_parity_count);
29592 }
29593
29594 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29595 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29596 "Detected Parity Error on %s\n",
29597 pci_name(dev));
29598
29599 - atomic_inc(&pci_parity_count);
29600 + atomic_inc_unchecked(&pci_parity_count);
29601 }
29602 }
29603 }
29604 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29605 if (!check_pci_errors)
29606 return;
29607
29608 - before_count = atomic_read(&pci_parity_count);
29609 + before_count = atomic_read_unchecked(&pci_parity_count);
29610
29611 /* scan all PCI devices looking for a Parity Error on devices and
29612 * bridges.
29613 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29614 /* Only if operator has selected panic on PCI Error */
29615 if (edac_pci_get_panic_on_pe()) {
29616 /* If the count is different 'after' from 'before' */
29617 - if (before_count != atomic_read(&pci_parity_count))
29618 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29619 panic("EDAC: PCI Parity Error");
29620 }
29621 }
29622 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29623 index c0510b3..6e2a954 100644
29624 --- a/drivers/edac/i3000_edac.c
29625 +++ b/drivers/edac/i3000_edac.c
29626 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29627 edac_mc_free(mci);
29628 }
29629
29630 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29631 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29632 {
29633 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29634 I3000},
29635 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29636 index 73f55e200..5faaf59 100644
29637 --- a/drivers/edac/i3200_edac.c
29638 +++ b/drivers/edac/i3200_edac.c
29639 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29640 edac_mc_free(mci);
29641 }
29642
29643 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29644 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29645 {
29646 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29647 I3200},
29648 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29649 index 4dc3ac2..67d05a6 100644
29650 --- a/drivers/edac/i5000_edac.c
29651 +++ b/drivers/edac/i5000_edac.c
29652 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29653 *
29654 * The "E500P" device is the first device supported.
29655 */
29656 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29657 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29658 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29659 .driver_data = I5000P},
29660
29661 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29662 index bcbdeec..9886d16 100644
29663 --- a/drivers/edac/i5100_edac.c
29664 +++ b/drivers/edac/i5100_edac.c
29665 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29666 edac_mc_free(mci);
29667 }
29668
29669 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29670 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29671 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29672 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29673 { 0, }
29674 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29675 index 74d6ec34..baff517 100644
29676 --- a/drivers/edac/i5400_edac.c
29677 +++ b/drivers/edac/i5400_edac.c
29678 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29679 *
29680 * The "E500P" device is the first device supported.
29681 */
29682 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29683 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29684 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29685 {0,} /* 0 terminated list. */
29686 };
29687 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29688 index 6104dba..e7ea8e1 100644
29689 --- a/drivers/edac/i7300_edac.c
29690 +++ b/drivers/edac/i7300_edac.c
29691 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29692 *
29693 * Has only 8086:360c PCI ID
29694 */
29695 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29696 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29697 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29698 {0,} /* 0 terminated list. */
29699 };
29700 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29701 index 8568d9b..42b2fa8 100644
29702 --- a/drivers/edac/i7core_edac.c
29703 +++ b/drivers/edac/i7core_edac.c
29704 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29705 /*
29706 * pci_device_id table for which devices we are looking for
29707 */
29708 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29709 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29710 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29711 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29712 {0,} /* 0 terminated list. */
29713 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29714 index 4329d39..f3022ef 100644
29715 --- a/drivers/edac/i82443bxgx_edac.c
29716 +++ b/drivers/edac/i82443bxgx_edac.c
29717 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29718
29719 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29720
29721 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29722 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29723 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29724 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29725 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29726 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29727 index 931a057..fd28340 100644
29728 --- a/drivers/edac/i82860_edac.c
29729 +++ b/drivers/edac/i82860_edac.c
29730 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29731 edac_mc_free(mci);
29732 }
29733
29734 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29735 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29736 {
29737 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29738 I82860},
29739 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29740 index 33864c6..01edc61 100644
29741 --- a/drivers/edac/i82875p_edac.c
29742 +++ b/drivers/edac/i82875p_edac.c
29743 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29744 edac_mc_free(mci);
29745 }
29746
29747 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29748 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29749 {
29750 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29751 I82875P},
29752 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29753 index 4184e01..dcb2cd3 100644
29754 --- a/drivers/edac/i82975x_edac.c
29755 +++ b/drivers/edac/i82975x_edac.c
29756 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29757 edac_mc_free(mci);
29758 }
29759
29760 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29761 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29762 {
29763 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29764 I82975X
29765 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29766 index 0106747..0b40417 100644
29767 --- a/drivers/edac/mce_amd.h
29768 +++ b/drivers/edac/mce_amd.h
29769 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
29770 bool (*dc_mce)(u16, u8);
29771 bool (*ic_mce)(u16, u8);
29772 bool (*nb_mce)(u16, u8);
29773 -};
29774 +} __no_const;
29775
29776 void amd_report_gart_errors(bool);
29777 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29778 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29779 index e294e1b..a41b05b 100644
29780 --- a/drivers/edac/r82600_edac.c
29781 +++ b/drivers/edac/r82600_edac.c
29782 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29783 edac_mc_free(mci);
29784 }
29785
29786 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29787 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29788 {
29789 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29790 },
29791 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29792 index 1dc118d..8c68af9 100644
29793 --- a/drivers/edac/sb_edac.c
29794 +++ b/drivers/edac/sb_edac.c
29795 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29796 /*
29797 * pci_device_id table for which devices we are looking for
29798 */
29799 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29800 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29801 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29802 {0,} /* 0 terminated list. */
29803 };
29804 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29805 index b6f47de..c5acf3a 100644
29806 --- a/drivers/edac/x38_edac.c
29807 +++ b/drivers/edac/x38_edac.c
29808 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29809 edac_mc_free(mci);
29810 }
29811
29812 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29813 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29814 {
29815 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29816 X38},
29817 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29818 index 85661b0..c784559a 100644
29819 --- a/drivers/firewire/core-card.c
29820 +++ b/drivers/firewire/core-card.c
29821 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29822
29823 void fw_core_remove_card(struct fw_card *card)
29824 {
29825 - struct fw_card_driver dummy_driver = dummy_driver_template;
29826 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29827
29828 card->driver->update_phy_reg(card, 4,
29829 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29830 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29831 index 4799393..37bd3ab 100644
29832 --- a/drivers/firewire/core-cdev.c
29833 +++ b/drivers/firewire/core-cdev.c
29834 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29835 int ret;
29836
29837 if ((request->channels == 0 && request->bandwidth == 0) ||
29838 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29839 - request->bandwidth < 0)
29840 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29841 return -EINVAL;
29842
29843 r = kmalloc(sizeof(*r), GFP_KERNEL);
29844 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29845 index 855ab3f..11f4bbd 100644
29846 --- a/drivers/firewire/core-transaction.c
29847 +++ b/drivers/firewire/core-transaction.c
29848 @@ -37,6 +37,7 @@
29849 #include <linux/timer.h>
29850 #include <linux/types.h>
29851 #include <linux/workqueue.h>
29852 +#include <linux/sched.h>
29853
29854 #include <asm/byteorder.h>
29855
29856 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29857 index b45be57..5fad18b 100644
29858 --- a/drivers/firewire/core.h
29859 +++ b/drivers/firewire/core.h
29860 @@ -101,6 +101,7 @@ struct fw_card_driver {
29861
29862 int (*stop_iso)(struct fw_iso_context *ctx);
29863 };
29864 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29865
29866 void fw_card_initialize(struct fw_card *card,
29867 const struct fw_card_driver *driver, struct device *device);
29868 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29869 index 153980b..4b4d046 100644
29870 --- a/drivers/firmware/dmi_scan.c
29871 +++ b/drivers/firmware/dmi_scan.c
29872 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29873 }
29874 }
29875 else {
29876 - /*
29877 - * no iounmap() for that ioremap(); it would be a no-op, but
29878 - * it's so early in setup that sucker gets confused into doing
29879 - * what it shouldn't if we actually call it.
29880 - */
29881 p = dmi_ioremap(0xF0000, 0x10000);
29882 if (p == NULL)
29883 goto error;
29884 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29885 if (buf == NULL)
29886 return -1;
29887
29888 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29889 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29890
29891 iounmap(buf);
29892 return 0;
29893 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29894 index 82d5c20..44a7177 100644
29895 --- a/drivers/gpio/gpio-vr41xx.c
29896 +++ b/drivers/gpio/gpio-vr41xx.c
29897 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29898 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29899 maskl, pendl, maskh, pendh);
29900
29901 - atomic_inc(&irq_err_count);
29902 + atomic_inc_unchecked(&irq_err_count);
29903
29904 return -EINVAL;
29905 }
29906 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29907 index 84a4a80..ce0306e 100644
29908 --- a/drivers/gpu/drm/drm_crtc_helper.c
29909 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29910 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29911 struct drm_crtc *tmp;
29912 int crtc_mask = 1;
29913
29914 - WARN(!crtc, "checking null crtc?\n");
29915 + BUG_ON(!crtc);
29916
29917 dev = crtc->dev;
29918
29919 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29920 index ebf7d3f..d64c436 100644
29921 --- a/drivers/gpu/drm/drm_drv.c
29922 +++ b/drivers/gpu/drm/drm_drv.c
29923 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
29924 /**
29925 * Copy and IOCTL return string to user space
29926 */
29927 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29928 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29929 {
29930 int len;
29931
29932 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
29933
29934 dev = file_priv->minor->dev;
29935 atomic_inc(&dev->ioctl_count);
29936 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29937 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29938 ++file_priv->ioctl_count;
29939
29940 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29941 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29942 index 6263b01..7987f55 100644
29943 --- a/drivers/gpu/drm/drm_fops.c
29944 +++ b/drivers/gpu/drm/drm_fops.c
29945 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29946 }
29947
29948 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29949 - atomic_set(&dev->counts[i], 0);
29950 + atomic_set_unchecked(&dev->counts[i], 0);
29951
29952 dev->sigdata.lock = NULL;
29953
29954 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
29955
29956 retcode = drm_open_helper(inode, filp, dev);
29957 if (!retcode) {
29958 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29959 - if (!dev->open_count++)
29960 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29961 + if (local_inc_return(&dev->open_count) == 1)
29962 retcode = drm_setup(dev);
29963 }
29964 if (!retcode) {
29965 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
29966
29967 mutex_lock(&drm_global_mutex);
29968
29969 - DRM_DEBUG("open_count = %d\n", dev->open_count);
29970 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
29971
29972 if (dev->driver->preclose)
29973 dev->driver->preclose(dev, file_priv);
29974 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
29975 * Begin inline drm_release
29976 */
29977
29978 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29979 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
29980 task_pid_nr(current),
29981 (long)old_encode_dev(file_priv->minor->device),
29982 - dev->open_count);
29983 + local_read(&dev->open_count));
29984
29985 /* Release any auth tokens that might point to this file_priv,
29986 (do that under the drm_global_mutex) */
29987 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
29988 * End inline drm_release
29989 */
29990
29991 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
29992 - if (!--dev->open_count) {
29993 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
29994 + if (local_dec_and_test(&dev->open_count)) {
29995 if (atomic_read(&dev->ioctl_count)) {
29996 DRM_ERROR("Device busy: %d\n",
29997 atomic_read(&dev->ioctl_count));
29998 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
29999 index c87dc96..326055d 100644
30000 --- a/drivers/gpu/drm/drm_global.c
30001 +++ b/drivers/gpu/drm/drm_global.c
30002 @@ -36,7 +36,7 @@
30003 struct drm_global_item {
30004 struct mutex mutex;
30005 void *object;
30006 - int refcount;
30007 + atomic_t refcount;
30008 };
30009
30010 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30011 @@ -49,7 +49,7 @@ void drm_global_init(void)
30012 struct drm_global_item *item = &glob[i];
30013 mutex_init(&item->mutex);
30014 item->object = NULL;
30015 - item->refcount = 0;
30016 + atomic_set(&item->refcount, 0);
30017 }
30018 }
30019
30020 @@ -59,7 +59,7 @@ void drm_global_release(void)
30021 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30022 struct drm_global_item *item = &glob[i];
30023 BUG_ON(item->object != NULL);
30024 - BUG_ON(item->refcount != 0);
30025 + BUG_ON(atomic_read(&item->refcount) != 0);
30026 }
30027 }
30028
30029 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30030 void *object;
30031
30032 mutex_lock(&item->mutex);
30033 - if (item->refcount == 0) {
30034 + if (atomic_read(&item->refcount) == 0) {
30035 item->object = kzalloc(ref->size, GFP_KERNEL);
30036 if (unlikely(item->object == NULL)) {
30037 ret = -ENOMEM;
30038 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30039 goto out_err;
30040
30041 }
30042 - ++item->refcount;
30043 + atomic_inc(&item->refcount);
30044 ref->object = item->object;
30045 object = item->object;
30046 mutex_unlock(&item->mutex);
30047 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30048 struct drm_global_item *item = &glob[ref->global_type];
30049
30050 mutex_lock(&item->mutex);
30051 - BUG_ON(item->refcount == 0);
30052 + BUG_ON(atomic_read(&item->refcount) == 0);
30053 BUG_ON(ref->object != item->object);
30054 - if (--item->refcount == 0) {
30055 + if (atomic_dec_and_test(&item->refcount)) {
30056 ref->release(ref);
30057 item->object = NULL;
30058 }
30059 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30060 index ab1162d..42587b2 100644
30061 --- a/drivers/gpu/drm/drm_info.c
30062 +++ b/drivers/gpu/drm/drm_info.c
30063 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30064 struct drm_local_map *map;
30065 struct drm_map_list *r_list;
30066
30067 - /* Hardcoded from _DRM_FRAME_BUFFER,
30068 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30069 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30070 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30071 + static const char * const types[] = {
30072 + [_DRM_FRAME_BUFFER] = "FB",
30073 + [_DRM_REGISTERS] = "REG",
30074 + [_DRM_SHM] = "SHM",
30075 + [_DRM_AGP] = "AGP",
30076 + [_DRM_SCATTER_GATHER] = "SG",
30077 + [_DRM_CONSISTENT] = "PCI",
30078 + [_DRM_GEM] = "GEM" };
30079 const char *type;
30080 int i;
30081
30082 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30083 map = r_list->map;
30084 if (!map)
30085 continue;
30086 - if (map->type < 0 || map->type > 5)
30087 + if (map->type >= ARRAY_SIZE(types))
30088 type = "??";
30089 else
30090 type = types[map->type];
30091 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30092 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30093 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30094 vma->vm_flags & VM_IO ? 'i' : '-',
30095 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30096 + 0);
30097 +#else
30098 vma->vm_pgoff);
30099 +#endif
30100
30101 #if defined(__i386__)
30102 pgprot = pgprot_val(vma->vm_page_prot);
30103 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30104 index 637fcc3..e890b33 100644
30105 --- a/drivers/gpu/drm/drm_ioc32.c
30106 +++ b/drivers/gpu/drm/drm_ioc32.c
30107 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30108 request = compat_alloc_user_space(nbytes);
30109 if (!access_ok(VERIFY_WRITE, request, nbytes))
30110 return -EFAULT;
30111 - list = (struct drm_buf_desc *) (request + 1);
30112 + list = (struct drm_buf_desc __user *) (request + 1);
30113
30114 if (__put_user(count, &request->count)
30115 || __put_user(list, &request->list))
30116 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30117 request = compat_alloc_user_space(nbytes);
30118 if (!access_ok(VERIFY_WRITE, request, nbytes))
30119 return -EFAULT;
30120 - list = (struct drm_buf_pub *) (request + 1);
30121 + list = (struct drm_buf_pub __user *) (request + 1);
30122
30123 if (__put_user(count, &request->count)
30124 || __put_user(list, &request->list))
30125 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30126 index 956fd38..e52167a 100644
30127 --- a/drivers/gpu/drm/drm_ioctl.c
30128 +++ b/drivers/gpu/drm/drm_ioctl.c
30129 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30130 stats->data[i].value =
30131 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30132 else
30133 - stats->data[i].value = atomic_read(&dev->counts[i]);
30134 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30135 stats->data[i].type = dev->types[i];
30136 }
30137
30138 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30139 index c79c713..2048588 100644
30140 --- a/drivers/gpu/drm/drm_lock.c
30141 +++ b/drivers/gpu/drm/drm_lock.c
30142 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30143 if (drm_lock_take(&master->lock, lock->context)) {
30144 master->lock.file_priv = file_priv;
30145 master->lock.lock_time = jiffies;
30146 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30147 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30148 break; /* Got lock */
30149 }
30150
30151 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30152 return -EINVAL;
30153 }
30154
30155 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30156 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30157
30158 if (drm_lock_free(&master->lock, lock->context)) {
30159 /* FIXME: Should really bail out here. */
30160 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30161 index 7f4b4e1..bf4def2 100644
30162 --- a/drivers/gpu/drm/i810/i810_dma.c
30163 +++ b/drivers/gpu/drm/i810/i810_dma.c
30164 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30165 dma->buflist[vertex->idx],
30166 vertex->discard, vertex->used);
30167
30168 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30169 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30170 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30171 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30172 sarea_priv->last_enqueue = dev_priv->counter - 1;
30173 sarea_priv->last_dispatch = (int)hw_status[5];
30174
30175 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30176 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30177 mc->last_render);
30178
30179 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30180 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30181 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30182 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30183 sarea_priv->last_enqueue = dev_priv->counter - 1;
30184 sarea_priv->last_dispatch = (int)hw_status[5];
30185
30186 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30187 index c9339f4..f5e1b9d 100644
30188 --- a/drivers/gpu/drm/i810/i810_drv.h
30189 +++ b/drivers/gpu/drm/i810/i810_drv.h
30190 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30191 int page_flipping;
30192
30193 wait_queue_head_t irq_queue;
30194 - atomic_t irq_received;
30195 - atomic_t irq_emitted;
30196 + atomic_unchecked_t irq_received;
30197 + atomic_unchecked_t irq_emitted;
30198
30199 int front_offset;
30200 } drm_i810_private_t;
30201 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30202 index deaa657..e0fd296 100644
30203 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30204 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30205 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30206 I915_READ(GTIMR));
30207 }
30208 seq_printf(m, "Interrupts received: %d\n",
30209 - atomic_read(&dev_priv->irq_received));
30210 + atomic_read_unchecked(&dev_priv->irq_received));
30211 for (i = 0; i < I915_NUM_RINGS; i++) {
30212 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30213 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30214 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30215 return ret;
30216
30217 if (opregion->header)
30218 - seq_write(m, opregion->header, OPREGION_SIZE);
30219 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30220
30221 mutex_unlock(&dev->struct_mutex);
30222
30223 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30224 index ddfe3d9..f6e6b21 100644
30225 --- a/drivers/gpu/drm/i915/i915_dma.c
30226 +++ b/drivers/gpu/drm/i915/i915_dma.c
30227 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30228 bool can_switch;
30229
30230 spin_lock(&dev->count_lock);
30231 - can_switch = (dev->open_count == 0);
30232 + can_switch = (local_read(&dev->open_count) == 0);
30233 spin_unlock(&dev->count_lock);
30234 return can_switch;
30235 }
30236 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30237 index 9689ca3..294f9c1 100644
30238 --- a/drivers/gpu/drm/i915/i915_drv.h
30239 +++ b/drivers/gpu/drm/i915/i915_drv.h
30240 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30241 /* render clock increase/decrease */
30242 /* display clock increase/decrease */
30243 /* pll clock increase/decrease */
30244 -};
30245 +} __no_const;
30246
30247 struct intel_device_info {
30248 u8 gen;
30249 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30250 int current_page;
30251 int page_flipping;
30252
30253 - atomic_t irq_received;
30254 + atomic_unchecked_t irq_received;
30255
30256 /* protects the irq masks */
30257 spinlock_t irq_lock;
30258 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30259 * will be page flipped away on the next vblank. When it
30260 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30261 */
30262 - atomic_t pending_flip;
30263 + atomic_unchecked_t pending_flip;
30264 };
30265
30266 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30267 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30268 extern void intel_teardown_gmbus(struct drm_device *dev);
30269 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30270 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30271 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30272 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30273 {
30274 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30275 }
30276 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30277 index 65e1f00..a30ef00 100644
30278 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30279 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30280 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30281 i915_gem_clflush_object(obj);
30282
30283 if (obj->base.pending_write_domain)
30284 - cd->flips |= atomic_read(&obj->pending_flip);
30285 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30286
30287 /* The actual obj->write_domain will be updated with
30288 * pending_write_domain after we emit the accumulated flush for all
30289 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30290
30291 static int
30292 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30293 - int count)
30294 + unsigned int count)
30295 {
30296 - int i;
30297 + unsigned int i;
30298
30299 for (i = 0; i < count; i++) {
30300 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30301 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30302 index 5bd4361..0241a42 100644
30303 --- a/drivers/gpu/drm/i915/i915_irq.c
30304 +++ b/drivers/gpu/drm/i915/i915_irq.c
30305 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30306 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30307 struct drm_i915_master_private *master_priv;
30308
30309 - atomic_inc(&dev_priv->irq_received);
30310 + atomic_inc_unchecked(&dev_priv->irq_received);
30311
30312 /* disable master interrupt before clearing iir */
30313 de_ier = I915_READ(DEIER);
30314 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30315 struct drm_i915_master_private *master_priv;
30316 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30317
30318 - atomic_inc(&dev_priv->irq_received);
30319 + atomic_inc_unchecked(&dev_priv->irq_received);
30320
30321 if (IS_GEN6(dev))
30322 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30323 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30324 int ret = IRQ_NONE, pipe;
30325 bool blc_event = false;
30326
30327 - atomic_inc(&dev_priv->irq_received);
30328 + atomic_inc_unchecked(&dev_priv->irq_received);
30329
30330 iir = I915_READ(IIR);
30331
30332 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30333 {
30334 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30335
30336 - atomic_set(&dev_priv->irq_received, 0);
30337 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30338
30339 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30340 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30341 @@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30342 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30343 int pipe;
30344
30345 - atomic_set(&dev_priv->irq_received, 0);
30346 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30347
30348 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30349 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30350 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30351 index 2163818..e536c3d 100644
30352 --- a/drivers/gpu/drm/i915/intel_display.c
30353 +++ b/drivers/gpu/drm/i915/intel_display.c
30354 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30355
30356 wait_event(dev_priv->pending_flip_queue,
30357 atomic_read(&dev_priv->mm.wedged) ||
30358 - atomic_read(&obj->pending_flip) == 0);
30359 + atomic_read_unchecked(&obj->pending_flip) == 0);
30360
30361 /* Big Hammer, we also need to ensure that any pending
30362 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30363 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30364 obj = to_intel_framebuffer(crtc->fb)->obj;
30365 dev_priv = crtc->dev->dev_private;
30366 wait_event(dev_priv->pending_flip_queue,
30367 - atomic_read(&obj->pending_flip) == 0);
30368 + atomic_read_unchecked(&obj->pending_flip) == 0);
30369 }
30370
30371 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30372 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30373
30374 atomic_clear_mask(1 << intel_crtc->plane,
30375 &obj->pending_flip.counter);
30376 - if (atomic_read(&obj->pending_flip) == 0)
30377 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30378 wake_up(&dev_priv->pending_flip_queue);
30379
30380 schedule_work(&work->work);
30381 @@ -7461,7 +7461,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30382 /* Block clients from rendering to the new back buffer until
30383 * the flip occurs and the object is no longer visible.
30384 */
30385 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30386 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30387
30388 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30389 if (ret)
30390 @@ -7475,7 +7475,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30391 return 0;
30392
30393 cleanup_pending:
30394 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30395 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30396 drm_gem_object_unreference(&work->old_fb_obj->base);
30397 drm_gem_object_unreference(&obj->base);
30398 mutex_unlock(&dev->struct_mutex);
30399 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30400 index 54558a0..2d97005 100644
30401 --- a/drivers/gpu/drm/mga/mga_drv.h
30402 +++ b/drivers/gpu/drm/mga/mga_drv.h
30403 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30404 u32 clear_cmd;
30405 u32 maccess;
30406
30407 - atomic_t vbl_received; /**< Number of vblanks received. */
30408 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30409 wait_queue_head_t fence_queue;
30410 - atomic_t last_fence_retired;
30411 + atomic_unchecked_t last_fence_retired;
30412 u32 next_fence_to_post;
30413
30414 unsigned int fb_cpp;
30415 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30416 index 2581202..f230a8d9 100644
30417 --- a/drivers/gpu/drm/mga/mga_irq.c
30418 +++ b/drivers/gpu/drm/mga/mga_irq.c
30419 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30420 if (crtc != 0)
30421 return 0;
30422
30423 - return atomic_read(&dev_priv->vbl_received);
30424 + return atomic_read_unchecked(&dev_priv->vbl_received);
30425 }
30426
30427
30428 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30429 /* VBLANK interrupt */
30430 if (status & MGA_VLINEPEN) {
30431 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30432 - atomic_inc(&dev_priv->vbl_received);
30433 + atomic_inc_unchecked(&dev_priv->vbl_received);
30434 drm_handle_vblank(dev, 0);
30435 handled = 1;
30436 }
30437 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30438 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30439 MGA_WRITE(MGA_PRIMEND, prim_end);
30440
30441 - atomic_inc(&dev_priv->last_fence_retired);
30442 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30443 DRM_WAKEUP(&dev_priv->fence_queue);
30444 handled = 1;
30445 }
30446 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30447 * using fences.
30448 */
30449 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30450 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30451 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30452 - *sequence) <= (1 << 23)));
30453
30454 *sequence = cur_fence;
30455 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30456 index e5cbead..6c354a3 100644
30457 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30458 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30459 @@ -199,7 +199,7 @@ struct methods {
30460 const char desc[8];
30461 void (*loadbios)(struct drm_device *, uint8_t *);
30462 const bool rw;
30463 -};
30464 +} __do_const;
30465
30466 static struct methods shadow_methods[] = {
30467 { "PRAMIN", load_vbios_pramin, true },
30468 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30469 struct bit_table {
30470 const char id;
30471 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30472 -};
30473 +} __no_const;
30474
30475 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30476
30477 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30478 index b827098..c31a797 100644
30479 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30480 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30481 @@ -242,7 +242,7 @@ struct nouveau_channel {
30482 struct list_head pending;
30483 uint32_t sequence;
30484 uint32_t sequence_ack;
30485 - atomic_t last_sequence_irq;
30486 + atomic_unchecked_t last_sequence_irq;
30487 struct nouveau_vma vma;
30488 } fence;
30489
30490 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30491 u32 handle, u16 class);
30492 void (*set_tile_region)(struct drm_device *dev, int i);
30493 void (*tlb_flush)(struct drm_device *, int engine);
30494 -};
30495 +} __no_const;
30496
30497 struct nouveau_instmem_engine {
30498 void *priv;
30499 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30500 struct nouveau_mc_engine {
30501 int (*init)(struct drm_device *dev);
30502 void (*takedown)(struct drm_device *dev);
30503 -};
30504 +} __no_const;
30505
30506 struct nouveau_timer_engine {
30507 int (*init)(struct drm_device *dev);
30508 void (*takedown)(struct drm_device *dev);
30509 uint64_t (*read)(struct drm_device *dev);
30510 -};
30511 +} __no_const;
30512
30513 struct nouveau_fb_engine {
30514 int num_tiles;
30515 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30516 void (*put)(struct drm_device *, struct nouveau_mem **);
30517
30518 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30519 -};
30520 +} __no_const;
30521
30522 struct nouveau_engine {
30523 struct nouveau_instmem_engine instmem;
30524 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
30525 struct drm_global_reference mem_global_ref;
30526 struct ttm_bo_global_ref bo_global_ref;
30527 struct ttm_bo_device bdev;
30528 - atomic_t validate_sequence;
30529 + atomic_unchecked_t validate_sequence;
30530 } ttm;
30531
30532 struct {
30533 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30534 index 2f6daae..c9d7b9e 100644
30535 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30536 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30537 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30538 if (USE_REFCNT(dev))
30539 sequence = nvchan_rd32(chan, 0x48);
30540 else
30541 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30542 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30543
30544 if (chan->fence.sequence_ack == sequence)
30545 goto out;
30546 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30547 return ret;
30548 }
30549
30550 - atomic_set(&chan->fence.last_sequence_irq, 0);
30551 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30552 return 0;
30553 }
30554
30555 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30556 index 7ce3fde..cb3ea04 100644
30557 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30558 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30559 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30560 int trycnt = 0;
30561 int ret, i;
30562
30563 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30564 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30565 retry:
30566 if (++trycnt > 100000) {
30567 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30568 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30569 index f80c5e0..936baa7 100644
30570 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30571 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30572 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30573 bool can_switch;
30574
30575 spin_lock(&dev->count_lock);
30576 - can_switch = (dev->open_count == 0);
30577 + can_switch = (local_read(&dev->open_count) == 0);
30578 spin_unlock(&dev->count_lock);
30579 return can_switch;
30580 }
30581 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30582 index dbdea8e..cd6eeeb 100644
30583 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30584 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30585 @@ -554,7 +554,7 @@ static int
30586 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30587 u32 class, u32 mthd, u32 data)
30588 {
30589 - atomic_set(&chan->fence.last_sequence_irq, data);
30590 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30591 return 0;
30592 }
30593
30594 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30595 index bcac90b..53bfc76 100644
30596 --- a/drivers/gpu/drm/r128/r128_cce.c
30597 +++ b/drivers/gpu/drm/r128/r128_cce.c
30598 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30599
30600 /* GH: Simple idle check.
30601 */
30602 - atomic_set(&dev_priv->idle_count, 0);
30603 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30604
30605 /* We don't support anything other than bus-mastering ring mode,
30606 * but the ring can be in either AGP or PCI space for the ring
30607 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30608 index 930c71b..499aded 100644
30609 --- a/drivers/gpu/drm/r128/r128_drv.h
30610 +++ b/drivers/gpu/drm/r128/r128_drv.h
30611 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30612 int is_pci;
30613 unsigned long cce_buffers_offset;
30614
30615 - atomic_t idle_count;
30616 + atomic_unchecked_t idle_count;
30617
30618 int page_flipping;
30619 int current_page;
30620 u32 crtc_offset;
30621 u32 crtc_offset_cntl;
30622
30623 - atomic_t vbl_received;
30624 + atomic_unchecked_t vbl_received;
30625
30626 u32 color_fmt;
30627 unsigned int front_offset;
30628 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30629 index 429d5a0..7e899ed 100644
30630 --- a/drivers/gpu/drm/r128/r128_irq.c
30631 +++ b/drivers/gpu/drm/r128/r128_irq.c
30632 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30633 if (crtc != 0)
30634 return 0;
30635
30636 - return atomic_read(&dev_priv->vbl_received);
30637 + return atomic_read_unchecked(&dev_priv->vbl_received);
30638 }
30639
30640 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30641 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30642 /* VBLANK interrupt */
30643 if (status & R128_CRTC_VBLANK_INT) {
30644 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30645 - atomic_inc(&dev_priv->vbl_received);
30646 + atomic_inc_unchecked(&dev_priv->vbl_received);
30647 drm_handle_vblank(dev, 0);
30648 return IRQ_HANDLED;
30649 }
30650 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30651 index a9e33ce..09edd4b 100644
30652 --- a/drivers/gpu/drm/r128/r128_state.c
30653 +++ b/drivers/gpu/drm/r128/r128_state.c
30654 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30655
30656 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30657 {
30658 - if (atomic_read(&dev_priv->idle_count) == 0)
30659 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30660 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30661 else
30662 - atomic_set(&dev_priv->idle_count, 0);
30663 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30664 }
30665
30666 #endif
30667 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30668 index 5a82b6b..9e69c73 100644
30669 --- a/drivers/gpu/drm/radeon/mkregtable.c
30670 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30671 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30672 regex_t mask_rex;
30673 regmatch_t match[4];
30674 char buf[1024];
30675 - size_t end;
30676 + long end;
30677 int len;
30678 int done = 0;
30679 int r;
30680 unsigned o;
30681 struct offset *offset;
30682 char last_reg_s[10];
30683 - int last_reg;
30684 + unsigned long last_reg;
30685
30686 if (regcomp
30687 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30688 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30689 index 1668ec1..30ebdab 100644
30690 --- a/drivers/gpu/drm/radeon/radeon.h
30691 +++ b/drivers/gpu/drm/radeon/radeon.h
30692 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
30693 uint32_t scratch_reg;
30694 uint64_t gpu_addr;
30695 volatile uint32_t *cpu_addr;
30696 - atomic_t seq;
30697 + atomic_unchecked_t seq;
30698 uint32_t last_seq;
30699 unsigned long last_jiffies;
30700 unsigned long last_timeout;
30701 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
30702 int x2, int y2);
30703 void (*draw_auto)(struct radeon_device *rdev);
30704 void (*set_default_state)(struct radeon_device *rdev);
30705 -};
30706 +} __no_const;
30707
30708 struct r600_blit {
30709 struct mutex mutex;
30710 @@ -1201,7 +1201,7 @@ struct radeon_asic {
30711 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30712 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30713 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30714 -};
30715 +} __no_const;
30716
30717 /*
30718 * Asic structures
30719 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30720 index 49f7cb7..2fcb48f 100644
30721 --- a/drivers/gpu/drm/radeon/radeon_device.c
30722 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30723 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30724 bool can_switch;
30725
30726 spin_lock(&dev->count_lock);
30727 - can_switch = (dev->open_count == 0);
30728 + can_switch = (local_read(&dev->open_count) == 0);
30729 spin_unlock(&dev->count_lock);
30730 return can_switch;
30731 }
30732 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30733 index a1b59ca..86f2d44 100644
30734 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30735 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30736 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30737
30738 /* SW interrupt */
30739 wait_queue_head_t swi_queue;
30740 - atomic_t swi_emitted;
30741 + atomic_unchecked_t swi_emitted;
30742 int vblank_crtc;
30743 uint32_t irq_enable_reg;
30744 uint32_t r500_disp_irq_reg;
30745 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30746 index 4bd36a3..e66fe9c 100644
30747 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30748 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30749 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30750 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30751 return 0;
30752 }
30753 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30754 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30755 if (!rdev->ring[fence->ring].ready)
30756 /* FIXME: cp is not running assume everythings is done right
30757 * away
30758 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30759 }
30760 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30761 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30762 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30763 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30764 rdev->fence_drv[ring].initialized = true;
30765 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30766 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30767 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30768 rdev->fence_drv[ring].scratch_reg = -1;
30769 rdev->fence_drv[ring].cpu_addr = NULL;
30770 rdev->fence_drv[ring].gpu_addr = 0;
30771 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30772 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30773 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30774 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30775 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30776 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30777 index 48b7cea..342236f 100644
30778 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30779 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30780 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30781 request = compat_alloc_user_space(sizeof(*request));
30782 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30783 || __put_user(req32.param, &request->param)
30784 - || __put_user((void __user *)(unsigned long)req32.value,
30785 + || __put_user((unsigned long)req32.value,
30786 &request->value))
30787 return -EFAULT;
30788
30789 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30790 index 00da384..32f972d 100644
30791 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30792 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30793 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30794 unsigned int ret;
30795 RING_LOCALS;
30796
30797 - atomic_inc(&dev_priv->swi_emitted);
30798 - ret = atomic_read(&dev_priv->swi_emitted);
30799 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30800 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30801
30802 BEGIN_RING(4);
30803 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30804 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30805 drm_radeon_private_t *dev_priv =
30806 (drm_radeon_private_t *) dev->dev_private;
30807
30808 - atomic_set(&dev_priv->swi_emitted, 0);
30809 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30810 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30811
30812 dev->max_vblank_count = 0x001fffff;
30813 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30814 index e8422ae..d22d4a8 100644
30815 --- a/drivers/gpu/drm/radeon/radeon_state.c
30816 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30817 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30818 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30819 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30820
30821 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30822 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30823 sarea_priv->nbox * sizeof(depth_boxes[0])))
30824 return -EFAULT;
30825
30826 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30827 {
30828 drm_radeon_private_t *dev_priv = dev->dev_private;
30829 drm_radeon_getparam_t *param = data;
30830 - int value;
30831 + int value = 0;
30832
30833 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30834
30835 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30836 index c421e77..e6bf2e8 100644
30837 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30838 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30839 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30840 }
30841 if (unlikely(ttm_vm_ops == NULL)) {
30842 ttm_vm_ops = vma->vm_ops;
30843 - radeon_ttm_vm_ops = *ttm_vm_ops;
30844 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30845 + pax_open_kernel();
30846 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30847 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30848 + pax_close_kernel();
30849 }
30850 vma->vm_ops = &radeon_ttm_vm_ops;
30851 return 0;
30852 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30853 index f68dff2..8df955c 100644
30854 --- a/drivers/gpu/drm/radeon/rs690.c
30855 +++ b/drivers/gpu/drm/radeon/rs690.c
30856 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30857 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30858 rdev->pm.sideport_bandwidth.full)
30859 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30860 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30861 + read_delay_latency.full = dfixed_const(800 * 1000);
30862 read_delay_latency.full = dfixed_div(read_delay_latency,
30863 rdev->pm.igp_sideport_mclk);
30864 + a.full = dfixed_const(370);
30865 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30866 } else {
30867 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30868 rdev->pm.k8_bandwidth.full)
30869 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30870 index 499debd..66fce72 100644
30871 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30872 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30873 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30874 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30875 struct shrink_control *sc)
30876 {
30877 - static atomic_t start_pool = ATOMIC_INIT(0);
30878 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30879 unsigned i;
30880 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30881 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30882 struct ttm_page_pool *pool;
30883 int shrink_pages = sc->nr_to_scan;
30884
30885 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30886 index 88edacc..1e5412b 100644
30887 --- a/drivers/gpu/drm/via/via_drv.h
30888 +++ b/drivers/gpu/drm/via/via_drv.h
30889 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30890 typedef uint32_t maskarray_t[5];
30891
30892 typedef struct drm_via_irq {
30893 - atomic_t irq_received;
30894 + atomic_unchecked_t irq_received;
30895 uint32_t pending_mask;
30896 uint32_t enable_mask;
30897 wait_queue_head_t irq_queue;
30898 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30899 struct timeval last_vblank;
30900 int last_vblank_valid;
30901 unsigned usec_per_vblank;
30902 - atomic_t vbl_received;
30903 + atomic_unchecked_t vbl_received;
30904 drm_via_state_t hc_state;
30905 char pci_buf[VIA_PCI_BUF_SIZE];
30906 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30907 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30908 index d391f48..10c8ca3 100644
30909 --- a/drivers/gpu/drm/via/via_irq.c
30910 +++ b/drivers/gpu/drm/via/via_irq.c
30911 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30912 if (crtc != 0)
30913 return 0;
30914
30915 - return atomic_read(&dev_priv->vbl_received);
30916 + return atomic_read_unchecked(&dev_priv->vbl_received);
30917 }
30918
30919 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30920 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30921
30922 status = VIA_READ(VIA_REG_INTERRUPT);
30923 if (status & VIA_IRQ_VBLANK_PENDING) {
30924 - atomic_inc(&dev_priv->vbl_received);
30925 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30926 + atomic_inc_unchecked(&dev_priv->vbl_received);
30927 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30928 do_gettimeofday(&cur_vblank);
30929 if (dev_priv->last_vblank_valid) {
30930 dev_priv->usec_per_vblank =
30931 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30932 dev_priv->last_vblank = cur_vblank;
30933 dev_priv->last_vblank_valid = 1;
30934 }
30935 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30936 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30937 DRM_DEBUG("US per vblank is: %u\n",
30938 dev_priv->usec_per_vblank);
30939 }
30940 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30941
30942 for (i = 0; i < dev_priv->num_irqs; ++i) {
30943 if (status & cur_irq->pending_mask) {
30944 - atomic_inc(&cur_irq->irq_received);
30945 + atomic_inc_unchecked(&cur_irq->irq_received);
30946 DRM_WAKEUP(&cur_irq->irq_queue);
30947 handled = 1;
30948 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
30949 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
30950 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30951 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30952 masks[irq][4]));
30953 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30954 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30955 } else {
30956 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30957 (((cur_irq_sequence =
30958 - atomic_read(&cur_irq->irq_received)) -
30959 + atomic_read_unchecked(&cur_irq->irq_received)) -
30960 *sequence) <= (1 << 23)));
30961 }
30962 *sequence = cur_irq_sequence;
30963 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
30964 }
30965
30966 for (i = 0; i < dev_priv->num_irqs; ++i) {
30967 - atomic_set(&cur_irq->irq_received, 0);
30968 + atomic_set_unchecked(&cur_irq->irq_received, 0);
30969 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30970 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30971 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30972 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
30973 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30974 case VIA_IRQ_RELATIVE:
30975 irqwait->request.sequence +=
30976 - atomic_read(&cur_irq->irq_received);
30977 + atomic_read_unchecked(&cur_irq->irq_received);
30978 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30979 case VIA_IRQ_ABSOLUTE:
30980 break;
30981 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30982 index dc27970..f18b008 100644
30983 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30984 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30985 @@ -260,7 +260,7 @@ struct vmw_private {
30986 * Fencing and IRQs.
30987 */
30988
30989 - atomic_t marker_seq;
30990 + atomic_unchecked_t marker_seq;
30991 wait_queue_head_t fence_queue;
30992 wait_queue_head_t fifo_queue;
30993 int fence_queue_waiters; /* Protected by hw_mutex */
30994 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30995 index a0c2f12..68ae6cb 100644
30996 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30997 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30998 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
30999 (unsigned int) min,
31000 (unsigned int) fifo->capabilities);
31001
31002 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31003 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31004 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31005 vmw_marker_queue_init(&fifo->marker_queue);
31006 return vmw_fifo_send_fence(dev_priv, &dummy);
31007 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31008 if (reserveable)
31009 iowrite32(bytes, fifo_mem +
31010 SVGA_FIFO_RESERVED);
31011 - return fifo_mem + (next_cmd >> 2);
31012 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31013 } else {
31014 need_bounce = true;
31015 }
31016 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31017
31018 fm = vmw_fifo_reserve(dev_priv, bytes);
31019 if (unlikely(fm == NULL)) {
31020 - *seqno = atomic_read(&dev_priv->marker_seq);
31021 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31022 ret = -ENOMEM;
31023 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31024 false, 3*HZ);
31025 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31026 }
31027
31028 do {
31029 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31030 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31031 } while (*seqno == 0);
31032
31033 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31034 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31035 index cabc95f..14b3d77 100644
31036 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31037 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31038 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31039 * emitted. Then the fence is stale and signaled.
31040 */
31041
31042 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31043 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31044 > VMW_FENCE_WRAP);
31045
31046 return ret;
31047 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31048
31049 if (fifo_idle)
31050 down_read(&fifo_state->rwsem);
31051 - signal_seq = atomic_read(&dev_priv->marker_seq);
31052 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31053 ret = 0;
31054
31055 for (;;) {
31056 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31057 index 8a8725c..afed796 100644
31058 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31059 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31060 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31061 while (!vmw_lag_lt(queue, us)) {
31062 spin_lock(&queue->lock);
31063 if (list_empty(&queue->head))
31064 - seqno = atomic_read(&dev_priv->marker_seq);
31065 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31066 else {
31067 marker = list_first_entry(&queue->head,
31068 struct vmw_marker, head);
31069 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31070 index 75dbe34..f9204a8 100644
31071 --- a/drivers/hid/hid-core.c
31072 +++ b/drivers/hid/hid-core.c
31073 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31074
31075 int hid_add_device(struct hid_device *hdev)
31076 {
31077 - static atomic_t id = ATOMIC_INIT(0);
31078 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31079 int ret;
31080
31081 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31082 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31083 /* XXX hack, any other cleaner solution after the driver core
31084 * is converted to allow more than 20 bytes as the device name? */
31085 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31086 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31087 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31088
31089 hid_debug_register(hdev, dev_name(&hdev->dev));
31090 ret = device_add(&hdev->dev);
31091 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31092 index b1ec0e2..c295a61 100644
31093 --- a/drivers/hid/usbhid/hiddev.c
31094 +++ b/drivers/hid/usbhid/hiddev.c
31095 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31096 break;
31097
31098 case HIDIOCAPPLICATION:
31099 - if (arg < 0 || arg >= hid->maxapplication)
31100 + if (arg >= hid->maxapplication)
31101 break;
31102
31103 for (i = 0; i < hid->maxcollection; i++)
31104 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31105 index 4065374..10ed7dc 100644
31106 --- a/drivers/hv/channel.c
31107 +++ b/drivers/hv/channel.c
31108 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31109 int ret = 0;
31110 int t;
31111
31112 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31113 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31114 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31115 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31116
31117 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31118 if (ret)
31119 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31120 index 12aa97f..c0679f7 100644
31121 --- a/drivers/hv/hv.c
31122 +++ b/drivers/hv/hv.c
31123 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31124 u64 output_address = (output) ? virt_to_phys(output) : 0;
31125 u32 output_address_hi = output_address >> 32;
31126 u32 output_address_lo = output_address & 0xFFFFFFFF;
31127 - void *hypercall_page = hv_context.hypercall_page;
31128 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31129
31130 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31131 "=a"(hv_status_lo) : "d" (control_hi),
31132 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31133 index 6d7d286..92b0873 100644
31134 --- a/drivers/hv/hyperv_vmbus.h
31135 +++ b/drivers/hv/hyperv_vmbus.h
31136 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31137 struct vmbus_connection {
31138 enum vmbus_connect_state conn_state;
31139
31140 - atomic_t next_gpadl_handle;
31141 + atomic_unchecked_t next_gpadl_handle;
31142
31143 /*
31144 * Represents channel interrupts. Each bit position represents a
31145 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31146 index a220e57..428f54d 100644
31147 --- a/drivers/hv/vmbus_drv.c
31148 +++ b/drivers/hv/vmbus_drv.c
31149 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31150 {
31151 int ret = 0;
31152
31153 - static atomic_t device_num = ATOMIC_INIT(0);
31154 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31155
31156 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31157 - atomic_inc_return(&device_num));
31158 + atomic_inc_return_unchecked(&device_num));
31159
31160 child_device_obj->device.bus = &hv_bus;
31161 child_device_obj->device.parent = &hv_acpi_dev->dev;
31162 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31163 index 554f046..f8b4729 100644
31164 --- a/drivers/hwmon/acpi_power_meter.c
31165 +++ b/drivers/hwmon/acpi_power_meter.c
31166 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31167 return res;
31168
31169 temp /= 1000;
31170 - if (temp < 0)
31171 - return -EINVAL;
31172
31173 mutex_lock(&resource->lock);
31174 resource->trip[attr->index - 7] = temp;
31175 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31176 index 91fdd1f..b66a686 100644
31177 --- a/drivers/hwmon/sht15.c
31178 +++ b/drivers/hwmon/sht15.c
31179 @@ -166,7 +166,7 @@ struct sht15_data {
31180 int supply_uV;
31181 bool supply_uV_valid;
31182 struct work_struct update_supply_work;
31183 - atomic_t interrupt_handled;
31184 + atomic_unchecked_t interrupt_handled;
31185 };
31186
31187 /**
31188 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31189 return ret;
31190
31191 gpio_direction_input(data->pdata->gpio_data);
31192 - atomic_set(&data->interrupt_handled, 0);
31193 + atomic_set_unchecked(&data->interrupt_handled, 0);
31194
31195 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31196 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31197 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31198 /* Only relevant if the interrupt hasn't occurred. */
31199 - if (!atomic_read(&data->interrupt_handled))
31200 + if (!atomic_read_unchecked(&data->interrupt_handled))
31201 schedule_work(&data->read_work);
31202 }
31203 ret = wait_event_timeout(data->wait_queue,
31204 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31205
31206 /* First disable the interrupt */
31207 disable_irq_nosync(irq);
31208 - atomic_inc(&data->interrupt_handled);
31209 + atomic_inc_unchecked(&data->interrupt_handled);
31210 /* Then schedule a reading work struct */
31211 if (data->state != SHT15_READING_NOTHING)
31212 schedule_work(&data->read_work);
31213 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31214 * If not, then start the interrupt again - care here as could
31215 * have gone low in meantime so verify it hasn't!
31216 */
31217 - atomic_set(&data->interrupt_handled, 0);
31218 + atomic_set_unchecked(&data->interrupt_handled, 0);
31219 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31220 /* If still not occurred or another handler has been scheduled */
31221 if (gpio_get_value(data->pdata->gpio_data)
31222 - || atomic_read(&data->interrupt_handled))
31223 + || atomic_read_unchecked(&data->interrupt_handled))
31224 return;
31225 }
31226
31227 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31228 index 378fcb5..5e91fa8 100644
31229 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31230 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31231 @@ -43,7 +43,7 @@
31232 extern struct i2c_adapter amd756_smbus;
31233
31234 static struct i2c_adapter *s4882_adapter;
31235 -static struct i2c_algorithm *s4882_algo;
31236 +static i2c_algorithm_no_const *s4882_algo;
31237
31238 /* Wrapper access functions for multiplexed SMBus */
31239 static DEFINE_MUTEX(amd756_lock);
31240 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31241 index 29015eb..af2d8e9 100644
31242 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31243 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31244 @@ -41,7 +41,7 @@
31245 extern struct i2c_adapter *nforce2_smbus;
31246
31247 static struct i2c_adapter *s4985_adapter;
31248 -static struct i2c_algorithm *s4985_algo;
31249 +static i2c_algorithm_no_const *s4985_algo;
31250
31251 /* Wrapper access functions for multiplexed SMBus */
31252 static DEFINE_MUTEX(nforce2_lock);
31253 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31254 index d7a4833..7fae376 100644
31255 --- a/drivers/i2c/i2c-mux.c
31256 +++ b/drivers/i2c/i2c-mux.c
31257 @@ -28,7 +28,7 @@
31258 /* multiplexer per channel data */
31259 struct i2c_mux_priv {
31260 struct i2c_adapter adap;
31261 - struct i2c_algorithm algo;
31262 + i2c_algorithm_no_const algo;
31263
31264 struct i2c_adapter *parent;
31265 void *mux_dev; /* the mux chip/device */
31266 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31267 index 57d00ca..0145194 100644
31268 --- a/drivers/ide/aec62xx.c
31269 +++ b/drivers/ide/aec62xx.c
31270 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31271 .cable_detect = atp86x_cable_detect,
31272 };
31273
31274 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31275 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31276 { /* 0: AEC6210 */
31277 .name = DRV_NAME,
31278 .init_chipset = init_chipset_aec62xx,
31279 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31280 index 2c8016a..911a27c 100644
31281 --- a/drivers/ide/alim15x3.c
31282 +++ b/drivers/ide/alim15x3.c
31283 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31284 .dma_sff_read_status = ide_dma_sff_read_status,
31285 };
31286
31287 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31288 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31289 .name = DRV_NAME,
31290 .init_chipset = init_chipset_ali15x3,
31291 .init_hwif = init_hwif_ali15x3,
31292 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31293 index 3747b25..56fc995 100644
31294 --- a/drivers/ide/amd74xx.c
31295 +++ b/drivers/ide/amd74xx.c
31296 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31297 .udma_mask = udma, \
31298 }
31299
31300 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31301 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31302 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31303 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31304 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31305 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31306 index 15f0ead..cb43480 100644
31307 --- a/drivers/ide/atiixp.c
31308 +++ b/drivers/ide/atiixp.c
31309 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31310 .cable_detect = atiixp_cable_detect,
31311 };
31312
31313 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31314 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31315 { /* 0: IXP200/300/400/700 */
31316 .name = DRV_NAME,
31317 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31318 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31319 index 5f80312..d1fc438 100644
31320 --- a/drivers/ide/cmd64x.c
31321 +++ b/drivers/ide/cmd64x.c
31322 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31323 .dma_sff_read_status = ide_dma_sff_read_status,
31324 };
31325
31326 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31327 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31328 { /* 0: CMD643 */
31329 .name = DRV_NAME,
31330 .init_chipset = init_chipset_cmd64x,
31331 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31332 index 2c1e5f7..1444762 100644
31333 --- a/drivers/ide/cs5520.c
31334 +++ b/drivers/ide/cs5520.c
31335 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31336 .set_dma_mode = cs5520_set_dma_mode,
31337 };
31338
31339 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31340 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31341 .name = DRV_NAME,
31342 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31343 .port_ops = &cs5520_port_ops,
31344 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31345 index 4dc4eb9..49b40ad 100644
31346 --- a/drivers/ide/cs5530.c
31347 +++ b/drivers/ide/cs5530.c
31348 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31349 .udma_filter = cs5530_udma_filter,
31350 };
31351
31352 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31353 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31354 .name = DRV_NAME,
31355 .init_chipset = init_chipset_cs5530,
31356 .init_hwif = init_hwif_cs5530,
31357 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31358 index 5059faf..18d4c85 100644
31359 --- a/drivers/ide/cs5535.c
31360 +++ b/drivers/ide/cs5535.c
31361 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31362 .cable_detect = cs5535_cable_detect,
31363 };
31364
31365 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31366 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31367 .name = DRV_NAME,
31368 .port_ops = &cs5535_port_ops,
31369 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31370 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31371 index 847553f..3ffb49d 100644
31372 --- a/drivers/ide/cy82c693.c
31373 +++ b/drivers/ide/cy82c693.c
31374 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31375 .set_dma_mode = cy82c693_set_dma_mode,
31376 };
31377
31378 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31379 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31380 .name = DRV_NAME,
31381 .init_iops = init_iops_cy82c693,
31382 .port_ops = &cy82c693_port_ops,
31383 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31384 index 58c51cd..4aec3b8 100644
31385 --- a/drivers/ide/hpt366.c
31386 +++ b/drivers/ide/hpt366.c
31387 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31388 }
31389 };
31390
31391 -static const struct hpt_info hpt36x __devinitdata = {
31392 +static const struct hpt_info hpt36x __devinitconst = {
31393 .chip_name = "HPT36x",
31394 .chip_type = HPT36x,
31395 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31396 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31397 .timings = &hpt36x_timings
31398 };
31399
31400 -static const struct hpt_info hpt370 __devinitdata = {
31401 +static const struct hpt_info hpt370 __devinitconst = {
31402 .chip_name = "HPT370",
31403 .chip_type = HPT370,
31404 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31405 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31406 .timings = &hpt37x_timings
31407 };
31408
31409 -static const struct hpt_info hpt370a __devinitdata = {
31410 +static const struct hpt_info hpt370a __devinitconst = {
31411 .chip_name = "HPT370A",
31412 .chip_type = HPT370A,
31413 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31414 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31415 .timings = &hpt37x_timings
31416 };
31417
31418 -static const struct hpt_info hpt374 __devinitdata = {
31419 +static const struct hpt_info hpt374 __devinitconst = {
31420 .chip_name = "HPT374",
31421 .chip_type = HPT374,
31422 .udma_mask = ATA_UDMA5,
31423 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31424 .timings = &hpt37x_timings
31425 };
31426
31427 -static const struct hpt_info hpt372 __devinitdata = {
31428 +static const struct hpt_info hpt372 __devinitconst = {
31429 .chip_name = "HPT372",
31430 .chip_type = HPT372,
31431 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31432 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31433 .timings = &hpt37x_timings
31434 };
31435
31436 -static const struct hpt_info hpt372a __devinitdata = {
31437 +static const struct hpt_info hpt372a __devinitconst = {
31438 .chip_name = "HPT372A",
31439 .chip_type = HPT372A,
31440 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31441 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31442 .timings = &hpt37x_timings
31443 };
31444
31445 -static const struct hpt_info hpt302 __devinitdata = {
31446 +static const struct hpt_info hpt302 __devinitconst = {
31447 .chip_name = "HPT302",
31448 .chip_type = HPT302,
31449 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31450 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31451 .timings = &hpt37x_timings
31452 };
31453
31454 -static const struct hpt_info hpt371 __devinitdata = {
31455 +static const struct hpt_info hpt371 __devinitconst = {
31456 .chip_name = "HPT371",
31457 .chip_type = HPT371,
31458 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31459 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31460 .timings = &hpt37x_timings
31461 };
31462
31463 -static const struct hpt_info hpt372n __devinitdata = {
31464 +static const struct hpt_info hpt372n __devinitconst = {
31465 .chip_name = "HPT372N",
31466 .chip_type = HPT372N,
31467 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31468 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31469 .timings = &hpt37x_timings
31470 };
31471
31472 -static const struct hpt_info hpt302n __devinitdata = {
31473 +static const struct hpt_info hpt302n __devinitconst = {
31474 .chip_name = "HPT302N",
31475 .chip_type = HPT302N,
31476 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31477 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31478 .timings = &hpt37x_timings
31479 };
31480
31481 -static const struct hpt_info hpt371n __devinitdata = {
31482 +static const struct hpt_info hpt371n __devinitconst = {
31483 .chip_name = "HPT371N",
31484 .chip_type = HPT371N,
31485 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31486 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31487 .dma_sff_read_status = ide_dma_sff_read_status,
31488 };
31489
31490 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31491 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31492 { /* 0: HPT36x */
31493 .name = DRV_NAME,
31494 .init_chipset = init_chipset_hpt366,
31495 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31496 index 8126824..55a2798 100644
31497 --- a/drivers/ide/ide-cd.c
31498 +++ b/drivers/ide/ide-cd.c
31499 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31500 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31501 if ((unsigned long)buf & alignment
31502 || blk_rq_bytes(rq) & q->dma_pad_mask
31503 - || object_is_on_stack(buf))
31504 + || object_starts_on_stack(buf))
31505 drive->dma = 0;
31506 }
31507 }
31508 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31509 index 7f56b73..dab5b67 100644
31510 --- a/drivers/ide/ide-pci-generic.c
31511 +++ b/drivers/ide/ide-pci-generic.c
31512 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31513 .udma_mask = ATA_UDMA6, \
31514 }
31515
31516 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31517 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31518 /* 0: Unknown */
31519 DECLARE_GENERIC_PCI_DEV(0),
31520
31521 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31522 index 560e66d..d5dd180 100644
31523 --- a/drivers/ide/it8172.c
31524 +++ b/drivers/ide/it8172.c
31525 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31526 .set_dma_mode = it8172_set_dma_mode,
31527 };
31528
31529 -static const struct ide_port_info it8172_port_info __devinitdata = {
31530 +static const struct ide_port_info it8172_port_info __devinitconst = {
31531 .name = DRV_NAME,
31532 .port_ops = &it8172_port_ops,
31533 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31534 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31535 index 46816ba..1847aeb 100644
31536 --- a/drivers/ide/it8213.c
31537 +++ b/drivers/ide/it8213.c
31538 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31539 .cable_detect = it8213_cable_detect,
31540 };
31541
31542 -static const struct ide_port_info it8213_chipset __devinitdata = {
31543 +static const struct ide_port_info it8213_chipset __devinitconst = {
31544 .name = DRV_NAME,
31545 .enablebits = { {0x41, 0x80, 0x80} },
31546 .port_ops = &it8213_port_ops,
31547 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31548 index 2e3169f..c5611db 100644
31549 --- a/drivers/ide/it821x.c
31550 +++ b/drivers/ide/it821x.c
31551 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31552 .cable_detect = it821x_cable_detect,
31553 };
31554
31555 -static const struct ide_port_info it821x_chipset __devinitdata = {
31556 +static const struct ide_port_info it821x_chipset __devinitconst = {
31557 .name = DRV_NAME,
31558 .init_chipset = init_chipset_it821x,
31559 .init_hwif = init_hwif_it821x,
31560 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31561 index 74c2c4a..efddd7d 100644
31562 --- a/drivers/ide/jmicron.c
31563 +++ b/drivers/ide/jmicron.c
31564 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31565 .cable_detect = jmicron_cable_detect,
31566 };
31567
31568 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31569 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31570 .name = DRV_NAME,
31571 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31572 .port_ops = &jmicron_port_ops,
31573 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31574 index 95327a2..73f78d8 100644
31575 --- a/drivers/ide/ns87415.c
31576 +++ b/drivers/ide/ns87415.c
31577 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31578 .dma_sff_read_status = superio_dma_sff_read_status,
31579 };
31580
31581 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31582 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31583 .name = DRV_NAME,
31584 .init_hwif = init_hwif_ns87415,
31585 .tp_ops = &ns87415_tp_ops,
31586 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31587 index 1a53a4c..39edc66 100644
31588 --- a/drivers/ide/opti621.c
31589 +++ b/drivers/ide/opti621.c
31590 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31591 .set_pio_mode = opti621_set_pio_mode,
31592 };
31593
31594 -static const struct ide_port_info opti621_chipset __devinitdata = {
31595 +static const struct ide_port_info opti621_chipset __devinitconst = {
31596 .name = DRV_NAME,
31597 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31598 .port_ops = &opti621_port_ops,
31599 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31600 index 9546fe2..2e5ceb6 100644
31601 --- a/drivers/ide/pdc202xx_new.c
31602 +++ b/drivers/ide/pdc202xx_new.c
31603 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31604 .udma_mask = udma, \
31605 }
31606
31607 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31608 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31609 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31610 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31611 };
31612 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31613 index 3a35ec6..5634510 100644
31614 --- a/drivers/ide/pdc202xx_old.c
31615 +++ b/drivers/ide/pdc202xx_old.c
31616 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31617 .max_sectors = sectors, \
31618 }
31619
31620 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31621 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31622 { /* 0: PDC20246 */
31623 .name = DRV_NAME,
31624 .init_chipset = init_chipset_pdc202xx,
31625 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31626 index 1892e81..fe0fd60 100644
31627 --- a/drivers/ide/piix.c
31628 +++ b/drivers/ide/piix.c
31629 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31630 .udma_mask = udma, \
31631 }
31632
31633 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31634 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31635 /* 0: MPIIX */
31636 { /*
31637 * MPIIX actually has only a single IDE channel mapped to
31638 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31639 index a6414a8..c04173e 100644
31640 --- a/drivers/ide/rz1000.c
31641 +++ b/drivers/ide/rz1000.c
31642 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31643 }
31644 }
31645
31646 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31647 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31648 .name = DRV_NAME,
31649 .host_flags = IDE_HFLAG_NO_DMA,
31650 };
31651 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31652 index 356b9b5..d4758eb 100644
31653 --- a/drivers/ide/sc1200.c
31654 +++ b/drivers/ide/sc1200.c
31655 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31656 .dma_sff_read_status = ide_dma_sff_read_status,
31657 };
31658
31659 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31660 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31661 .name = DRV_NAME,
31662 .port_ops = &sc1200_port_ops,
31663 .dma_ops = &sc1200_dma_ops,
31664 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31665 index b7f5b0c..9701038 100644
31666 --- a/drivers/ide/scc_pata.c
31667 +++ b/drivers/ide/scc_pata.c
31668 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31669 .dma_sff_read_status = scc_dma_sff_read_status,
31670 };
31671
31672 -static const struct ide_port_info scc_chipset __devinitdata = {
31673 +static const struct ide_port_info scc_chipset __devinitconst = {
31674 .name = "sccIDE",
31675 .init_iops = init_iops_scc,
31676 .init_dma = scc_init_dma,
31677 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31678 index 35fb8da..24d72ef 100644
31679 --- a/drivers/ide/serverworks.c
31680 +++ b/drivers/ide/serverworks.c
31681 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31682 .cable_detect = svwks_cable_detect,
31683 };
31684
31685 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31686 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31687 { /* 0: OSB4 */
31688 .name = DRV_NAME,
31689 .init_chipset = init_chipset_svwks,
31690 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31691 index ddeda44..46f7e30 100644
31692 --- a/drivers/ide/siimage.c
31693 +++ b/drivers/ide/siimage.c
31694 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31695 .udma_mask = ATA_UDMA6, \
31696 }
31697
31698 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31699 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31700 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31701 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31702 };
31703 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31704 index 4a00225..09e61b4 100644
31705 --- a/drivers/ide/sis5513.c
31706 +++ b/drivers/ide/sis5513.c
31707 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31708 .cable_detect = sis_cable_detect,
31709 };
31710
31711 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31712 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31713 .name = DRV_NAME,
31714 .init_chipset = init_chipset_sis5513,
31715 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31716 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31717 index f21dc2a..d051cd2 100644
31718 --- a/drivers/ide/sl82c105.c
31719 +++ b/drivers/ide/sl82c105.c
31720 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31721 .dma_sff_read_status = ide_dma_sff_read_status,
31722 };
31723
31724 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31725 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31726 .name = DRV_NAME,
31727 .init_chipset = init_chipset_sl82c105,
31728 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31729 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31730 index 864ffe0..863a5e9 100644
31731 --- a/drivers/ide/slc90e66.c
31732 +++ b/drivers/ide/slc90e66.c
31733 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31734 .cable_detect = slc90e66_cable_detect,
31735 };
31736
31737 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31738 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31739 .name = DRV_NAME,
31740 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31741 .port_ops = &slc90e66_port_ops,
31742 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31743 index 4799d5c..1794678 100644
31744 --- a/drivers/ide/tc86c001.c
31745 +++ b/drivers/ide/tc86c001.c
31746 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31747 .dma_sff_read_status = ide_dma_sff_read_status,
31748 };
31749
31750 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31751 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31752 .name = DRV_NAME,
31753 .init_hwif = init_hwif_tc86c001,
31754 .port_ops = &tc86c001_port_ops,
31755 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31756 index 281c914..55ce1b8 100644
31757 --- a/drivers/ide/triflex.c
31758 +++ b/drivers/ide/triflex.c
31759 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31760 .set_dma_mode = triflex_set_mode,
31761 };
31762
31763 -static const struct ide_port_info triflex_device __devinitdata = {
31764 +static const struct ide_port_info triflex_device __devinitconst = {
31765 .name = DRV_NAME,
31766 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31767 .port_ops = &triflex_port_ops,
31768 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31769 index 4b42ca0..e494a98 100644
31770 --- a/drivers/ide/trm290.c
31771 +++ b/drivers/ide/trm290.c
31772 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31773 .dma_check = trm290_dma_check,
31774 };
31775
31776 -static const struct ide_port_info trm290_chipset __devinitdata = {
31777 +static const struct ide_port_info trm290_chipset __devinitconst = {
31778 .name = DRV_NAME,
31779 .init_hwif = init_hwif_trm290,
31780 .tp_ops = &trm290_tp_ops,
31781 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31782 index f46f49c..eb77678 100644
31783 --- a/drivers/ide/via82cxxx.c
31784 +++ b/drivers/ide/via82cxxx.c
31785 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31786 .cable_detect = via82cxxx_cable_detect,
31787 };
31788
31789 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31790 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31791 .name = DRV_NAME,
31792 .init_chipset = init_chipset_via82cxxx,
31793 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31794 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31795 index 73d4531..c90cd2d 100644
31796 --- a/drivers/ieee802154/fakehard.c
31797 +++ b/drivers/ieee802154/fakehard.c
31798 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31799 phy->transmit_power = 0xbf;
31800
31801 dev->netdev_ops = &fake_ops;
31802 - dev->ml_priv = &fake_mlme;
31803 + dev->ml_priv = (void *)&fake_mlme;
31804
31805 priv = netdev_priv(dev);
31806 priv->phy = phy;
31807 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31808 index c889aae..6cf5aa7 100644
31809 --- a/drivers/infiniband/core/cm.c
31810 +++ b/drivers/infiniband/core/cm.c
31811 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31812
31813 struct cm_counter_group {
31814 struct kobject obj;
31815 - atomic_long_t counter[CM_ATTR_COUNT];
31816 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31817 };
31818
31819 struct cm_counter_attribute {
31820 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31821 struct ib_mad_send_buf *msg = NULL;
31822 int ret;
31823
31824 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31825 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31826 counter[CM_REQ_COUNTER]);
31827
31828 /* Quick state check to discard duplicate REQs. */
31829 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31830 if (!cm_id_priv)
31831 return;
31832
31833 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31834 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31835 counter[CM_REP_COUNTER]);
31836 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31837 if (ret)
31838 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31839 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31840 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31841 spin_unlock_irq(&cm_id_priv->lock);
31842 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31843 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31844 counter[CM_RTU_COUNTER]);
31845 goto out;
31846 }
31847 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31848 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31849 dreq_msg->local_comm_id);
31850 if (!cm_id_priv) {
31851 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31852 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31853 counter[CM_DREQ_COUNTER]);
31854 cm_issue_drep(work->port, work->mad_recv_wc);
31855 return -EINVAL;
31856 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31857 case IB_CM_MRA_REP_RCVD:
31858 break;
31859 case IB_CM_TIMEWAIT:
31860 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31861 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31862 counter[CM_DREQ_COUNTER]);
31863 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31864 goto unlock;
31865 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31866 cm_free_msg(msg);
31867 goto deref;
31868 case IB_CM_DREQ_RCVD:
31869 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31870 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31871 counter[CM_DREQ_COUNTER]);
31872 goto unlock;
31873 default:
31874 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31875 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31876 cm_id_priv->msg, timeout)) {
31877 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31878 - atomic_long_inc(&work->port->
31879 + atomic_long_inc_unchecked(&work->port->
31880 counter_group[CM_RECV_DUPLICATES].
31881 counter[CM_MRA_COUNTER]);
31882 goto out;
31883 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31884 break;
31885 case IB_CM_MRA_REQ_RCVD:
31886 case IB_CM_MRA_REP_RCVD:
31887 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31888 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31889 counter[CM_MRA_COUNTER]);
31890 /* fall through */
31891 default:
31892 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31893 case IB_CM_LAP_IDLE:
31894 break;
31895 case IB_CM_MRA_LAP_SENT:
31896 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31897 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31898 counter[CM_LAP_COUNTER]);
31899 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31900 goto unlock;
31901 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31902 cm_free_msg(msg);
31903 goto deref;
31904 case IB_CM_LAP_RCVD:
31905 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31906 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31907 counter[CM_LAP_COUNTER]);
31908 goto unlock;
31909 default:
31910 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31911 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31912 if (cur_cm_id_priv) {
31913 spin_unlock_irq(&cm.lock);
31914 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31915 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31916 counter[CM_SIDR_REQ_COUNTER]);
31917 goto out; /* Duplicate message. */
31918 }
31919 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31920 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31921 msg->retries = 1;
31922
31923 - atomic_long_add(1 + msg->retries,
31924 + atomic_long_add_unchecked(1 + msg->retries,
31925 &port->counter_group[CM_XMIT].counter[attr_index]);
31926 if (msg->retries)
31927 - atomic_long_add(msg->retries,
31928 + atomic_long_add_unchecked(msg->retries,
31929 &port->counter_group[CM_XMIT_RETRIES].
31930 counter[attr_index]);
31931
31932 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31933 }
31934
31935 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31936 - atomic_long_inc(&port->counter_group[CM_RECV].
31937 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31938 counter[attr_id - CM_ATTR_ID_OFFSET]);
31939
31940 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31941 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31942 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31943
31944 return sprintf(buf, "%ld\n",
31945 - atomic_long_read(&group->counter[cm_attr->index]));
31946 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31947 }
31948
31949 static const struct sysfs_ops cm_counter_ops = {
31950 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
31951 index 176c8f9..2627b62 100644
31952 --- a/drivers/infiniband/core/fmr_pool.c
31953 +++ b/drivers/infiniband/core/fmr_pool.c
31954 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
31955
31956 struct task_struct *thread;
31957
31958 - atomic_t req_ser;
31959 - atomic_t flush_ser;
31960 + atomic_unchecked_t req_ser;
31961 + atomic_unchecked_t flush_ser;
31962
31963 wait_queue_head_t force_wait;
31964 };
31965 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31966 struct ib_fmr_pool *pool = pool_ptr;
31967
31968 do {
31969 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31970 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31971 ib_fmr_batch_release(pool);
31972
31973 - atomic_inc(&pool->flush_ser);
31974 + atomic_inc_unchecked(&pool->flush_ser);
31975 wake_up_interruptible(&pool->force_wait);
31976
31977 if (pool->flush_function)
31978 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31979 }
31980
31981 set_current_state(TASK_INTERRUPTIBLE);
31982 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
31983 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
31984 !kthread_should_stop())
31985 schedule();
31986 __set_current_state(TASK_RUNNING);
31987 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
31988 pool->dirty_watermark = params->dirty_watermark;
31989 pool->dirty_len = 0;
31990 spin_lock_init(&pool->pool_lock);
31991 - atomic_set(&pool->req_ser, 0);
31992 - atomic_set(&pool->flush_ser, 0);
31993 + atomic_set_unchecked(&pool->req_ser, 0);
31994 + atomic_set_unchecked(&pool->flush_ser, 0);
31995 init_waitqueue_head(&pool->force_wait);
31996
31997 pool->thread = kthread_run(ib_fmr_cleanup_thread,
31998 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
31999 }
32000 spin_unlock_irq(&pool->pool_lock);
32001
32002 - serial = atomic_inc_return(&pool->req_ser);
32003 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32004 wake_up_process(pool->thread);
32005
32006 if (wait_event_interruptible(pool->force_wait,
32007 - atomic_read(&pool->flush_ser) - serial >= 0))
32008 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32009 return -EINTR;
32010
32011 return 0;
32012 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32013 } else {
32014 list_add_tail(&fmr->list, &pool->dirty_list);
32015 if (++pool->dirty_len >= pool->dirty_watermark) {
32016 - atomic_inc(&pool->req_ser);
32017 + atomic_inc_unchecked(&pool->req_ser);
32018 wake_up_process(pool->thread);
32019 }
32020 }
32021 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32022 index 40c8353..946b0e4 100644
32023 --- a/drivers/infiniband/hw/cxgb4/mem.c
32024 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32025 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32026 int err;
32027 struct fw_ri_tpte tpt;
32028 u32 stag_idx;
32029 - static atomic_t key;
32030 + static atomic_unchecked_t key;
32031
32032 if (c4iw_fatal_error(rdev))
32033 return -EIO;
32034 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32035 &rdev->resource.tpt_fifo_lock);
32036 if (!stag_idx)
32037 return -ENOMEM;
32038 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32039 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32040 }
32041 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32042 __func__, stag_state, type, pdid, stag_idx);
32043 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
32044 index a4de9d5..5fa20c3 100644
32045 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
32046 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
32047 @@ -126,6 +126,8 @@ static const struct file_operations atomic_counters_ops = {
32048 };
32049
32050 static ssize_t flash_read(struct file *file, char __user *buf,
32051 + size_t count, loff_t *ppos) __size_overflow(3);
32052 +static ssize_t flash_read(struct file *file, char __user *buf,
32053 size_t count, loff_t *ppos)
32054 {
32055 struct ipath_devdata *dd;
32056 @@ -177,6 +179,8 @@ bail:
32057 }
32058
32059 static ssize_t flash_write(struct file *file, const char __user *buf,
32060 + size_t count, loff_t *ppos) __size_overflow(3);
32061 +static ssize_t flash_write(struct file *file, const char __user *buf,
32062 size_t count, loff_t *ppos)
32063 {
32064 struct ipath_devdata *dd;
32065 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32066 index 79b3dbc..96e5fcc 100644
32067 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32068 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32069 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32070 struct ib_atomic_eth *ateth;
32071 struct ipath_ack_entry *e;
32072 u64 vaddr;
32073 - atomic64_t *maddr;
32074 + atomic64_unchecked_t *maddr;
32075 u64 sdata;
32076 u32 rkey;
32077 u8 next;
32078 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32079 IB_ACCESS_REMOTE_ATOMIC)))
32080 goto nack_acc_unlck;
32081 /* Perform atomic OP and save result. */
32082 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32083 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32084 sdata = be64_to_cpu(ateth->swap_data);
32085 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32086 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32087 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32088 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32089 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32090 be64_to_cpu(ateth->compare_data),
32091 sdata);
32092 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32093 index 1f95bba..9530f87 100644
32094 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32095 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32096 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32097 unsigned long flags;
32098 struct ib_wc wc;
32099 u64 sdata;
32100 - atomic64_t *maddr;
32101 + atomic64_unchecked_t *maddr;
32102 enum ib_wc_status send_status;
32103
32104 /*
32105 @@ -382,11 +382,11 @@ again:
32106 IB_ACCESS_REMOTE_ATOMIC)))
32107 goto acc_err;
32108 /* Perform atomic OP and save result. */
32109 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32110 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32111 sdata = wqe->wr.wr.atomic.compare_add;
32112 *(u64 *) sqp->s_sge.sge.vaddr =
32113 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32114 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32115 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32116 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32117 sdata, wqe->wr.wr.atomic.swap);
32118 goto send_comp;
32119 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32120 index 7140199..da60063 100644
32121 --- a/drivers/infiniband/hw/nes/nes.c
32122 +++ b/drivers/infiniband/hw/nes/nes.c
32123 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32124 LIST_HEAD(nes_adapter_list);
32125 static LIST_HEAD(nes_dev_list);
32126
32127 -atomic_t qps_destroyed;
32128 +atomic_unchecked_t qps_destroyed;
32129
32130 static unsigned int ee_flsh_adapter;
32131 static unsigned int sysfs_nonidx_addr;
32132 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32133 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32134 struct nes_adapter *nesadapter = nesdev->nesadapter;
32135
32136 - atomic_inc(&qps_destroyed);
32137 + atomic_inc_unchecked(&qps_destroyed);
32138
32139 /* Free the control structures */
32140
32141 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32142 index c438e46..ca30356 100644
32143 --- a/drivers/infiniband/hw/nes/nes.h
32144 +++ b/drivers/infiniband/hw/nes/nes.h
32145 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32146 extern unsigned int wqm_quanta;
32147 extern struct list_head nes_adapter_list;
32148
32149 -extern atomic_t cm_connects;
32150 -extern atomic_t cm_accepts;
32151 -extern atomic_t cm_disconnects;
32152 -extern atomic_t cm_closes;
32153 -extern atomic_t cm_connecteds;
32154 -extern atomic_t cm_connect_reqs;
32155 -extern atomic_t cm_rejects;
32156 -extern atomic_t mod_qp_timouts;
32157 -extern atomic_t qps_created;
32158 -extern atomic_t qps_destroyed;
32159 -extern atomic_t sw_qps_destroyed;
32160 +extern atomic_unchecked_t cm_connects;
32161 +extern atomic_unchecked_t cm_accepts;
32162 +extern atomic_unchecked_t cm_disconnects;
32163 +extern atomic_unchecked_t cm_closes;
32164 +extern atomic_unchecked_t cm_connecteds;
32165 +extern atomic_unchecked_t cm_connect_reqs;
32166 +extern atomic_unchecked_t cm_rejects;
32167 +extern atomic_unchecked_t mod_qp_timouts;
32168 +extern atomic_unchecked_t qps_created;
32169 +extern atomic_unchecked_t qps_destroyed;
32170 +extern atomic_unchecked_t sw_qps_destroyed;
32171 extern u32 mh_detected;
32172 extern u32 mh_pauses_sent;
32173 extern u32 cm_packets_sent;
32174 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32175 extern u32 cm_packets_received;
32176 extern u32 cm_packets_dropped;
32177 extern u32 cm_packets_retrans;
32178 -extern atomic_t cm_listens_created;
32179 -extern atomic_t cm_listens_destroyed;
32180 +extern atomic_unchecked_t cm_listens_created;
32181 +extern atomic_unchecked_t cm_listens_destroyed;
32182 extern u32 cm_backlog_drops;
32183 -extern atomic_t cm_loopbacks;
32184 -extern atomic_t cm_nodes_created;
32185 -extern atomic_t cm_nodes_destroyed;
32186 -extern atomic_t cm_accel_dropped_pkts;
32187 -extern atomic_t cm_resets_recvd;
32188 -extern atomic_t pau_qps_created;
32189 -extern atomic_t pau_qps_destroyed;
32190 +extern atomic_unchecked_t cm_loopbacks;
32191 +extern atomic_unchecked_t cm_nodes_created;
32192 +extern atomic_unchecked_t cm_nodes_destroyed;
32193 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32194 +extern atomic_unchecked_t cm_resets_recvd;
32195 +extern atomic_unchecked_t pau_qps_created;
32196 +extern atomic_unchecked_t pau_qps_destroyed;
32197
32198 extern u32 int_mod_timer_init;
32199 extern u32 int_mod_cq_depth_256;
32200 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32201 index a4972ab..1bcfc31 100644
32202 --- a/drivers/infiniband/hw/nes/nes_cm.c
32203 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32204 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32205 u32 cm_packets_retrans;
32206 u32 cm_packets_created;
32207 u32 cm_packets_received;
32208 -atomic_t cm_listens_created;
32209 -atomic_t cm_listens_destroyed;
32210 +atomic_unchecked_t cm_listens_created;
32211 +atomic_unchecked_t cm_listens_destroyed;
32212 u32 cm_backlog_drops;
32213 -atomic_t cm_loopbacks;
32214 -atomic_t cm_nodes_created;
32215 -atomic_t cm_nodes_destroyed;
32216 -atomic_t cm_accel_dropped_pkts;
32217 -atomic_t cm_resets_recvd;
32218 +atomic_unchecked_t cm_loopbacks;
32219 +atomic_unchecked_t cm_nodes_created;
32220 +atomic_unchecked_t cm_nodes_destroyed;
32221 +atomic_unchecked_t cm_accel_dropped_pkts;
32222 +atomic_unchecked_t cm_resets_recvd;
32223
32224 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32225 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32226 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32227
32228 static struct nes_cm_core *g_cm_core;
32229
32230 -atomic_t cm_connects;
32231 -atomic_t cm_accepts;
32232 -atomic_t cm_disconnects;
32233 -atomic_t cm_closes;
32234 -atomic_t cm_connecteds;
32235 -atomic_t cm_connect_reqs;
32236 -atomic_t cm_rejects;
32237 +atomic_unchecked_t cm_connects;
32238 +atomic_unchecked_t cm_accepts;
32239 +atomic_unchecked_t cm_disconnects;
32240 +atomic_unchecked_t cm_closes;
32241 +atomic_unchecked_t cm_connecteds;
32242 +atomic_unchecked_t cm_connect_reqs;
32243 +atomic_unchecked_t cm_rejects;
32244
32245 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32246 {
32247 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32248 kfree(listener);
32249 listener = NULL;
32250 ret = 0;
32251 - atomic_inc(&cm_listens_destroyed);
32252 + atomic_inc_unchecked(&cm_listens_destroyed);
32253 } else {
32254 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32255 }
32256 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32257 cm_node->rem_mac);
32258
32259 add_hte_node(cm_core, cm_node);
32260 - atomic_inc(&cm_nodes_created);
32261 + atomic_inc_unchecked(&cm_nodes_created);
32262
32263 return cm_node;
32264 }
32265 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32266 }
32267
32268 atomic_dec(&cm_core->node_cnt);
32269 - atomic_inc(&cm_nodes_destroyed);
32270 + atomic_inc_unchecked(&cm_nodes_destroyed);
32271 nesqp = cm_node->nesqp;
32272 if (nesqp) {
32273 nesqp->cm_node = NULL;
32274 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32275
32276 static void drop_packet(struct sk_buff *skb)
32277 {
32278 - atomic_inc(&cm_accel_dropped_pkts);
32279 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32280 dev_kfree_skb_any(skb);
32281 }
32282
32283 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32284 {
32285
32286 int reset = 0; /* whether to send reset in case of err.. */
32287 - atomic_inc(&cm_resets_recvd);
32288 + atomic_inc_unchecked(&cm_resets_recvd);
32289 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32290 " refcnt=%d\n", cm_node, cm_node->state,
32291 atomic_read(&cm_node->ref_count));
32292 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32293 rem_ref_cm_node(cm_node->cm_core, cm_node);
32294 return NULL;
32295 }
32296 - atomic_inc(&cm_loopbacks);
32297 + atomic_inc_unchecked(&cm_loopbacks);
32298 loopbackremotenode->loopbackpartner = cm_node;
32299 loopbackremotenode->tcp_cntxt.rcv_wscale =
32300 NES_CM_DEFAULT_RCV_WND_SCALE;
32301 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32302 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32303 else {
32304 rem_ref_cm_node(cm_core, cm_node);
32305 - atomic_inc(&cm_accel_dropped_pkts);
32306 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32307 dev_kfree_skb_any(skb);
32308 }
32309 break;
32310 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32311
32312 if ((cm_id) && (cm_id->event_handler)) {
32313 if (issue_disconn) {
32314 - atomic_inc(&cm_disconnects);
32315 + atomic_inc_unchecked(&cm_disconnects);
32316 cm_event.event = IW_CM_EVENT_DISCONNECT;
32317 cm_event.status = disconn_status;
32318 cm_event.local_addr = cm_id->local_addr;
32319 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32320 }
32321
32322 if (issue_close) {
32323 - atomic_inc(&cm_closes);
32324 + atomic_inc_unchecked(&cm_closes);
32325 nes_disconnect(nesqp, 1);
32326
32327 cm_id->provider_data = nesqp;
32328 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32329
32330 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32331 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32332 - atomic_inc(&cm_accepts);
32333 + atomic_inc_unchecked(&cm_accepts);
32334
32335 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32336 netdev_refcnt_read(nesvnic->netdev));
32337 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32338 struct nes_cm_core *cm_core;
32339 u8 *start_buff;
32340
32341 - atomic_inc(&cm_rejects);
32342 + atomic_inc_unchecked(&cm_rejects);
32343 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32344 loopback = cm_node->loopbackpartner;
32345 cm_core = cm_node->cm_core;
32346 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32347 ntohl(cm_id->local_addr.sin_addr.s_addr),
32348 ntohs(cm_id->local_addr.sin_port));
32349
32350 - atomic_inc(&cm_connects);
32351 + atomic_inc_unchecked(&cm_connects);
32352 nesqp->active_conn = 1;
32353
32354 /* cache the cm_id in the qp */
32355 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32356 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32357 return err;
32358 }
32359 - atomic_inc(&cm_listens_created);
32360 + atomic_inc_unchecked(&cm_listens_created);
32361 }
32362
32363 cm_id->add_ref(cm_id);
32364 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32365
32366 if (nesqp->destroyed)
32367 return;
32368 - atomic_inc(&cm_connecteds);
32369 + atomic_inc_unchecked(&cm_connecteds);
32370 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32371 " local port 0x%04X. jiffies = %lu.\n",
32372 nesqp->hwqp.qp_id,
32373 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32374
32375 cm_id->add_ref(cm_id);
32376 ret = cm_id->event_handler(cm_id, &cm_event);
32377 - atomic_inc(&cm_closes);
32378 + atomic_inc_unchecked(&cm_closes);
32379 cm_event.event = IW_CM_EVENT_CLOSE;
32380 cm_event.status = 0;
32381 cm_event.provider_data = cm_id->provider_data;
32382 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32383 return;
32384 cm_id = cm_node->cm_id;
32385
32386 - atomic_inc(&cm_connect_reqs);
32387 + atomic_inc_unchecked(&cm_connect_reqs);
32388 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32389 cm_node, cm_id, jiffies);
32390
32391 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32392 return;
32393 cm_id = cm_node->cm_id;
32394
32395 - atomic_inc(&cm_connect_reqs);
32396 + atomic_inc_unchecked(&cm_connect_reqs);
32397 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32398 cm_node, cm_id, jiffies);
32399
32400 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32401 index 3ba7be3..c81f6ff 100644
32402 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32403 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32404 @@ -40,8 +40,8 @@
32405 #include "nes.h"
32406 #include "nes_mgt.h"
32407
32408 -atomic_t pau_qps_created;
32409 -atomic_t pau_qps_destroyed;
32410 +atomic_unchecked_t pau_qps_created;
32411 +atomic_unchecked_t pau_qps_destroyed;
32412
32413 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32414 {
32415 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32416 {
32417 struct sk_buff *skb;
32418 unsigned long flags;
32419 - atomic_inc(&pau_qps_destroyed);
32420 + atomic_inc_unchecked(&pau_qps_destroyed);
32421
32422 /* Free packets that have not yet been forwarded */
32423 /* Lock is acquired by skb_dequeue when removing the skb */
32424 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32425 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32426 skb_queue_head_init(&nesqp->pau_list);
32427 spin_lock_init(&nesqp->pau_lock);
32428 - atomic_inc(&pau_qps_created);
32429 + atomic_inc_unchecked(&pau_qps_created);
32430 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32431 }
32432
32433 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32434 index f3a3ecf..57d311d 100644
32435 --- a/drivers/infiniband/hw/nes/nes_nic.c
32436 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32437 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32438 target_stat_values[++index] = mh_detected;
32439 target_stat_values[++index] = mh_pauses_sent;
32440 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32441 - target_stat_values[++index] = atomic_read(&cm_connects);
32442 - target_stat_values[++index] = atomic_read(&cm_accepts);
32443 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32444 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32445 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32446 - target_stat_values[++index] = atomic_read(&cm_rejects);
32447 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32448 - target_stat_values[++index] = atomic_read(&qps_created);
32449 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32450 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32451 - target_stat_values[++index] = atomic_read(&cm_closes);
32452 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32453 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32454 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32455 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32456 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32457 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32458 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32459 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32460 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32461 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32462 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32463 target_stat_values[++index] = cm_packets_sent;
32464 target_stat_values[++index] = cm_packets_bounced;
32465 target_stat_values[++index] = cm_packets_created;
32466 target_stat_values[++index] = cm_packets_received;
32467 target_stat_values[++index] = cm_packets_dropped;
32468 target_stat_values[++index] = cm_packets_retrans;
32469 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32470 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32471 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32472 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32473 target_stat_values[++index] = cm_backlog_drops;
32474 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32475 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32476 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32477 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32478 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32479 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32480 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32481 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32482 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32483 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32484 target_stat_values[++index] = nesadapter->free_4kpbl;
32485 target_stat_values[++index] = nesadapter->free_256pbl;
32486 target_stat_values[++index] = int_mod_timer_init;
32487 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32488 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32489 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32490 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32491 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32492 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32493 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32494 }
32495
32496 /**
32497 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32498 index 0927b5c..ed67986 100644
32499 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32500 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32501 @@ -46,9 +46,9 @@
32502
32503 #include <rdma/ib_umem.h>
32504
32505 -atomic_t mod_qp_timouts;
32506 -atomic_t qps_created;
32507 -atomic_t sw_qps_destroyed;
32508 +atomic_unchecked_t mod_qp_timouts;
32509 +atomic_unchecked_t qps_created;
32510 +atomic_unchecked_t sw_qps_destroyed;
32511
32512 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32513
32514 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32515 if (init_attr->create_flags)
32516 return ERR_PTR(-EINVAL);
32517
32518 - atomic_inc(&qps_created);
32519 + atomic_inc_unchecked(&qps_created);
32520 switch (init_attr->qp_type) {
32521 case IB_QPT_RC:
32522 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32523 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32524 struct iw_cm_event cm_event;
32525 int ret = 0;
32526
32527 - atomic_inc(&sw_qps_destroyed);
32528 + atomic_inc_unchecked(&sw_qps_destroyed);
32529 nesqp->destroyed = 1;
32530
32531 /* Blow away the connection if it exists. */
32532 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32533 index b881bdc..c2e360c 100644
32534 --- a/drivers/infiniband/hw/qib/qib.h
32535 +++ b/drivers/infiniband/hw/qib/qib.h
32536 @@ -51,6 +51,7 @@
32537 #include <linux/completion.h>
32538 #include <linux/kref.h>
32539 #include <linux/sched.h>
32540 +#include <linux/slab.h>
32541
32542 #include "qib_common.h"
32543 #include "qib_verbs.h"
32544 diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
32545 index 05e0f17..0275789 100644
32546 --- a/drivers/infiniband/hw/qib/qib_fs.c
32547 +++ b/drivers/infiniband/hw/qib/qib_fs.c
32548 @@ -267,6 +267,8 @@ static const struct file_operations qsfp_ops[] = {
32549 };
32550
32551 static ssize_t flash_read(struct file *file, char __user *buf,
32552 + size_t count, loff_t *ppos) __size_overflow(3);
32553 +static ssize_t flash_read(struct file *file, char __user *buf,
32554 size_t count, loff_t *ppos)
32555 {
32556 struct qib_devdata *dd;
32557 @@ -318,6 +320,8 @@ bail:
32558 }
32559
32560 static ssize_t flash_write(struct file *file, const char __user *buf,
32561 + size_t count, loff_t *ppos) __size_overflow(3);
32562 +static ssize_t flash_write(struct file *file, const char __user *buf,
32563 size_t count, loff_t *ppos)
32564 {
32565 struct qib_devdata *dd;
32566 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32567 index c351aa4..e6967c2 100644
32568 --- a/drivers/input/gameport/gameport.c
32569 +++ b/drivers/input/gameport/gameport.c
32570 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32571 */
32572 static void gameport_init_port(struct gameport *gameport)
32573 {
32574 - static atomic_t gameport_no = ATOMIC_INIT(0);
32575 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32576
32577 __module_get(THIS_MODULE);
32578
32579 mutex_init(&gameport->drv_mutex);
32580 device_initialize(&gameport->dev);
32581 dev_set_name(&gameport->dev, "gameport%lu",
32582 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32583 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32584 gameport->dev.bus = &gameport_bus;
32585 gameport->dev.release = gameport_release_port;
32586 if (gameport->parent)
32587 diff --git a/drivers/input/input.c b/drivers/input/input.c
32588 index 1f78c95..3cddc6c 100644
32589 --- a/drivers/input/input.c
32590 +++ b/drivers/input/input.c
32591 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32592 */
32593 int input_register_device(struct input_dev *dev)
32594 {
32595 - static atomic_t input_no = ATOMIC_INIT(0);
32596 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32597 struct input_handler *handler;
32598 const char *path;
32599 int error;
32600 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32601 dev->setkeycode = input_default_setkeycode;
32602
32603 dev_set_name(&dev->dev, "input%ld",
32604 - (unsigned long) atomic_inc_return(&input_no) - 1);
32605 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32606
32607 error = device_add(&dev->dev);
32608 if (error)
32609 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32610 index b8d8611..7a4a04b 100644
32611 --- a/drivers/input/joystick/sidewinder.c
32612 +++ b/drivers/input/joystick/sidewinder.c
32613 @@ -30,6 +30,7 @@
32614 #include <linux/kernel.h>
32615 #include <linux/module.h>
32616 #include <linux/slab.h>
32617 +#include <linux/sched.h>
32618 #include <linux/init.h>
32619 #include <linux/input.h>
32620 #include <linux/gameport.h>
32621 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32622 index fd7a0d5..a4af10c 100644
32623 --- a/drivers/input/joystick/xpad.c
32624 +++ b/drivers/input/joystick/xpad.c
32625 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32626
32627 static int xpad_led_probe(struct usb_xpad *xpad)
32628 {
32629 - static atomic_t led_seq = ATOMIC_INIT(0);
32630 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32631 long led_no;
32632 struct xpad_led *led;
32633 struct led_classdev *led_cdev;
32634 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32635 if (!led)
32636 return -ENOMEM;
32637
32638 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32639 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32640
32641 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32642 led->xpad = xpad;
32643 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32644 index 0110b5a..d3ad144 100644
32645 --- a/drivers/input/mousedev.c
32646 +++ b/drivers/input/mousedev.c
32647 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32648
32649 spin_unlock_irq(&client->packet_lock);
32650
32651 - if (copy_to_user(buffer, data, count))
32652 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32653 return -EFAULT;
32654
32655 return count;
32656 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32657 index ba70058..571d25d 100644
32658 --- a/drivers/input/serio/serio.c
32659 +++ b/drivers/input/serio/serio.c
32660 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32661 */
32662 static void serio_init_port(struct serio *serio)
32663 {
32664 - static atomic_t serio_no = ATOMIC_INIT(0);
32665 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32666
32667 __module_get(THIS_MODULE);
32668
32669 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32670 mutex_init(&serio->drv_mutex);
32671 device_initialize(&serio->dev);
32672 dev_set_name(&serio->dev, "serio%ld",
32673 - (long)atomic_inc_return(&serio_no) - 1);
32674 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32675 serio->dev.bus = &serio_bus;
32676 serio->dev.release = serio_release_port;
32677 serio->dev.groups = serio_device_attr_groups;
32678 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32679 index e44933d..9ba484a 100644
32680 --- a/drivers/isdn/capi/capi.c
32681 +++ b/drivers/isdn/capi/capi.c
32682 @@ -83,8 +83,8 @@ struct capiminor {
32683
32684 struct capi20_appl *ap;
32685 u32 ncci;
32686 - atomic_t datahandle;
32687 - atomic_t msgid;
32688 + atomic_unchecked_t datahandle;
32689 + atomic_unchecked_t msgid;
32690
32691 struct tty_port port;
32692 int ttyinstop;
32693 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32694 capimsg_setu16(s, 2, mp->ap->applid);
32695 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32696 capimsg_setu8 (s, 5, CAPI_RESP);
32697 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32698 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32699 capimsg_setu32(s, 8, mp->ncci);
32700 capimsg_setu16(s, 12, datahandle);
32701 }
32702 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32703 mp->outbytes -= len;
32704 spin_unlock_bh(&mp->outlock);
32705
32706 - datahandle = atomic_inc_return(&mp->datahandle);
32707 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32708 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32709 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32710 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32711 capimsg_setu16(skb->data, 2, mp->ap->applid);
32712 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32713 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32714 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32715 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32716 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32717 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32718 capimsg_setu16(skb->data, 16, len); /* Data length */
32719 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32720 index db621db..825ea1a 100644
32721 --- a/drivers/isdn/gigaset/common.c
32722 +++ b/drivers/isdn/gigaset/common.c
32723 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32724 cs->commands_pending = 0;
32725 cs->cur_at_seq = 0;
32726 cs->gotfwver = -1;
32727 - cs->open_count = 0;
32728 + local_set(&cs->open_count, 0);
32729 cs->dev = NULL;
32730 cs->tty = NULL;
32731 cs->tty_dev = NULL;
32732 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32733 index 212efaf..f187c6b 100644
32734 --- a/drivers/isdn/gigaset/gigaset.h
32735 +++ b/drivers/isdn/gigaset/gigaset.h
32736 @@ -35,6 +35,7 @@
32737 #include <linux/tty_driver.h>
32738 #include <linux/list.h>
32739 #include <linux/atomic.h>
32740 +#include <asm/local.h>
32741
32742 #define GIG_VERSION {0, 5, 0, 0}
32743 #define GIG_COMPAT {0, 4, 0, 0}
32744 @@ -433,7 +434,7 @@ struct cardstate {
32745 spinlock_t cmdlock;
32746 unsigned curlen, cmdbytes;
32747
32748 - unsigned open_count;
32749 + local_t open_count;
32750 struct tty_struct *tty;
32751 struct tasklet_struct if_wake_tasklet;
32752 unsigned control_state;
32753 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32754 index ee0a549..a7c9798 100644
32755 --- a/drivers/isdn/gigaset/interface.c
32756 +++ b/drivers/isdn/gigaset/interface.c
32757 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32758 }
32759 tty->driver_data = cs;
32760
32761 - ++cs->open_count;
32762 -
32763 - if (cs->open_count == 1) {
32764 + if (local_inc_return(&cs->open_count) == 1) {
32765 spin_lock_irqsave(&cs->lock, flags);
32766 cs->tty = tty;
32767 spin_unlock_irqrestore(&cs->lock, flags);
32768 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32769
32770 if (!cs->connected)
32771 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32772 - else if (!cs->open_count)
32773 + else if (!local_read(&cs->open_count))
32774 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32775 else {
32776 - if (!--cs->open_count) {
32777 + if (!local_dec_return(&cs->open_count)) {
32778 spin_lock_irqsave(&cs->lock, flags);
32779 cs->tty = NULL;
32780 spin_unlock_irqrestore(&cs->lock, flags);
32781 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32782 if (!cs->connected) {
32783 gig_dbg(DEBUG_IF, "not connected");
32784 retval = -ENODEV;
32785 - } else if (!cs->open_count)
32786 + } else if (!local_read(&cs->open_count))
32787 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32788 else {
32789 retval = 0;
32790 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32791 retval = -ENODEV;
32792 goto done;
32793 }
32794 - if (!cs->open_count) {
32795 + if (!local_read(&cs->open_count)) {
32796 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32797 retval = -ENODEV;
32798 goto done;
32799 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32800 if (!cs->connected) {
32801 gig_dbg(DEBUG_IF, "not connected");
32802 retval = -ENODEV;
32803 - } else if (!cs->open_count)
32804 + } else if (!local_read(&cs->open_count))
32805 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32806 else if (cs->mstate != MS_LOCKED) {
32807 dev_warn(cs->dev, "can't write to unlocked device\n");
32808 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32809
32810 if (!cs->connected)
32811 gig_dbg(DEBUG_IF, "not connected");
32812 - else if (!cs->open_count)
32813 + else if (!local_read(&cs->open_count))
32814 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32815 else if (cs->mstate != MS_LOCKED)
32816 dev_warn(cs->dev, "can't write to unlocked device\n");
32817 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32818
32819 if (!cs->connected)
32820 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32821 - else if (!cs->open_count)
32822 + else if (!local_read(&cs->open_count))
32823 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32824 else
32825 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32826 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32827
32828 if (!cs->connected)
32829 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32830 - else if (!cs->open_count)
32831 + else if (!local_read(&cs->open_count))
32832 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32833 else
32834 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32835 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32836 goto out;
32837 }
32838
32839 - if (!cs->open_count) {
32840 + if (!local_read(&cs->open_count)) {
32841 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32842 goto out;
32843 }
32844 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32845 index 2a57da59..e7a12ed 100644
32846 --- a/drivers/isdn/hardware/avm/b1.c
32847 +++ b/drivers/isdn/hardware/avm/b1.c
32848 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32849 }
32850 if (left) {
32851 if (t4file->user) {
32852 - if (copy_from_user(buf, dp, left))
32853 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32854 return -EFAULT;
32855 } else {
32856 memcpy(buf, dp, left);
32857 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32858 }
32859 if (left) {
32860 if (config->user) {
32861 - if (copy_from_user(buf, dp, left))
32862 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32863 return -EFAULT;
32864 } else {
32865 memcpy(buf, dp, left);
32866 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32867 index 85784a7..a19ca98 100644
32868 --- a/drivers/isdn/hardware/eicon/divasync.h
32869 +++ b/drivers/isdn/hardware/eicon/divasync.h
32870 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32871 } diva_didd_add_adapter_t;
32872 typedef struct _diva_didd_remove_adapter {
32873 IDI_CALL p_request;
32874 -} diva_didd_remove_adapter_t;
32875 +} __no_const diva_didd_remove_adapter_t;
32876 typedef struct _diva_didd_read_adapter_array {
32877 void * buffer;
32878 dword length;
32879 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32880 index a3bd163..8956575 100644
32881 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32882 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32883 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32884 typedef struct _diva_os_idi_adapter_interface {
32885 diva_init_card_proc_t cleanup_adapter_proc;
32886 diva_cmd_card_proc_t cmd_proc;
32887 -} diva_os_idi_adapter_interface_t;
32888 +} __no_const diva_os_idi_adapter_interface_t;
32889
32890 typedef struct _diva_os_xdi_adapter {
32891 struct list_head link;
32892 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32893 index 1f355bb..43f1fea 100644
32894 --- a/drivers/isdn/icn/icn.c
32895 +++ b/drivers/isdn/icn/icn.c
32896 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32897 if (count > len)
32898 count = len;
32899 if (user) {
32900 - if (copy_from_user(msg, buf, count))
32901 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32902 return -EFAULT;
32903 } else
32904 memcpy(msg, buf, count);
32905 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32906 index b5fdcb7..5b6c59f 100644
32907 --- a/drivers/lguest/core.c
32908 +++ b/drivers/lguest/core.c
32909 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32910 * it's worked so far. The end address needs +1 because __get_vm_area
32911 * allocates an extra guard page, so we need space for that.
32912 */
32913 +
32914 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32915 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32916 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32917 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32918 +#else
32919 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32920 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32921 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32922 +#endif
32923 +
32924 if (!switcher_vma) {
32925 err = -ENOMEM;
32926 printk("lguest: could not map switcher pages high\n");
32927 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32928 * Now the Switcher is mapped at the right address, we can't fail!
32929 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32930 */
32931 - memcpy(switcher_vma->addr, start_switcher_text,
32932 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32933 end_switcher_text - start_switcher_text);
32934
32935 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32936 diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
32937 index ff4a0bc..f5fdd9c 100644
32938 --- a/drivers/lguest/lguest_user.c
32939 +++ b/drivers/lguest/lguest_user.c
32940 @@ -198,6 +198,7 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
32941 * Once our Guest is initialized, the Launcher makes it run by reading
32942 * from /dev/lguest.
32943 */
32944 +static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) __size_overflow(3);
32945 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
32946 {
32947 struct lguest *lg = file->private_data;
32948 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32949 index 3980903..ce25c5e 100644
32950 --- a/drivers/lguest/x86/core.c
32951 +++ b/drivers/lguest/x86/core.c
32952 @@ -59,7 +59,7 @@ static struct {
32953 /* Offset from where switcher.S was compiled to where we've copied it */
32954 static unsigned long switcher_offset(void)
32955 {
32956 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32957 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32958 }
32959
32960 /* This cpu's struct lguest_pages. */
32961 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32962 * These copies are pretty cheap, so we do them unconditionally: */
32963 /* Save the current Host top-level page directory.
32964 */
32965 +
32966 +#ifdef CONFIG_PAX_PER_CPU_PGD
32967 + pages->state.host_cr3 = read_cr3();
32968 +#else
32969 pages->state.host_cr3 = __pa(current->mm->pgd);
32970 +#endif
32971 +
32972 /*
32973 * Set up the Guest's page tables to see this CPU's pages (and no
32974 * other CPU's pages).
32975 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32976 * compiled-in switcher code and the high-mapped copy we just made.
32977 */
32978 for (i = 0; i < IDT_ENTRIES; i++)
32979 - default_idt_entries[i] += switcher_offset();
32980 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32981
32982 /*
32983 * Set up the Switcher's per-cpu areas.
32984 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32985 * it will be undisturbed when we switch. To change %cs and jump we
32986 * need this structure to feed to Intel's "lcall" instruction.
32987 */
32988 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32989 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32990 lguest_entry.segment = LGUEST_CS;
32991
32992 /*
32993 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32994 index 40634b0..4f5855e 100644
32995 --- a/drivers/lguest/x86/switcher_32.S
32996 +++ b/drivers/lguest/x86/switcher_32.S
32997 @@ -87,6 +87,7 @@
32998 #include <asm/page.h>
32999 #include <asm/segment.h>
33000 #include <asm/lguest.h>
33001 +#include <asm/processor-flags.h>
33002
33003 // We mark the start of the code to copy
33004 // It's placed in .text tho it's never run here
33005 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33006 // Changes type when we load it: damn Intel!
33007 // For after we switch over our page tables
33008 // That entry will be read-only: we'd crash.
33009 +
33010 +#ifdef CONFIG_PAX_KERNEXEC
33011 + mov %cr0, %edx
33012 + xor $X86_CR0_WP, %edx
33013 + mov %edx, %cr0
33014 +#endif
33015 +
33016 movl $(GDT_ENTRY_TSS*8), %edx
33017 ltr %dx
33018
33019 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33020 // Let's clear it again for our return.
33021 // The GDT descriptor of the Host
33022 // Points to the table after two "size" bytes
33023 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33024 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33025 // Clear "used" from type field (byte 5, bit 2)
33026 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33027 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33028 +
33029 +#ifdef CONFIG_PAX_KERNEXEC
33030 + mov %cr0, %eax
33031 + xor $X86_CR0_WP, %eax
33032 + mov %eax, %cr0
33033 +#endif
33034
33035 // Once our page table's switched, the Guest is live!
33036 // The Host fades as we run this final step.
33037 @@ -295,13 +309,12 @@ deliver_to_host:
33038 // I consulted gcc, and it gave
33039 // These instructions, which I gladly credit:
33040 leal (%edx,%ebx,8), %eax
33041 - movzwl (%eax),%edx
33042 - movl 4(%eax), %eax
33043 - xorw %ax, %ax
33044 - orl %eax, %edx
33045 + movl 4(%eax), %edx
33046 + movw (%eax), %dx
33047 // Now the address of the handler's in %edx
33048 // We call it now: its "iret" drops us home.
33049 - jmp *%edx
33050 + ljmp $__KERNEL_CS, $1f
33051 +1: jmp *%edx
33052
33053 // Every interrupt can come to us here
33054 // But we must truly tell each apart.
33055 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33056 index 4daf9e5..b8d1d0f 100644
33057 --- a/drivers/macintosh/macio_asic.c
33058 +++ b/drivers/macintosh/macio_asic.c
33059 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33060 * MacIO is matched against any Apple ID, it's probe() function
33061 * will then decide wether it applies or not
33062 */
33063 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33064 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33065 .vendor = PCI_VENDOR_ID_APPLE,
33066 .device = PCI_ANY_ID,
33067 .subvendor = PCI_ANY_ID,
33068 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33069 index 1ce84ed..0fdd40a 100644
33070 --- a/drivers/md/dm-ioctl.c
33071 +++ b/drivers/md/dm-ioctl.c
33072 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33073 cmd == DM_LIST_VERSIONS_CMD)
33074 return 0;
33075
33076 - if ((cmd == DM_DEV_CREATE_CMD)) {
33077 + if (cmd == DM_DEV_CREATE_CMD) {
33078 if (!*param->name) {
33079 DMWARN("name not supplied when creating device");
33080 return -EINVAL;
33081 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33082 index 9bfd057..5373ff3 100644
33083 --- a/drivers/md/dm-raid1.c
33084 +++ b/drivers/md/dm-raid1.c
33085 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33086
33087 struct mirror {
33088 struct mirror_set *ms;
33089 - atomic_t error_count;
33090 + atomic_unchecked_t error_count;
33091 unsigned long error_type;
33092 struct dm_dev *dev;
33093 sector_t offset;
33094 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33095 struct mirror *m;
33096
33097 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33098 - if (!atomic_read(&m->error_count))
33099 + if (!atomic_read_unchecked(&m->error_count))
33100 return m;
33101
33102 return NULL;
33103 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33104 * simple way to tell if a device has encountered
33105 * errors.
33106 */
33107 - atomic_inc(&m->error_count);
33108 + atomic_inc_unchecked(&m->error_count);
33109
33110 if (test_and_set_bit(error_type, &m->error_type))
33111 return;
33112 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33113 struct mirror *m = get_default_mirror(ms);
33114
33115 do {
33116 - if (likely(!atomic_read(&m->error_count)))
33117 + if (likely(!atomic_read_unchecked(&m->error_count)))
33118 return m;
33119
33120 if (m-- == ms->mirror)
33121 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33122 {
33123 struct mirror *default_mirror = get_default_mirror(m->ms);
33124
33125 - return !atomic_read(&default_mirror->error_count);
33126 + return !atomic_read_unchecked(&default_mirror->error_count);
33127 }
33128
33129 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33130 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33131 */
33132 if (likely(region_in_sync(ms, region, 1)))
33133 m = choose_mirror(ms, bio->bi_sector);
33134 - else if (m && atomic_read(&m->error_count))
33135 + else if (m && atomic_read_unchecked(&m->error_count))
33136 m = NULL;
33137
33138 if (likely(m))
33139 @@ -848,6 +848,10 @@ static void do_mirror(struct work_struct *work)
33140 static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33141 uint32_t region_size,
33142 struct dm_target *ti,
33143 + struct dm_dirty_log *dl) __size_overflow(1);
33144 +static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33145 + uint32_t region_size,
33146 + struct dm_target *ti,
33147 struct dm_dirty_log *dl)
33148 {
33149 size_t len;
33150 @@ -937,7 +941,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33151 }
33152
33153 ms->mirror[mirror].ms = ms;
33154 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33155 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33156 ms->mirror[mirror].error_type = 0;
33157 ms->mirror[mirror].offset = offset;
33158
33159 @@ -1347,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33160 */
33161 static char device_status_char(struct mirror *m)
33162 {
33163 - if (!atomic_read(&(m->error_count)))
33164 + if (!atomic_read_unchecked(&(m->error_count)))
33165 return 'A';
33166
33167 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33168 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33169 index 3d80cf0..7d98e1a 100644
33170 --- a/drivers/md/dm-stripe.c
33171 +++ b/drivers/md/dm-stripe.c
33172 @@ -20,7 +20,7 @@ struct stripe {
33173 struct dm_dev *dev;
33174 sector_t physical_start;
33175
33176 - atomic_t error_count;
33177 + atomic_unchecked_t error_count;
33178 };
33179
33180 struct stripe_c {
33181 @@ -55,6 +55,7 @@ static void trigger_event(struct work_struct *work)
33182 dm_table_event(sc->ti->table);
33183 }
33184
33185 +static inline struct stripe_c *alloc_context(unsigned int stripes) __size_overflow(1);
33186 static inline struct stripe_c *alloc_context(unsigned int stripes)
33187 {
33188 size_t len;
33189 @@ -192,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33190 kfree(sc);
33191 return r;
33192 }
33193 - atomic_set(&(sc->stripe[i].error_count), 0);
33194 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33195 }
33196
33197 ti->private = sc;
33198 @@ -314,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33199 DMEMIT("%d ", sc->stripes);
33200 for (i = 0; i < sc->stripes; i++) {
33201 DMEMIT("%s ", sc->stripe[i].dev->name);
33202 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33203 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33204 'D' : 'A';
33205 }
33206 buffer[i] = '\0';
33207 @@ -361,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33208 */
33209 for (i = 0; i < sc->stripes; i++)
33210 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33211 - atomic_inc(&(sc->stripe[i].error_count));
33212 - if (atomic_read(&(sc->stripe[i].error_count)) <
33213 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33214 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33215 DM_IO_ERROR_THRESHOLD)
33216 schedule_work(&sc->trigger_event);
33217 }
33218 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33219 index 63cc542..8d45caf3 100644
33220 --- a/drivers/md/dm-table.c
33221 +++ b/drivers/md/dm-table.c
33222 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33223 if (!dev_size)
33224 return 0;
33225
33226 - if ((start >= dev_size) || (start + len > dev_size)) {
33227 + if ((start >= dev_size) || (len > dev_size - start)) {
33228 DMWARN("%s: %s too small for target: "
33229 "start=%llu, len=%llu, dev_size=%llu",
33230 dm_device_name(ti->table->md), bdevname(bdev, b),
33231 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33232 index 237571a..fb6d19b 100644
33233 --- a/drivers/md/dm-thin-metadata.c
33234 +++ b/drivers/md/dm-thin-metadata.c
33235 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33236
33237 pmd->info.tm = tm;
33238 pmd->info.levels = 2;
33239 - pmd->info.value_type.context = pmd->data_sm;
33240 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33241 pmd->info.value_type.size = sizeof(__le64);
33242 pmd->info.value_type.inc = data_block_inc;
33243 pmd->info.value_type.dec = data_block_dec;
33244 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33245
33246 pmd->bl_info.tm = tm;
33247 pmd->bl_info.levels = 1;
33248 - pmd->bl_info.value_type.context = pmd->data_sm;
33249 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33250 pmd->bl_info.value_type.size = sizeof(__le64);
33251 pmd->bl_info.value_type.inc = data_block_inc;
33252 pmd->bl_info.value_type.dec = data_block_dec;
33253 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33254 index b89c548..2af3ce4 100644
33255 --- a/drivers/md/dm.c
33256 +++ b/drivers/md/dm.c
33257 @@ -176,9 +176,9 @@ struct mapped_device {
33258 /*
33259 * Event handling.
33260 */
33261 - atomic_t event_nr;
33262 + atomic_unchecked_t event_nr;
33263 wait_queue_head_t eventq;
33264 - atomic_t uevent_seq;
33265 + atomic_unchecked_t uevent_seq;
33266 struct list_head uevent_list;
33267 spinlock_t uevent_lock; /* Protect access to uevent_list */
33268
33269 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33270 rwlock_init(&md->map_lock);
33271 atomic_set(&md->holders, 1);
33272 atomic_set(&md->open_count, 0);
33273 - atomic_set(&md->event_nr, 0);
33274 - atomic_set(&md->uevent_seq, 0);
33275 + atomic_set_unchecked(&md->event_nr, 0);
33276 + atomic_set_unchecked(&md->uevent_seq, 0);
33277 INIT_LIST_HEAD(&md->uevent_list);
33278 spin_lock_init(&md->uevent_lock);
33279
33280 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33281
33282 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33283
33284 - atomic_inc(&md->event_nr);
33285 + atomic_inc_unchecked(&md->event_nr);
33286 wake_up(&md->eventq);
33287 }
33288
33289 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33290
33291 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33292 {
33293 - return atomic_add_return(1, &md->uevent_seq);
33294 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33295 }
33296
33297 uint32_t dm_get_event_nr(struct mapped_device *md)
33298 {
33299 - return atomic_read(&md->event_nr);
33300 + return atomic_read_unchecked(&md->event_nr);
33301 }
33302
33303 int dm_wait_event(struct mapped_device *md, int event_nr)
33304 {
33305 return wait_event_interruptible(md->eventq,
33306 - (event_nr != atomic_read(&md->event_nr)));
33307 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33308 }
33309
33310 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33311 diff --git a/drivers/md/md.c b/drivers/md/md.c
33312 index 6acc846..80a6b96 100644
33313 --- a/drivers/md/md.c
33314 +++ b/drivers/md/md.c
33315 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33316 * start build, activate spare
33317 */
33318 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33319 -static atomic_t md_event_count;
33320 +static atomic_unchecked_t md_event_count;
33321 void md_new_event(struct mddev *mddev)
33322 {
33323 - atomic_inc(&md_event_count);
33324 + atomic_inc_unchecked(&md_event_count);
33325 wake_up(&md_event_waiters);
33326 }
33327 EXPORT_SYMBOL_GPL(md_new_event);
33328 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33329 */
33330 static void md_new_event_inintr(struct mddev *mddev)
33331 {
33332 - atomic_inc(&md_event_count);
33333 + atomic_inc_unchecked(&md_event_count);
33334 wake_up(&md_event_waiters);
33335 }
33336
33337 @@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33338
33339 rdev->preferred_minor = 0xffff;
33340 rdev->data_offset = le64_to_cpu(sb->data_offset);
33341 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33342 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33343
33344 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33345 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33346 @@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33347 else
33348 sb->resync_offset = cpu_to_le64(0);
33349
33350 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33351 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33352
33353 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33354 sb->size = cpu_to_le64(mddev->dev_sectors);
33355 @@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33356 static ssize_t
33357 errors_show(struct md_rdev *rdev, char *page)
33358 {
33359 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33360 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33361 }
33362
33363 static ssize_t
33364 @@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33365 char *e;
33366 unsigned long n = simple_strtoul(buf, &e, 10);
33367 if (*buf && (*e == 0 || *e == '\n')) {
33368 - atomic_set(&rdev->corrected_errors, n);
33369 + atomic_set_unchecked(&rdev->corrected_errors, n);
33370 return len;
33371 }
33372 return -EINVAL;
33373 @@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
33374 rdev->sb_loaded = 0;
33375 rdev->bb_page = NULL;
33376 atomic_set(&rdev->nr_pending, 0);
33377 - atomic_set(&rdev->read_errors, 0);
33378 - atomic_set(&rdev->corrected_errors, 0);
33379 + atomic_set_unchecked(&rdev->read_errors, 0);
33380 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33381
33382 INIT_LIST_HEAD(&rdev->same_set);
33383 init_waitqueue_head(&rdev->blocked_wait);
33384 @@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33385
33386 spin_unlock(&pers_lock);
33387 seq_printf(seq, "\n");
33388 - seq->poll_event = atomic_read(&md_event_count);
33389 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33390 return 0;
33391 }
33392 if (v == (void*)2) {
33393 @@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33394 chunk_kb ? "KB" : "B");
33395 if (bitmap->file) {
33396 seq_printf(seq, ", file: ");
33397 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33398 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33399 }
33400
33401 seq_printf(seq, "\n");
33402 @@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33403 return error;
33404
33405 seq = file->private_data;
33406 - seq->poll_event = atomic_read(&md_event_count);
33407 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33408 return error;
33409 }
33410
33411 @@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33412 /* always allow read */
33413 mask = POLLIN | POLLRDNORM;
33414
33415 - if (seq->poll_event != atomic_read(&md_event_count))
33416 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33417 mask |= POLLERR | POLLPRI;
33418 return mask;
33419 }
33420 @@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33421 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33422 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33423 (int)part_stat_read(&disk->part0, sectors[1]) -
33424 - atomic_read(&disk->sync_io);
33425 + atomic_read_unchecked(&disk->sync_io);
33426 /* sync IO will cause sync_io to increase before the disk_stats
33427 * as sync_io is counted when a request starts, and
33428 * disk_stats is counted when it completes.
33429 diff --git a/drivers/md/md.h b/drivers/md/md.h
33430 index 44c63df..b795d1a 100644
33431 --- a/drivers/md/md.h
33432 +++ b/drivers/md/md.h
33433 @@ -93,13 +93,13 @@ struct md_rdev {
33434 * only maintained for arrays that
33435 * support hot removal
33436 */
33437 - atomic_t read_errors; /* number of consecutive read errors that
33438 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33439 * we have tried to ignore.
33440 */
33441 struct timespec last_read_error; /* monotonic time since our
33442 * last read error
33443 */
33444 - atomic_t corrected_errors; /* number of corrected read errors,
33445 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33446 * for reporting to userspace and storing
33447 * in superblock.
33448 */
33449 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33450
33451 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33452 {
33453 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33454 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33455 }
33456
33457 struct md_personality
33458 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33459 index 50ed53b..4f29d7d 100644
33460 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33461 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33462 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33463 /*----------------------------------------------------------------*/
33464
33465 struct sm_checker {
33466 - struct dm_space_map sm;
33467 + dm_space_map_no_const sm;
33468
33469 struct count_array old_counts;
33470 struct count_array counts;
33471 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33472 index fc469ba..2d91555 100644
33473 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33474 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33475 @@ -23,7 +23,7 @@
33476 * Space map interface.
33477 */
33478 struct sm_disk {
33479 - struct dm_space_map sm;
33480 + dm_space_map_no_const sm;
33481
33482 struct ll_disk ll;
33483 struct ll_disk old_ll;
33484 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33485 index e89ae5e..062e4c2 100644
33486 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33487 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33488 @@ -43,7 +43,7 @@ struct block_op {
33489 };
33490
33491 struct sm_metadata {
33492 - struct dm_space_map sm;
33493 + dm_space_map_no_const sm;
33494
33495 struct ll_disk ll;
33496 struct ll_disk old_ll;
33497 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33498 index 1cbfc6b..56e1dbb 100644
33499 --- a/drivers/md/persistent-data/dm-space-map.h
33500 +++ b/drivers/md/persistent-data/dm-space-map.h
33501 @@ -60,6 +60,7 @@ struct dm_space_map {
33502 int (*root_size)(struct dm_space_map *sm, size_t *result);
33503 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33504 };
33505 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33506
33507 /*----------------------------------------------------------------*/
33508
33509 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33510 index edc735a..e9b97f1 100644
33511 --- a/drivers/md/raid1.c
33512 +++ b/drivers/md/raid1.c
33513 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33514 if (r1_sync_page_io(rdev, sect, s,
33515 bio->bi_io_vec[idx].bv_page,
33516 READ) != 0)
33517 - atomic_add(s, &rdev->corrected_errors);
33518 + atomic_add_unchecked(s, &rdev->corrected_errors);
33519 }
33520 sectors -= s;
33521 sect += s;
33522 @@ -1859,7 +1859,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33523 test_bit(In_sync, &rdev->flags)) {
33524 if (r1_sync_page_io(rdev, sect, s,
33525 conf->tmppage, READ)) {
33526 - atomic_add(s, &rdev->corrected_errors);
33527 + atomic_add_unchecked(s, &rdev->corrected_errors);
33528 printk(KERN_INFO
33529 "md/raid1:%s: read error corrected "
33530 "(%d sectors at %llu on %s)\n",
33531 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33532 index 1898389..a3aa617 100644
33533 --- a/drivers/md/raid10.c
33534 +++ b/drivers/md/raid10.c
33535 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33536 /* The write handler will notice the lack of
33537 * R10BIO_Uptodate and record any errors etc
33538 */
33539 - atomic_add(r10_bio->sectors,
33540 + atomic_add_unchecked(r10_bio->sectors,
33541 &conf->mirrors[d].rdev->corrected_errors);
33542
33543 /* for reconstruct, we always reschedule after a read.
33544 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33545 {
33546 struct timespec cur_time_mon;
33547 unsigned long hours_since_last;
33548 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33549 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33550
33551 ktime_get_ts(&cur_time_mon);
33552
33553 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33554 * overflowing the shift of read_errors by hours_since_last.
33555 */
33556 if (hours_since_last >= 8 * sizeof(read_errors))
33557 - atomic_set(&rdev->read_errors, 0);
33558 + atomic_set_unchecked(&rdev->read_errors, 0);
33559 else
33560 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33561 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33562 }
33563
33564 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33565 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33566 return;
33567
33568 check_decay_read_errors(mddev, rdev);
33569 - atomic_inc(&rdev->read_errors);
33570 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33571 + atomic_inc_unchecked(&rdev->read_errors);
33572 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33573 char b[BDEVNAME_SIZE];
33574 bdevname(rdev->bdev, b);
33575
33576 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33577 "md/raid10:%s: %s: Raid device exceeded "
33578 "read_error threshold [cur %d:max %d]\n",
33579 mdname(mddev), b,
33580 - atomic_read(&rdev->read_errors), max_read_errors);
33581 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33582 printk(KERN_NOTICE
33583 "md/raid10:%s: %s: Failing raid device\n",
33584 mdname(mddev), b);
33585 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33586 (unsigned long long)(
33587 sect + rdev->data_offset),
33588 bdevname(rdev->bdev, b));
33589 - atomic_add(s, &rdev->corrected_errors);
33590 + atomic_add_unchecked(s, &rdev->corrected_errors);
33591 }
33592
33593 rdev_dec_pending(rdev, mddev);
33594 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33595 index 360f2b9..08b5382 100644
33596 --- a/drivers/md/raid5.c
33597 +++ b/drivers/md/raid5.c
33598 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33599 (unsigned long long)(sh->sector
33600 + rdev->data_offset),
33601 bdevname(rdev->bdev, b));
33602 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33603 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33604 clear_bit(R5_ReadError, &sh->dev[i].flags);
33605 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33606 }
33607 - if (atomic_read(&rdev->read_errors))
33608 - atomic_set(&rdev->read_errors, 0);
33609 + if (atomic_read_unchecked(&rdev->read_errors))
33610 + atomic_set_unchecked(&rdev->read_errors, 0);
33611 } else {
33612 const char *bdn = bdevname(rdev->bdev, b);
33613 int retry = 0;
33614
33615 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33616 - atomic_inc(&rdev->read_errors);
33617 + atomic_inc_unchecked(&rdev->read_errors);
33618 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33619 printk_ratelimited(
33620 KERN_WARNING
33621 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33622 (unsigned long long)(sh->sector
33623 + rdev->data_offset),
33624 bdn);
33625 - else if (atomic_read(&rdev->read_errors)
33626 + else if (atomic_read_unchecked(&rdev->read_errors)
33627 > conf->max_nr_stripes)
33628 printk(KERN_WARNING
33629 "md/raid:%s: Too many read errors, failing device %s.\n",
33630 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33631 index ce4f858..7bcfb46 100644
33632 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33633 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33634 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33635 .subvendor = _subvend, .subdevice = _subdev, \
33636 .driver_data = (unsigned long)&_driverdata }
33637
33638 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33639 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33640 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33641 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33642 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33643 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33644 index a7d876f..8c21b61 100644
33645 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33646 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33647 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33648 union {
33649 dmx_ts_cb ts;
33650 dmx_section_cb sec;
33651 - } cb;
33652 + } __no_const cb;
33653
33654 struct dvb_demux *demux;
33655 void *priv;
33656 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33657 index 00a6732..70a682e 100644
33658 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33659 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33660 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33661 const struct dvb_device *template, void *priv, int type)
33662 {
33663 struct dvb_device *dvbdev;
33664 - struct file_operations *dvbdevfops;
33665 + file_operations_no_const *dvbdevfops;
33666 struct device *clsdev;
33667 int minor;
33668 int id;
33669 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33670 index 3940bb0..fb3952a 100644
33671 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33672 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33673 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33674
33675 struct dib0700_adapter_state {
33676 int (*set_param_save) (struct dvb_frontend *);
33677 -};
33678 +} __no_const;
33679
33680 static int dib7070_set_param_override(struct dvb_frontend *fe)
33681 {
33682 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33683 index 451c5a7..649f711 100644
33684 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33685 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33686 @@ -95,7 +95,7 @@ struct su3000_state {
33687
33688 struct s6x0_state {
33689 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33690 -};
33691 +} __no_const;
33692
33693 /* debug */
33694 static int dvb_usb_dw2102_debug;
33695 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33696 index 404f63a..4796533 100644
33697 --- a/drivers/media/dvb/frontends/dib3000.h
33698 +++ b/drivers/media/dvb/frontends/dib3000.h
33699 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33700 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33701 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33702 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33703 -};
33704 +} __no_const;
33705
33706 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33707 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33708 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33709 index 8418c02..8555013 100644
33710 --- a/drivers/media/dvb/ngene/ngene-cards.c
33711 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33712 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33713
33714 /****************************************************************************/
33715
33716 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33717 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33718 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33719 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33720 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33721 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33722 index 16a089f..ab1667d 100644
33723 --- a/drivers/media/radio/radio-cadet.c
33724 +++ b/drivers/media/radio/radio-cadet.c
33725 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33726 unsigned char readbuf[RDS_BUFFER];
33727 int i = 0;
33728
33729 + if (count > RDS_BUFFER)
33730 + return -EFAULT;
33731 mutex_lock(&dev->lock);
33732 if (dev->rdsstat == 0) {
33733 dev->rdsstat = 1;
33734 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33735 index 9cde353..8c6a1c3 100644
33736 --- a/drivers/media/video/au0828/au0828.h
33737 +++ b/drivers/media/video/au0828/au0828.h
33738 @@ -191,7 +191,7 @@ struct au0828_dev {
33739
33740 /* I2C */
33741 struct i2c_adapter i2c_adap;
33742 - struct i2c_algorithm i2c_algo;
33743 + i2c_algorithm_no_const i2c_algo;
33744 struct i2c_client i2c_client;
33745 u32 i2c_rc;
33746
33747 diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
33748 index ee91e295..04ad048 100644
33749 --- a/drivers/media/video/cpia2/cpia2_core.c
33750 +++ b/drivers/media/video/cpia2/cpia2_core.c
33751 @@ -86,6 +86,7 @@ static inline unsigned long kvirt_to_pa(unsigned long adr)
33752 return ret;
33753 }
33754
33755 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33756 static void *rvmalloc(unsigned long size)
33757 {
33758 void *mem;
33759 diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
33760 index 82d195b..181103c 100644
33761 --- a/drivers/media/video/cx18/cx18-alsa-pcm.c
33762 +++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
33763 @@ -229,6 +229,8 @@ static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
33764
33765
33766 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33767 + size_t size) __size_overflow(2);
33768 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33769 size_t size)
33770 {
33771 struct snd_pcm_runtime *runtime = subs->runtime;
33772 diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
33773 index a2c2b7d..8f1bec7 100644
33774 --- a/drivers/media/video/cx231xx/cx231xx-audio.c
33775 +++ b/drivers/media/video/cx231xx/cx231xx-audio.c
33776 @@ -389,6 +389,8 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
33777 }
33778
33779 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33780 + size_t size) __size_overflow(2);
33781 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33782 size_t size)
33783 {
33784 struct snd_pcm_runtime *runtime = subs->runtime;
33785 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33786 index 04bf662..e0ac026 100644
33787 --- a/drivers/media/video/cx88/cx88-alsa.c
33788 +++ b/drivers/media/video/cx88/cx88-alsa.c
33789 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33790 * Only boards with eeprom and byte 1 at eeprom=1 have it
33791 */
33792
33793 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33794 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33795 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33796 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33797 {0, }
33798 diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
33799 index e2a7b77..753d0ee 100644
33800 --- a/drivers/media/video/em28xx/em28xx-audio.c
33801 +++ b/drivers/media/video/em28xx/em28xx-audio.c
33802 @@ -225,6 +225,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
33803 }
33804
33805 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33806 + size_t size) __size_overflow(2);
33807 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
33808 size_t size)
33809 {
33810 struct snd_pcm_runtime *runtime = subs->runtime;
33811 diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
33812 index b09a3c8..6dcba0a 100644
33813 --- a/drivers/media/video/meye.c
33814 +++ b/drivers/media/video/meye.c
33815 @@ -72,6 +72,7 @@ static struct meye meye;
33816 /****************************************************************************/
33817 /* Memory allocation routines (stolen from bttv-driver.c) */
33818 /****************************************************************************/
33819 +static void *rvmalloc(unsigned long size) __size_overflow(1);
33820 static void *rvmalloc(unsigned long size)
33821 {
33822 void *mem;
33823 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33824 index 1fb7d5b..3901e77 100644
33825 --- a/drivers/media/video/omap/omap_vout.c
33826 +++ b/drivers/media/video/omap/omap_vout.c
33827 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33828 OMAP_VIDEO2,
33829 };
33830
33831 -static struct videobuf_queue_ops video_vbq_ops;
33832 /* Variables configurable through module params*/
33833 static u32 video1_numbuffers = 3;
33834 static u32 video2_numbuffers = 3;
33835 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33836 {
33837 struct videobuf_queue *q;
33838 struct omap_vout_device *vout = NULL;
33839 + static struct videobuf_queue_ops video_vbq_ops = {
33840 + .buf_setup = omap_vout_buffer_setup,
33841 + .buf_prepare = omap_vout_buffer_prepare,
33842 + .buf_release = omap_vout_buffer_release,
33843 + .buf_queue = omap_vout_buffer_queue,
33844 + };
33845
33846 vout = video_drvdata(file);
33847 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33848 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33849 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33850
33851 q = &vout->vbq;
33852 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33853 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33854 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33855 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33856 spin_lock_init(&vout->vbq_lock);
33857
33858 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33859 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33860 index 305e6aa..0143317 100644
33861 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33862 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33863 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33864
33865 /* I2C stuff */
33866 struct i2c_adapter i2c_adap;
33867 - struct i2c_algorithm i2c_algo;
33868 + i2c_algorithm_no_const i2c_algo;
33869 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33870 int i2c_cx25840_hack_state;
33871 int i2c_linked;
33872 diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
33873 index 2fd38a0..ddec3c4 100644
33874 --- a/drivers/media/video/saa7164/saa7164-encoder.c
33875 +++ b/drivers/media/video/saa7164/saa7164-encoder.c
33876 @@ -1136,6 +1136,8 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
33877 }
33878
33879 static ssize_t fops_read(struct file *file, char __user *buffer,
33880 + size_t count, loff_t *pos) __size_overflow(3);
33881 +static ssize_t fops_read(struct file *file, char __user *buffer,
33882 size_t count, loff_t *pos)
33883 {
33884 struct saa7164_encoder_fh *fh = file->private_data;
33885 diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
33886 index e2e0341..b80056c 100644
33887 --- a/drivers/media/video/saa7164/saa7164-vbi.c
33888 +++ b/drivers/media/video/saa7164/saa7164-vbi.c
33889 @@ -1081,6 +1081,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
33890 }
33891
33892 static ssize_t fops_read(struct file *file, char __user *buffer,
33893 + size_t count, loff_t *pos) __size_overflow(3);
33894 +static ssize_t fops_read(struct file *file, char __user *buffer,
33895 size_t count, loff_t *pos)
33896 {
33897 struct saa7164_vbi_fh *fh = file->private_data;
33898 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33899 index 4ed1c7c2..8f15e13 100644
33900 --- a/drivers/media/video/timblogiw.c
33901 +++ b/drivers/media/video/timblogiw.c
33902 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33903
33904 /* Platform device functions */
33905
33906 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33907 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33908 .vidioc_querycap = timblogiw_querycap,
33909 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33910 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33911 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33912 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33913 };
33914
33915 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33916 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33917 .owner = THIS_MODULE,
33918 .open = timblogiw_open,
33919 .release = timblogiw_close,
33920 diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
33921 index c969111..a7910f4 100644
33922 --- a/drivers/media/video/videobuf-dma-contig.c
33923 +++ b/drivers/media/video/videobuf-dma-contig.c
33924 @@ -184,6 +184,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
33925 return ret;
33926 }
33927
33928 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33929 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33930 {
33931 struct videobuf_dma_contig_memory *mem;
33932 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
33933 index f300dea..5fc9c4a 100644
33934 --- a/drivers/media/video/videobuf-dma-sg.c
33935 +++ b/drivers/media/video/videobuf-dma-sg.c
33936 @@ -419,6 +419,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
33937 struct videobuf_dma_sg_memory
33938 */
33939
33940 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33941 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33942 {
33943 struct videobuf_dma_sg_memory *mem;
33944 diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
33945 index df14258..12cc7a3 100644
33946 --- a/drivers/media/video/videobuf-vmalloc.c
33947 +++ b/drivers/media/video/videobuf-vmalloc.c
33948 @@ -135,6 +135,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
33949 struct videobuf_dma_sg_memory
33950 */
33951
33952 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
33953 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
33954 {
33955 struct videobuf_vmalloc_memory *mem;
33956 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33957 index a7dc467..a55c423 100644
33958 --- a/drivers/message/fusion/mptbase.c
33959 +++ b/drivers/message/fusion/mptbase.c
33960 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33961 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33962 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33963
33964 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33965 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33966 +#else
33967 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33968 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33969 +#endif
33970 +
33971 /*
33972 * Rounding UP to nearest 4-kB boundary here...
33973 */
33974 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33975 index 551262e..7551198 100644
33976 --- a/drivers/message/fusion/mptsas.c
33977 +++ b/drivers/message/fusion/mptsas.c
33978 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33979 return 0;
33980 }
33981
33982 +static inline void
33983 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33984 +{
33985 + if (phy_info->port_details) {
33986 + phy_info->port_details->rphy = rphy;
33987 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33988 + ioc->name, rphy));
33989 + }
33990 +
33991 + if (rphy) {
33992 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33993 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33994 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33995 + ioc->name, rphy, rphy->dev.release));
33996 + }
33997 +}
33998 +
33999 /* no mutex */
34000 static void
34001 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34002 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34003 return NULL;
34004 }
34005
34006 -static inline void
34007 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34008 -{
34009 - if (phy_info->port_details) {
34010 - phy_info->port_details->rphy = rphy;
34011 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34012 - ioc->name, rphy));
34013 - }
34014 -
34015 - if (rphy) {
34016 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34017 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34018 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34019 - ioc->name, rphy, rphy->dev.release));
34020 - }
34021 -}
34022 -
34023 static inline struct sas_port *
34024 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34025 {
34026 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34027 index 0c3ced7..1fe34ec 100644
34028 --- a/drivers/message/fusion/mptscsih.c
34029 +++ b/drivers/message/fusion/mptscsih.c
34030 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34031
34032 h = shost_priv(SChost);
34033
34034 - if (h) {
34035 - if (h->info_kbuf == NULL)
34036 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34037 - return h->info_kbuf;
34038 - h->info_kbuf[0] = '\0';
34039 + if (!h)
34040 + return NULL;
34041
34042 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34043 - h->info_kbuf[size-1] = '\0';
34044 - }
34045 + if (h->info_kbuf == NULL)
34046 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34047 + return h->info_kbuf;
34048 + h->info_kbuf[0] = '\0';
34049 +
34050 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34051 + h->info_kbuf[size-1] = '\0';
34052
34053 return h->info_kbuf;
34054 }
34055 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34056 index 6d115c7..58ff7fd 100644
34057 --- a/drivers/message/i2o/i2o_proc.c
34058 +++ b/drivers/message/i2o/i2o_proc.c
34059 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34060 "Array Controller Device"
34061 };
34062
34063 -static char *chtostr(u8 * chars, int n)
34064 -{
34065 - char tmp[256];
34066 - tmp[0] = 0;
34067 - return strncat(tmp, (char *)chars, n);
34068 -}
34069 -
34070 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34071 char *group)
34072 {
34073 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34074
34075 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34076 seq_printf(seq, "%-#8x", ddm_table.module_id);
34077 - seq_printf(seq, "%-29s",
34078 - chtostr(ddm_table.module_name_version, 28));
34079 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34080 seq_printf(seq, "%9d ", ddm_table.data_size);
34081 seq_printf(seq, "%8d", ddm_table.code_size);
34082
34083 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34084
34085 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34086 seq_printf(seq, "%-#8x", dst->module_id);
34087 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34088 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34089 + seq_printf(seq, "%-.28s", dst->module_name_version);
34090 + seq_printf(seq, "%-.8s", dst->date);
34091 seq_printf(seq, "%8d ", dst->module_size);
34092 seq_printf(seq, "%8d ", dst->mpb_size);
34093 seq_printf(seq, "0x%04x", dst->module_flags);
34094 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34095 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34096 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34097 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34098 - seq_printf(seq, "Vendor info : %s\n",
34099 - chtostr((u8 *) (work32 + 2), 16));
34100 - seq_printf(seq, "Product info : %s\n",
34101 - chtostr((u8 *) (work32 + 6), 16));
34102 - seq_printf(seq, "Description : %s\n",
34103 - chtostr((u8 *) (work32 + 10), 16));
34104 - seq_printf(seq, "Product rev. : %s\n",
34105 - chtostr((u8 *) (work32 + 14), 8));
34106 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34107 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34108 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34109 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34110
34111 seq_printf(seq, "Serial number : ");
34112 print_serial_number(seq, (u8 *) (work32 + 16),
34113 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34114 }
34115
34116 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34117 - seq_printf(seq, "Module name : %s\n",
34118 - chtostr(result.module_name, 24));
34119 - seq_printf(seq, "Module revision : %s\n",
34120 - chtostr(result.module_rev, 8));
34121 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34122 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34123
34124 seq_printf(seq, "Serial number : ");
34125 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34126 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34127 return 0;
34128 }
34129
34130 - seq_printf(seq, "Device name : %s\n",
34131 - chtostr(result.device_name, 64));
34132 - seq_printf(seq, "Service name : %s\n",
34133 - chtostr(result.service_name, 64));
34134 - seq_printf(seq, "Physical name : %s\n",
34135 - chtostr(result.physical_location, 64));
34136 - seq_printf(seq, "Instance number : %s\n",
34137 - chtostr(result.instance_number, 4));
34138 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34139 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34140 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34141 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34142
34143 return 0;
34144 }
34145 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34146 index a8c08f3..155fe3d 100644
34147 --- a/drivers/message/i2o/iop.c
34148 +++ b/drivers/message/i2o/iop.c
34149 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34150
34151 spin_lock_irqsave(&c->context_list_lock, flags);
34152
34153 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34154 - atomic_inc(&c->context_list_counter);
34155 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34156 + atomic_inc_unchecked(&c->context_list_counter);
34157
34158 - entry->context = atomic_read(&c->context_list_counter);
34159 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34160
34161 list_add(&entry->list, &c->context_list);
34162
34163 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34164
34165 #if BITS_PER_LONG == 64
34166 spin_lock_init(&c->context_list_lock);
34167 - atomic_set(&c->context_list_counter, 0);
34168 + atomic_set_unchecked(&c->context_list_counter, 0);
34169 INIT_LIST_HEAD(&c->context_list);
34170 #endif
34171
34172 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34173 index 7ce65f4..e66e9bc 100644
34174 --- a/drivers/mfd/abx500-core.c
34175 +++ b/drivers/mfd/abx500-core.c
34176 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34177
34178 struct abx500_device_entry {
34179 struct list_head list;
34180 - struct abx500_ops ops;
34181 + abx500_ops_no_const ops;
34182 struct device *dev;
34183 };
34184
34185 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34186 index a9223ed..4127b13 100644
34187 --- a/drivers/mfd/janz-cmodio.c
34188 +++ b/drivers/mfd/janz-cmodio.c
34189 @@ -13,6 +13,7 @@
34190
34191 #include <linux/kernel.h>
34192 #include <linux/module.h>
34193 +#include <linux/slab.h>
34194 #include <linux/init.h>
34195 #include <linux/pci.h>
34196 #include <linux/interrupt.h>
34197 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34198 index a981e2a..5ca0c8b 100644
34199 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34200 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34201 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34202 * the lid is closed. This leads to interrupts as soon as a little move
34203 * is done.
34204 */
34205 - atomic_inc(&lis3->count);
34206 + atomic_inc_unchecked(&lis3->count);
34207
34208 wake_up_interruptible(&lis3->misc_wait);
34209 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34210 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34211 if (lis3->pm_dev)
34212 pm_runtime_get_sync(lis3->pm_dev);
34213
34214 - atomic_set(&lis3->count, 0);
34215 + atomic_set_unchecked(&lis3->count, 0);
34216 return 0;
34217 }
34218
34219 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34220 add_wait_queue(&lis3->misc_wait, &wait);
34221 while (true) {
34222 set_current_state(TASK_INTERRUPTIBLE);
34223 - data = atomic_xchg(&lis3->count, 0);
34224 + data = atomic_xchg_unchecked(&lis3->count, 0);
34225 if (data)
34226 break;
34227
34228 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34229 struct lis3lv02d, miscdev);
34230
34231 poll_wait(file, &lis3->misc_wait, wait);
34232 - if (atomic_read(&lis3->count))
34233 + if (atomic_read_unchecked(&lis3->count))
34234 return POLLIN | POLLRDNORM;
34235 return 0;
34236 }
34237 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34238 index 2b1482a..5d33616 100644
34239 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34240 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34241 @@ -266,7 +266,7 @@ struct lis3lv02d {
34242 struct input_polled_dev *idev; /* input device */
34243 struct platform_device *pdev; /* platform device */
34244 struct regulator_bulk_data regulators[2];
34245 - atomic_t count; /* interrupt count after last read */
34246 + atomic_unchecked_t count; /* interrupt count after last read */
34247 union axis_conversion ac; /* hw -> logical axis */
34248 int mapped_btns[3];
34249
34250 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34251 index 2f30bad..c4c13d0 100644
34252 --- a/drivers/misc/sgi-gru/gruhandles.c
34253 +++ b/drivers/misc/sgi-gru/gruhandles.c
34254 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34255 unsigned long nsec;
34256
34257 nsec = CLKS2NSEC(clks);
34258 - atomic_long_inc(&mcs_op_statistics[op].count);
34259 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34260 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34261 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34262 if (mcs_op_statistics[op].max < nsec)
34263 mcs_op_statistics[op].max = nsec;
34264 }
34265 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34266 index 950dbe9..eeef0f8 100644
34267 --- a/drivers/misc/sgi-gru/gruprocfs.c
34268 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34269 @@ -32,9 +32,9 @@
34270
34271 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34272
34273 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34274 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34275 {
34276 - unsigned long val = atomic_long_read(v);
34277 + unsigned long val = atomic_long_read_unchecked(v);
34278
34279 seq_printf(s, "%16lu %s\n", val, id);
34280 }
34281 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34282
34283 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34284 for (op = 0; op < mcsop_last; op++) {
34285 - count = atomic_long_read(&mcs_op_statistics[op].count);
34286 - total = atomic_long_read(&mcs_op_statistics[op].total);
34287 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34288 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34289 max = mcs_op_statistics[op].max;
34290 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34291 count ? total / count : 0, max);
34292 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34293 index 5c3ce24..4915ccb 100644
34294 --- a/drivers/misc/sgi-gru/grutables.h
34295 +++ b/drivers/misc/sgi-gru/grutables.h
34296 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34297 * GRU statistics.
34298 */
34299 struct gru_stats_s {
34300 - atomic_long_t vdata_alloc;
34301 - atomic_long_t vdata_free;
34302 - atomic_long_t gts_alloc;
34303 - atomic_long_t gts_free;
34304 - atomic_long_t gms_alloc;
34305 - atomic_long_t gms_free;
34306 - atomic_long_t gts_double_allocate;
34307 - atomic_long_t assign_context;
34308 - atomic_long_t assign_context_failed;
34309 - atomic_long_t free_context;
34310 - atomic_long_t load_user_context;
34311 - atomic_long_t load_kernel_context;
34312 - atomic_long_t lock_kernel_context;
34313 - atomic_long_t unlock_kernel_context;
34314 - atomic_long_t steal_user_context;
34315 - atomic_long_t steal_kernel_context;
34316 - atomic_long_t steal_context_failed;
34317 - atomic_long_t nopfn;
34318 - atomic_long_t asid_new;
34319 - atomic_long_t asid_next;
34320 - atomic_long_t asid_wrap;
34321 - atomic_long_t asid_reuse;
34322 - atomic_long_t intr;
34323 - atomic_long_t intr_cbr;
34324 - atomic_long_t intr_tfh;
34325 - atomic_long_t intr_spurious;
34326 - atomic_long_t intr_mm_lock_failed;
34327 - atomic_long_t call_os;
34328 - atomic_long_t call_os_wait_queue;
34329 - atomic_long_t user_flush_tlb;
34330 - atomic_long_t user_unload_context;
34331 - atomic_long_t user_exception;
34332 - atomic_long_t set_context_option;
34333 - atomic_long_t check_context_retarget_intr;
34334 - atomic_long_t check_context_unload;
34335 - atomic_long_t tlb_dropin;
34336 - atomic_long_t tlb_preload_page;
34337 - atomic_long_t tlb_dropin_fail_no_asid;
34338 - atomic_long_t tlb_dropin_fail_upm;
34339 - atomic_long_t tlb_dropin_fail_invalid;
34340 - atomic_long_t tlb_dropin_fail_range_active;
34341 - atomic_long_t tlb_dropin_fail_idle;
34342 - atomic_long_t tlb_dropin_fail_fmm;
34343 - atomic_long_t tlb_dropin_fail_no_exception;
34344 - atomic_long_t tfh_stale_on_fault;
34345 - atomic_long_t mmu_invalidate_range;
34346 - atomic_long_t mmu_invalidate_page;
34347 - atomic_long_t flush_tlb;
34348 - atomic_long_t flush_tlb_gru;
34349 - atomic_long_t flush_tlb_gru_tgh;
34350 - atomic_long_t flush_tlb_gru_zero_asid;
34351 + atomic_long_unchecked_t vdata_alloc;
34352 + atomic_long_unchecked_t vdata_free;
34353 + atomic_long_unchecked_t gts_alloc;
34354 + atomic_long_unchecked_t gts_free;
34355 + atomic_long_unchecked_t gms_alloc;
34356 + atomic_long_unchecked_t gms_free;
34357 + atomic_long_unchecked_t gts_double_allocate;
34358 + atomic_long_unchecked_t assign_context;
34359 + atomic_long_unchecked_t assign_context_failed;
34360 + atomic_long_unchecked_t free_context;
34361 + atomic_long_unchecked_t load_user_context;
34362 + atomic_long_unchecked_t load_kernel_context;
34363 + atomic_long_unchecked_t lock_kernel_context;
34364 + atomic_long_unchecked_t unlock_kernel_context;
34365 + atomic_long_unchecked_t steal_user_context;
34366 + atomic_long_unchecked_t steal_kernel_context;
34367 + atomic_long_unchecked_t steal_context_failed;
34368 + atomic_long_unchecked_t nopfn;
34369 + atomic_long_unchecked_t asid_new;
34370 + atomic_long_unchecked_t asid_next;
34371 + atomic_long_unchecked_t asid_wrap;
34372 + atomic_long_unchecked_t asid_reuse;
34373 + atomic_long_unchecked_t intr;
34374 + atomic_long_unchecked_t intr_cbr;
34375 + atomic_long_unchecked_t intr_tfh;
34376 + atomic_long_unchecked_t intr_spurious;
34377 + atomic_long_unchecked_t intr_mm_lock_failed;
34378 + atomic_long_unchecked_t call_os;
34379 + atomic_long_unchecked_t call_os_wait_queue;
34380 + atomic_long_unchecked_t user_flush_tlb;
34381 + atomic_long_unchecked_t user_unload_context;
34382 + atomic_long_unchecked_t user_exception;
34383 + atomic_long_unchecked_t set_context_option;
34384 + atomic_long_unchecked_t check_context_retarget_intr;
34385 + atomic_long_unchecked_t check_context_unload;
34386 + atomic_long_unchecked_t tlb_dropin;
34387 + atomic_long_unchecked_t tlb_preload_page;
34388 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34389 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34390 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34391 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34392 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34393 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34394 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34395 + atomic_long_unchecked_t tfh_stale_on_fault;
34396 + atomic_long_unchecked_t mmu_invalidate_range;
34397 + atomic_long_unchecked_t mmu_invalidate_page;
34398 + atomic_long_unchecked_t flush_tlb;
34399 + atomic_long_unchecked_t flush_tlb_gru;
34400 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34401 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34402
34403 - atomic_long_t copy_gpa;
34404 - atomic_long_t read_gpa;
34405 + atomic_long_unchecked_t copy_gpa;
34406 + atomic_long_unchecked_t read_gpa;
34407
34408 - atomic_long_t mesq_receive;
34409 - atomic_long_t mesq_receive_none;
34410 - atomic_long_t mesq_send;
34411 - atomic_long_t mesq_send_failed;
34412 - atomic_long_t mesq_noop;
34413 - atomic_long_t mesq_send_unexpected_error;
34414 - atomic_long_t mesq_send_lb_overflow;
34415 - atomic_long_t mesq_send_qlimit_reached;
34416 - atomic_long_t mesq_send_amo_nacked;
34417 - atomic_long_t mesq_send_put_nacked;
34418 - atomic_long_t mesq_page_overflow;
34419 - atomic_long_t mesq_qf_locked;
34420 - atomic_long_t mesq_qf_noop_not_full;
34421 - atomic_long_t mesq_qf_switch_head_failed;
34422 - atomic_long_t mesq_qf_unexpected_error;
34423 - atomic_long_t mesq_noop_unexpected_error;
34424 - atomic_long_t mesq_noop_lb_overflow;
34425 - atomic_long_t mesq_noop_qlimit_reached;
34426 - atomic_long_t mesq_noop_amo_nacked;
34427 - atomic_long_t mesq_noop_put_nacked;
34428 - atomic_long_t mesq_noop_page_overflow;
34429 + atomic_long_unchecked_t mesq_receive;
34430 + atomic_long_unchecked_t mesq_receive_none;
34431 + atomic_long_unchecked_t mesq_send;
34432 + atomic_long_unchecked_t mesq_send_failed;
34433 + atomic_long_unchecked_t mesq_noop;
34434 + atomic_long_unchecked_t mesq_send_unexpected_error;
34435 + atomic_long_unchecked_t mesq_send_lb_overflow;
34436 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34437 + atomic_long_unchecked_t mesq_send_amo_nacked;
34438 + atomic_long_unchecked_t mesq_send_put_nacked;
34439 + atomic_long_unchecked_t mesq_page_overflow;
34440 + atomic_long_unchecked_t mesq_qf_locked;
34441 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34442 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34443 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34444 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34445 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34446 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34447 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34448 + atomic_long_unchecked_t mesq_noop_put_nacked;
34449 + atomic_long_unchecked_t mesq_noop_page_overflow;
34450
34451 };
34452
34453 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34454 tghop_invalidate, mcsop_last};
34455
34456 struct mcs_op_statistic {
34457 - atomic_long_t count;
34458 - atomic_long_t total;
34459 + atomic_long_unchecked_t count;
34460 + atomic_long_unchecked_t total;
34461 unsigned long max;
34462 };
34463
34464 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34465
34466 #define STAT(id) do { \
34467 if (gru_options & OPT_STATS) \
34468 - atomic_long_inc(&gru_stats.id); \
34469 + atomic_long_inc_unchecked(&gru_stats.id); \
34470 } while (0)
34471
34472 #ifdef CONFIG_SGI_GRU_DEBUG
34473 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34474 index 851b2f2..a4ec097 100644
34475 --- a/drivers/misc/sgi-xp/xp.h
34476 +++ b/drivers/misc/sgi-xp/xp.h
34477 @@ -289,7 +289,7 @@ struct xpc_interface {
34478 xpc_notify_func, void *);
34479 void (*received) (short, int, void *);
34480 enum xp_retval (*partid_to_nasids) (short, void *);
34481 -};
34482 +} __no_const;
34483
34484 extern struct xpc_interface xpc_interface;
34485
34486 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34487 index b94d5f7..7f494c5 100644
34488 --- a/drivers/misc/sgi-xp/xpc.h
34489 +++ b/drivers/misc/sgi-xp/xpc.h
34490 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34491 void (*received_payload) (struct xpc_channel *, void *);
34492 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34493 };
34494 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34495
34496 /* struct xpc_partition act_state values (for XPC HB) */
34497
34498 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34499 /* found in xpc_main.c */
34500 extern struct device *xpc_part;
34501 extern struct device *xpc_chan;
34502 -extern struct xpc_arch_operations xpc_arch_ops;
34503 +extern xpc_arch_operations_no_const xpc_arch_ops;
34504 extern int xpc_disengage_timelimit;
34505 extern int xpc_disengage_timedout;
34506 extern int xpc_activate_IRQ_rcvd;
34507 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34508 index 8d082b4..aa749ae 100644
34509 --- a/drivers/misc/sgi-xp/xpc_main.c
34510 +++ b/drivers/misc/sgi-xp/xpc_main.c
34511 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34512 .notifier_call = xpc_system_die,
34513 };
34514
34515 -struct xpc_arch_operations xpc_arch_ops;
34516 +xpc_arch_operations_no_const xpc_arch_ops;
34517
34518 /*
34519 * Timer function to enforce the timelimit on the partition disengage.
34520 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34521 index 6ebdc40..9edf5d8 100644
34522 --- a/drivers/mmc/host/sdhci-pci.c
34523 +++ b/drivers/mmc/host/sdhci-pci.c
34524 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34525 .probe = via_probe,
34526 };
34527
34528 -static const struct pci_device_id pci_ids[] __devinitdata = {
34529 +static const struct pci_device_id pci_ids[] __devinitconst = {
34530 {
34531 .vendor = PCI_VENDOR_ID_RICOH,
34532 .device = PCI_DEVICE_ID_RICOH_R5C822,
34533 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34534 index 87a431c..4959b43 100644
34535 --- a/drivers/mtd/devices/doc2000.c
34536 +++ b/drivers/mtd/devices/doc2000.c
34537 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34538
34539 /* The ECC will not be calculated correctly if less than 512 is written */
34540 /* DBB-
34541 - if (len != 0x200 && eccbuf)
34542 + if (len != 0x200)
34543 printk(KERN_WARNING
34544 "ECC needs a full sector write (adr: %lx size %lx)\n",
34545 (long) to, (long) len);
34546 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34547 index 9eacf67..4534b5b 100644
34548 --- a/drivers/mtd/devices/doc2001.c
34549 +++ b/drivers/mtd/devices/doc2001.c
34550 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34551 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34552
34553 /* Don't allow read past end of device */
34554 - if (from >= this->totlen)
34555 + if (from >= this->totlen || !len)
34556 return -EINVAL;
34557
34558 /* Don't allow a single read to cross a 512-byte block boundary */
34559 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34560 index 3984d48..28aa897 100644
34561 --- a/drivers/mtd/nand/denali.c
34562 +++ b/drivers/mtd/nand/denali.c
34563 @@ -26,6 +26,7 @@
34564 #include <linux/pci.h>
34565 #include <linux/mtd/mtd.h>
34566 #include <linux/module.h>
34567 +#include <linux/slab.h>
34568
34569 #include "denali.h"
34570
34571 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34572 index 51b9d6a..52af9a7 100644
34573 --- a/drivers/mtd/nftlmount.c
34574 +++ b/drivers/mtd/nftlmount.c
34575 @@ -24,6 +24,7 @@
34576 #include <asm/errno.h>
34577 #include <linux/delay.h>
34578 #include <linux/slab.h>
34579 +#include <linux/sched.h>
34580 #include <linux/mtd/mtd.h>
34581 #include <linux/mtd/nand.h>
34582 #include <linux/mtd/nftl.h>
34583 diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
34584 index e2cdebf..d48183a 100644
34585 --- a/drivers/mtd/ubi/debug.c
34586 +++ b/drivers/mtd/ubi/debug.c
34587 @@ -338,6 +338,8 @@ out:
34588
34589 /* Write an UBI debugfs file */
34590 static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34591 + size_t count, loff_t *ppos) __size_overflow(3);
34592 +static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34593 size_t count, loff_t *ppos)
34594 {
34595 unsigned long ubi_num = (unsigned long)file->private_data;
34596 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34597 index 071f4c8..440862e 100644
34598 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34599 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34600 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34601 */
34602
34603 #define ATL2_PARAM(X, desc) \
34604 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34605 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34606 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34607 MODULE_PARM_DESC(X, desc);
34608 #else
34609 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34610 index 66da39f..5dc436d 100644
34611 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34612 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34613 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34614
34615 int (*wait_comp)(struct bnx2x *bp,
34616 struct bnx2x_rx_mode_ramrod_params *p);
34617 -};
34618 +} __no_const;
34619
34620 /********************** Set multicast group ***********************************/
34621
34622 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34623 index aea8f72..fcebf75 100644
34624 --- a/drivers/net/ethernet/broadcom/tg3.h
34625 +++ b/drivers/net/ethernet/broadcom/tg3.h
34626 @@ -140,6 +140,7 @@
34627 #define CHIPREV_ID_5750_A0 0x4000
34628 #define CHIPREV_ID_5750_A1 0x4001
34629 #define CHIPREV_ID_5750_A3 0x4003
34630 +#define CHIPREV_ID_5750_C1 0x4201
34631 #define CHIPREV_ID_5750_C2 0x4202
34632 #define CHIPREV_ID_5752_A0_HW 0x5000
34633 #define CHIPREV_ID_5752_A0 0x6000
34634 diff --git a/drivers/net/ethernet/chelsio/cxgb/sge.c b/drivers/net/ethernet/chelsio/cxgb/sge.c
34635 index 47a8435..248e4b3 100644
34636 --- a/drivers/net/ethernet/chelsio/cxgb/sge.c
34637 +++ b/drivers/net/ethernet/chelsio/cxgb/sge.c
34638 @@ -1052,6 +1052,8 @@ MODULE_PARM_DESC(copybreak, "Receive copy threshold");
34639 * be copied but there is no memory for the copy.
34640 */
34641 static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34642 + struct freelQ *fl, unsigned int len) __size_overflow(3);
34643 +static inline struct sk_buff *get_packet(struct pci_dev *pdev,
34644 struct freelQ *fl, unsigned int len)
34645 {
34646 struct sk_buff *skb;
34647 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34648 index c4e8643..0979484 100644
34649 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34650 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34651 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34652 */
34653 struct l2t_skb_cb {
34654 arp_failure_handler_func arp_failure_handler;
34655 -};
34656 +} __no_const;
34657
34658 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34659
34660 diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34661 index cfb60e1..94af340 100644
34662 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
34663 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34664 @@ -611,6 +611,8 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
34665 * of the SW ring.
34666 */
34667 static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34668 + size_t sw_size, dma_addr_t * phys, void *metadata) __size_overflow(2,4);
34669 +static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34670 size_t sw_size, dma_addr_t * phys, void *metadata)
34671 {
34672 size_t len = nelem * elem_size;
34673 @@ -777,6 +779,8 @@ static inline unsigned int flits_to_desc(unsigned int n)
34674 * be copied but there is no memory for the copy.
34675 */
34676 static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34677 + unsigned int len, unsigned int drop_thres) __size_overflow(3);
34678 +static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
34679 unsigned int len, unsigned int drop_thres)
34680 {
34681 struct sk_buff *skb = NULL;
34682 diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34683 index 2dae795..73037d2 100644
34684 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
34685 +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34686 @@ -593,6 +593,9 @@ static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
34687 */
34688 static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34689 size_t sw_size, dma_addr_t *phys, void *metadata,
34690 + size_t stat_size, int node) __size_overflow(2,4);
34691 +static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34692 + size_t sw_size, dma_addr_t *phys, void *metadata,
34693 size_t stat_size, int node)
34694 {
34695 size_t len = nelem * elem_size + stat_size;
34696 diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34697 index 0bd585b..d954ca5 100644
34698 --- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34699 +++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34700 @@ -729,6 +729,9 @@ static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
34701 */
34702 static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34703 size_t swsize, dma_addr_t *busaddrp, void *swringp,
34704 + size_t stat_size) __size_overflow(2,4);
34705 +static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34706 + size_t swsize, dma_addr_t *busaddrp, void *swringp,
34707 size_t stat_size)
34708 {
34709 /*
34710 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34711 index 4d71f5a..8004440 100644
34712 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34713 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34714 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34715 for (i=0; i<ETH_ALEN; i++) {
34716 tmp.addr[i] = dev->dev_addr[i];
34717 }
34718 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34719 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34720 break;
34721
34722 case DE4X5_SET_HWADDR: /* Set the hardware address */
34723 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34724 spin_lock_irqsave(&lp->lock, flags);
34725 memcpy(&statbuf, &lp->pktStats, ioc->len);
34726 spin_unlock_irqrestore(&lp->lock, flags);
34727 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34728 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34729 return -EFAULT;
34730 break;
34731 }
34732 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34733 index 14d5b61..1398636 100644
34734 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34735 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34736 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34737 {NULL}};
34738
34739
34740 -static const char *block_name[] __devinitdata = {
34741 +static const char *block_name[] __devinitconst = {
34742 "21140 non-MII",
34743 "21140 MII PHY",
34744 "21142 Serial PHY",
34745 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34746 index 52da7b2..4ddfe1c 100644
34747 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34748 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34749 @@ -236,7 +236,7 @@ struct pci_id_info {
34750 int drv_flags; /* Driver use, intended as capability flags. */
34751 };
34752
34753 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34754 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34755 { /* Sometime a Level-One switch card. */
34756 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34757 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34758 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34759 index 28a3a9b..d96cb63 100644
34760 --- a/drivers/net/ethernet/dlink/sundance.c
34761 +++ b/drivers/net/ethernet/dlink/sundance.c
34762 @@ -218,7 +218,7 @@ enum {
34763 struct pci_id_info {
34764 const char *name;
34765 };
34766 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34767 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34768 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34769 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34770 {"D-Link DFE-580TX 4 port Server Adapter"},
34771 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34772 index e703d64..d62ecf9 100644
34773 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34774 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34775 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34776
34777 if (wrapped)
34778 newacc += 65536;
34779 - ACCESS_ONCE(*acc) = newacc;
34780 + ACCESS_ONCE_RW(*acc) = newacc;
34781 }
34782
34783 void be_parse_stats(struct be_adapter *adapter)
34784 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34785 index 47f85c3..82ab6c4 100644
34786 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34787 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34788 @@ -31,6 +31,8 @@
34789 #include <linux/netdevice.h>
34790 #include <linux/phy.h>
34791 #include <linux/platform_device.h>
34792 +#include <linux/interrupt.h>
34793 +#include <linux/irqreturn.h>
34794 #include <net/ip.h>
34795
34796 #include "ftgmac100.h"
34797 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34798 index bb336a0..4b472da 100644
34799 --- a/drivers/net/ethernet/faraday/ftmac100.c
34800 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34801 @@ -31,6 +31,8 @@
34802 #include <linux/module.h>
34803 #include <linux/netdevice.h>
34804 #include <linux/platform_device.h>
34805 +#include <linux/interrupt.h>
34806 +#include <linux/irqreturn.h>
34807
34808 #include "ftmac100.h"
34809
34810 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34811 index c82d444..0007fb4 100644
34812 --- a/drivers/net/ethernet/fealnx.c
34813 +++ b/drivers/net/ethernet/fealnx.c
34814 @@ -150,7 +150,7 @@ struct chip_info {
34815 int flags;
34816 };
34817
34818 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34819 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34820 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34821 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34822 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34823 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34824 index e1159e5..e18684d 100644
34825 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34826 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34827 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34828 {
34829 struct e1000_hw *hw = &adapter->hw;
34830 struct e1000_mac_info *mac = &hw->mac;
34831 - struct e1000_mac_operations *func = &mac->ops;
34832 + e1000_mac_operations_no_const *func = &mac->ops;
34833
34834 /* Set media type */
34835 switch (adapter->pdev->device) {
34836 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34837 index a3e65fd..f451444 100644
34838 --- a/drivers/net/ethernet/intel/e1000e/82571.c
34839 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
34840 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34841 {
34842 struct e1000_hw *hw = &adapter->hw;
34843 struct e1000_mac_info *mac = &hw->mac;
34844 - struct e1000_mac_operations *func = &mac->ops;
34845 + e1000_mac_operations_no_const *func = &mac->ops;
34846 u32 swsm = 0;
34847 u32 swsm2 = 0;
34848 bool force_clear_smbi = false;
34849 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34850 index 2967039..ca8c40c 100644
34851 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34852 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34853 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34854 void (*write_vfta)(struct e1000_hw *, u32, u32);
34855 s32 (*read_mac_addr)(struct e1000_hw *);
34856 };
34857 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34858
34859 /*
34860 * When to use various PHY register access functions:
34861 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
34862 void (*power_up)(struct e1000_hw *);
34863 void (*power_down)(struct e1000_hw *);
34864 };
34865 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34866
34867 /* Function pointers for the NVM. */
34868 struct e1000_nvm_operations {
34869 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34870 s32 (*validate)(struct e1000_hw *);
34871 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34872 };
34873 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34874
34875 struct e1000_mac_info {
34876 - struct e1000_mac_operations ops;
34877 + e1000_mac_operations_no_const ops;
34878 u8 addr[ETH_ALEN];
34879 u8 perm_addr[ETH_ALEN];
34880
34881 @@ -872,7 +875,7 @@ struct e1000_mac_info {
34882 };
34883
34884 struct e1000_phy_info {
34885 - struct e1000_phy_operations ops;
34886 + e1000_phy_operations_no_const ops;
34887
34888 enum e1000_phy_type type;
34889
34890 @@ -906,7 +909,7 @@ struct e1000_phy_info {
34891 };
34892
34893 struct e1000_nvm_info {
34894 - struct e1000_nvm_operations ops;
34895 + e1000_nvm_operations_no_const ops;
34896
34897 enum e1000_nvm_type type;
34898 enum e1000_nvm_override override;
34899 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34900 index f67cbd3..cef9e3d 100644
34901 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34902 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34903 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34904 s32 (*read_mac_addr)(struct e1000_hw *);
34905 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34906 };
34907 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34908
34909 struct e1000_phy_operations {
34910 s32 (*acquire)(struct e1000_hw *);
34911 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34912 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34913 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34914 };
34915 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34916
34917 struct e1000_nvm_operations {
34918 s32 (*acquire)(struct e1000_hw *);
34919 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34920 s32 (*update)(struct e1000_hw *);
34921 s32 (*validate)(struct e1000_hw *);
34922 };
34923 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34924
34925 struct e1000_info {
34926 s32 (*get_invariants)(struct e1000_hw *);
34927 @@ -350,7 +353,7 @@ struct e1000_info {
34928 extern const struct e1000_info e1000_82575_info;
34929
34930 struct e1000_mac_info {
34931 - struct e1000_mac_operations ops;
34932 + e1000_mac_operations_no_const ops;
34933
34934 u8 addr[6];
34935 u8 perm_addr[6];
34936 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34937 };
34938
34939 struct e1000_phy_info {
34940 - struct e1000_phy_operations ops;
34941 + e1000_phy_operations_no_const ops;
34942
34943 enum e1000_phy_type type;
34944
34945 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34946 };
34947
34948 struct e1000_nvm_info {
34949 - struct e1000_nvm_operations ops;
34950 + e1000_nvm_operations_no_const ops;
34951 enum e1000_nvm_type type;
34952 enum e1000_nvm_override override;
34953
34954 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34955 s32 (*check_for_ack)(struct e1000_hw *, u16);
34956 s32 (*check_for_rst)(struct e1000_hw *, u16);
34957 };
34958 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34959
34960 struct e1000_mbx_stats {
34961 u32 msgs_tx;
34962 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34963 };
34964
34965 struct e1000_mbx_info {
34966 - struct e1000_mbx_operations ops;
34967 + e1000_mbx_operations_no_const ops;
34968 struct e1000_mbx_stats stats;
34969 u32 timeout;
34970 u32 usec_delay;
34971 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34972 index 57db3c6..aa825fc 100644
34973 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34974 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34975 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34976 s32 (*read_mac_addr)(struct e1000_hw *);
34977 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34978 };
34979 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34980
34981 struct e1000_mac_info {
34982 - struct e1000_mac_operations ops;
34983 + e1000_mac_operations_no_const ops;
34984 u8 addr[6];
34985 u8 perm_addr[6];
34986
34987 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34988 s32 (*check_for_ack)(struct e1000_hw *);
34989 s32 (*check_for_rst)(struct e1000_hw *);
34990 };
34991 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34992
34993 struct e1000_mbx_stats {
34994 u32 msgs_tx;
34995 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34996 };
34997
34998 struct e1000_mbx_info {
34999 - struct e1000_mbx_operations ops;
35000 + e1000_mbx_operations_no_const ops;
35001 struct e1000_mbx_stats stats;
35002 u32 timeout;
35003 u32 usec_delay;
35004 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35005 index 9b95bef..7e254ee 100644
35006 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35007 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35008 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35009 s32 (*update_checksum)(struct ixgbe_hw *);
35010 u16 (*calc_checksum)(struct ixgbe_hw *);
35011 };
35012 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35013
35014 struct ixgbe_mac_operations {
35015 s32 (*init_hw)(struct ixgbe_hw *);
35016 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35017 /* Manageability interface */
35018 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35019 };
35020 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35021
35022 struct ixgbe_phy_operations {
35023 s32 (*identify)(struct ixgbe_hw *);
35024 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35025 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35026 s32 (*check_overtemp)(struct ixgbe_hw *);
35027 };
35028 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35029
35030 struct ixgbe_eeprom_info {
35031 - struct ixgbe_eeprom_operations ops;
35032 + ixgbe_eeprom_operations_no_const ops;
35033 enum ixgbe_eeprom_type type;
35034 u32 semaphore_delay;
35035 u16 word_size;
35036 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35037
35038 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35039 struct ixgbe_mac_info {
35040 - struct ixgbe_mac_operations ops;
35041 + ixgbe_mac_operations_no_const ops;
35042 enum ixgbe_mac_type type;
35043 u8 addr[ETH_ALEN];
35044 u8 perm_addr[ETH_ALEN];
35045 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35046 };
35047
35048 struct ixgbe_phy_info {
35049 - struct ixgbe_phy_operations ops;
35050 + ixgbe_phy_operations_no_const ops;
35051 struct mdio_if_info mdio;
35052 enum ixgbe_phy_type type;
35053 u32 id;
35054 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35055 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35056 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35057 };
35058 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35059
35060 struct ixgbe_mbx_stats {
35061 u32 msgs_tx;
35062 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35063 };
35064
35065 struct ixgbe_mbx_info {
35066 - struct ixgbe_mbx_operations ops;
35067 + ixgbe_mbx_operations_no_const ops;
35068 struct ixgbe_mbx_stats stats;
35069 u32 timeout;
35070 u32 usec_delay;
35071 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35072 index 25c951d..cc7cf33 100644
35073 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35074 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35075 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35076 s32 (*clear_vfta)(struct ixgbe_hw *);
35077 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35078 };
35079 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35080
35081 enum ixgbe_mac_type {
35082 ixgbe_mac_unknown = 0,
35083 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35084 };
35085
35086 struct ixgbe_mac_info {
35087 - struct ixgbe_mac_operations ops;
35088 + ixgbe_mac_operations_no_const ops;
35089 u8 addr[6];
35090 u8 perm_addr[6];
35091
35092 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35093 s32 (*check_for_ack)(struct ixgbe_hw *);
35094 s32 (*check_for_rst)(struct ixgbe_hw *);
35095 };
35096 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35097
35098 struct ixgbe_mbx_stats {
35099 u32 msgs_tx;
35100 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35101 };
35102
35103 struct ixgbe_mbx_info {
35104 - struct ixgbe_mbx_operations ops;
35105 + ixgbe_mbx_operations_no_const ops;
35106 struct ixgbe_mbx_stats stats;
35107 u32 timeout;
35108 u32 udelay;
35109 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35110 index 8bf22b6..7f5baaa 100644
35111 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35112 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35113 @@ -41,6 +41,7 @@
35114 #include <linux/slab.h>
35115 #include <linux/io-mapping.h>
35116 #include <linux/delay.h>
35117 +#include <linux/sched.h>
35118
35119 #include <linux/mlx4/device.h>
35120 #include <linux/mlx4/doorbell.h>
35121 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35122 index 5046a64..71ca936 100644
35123 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35124 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35125 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35126 void (*link_down)(struct __vxge_hw_device *devh);
35127 void (*crit_err)(struct __vxge_hw_device *devh,
35128 enum vxge_hw_event type, u64 ext_data);
35129 -};
35130 +} __no_const;
35131
35132 /*
35133 * struct __vxge_hw_blockpool_entry - Block private data structure
35134 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35135 index 4a518a3..936b334 100644
35136 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35137 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35138 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35139 struct vxge_hw_mempool_dma *dma_object,
35140 u32 index,
35141 u32 is_last);
35142 -};
35143 +} __no_const;
35144
35145 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35146 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35147 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35148 index bbacb37..d60887d 100644
35149 --- a/drivers/net/ethernet/realtek/r8169.c
35150 +++ b/drivers/net/ethernet/realtek/r8169.c
35151 @@ -695,17 +695,17 @@ struct rtl8169_private {
35152 struct mdio_ops {
35153 void (*write)(void __iomem *, int, int);
35154 int (*read)(void __iomem *, int);
35155 - } mdio_ops;
35156 + } __no_const mdio_ops;
35157
35158 struct pll_power_ops {
35159 void (*down)(struct rtl8169_private *);
35160 void (*up)(struct rtl8169_private *);
35161 - } pll_power_ops;
35162 + } __no_const pll_power_ops;
35163
35164 struct jumbo_ops {
35165 void (*enable)(struct rtl8169_private *);
35166 void (*disable)(struct rtl8169_private *);
35167 - } jumbo_ops;
35168 + } __no_const jumbo_ops;
35169
35170 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35171 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35172 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35173 index 5b118cd..858b523 100644
35174 --- a/drivers/net/ethernet/sis/sis190.c
35175 +++ b/drivers/net/ethernet/sis/sis190.c
35176 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35177 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35178 struct net_device *dev)
35179 {
35180 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35181 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35182 struct sis190_private *tp = netdev_priv(dev);
35183 struct pci_dev *isa_bridge;
35184 u8 reg, tmp8;
35185 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35186 index c07cfe9..81cbf7e 100644
35187 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35188 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35189 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35190
35191 writel(value, ioaddr + MMC_CNTRL);
35192
35193 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35194 - MMC_CNTRL, value);
35195 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35196 +// MMC_CNTRL, value);
35197 }
35198
35199 /* To mask all all interrupts.*/
35200 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35201 index dec5836..6d4db7d 100644
35202 --- a/drivers/net/hyperv/hyperv_net.h
35203 +++ b/drivers/net/hyperv/hyperv_net.h
35204 @@ -97,7 +97,7 @@ struct rndis_device {
35205
35206 enum rndis_device_state state;
35207 bool link_state;
35208 - atomic_t new_req_id;
35209 + atomic_unchecked_t new_req_id;
35210
35211 spinlock_t request_lock;
35212 struct list_head req_list;
35213 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35214 index 133b7fb..d58c559 100644
35215 --- a/drivers/net/hyperv/rndis_filter.c
35216 +++ b/drivers/net/hyperv/rndis_filter.c
35217 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35218 * template
35219 */
35220 set = &rndis_msg->msg.set_req;
35221 - set->req_id = atomic_inc_return(&dev->new_req_id);
35222 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35223
35224 /* Add to the request list */
35225 spin_lock_irqsave(&dev->request_lock, flags);
35226 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35227
35228 /* Setup the rndis set */
35229 halt = &request->request_msg.msg.halt_req;
35230 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35231 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35232
35233 /* Ignore return since this msg is optional. */
35234 rndis_filter_send_request(dev, request);
35235 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35236 index 58dc117..f140c77 100644
35237 --- a/drivers/net/macvtap.c
35238 +++ b/drivers/net/macvtap.c
35239 @@ -526,6 +526,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35240 }
35241 base = (unsigned long)from->iov_base + offset1;
35242 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35243 + if (i + size >= MAX_SKB_FRAGS)
35244 + return -EFAULT;
35245 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35246 if ((num_pages != size) ||
35247 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35248 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35249 index 486b404..0d6677d 100644
35250 --- a/drivers/net/ppp/ppp_generic.c
35251 +++ b/drivers/net/ppp/ppp_generic.c
35252 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35253 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35254 struct ppp_stats stats;
35255 struct ppp_comp_stats cstats;
35256 - char *vers;
35257
35258 switch (cmd) {
35259 case SIOCGPPPSTATS:
35260 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35261 break;
35262
35263 case SIOCGPPPVER:
35264 - vers = PPP_VERSION;
35265 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35266 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35267 break;
35268 err = 0;
35269 break;
35270 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35271 index 515f122..41dd273 100644
35272 --- a/drivers/net/tokenring/abyss.c
35273 +++ b/drivers/net/tokenring/abyss.c
35274 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35275
35276 static int __init abyss_init (void)
35277 {
35278 - abyss_netdev_ops = tms380tr_netdev_ops;
35279 + pax_open_kernel();
35280 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35281
35282 - abyss_netdev_ops.ndo_open = abyss_open;
35283 - abyss_netdev_ops.ndo_stop = abyss_close;
35284 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35285 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35286 + pax_close_kernel();
35287
35288 return pci_register_driver(&abyss_driver);
35289 }
35290 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35291 index 6153cfd..cf69c1c 100644
35292 --- a/drivers/net/tokenring/madgemc.c
35293 +++ b/drivers/net/tokenring/madgemc.c
35294 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35295
35296 static int __init madgemc_init (void)
35297 {
35298 - madgemc_netdev_ops = tms380tr_netdev_ops;
35299 - madgemc_netdev_ops.ndo_open = madgemc_open;
35300 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35301 + pax_open_kernel();
35302 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35303 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35304 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35305 + pax_close_kernel();
35306
35307 return mca_register_driver (&madgemc_driver);
35308 }
35309 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35310 index 8d362e6..f91cc52 100644
35311 --- a/drivers/net/tokenring/proteon.c
35312 +++ b/drivers/net/tokenring/proteon.c
35313 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35314 struct platform_device *pdev;
35315 int i, num = 0, err = 0;
35316
35317 - proteon_netdev_ops = tms380tr_netdev_ops;
35318 - proteon_netdev_ops.ndo_open = proteon_open;
35319 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35320 + pax_open_kernel();
35321 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35322 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35323 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35324 + pax_close_kernel();
35325
35326 err = platform_driver_register(&proteon_driver);
35327 if (err)
35328 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35329 index 46db5c5..37c1536 100644
35330 --- a/drivers/net/tokenring/skisa.c
35331 +++ b/drivers/net/tokenring/skisa.c
35332 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35333 struct platform_device *pdev;
35334 int i, num = 0, err = 0;
35335
35336 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35337 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35338 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35339 + pax_open_kernel();
35340 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35341 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35342 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35343 + pax_close_kernel();
35344
35345 err = platform_driver_register(&sk_isa_driver);
35346 if (err)
35347 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35348 index e1324b4..e1b0041 100644
35349 --- a/drivers/net/usb/hso.c
35350 +++ b/drivers/net/usb/hso.c
35351 @@ -71,7 +71,7 @@
35352 #include <asm/byteorder.h>
35353 #include <linux/serial_core.h>
35354 #include <linux/serial.h>
35355 -
35356 +#include <asm/local.h>
35357
35358 #define MOD_AUTHOR "Option Wireless"
35359 #define MOD_DESCRIPTION "USB High Speed Option driver"
35360 @@ -257,7 +257,7 @@ struct hso_serial {
35361
35362 /* from usb_serial_port */
35363 struct tty_struct *tty;
35364 - int open_count;
35365 + local_t open_count;
35366 spinlock_t serial_lock;
35367
35368 int (*write_data) (struct hso_serial *serial);
35369 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35370 struct urb *urb;
35371
35372 urb = serial->rx_urb[0];
35373 - if (serial->open_count > 0) {
35374 + if (local_read(&serial->open_count) > 0) {
35375 count = put_rxbuf_data(urb, serial);
35376 if (count == -1)
35377 return;
35378 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35379 DUMP1(urb->transfer_buffer, urb->actual_length);
35380
35381 /* Anyone listening? */
35382 - if (serial->open_count == 0)
35383 + if (local_read(&serial->open_count) == 0)
35384 return;
35385
35386 if (status == 0) {
35387 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35388 spin_unlock_irq(&serial->serial_lock);
35389
35390 /* check for port already opened, if not set the termios */
35391 - serial->open_count++;
35392 - if (serial->open_count == 1) {
35393 + if (local_inc_return(&serial->open_count) == 1) {
35394 serial->rx_state = RX_IDLE;
35395 /* Force default termio settings */
35396 _hso_serial_set_termios(tty, NULL);
35397 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35398 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35399 if (result) {
35400 hso_stop_serial_device(serial->parent);
35401 - serial->open_count--;
35402 + local_dec(&serial->open_count);
35403 kref_put(&serial->parent->ref, hso_serial_ref_free);
35404 }
35405 } else {
35406 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35407
35408 /* reset the rts and dtr */
35409 /* do the actual close */
35410 - serial->open_count--;
35411 + local_dec(&serial->open_count);
35412
35413 - if (serial->open_count <= 0) {
35414 - serial->open_count = 0;
35415 + if (local_read(&serial->open_count) <= 0) {
35416 + local_set(&serial->open_count, 0);
35417 spin_lock_irq(&serial->serial_lock);
35418 if (serial->tty == tty) {
35419 serial->tty->driver_data = NULL;
35420 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35421
35422 /* the actual setup */
35423 spin_lock_irqsave(&serial->serial_lock, flags);
35424 - if (serial->open_count)
35425 + if (local_read(&serial->open_count))
35426 _hso_serial_set_termios(tty, old);
35427 else
35428 tty->termios = old;
35429 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35430 D1("Pending read interrupt on port %d\n", i);
35431 spin_lock(&serial->serial_lock);
35432 if (serial->rx_state == RX_IDLE &&
35433 - serial->open_count > 0) {
35434 + local_read(&serial->open_count) > 0) {
35435 /* Setup and send a ctrl req read on
35436 * port i */
35437 if (!serial->rx_urb_filled[0]) {
35438 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35439 /* Start all serial ports */
35440 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35441 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35442 - if (dev2ser(serial_table[i])->open_count) {
35443 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35444 result =
35445 hso_start_serial_device(serial_table[i], GFP_NOIO);
35446 hso_kick_transmit(dev2ser(serial_table[i]));
35447 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35448 index efc0111..79c8f5b 100644
35449 --- a/drivers/net/wireless/ath/ath.h
35450 +++ b/drivers/net/wireless/ath/ath.h
35451 @@ -119,6 +119,7 @@ struct ath_ops {
35452 void (*write_flush) (void *);
35453 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35454 };
35455 +typedef struct ath_ops __no_const ath_ops_no_const;
35456
35457 struct ath_common;
35458 struct ath_bus_ops;
35459 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
35460 index 8c5ce8b..abf101b 100644
35461 --- a/drivers/net/wireless/ath/ath5k/debug.c
35462 +++ b/drivers/net/wireless/ath/ath5k/debug.c
35463 @@ -343,6 +343,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35464
35465 static ssize_t write_file_debug(struct file *file,
35466 const char __user *userbuf,
35467 + size_t count, loff_t *ppos) __size_overflow(3);
35468 +static ssize_t write_file_debug(struct file *file,
35469 + const char __user *userbuf,
35470 size_t count, loff_t *ppos)
35471 {
35472 struct ath5k_hw *ah = file->private_data;
35473 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35474 index 7b6417b..ab5db98 100644
35475 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35476 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35477 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35478 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35479 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35480
35481 - ACCESS_ONCE(ads->ds_link) = i->link;
35482 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35483 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35484 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35485
35486 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35487 ctl6 = SM(i->keytype, AR_EncrType);
35488 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35489
35490 if ((i->is_first || i->is_last) &&
35491 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35492 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35493 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35494 | set11nTries(i->rates, 1)
35495 | set11nTries(i->rates, 2)
35496 | set11nTries(i->rates, 3)
35497 | (i->dur_update ? AR_DurUpdateEna : 0)
35498 | SM(0, AR_BurstDur);
35499
35500 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35501 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35502 | set11nRate(i->rates, 1)
35503 | set11nRate(i->rates, 2)
35504 | set11nRate(i->rates, 3);
35505 } else {
35506 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35507 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35508 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35509 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35510 }
35511
35512 if (!i->is_first) {
35513 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35514 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35515 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35516 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35517 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35518 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35519 return;
35520 }
35521
35522 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35523 break;
35524 }
35525
35526 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35527 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35528 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35529 | SM(i->txpower, AR_XmitPower)
35530 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35531 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35532 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35533 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35534
35535 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35536 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35537 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35538 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35539
35540 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35541 return;
35542
35543 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35544 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35545 | set11nPktDurRTSCTS(i->rates, 1);
35546
35547 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35548 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35549 | set11nPktDurRTSCTS(i->rates, 3);
35550
35551 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35552 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35553 | set11nRateFlags(i->rates, 1)
35554 | set11nRateFlags(i->rates, 2)
35555 | set11nRateFlags(i->rates, 3)
35556 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35557 index 09b8c9d..905339e 100644
35558 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35559 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35560 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35561 (i->qcu << AR_TxQcuNum_S) | 0x17;
35562
35563 checksum += val;
35564 - ACCESS_ONCE(ads->info) = val;
35565 + ACCESS_ONCE_RW(ads->info) = val;
35566
35567 checksum += i->link;
35568 - ACCESS_ONCE(ads->link) = i->link;
35569 + ACCESS_ONCE_RW(ads->link) = i->link;
35570
35571 checksum += i->buf_addr[0];
35572 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35573 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35574 checksum += i->buf_addr[1];
35575 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35576 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35577 checksum += i->buf_addr[2];
35578 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35579 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35580 checksum += i->buf_addr[3];
35581 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35582 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35583
35584 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35585 - ACCESS_ONCE(ads->ctl3) = val;
35586 + ACCESS_ONCE_RW(ads->ctl3) = val;
35587 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35588 - ACCESS_ONCE(ads->ctl5) = val;
35589 + ACCESS_ONCE_RW(ads->ctl5) = val;
35590 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35591 - ACCESS_ONCE(ads->ctl7) = val;
35592 + ACCESS_ONCE_RW(ads->ctl7) = val;
35593 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35594 - ACCESS_ONCE(ads->ctl9) = val;
35595 + ACCESS_ONCE_RW(ads->ctl9) = val;
35596
35597 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35598 - ACCESS_ONCE(ads->ctl10) = checksum;
35599 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35600
35601 if (i->is_first || i->is_last) {
35602 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35603 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35604 | set11nTries(i->rates, 1)
35605 | set11nTries(i->rates, 2)
35606 | set11nTries(i->rates, 3)
35607 | (i->dur_update ? AR_DurUpdateEna : 0)
35608 | SM(0, AR_BurstDur);
35609
35610 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35611 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35612 | set11nRate(i->rates, 1)
35613 | set11nRate(i->rates, 2)
35614 | set11nRate(i->rates, 3);
35615 } else {
35616 - ACCESS_ONCE(ads->ctl13) = 0;
35617 - ACCESS_ONCE(ads->ctl14) = 0;
35618 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35619 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35620 }
35621
35622 ads->ctl20 = 0;
35623 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35624
35625 ctl17 = SM(i->keytype, AR_EncrType);
35626 if (!i->is_first) {
35627 - ACCESS_ONCE(ads->ctl11) = 0;
35628 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35629 - ACCESS_ONCE(ads->ctl15) = 0;
35630 - ACCESS_ONCE(ads->ctl16) = 0;
35631 - ACCESS_ONCE(ads->ctl17) = ctl17;
35632 - ACCESS_ONCE(ads->ctl18) = 0;
35633 - ACCESS_ONCE(ads->ctl19) = 0;
35634 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35635 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35636 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35637 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35638 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35639 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35640 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35641 return;
35642 }
35643
35644 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35645 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35646 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35647 | SM(i->txpower, AR_XmitPower)
35648 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35649 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35650 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35651 ctl12 |= SM(val, AR_PAPRDChainMask);
35652
35653 - ACCESS_ONCE(ads->ctl12) = ctl12;
35654 - ACCESS_ONCE(ads->ctl17) = ctl17;
35655 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35656 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35657
35658 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35659 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35660 | set11nPktDurRTSCTS(i->rates, 1);
35661
35662 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35663 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35664 | set11nPktDurRTSCTS(i->rates, 3);
35665
35666 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35667 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35668 | set11nRateFlags(i->rates, 1)
35669 | set11nRateFlags(i->rates, 2)
35670 | set11nRateFlags(i->rates, 3)
35671 | SM(i->rtscts_rate, AR_RTSCTSRate);
35672
35673 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35674 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35675 }
35676
35677 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35678 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
35679 index 68d972b..1d9205b 100644
35680 --- a/drivers/net/wireless/ath/ath9k/debug.c
35681 +++ b/drivers/net/wireless/ath/ath9k/debug.c
35682 @@ -60,6 +60,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35683 }
35684
35685 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35686 + size_t count, loff_t *ppos) __size_overflow(3);
35687 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35688 size_t count, loff_t *ppos)
35689 {
35690 struct ath_softc *sc = file->private_data;
35691 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35692 index d3ff33c..c98bcda 100644
35693 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35694 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35695 @@ -464,6 +464,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35696 }
35697
35698 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35699 + size_t count, loff_t *ppos) __size_overflow(3);
35700 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35701 size_t count, loff_t *ppos)
35702 {
35703 struct ath9k_htc_priv *priv = file->private_data;
35704 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35705 index c8261d4..8d88929 100644
35706 --- a/drivers/net/wireless/ath/ath9k/hw.h
35707 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35708 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
35709
35710 /* ANI */
35711 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35712 -};
35713 +} __no_const;
35714
35715 /**
35716 * struct ath_hw_ops - callbacks used by hardware code and driver code
35717 @@ -803,7 +803,7 @@ struct ath_hw_ops {
35718 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35719 struct ath_hw_antcomb_conf *antconf);
35720
35721 -};
35722 +} __no_const;
35723
35724 struct ath_nf_limits {
35725 s16 max;
35726 @@ -823,7 +823,7 @@ enum ath_cal_list {
35727 #define AH_FASTCC 0x4
35728
35729 struct ath_hw {
35730 - struct ath_ops reg_ops;
35731 + ath_ops_no_const reg_ops;
35732
35733 struct ieee80211_hw *hw;
35734 struct ath_common common;
35735 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35736 index af00e2c..ab04d34 100644
35737 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35738 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35739 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35740 void (*carrsuppr)(struct brcms_phy *);
35741 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35742 void (*detach)(struct brcms_phy *);
35743 -};
35744 +} __no_const;
35745
35746 struct brcms_phy {
35747 struct brcms_phy_pub pubpi_ro;
35748 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35749 index a2ec369..36fdf14 100644
35750 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35751 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35752 @@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35753 */
35754 if (il3945_mod_params.disable_hw_scan) {
35755 D_INFO("Disabling hw_scan\n");
35756 - il3945_hw_ops.hw_scan = NULL;
35757 + pax_open_kernel();
35758 + *(void **)&il3945_hw_ops.hw_scan = NULL;
35759 + pax_close_kernel();
35760 }
35761
35762 D_INFO("*** LOAD DRIVER ***\n");
35763 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35764 index f8fc239..8cade22 100644
35765 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35766 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35767 @@ -86,8 +86,8 @@ do { \
35768 } while (0)
35769
35770 #else
35771 -#define IWL_DEBUG(m, level, fmt, args...)
35772 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35773 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35774 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35775 #define iwl_print_hex_dump(m, level, p, len)
35776 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
35777 do { \
35778 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35779 index 4b9e730..7603659 100644
35780 --- a/drivers/net/wireless/mac80211_hwsim.c
35781 +++ b/drivers/net/wireless/mac80211_hwsim.c
35782 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
35783 return -EINVAL;
35784
35785 if (fake_hw_scan) {
35786 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35787 - mac80211_hwsim_ops.sw_scan_start = NULL;
35788 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35789 + pax_open_kernel();
35790 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35791 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35792 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35793 + pax_close_kernel();
35794 }
35795
35796 spin_lock_init(&hwsim_radio_lock);
35797 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35798 index 3186aa4..b35b09f 100644
35799 --- a/drivers/net/wireless/mwifiex/main.h
35800 +++ b/drivers/net/wireless/mwifiex/main.h
35801 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
35802 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35803 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35804 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35805 -};
35806 +} __no_const;
35807
35808 struct mwifiex_adapter {
35809 u8 iface_type;
35810 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35811 index a330c69..a81540f 100644
35812 --- a/drivers/net/wireless/rndis_wlan.c
35813 +++ b/drivers/net/wireless/rndis_wlan.c
35814 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35815
35816 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35817
35818 - if (rts_threshold < 0 || rts_threshold > 2347)
35819 + if (rts_threshold > 2347)
35820 rts_threshold = 2347;
35821
35822 tmp = cpu_to_le32(rts_threshold);
35823 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35824 index a77f1bb..c608b2b 100644
35825 --- a/drivers/net/wireless/wl1251/wl1251.h
35826 +++ b/drivers/net/wireless/wl1251/wl1251.h
35827 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35828 void (*reset)(struct wl1251 *wl);
35829 void (*enable_irq)(struct wl1251 *wl);
35830 void (*disable_irq)(struct wl1251 *wl);
35831 -};
35832 +} __no_const;
35833
35834 struct wl1251 {
35835 struct ieee80211_hw *hw;
35836 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35837 index f34b5b2..b5abb9f 100644
35838 --- a/drivers/oprofile/buffer_sync.c
35839 +++ b/drivers/oprofile/buffer_sync.c
35840 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35841 if (cookie == NO_COOKIE)
35842 offset = pc;
35843 if (cookie == INVALID_COOKIE) {
35844 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35845 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35846 offset = pc;
35847 }
35848 if (cookie != last_cookie) {
35849 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35850 /* add userspace sample */
35851
35852 if (!mm) {
35853 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35854 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35855 return 0;
35856 }
35857
35858 cookie = lookup_dcookie(mm, s->eip, &offset);
35859
35860 if (cookie == INVALID_COOKIE) {
35861 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35862 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35863 return 0;
35864 }
35865
35866 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35867 /* ignore backtraces if failed to add a sample */
35868 if (state == sb_bt_start) {
35869 state = sb_bt_ignore;
35870 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35871 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35872 }
35873 }
35874 release_mm(mm);
35875 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35876 index c0cc4e7..44d4e54 100644
35877 --- a/drivers/oprofile/event_buffer.c
35878 +++ b/drivers/oprofile/event_buffer.c
35879 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35880 }
35881
35882 if (buffer_pos == buffer_size) {
35883 - atomic_inc(&oprofile_stats.event_lost_overflow);
35884 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35885 return;
35886 }
35887
35888 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35889 index ed2c3ec..deda85a 100644
35890 --- a/drivers/oprofile/oprof.c
35891 +++ b/drivers/oprofile/oprof.c
35892 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35893 if (oprofile_ops.switch_events())
35894 return;
35895
35896 - atomic_inc(&oprofile_stats.multiplex_counter);
35897 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35898 start_switch_worker();
35899 }
35900
35901 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
35902 index 84a208d..f07d177 100644
35903 --- a/drivers/oprofile/oprofile_files.c
35904 +++ b/drivers/oprofile/oprofile_files.c
35905 @@ -36,6 +36,8 @@ static ssize_t timeout_read(struct file *file, char __user *buf,
35906
35907
35908 static ssize_t timeout_write(struct file *file, char const __user *buf,
35909 + size_t count, loff_t *offset) __size_overflow(3);
35910 +static ssize_t timeout_write(struct file *file, char const __user *buf,
35911 size_t count, loff_t *offset)
35912 {
35913 unsigned long val;
35914 @@ -72,6 +74,7 @@ static ssize_t depth_read(struct file *file, char __user *buf, size_t count, lof
35915 }
35916
35917
35918 +static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35919 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35920 {
35921 unsigned long val;
35922 @@ -126,12 +129,14 @@ static const struct file_operations cpu_type_fops = {
35923 };
35924
35925
35926 +static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35927 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
35928 {
35929 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
35930 }
35931
35932
35933 +static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35934 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35935 {
35936 unsigned long val;
35937 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35938 index 917d28e..d62d981 100644
35939 --- a/drivers/oprofile/oprofile_stats.c
35940 +++ b/drivers/oprofile/oprofile_stats.c
35941 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35942 cpu_buf->sample_invalid_eip = 0;
35943 }
35944
35945 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35946 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35947 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35948 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35949 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35950 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35951 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35952 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35953 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35954 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35955 }
35956
35957
35958 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35959 index 38b6fc0..b5cbfce 100644
35960 --- a/drivers/oprofile/oprofile_stats.h
35961 +++ b/drivers/oprofile/oprofile_stats.h
35962 @@ -13,11 +13,11 @@
35963 #include <linux/atomic.h>
35964
35965 struct oprofile_stat_struct {
35966 - atomic_t sample_lost_no_mm;
35967 - atomic_t sample_lost_no_mapping;
35968 - atomic_t bt_lost_no_mapping;
35969 - atomic_t event_lost_overflow;
35970 - atomic_t multiplex_counter;
35971 + atomic_unchecked_t sample_lost_no_mm;
35972 + atomic_unchecked_t sample_lost_no_mapping;
35973 + atomic_unchecked_t bt_lost_no_mapping;
35974 + atomic_unchecked_t event_lost_overflow;
35975 + atomic_unchecked_t multiplex_counter;
35976 };
35977
35978 extern struct oprofile_stat_struct oprofile_stats;
35979 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35980 index 2f0aa0f..d5246c3 100644
35981 --- a/drivers/oprofile/oprofilefs.c
35982 +++ b/drivers/oprofile/oprofilefs.c
35983 @@ -97,6 +97,7 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
35984 }
35985
35986
35987 +static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35988 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35989 {
35990 unsigned long value;
35991 @@ -193,7 +194,7 @@ static const struct file_operations atomic_ro_fops = {
35992
35993
35994 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35995 - char const *name, atomic_t *val)
35996 + char const *name, atomic_unchecked_t *val)
35997 {
35998 return __oprofilefs_create_file(sb, root, name,
35999 &atomic_ro_fops, 0444, val);
36000 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36001 index 3f56bc0..707d642 100644
36002 --- a/drivers/parport/procfs.c
36003 +++ b/drivers/parport/procfs.c
36004 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36005
36006 *ppos += len;
36007
36008 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36009 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36010 }
36011
36012 #ifdef CONFIG_PARPORT_1284
36013 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36014
36015 *ppos += len;
36016
36017 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36018 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36019 }
36020 #endif /* IEEE1284.3 support. */
36021
36022 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36023 index 9fff878..ad0ad53 100644
36024 --- a/drivers/pci/hotplug/cpci_hotplug.h
36025 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36026 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36027 int (*hardware_test) (struct slot* slot, u32 value);
36028 u8 (*get_power) (struct slot* slot);
36029 int (*set_power) (struct slot* slot, int value);
36030 -};
36031 +} __no_const;
36032
36033 struct cpci_hp_controller {
36034 unsigned int irq;
36035 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36036 index 76ba8a1..20ca857 100644
36037 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36038 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36039 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36040
36041 void compaq_nvram_init (void __iomem *rom_start)
36042 {
36043 +
36044 +#ifndef CONFIG_PAX_KERNEXEC
36045 if (rom_start) {
36046 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36047 }
36048 +#endif
36049 +
36050 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36051
36052 /* initialize our int15 lock */
36053 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36054 index 2275162..95f1a92 100644
36055 --- a/drivers/pci/pcie/aspm.c
36056 +++ b/drivers/pci/pcie/aspm.c
36057 @@ -27,9 +27,9 @@
36058 #define MODULE_PARAM_PREFIX "pcie_aspm."
36059
36060 /* Note: those are not register definitions */
36061 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36062 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36063 -#define ASPM_STATE_L1 (4) /* L1 state */
36064 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36065 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36066 +#define ASPM_STATE_L1 (4U) /* L1 state */
36067 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36068 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36069
36070 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36071 index 71eac9c..2de27ef 100644
36072 --- a/drivers/pci/probe.c
36073 +++ b/drivers/pci/probe.c
36074 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36075 u32 l, sz, mask;
36076 u16 orig_cmd;
36077
36078 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36079 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36080
36081 if (!dev->mmio_always_on) {
36082 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36083 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36084 index 27911b5..5b6db88 100644
36085 --- a/drivers/pci/proc.c
36086 +++ b/drivers/pci/proc.c
36087 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36088 static int __init pci_proc_init(void)
36089 {
36090 struct pci_dev *dev = NULL;
36091 +
36092 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36093 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36094 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36095 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36096 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36097 +#endif
36098 +#else
36099 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36100 +#endif
36101 proc_create("devices", 0, proc_bus_pci_dir,
36102 &proc_bus_pci_dev_operations);
36103 proc_initialized = 1;
36104 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
36105 index 6f966d6..68e18ed 100644
36106 --- a/drivers/platform/x86/asus_acpi.c
36107 +++ b/drivers/platform/x86/asus_acpi.c
36108 @@ -887,6 +887,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
36109 }
36110
36111 static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36112 + size_t count, loff_t *pos) __size_overflow(3);
36113 +static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36114 size_t count, loff_t *pos)
36115 {
36116 int rv, value;
36117 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36118 index ea0c607..58c4628 100644
36119 --- a/drivers/platform/x86/thinkpad_acpi.c
36120 +++ b/drivers/platform/x86/thinkpad_acpi.c
36121 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36122 return 0;
36123 }
36124
36125 -void static hotkey_mask_warn_incomplete_mask(void)
36126 +static void hotkey_mask_warn_incomplete_mask(void)
36127 {
36128 /* log only what the user can fix... */
36129 const u32 wantedmask = hotkey_driver_mask &
36130 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36131 }
36132 }
36133
36134 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36135 - struct tp_nvram_state *newn,
36136 - const u32 event_mask)
36137 -{
36138 -
36139 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36140 do { \
36141 if ((event_mask & (1 << __scancode)) && \
36142 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36143 tpacpi_hotkey_send_key(__scancode); \
36144 } while (0)
36145
36146 - void issue_volchange(const unsigned int oldvol,
36147 - const unsigned int newvol)
36148 - {
36149 - unsigned int i = oldvol;
36150 +static void issue_volchange(const unsigned int oldvol,
36151 + const unsigned int newvol,
36152 + const u32 event_mask)
36153 +{
36154 + unsigned int i = oldvol;
36155
36156 - while (i > newvol) {
36157 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36158 - i--;
36159 - }
36160 - while (i < newvol) {
36161 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36162 - i++;
36163 - }
36164 + while (i > newvol) {
36165 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36166 + i--;
36167 }
36168 + while (i < newvol) {
36169 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36170 + i++;
36171 + }
36172 +}
36173
36174 - void issue_brightnesschange(const unsigned int oldbrt,
36175 - const unsigned int newbrt)
36176 - {
36177 - unsigned int i = oldbrt;
36178 +static void issue_brightnesschange(const unsigned int oldbrt,
36179 + const unsigned int newbrt,
36180 + const u32 event_mask)
36181 +{
36182 + unsigned int i = oldbrt;
36183
36184 - while (i > newbrt) {
36185 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36186 - i--;
36187 - }
36188 - while (i < newbrt) {
36189 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36190 - i++;
36191 - }
36192 + while (i > newbrt) {
36193 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36194 + i--;
36195 + }
36196 + while (i < newbrt) {
36197 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36198 + i++;
36199 }
36200 +}
36201
36202 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36203 + struct tp_nvram_state *newn,
36204 + const u32 event_mask)
36205 +{
36206 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36207 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36208 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36209 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36210 oldn->volume_level != newn->volume_level) {
36211 /* recently muted, or repeated mute keypress, or
36212 * multiple presses ending in mute */
36213 - issue_volchange(oldn->volume_level, newn->volume_level);
36214 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36215 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36216 }
36217 } else {
36218 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36219 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36220 }
36221 if (oldn->volume_level != newn->volume_level) {
36222 - issue_volchange(oldn->volume_level, newn->volume_level);
36223 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36224 } else if (oldn->volume_toggle != newn->volume_toggle) {
36225 /* repeated vol up/down keypress at end of scale ? */
36226 if (newn->volume_level == 0)
36227 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36228 /* handle brightness */
36229 if (oldn->brightness_level != newn->brightness_level) {
36230 issue_brightnesschange(oldn->brightness_level,
36231 - newn->brightness_level);
36232 + newn->brightness_level,
36233 + event_mask);
36234 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36235 /* repeated key presses that didn't change state */
36236 if (newn->brightness_level == 0)
36237 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36238 && !tp_features.bright_unkfw)
36239 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36240 }
36241 +}
36242
36243 #undef TPACPI_COMPARE_KEY
36244 #undef TPACPI_MAY_SEND_KEY
36245 -}
36246
36247 /*
36248 * Polling driver
36249 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
36250 index dcdc1f4..85cee16 100644
36251 --- a/drivers/platform/x86/toshiba_acpi.c
36252 +++ b/drivers/platform/x86/toshiba_acpi.c
36253 @@ -517,6 +517,8 @@ static int set_lcd_status(struct backlight_device *bd)
36254 }
36255
36256 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36257 + size_t count, loff_t *pos) __size_overflow(3);
36258 +static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36259 size_t count, loff_t *pos)
36260 {
36261 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
36262 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36263 index b859d16..5cc6b1a 100644
36264 --- a/drivers/pnp/pnpbios/bioscalls.c
36265 +++ b/drivers/pnp/pnpbios/bioscalls.c
36266 @@ -59,7 +59,7 @@ do { \
36267 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36268 } while(0)
36269
36270 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36271 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36272 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36273
36274 /*
36275 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36276
36277 cpu = get_cpu();
36278 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36279 +
36280 + pax_open_kernel();
36281 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36282 + pax_close_kernel();
36283
36284 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36285 spin_lock_irqsave(&pnp_bios_lock, flags);
36286 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36287 :"memory");
36288 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36289
36290 + pax_open_kernel();
36291 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36292 + pax_close_kernel();
36293 +
36294 put_cpu();
36295
36296 /* If we get here and this is set then the PnP BIOS faulted on us. */
36297 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36298 return status;
36299 }
36300
36301 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36302 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36303 {
36304 int i;
36305
36306 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36307 pnp_bios_callpoint.offset = header->fields.pm16offset;
36308 pnp_bios_callpoint.segment = PNP_CS16;
36309
36310 + pax_open_kernel();
36311 +
36312 for_each_possible_cpu(i) {
36313 struct desc_struct *gdt = get_cpu_gdt_table(i);
36314 if (!gdt)
36315 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36316 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36317 (unsigned long)__va(header->fields.pm16dseg));
36318 }
36319 +
36320 + pax_close_kernel();
36321 }
36322 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36323 index b0ecacb..7c9da2e 100644
36324 --- a/drivers/pnp/resource.c
36325 +++ b/drivers/pnp/resource.c
36326 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36327 return 1;
36328
36329 /* check if the resource is valid */
36330 - if (*irq < 0 || *irq > 15)
36331 + if (*irq > 15)
36332 return 0;
36333
36334 /* check if the resource is reserved */
36335 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36336 return 1;
36337
36338 /* check if the resource is valid */
36339 - if (*dma < 0 || *dma == 4 || *dma > 7)
36340 + if (*dma == 4 || *dma > 7)
36341 return 0;
36342
36343 /* check if the resource is reserved */
36344 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36345 index 1ed6ea0..77c0bd2 100644
36346 --- a/drivers/power/bq27x00_battery.c
36347 +++ b/drivers/power/bq27x00_battery.c
36348 @@ -72,7 +72,7 @@
36349 struct bq27x00_device_info;
36350 struct bq27x00_access_methods {
36351 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36352 -};
36353 +} __no_const;
36354
36355 enum bq27x00_chip { BQ27000, BQ27500 };
36356
36357 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36358 index a838e66..a9e1665 100644
36359 --- a/drivers/regulator/max8660.c
36360 +++ b/drivers/regulator/max8660.c
36361 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36362 max8660->shadow_regs[MAX8660_OVER1] = 5;
36363 } else {
36364 /* Otherwise devices can be toggled via software */
36365 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36366 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36367 + pax_open_kernel();
36368 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36369 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36370 + pax_close_kernel();
36371 }
36372
36373 /*
36374 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36375 index e8cfc99..072aee2 100644
36376 --- a/drivers/regulator/mc13892-regulator.c
36377 +++ b/drivers/regulator/mc13892-regulator.c
36378 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36379 }
36380 mc13xxx_unlock(mc13892);
36381
36382 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36383 + pax_open_kernel();
36384 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36385 = mc13892_vcam_set_mode;
36386 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36387 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36388 = mc13892_vcam_get_mode;
36389 + pax_close_kernel();
36390
36391 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36392 ARRAY_SIZE(mc13892_regulators));
36393 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36394 index cace6d3..f623fda 100644
36395 --- a/drivers/rtc/rtc-dev.c
36396 +++ b/drivers/rtc/rtc-dev.c
36397 @@ -14,6 +14,7 @@
36398 #include <linux/module.h>
36399 #include <linux/rtc.h>
36400 #include <linux/sched.h>
36401 +#include <linux/grsecurity.h>
36402 #include "rtc-core.h"
36403
36404 static dev_t rtc_devt;
36405 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36406 if (copy_from_user(&tm, uarg, sizeof(tm)))
36407 return -EFAULT;
36408
36409 + gr_log_timechange();
36410 +
36411 return rtc_set_time(rtc, &tm);
36412
36413 case RTC_PIE_ON:
36414 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36415 index ffb5878..e6d785c 100644
36416 --- a/drivers/scsi/aacraid/aacraid.h
36417 +++ b/drivers/scsi/aacraid/aacraid.h
36418 @@ -492,7 +492,7 @@ struct adapter_ops
36419 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36420 /* Administrative operations */
36421 int (*adapter_comm)(struct aac_dev * dev, int comm);
36422 -};
36423 +} __no_const;
36424
36425 /*
36426 * Define which interrupt handler needs to be installed
36427 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36428 index 705e13e..91c873c 100644
36429 --- a/drivers/scsi/aacraid/linit.c
36430 +++ b/drivers/scsi/aacraid/linit.c
36431 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36432 #elif defined(__devinitconst)
36433 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36434 #else
36435 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36436 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36437 #endif
36438 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36439 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36440 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36441 index d5ff142..49c0ebb 100644
36442 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36443 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36444 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36445 .lldd_control_phy = asd_control_phy,
36446 };
36447
36448 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36449 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36450 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36451 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36452 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36453 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36454 index a796de9..1ef20e1 100644
36455 --- a/drivers/scsi/bfa/bfa.h
36456 +++ b/drivers/scsi/bfa/bfa.h
36457 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36458 u32 *end);
36459 int cpe_vec_q0;
36460 int rme_vec_q0;
36461 -};
36462 +} __no_const;
36463 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36464
36465 struct bfa_faa_cbfn_s {
36466 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36467 index f0f80e2..8ec946b 100644
36468 --- a/drivers/scsi/bfa/bfa_fcpim.c
36469 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36470 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36471
36472 bfa_iotag_attach(fcp);
36473
36474 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36475 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36476 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36477 (fcp->num_itns * sizeof(struct bfa_itn_s));
36478 memset(fcp->itn_arr, 0,
36479 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36480 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36481 {
36482 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36483 - struct bfa_itn_s *itn;
36484 + bfa_itn_s_no_const *itn;
36485
36486 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36487 itn->isr = isr;
36488 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36489 index 36f26da..38a34a8 100644
36490 --- a/drivers/scsi/bfa/bfa_fcpim.h
36491 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36492 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36493 struct bfa_itn_s {
36494 bfa_isr_func_t isr;
36495 };
36496 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36497
36498 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36499 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36500 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36501 struct list_head iotag_tio_free_q; /* free IO resources */
36502 struct list_head iotag_unused_q; /* unused IO resources*/
36503 struct bfa_iotag_s *iotag_arr;
36504 - struct bfa_itn_s *itn_arr;
36505 + bfa_itn_s_no_const *itn_arr;
36506 int num_ioim_reqs;
36507 int num_fwtio_reqs;
36508 int num_itns;
36509 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36510 index 546d46b..642fa5b 100644
36511 --- a/drivers/scsi/bfa/bfa_ioc.h
36512 +++ b/drivers/scsi/bfa/bfa_ioc.h
36513 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36514 bfa_ioc_disable_cbfn_t disable_cbfn;
36515 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36516 bfa_ioc_reset_cbfn_t reset_cbfn;
36517 -};
36518 +} __no_const;
36519
36520 /*
36521 * IOC event notification mechanism.
36522 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36523 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36524 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36525 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36526 -};
36527 +} __no_const;
36528
36529 /*
36530 * Queue element to wait for room in request queue. FIFO order is
36531 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36532 index 351dc0b..951dc32 100644
36533 --- a/drivers/scsi/hosts.c
36534 +++ b/drivers/scsi/hosts.c
36535 @@ -42,7 +42,7 @@
36536 #include "scsi_logging.h"
36537
36538
36539 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36540 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36541
36542
36543 static void scsi_host_cls_release(struct device *dev)
36544 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36545 * subtract one because we increment first then return, but we need to
36546 * know what the next host number was before increment
36547 */
36548 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36549 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36550 shost->dma_channel = 0xff;
36551
36552 /* These three are default values which can be overridden */
36553 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36554 index b96962c..0c82ec2 100644
36555 --- a/drivers/scsi/hpsa.c
36556 +++ b/drivers/scsi/hpsa.c
36557 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36558 u32 a;
36559
36560 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36561 - return h->access.command_completed(h);
36562 + return h->access->command_completed(h);
36563
36564 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36565 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36566 @@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
36567 while (!list_empty(&h->reqQ)) {
36568 c = list_entry(h->reqQ.next, struct CommandList, list);
36569 /* can't do anything if fifo is full */
36570 - if ((h->access.fifo_full(h))) {
36571 + if ((h->access->fifo_full(h))) {
36572 dev_warn(&h->pdev->dev, "fifo full\n");
36573 break;
36574 }
36575 @@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
36576 h->Qdepth--;
36577
36578 /* Tell the controller execute command */
36579 - h->access.submit_command(h, c);
36580 + h->access->submit_command(h, c);
36581
36582 /* Put job onto the completed Q */
36583 addQ(&h->cmpQ, c);
36584 @@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
36585
36586 static inline unsigned long get_next_completion(struct ctlr_info *h)
36587 {
36588 - return h->access.command_completed(h);
36589 + return h->access->command_completed(h);
36590 }
36591
36592 static inline bool interrupt_pending(struct ctlr_info *h)
36593 {
36594 - return h->access.intr_pending(h);
36595 + return h->access->intr_pending(h);
36596 }
36597
36598 static inline long interrupt_not_for_us(struct ctlr_info *h)
36599 {
36600 - return (h->access.intr_pending(h) == 0) ||
36601 + return (h->access->intr_pending(h) == 0) ||
36602 (h->interrupts_enabled == 0);
36603 }
36604
36605 @@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36606 if (prod_index < 0)
36607 return -ENODEV;
36608 h->product_name = products[prod_index].product_name;
36609 - h->access = *(products[prod_index].access);
36610 + h->access = products[prod_index].access;
36611
36612 if (hpsa_board_disabled(h->pdev)) {
36613 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36614 @@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36615
36616 assert_spin_locked(&lockup_detector_lock);
36617 remove_ctlr_from_lockup_detector_list(h);
36618 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36619 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36620 spin_lock_irqsave(&h->lock, flags);
36621 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36622 spin_unlock_irqrestore(&h->lock, flags);
36623 @@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
36624 }
36625
36626 /* make sure the board interrupts are off */
36627 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36628 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36629
36630 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36631 goto clean2;
36632 @@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
36633 * fake ones to scoop up any residual completions.
36634 */
36635 spin_lock_irqsave(&h->lock, flags);
36636 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36637 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36638 spin_unlock_irqrestore(&h->lock, flags);
36639 free_irq(h->intr[h->intr_mode], h);
36640 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36641 @@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
36642 dev_info(&h->pdev->dev, "Board READY.\n");
36643 dev_info(&h->pdev->dev,
36644 "Waiting for stale completions to drain.\n");
36645 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36646 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36647 msleep(10000);
36648 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36649 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36650
36651 rc = controller_reset_failed(h->cfgtable);
36652 if (rc)
36653 @@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
36654 }
36655
36656 /* Turn the interrupts on so we can service requests */
36657 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36658 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36659
36660 hpsa_hba_inquiry(h);
36661 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36662 @@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36663 * To write all data in the battery backed cache to disks
36664 */
36665 hpsa_flush_cache(h);
36666 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36667 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36668 free_irq(h->intr[h->intr_mode], h);
36669 #ifdef CONFIG_PCI_MSI
36670 if (h->msix_vector)
36671 @@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36672 return;
36673 }
36674 /* Change the access methods to the performant access methods */
36675 - h->access = SA5_performant_access;
36676 + h->access = &SA5_performant_access;
36677 h->transMethod = CFGTBL_Trans_Performant;
36678 }
36679
36680 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36681 index 91edafb..a9b88ec 100644
36682 --- a/drivers/scsi/hpsa.h
36683 +++ b/drivers/scsi/hpsa.h
36684 @@ -73,7 +73,7 @@ struct ctlr_info {
36685 unsigned int msix_vector;
36686 unsigned int msi_vector;
36687 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36688 - struct access_method access;
36689 + struct access_method *access;
36690
36691 /* queue and queue Info */
36692 struct list_head reqQ;
36693 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36694 index f2df059..a3a9930 100644
36695 --- a/drivers/scsi/ips.h
36696 +++ b/drivers/scsi/ips.h
36697 @@ -1027,7 +1027,7 @@ typedef struct {
36698 int (*intr)(struct ips_ha *);
36699 void (*enableint)(struct ips_ha *);
36700 uint32_t (*statupd)(struct ips_ha *);
36701 -} ips_hw_func_t;
36702 +} __no_const ips_hw_func_t;
36703
36704 typedef struct ips_ha {
36705 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36706 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36707 index 4d70d96..84d0573 100644
36708 --- a/drivers/scsi/libfc/fc_exch.c
36709 +++ b/drivers/scsi/libfc/fc_exch.c
36710 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36711 * all together if not used XXX
36712 */
36713 struct {
36714 - atomic_t no_free_exch;
36715 - atomic_t no_free_exch_xid;
36716 - atomic_t xid_not_found;
36717 - atomic_t xid_busy;
36718 - atomic_t seq_not_found;
36719 - atomic_t non_bls_resp;
36720 + atomic_unchecked_t no_free_exch;
36721 + atomic_unchecked_t no_free_exch_xid;
36722 + atomic_unchecked_t xid_not_found;
36723 + atomic_unchecked_t xid_busy;
36724 + atomic_unchecked_t seq_not_found;
36725 + atomic_unchecked_t non_bls_resp;
36726 } stats;
36727 };
36728
36729 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36730 /* allocate memory for exchange */
36731 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36732 if (!ep) {
36733 - atomic_inc(&mp->stats.no_free_exch);
36734 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36735 goto out;
36736 }
36737 memset(ep, 0, sizeof(*ep));
36738 @@ -780,7 +780,7 @@ out:
36739 return ep;
36740 err:
36741 spin_unlock_bh(&pool->lock);
36742 - atomic_inc(&mp->stats.no_free_exch_xid);
36743 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36744 mempool_free(ep, mp->ep_pool);
36745 return NULL;
36746 }
36747 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36748 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36749 ep = fc_exch_find(mp, xid);
36750 if (!ep) {
36751 - atomic_inc(&mp->stats.xid_not_found);
36752 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36753 reject = FC_RJT_OX_ID;
36754 goto out;
36755 }
36756 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36757 ep = fc_exch_find(mp, xid);
36758 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36759 if (ep) {
36760 - atomic_inc(&mp->stats.xid_busy);
36761 + atomic_inc_unchecked(&mp->stats.xid_busy);
36762 reject = FC_RJT_RX_ID;
36763 goto rel;
36764 }
36765 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36766 }
36767 xid = ep->xid; /* get our XID */
36768 } else if (!ep) {
36769 - atomic_inc(&mp->stats.xid_not_found);
36770 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36771 reject = FC_RJT_RX_ID; /* XID not found */
36772 goto out;
36773 }
36774 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36775 } else {
36776 sp = &ep->seq;
36777 if (sp->id != fh->fh_seq_id) {
36778 - atomic_inc(&mp->stats.seq_not_found);
36779 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36780 if (f_ctl & FC_FC_END_SEQ) {
36781 /*
36782 * Update sequence_id based on incoming last
36783 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36784
36785 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36786 if (!ep) {
36787 - atomic_inc(&mp->stats.xid_not_found);
36788 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36789 goto out;
36790 }
36791 if (ep->esb_stat & ESB_ST_COMPLETE) {
36792 - atomic_inc(&mp->stats.xid_not_found);
36793 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36794 goto rel;
36795 }
36796 if (ep->rxid == FC_XID_UNKNOWN)
36797 ep->rxid = ntohs(fh->fh_rx_id);
36798 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36799 - atomic_inc(&mp->stats.xid_not_found);
36800 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36801 goto rel;
36802 }
36803 if (ep->did != ntoh24(fh->fh_s_id) &&
36804 ep->did != FC_FID_FLOGI) {
36805 - atomic_inc(&mp->stats.xid_not_found);
36806 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36807 goto rel;
36808 }
36809 sof = fr_sof(fp);
36810 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36811 sp->ssb_stat |= SSB_ST_RESP;
36812 sp->id = fh->fh_seq_id;
36813 } else if (sp->id != fh->fh_seq_id) {
36814 - atomic_inc(&mp->stats.seq_not_found);
36815 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36816 goto rel;
36817 }
36818
36819 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36820 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36821
36822 if (!sp)
36823 - atomic_inc(&mp->stats.xid_not_found);
36824 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36825 else
36826 - atomic_inc(&mp->stats.non_bls_resp);
36827 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36828
36829 fc_frame_free(fp);
36830 }
36831 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36832 index db9238f..4378ed2 100644
36833 --- a/drivers/scsi/libsas/sas_ata.c
36834 +++ b/drivers/scsi/libsas/sas_ata.c
36835 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36836 .postreset = ata_std_postreset,
36837 .error_handler = ata_std_error_handler,
36838 .post_internal_cmd = sas_ata_post_internal,
36839 - .qc_defer = ata_std_qc_defer,
36840 + .qc_defer = ata_std_qc_defer,
36841 .qc_prep = ata_noop_qc_prep,
36842 .qc_issue = sas_ata_qc_issue,
36843 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36844 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36845 index 825f930..ce42672 100644
36846 --- a/drivers/scsi/lpfc/lpfc.h
36847 +++ b/drivers/scsi/lpfc/lpfc.h
36848 @@ -413,7 +413,7 @@ struct lpfc_vport {
36849 struct dentry *debug_nodelist;
36850 struct dentry *vport_debugfs_root;
36851 struct lpfc_debugfs_trc *disc_trc;
36852 - atomic_t disc_trc_cnt;
36853 + atomic_unchecked_t disc_trc_cnt;
36854 #endif
36855 uint8_t stat_data_enabled;
36856 uint8_t stat_data_blocked;
36857 @@ -821,8 +821,8 @@ struct lpfc_hba {
36858 struct timer_list fabric_block_timer;
36859 unsigned long bit_flags;
36860 #define FABRIC_COMANDS_BLOCKED 0
36861 - atomic_t num_rsrc_err;
36862 - atomic_t num_cmd_success;
36863 + atomic_unchecked_t num_rsrc_err;
36864 + atomic_unchecked_t num_cmd_success;
36865 unsigned long last_rsrc_error_time;
36866 unsigned long last_ramp_down_time;
36867 unsigned long last_ramp_up_time;
36868 @@ -852,7 +852,7 @@ struct lpfc_hba {
36869
36870 struct dentry *debug_slow_ring_trc;
36871 struct lpfc_debugfs_trc *slow_ring_trc;
36872 - atomic_t slow_ring_trc_cnt;
36873 + atomic_unchecked_t slow_ring_trc_cnt;
36874 /* iDiag debugfs sub-directory */
36875 struct dentry *idiag_root;
36876 struct dentry *idiag_pci_cfg;
36877 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36878 index 3587a3f..d45b81b 100644
36879 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36880 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36881 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36882
36883 #include <linux/debugfs.h>
36884
36885 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36886 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36887 static unsigned long lpfc_debugfs_start_time = 0L;
36888
36889 /* iDiag */
36890 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36891 lpfc_debugfs_enable = 0;
36892
36893 len = 0;
36894 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36895 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36896 (lpfc_debugfs_max_disc_trc - 1);
36897 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36898 dtp = vport->disc_trc + i;
36899 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36900 lpfc_debugfs_enable = 0;
36901
36902 len = 0;
36903 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36904 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36905 (lpfc_debugfs_max_slow_ring_trc - 1);
36906 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36907 dtp = phba->slow_ring_trc + i;
36908 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36909 !vport || !vport->disc_trc)
36910 return;
36911
36912 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36913 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36914 (lpfc_debugfs_max_disc_trc - 1);
36915 dtp = vport->disc_trc + index;
36916 dtp->fmt = fmt;
36917 dtp->data1 = data1;
36918 dtp->data2 = data2;
36919 dtp->data3 = data3;
36920 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36921 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36922 dtp->jif = jiffies;
36923 #endif
36924 return;
36925 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36926 !phba || !phba->slow_ring_trc)
36927 return;
36928
36929 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36930 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36931 (lpfc_debugfs_max_slow_ring_trc - 1);
36932 dtp = phba->slow_ring_trc + index;
36933 dtp->fmt = fmt;
36934 dtp->data1 = data1;
36935 dtp->data2 = data2;
36936 dtp->data3 = data3;
36937 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36938 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36939 dtp->jif = jiffies;
36940 #endif
36941 return;
36942 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36943 "slow_ring buffer\n");
36944 goto debug_failed;
36945 }
36946 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36947 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36948 memset(phba->slow_ring_trc, 0,
36949 (sizeof(struct lpfc_debugfs_trc) *
36950 lpfc_debugfs_max_slow_ring_trc));
36951 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36952 "buffer\n");
36953 goto debug_failed;
36954 }
36955 - atomic_set(&vport->disc_trc_cnt, 0);
36956 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36957
36958 snprintf(name, sizeof(name), "discovery_trace");
36959 vport->debug_disc_trc =
36960 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36961 index dfea2da..8e17227 100644
36962 --- a/drivers/scsi/lpfc/lpfc_init.c
36963 +++ b/drivers/scsi/lpfc/lpfc_init.c
36964 @@ -10145,8 +10145,10 @@ lpfc_init(void)
36965 printk(LPFC_COPYRIGHT "\n");
36966
36967 if (lpfc_enable_npiv) {
36968 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36969 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36970 + pax_open_kernel();
36971 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36972 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36973 + pax_close_kernel();
36974 }
36975 lpfc_transport_template =
36976 fc_attach_transport(&lpfc_transport_functions);
36977 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36978 index c60f5d0..751535c 100644
36979 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36980 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36981 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36982 uint32_t evt_posted;
36983
36984 spin_lock_irqsave(&phba->hbalock, flags);
36985 - atomic_inc(&phba->num_rsrc_err);
36986 + atomic_inc_unchecked(&phba->num_rsrc_err);
36987 phba->last_rsrc_error_time = jiffies;
36988
36989 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36990 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36991 unsigned long flags;
36992 struct lpfc_hba *phba = vport->phba;
36993 uint32_t evt_posted;
36994 - atomic_inc(&phba->num_cmd_success);
36995 + atomic_inc_unchecked(&phba->num_cmd_success);
36996
36997 if (vport->cfg_lun_queue_depth <= queue_depth)
36998 return;
36999 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37000 unsigned long num_rsrc_err, num_cmd_success;
37001 int i;
37002
37003 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37004 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37005 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37006 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37007
37008 vports = lpfc_create_vport_work_array(phba);
37009 if (vports != NULL)
37010 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37011 }
37012 }
37013 lpfc_destroy_vport_work_array(phba, vports);
37014 - atomic_set(&phba->num_rsrc_err, 0);
37015 - atomic_set(&phba->num_cmd_success, 0);
37016 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37017 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37018 }
37019
37020 /**
37021 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37022 }
37023 }
37024 lpfc_destroy_vport_work_array(phba, vports);
37025 - atomic_set(&phba->num_rsrc_err, 0);
37026 - atomic_set(&phba->num_cmd_success, 0);
37027 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37028 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37029 }
37030
37031 /**
37032 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37033 index ea8a0b4..812a124 100644
37034 --- a/drivers/scsi/pmcraid.c
37035 +++ b/drivers/scsi/pmcraid.c
37036 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37037 res->scsi_dev = scsi_dev;
37038 scsi_dev->hostdata = res;
37039 res->change_detected = 0;
37040 - atomic_set(&res->read_failures, 0);
37041 - atomic_set(&res->write_failures, 0);
37042 + atomic_set_unchecked(&res->read_failures, 0);
37043 + atomic_set_unchecked(&res->write_failures, 0);
37044 rc = 0;
37045 }
37046 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37047 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37048
37049 /* If this was a SCSI read/write command keep count of errors */
37050 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37051 - atomic_inc(&res->read_failures);
37052 + atomic_inc_unchecked(&res->read_failures);
37053 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37054 - atomic_inc(&res->write_failures);
37055 + atomic_inc_unchecked(&res->write_failures);
37056
37057 if (!RES_IS_GSCSI(res->cfg_entry) &&
37058 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37059 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37060 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37061 * hrrq_id assigned here in queuecommand
37062 */
37063 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37064 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37065 pinstance->num_hrrq;
37066 cmd->cmd_done = pmcraid_io_done;
37067
37068 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37069 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37070 * hrrq_id assigned here in queuecommand
37071 */
37072 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37073 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37074 pinstance->num_hrrq;
37075
37076 if (request_size) {
37077 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37078
37079 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37080 /* add resources only after host is added into system */
37081 - if (!atomic_read(&pinstance->expose_resources))
37082 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37083 return;
37084
37085 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37086 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37087 init_waitqueue_head(&pinstance->reset_wait_q);
37088
37089 atomic_set(&pinstance->outstanding_cmds, 0);
37090 - atomic_set(&pinstance->last_message_id, 0);
37091 - atomic_set(&pinstance->expose_resources, 0);
37092 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37093 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37094
37095 INIT_LIST_HEAD(&pinstance->free_res_q);
37096 INIT_LIST_HEAD(&pinstance->used_res_q);
37097 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37098 /* Schedule worker thread to handle CCN and take care of adding and
37099 * removing devices to OS
37100 */
37101 - atomic_set(&pinstance->expose_resources, 1);
37102 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37103 schedule_work(&pinstance->worker_q);
37104 return rc;
37105
37106 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37107 index ca496c7..9c791d5 100644
37108 --- a/drivers/scsi/pmcraid.h
37109 +++ b/drivers/scsi/pmcraid.h
37110 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37111 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37112
37113 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37114 - atomic_t last_message_id;
37115 + atomic_unchecked_t last_message_id;
37116
37117 /* configuration table */
37118 struct pmcraid_config_table *cfg_table;
37119 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37120 atomic_t outstanding_cmds;
37121
37122 /* should add/delete resources to mid-layer now ?*/
37123 - atomic_t expose_resources;
37124 + atomic_unchecked_t expose_resources;
37125
37126
37127
37128 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37129 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37130 };
37131 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37132 - atomic_t read_failures; /* count of failed READ commands */
37133 - atomic_t write_failures; /* count of failed WRITE commands */
37134 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37135 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37136
37137 /* To indicate add/delete/modify during CCN */
37138 u8 change_detected;
37139 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37140 index af1003f..be55a75 100644
37141 --- a/drivers/scsi/qla2xxx/qla_def.h
37142 +++ b/drivers/scsi/qla2xxx/qla_def.h
37143 @@ -2247,7 +2247,7 @@ struct isp_operations {
37144 int (*start_scsi) (srb_t *);
37145 int (*abort_isp) (struct scsi_qla_host *);
37146 int (*iospace_config)(struct qla_hw_data*);
37147 -};
37148 +} __no_const;
37149
37150 /* MSI-X Support *************************************************************/
37151
37152 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37153 index bfe6854..ceac088 100644
37154 --- a/drivers/scsi/qla4xxx/ql4_def.h
37155 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37156 @@ -261,7 +261,7 @@ struct ddb_entry {
37157 * (4000 only) */
37158 atomic_t relogin_timer; /* Max Time to wait for
37159 * relogin to complete */
37160 - atomic_t relogin_retry_count; /* Num of times relogin has been
37161 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37162 * retried */
37163 uint32_t default_time2wait; /* Default Min time between
37164 * relogins (+aens) */
37165 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37166 index ce6d3b7..73fac54 100644
37167 --- a/drivers/scsi/qla4xxx/ql4_os.c
37168 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37169 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37170 */
37171 if (!iscsi_is_session_online(cls_sess)) {
37172 /* Reset retry relogin timer */
37173 - atomic_inc(&ddb_entry->relogin_retry_count);
37174 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37175 DEBUG2(ql4_printk(KERN_INFO, ha,
37176 "%s: index[%d] relogin timed out-retrying"
37177 " relogin (%d), retry (%d)\n", __func__,
37178 ddb_entry->fw_ddb_index,
37179 - atomic_read(&ddb_entry->relogin_retry_count),
37180 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37181 ddb_entry->default_time2wait + 4));
37182 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37183 atomic_set(&ddb_entry->retry_relogin_timer,
37184 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37185
37186 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37187 atomic_set(&ddb_entry->relogin_timer, 0);
37188 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37189 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37190 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37191 ddb_entry->default_relogin_timeout =
37192 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37193 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37194 index 2aeb2e9..46e3925 100644
37195 --- a/drivers/scsi/scsi.c
37196 +++ b/drivers/scsi/scsi.c
37197 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37198 unsigned long timeout;
37199 int rtn = 0;
37200
37201 - atomic_inc(&cmd->device->iorequest_cnt);
37202 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37203
37204 /* check if the device is still usable */
37205 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37206 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37207 index b2c95db..227d74e 100644
37208 --- a/drivers/scsi/scsi_lib.c
37209 +++ b/drivers/scsi/scsi_lib.c
37210 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37211 shost = sdev->host;
37212 scsi_init_cmd_errh(cmd);
37213 cmd->result = DID_NO_CONNECT << 16;
37214 - atomic_inc(&cmd->device->iorequest_cnt);
37215 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37216
37217 /*
37218 * SCSI request completion path will do scsi_device_unbusy(),
37219 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37220
37221 INIT_LIST_HEAD(&cmd->eh_entry);
37222
37223 - atomic_inc(&cmd->device->iodone_cnt);
37224 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37225 if (cmd->result)
37226 - atomic_inc(&cmd->device->ioerr_cnt);
37227 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37228
37229 disposition = scsi_decide_disposition(cmd);
37230 if (disposition != SUCCESS &&
37231 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37232 index 04c2a27..9d8bd66 100644
37233 --- a/drivers/scsi/scsi_sysfs.c
37234 +++ b/drivers/scsi/scsi_sysfs.c
37235 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37236 char *buf) \
37237 { \
37238 struct scsi_device *sdev = to_scsi_device(dev); \
37239 - unsigned long long count = atomic_read(&sdev->field); \
37240 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37241 return snprintf(buf, 20, "0x%llx\n", count); \
37242 } \
37243 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37244 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37245 index 84a1fdf..693b0d6 100644
37246 --- a/drivers/scsi/scsi_tgt_lib.c
37247 +++ b/drivers/scsi/scsi_tgt_lib.c
37248 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37249 int err;
37250
37251 dprintk("%lx %u\n", uaddr, len);
37252 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37253 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37254 if (err) {
37255 /*
37256 * TODO: need to fixup sg_tablesize, max_segment_size,
37257 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37258 index f59d4a0..1d89407 100644
37259 --- a/drivers/scsi/scsi_transport_fc.c
37260 +++ b/drivers/scsi/scsi_transport_fc.c
37261 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37262 * Netlink Infrastructure
37263 */
37264
37265 -static atomic_t fc_event_seq;
37266 +static atomic_unchecked_t fc_event_seq;
37267
37268 /**
37269 * fc_get_event_number - Obtain the next sequential FC event number
37270 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37271 u32
37272 fc_get_event_number(void)
37273 {
37274 - return atomic_add_return(1, &fc_event_seq);
37275 + return atomic_add_return_unchecked(1, &fc_event_seq);
37276 }
37277 EXPORT_SYMBOL(fc_get_event_number);
37278
37279 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37280 {
37281 int error;
37282
37283 - atomic_set(&fc_event_seq, 0);
37284 + atomic_set_unchecked(&fc_event_seq, 0);
37285
37286 error = transport_class_register(&fc_host_class);
37287 if (error)
37288 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37289 char *cp;
37290
37291 *val = simple_strtoul(buf, &cp, 0);
37292 - if ((*cp && (*cp != '\n')) || (*val < 0))
37293 + if (*cp && (*cp != '\n'))
37294 return -EINVAL;
37295 /*
37296 * Check for overflow; dev_loss_tmo is u32
37297 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37298 index e3e3c7d..ebdab62 100644
37299 --- a/drivers/scsi/scsi_transport_iscsi.c
37300 +++ b/drivers/scsi/scsi_transport_iscsi.c
37301 @@ -79,7 +79,7 @@ struct iscsi_internal {
37302 struct transport_container session_cont;
37303 };
37304
37305 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37306 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37307 static struct workqueue_struct *iscsi_eh_timer_workq;
37308
37309 static DEFINE_IDA(iscsi_sess_ida);
37310 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37311 int err;
37312
37313 ihost = shost->shost_data;
37314 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37315 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37316
37317 if (target_id == ISCSI_MAX_TARGET) {
37318 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37319 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37320 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37321 ISCSI_TRANSPORT_VERSION);
37322
37323 - atomic_set(&iscsi_session_nr, 0);
37324 + atomic_set_unchecked(&iscsi_session_nr, 0);
37325
37326 err = class_register(&iscsi_transport_class);
37327 if (err)
37328 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37329 index 21a045e..ec89e03 100644
37330 --- a/drivers/scsi/scsi_transport_srp.c
37331 +++ b/drivers/scsi/scsi_transport_srp.c
37332 @@ -33,7 +33,7 @@
37333 #include "scsi_transport_srp_internal.h"
37334
37335 struct srp_host_attrs {
37336 - atomic_t next_port_id;
37337 + atomic_unchecked_t next_port_id;
37338 };
37339 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37340
37341 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37342 struct Scsi_Host *shost = dev_to_shost(dev);
37343 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37344
37345 - atomic_set(&srp_host->next_port_id, 0);
37346 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37347 return 0;
37348 }
37349
37350 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37351 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37352 rport->roles = ids->roles;
37353
37354 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37355 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37356 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37357
37358 transport_setup_device(&rport->dev);
37359 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37360 index eacd46b..e3f4d62 100644
37361 --- a/drivers/scsi/sg.c
37362 +++ b/drivers/scsi/sg.c
37363 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37364 sdp->disk->disk_name,
37365 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37366 NULL,
37367 - (char *)arg);
37368 + (char __user *)arg);
37369 case BLKTRACESTART:
37370 return blk_trace_startstop(sdp->device->request_queue, 1);
37371 case BLKTRACESTOP:
37372 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37373 const struct file_operations * fops;
37374 };
37375
37376 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37377 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37378 {"allow_dio", &adio_fops},
37379 {"debug", &debug_fops},
37380 {"def_reserved_size", &dressz_fops},
37381 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37382 if (!sg_proc_sgp)
37383 return 1;
37384 for (k = 0; k < num_leaves; ++k) {
37385 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37386 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37387 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37388 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37389 }
37390 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37391 index f64250e..1ee3049 100644
37392 --- a/drivers/spi/spi-dw-pci.c
37393 +++ b/drivers/spi/spi-dw-pci.c
37394 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37395 #define spi_resume NULL
37396 #endif
37397
37398 -static const struct pci_device_id pci_ids[] __devinitdata = {
37399 +static const struct pci_device_id pci_ids[] __devinitconst = {
37400 /* Intel MID platform SPI controller 0 */
37401 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37402 {},
37403 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37404 index b2ccdea..84cde75 100644
37405 --- a/drivers/spi/spi.c
37406 +++ b/drivers/spi/spi.c
37407 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37408 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37409
37410 /* portable code must never pass more than 32 bytes */
37411 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37412 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37413
37414 static u8 *buf;
37415
37416 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37417 index 400df8c..065d4f4 100644
37418 --- a/drivers/staging/octeon/ethernet-rx.c
37419 +++ b/drivers/staging/octeon/ethernet-rx.c
37420 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37421 /* Increment RX stats for virtual ports */
37422 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37423 #ifdef CONFIG_64BIT
37424 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37425 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37426 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37427 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37428 #else
37429 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37430 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37431 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37432 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37433 #endif
37434 }
37435 netif_receive_skb(skb);
37436 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37437 dev->name);
37438 */
37439 #ifdef CONFIG_64BIT
37440 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37441 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37442 #else
37443 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37444 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37445 #endif
37446 dev_kfree_skb_irq(skb);
37447 }
37448 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37449 index 9112cd8..92f8d51 100644
37450 --- a/drivers/staging/octeon/ethernet.c
37451 +++ b/drivers/staging/octeon/ethernet.c
37452 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37453 * since the RX tasklet also increments it.
37454 */
37455 #ifdef CONFIG_64BIT
37456 - atomic64_add(rx_status.dropped_packets,
37457 - (atomic64_t *)&priv->stats.rx_dropped);
37458 + atomic64_add_unchecked(rx_status.dropped_packets,
37459 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37460 #else
37461 - atomic_add(rx_status.dropped_packets,
37462 - (atomic_t *)&priv->stats.rx_dropped);
37463 + atomic_add_unchecked(rx_status.dropped_packets,
37464 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37465 #endif
37466 }
37467
37468 diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
37469 index f9dae95..ff48901 100644
37470 --- a/drivers/staging/rtl8192e/rtllib_module.c
37471 +++ b/drivers/staging/rtl8192e/rtllib_module.c
37472 @@ -215,6 +215,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37473 }
37474
37475 static int store_debug_level(struct file *file, const char __user *buffer,
37476 + unsigned long count, void *data) __size_overflow(3);
37477 +static int store_debug_level(struct file *file, const char __user *buffer,
37478 unsigned long count, void *data)
37479 {
37480 char buf[] = "0x00000000";
37481 diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37482 index e3d47bc..85f4d0d 100644
37483 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37484 +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37485 @@ -250,6 +250,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37486 }
37487
37488 static int store_debug_level(struct file *file, const char *buffer,
37489 + unsigned long count, void *data) __size_overflow(3);
37490 +static int store_debug_level(struct file *file, const char *buffer,
37491 unsigned long count, void *data)
37492 {
37493 char buf[] = "0x00000000";
37494 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37495 index 86308a0..feaa925 100644
37496 --- a/drivers/staging/rtl8712/rtl871x_io.h
37497 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37498 @@ -108,7 +108,7 @@ struct _io_ops {
37499 u8 *pmem);
37500 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37501 u8 *pmem);
37502 -};
37503 +} __no_const;
37504
37505 struct io_req {
37506 struct list_head list;
37507 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37508 index c7b5e8b..783d6cb 100644
37509 --- a/drivers/staging/sbe-2t3e3/netdev.c
37510 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37511 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37512 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37513
37514 if (rlen)
37515 - if (copy_to_user(data, &resp, rlen))
37516 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37517 return -EFAULT;
37518
37519 return 0;
37520 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37521 index 42cdafe..2769103 100644
37522 --- a/drivers/staging/speakup/speakup_soft.c
37523 +++ b/drivers/staging/speakup/speakup_soft.c
37524 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37525 break;
37526 } else if (!initialized) {
37527 if (*init) {
37528 - ch = *init;
37529 init++;
37530 } else {
37531 initialized = 1;
37532 }
37533 + ch = *init;
37534 } else {
37535 ch = synth_buffer_getc();
37536 }
37537 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37538 index b8f8c48..1fc5025 100644
37539 --- a/drivers/staging/usbip/usbip_common.h
37540 +++ b/drivers/staging/usbip/usbip_common.h
37541 @@ -289,7 +289,7 @@ struct usbip_device {
37542 void (*shutdown)(struct usbip_device *);
37543 void (*reset)(struct usbip_device *);
37544 void (*unusable)(struct usbip_device *);
37545 - } eh_ops;
37546 + } __no_const eh_ops;
37547 };
37548
37549 /* usbip_common.c */
37550 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37551 index 88b3298..3783eee 100644
37552 --- a/drivers/staging/usbip/vhci.h
37553 +++ b/drivers/staging/usbip/vhci.h
37554 @@ -88,7 +88,7 @@ struct vhci_hcd {
37555 unsigned resuming:1;
37556 unsigned long re_timeout;
37557
37558 - atomic_t seqnum;
37559 + atomic_unchecked_t seqnum;
37560
37561 /*
37562 * NOTE:
37563 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37564 index 2ee97e2..0420b86 100644
37565 --- a/drivers/staging/usbip/vhci_hcd.c
37566 +++ b/drivers/staging/usbip/vhci_hcd.c
37567 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37568 return;
37569 }
37570
37571 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37572 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37573 if (priv->seqnum == 0xffff)
37574 dev_info(&urb->dev->dev, "seqnum max\n");
37575
37576 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37577 return -ENOMEM;
37578 }
37579
37580 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37581 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37582 if (unlink->seqnum == 0xffff)
37583 pr_info("seqnum max\n");
37584
37585 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37586 vdev->rhport = rhport;
37587 }
37588
37589 - atomic_set(&vhci->seqnum, 0);
37590 + atomic_set_unchecked(&vhci->seqnum, 0);
37591 spin_lock_init(&vhci->lock);
37592
37593 hcd->power_budget = 0; /* no limit */
37594 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37595 index 3f511b4..d3dbc1e 100644
37596 --- a/drivers/staging/usbip/vhci_rx.c
37597 +++ b/drivers/staging/usbip/vhci_rx.c
37598 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37599 if (!urb) {
37600 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37601 pr_info("max seqnum %d\n",
37602 - atomic_read(&the_controller->seqnum));
37603 + atomic_read_unchecked(&the_controller->seqnum));
37604 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37605 return;
37606 }
37607 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37608 index 7735027..30eed13 100644
37609 --- a/drivers/staging/vt6655/hostap.c
37610 +++ b/drivers/staging/vt6655/hostap.c
37611 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37612 *
37613 */
37614
37615 +static net_device_ops_no_const apdev_netdev_ops;
37616 +
37617 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37618 {
37619 PSDevice apdev_priv;
37620 struct net_device *dev = pDevice->dev;
37621 int ret;
37622 - const struct net_device_ops apdev_netdev_ops = {
37623 - .ndo_start_xmit = pDevice->tx_80211,
37624 - };
37625
37626 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37627
37628 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37629 *apdev_priv = *pDevice;
37630 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37631
37632 + /* only half broken now */
37633 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37634 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37635
37636 pDevice->apdev->type = ARPHRD_IEEE80211;
37637 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37638 index 51b5adf..098e320 100644
37639 --- a/drivers/staging/vt6656/hostap.c
37640 +++ b/drivers/staging/vt6656/hostap.c
37641 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37642 *
37643 */
37644
37645 +static net_device_ops_no_const apdev_netdev_ops;
37646 +
37647 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37648 {
37649 PSDevice apdev_priv;
37650 struct net_device *dev = pDevice->dev;
37651 int ret;
37652 - const struct net_device_ops apdev_netdev_ops = {
37653 - .ndo_start_xmit = pDevice->tx_80211,
37654 - };
37655
37656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37657
37658 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37659 *apdev_priv = *pDevice;
37660 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37661
37662 + /* only half broken now */
37663 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37664 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37665
37666 pDevice->apdev->type = ARPHRD_IEEE80211;
37667 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37668 index 7843dfd..3db105f 100644
37669 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37670 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37671 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37672
37673 struct usbctlx_completor {
37674 int (*complete) (struct usbctlx_completor *);
37675 -};
37676 +} __no_const;
37677
37678 static int
37679 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37680 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37681 index 1ca66ea..76f1343 100644
37682 --- a/drivers/staging/zcache/tmem.c
37683 +++ b/drivers/staging/zcache/tmem.c
37684 @@ -39,7 +39,7 @@
37685 * A tmem host implementation must use this function to register callbacks
37686 * for memory allocation.
37687 */
37688 -static struct tmem_hostops tmem_hostops;
37689 +static tmem_hostops_no_const tmem_hostops;
37690
37691 static void tmem_objnode_tree_init(void);
37692
37693 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37694 * A tmem host implementation must use this function to register
37695 * callbacks for a page-accessible memory (PAM) implementation
37696 */
37697 -static struct tmem_pamops tmem_pamops;
37698 +static tmem_pamops_no_const tmem_pamops;
37699
37700 void tmem_register_pamops(struct tmem_pamops *m)
37701 {
37702 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37703 index ed147c4..94fc3c6 100644
37704 --- a/drivers/staging/zcache/tmem.h
37705 +++ b/drivers/staging/zcache/tmem.h
37706 @@ -180,6 +180,7 @@ struct tmem_pamops {
37707 void (*new_obj)(struct tmem_obj *);
37708 int (*replace_in_obj)(void *, struct tmem_obj *);
37709 };
37710 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37711 extern void tmem_register_pamops(struct tmem_pamops *m);
37712
37713 /* memory allocation methods provided by the host implementation */
37714 @@ -189,6 +190,7 @@ struct tmem_hostops {
37715 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37716 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37717 };
37718 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37719 extern void tmem_register_hostops(struct tmem_hostops *m);
37720
37721 /* core tmem accessor functions */
37722 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37723 index 97c74ee..7f6d77d 100644
37724 --- a/drivers/target/iscsi/iscsi_target.c
37725 +++ b/drivers/target/iscsi/iscsi_target.c
37726 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37727 * outstanding_r2ts reaches zero, go ahead and send the delayed
37728 * TASK_ABORTED status.
37729 */
37730 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37731 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37732 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37733 if (--cmd->outstanding_r2ts < 1) {
37734 iscsit_stop_dataout_timer(cmd);
37735 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37736 index dcb0618..97e3d85 100644
37737 --- a/drivers/target/target_core_tmr.c
37738 +++ b/drivers/target/target_core_tmr.c
37739 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
37740 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37741 cmd->t_task_list_num,
37742 atomic_read(&cmd->t_task_cdbs_left),
37743 - atomic_read(&cmd->t_task_cdbs_sent),
37744 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37745 atomic_read(&cmd->t_transport_active),
37746 atomic_read(&cmd->t_transport_stop),
37747 atomic_read(&cmd->t_transport_sent));
37748 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37749 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37750 " task: %p, t_fe_count: %d dev: %p\n", task,
37751 fe_count, dev);
37752 - atomic_set(&cmd->t_transport_aborted, 1);
37753 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37754 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37755
37756 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37757 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37758 }
37759 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37760 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37761 - atomic_set(&cmd->t_transport_aborted, 1);
37762 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37763 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37764
37765 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37766 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37767 index cd5cd95..5249d30 100644
37768 --- a/drivers/target/target_core_transport.c
37769 +++ b/drivers/target/target_core_transport.c
37770 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
37771 spin_lock_init(&dev->se_port_lock);
37772 spin_lock_init(&dev->se_tmr_lock);
37773 spin_lock_init(&dev->qf_cmd_lock);
37774 - atomic_set(&dev->dev_ordered_id, 0);
37775 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37776
37777 se_dev_set_default_attribs(dev, dev_limits);
37778
37779 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37780 * Used to determine when ORDERED commands should go from
37781 * Dormant to Active status.
37782 */
37783 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37784 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37785 smp_mb__after_atomic_inc();
37786 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37787 cmd->se_ordered_id, cmd->sam_task_attr,
37788 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37789 " t_transport_active: %d t_transport_stop: %d"
37790 " t_transport_sent: %d\n", cmd->t_task_list_num,
37791 atomic_read(&cmd->t_task_cdbs_left),
37792 - atomic_read(&cmd->t_task_cdbs_sent),
37793 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37794 atomic_read(&cmd->t_task_cdbs_ex_left),
37795 atomic_read(&cmd->t_transport_active),
37796 atomic_read(&cmd->t_transport_stop),
37797 @@ -2121,9 +2121,9 @@ check_depth:
37798 cmd = task->task_se_cmd;
37799 spin_lock_irqsave(&cmd->t_state_lock, flags);
37800 task->task_flags |= (TF_ACTIVE | TF_SENT);
37801 - atomic_inc(&cmd->t_task_cdbs_sent);
37802 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37803
37804 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37805 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37806 cmd->t_task_list_num)
37807 atomic_set(&cmd->t_transport_sent, 1);
37808
37809 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37810 atomic_set(&cmd->transport_lun_stop, 0);
37811 }
37812 if (!atomic_read(&cmd->t_transport_active) ||
37813 - atomic_read(&cmd->t_transport_aborted)) {
37814 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
37815 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37816 return false;
37817 }
37818 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37819 {
37820 int ret = 0;
37821
37822 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37823 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37824 if (!send_status ||
37825 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37826 return 1;
37827 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37828 */
37829 if (cmd->data_direction == DMA_TO_DEVICE) {
37830 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37831 - atomic_inc(&cmd->t_transport_aborted);
37832 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37833 smp_mb__after_atomic_inc();
37834 }
37835 }
37836 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37837 index b9040be..e3f5aab 100644
37838 --- a/drivers/tty/hvc/hvcs.c
37839 +++ b/drivers/tty/hvc/hvcs.c
37840 @@ -83,6 +83,7 @@
37841 #include <asm/hvcserver.h>
37842 #include <asm/uaccess.h>
37843 #include <asm/vio.h>
37844 +#include <asm/local.h>
37845
37846 /*
37847 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37848 @@ -270,7 +271,7 @@ struct hvcs_struct {
37849 unsigned int index;
37850
37851 struct tty_struct *tty;
37852 - int open_count;
37853 + local_t open_count;
37854
37855 /*
37856 * Used to tell the driver kernel_thread what operations need to take
37857 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37858
37859 spin_lock_irqsave(&hvcsd->lock, flags);
37860
37861 - if (hvcsd->open_count > 0) {
37862 + if (local_read(&hvcsd->open_count) > 0) {
37863 spin_unlock_irqrestore(&hvcsd->lock, flags);
37864 printk(KERN_INFO "HVCS: vterm state unchanged. "
37865 "The hvcs device node is still in use.\n");
37866 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37867 if ((retval = hvcs_partner_connect(hvcsd)))
37868 goto error_release;
37869
37870 - hvcsd->open_count = 1;
37871 + local_set(&hvcsd->open_count, 1);
37872 hvcsd->tty = tty;
37873 tty->driver_data = hvcsd;
37874
37875 @@ -1179,7 +1180,7 @@ fast_open:
37876
37877 spin_lock_irqsave(&hvcsd->lock, flags);
37878 kref_get(&hvcsd->kref);
37879 - hvcsd->open_count++;
37880 + local_inc(&hvcsd->open_count);
37881 hvcsd->todo_mask |= HVCS_SCHED_READ;
37882 spin_unlock_irqrestore(&hvcsd->lock, flags);
37883
37884 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37885 hvcsd = tty->driver_data;
37886
37887 spin_lock_irqsave(&hvcsd->lock, flags);
37888 - if (--hvcsd->open_count == 0) {
37889 + if (local_dec_and_test(&hvcsd->open_count)) {
37890
37891 vio_disable_interrupts(hvcsd->vdev);
37892
37893 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37894 free_irq(irq, hvcsd);
37895 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37896 return;
37897 - } else if (hvcsd->open_count < 0) {
37898 + } else if (local_read(&hvcsd->open_count) < 0) {
37899 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37900 " is missmanaged.\n",
37901 - hvcsd->vdev->unit_address, hvcsd->open_count);
37902 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37903 }
37904
37905 spin_unlock_irqrestore(&hvcsd->lock, flags);
37906 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37907
37908 spin_lock_irqsave(&hvcsd->lock, flags);
37909 /* Preserve this so that we know how many kref refs to put */
37910 - temp_open_count = hvcsd->open_count;
37911 + temp_open_count = local_read(&hvcsd->open_count);
37912
37913 /*
37914 * Don't kref put inside the spinlock because the destruction
37915 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37916 hvcsd->tty->driver_data = NULL;
37917 hvcsd->tty = NULL;
37918
37919 - hvcsd->open_count = 0;
37920 + local_set(&hvcsd->open_count, 0);
37921
37922 /* This will drop any buffered data on the floor which is OK in a hangup
37923 * scenario. */
37924 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37925 * the middle of a write operation? This is a crummy place to do this
37926 * but we want to keep it all in the spinlock.
37927 */
37928 - if (hvcsd->open_count <= 0) {
37929 + if (local_read(&hvcsd->open_count) <= 0) {
37930 spin_unlock_irqrestore(&hvcsd->lock, flags);
37931 return -ENODEV;
37932 }
37933 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37934 {
37935 struct hvcs_struct *hvcsd = tty->driver_data;
37936
37937 - if (!hvcsd || hvcsd->open_count <= 0)
37938 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37939 return 0;
37940
37941 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37942 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37943 index ef92869..f4ebd88 100644
37944 --- a/drivers/tty/ipwireless/tty.c
37945 +++ b/drivers/tty/ipwireless/tty.c
37946 @@ -29,6 +29,7 @@
37947 #include <linux/tty_driver.h>
37948 #include <linux/tty_flip.h>
37949 #include <linux/uaccess.h>
37950 +#include <asm/local.h>
37951
37952 #include "tty.h"
37953 #include "network.h"
37954 @@ -51,7 +52,7 @@ struct ipw_tty {
37955 int tty_type;
37956 struct ipw_network *network;
37957 struct tty_struct *linux_tty;
37958 - int open_count;
37959 + local_t open_count;
37960 unsigned int control_lines;
37961 struct mutex ipw_tty_mutex;
37962 int tx_bytes_queued;
37963 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37964 mutex_unlock(&tty->ipw_tty_mutex);
37965 return -ENODEV;
37966 }
37967 - if (tty->open_count == 0)
37968 + if (local_read(&tty->open_count) == 0)
37969 tty->tx_bytes_queued = 0;
37970
37971 - tty->open_count++;
37972 + local_inc(&tty->open_count);
37973
37974 tty->linux_tty = linux_tty;
37975 linux_tty->driver_data = tty;
37976 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37977
37978 static void do_ipw_close(struct ipw_tty *tty)
37979 {
37980 - tty->open_count--;
37981 -
37982 - if (tty->open_count == 0) {
37983 + if (local_dec_return(&tty->open_count) == 0) {
37984 struct tty_struct *linux_tty = tty->linux_tty;
37985
37986 if (linux_tty != NULL) {
37987 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37988 return;
37989
37990 mutex_lock(&tty->ipw_tty_mutex);
37991 - if (tty->open_count == 0) {
37992 + if (local_read(&tty->open_count) == 0) {
37993 mutex_unlock(&tty->ipw_tty_mutex);
37994 return;
37995 }
37996 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37997 return;
37998 }
37999
38000 - if (!tty->open_count) {
38001 + if (!local_read(&tty->open_count)) {
38002 mutex_unlock(&tty->ipw_tty_mutex);
38003 return;
38004 }
38005 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38006 return -ENODEV;
38007
38008 mutex_lock(&tty->ipw_tty_mutex);
38009 - if (!tty->open_count) {
38010 + if (!local_read(&tty->open_count)) {
38011 mutex_unlock(&tty->ipw_tty_mutex);
38012 return -EINVAL;
38013 }
38014 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38015 if (!tty)
38016 return -ENODEV;
38017
38018 - if (!tty->open_count)
38019 + if (!local_read(&tty->open_count))
38020 return -EINVAL;
38021
38022 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38023 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38024 if (!tty)
38025 return 0;
38026
38027 - if (!tty->open_count)
38028 + if (!local_read(&tty->open_count))
38029 return 0;
38030
38031 return tty->tx_bytes_queued;
38032 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38033 if (!tty)
38034 return -ENODEV;
38035
38036 - if (!tty->open_count)
38037 + if (!local_read(&tty->open_count))
38038 return -EINVAL;
38039
38040 return get_control_lines(tty);
38041 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38042 if (!tty)
38043 return -ENODEV;
38044
38045 - if (!tty->open_count)
38046 + if (!local_read(&tty->open_count))
38047 return -EINVAL;
38048
38049 return set_control_lines(tty, set, clear);
38050 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38051 if (!tty)
38052 return -ENODEV;
38053
38054 - if (!tty->open_count)
38055 + if (!local_read(&tty->open_count))
38056 return -EINVAL;
38057
38058 /* FIXME: Exactly how is the tty object locked here .. */
38059 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38060 against a parallel ioctl etc */
38061 mutex_lock(&ttyj->ipw_tty_mutex);
38062 }
38063 - while (ttyj->open_count)
38064 + while (local_read(&ttyj->open_count))
38065 do_ipw_close(ttyj);
38066 ipwireless_disassociate_network_ttys(network,
38067 ttyj->channel_idx);
38068 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38069 index fc7bbba..9527e93 100644
38070 --- a/drivers/tty/n_gsm.c
38071 +++ b/drivers/tty/n_gsm.c
38072 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38073 kref_init(&dlci->ref);
38074 mutex_init(&dlci->mutex);
38075 dlci->fifo = &dlci->_fifo;
38076 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38077 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38078 kfree(dlci);
38079 return NULL;
38080 }
38081 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38082 index d2256d0..97476fa 100644
38083 --- a/drivers/tty/n_tty.c
38084 +++ b/drivers/tty/n_tty.c
38085 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38086 {
38087 *ops = tty_ldisc_N_TTY;
38088 ops->owner = NULL;
38089 - ops->refcount = ops->flags = 0;
38090 + atomic_set(&ops->refcount, 0);
38091 + ops->flags = 0;
38092 }
38093 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38094 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38095 index d8653ab..f8afd9d 100644
38096 --- a/drivers/tty/pty.c
38097 +++ b/drivers/tty/pty.c
38098 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38099 register_sysctl_table(pty_root_table);
38100
38101 /* Now create the /dev/ptmx special device */
38102 + pax_open_kernel();
38103 tty_default_fops(&ptmx_fops);
38104 - ptmx_fops.open = ptmx_open;
38105 + *(void **)&ptmx_fops.open = ptmx_open;
38106 + pax_close_kernel();
38107
38108 cdev_init(&ptmx_cdev, &ptmx_fops);
38109 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38110 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38111 index 2b42a01..32a2ed3 100644
38112 --- a/drivers/tty/serial/kgdboc.c
38113 +++ b/drivers/tty/serial/kgdboc.c
38114 @@ -24,8 +24,9 @@
38115 #define MAX_CONFIG_LEN 40
38116
38117 static struct kgdb_io kgdboc_io_ops;
38118 +static struct kgdb_io kgdboc_io_ops_console;
38119
38120 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38121 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38122 static int configured = -1;
38123
38124 static char config[MAX_CONFIG_LEN];
38125 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38126 kgdboc_unregister_kbd();
38127 if (configured == 1)
38128 kgdb_unregister_io_module(&kgdboc_io_ops);
38129 + else if (configured == 2)
38130 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38131 }
38132
38133 static int configure_kgdboc(void)
38134 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38135 int err;
38136 char *cptr = config;
38137 struct console *cons;
38138 + int is_console = 0;
38139
38140 err = kgdboc_option_setup(config);
38141 if (err || !strlen(config) || isspace(config[0]))
38142 goto noconfig;
38143
38144 err = -ENODEV;
38145 - kgdboc_io_ops.is_console = 0;
38146 kgdb_tty_driver = NULL;
38147
38148 kgdboc_use_kms = 0;
38149 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38150 int idx;
38151 if (cons->device && cons->device(cons, &idx) == p &&
38152 idx == tty_line) {
38153 - kgdboc_io_ops.is_console = 1;
38154 + is_console = 1;
38155 break;
38156 }
38157 cons = cons->next;
38158 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38159 kgdb_tty_line = tty_line;
38160
38161 do_register:
38162 - err = kgdb_register_io_module(&kgdboc_io_ops);
38163 + if (is_console) {
38164 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38165 + configured = 2;
38166 + } else {
38167 + err = kgdb_register_io_module(&kgdboc_io_ops);
38168 + configured = 1;
38169 + }
38170 if (err)
38171 goto noconfig;
38172
38173 - configured = 1;
38174 -
38175 return 0;
38176
38177 noconfig:
38178 @@ -213,7 +220,7 @@ noconfig:
38179 static int __init init_kgdboc(void)
38180 {
38181 /* Already configured? */
38182 - if (configured == 1)
38183 + if (configured >= 1)
38184 return 0;
38185
38186 return configure_kgdboc();
38187 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38188 if (config[len - 1] == '\n')
38189 config[len - 1] = '\0';
38190
38191 - if (configured == 1)
38192 + if (configured >= 1)
38193 cleanup_kgdboc();
38194
38195 /* Go and configure with the new params. */
38196 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38197 .post_exception = kgdboc_post_exp_handler,
38198 };
38199
38200 +static struct kgdb_io kgdboc_io_ops_console = {
38201 + .name = "kgdboc",
38202 + .read_char = kgdboc_get_char,
38203 + .write_char = kgdboc_put_char,
38204 + .pre_exception = kgdboc_pre_exp_handler,
38205 + .post_exception = kgdboc_post_exp_handler,
38206 + .is_console = 1
38207 +};
38208 +
38209 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38210 /* This is only available if kgdboc is a built in for early debugging */
38211 static int __init kgdboc_early_init(char *opt)
38212 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38213 index 7867b7c..b3c119d 100644
38214 --- a/drivers/tty/sysrq.c
38215 +++ b/drivers/tty/sysrq.c
38216 @@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38217 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38218 size_t count, loff_t *ppos)
38219 {
38220 - if (count) {
38221 + if (count && capable(CAP_SYS_ADMIN)) {
38222 char c;
38223
38224 if (get_user(c, buf))
38225 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38226 index e41b9bb..84002fb 100644
38227 --- a/drivers/tty/tty_io.c
38228 +++ b/drivers/tty/tty_io.c
38229 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38230
38231 void tty_default_fops(struct file_operations *fops)
38232 {
38233 - *fops = tty_fops;
38234 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38235 }
38236
38237 /*
38238 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38239 index 24b95db..9c078d0 100644
38240 --- a/drivers/tty/tty_ldisc.c
38241 +++ b/drivers/tty/tty_ldisc.c
38242 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38243 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38244 struct tty_ldisc_ops *ldo = ld->ops;
38245
38246 - ldo->refcount--;
38247 + atomic_dec(&ldo->refcount);
38248 module_put(ldo->owner);
38249 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38250
38251 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38252 spin_lock_irqsave(&tty_ldisc_lock, flags);
38253 tty_ldiscs[disc] = new_ldisc;
38254 new_ldisc->num = disc;
38255 - new_ldisc->refcount = 0;
38256 + atomic_set(&new_ldisc->refcount, 0);
38257 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38258
38259 return ret;
38260 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38261 return -EINVAL;
38262
38263 spin_lock_irqsave(&tty_ldisc_lock, flags);
38264 - if (tty_ldiscs[disc]->refcount)
38265 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38266 ret = -EBUSY;
38267 else
38268 tty_ldiscs[disc] = NULL;
38269 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38270 if (ldops) {
38271 ret = ERR_PTR(-EAGAIN);
38272 if (try_module_get(ldops->owner)) {
38273 - ldops->refcount++;
38274 + atomic_inc(&ldops->refcount);
38275 ret = ldops;
38276 }
38277 }
38278 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38279 unsigned long flags;
38280
38281 spin_lock_irqsave(&tty_ldisc_lock, flags);
38282 - ldops->refcount--;
38283 + atomic_dec(&ldops->refcount);
38284 module_put(ldops->owner);
38285 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38286 }
38287 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38288 index a605549..6bd3c96 100644
38289 --- a/drivers/tty/vt/keyboard.c
38290 +++ b/drivers/tty/vt/keyboard.c
38291 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38292 kbd->kbdmode == VC_OFF) &&
38293 value != KVAL(K_SAK))
38294 return; /* SAK is allowed even in raw mode */
38295 +
38296 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38297 + {
38298 + void *func = fn_handler[value];
38299 + if (func == fn_show_state || func == fn_show_ptregs ||
38300 + func == fn_show_mem)
38301 + return;
38302 + }
38303 +#endif
38304 +
38305 fn_handler[value](vc);
38306 }
38307
38308 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38309 index 65447c5..0526f0a 100644
38310 --- a/drivers/tty/vt/vt_ioctl.c
38311 +++ b/drivers/tty/vt/vt_ioctl.c
38312 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38313 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38314 return -EFAULT;
38315
38316 - if (!capable(CAP_SYS_TTY_CONFIG))
38317 - perm = 0;
38318 -
38319 switch (cmd) {
38320 case KDGKBENT:
38321 key_map = key_maps[s];
38322 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38323 val = (i ? K_HOLE : K_NOSUCHMAP);
38324 return put_user(val, &user_kbe->kb_value);
38325 case KDSKBENT:
38326 + if (!capable(CAP_SYS_TTY_CONFIG))
38327 + perm = 0;
38328 +
38329 if (!perm)
38330 return -EPERM;
38331 if (!i && v == K_NOSUCHMAP) {
38332 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38333 int i, j, k;
38334 int ret;
38335
38336 - if (!capable(CAP_SYS_TTY_CONFIG))
38337 - perm = 0;
38338 -
38339 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38340 if (!kbs) {
38341 ret = -ENOMEM;
38342 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38343 kfree(kbs);
38344 return ((p && *p) ? -EOVERFLOW : 0);
38345 case KDSKBSENT:
38346 + if (!capable(CAP_SYS_TTY_CONFIG))
38347 + perm = 0;
38348 +
38349 if (!perm) {
38350 ret = -EPERM;
38351 goto reterr;
38352 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38353 index a783d53..cb30d94 100644
38354 --- a/drivers/uio/uio.c
38355 +++ b/drivers/uio/uio.c
38356 @@ -25,6 +25,7 @@
38357 #include <linux/kobject.h>
38358 #include <linux/cdev.h>
38359 #include <linux/uio_driver.h>
38360 +#include <asm/local.h>
38361
38362 #define UIO_MAX_DEVICES (1U << MINORBITS)
38363
38364 @@ -32,10 +33,10 @@ struct uio_device {
38365 struct module *owner;
38366 struct device *dev;
38367 int minor;
38368 - atomic_t event;
38369 + atomic_unchecked_t event;
38370 struct fasync_struct *async_queue;
38371 wait_queue_head_t wait;
38372 - int vma_count;
38373 + local_t vma_count;
38374 struct uio_info *info;
38375 struct kobject *map_dir;
38376 struct kobject *portio_dir;
38377 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38378 struct device_attribute *attr, char *buf)
38379 {
38380 struct uio_device *idev = dev_get_drvdata(dev);
38381 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38382 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38383 }
38384
38385 static struct device_attribute uio_class_attributes[] = {
38386 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38387 {
38388 struct uio_device *idev = info->uio_dev;
38389
38390 - atomic_inc(&idev->event);
38391 + atomic_inc_unchecked(&idev->event);
38392 wake_up_interruptible(&idev->wait);
38393 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38394 }
38395 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38396 }
38397
38398 listener->dev = idev;
38399 - listener->event_count = atomic_read(&idev->event);
38400 + listener->event_count = atomic_read_unchecked(&idev->event);
38401 filep->private_data = listener;
38402
38403 if (idev->info->open) {
38404 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38405 return -EIO;
38406
38407 poll_wait(filep, &idev->wait, wait);
38408 - if (listener->event_count != atomic_read(&idev->event))
38409 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38410 return POLLIN | POLLRDNORM;
38411 return 0;
38412 }
38413 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38414 do {
38415 set_current_state(TASK_INTERRUPTIBLE);
38416
38417 - event_count = atomic_read(&idev->event);
38418 + event_count = atomic_read_unchecked(&idev->event);
38419 if (event_count != listener->event_count) {
38420 if (copy_to_user(buf, &event_count, count))
38421 retval = -EFAULT;
38422 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38423 static void uio_vma_open(struct vm_area_struct *vma)
38424 {
38425 struct uio_device *idev = vma->vm_private_data;
38426 - idev->vma_count++;
38427 + local_inc(&idev->vma_count);
38428 }
38429
38430 static void uio_vma_close(struct vm_area_struct *vma)
38431 {
38432 struct uio_device *idev = vma->vm_private_data;
38433 - idev->vma_count--;
38434 + local_dec(&idev->vma_count);
38435 }
38436
38437 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38438 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38439 idev->owner = owner;
38440 idev->info = info;
38441 init_waitqueue_head(&idev->wait);
38442 - atomic_set(&idev->event, 0);
38443 + atomic_set_unchecked(&idev->event, 0);
38444
38445 ret = uio_get_minor(idev);
38446 if (ret)
38447 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38448 index 98b89fe..aff824e 100644
38449 --- a/drivers/usb/atm/cxacru.c
38450 +++ b/drivers/usb/atm/cxacru.c
38451 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38452 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38453 if (ret < 2)
38454 return -EINVAL;
38455 - if (index < 0 || index > 0x7f)
38456 + if (index > 0x7f)
38457 return -EINVAL;
38458 pos += tmp;
38459
38460 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38461 index d3448ca..d2864ca 100644
38462 --- a/drivers/usb/atm/usbatm.c
38463 +++ b/drivers/usb/atm/usbatm.c
38464 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38465 if (printk_ratelimit())
38466 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38467 __func__, vpi, vci);
38468 - atomic_inc(&vcc->stats->rx_err);
38469 + atomic_inc_unchecked(&vcc->stats->rx_err);
38470 return;
38471 }
38472
38473 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38474 if (length > ATM_MAX_AAL5_PDU) {
38475 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38476 __func__, length, vcc);
38477 - atomic_inc(&vcc->stats->rx_err);
38478 + atomic_inc_unchecked(&vcc->stats->rx_err);
38479 goto out;
38480 }
38481
38482 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38483 if (sarb->len < pdu_length) {
38484 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38485 __func__, pdu_length, sarb->len, vcc);
38486 - atomic_inc(&vcc->stats->rx_err);
38487 + atomic_inc_unchecked(&vcc->stats->rx_err);
38488 goto out;
38489 }
38490
38491 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38492 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38493 __func__, vcc);
38494 - atomic_inc(&vcc->stats->rx_err);
38495 + atomic_inc_unchecked(&vcc->stats->rx_err);
38496 goto out;
38497 }
38498
38499 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38500 if (printk_ratelimit())
38501 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38502 __func__, length);
38503 - atomic_inc(&vcc->stats->rx_drop);
38504 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38505 goto out;
38506 }
38507
38508 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38509
38510 vcc->push(vcc, skb);
38511
38512 - atomic_inc(&vcc->stats->rx);
38513 + atomic_inc_unchecked(&vcc->stats->rx);
38514 out:
38515 skb_trim(sarb, 0);
38516 }
38517 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38518 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38519
38520 usbatm_pop(vcc, skb);
38521 - atomic_inc(&vcc->stats->tx);
38522 + atomic_inc_unchecked(&vcc->stats->tx);
38523
38524 skb = skb_dequeue(&instance->sndqueue);
38525 }
38526 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38527 if (!left--)
38528 return sprintf(page,
38529 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38530 - atomic_read(&atm_dev->stats.aal5.tx),
38531 - atomic_read(&atm_dev->stats.aal5.tx_err),
38532 - atomic_read(&atm_dev->stats.aal5.rx),
38533 - atomic_read(&atm_dev->stats.aal5.rx_err),
38534 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38535 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38536 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38537 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38538 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38539 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38540
38541 if (!left--) {
38542 if (instance->disconnected)
38543 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38544 index d956965..4179a77 100644
38545 --- a/drivers/usb/core/devices.c
38546 +++ b/drivers/usb/core/devices.c
38547 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38548 * time it gets called.
38549 */
38550 static struct device_connect_event {
38551 - atomic_t count;
38552 + atomic_unchecked_t count;
38553 wait_queue_head_t wait;
38554 } device_event = {
38555 .count = ATOMIC_INIT(1),
38556 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38557
38558 void usbfs_conn_disc_event(void)
38559 {
38560 - atomic_add(2, &device_event.count);
38561 + atomic_add_unchecked(2, &device_event.count);
38562 wake_up(&device_event.wait);
38563 }
38564
38565 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38566
38567 poll_wait(file, &device_event.wait, wait);
38568
38569 - event_count = atomic_read(&device_event.count);
38570 + event_count = atomic_read_unchecked(&device_event.count);
38571 if (file->f_version != event_count) {
38572 file->f_version = event_count;
38573 return POLLIN | POLLRDNORM;
38574 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38575 index 1fc8f12..20647c1 100644
38576 --- a/drivers/usb/early/ehci-dbgp.c
38577 +++ b/drivers/usb/early/ehci-dbgp.c
38578 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38579
38580 #ifdef CONFIG_KGDB
38581 static struct kgdb_io kgdbdbgp_io_ops;
38582 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38583 +static struct kgdb_io kgdbdbgp_io_ops_console;
38584 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38585 #else
38586 #define dbgp_kgdb_mode (0)
38587 #endif
38588 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38589 .write_char = kgdbdbgp_write_char,
38590 };
38591
38592 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38593 + .name = "kgdbdbgp",
38594 + .read_char = kgdbdbgp_read_char,
38595 + .write_char = kgdbdbgp_write_char,
38596 + .is_console = 1
38597 +};
38598 +
38599 static int kgdbdbgp_wait_time;
38600
38601 static int __init kgdbdbgp_parse_config(char *str)
38602 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38603 ptr++;
38604 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38605 }
38606 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38607 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38608 + if (early_dbgp_console.index != -1)
38609 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38610 + else
38611 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38612
38613 return 0;
38614 }
38615 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38616 index d6bea3e..60b250e 100644
38617 --- a/drivers/usb/wusbcore/wa-hc.h
38618 +++ b/drivers/usb/wusbcore/wa-hc.h
38619 @@ -192,7 +192,7 @@ struct wahc {
38620 struct list_head xfer_delayed_list;
38621 spinlock_t xfer_list_lock;
38622 struct work_struct xfer_work;
38623 - atomic_t xfer_id_count;
38624 + atomic_unchecked_t xfer_id_count;
38625 };
38626
38627
38628 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38629 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38630 spin_lock_init(&wa->xfer_list_lock);
38631 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38632 - atomic_set(&wa->xfer_id_count, 1);
38633 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38634 }
38635
38636 /**
38637 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38638 index 57c01ab..8a05959 100644
38639 --- a/drivers/usb/wusbcore/wa-xfer.c
38640 +++ b/drivers/usb/wusbcore/wa-xfer.c
38641 @@ -296,7 +296,7 @@ out:
38642 */
38643 static void wa_xfer_id_init(struct wa_xfer *xfer)
38644 {
38645 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38646 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38647 }
38648
38649 /*
38650 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38651 index c14c42b..f955cc2 100644
38652 --- a/drivers/vhost/vhost.c
38653 +++ b/drivers/vhost/vhost.c
38654 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38655 return 0;
38656 }
38657
38658 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38659 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38660 {
38661 struct file *eventfp, *filep = NULL,
38662 *pollstart = NULL, *pollstop = NULL;
38663 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38664 index b0b2ac3..89a4399 100644
38665 --- a/drivers/video/aty/aty128fb.c
38666 +++ b/drivers/video/aty/aty128fb.c
38667 @@ -148,7 +148,7 @@ enum {
38668 };
38669
38670 /* Must match above enum */
38671 -static const char *r128_family[] __devinitdata = {
38672 +static const char *r128_family[] __devinitconst = {
38673 "AGP",
38674 "PCI",
38675 "PRO AGP",
38676 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38677 index 5c3960d..15cf8fc 100644
38678 --- a/drivers/video/fbcmap.c
38679 +++ b/drivers/video/fbcmap.c
38680 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38681 rc = -ENODEV;
38682 goto out;
38683 }
38684 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38685 - !info->fbops->fb_setcmap)) {
38686 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38687 rc = -EINVAL;
38688 goto out1;
38689 }
38690 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38691 index c6ce416..3b9b642 100644
38692 --- a/drivers/video/fbmem.c
38693 +++ b/drivers/video/fbmem.c
38694 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38695 image->dx += image->width + 8;
38696 }
38697 } else if (rotate == FB_ROTATE_UD) {
38698 - for (x = 0; x < num && image->dx >= 0; x++) {
38699 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38700 info->fbops->fb_imageblit(info, image);
38701 image->dx -= image->width + 8;
38702 }
38703 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38704 image->dy += image->height + 8;
38705 }
38706 } else if (rotate == FB_ROTATE_CCW) {
38707 - for (x = 0; x < num && image->dy >= 0; x++) {
38708 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38709 info->fbops->fb_imageblit(info, image);
38710 image->dy -= image->height + 8;
38711 }
38712 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38713 return -EFAULT;
38714 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38715 return -EINVAL;
38716 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38717 + if (con2fb.framebuffer >= FB_MAX)
38718 return -EINVAL;
38719 if (!registered_fb[con2fb.framebuffer])
38720 request_module("fb%d", con2fb.framebuffer);
38721 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38722 index 5a5d092..265c5ed 100644
38723 --- a/drivers/video/geode/gx1fb_core.c
38724 +++ b/drivers/video/geode/gx1fb_core.c
38725 @@ -29,7 +29,7 @@ static int crt_option = 1;
38726 static char panel_option[32] = "";
38727
38728 /* Modes relevant to the GX1 (taken from modedb.c) */
38729 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38730 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38731 /* 640x480-60 VESA */
38732 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38733 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38734 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38735 index 0fad23f..0e9afa4 100644
38736 --- a/drivers/video/gxt4500.c
38737 +++ b/drivers/video/gxt4500.c
38738 @@ -156,7 +156,7 @@ struct gxt4500_par {
38739 static char *mode_option;
38740
38741 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38742 -static const struct fb_videomode defaultmode __devinitdata = {
38743 +static const struct fb_videomode defaultmode __devinitconst = {
38744 .refresh = 60,
38745 .xres = 1280,
38746 .yres = 1024,
38747 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38748 return 0;
38749 }
38750
38751 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38752 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38753 .id = "IBM GXT4500P",
38754 .type = FB_TYPE_PACKED_PIXELS,
38755 .visual = FB_VISUAL_PSEUDOCOLOR,
38756 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38757 index 7672d2e..b56437f 100644
38758 --- a/drivers/video/i810/i810_accel.c
38759 +++ b/drivers/video/i810/i810_accel.c
38760 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38761 }
38762 }
38763 printk("ringbuffer lockup!!!\n");
38764 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38765 i810_report_error(mmio);
38766 par->dev_flags |= LOCKUP;
38767 info->pixmap.scan_align = 1;
38768 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38769 index b83f361..2b05a91 100644
38770 --- a/drivers/video/i810/i810_main.c
38771 +++ b/drivers/video/i810/i810_main.c
38772 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38773 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38774
38775 /* PCI */
38776 -static const char *i810_pci_list[] __devinitdata = {
38777 +static const char *i810_pci_list[] __devinitconst = {
38778 "Intel(R) 810 Framebuffer Device" ,
38779 "Intel(R) 810-DC100 Framebuffer Device" ,
38780 "Intel(R) 810E Framebuffer Device" ,
38781 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38782 index de36693..3c63fc2 100644
38783 --- a/drivers/video/jz4740_fb.c
38784 +++ b/drivers/video/jz4740_fb.c
38785 @@ -136,7 +136,7 @@ struct jzfb {
38786 uint32_t pseudo_palette[16];
38787 };
38788
38789 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38790 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38791 .id = "JZ4740 FB",
38792 .type = FB_TYPE_PACKED_PIXELS,
38793 .visual = FB_VISUAL_TRUECOLOR,
38794 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38795 index 3c14e43..eafa544 100644
38796 --- a/drivers/video/logo/logo_linux_clut224.ppm
38797 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38798 @@ -1,1604 +1,1123 @@
38799 P3
38800 -# Standard 224-color Linux logo
38801 80 80
38802 255
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 - 0 0 0 0 0 0 0 0 0 0 0 0
38812 - 6 6 6 6 6 6 10 10 10 10 10 10
38813 - 10 10 10 6 6 6 6 6 6 6 6 6
38814 - 0 0 0 0 0 0 0 0 0 0 0 0
38815 - 0 0 0 0 0 0 0 0 0 0 0 0
38816 - 0 0 0 0 0 0 0 0 0 0 0 0
38817 - 0 0 0 0 0 0 0 0 0 0 0 0
38818 - 0 0 0 0 0 0 0 0 0 0 0 0
38819 - 0 0 0 0 0 0 0 0 0 0 0 0
38820 - 0 0 0 0 0 0 0 0 0 0 0 0
38821 - 0 0 0 0 0 0 0 0 0 0 0 0
38822 - 0 0 0 0 0 0 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 0 0 0
38831 - 0 0 0 6 6 6 10 10 10 14 14 14
38832 - 22 22 22 26 26 26 30 30 30 34 34 34
38833 - 30 30 30 30 30 30 26 26 26 18 18 18
38834 - 14 14 14 10 10 10 6 6 6 0 0 0
38835 - 0 0 0 0 0 0 0 0 0 0 0 0
38836 - 0 0 0 0 0 0 0 0 0 0 0 0
38837 - 0 0 0 0 0 0 0 0 0 0 0 0
38838 - 0 0 0 0 0 0 0 0 0 0 0 0
38839 - 0 0 0 0 0 0 0 0 0 0 0 0
38840 - 0 0 0 0 0 0 0 0 0 0 0 0
38841 - 0 0 0 0 0 0 0 0 0 0 0 0
38842 - 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0
38851 - 6 6 6 14 14 14 26 26 26 42 42 42
38852 - 54 54 54 66 66 66 78 78 78 78 78 78
38853 - 78 78 78 74 74 74 66 66 66 54 54 54
38854 - 42 42 42 26 26 26 18 18 18 10 10 10
38855 - 6 6 6 0 0 0 0 0 0 0 0 0
38856 - 0 0 0 0 0 0 0 0 0 0 0 0
38857 - 0 0 0 0 0 0 0 0 0 0 0 0
38858 - 0 0 0 0 0 0 0 0 0 0 0 0
38859 - 0 0 0 0 0 0 0 0 0 0 0 0
38860 - 0 0 0 0 0 0 0 0 0 0 0 0
38861 - 0 0 0 0 0 0 0 0 0 0 0 0
38862 - 0 0 0 0 0 0 0 0 0 0 0 0
38863 - 0 0 0 0 0 0 0 0 0 0 0 0
38864 - 0 0 1 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 10 10 10
38871 - 22 22 22 42 42 42 66 66 66 86 86 86
38872 - 66 66 66 38 38 38 38 38 38 22 22 22
38873 - 26 26 26 34 34 34 54 54 54 66 66 66
38874 - 86 86 86 70 70 70 46 46 46 26 26 26
38875 - 14 14 14 6 6 6 0 0 0 0 0 0
38876 - 0 0 0 0 0 0 0 0 0 0 0 0
38877 - 0 0 0 0 0 0 0 0 0 0 0 0
38878 - 0 0 0 0 0 0 0 0 0 0 0 0
38879 - 0 0 0 0 0 0 0 0 0 0 0 0
38880 - 0 0 0 0 0 0 0 0 0 0 0 0
38881 - 0 0 0 0 0 0 0 0 0 0 0 0
38882 - 0 0 0 0 0 0 0 0 0 0 0 0
38883 - 0 0 0 0 0 0 0 0 0 0 0 0
38884 - 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
38891 - 50 50 50 82 82 82 58 58 58 6 6 6
38892 - 2 2 6 2 2 6 2 2 6 2 2 6
38893 - 2 2 6 2 2 6 2 2 6 2 2 6
38894 - 6 6 6 54 54 54 86 86 86 66 66 66
38895 - 38 38 38 18 18 18 6 6 6 0 0 0
38896 - 0 0 0 0 0 0 0 0 0 0 0 0
38897 - 0 0 0 0 0 0 0 0 0 0 0 0
38898 - 0 0 0 0 0 0 0 0 0 0 0 0
38899 - 0 0 0 0 0 0 0 0 0 0 0 0
38900 - 0 0 0 0 0 0 0 0 0 0 0 0
38901 - 0 0 0 0 0 0 0 0 0 0 0 0
38902 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
38911 - 78 78 78 34 34 34 2 2 6 2 2 6
38912 - 2 2 6 2 2 6 2 2 6 2 2 6
38913 - 2 2 6 2 2 6 2 2 6 2 2 6
38914 - 2 2 6 2 2 6 6 6 6 70 70 70
38915 - 78 78 78 46 46 46 22 22 22 6 6 6
38916 - 0 0 0 0 0 0 0 0 0 0 0 0
38917 - 0 0 0 0 0 0 0 0 0 0 0 0
38918 - 0 0 0 0 0 0 0 0 0 0 0 0
38919 - 0 0 0 0 0 0 0 0 0 0 0 0
38920 - 0 0 0 0 0 0 0 0 0 0 0 0
38921 - 0 0 0 0 0 0 0 0 0 0 0 0
38922 - 0 0 0 0 0 0 0 0 0 0 0 0
38923 - 0 0 0 0 0 0 0 0 0 0 0 0
38924 - 0 0 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
38931 - 26 26 26 2 2 6 2 2 6 2 2 6
38932 - 2 2 6 2 2 6 2 2 6 2 2 6
38933 - 2 2 6 2 2 6 2 2 6 14 14 14
38934 - 46 46 46 34 34 34 6 6 6 2 2 6
38935 - 42 42 42 78 78 78 42 42 42 18 18 18
38936 - 6 6 6 0 0 0 0 0 0 0 0 0
38937 - 0 0 0 0 0 0 0 0 0 0 0 0
38938 - 0 0 0 0 0 0 0 0 0 0 0 0
38939 - 0 0 0 0 0 0 0 0 0 0 0 0
38940 - 0 0 0 0 0 0 0 0 0 0 0 0
38941 - 0 0 0 0 0 0 0 0 0 0 0 0
38942 - 0 0 0 0 0 0 0 0 0 0 0 0
38943 - 0 0 0 0 0 0 0 0 0 0 0 0
38944 - 0 0 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
38951 - 2 2 6 2 2 6 2 2 6 2 2 6
38952 - 2 2 6 2 2 6 2 2 6 2 2 6
38953 - 2 2 6 2 2 6 2 2 6 26 26 26
38954 - 86 86 86 101 101 101 46 46 46 10 10 10
38955 - 2 2 6 58 58 58 70 70 70 34 34 34
38956 - 10 10 10 0 0 0 0 0 0 0 0 0
38957 - 0 0 0 0 0 0 0 0 0 0 0 0
38958 - 0 0 0 0 0 0 0 0 0 0 0 0
38959 - 0 0 0 0 0 0 0 0 0 0 0 0
38960 - 0 0 0 0 0 0 0 0 0 0 0 0
38961 - 0 0 0 0 0 0 0 0 0 0 0 0
38962 - 0 0 0 0 0 0 0 0 0 0 0 0
38963 - 0 0 0 0 0 0 0 0 0 0 0 0
38964 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
38971 - 2 2 6 2 2 6 2 2 6 2 2 6
38972 - 2 2 6 2 2 6 2 2 6 2 2 6
38973 - 2 2 6 2 2 6 2 2 6 30 30 30
38974 - 94 94 94 94 94 94 58 58 58 26 26 26
38975 - 2 2 6 6 6 6 78 78 78 54 54 54
38976 - 22 22 22 6 6 6 0 0 0 0 0 0
38977 - 0 0 0 0 0 0 0 0 0 0 0 0
38978 - 0 0 0 0 0 0 0 0 0 0 0 0
38979 - 0 0 0 0 0 0 0 0 0 0 0 0
38980 - 0 0 0 0 0 0 0 0 0 0 0 0
38981 - 0 0 0 0 0 0 0 0 0 0 0 0
38982 - 0 0 0 0 0 0 0 0 0 0 0 0
38983 - 0 0 0 0 0 0 0 0 0 0 0 0
38984 - 0 0 0 0 0 0 0 0 0 0 0 0
38985 - 0 0 0 0 0 0 0 0 0 0 0 0
38986 - 0 0 0 0 0 0 0 0 0 0 0 0
38987 - 0 0 0 0 0 0 0 0 0 0 0 0
38988 - 0 0 0 0 0 0 0 0 0 0 0 0
38989 - 0 0 0 0 0 0 0 0 0 6 6 6
38990 - 22 22 22 62 62 62 62 62 62 2 2 6
38991 - 2 2 6 2 2 6 2 2 6 2 2 6
38992 - 2 2 6 2 2 6 2 2 6 2 2 6
38993 - 2 2 6 2 2 6 2 2 6 26 26 26
38994 - 54 54 54 38 38 38 18 18 18 10 10 10
38995 - 2 2 6 2 2 6 34 34 34 82 82 82
38996 - 38 38 38 14 14 14 0 0 0 0 0 0
38997 - 0 0 0 0 0 0 0 0 0 0 0 0
38998 - 0 0 0 0 0 0 0 0 0 0 0 0
38999 - 0 0 0 0 0 0 0 0 0 0 0 0
39000 - 0 0 0 0 0 0 0 0 0 0 0 0
39001 - 0 0 0 0 0 0 0 0 0 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 0 0 0
39003 - 0 0 0 0 0 0 0 0 0 0 0 0
39004 - 0 0 0 0 0 1 0 0 1 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 - 30 30 30 78 78 78 30 30 30 2 2 6
39011 - 2 2 6 2 2 6 2 2 6 2 2 6
39012 - 2 2 6 2 2 6 2 2 6 2 2 6
39013 - 2 2 6 2 2 6 2 2 6 10 10 10
39014 - 10 10 10 2 2 6 2 2 6 2 2 6
39015 - 2 2 6 2 2 6 2 2 6 78 78 78
39016 - 50 50 50 18 18 18 6 6 6 0 0 0
39017 - 0 0 0 0 0 0 0 0 0 0 0 0
39018 - 0 0 0 0 0 0 0 0 0 0 0 0
39019 - 0 0 0 0 0 0 0 0 0 0 0 0
39020 - 0 0 0 0 0 0 0 0 0 0 0 0
39021 - 0 0 0 0 0 0 0 0 0 0 0 0
39022 - 0 0 0 0 0 0 0 0 0 0 0 0
39023 - 0 0 0 0 0 0 0 0 0 0 0 0
39024 - 0 0 1 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 - 38 38 38 86 86 86 14 14 14 2 2 6
39031 - 2 2 6 2 2 6 2 2 6 2 2 6
39032 - 2 2 6 2 2 6 2 2 6 2 2 6
39033 - 2 2 6 2 2 6 2 2 6 2 2 6
39034 - 2 2 6 2 2 6 2 2 6 2 2 6
39035 - 2 2 6 2 2 6 2 2 6 54 54 54
39036 - 66 66 66 26 26 26 6 6 6 0 0 0
39037 - 0 0 0 0 0 0 0 0 0 0 0 0
39038 - 0 0 0 0 0 0 0 0 0 0 0 0
39039 - 0 0 0 0 0 0 0 0 0 0 0 0
39040 - 0 0 0 0 0 0 0 0 0 0 0 0
39041 - 0 0 0 0 0 0 0 0 0 0 0 0
39042 - 0 0 0 0 0 0 0 0 0 0 0 0
39043 - 0 0 0 0 0 0 0 0 0 0 0 0
39044 - 0 0 0 0 0 1 0 0 1 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 14 14 14
39050 - 42 42 42 82 82 82 2 2 6 2 2 6
39051 - 2 2 6 6 6 6 10 10 10 2 2 6
39052 - 2 2 6 2 2 6 2 2 6 2 2 6
39053 - 2 2 6 2 2 6 2 2 6 6 6 6
39054 - 14 14 14 10 10 10 2 2 6 2 2 6
39055 - 2 2 6 2 2 6 2 2 6 18 18 18
39056 - 82 82 82 34 34 34 10 10 10 0 0 0
39057 - 0 0 0 0 0 0 0 0 0 0 0 0
39058 - 0 0 0 0 0 0 0 0 0 0 0 0
39059 - 0 0 0 0 0 0 0 0 0 0 0 0
39060 - 0 0 0 0 0 0 0 0 0 0 0 0
39061 - 0 0 0 0 0 0 0 0 0 0 0 0
39062 - 0 0 0 0 0 0 0 0 0 0 0 0
39063 - 0 0 0 0 0 0 0 0 0 0 0 0
39064 - 0 0 1 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 0 0 0 14 14 14
39070 - 46 46 46 86 86 86 2 2 6 2 2 6
39071 - 6 6 6 6 6 6 22 22 22 34 34 34
39072 - 6 6 6 2 2 6 2 2 6 2 2 6
39073 - 2 2 6 2 2 6 18 18 18 34 34 34
39074 - 10 10 10 50 50 50 22 22 22 2 2 6
39075 - 2 2 6 2 2 6 2 2 6 10 10 10
39076 - 86 86 86 42 42 42 14 14 14 0 0 0
39077 - 0 0 0 0 0 0 0 0 0 0 0 0
39078 - 0 0 0 0 0 0 0 0 0 0 0 0
39079 - 0 0 0 0 0 0 0 0 0 0 0 0
39080 - 0 0 0 0 0 0 0 0 0 0 0 0
39081 - 0 0 0 0 0 0 0 0 0 0 0 0
39082 - 0 0 0 0 0 0 0 0 0 0 0 0
39083 - 0 0 0 0 0 0 0 0 0 0 0 0
39084 - 0 0 1 0 0 1 0 0 1 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 0 0 0 14 14 14
39090 - 46 46 46 86 86 86 2 2 6 2 2 6
39091 - 38 38 38 116 116 116 94 94 94 22 22 22
39092 - 22 22 22 2 2 6 2 2 6 2 2 6
39093 - 14 14 14 86 86 86 138 138 138 162 162 162
39094 -154 154 154 38 38 38 26 26 26 6 6 6
39095 - 2 2 6 2 2 6 2 2 6 2 2 6
39096 - 86 86 86 46 46 46 14 14 14 0 0 0
39097 - 0 0 0 0 0 0 0 0 0 0 0 0
39098 - 0 0 0 0 0 0 0 0 0 0 0 0
39099 - 0 0 0 0 0 0 0 0 0 0 0 0
39100 - 0 0 0 0 0 0 0 0 0 0 0 0
39101 - 0 0 0 0 0 0 0 0 0 0 0 0
39102 - 0 0 0 0 0 0 0 0 0 0 0 0
39103 - 0 0 0 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 0 0 0 14 14 14
39110 - 46 46 46 86 86 86 2 2 6 14 14 14
39111 -134 134 134 198 198 198 195 195 195 116 116 116
39112 - 10 10 10 2 2 6 2 2 6 6 6 6
39113 -101 98 89 187 187 187 210 210 210 218 218 218
39114 -214 214 214 134 134 134 14 14 14 6 6 6
39115 - 2 2 6 2 2 6 2 2 6 2 2 6
39116 - 86 86 86 50 50 50 18 18 18 6 6 6
39117 - 0 0 0 0 0 0 0 0 0 0 0 0
39118 - 0 0 0 0 0 0 0 0 0 0 0 0
39119 - 0 0 0 0 0 0 0 0 0 0 0 0
39120 - 0 0 0 0 0 0 0 0 0 0 0 0
39121 - 0 0 0 0 0 0 0 0 0 0 0 0
39122 - 0 0 0 0 0 0 0 0 0 0 0 0
39123 - 0 0 0 0 0 0 0 0 1 0 0 0
39124 - 0 0 1 0 0 1 0 0 1 0 0 0
39125 - 0 0 0 0 0 0 0 0 0 0 0 0
39126 - 0 0 0 0 0 0 0 0 0 0 0 0
39127 - 0 0 0 0 0 0 0 0 0 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 14 14 14
39130 - 46 46 46 86 86 86 2 2 6 54 54 54
39131 -218 218 218 195 195 195 226 226 226 246 246 246
39132 - 58 58 58 2 2 6 2 2 6 30 30 30
39133 -210 210 210 253 253 253 174 174 174 123 123 123
39134 -221 221 221 234 234 234 74 74 74 2 2 6
39135 - 2 2 6 2 2 6 2 2 6 2 2 6
39136 - 70 70 70 58 58 58 22 22 22 6 6 6
39137 - 0 0 0 0 0 0 0 0 0 0 0 0
39138 - 0 0 0 0 0 0 0 0 0 0 0 0
39139 - 0 0 0 0 0 0 0 0 0 0 0 0
39140 - 0 0 0 0 0 0 0 0 0 0 0 0
39141 - 0 0 0 0 0 0 0 0 0 0 0 0
39142 - 0 0 0 0 0 0 0 0 0 0 0 0
39143 - 0 0 0 0 0 0 0 0 0 0 0 0
39144 - 0 0 0 0 0 0 0 0 0 0 0 0
39145 - 0 0 0 0 0 0 0 0 0 0 0 0
39146 - 0 0 0 0 0 0 0 0 0 0 0 0
39147 - 0 0 0 0 0 0 0 0 0 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 0 0 0 0 0 0 0 0 0 14 14 14
39150 - 46 46 46 82 82 82 2 2 6 106 106 106
39151 -170 170 170 26 26 26 86 86 86 226 226 226
39152 -123 123 123 10 10 10 14 14 14 46 46 46
39153 -231 231 231 190 190 190 6 6 6 70 70 70
39154 - 90 90 90 238 238 238 158 158 158 2 2 6
39155 - 2 2 6 2 2 6 2 2 6 2 2 6
39156 - 70 70 70 58 58 58 22 22 22 6 6 6
39157 - 0 0 0 0 0 0 0 0 0 0 0 0
39158 - 0 0 0 0 0 0 0 0 0 0 0 0
39159 - 0 0 0 0 0 0 0 0 0 0 0 0
39160 - 0 0 0 0 0 0 0 0 0 0 0 0
39161 - 0 0 0 0 0 0 0 0 0 0 0 0
39162 - 0 0 0 0 0 0 0 0 0 0 0 0
39163 - 0 0 0 0 0 0 0 0 1 0 0 0
39164 - 0 0 1 0 0 1 0 0 1 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 14 14 14
39170 - 42 42 42 86 86 86 6 6 6 116 116 116
39171 -106 106 106 6 6 6 70 70 70 149 149 149
39172 -128 128 128 18 18 18 38 38 38 54 54 54
39173 -221 221 221 106 106 106 2 2 6 14 14 14
39174 - 46 46 46 190 190 190 198 198 198 2 2 6
39175 - 2 2 6 2 2 6 2 2 6 2 2 6
39176 - 74 74 74 62 62 62 22 22 22 6 6 6
39177 - 0 0 0 0 0 0 0 0 0 0 0 0
39178 - 0 0 0 0 0 0 0 0 0 0 0 0
39179 - 0 0 0 0 0 0 0 0 0 0 0 0
39180 - 0 0 0 0 0 0 0 0 0 0 0 0
39181 - 0 0 0 0 0 0 0 0 0 0 0 0
39182 - 0 0 0 0 0 0 0 0 0 0 0 0
39183 - 0 0 0 0 0 0 0 0 1 0 0 0
39184 - 0 0 1 0 0 0 0 0 1 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 14 14 14
39190 - 42 42 42 94 94 94 14 14 14 101 101 101
39191 -128 128 128 2 2 6 18 18 18 116 116 116
39192 -118 98 46 121 92 8 121 92 8 98 78 10
39193 -162 162 162 106 106 106 2 2 6 2 2 6
39194 - 2 2 6 195 195 195 195 195 195 6 6 6
39195 - 2 2 6 2 2 6 2 2 6 2 2 6
39196 - 74 74 74 62 62 62 22 22 22 6 6 6
39197 - 0 0 0 0 0 0 0 0 0 0 0 0
39198 - 0 0 0 0 0 0 0 0 0 0 0 0
39199 - 0 0 0 0 0 0 0 0 0 0 0 0
39200 - 0 0 0 0 0 0 0 0 0 0 0 0
39201 - 0 0 0 0 0 0 0 0 0 0 0 0
39202 - 0 0 0 0 0 0 0 0 0 0 0 0
39203 - 0 0 0 0 0 0 0 0 1 0 0 1
39204 - 0 0 1 0 0 0 0 0 1 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 10 10 10
39210 - 38 38 38 90 90 90 14 14 14 58 58 58
39211 -210 210 210 26 26 26 54 38 6 154 114 10
39212 -226 170 11 236 186 11 225 175 15 184 144 12
39213 -215 174 15 175 146 61 37 26 9 2 2 6
39214 - 70 70 70 246 246 246 138 138 138 2 2 6
39215 - 2 2 6 2 2 6 2 2 6 2 2 6
39216 - 70 70 70 66 66 66 26 26 26 6 6 6
39217 - 0 0 0 0 0 0 0 0 0 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 0 0 0 0 0 0 0 0 0
39222 - 0 0 0 0 0 0 0 0 0 0 0 0
39223 - 0 0 0 0 0 0 0 0 0 0 0 0
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 10 10 10
39230 - 38 38 38 86 86 86 14 14 14 10 10 10
39231 -195 195 195 188 164 115 192 133 9 225 175 15
39232 -239 182 13 234 190 10 232 195 16 232 200 30
39233 -245 207 45 241 208 19 232 195 16 184 144 12
39234 -218 194 134 211 206 186 42 42 42 2 2 6
39235 - 2 2 6 2 2 6 2 2 6 2 2 6
39236 - 50 50 50 74 74 74 30 30 30 6 6 6
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 0 0 0 0 0 0 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 0 0 0
39243 - 0 0 0 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 0 0 0 0 0 0 0 0 0
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 10 10 10
39250 - 34 34 34 86 86 86 14 14 14 2 2 6
39251 -121 87 25 192 133 9 219 162 10 239 182 13
39252 -236 186 11 232 195 16 241 208 19 244 214 54
39253 -246 218 60 246 218 38 246 215 20 241 208 19
39254 -241 208 19 226 184 13 121 87 25 2 2 6
39255 - 2 2 6 2 2 6 2 2 6 2 2 6
39256 - 50 50 50 82 82 82 34 34 34 10 10 10
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 0 0 0
39263 - 0 0 0 0 0 0 0 0 0 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 0 0 0 0 0 0 0 0 0 0 0 0
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 10 10 10
39270 - 34 34 34 82 82 82 30 30 30 61 42 6
39271 -180 123 7 206 145 10 230 174 11 239 182 13
39272 -234 190 10 238 202 15 241 208 19 246 218 74
39273 -246 218 38 246 215 20 246 215 20 246 215 20
39274 -226 184 13 215 174 15 184 144 12 6 6 6
39275 - 2 2 6 2 2 6 2 2 6 2 2 6
39276 - 26 26 26 94 94 94 42 42 42 14 14 14
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 0 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 0 0 0 0
39281 - 0 0 0 0 0 0 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 0 0 0
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 10 10 10
39290 - 30 30 30 78 78 78 50 50 50 104 69 6
39291 -192 133 9 216 158 10 236 178 12 236 186 11
39292 -232 195 16 241 208 19 244 214 54 245 215 43
39293 -246 215 20 246 215 20 241 208 19 198 155 10
39294 -200 144 11 216 158 10 156 118 10 2 2 6
39295 - 2 2 6 2 2 6 2 2 6 2 2 6
39296 - 6 6 6 90 90 90 54 54 54 18 18 18
39297 - 6 6 6 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 0 0 0 0 0 0 0 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 0 0 0
39301 - 0 0 0 0 0 0 0 0 0 0 0 0
39302 - 0 0 0 0 0 0 0 0 0 0 0 0
39303 - 0 0 0 0 0 0 0 0 0 0 0 0
39304 - 0 0 0 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 10 10 10
39310 - 30 30 30 78 78 78 46 46 46 22 22 22
39311 -137 92 6 210 162 10 239 182 13 238 190 10
39312 -238 202 15 241 208 19 246 215 20 246 215 20
39313 -241 208 19 203 166 17 185 133 11 210 150 10
39314 -216 158 10 210 150 10 102 78 10 2 2 6
39315 - 6 6 6 54 54 54 14 14 14 2 2 6
39316 - 2 2 6 62 62 62 74 74 74 30 30 30
39317 - 10 10 10 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 0 0 0 0
39321 - 0 0 0 0 0 0 0 0 0 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 0 0 0
39323 - 0 0 0 0 0 0 0 0 0 0 0 0
39324 - 0 0 0 0 0 0 0 0 0 0 0 0
39325 - 0 0 0 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 10 10 10
39330 - 34 34 34 78 78 78 50 50 50 6 6 6
39331 - 94 70 30 139 102 15 190 146 13 226 184 13
39332 -232 200 30 232 195 16 215 174 15 190 146 13
39333 -168 122 10 192 133 9 210 150 10 213 154 11
39334 -202 150 34 182 157 106 101 98 89 2 2 6
39335 - 2 2 6 78 78 78 116 116 116 58 58 58
39336 - 2 2 6 22 22 22 90 90 90 46 46 46
39337 - 18 18 18 6 6 6 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 0 0 0 0 0 0 0 0 0 0
39340 - 0 0 0 0 0 0 0 0 0 0 0 0
39341 - 0 0 0 0 0 0 0 0 0 0 0 0
39342 - 0 0 0 0 0 0 0 0 0 0 0 0
39343 - 0 0 0 0 0 0 0 0 0 0 0 0
39344 - 0 0 0 0 0 0 0 0 0 0 0 0
39345 - 0 0 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 10 10 10
39350 - 38 38 38 86 86 86 50 50 50 6 6 6
39351 -128 128 128 174 154 114 156 107 11 168 122 10
39352 -198 155 10 184 144 12 197 138 11 200 144 11
39353 -206 145 10 206 145 10 197 138 11 188 164 115
39354 -195 195 195 198 198 198 174 174 174 14 14 14
39355 - 2 2 6 22 22 22 116 116 116 116 116 116
39356 - 22 22 22 2 2 6 74 74 74 70 70 70
39357 - 30 30 30 10 10 10 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 0 0 0 0 0 0
39361 - 0 0 0 0 0 0 0 0 0 0 0 0
39362 - 0 0 0 0 0 0 0 0 0 0 0 0
39363 - 0 0 0 0 0 0 0 0 0 0 0 0
39364 - 0 0 0 0 0 0 0 0 0 0 0 0
39365 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 6 6 6 18 18 18
39370 - 50 50 50 101 101 101 26 26 26 10 10 10
39371 -138 138 138 190 190 190 174 154 114 156 107 11
39372 -197 138 11 200 144 11 197 138 11 192 133 9
39373 -180 123 7 190 142 34 190 178 144 187 187 187
39374 -202 202 202 221 221 221 214 214 214 66 66 66
39375 - 2 2 6 2 2 6 50 50 50 62 62 62
39376 - 6 6 6 2 2 6 10 10 10 90 90 90
39377 - 50 50 50 18 18 18 6 6 6 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 0 0 0
39381 - 0 0 0 0 0 0 0 0 0 0 0 0
39382 - 0 0 0 0 0 0 0 0 0 0 0 0
39383 - 0 0 0 0 0 0 0 0 0 0 0 0
39384 - 0 0 0 0 0 0 0 0 0 0 0 0
39385 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 10 10 10 34 34 34
39390 - 74 74 74 74 74 74 2 2 6 6 6 6
39391 -144 144 144 198 198 198 190 190 190 178 166 146
39392 -154 121 60 156 107 11 156 107 11 168 124 44
39393 -174 154 114 187 187 187 190 190 190 210 210 210
39394 -246 246 246 253 253 253 253 253 253 182 182 182
39395 - 6 6 6 2 2 6 2 2 6 2 2 6
39396 - 2 2 6 2 2 6 2 2 6 62 62 62
39397 - 74 74 74 34 34 34 14 14 14 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 0 0 0 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 0 0 0
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 0 0 0 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 - 0 0 0 10 10 10 22 22 22 54 54 54
39410 - 94 94 94 18 18 18 2 2 6 46 46 46
39411 -234 234 234 221 221 221 190 190 190 190 190 190
39412 -190 190 190 187 187 187 187 187 187 190 190 190
39413 -190 190 190 195 195 195 214 214 214 242 242 242
39414 -253 253 253 253 253 253 253 253 253 253 253 253
39415 - 82 82 82 2 2 6 2 2 6 2 2 6
39416 - 2 2 6 2 2 6 2 2 6 14 14 14
39417 - 86 86 86 54 54 54 22 22 22 6 6 6
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 0 0 0 0 0 0 0
39420 - 0 0 0 0 0 0 0 0 0 0 0 0
39421 - 0 0 0 0 0 0 0 0 0 0 0 0
39422 - 0 0 0 0 0 0 0 0 0 0 0 0
39423 - 0 0 0 0 0 0 0 0 0 0 0 0
39424 - 0 0 0 0 0 0 0 0 0 0 0 0
39425 - 0 0 0 0 0 0 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 0 0 0
39427 - 0 0 0 0 0 0 0 0 0 0 0 0
39428 - 0 0 0 0 0 0 0 0 0 0 0 0
39429 - 6 6 6 18 18 18 46 46 46 90 90 90
39430 - 46 46 46 18 18 18 6 6 6 182 182 182
39431 -253 253 253 246 246 246 206 206 206 190 190 190
39432 -190 190 190 190 190 190 190 190 190 190 190 190
39433 -206 206 206 231 231 231 250 250 250 253 253 253
39434 -253 253 253 253 253 253 253 253 253 253 253 253
39435 -202 202 202 14 14 14 2 2 6 2 2 6
39436 - 2 2 6 2 2 6 2 2 6 2 2 6
39437 - 42 42 42 86 86 86 42 42 42 18 18 18
39438 - 6 6 6 0 0 0 0 0 0 0 0 0
39439 - 0 0 0 0 0 0 0 0 0 0 0 0
39440 - 0 0 0 0 0 0 0 0 0 0 0 0
39441 - 0 0 0 0 0 0 0 0 0 0 0 0
39442 - 0 0 0 0 0 0 0 0 0 0 0 0
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 0 0 0 0 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 0 0 0
39447 - 0 0 0 0 0 0 0 0 0 0 0 0
39448 - 0 0 0 0 0 0 0 0 0 6 6 6
39449 - 14 14 14 38 38 38 74 74 74 66 66 66
39450 - 2 2 6 6 6 6 90 90 90 250 250 250
39451 -253 253 253 253 253 253 238 238 238 198 198 198
39452 -190 190 190 190 190 190 195 195 195 221 221 221
39453 -246 246 246 253 253 253 253 253 253 253 253 253
39454 -253 253 253 253 253 253 253 253 253 253 253 253
39455 -253 253 253 82 82 82 2 2 6 2 2 6
39456 - 2 2 6 2 2 6 2 2 6 2 2 6
39457 - 2 2 6 78 78 78 70 70 70 34 34 34
39458 - 14 14 14 6 6 6 0 0 0 0 0 0
39459 - 0 0 0 0 0 0 0 0 0 0 0 0
39460 - 0 0 0 0 0 0 0 0 0 0 0 0
39461 - 0 0 0 0 0 0 0 0 0 0 0 0
39462 - 0 0 0 0 0 0 0 0 0 0 0 0
39463 - 0 0 0 0 0 0 0 0 0 0 0 0
39464 - 0 0 0 0 0 0 0 0 0 0 0 0
39465 - 0 0 0 0 0 0 0 0 0 0 0 0
39466 - 0 0 0 0 0 0 0 0 0 0 0 0
39467 - 0 0 0 0 0 0 0 0 0 0 0 0
39468 - 0 0 0 0 0 0 0 0 0 14 14 14
39469 - 34 34 34 66 66 66 78 78 78 6 6 6
39470 - 2 2 6 18 18 18 218 218 218 253 253 253
39471 -253 253 253 253 253 253 253 253 253 246 246 246
39472 -226 226 226 231 231 231 246 246 246 253 253 253
39473 -253 253 253 253 253 253 253 253 253 253 253 253
39474 -253 253 253 253 253 253 253 253 253 253 253 253
39475 -253 253 253 178 178 178 2 2 6 2 2 6
39476 - 2 2 6 2 2 6 2 2 6 2 2 6
39477 - 2 2 6 18 18 18 90 90 90 62 62 62
39478 - 30 30 30 10 10 10 0 0 0 0 0 0
39479 - 0 0 0 0 0 0 0 0 0 0 0 0
39480 - 0 0 0 0 0 0 0 0 0 0 0 0
39481 - 0 0 0 0 0 0 0 0 0 0 0 0
39482 - 0 0 0 0 0 0 0 0 0 0 0 0
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 0 0 0
39488 - 0 0 0 0 0 0 10 10 10 26 26 26
39489 - 58 58 58 90 90 90 18 18 18 2 2 6
39490 - 2 2 6 110 110 110 253 253 253 253 253 253
39491 -253 253 253 253 253 253 253 253 253 253 253 253
39492 -250 250 250 253 253 253 253 253 253 253 253 253
39493 -253 253 253 253 253 253 253 253 253 253 253 253
39494 -253 253 253 253 253 253 253 253 253 253 253 253
39495 -253 253 253 231 231 231 18 18 18 2 2 6
39496 - 2 2 6 2 2 6 2 2 6 2 2 6
39497 - 2 2 6 2 2 6 18 18 18 94 94 94
39498 - 54 54 54 26 26 26 10 10 10 0 0 0
39499 - 0 0 0 0 0 0 0 0 0 0 0 0
39500 - 0 0 0 0 0 0 0 0 0 0 0 0
39501 - 0 0 0 0 0 0 0 0 0 0 0 0
39502 - 0 0 0 0 0 0 0 0 0 0 0 0
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 0 0 0 0
39508 - 0 0 0 6 6 6 22 22 22 50 50 50
39509 - 90 90 90 26 26 26 2 2 6 2 2 6
39510 - 14 14 14 195 195 195 250 250 250 253 253 253
39511 -253 253 253 253 253 253 253 253 253 253 253 253
39512 -253 253 253 253 253 253 253 253 253 253 253 253
39513 -253 253 253 253 253 253 253 253 253 253 253 253
39514 -253 253 253 253 253 253 253 253 253 253 253 253
39515 -250 250 250 242 242 242 54 54 54 2 2 6
39516 - 2 2 6 2 2 6 2 2 6 2 2 6
39517 - 2 2 6 2 2 6 2 2 6 38 38 38
39518 - 86 86 86 50 50 50 22 22 22 6 6 6
39519 - 0 0 0 0 0 0 0 0 0 0 0 0
39520 - 0 0 0 0 0 0 0 0 0 0 0 0
39521 - 0 0 0 0 0 0 0 0 0 0 0 0
39522 - 0 0 0 0 0 0 0 0 0 0 0 0
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 0 0 0
39525 - 0 0 0 0 0 0 0 0 0 0 0 0
39526 - 0 0 0 0 0 0 0 0 0 0 0 0
39527 - 0 0 0 0 0 0 0 0 0 0 0 0
39528 - 6 6 6 14 14 14 38 38 38 82 82 82
39529 - 34 34 34 2 2 6 2 2 6 2 2 6
39530 - 42 42 42 195 195 195 246 246 246 253 253 253
39531 -253 253 253 253 253 253 253 253 253 250 250 250
39532 -242 242 242 242 242 242 250 250 250 253 253 253
39533 -253 253 253 253 253 253 253 253 253 253 253 253
39534 -253 253 253 250 250 250 246 246 246 238 238 238
39535 -226 226 226 231 231 231 101 101 101 6 6 6
39536 - 2 2 6 2 2 6 2 2 6 2 2 6
39537 - 2 2 6 2 2 6 2 2 6 2 2 6
39538 - 38 38 38 82 82 82 42 42 42 14 14 14
39539 - 6 6 6 0 0 0 0 0 0 0 0 0
39540 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 10 10 10 26 26 26 62 62 62 66 66 66
39549 - 2 2 6 2 2 6 2 2 6 6 6 6
39550 - 70 70 70 170 170 170 206 206 206 234 234 234
39551 -246 246 246 250 250 250 250 250 250 238 238 238
39552 -226 226 226 231 231 231 238 238 238 250 250 250
39553 -250 250 250 250 250 250 246 246 246 231 231 231
39554 -214 214 214 206 206 206 202 202 202 202 202 202
39555 -198 198 198 202 202 202 182 182 182 18 18 18
39556 - 2 2 6 2 2 6 2 2 6 2 2 6
39557 - 2 2 6 2 2 6 2 2 6 2 2 6
39558 - 2 2 6 62 62 62 66 66 66 30 30 30
39559 - 10 10 10 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 14 14 14 42 42 42 82 82 82 18 18 18
39569 - 2 2 6 2 2 6 2 2 6 10 10 10
39570 - 94 94 94 182 182 182 218 218 218 242 242 242
39571 -250 250 250 253 253 253 253 253 253 250 250 250
39572 -234 234 234 253 253 253 253 253 253 253 253 253
39573 -253 253 253 253 253 253 253 253 253 246 246 246
39574 -238 238 238 226 226 226 210 210 210 202 202 202
39575 -195 195 195 195 195 195 210 210 210 158 158 158
39576 - 6 6 6 14 14 14 50 50 50 14 14 14
39577 - 2 2 6 2 2 6 2 2 6 2 2 6
39578 - 2 2 6 6 6 6 86 86 86 46 46 46
39579 - 18 18 18 6 6 6 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 6 6 6
39588 - 22 22 22 54 54 54 70 70 70 2 2 6
39589 - 2 2 6 10 10 10 2 2 6 22 22 22
39590 -166 166 166 231 231 231 250 250 250 253 253 253
39591 -253 253 253 253 253 253 253 253 253 250 250 250
39592 -242 242 242 253 253 253 253 253 253 253 253 253
39593 -253 253 253 253 253 253 253 253 253 253 253 253
39594 -253 253 253 253 253 253 253 253 253 246 246 246
39595 -231 231 231 206 206 206 198 198 198 226 226 226
39596 - 94 94 94 2 2 6 6 6 6 38 38 38
39597 - 30 30 30 2 2 6 2 2 6 2 2 6
39598 - 2 2 6 2 2 6 62 62 62 66 66 66
39599 - 26 26 26 10 10 10 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 10 10 10
39608 - 30 30 30 74 74 74 50 50 50 2 2 6
39609 - 26 26 26 26 26 26 2 2 6 106 106 106
39610 -238 238 238 253 253 253 253 253 253 253 253 253
39611 -253 253 253 253 253 253 253 253 253 253 253 253
39612 -253 253 253 253 253 253 253 253 253 253 253 253
39613 -253 253 253 253 253 253 253 253 253 253 253 253
39614 -253 253 253 253 253 253 253 253 253 253 253 253
39615 -253 253 253 246 246 246 218 218 218 202 202 202
39616 -210 210 210 14 14 14 2 2 6 2 2 6
39617 - 30 30 30 22 22 22 2 2 6 2 2 6
39618 - 2 2 6 2 2 6 18 18 18 86 86 86
39619 - 42 42 42 14 14 14 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 14 14 14
39628 - 42 42 42 90 90 90 22 22 22 2 2 6
39629 - 42 42 42 2 2 6 18 18 18 218 218 218
39630 -253 253 253 253 253 253 253 253 253 253 253 253
39631 -253 253 253 253 253 253 253 253 253 253 253 253
39632 -253 253 253 253 253 253 253 253 253 253 253 253
39633 -253 253 253 253 253 253 253 253 253 253 253 253
39634 -253 253 253 253 253 253 253 253 253 253 253 253
39635 -253 253 253 253 253 253 250 250 250 221 221 221
39636 -218 218 218 101 101 101 2 2 6 14 14 14
39637 - 18 18 18 38 38 38 10 10 10 2 2 6
39638 - 2 2 6 2 2 6 2 2 6 78 78 78
39639 - 58 58 58 22 22 22 6 6 6 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 6 6 6 18 18 18
39648 - 54 54 54 82 82 82 2 2 6 26 26 26
39649 - 22 22 22 2 2 6 123 123 123 253 253 253
39650 -253 253 253 253 253 253 253 253 253 253 253 253
39651 -253 253 253 253 253 253 253 253 253 253 253 253
39652 -253 253 253 253 253 253 253 253 253 253 253 253
39653 -253 253 253 253 253 253 253 253 253 253 253 253
39654 -253 253 253 253 253 253 253 253 253 253 253 253
39655 -253 253 253 253 253 253 253 253 253 250 250 250
39656 -238 238 238 198 198 198 6 6 6 38 38 38
39657 - 58 58 58 26 26 26 38 38 38 2 2 6
39658 - 2 2 6 2 2 6 2 2 6 46 46 46
39659 - 78 78 78 30 30 30 10 10 10 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 0 0 0 0 10 10 10 30 30 30
39668 - 74 74 74 58 58 58 2 2 6 42 42 42
39669 - 2 2 6 22 22 22 231 231 231 253 253 253
39670 -253 253 253 253 253 253 253 253 253 253 253 253
39671 -253 253 253 253 253 253 253 253 253 250 250 250
39672 -253 253 253 253 253 253 253 253 253 253 253 253
39673 -253 253 253 253 253 253 253 253 253 253 253 253
39674 -253 253 253 253 253 253 253 253 253 253 253 253
39675 -253 253 253 253 253 253 253 253 253 253 253 253
39676 -253 253 253 246 246 246 46 46 46 38 38 38
39677 - 42 42 42 14 14 14 38 38 38 14 14 14
39678 - 2 2 6 2 2 6 2 2 6 6 6 6
39679 - 86 86 86 46 46 46 14 14 14 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 6 6 6 14 14 14 42 42 42
39688 - 90 90 90 18 18 18 18 18 18 26 26 26
39689 - 2 2 6 116 116 116 253 253 253 253 253 253
39690 -253 253 253 253 253 253 253 253 253 253 253 253
39691 -253 253 253 253 253 253 250 250 250 238 238 238
39692 -253 253 253 253 253 253 253 253 253 253 253 253
39693 -253 253 253 253 253 253 253 253 253 253 253 253
39694 -253 253 253 253 253 253 253 253 253 253 253 253
39695 -253 253 253 253 253 253 253 253 253 253 253 253
39696 -253 253 253 253 253 253 94 94 94 6 6 6
39697 - 2 2 6 2 2 6 10 10 10 34 34 34
39698 - 2 2 6 2 2 6 2 2 6 2 2 6
39699 - 74 74 74 58 58 58 22 22 22 6 6 6
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 10 10 10 26 26 26 66 66 66
39708 - 82 82 82 2 2 6 38 38 38 6 6 6
39709 - 14 14 14 210 210 210 253 253 253 253 253 253
39710 -253 253 253 253 253 253 253 253 253 253 253 253
39711 -253 253 253 253 253 253 246 246 246 242 242 242
39712 -253 253 253 253 253 253 253 253 253 253 253 253
39713 -253 253 253 253 253 253 253 253 253 253 253 253
39714 -253 253 253 253 253 253 253 253 253 253 253 253
39715 -253 253 253 253 253 253 253 253 253 253 253 253
39716 -253 253 253 253 253 253 144 144 144 2 2 6
39717 - 2 2 6 2 2 6 2 2 6 46 46 46
39718 - 2 2 6 2 2 6 2 2 6 2 2 6
39719 - 42 42 42 74 74 74 30 30 30 10 10 10
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 6 6 6 14 14 14 42 42 42 90 90 90
39728 - 26 26 26 6 6 6 42 42 42 2 2 6
39729 - 74 74 74 250 250 250 253 253 253 253 253 253
39730 -253 253 253 253 253 253 253 253 253 253 253 253
39731 -253 253 253 253 253 253 242 242 242 242 242 242
39732 -253 253 253 253 253 253 253 253 253 253 253 253
39733 -253 253 253 253 253 253 253 253 253 253 253 253
39734 -253 253 253 253 253 253 253 253 253 253 253 253
39735 -253 253 253 253 253 253 253 253 253 253 253 253
39736 -253 253 253 253 253 253 182 182 182 2 2 6
39737 - 2 2 6 2 2 6 2 2 6 46 46 46
39738 - 2 2 6 2 2 6 2 2 6 2 2 6
39739 - 10 10 10 86 86 86 38 38 38 10 10 10
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 10 10 10 26 26 26 66 66 66 82 82 82
39748 - 2 2 6 22 22 22 18 18 18 2 2 6
39749 -149 149 149 253 253 253 253 253 253 253 253 253
39750 -253 253 253 253 253 253 253 253 253 253 253 253
39751 -253 253 253 253 253 253 234 234 234 242 242 242
39752 -253 253 253 253 253 253 253 253 253 253 253 253
39753 -253 253 253 253 253 253 253 253 253 253 253 253
39754 -253 253 253 253 253 253 253 253 253 253 253 253
39755 -253 253 253 253 253 253 253 253 253 253 253 253
39756 -253 253 253 253 253 253 206 206 206 2 2 6
39757 - 2 2 6 2 2 6 2 2 6 38 38 38
39758 - 2 2 6 2 2 6 2 2 6 2 2 6
39759 - 6 6 6 86 86 86 46 46 46 14 14 14
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 6 6 6
39767 - 18 18 18 46 46 46 86 86 86 18 18 18
39768 - 2 2 6 34 34 34 10 10 10 6 6 6
39769 -210 210 210 253 253 253 253 253 253 253 253 253
39770 -253 253 253 253 253 253 253 253 253 253 253 253
39771 -253 253 253 253 253 253 234 234 234 242 242 242
39772 -253 253 253 253 253 253 253 253 253 253 253 253
39773 -253 253 253 253 253 253 253 253 253 253 253 253
39774 -253 253 253 253 253 253 253 253 253 253 253 253
39775 -253 253 253 253 253 253 253 253 253 253 253 253
39776 -253 253 253 253 253 253 221 221 221 6 6 6
39777 - 2 2 6 2 2 6 6 6 6 30 30 30
39778 - 2 2 6 2 2 6 2 2 6 2 2 6
39779 - 2 2 6 82 82 82 54 54 54 18 18 18
39780 - 6 6 6 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 10 10 10
39787 - 26 26 26 66 66 66 62 62 62 2 2 6
39788 - 2 2 6 38 38 38 10 10 10 26 26 26
39789 -238 238 238 253 253 253 253 253 253 253 253 253
39790 -253 253 253 253 253 253 253 253 253 253 253 253
39791 -253 253 253 253 253 253 231 231 231 238 238 238
39792 -253 253 253 253 253 253 253 253 253 253 253 253
39793 -253 253 253 253 253 253 253 253 253 253 253 253
39794 -253 253 253 253 253 253 253 253 253 253 253 253
39795 -253 253 253 253 253 253 253 253 253 253 253 253
39796 -253 253 253 253 253 253 231 231 231 6 6 6
39797 - 2 2 6 2 2 6 10 10 10 30 30 30
39798 - 2 2 6 2 2 6 2 2 6 2 2 6
39799 - 2 2 6 66 66 66 58 58 58 22 22 22
39800 - 6 6 6 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 10 10 10
39807 - 38 38 38 78 78 78 6 6 6 2 2 6
39808 - 2 2 6 46 46 46 14 14 14 42 42 42
39809 -246 246 246 253 253 253 253 253 253 253 253 253
39810 -253 253 253 253 253 253 253 253 253 253 253 253
39811 -253 253 253 253 253 253 231 231 231 242 242 242
39812 -253 253 253 253 253 253 253 253 253 253 253 253
39813 -253 253 253 253 253 253 253 253 253 253 253 253
39814 -253 253 253 253 253 253 253 253 253 253 253 253
39815 -253 253 253 253 253 253 253 253 253 253 253 253
39816 -253 253 253 253 253 253 234 234 234 10 10 10
39817 - 2 2 6 2 2 6 22 22 22 14 14 14
39818 - 2 2 6 2 2 6 2 2 6 2 2 6
39819 - 2 2 6 66 66 66 62 62 62 22 22 22
39820 - 6 6 6 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 6 6 6 18 18 18
39827 - 50 50 50 74 74 74 2 2 6 2 2 6
39828 - 14 14 14 70 70 70 34 34 34 62 62 62
39829 -250 250 250 253 253 253 253 253 253 253 253 253
39830 -253 253 253 253 253 253 253 253 253 253 253 253
39831 -253 253 253 253 253 253 231 231 231 246 246 246
39832 -253 253 253 253 253 253 253 253 253 253 253 253
39833 -253 253 253 253 253 253 253 253 253 253 253 253
39834 -253 253 253 253 253 253 253 253 253 253 253 253
39835 -253 253 253 253 253 253 253 253 253 253 253 253
39836 -253 253 253 253 253 253 234 234 234 14 14 14
39837 - 2 2 6 2 2 6 30 30 30 2 2 6
39838 - 2 2 6 2 2 6 2 2 6 2 2 6
39839 - 2 2 6 66 66 66 62 62 62 22 22 22
39840 - 6 6 6 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 6 6 6 18 18 18
39847 - 54 54 54 62 62 62 2 2 6 2 2 6
39848 - 2 2 6 30 30 30 46 46 46 70 70 70
39849 -250 250 250 253 253 253 253 253 253 253 253 253
39850 -253 253 253 253 253 253 253 253 253 253 253 253
39851 -253 253 253 253 253 253 231 231 231 246 246 246
39852 -253 253 253 253 253 253 253 253 253 253 253 253
39853 -253 253 253 253 253 253 253 253 253 253 253 253
39854 -253 253 253 253 253 253 253 253 253 253 253 253
39855 -253 253 253 253 253 253 253 253 253 253 253 253
39856 -253 253 253 253 253 253 226 226 226 10 10 10
39857 - 2 2 6 6 6 6 30 30 30 2 2 6
39858 - 2 2 6 2 2 6 2 2 6 2 2 6
39859 - 2 2 6 66 66 66 58 58 58 22 22 22
39860 - 6 6 6 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 6 6 6 22 22 22
39867 - 58 58 58 62 62 62 2 2 6 2 2 6
39868 - 2 2 6 2 2 6 30 30 30 78 78 78
39869 -250 250 250 253 253 253 253 253 253 253 253 253
39870 -253 253 253 253 253 253 253 253 253 253 253 253
39871 -253 253 253 253 253 253 231 231 231 246 246 246
39872 -253 253 253 253 253 253 253 253 253 253 253 253
39873 -253 253 253 253 253 253 253 253 253 253 253 253
39874 -253 253 253 253 253 253 253 253 253 253 253 253
39875 -253 253 253 253 253 253 253 253 253 253 253 253
39876 -253 253 253 253 253 253 206 206 206 2 2 6
39877 - 22 22 22 34 34 34 18 14 6 22 22 22
39878 - 26 26 26 18 18 18 6 6 6 2 2 6
39879 - 2 2 6 82 82 82 54 54 54 18 18 18
39880 - 6 6 6 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 6 6 6 26 26 26
39887 - 62 62 62 106 106 106 74 54 14 185 133 11
39888 -210 162 10 121 92 8 6 6 6 62 62 62
39889 -238 238 238 253 253 253 253 253 253 253 253 253
39890 -253 253 253 253 253 253 253 253 253 253 253 253
39891 -253 253 253 253 253 253 231 231 231 246 246 246
39892 -253 253 253 253 253 253 253 253 253 253 253 253
39893 -253 253 253 253 253 253 253 253 253 253 253 253
39894 -253 253 253 253 253 253 253 253 253 253 253 253
39895 -253 253 253 253 253 253 253 253 253 253 253 253
39896 -253 253 253 253 253 253 158 158 158 18 18 18
39897 - 14 14 14 2 2 6 2 2 6 2 2 6
39898 - 6 6 6 18 18 18 66 66 66 38 38 38
39899 - 6 6 6 94 94 94 50 50 50 18 18 18
39900 - 6 6 6 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 6 6 6
39906 - 10 10 10 10 10 10 18 18 18 38 38 38
39907 - 78 78 78 142 134 106 216 158 10 242 186 14
39908 -246 190 14 246 190 14 156 118 10 10 10 10
39909 - 90 90 90 238 238 238 253 253 253 253 253 253
39910 -253 253 253 253 253 253 253 253 253 253 253 253
39911 -253 253 253 253 253 253 231 231 231 250 250 250
39912 -253 253 253 253 253 253 253 253 253 253 253 253
39913 -253 253 253 253 253 253 253 253 253 253 253 253
39914 -253 253 253 253 253 253 253 253 253 253 253 253
39915 -253 253 253 253 253 253 253 253 253 246 230 190
39916 -238 204 91 238 204 91 181 142 44 37 26 9
39917 - 2 2 6 2 2 6 2 2 6 2 2 6
39918 - 2 2 6 2 2 6 38 38 38 46 46 46
39919 - 26 26 26 106 106 106 54 54 54 18 18 18
39920 - 6 6 6 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 6 6 6 14 14 14 22 22 22
39926 - 30 30 30 38 38 38 50 50 50 70 70 70
39927 -106 106 106 190 142 34 226 170 11 242 186 14
39928 -246 190 14 246 190 14 246 190 14 154 114 10
39929 - 6 6 6 74 74 74 226 226 226 253 253 253
39930 -253 253 253 253 253 253 253 253 253 253 253 253
39931 -253 253 253 253 253 253 231 231 231 250 250 250
39932 -253 253 253 253 253 253 253 253 253 253 253 253
39933 -253 253 253 253 253 253 253 253 253 253 253 253
39934 -253 253 253 253 253 253 253 253 253 253 253 253
39935 -253 253 253 253 253 253 253 253 253 228 184 62
39936 -241 196 14 241 208 19 232 195 16 38 30 10
39937 - 2 2 6 2 2 6 2 2 6 2 2 6
39938 - 2 2 6 6 6 6 30 30 30 26 26 26
39939 -203 166 17 154 142 90 66 66 66 26 26 26
39940 - 6 6 6 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 6 6 6 18 18 18 38 38 38 58 58 58
39946 - 78 78 78 86 86 86 101 101 101 123 123 123
39947 -175 146 61 210 150 10 234 174 13 246 186 14
39948 -246 190 14 246 190 14 246 190 14 238 190 10
39949 -102 78 10 2 2 6 46 46 46 198 198 198
39950 -253 253 253 253 253 253 253 253 253 253 253 253
39951 -253 253 253 253 253 253 234 234 234 242 242 242
39952 -253 253 253 253 253 253 253 253 253 253 253 253
39953 -253 253 253 253 253 253 253 253 253 253 253 253
39954 -253 253 253 253 253 253 253 253 253 253 253 253
39955 -253 253 253 253 253 253 253 253 253 224 178 62
39956 -242 186 14 241 196 14 210 166 10 22 18 6
39957 - 2 2 6 2 2 6 2 2 6 2 2 6
39958 - 2 2 6 2 2 6 6 6 6 121 92 8
39959 -238 202 15 232 195 16 82 82 82 34 34 34
39960 - 10 10 10 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 14 14 14 38 38 38 70 70 70 154 122 46
39966 -190 142 34 200 144 11 197 138 11 197 138 11
39967 -213 154 11 226 170 11 242 186 14 246 190 14
39968 -246 190 14 246 190 14 246 190 14 246 190 14
39969 -225 175 15 46 32 6 2 2 6 22 22 22
39970 -158 158 158 250 250 250 253 253 253 253 253 253
39971 -253 253 253 253 253 253 253 253 253 253 253 253
39972 -253 253 253 253 253 253 253 253 253 253 253 253
39973 -253 253 253 253 253 253 253 253 253 253 253 253
39974 -253 253 253 253 253 253 253 253 253 253 253 253
39975 -253 253 253 250 250 250 242 242 242 224 178 62
39976 -239 182 13 236 186 11 213 154 11 46 32 6
39977 - 2 2 6 2 2 6 2 2 6 2 2 6
39978 - 2 2 6 2 2 6 61 42 6 225 175 15
39979 -238 190 10 236 186 11 112 100 78 42 42 42
39980 - 14 14 14 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 6 6 6
39985 - 22 22 22 54 54 54 154 122 46 213 154 11
39986 -226 170 11 230 174 11 226 170 11 226 170 11
39987 -236 178 12 242 186 14 246 190 14 246 190 14
39988 -246 190 14 246 190 14 246 190 14 246 190 14
39989 -241 196 14 184 144 12 10 10 10 2 2 6
39990 - 6 6 6 116 116 116 242 242 242 253 253 253
39991 -253 253 253 253 253 253 253 253 253 253 253 253
39992 -253 253 253 253 253 253 253 253 253 253 253 253
39993 -253 253 253 253 253 253 253 253 253 253 253 253
39994 -253 253 253 253 253 253 253 253 253 253 253 253
39995 -253 253 253 231 231 231 198 198 198 214 170 54
39996 -236 178 12 236 178 12 210 150 10 137 92 6
39997 - 18 14 6 2 2 6 2 2 6 2 2 6
39998 - 6 6 6 70 47 6 200 144 11 236 178 12
39999 -239 182 13 239 182 13 124 112 88 58 58 58
40000 - 22 22 22 6 6 6 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 10 10 10
40005 - 30 30 30 70 70 70 180 133 36 226 170 11
40006 -239 182 13 242 186 14 242 186 14 246 186 14
40007 -246 190 14 246 190 14 246 190 14 246 190 14
40008 -246 190 14 246 190 14 246 190 14 246 190 14
40009 -246 190 14 232 195 16 98 70 6 2 2 6
40010 - 2 2 6 2 2 6 66 66 66 221 221 221
40011 -253 253 253 253 253 253 253 253 253 253 253 253
40012 -253 253 253 253 253 253 253 253 253 253 253 253
40013 -253 253 253 253 253 253 253 253 253 253 253 253
40014 -253 253 253 253 253 253 253 253 253 253 253 253
40015 -253 253 253 206 206 206 198 198 198 214 166 58
40016 -230 174 11 230 174 11 216 158 10 192 133 9
40017 -163 110 8 116 81 8 102 78 10 116 81 8
40018 -167 114 7 197 138 11 226 170 11 239 182 13
40019 -242 186 14 242 186 14 162 146 94 78 78 78
40020 - 34 34 34 14 14 14 6 6 6 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 6 6 6
40025 - 30 30 30 78 78 78 190 142 34 226 170 11
40026 -239 182 13 246 190 14 246 190 14 246 190 14
40027 -246 190 14 246 190 14 246 190 14 246 190 14
40028 -246 190 14 246 190 14 246 190 14 246 190 14
40029 -246 190 14 241 196 14 203 166 17 22 18 6
40030 - 2 2 6 2 2 6 2 2 6 38 38 38
40031 -218 218 218 253 253 253 253 253 253 253 253 253
40032 -253 253 253 253 253 253 253 253 253 253 253 253
40033 -253 253 253 253 253 253 253 253 253 253 253 253
40034 -253 253 253 253 253 253 253 253 253 253 253 253
40035 -250 250 250 206 206 206 198 198 198 202 162 69
40036 -226 170 11 236 178 12 224 166 10 210 150 10
40037 -200 144 11 197 138 11 192 133 9 197 138 11
40038 -210 150 10 226 170 11 242 186 14 246 190 14
40039 -246 190 14 246 186 14 225 175 15 124 112 88
40040 - 62 62 62 30 30 30 14 14 14 6 6 6
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 10 10 10
40045 - 30 30 30 78 78 78 174 135 50 224 166 10
40046 -239 182 13 246 190 14 246 190 14 246 190 14
40047 -246 190 14 246 190 14 246 190 14 246 190 14
40048 -246 190 14 246 190 14 246 190 14 246 190 14
40049 -246 190 14 246 190 14 241 196 14 139 102 15
40050 - 2 2 6 2 2 6 2 2 6 2 2 6
40051 - 78 78 78 250 250 250 253 253 253 253 253 253
40052 -253 253 253 253 253 253 253 253 253 253 253 253
40053 -253 253 253 253 253 253 253 253 253 253 253 253
40054 -253 253 253 253 253 253 253 253 253 253 253 253
40055 -250 250 250 214 214 214 198 198 198 190 150 46
40056 -219 162 10 236 178 12 234 174 13 224 166 10
40057 -216 158 10 213 154 11 213 154 11 216 158 10
40058 -226 170 11 239 182 13 246 190 14 246 190 14
40059 -246 190 14 246 190 14 242 186 14 206 162 42
40060 -101 101 101 58 58 58 30 30 30 14 14 14
40061 - 6 6 6 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 10 10 10
40065 - 30 30 30 74 74 74 174 135 50 216 158 10
40066 -236 178 12 246 190 14 246 190 14 246 190 14
40067 -246 190 14 246 190 14 246 190 14 246 190 14
40068 -246 190 14 246 190 14 246 190 14 246 190 14
40069 -246 190 14 246 190 14 241 196 14 226 184 13
40070 - 61 42 6 2 2 6 2 2 6 2 2 6
40071 - 22 22 22 238 238 238 253 253 253 253 253 253
40072 -253 253 253 253 253 253 253 253 253 253 253 253
40073 -253 253 253 253 253 253 253 253 253 253 253 253
40074 -253 253 253 253 253 253 253 253 253 253 253 253
40075 -253 253 253 226 226 226 187 187 187 180 133 36
40076 -216 158 10 236 178 12 239 182 13 236 178 12
40077 -230 174 11 226 170 11 226 170 11 230 174 11
40078 -236 178 12 242 186 14 246 190 14 246 190 14
40079 -246 190 14 246 190 14 246 186 14 239 182 13
40080 -206 162 42 106 106 106 66 66 66 34 34 34
40081 - 14 14 14 6 6 6 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 6 6 6
40085 - 26 26 26 70 70 70 163 133 67 213 154 11
40086 -236 178 12 246 190 14 246 190 14 246 190 14
40087 -246 190 14 246 190 14 246 190 14 246 190 14
40088 -246 190 14 246 190 14 246 190 14 246 190 14
40089 -246 190 14 246 190 14 246 190 14 241 196 14
40090 -190 146 13 18 14 6 2 2 6 2 2 6
40091 - 46 46 46 246 246 246 253 253 253 253 253 253
40092 -253 253 253 253 253 253 253 253 253 253 253 253
40093 -253 253 253 253 253 253 253 253 253 253 253 253
40094 -253 253 253 253 253 253 253 253 253 253 253 253
40095 -253 253 253 221 221 221 86 86 86 156 107 11
40096 -216 158 10 236 178 12 242 186 14 246 186 14
40097 -242 186 14 239 182 13 239 182 13 242 186 14
40098 -242 186 14 246 186 14 246 190 14 246 190 14
40099 -246 190 14 246 190 14 246 190 14 246 190 14
40100 -242 186 14 225 175 15 142 122 72 66 66 66
40101 - 30 30 30 10 10 10 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 6 6 6
40105 - 26 26 26 70 70 70 163 133 67 210 150 10
40106 -236 178 12 246 190 14 246 190 14 246 190 14
40107 -246 190 14 246 190 14 246 190 14 246 190 14
40108 -246 190 14 246 190 14 246 190 14 246 190 14
40109 -246 190 14 246 190 14 246 190 14 246 190 14
40110 -232 195 16 121 92 8 34 34 34 106 106 106
40111 -221 221 221 253 253 253 253 253 253 253 253 253
40112 -253 253 253 253 253 253 253 253 253 253 253 253
40113 -253 253 253 253 253 253 253 253 253 253 253 253
40114 -253 253 253 253 253 253 253 253 253 253 253 253
40115 -242 242 242 82 82 82 18 14 6 163 110 8
40116 -216 158 10 236 178 12 242 186 14 246 190 14
40117 -246 190 14 246 190 14 246 190 14 246 190 14
40118 -246 190 14 246 190 14 246 190 14 246 190 14
40119 -246 190 14 246 190 14 246 190 14 246 190 14
40120 -246 190 14 246 190 14 242 186 14 163 133 67
40121 - 46 46 46 18 18 18 6 6 6 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 10 10 10
40125 - 30 30 30 78 78 78 163 133 67 210 150 10
40126 -236 178 12 246 186 14 246 190 14 246 190 14
40127 -246 190 14 246 190 14 246 190 14 246 190 14
40128 -246 190 14 246 190 14 246 190 14 246 190 14
40129 -246 190 14 246 190 14 246 190 14 246 190 14
40130 -241 196 14 215 174 15 190 178 144 253 253 253
40131 -253 253 253 253 253 253 253 253 253 253 253 253
40132 -253 253 253 253 253 253 253 253 253 253 253 253
40133 -253 253 253 253 253 253 253 253 253 253 253 253
40134 -253 253 253 253 253 253 253 253 253 218 218 218
40135 - 58 58 58 2 2 6 22 18 6 167 114 7
40136 -216 158 10 236 178 12 246 186 14 246 190 14
40137 -246 190 14 246 190 14 246 190 14 246 190 14
40138 -246 190 14 246 190 14 246 190 14 246 190 14
40139 -246 190 14 246 190 14 246 190 14 246 190 14
40140 -246 190 14 246 186 14 242 186 14 190 150 46
40141 - 54 54 54 22 22 22 6 6 6 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 14 14 14
40145 - 38 38 38 86 86 86 180 133 36 213 154 11
40146 -236 178 12 246 186 14 246 190 14 246 190 14
40147 -246 190 14 246 190 14 246 190 14 246 190 14
40148 -246 190 14 246 190 14 246 190 14 246 190 14
40149 -246 190 14 246 190 14 246 190 14 246 190 14
40150 -246 190 14 232 195 16 190 146 13 214 214 214
40151 -253 253 253 253 253 253 253 253 253 253 253 253
40152 -253 253 253 253 253 253 253 253 253 253 253 253
40153 -253 253 253 253 253 253 253 253 253 253 253 253
40154 -253 253 253 250 250 250 170 170 170 26 26 26
40155 - 2 2 6 2 2 6 37 26 9 163 110 8
40156 -219 162 10 239 182 13 246 186 14 246 190 14
40157 -246 190 14 246 190 14 246 190 14 246 190 14
40158 -246 190 14 246 190 14 246 190 14 246 190 14
40159 -246 190 14 246 190 14 246 190 14 246 190 14
40160 -246 186 14 236 178 12 224 166 10 142 122 72
40161 - 46 46 46 18 18 18 6 6 6 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 6 6 6 18 18 18
40165 - 50 50 50 109 106 95 192 133 9 224 166 10
40166 -242 186 14 246 190 14 246 190 14 246 190 14
40167 -246 190 14 246 190 14 246 190 14 246 190 14
40168 -246 190 14 246 190 14 246 190 14 246 190 14
40169 -246 190 14 246 190 14 246 190 14 246 190 14
40170 -242 186 14 226 184 13 210 162 10 142 110 46
40171 -226 226 226 253 253 253 253 253 253 253 253 253
40172 -253 253 253 253 253 253 253 253 253 253 253 253
40173 -253 253 253 253 253 253 253 253 253 253 253 253
40174 -198 198 198 66 66 66 2 2 6 2 2 6
40175 - 2 2 6 2 2 6 50 34 6 156 107 11
40176 -219 162 10 239 182 13 246 186 14 246 190 14
40177 -246 190 14 246 190 14 246 190 14 246 190 14
40178 -246 190 14 246 190 14 246 190 14 246 190 14
40179 -246 190 14 246 190 14 246 190 14 242 186 14
40180 -234 174 13 213 154 11 154 122 46 66 66 66
40181 - 30 30 30 10 10 10 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 6 6 6 22 22 22
40185 - 58 58 58 154 121 60 206 145 10 234 174 13
40186 -242 186 14 246 186 14 246 190 14 246 190 14
40187 -246 190 14 246 190 14 246 190 14 246 190 14
40188 -246 190 14 246 190 14 246 190 14 246 190 14
40189 -246 190 14 246 190 14 246 190 14 246 190 14
40190 -246 186 14 236 178 12 210 162 10 163 110 8
40191 - 61 42 6 138 138 138 218 218 218 250 250 250
40192 -253 253 253 253 253 253 253 253 253 250 250 250
40193 -242 242 242 210 210 210 144 144 144 66 66 66
40194 - 6 6 6 2 2 6 2 2 6 2 2 6
40195 - 2 2 6 2 2 6 61 42 6 163 110 8
40196 -216 158 10 236 178 12 246 190 14 246 190 14
40197 -246 190 14 246 190 14 246 190 14 246 190 14
40198 -246 190 14 246 190 14 246 190 14 246 190 14
40199 -246 190 14 239 182 13 230 174 11 216 158 10
40200 -190 142 34 124 112 88 70 70 70 38 38 38
40201 - 18 18 18 6 6 6 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 6 6 6 22 22 22
40205 - 62 62 62 168 124 44 206 145 10 224 166 10
40206 -236 178 12 239 182 13 242 186 14 242 186 14
40207 -246 186 14 246 190 14 246 190 14 246 190 14
40208 -246 190 14 246 190 14 246 190 14 246 190 14
40209 -246 190 14 246 190 14 246 190 14 246 190 14
40210 -246 190 14 236 178 12 216 158 10 175 118 6
40211 - 80 54 7 2 2 6 6 6 6 30 30 30
40212 - 54 54 54 62 62 62 50 50 50 38 38 38
40213 - 14 14 14 2 2 6 2 2 6 2 2 6
40214 - 2 2 6 2 2 6 2 2 6 2 2 6
40215 - 2 2 6 6 6 6 80 54 7 167 114 7
40216 -213 154 11 236 178 12 246 190 14 246 190 14
40217 -246 190 14 246 190 14 246 190 14 246 190 14
40218 -246 190 14 242 186 14 239 182 13 239 182 13
40219 -230 174 11 210 150 10 174 135 50 124 112 88
40220 - 82 82 82 54 54 54 34 34 34 18 18 18
40221 - 6 6 6 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 6 6 6 18 18 18
40225 - 50 50 50 158 118 36 192 133 9 200 144 11
40226 -216 158 10 219 162 10 224 166 10 226 170 11
40227 -230 174 11 236 178 12 239 182 13 239 182 13
40228 -242 186 14 246 186 14 246 190 14 246 190 14
40229 -246 190 14 246 190 14 246 190 14 246 190 14
40230 -246 186 14 230 174 11 210 150 10 163 110 8
40231 -104 69 6 10 10 10 2 2 6 2 2 6
40232 - 2 2 6 2 2 6 2 2 6 2 2 6
40233 - 2 2 6 2 2 6 2 2 6 2 2 6
40234 - 2 2 6 2 2 6 2 2 6 2 2 6
40235 - 2 2 6 6 6 6 91 60 6 167 114 7
40236 -206 145 10 230 174 11 242 186 14 246 190 14
40237 -246 190 14 246 190 14 246 186 14 242 186 14
40238 -239 182 13 230 174 11 224 166 10 213 154 11
40239 -180 133 36 124 112 88 86 86 86 58 58 58
40240 - 38 38 38 22 22 22 10 10 10 6 6 6
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 14 14 14
40245 - 34 34 34 70 70 70 138 110 50 158 118 36
40246 -167 114 7 180 123 7 192 133 9 197 138 11
40247 -200 144 11 206 145 10 213 154 11 219 162 10
40248 -224 166 10 230 174 11 239 182 13 242 186 14
40249 -246 186 14 246 186 14 246 186 14 246 186 14
40250 -239 182 13 216 158 10 185 133 11 152 99 6
40251 -104 69 6 18 14 6 2 2 6 2 2 6
40252 - 2 2 6 2 2 6 2 2 6 2 2 6
40253 - 2 2 6 2 2 6 2 2 6 2 2 6
40254 - 2 2 6 2 2 6 2 2 6 2 2 6
40255 - 2 2 6 6 6 6 80 54 7 152 99 6
40256 -192 133 9 219 162 10 236 178 12 239 182 13
40257 -246 186 14 242 186 14 239 182 13 236 178 12
40258 -224 166 10 206 145 10 192 133 9 154 121 60
40259 - 94 94 94 62 62 62 42 42 42 22 22 22
40260 - 14 14 14 6 6 6 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 6 6 6
40265 - 18 18 18 34 34 34 58 58 58 78 78 78
40266 -101 98 89 124 112 88 142 110 46 156 107 11
40267 -163 110 8 167 114 7 175 118 6 180 123 7
40268 -185 133 11 197 138 11 210 150 10 219 162 10
40269 -226 170 11 236 178 12 236 178 12 234 174 13
40270 -219 162 10 197 138 11 163 110 8 130 83 6
40271 - 91 60 6 10 10 10 2 2 6 2 2 6
40272 - 18 18 18 38 38 38 38 38 38 38 38 38
40273 - 38 38 38 38 38 38 38 38 38 38 38 38
40274 - 38 38 38 38 38 38 26 26 26 2 2 6
40275 - 2 2 6 6 6 6 70 47 6 137 92 6
40276 -175 118 6 200 144 11 219 162 10 230 174 11
40277 -234 174 13 230 174 11 219 162 10 210 150 10
40278 -192 133 9 163 110 8 124 112 88 82 82 82
40279 - 50 50 50 30 30 30 14 14 14 6 6 6
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 6 6 6 14 14 14 22 22 22 34 34 34
40286 - 42 42 42 58 58 58 74 74 74 86 86 86
40287 -101 98 89 122 102 70 130 98 46 121 87 25
40288 -137 92 6 152 99 6 163 110 8 180 123 7
40289 -185 133 11 197 138 11 206 145 10 200 144 11
40290 -180 123 7 156 107 11 130 83 6 104 69 6
40291 - 50 34 6 54 54 54 110 110 110 101 98 89
40292 - 86 86 86 82 82 82 78 78 78 78 78 78
40293 - 78 78 78 78 78 78 78 78 78 78 78 78
40294 - 78 78 78 82 82 82 86 86 86 94 94 94
40295 -106 106 106 101 101 101 86 66 34 124 80 6
40296 -156 107 11 180 123 7 192 133 9 200 144 11
40297 -206 145 10 200 144 11 192 133 9 175 118 6
40298 -139 102 15 109 106 95 70 70 70 42 42 42
40299 - 22 22 22 10 10 10 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 6 6 6 10 10 10
40306 - 14 14 14 22 22 22 30 30 30 38 38 38
40307 - 50 50 50 62 62 62 74 74 74 90 90 90
40308 -101 98 89 112 100 78 121 87 25 124 80 6
40309 -137 92 6 152 99 6 152 99 6 152 99 6
40310 -138 86 6 124 80 6 98 70 6 86 66 30
40311 -101 98 89 82 82 82 58 58 58 46 46 46
40312 - 38 38 38 34 34 34 34 34 34 34 34 34
40313 - 34 34 34 34 34 34 34 34 34 34 34 34
40314 - 34 34 34 34 34 34 38 38 38 42 42 42
40315 - 54 54 54 82 82 82 94 86 76 91 60 6
40316 -134 86 6 156 107 11 167 114 7 175 118 6
40317 -175 118 6 167 114 7 152 99 6 121 87 25
40318 -101 98 89 62 62 62 34 34 34 18 18 18
40319 - 6 6 6 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 6 6 6 6 6 6 10 10 10
40327 - 18 18 18 22 22 22 30 30 30 42 42 42
40328 - 50 50 50 66 66 66 86 86 86 101 98 89
40329 -106 86 58 98 70 6 104 69 6 104 69 6
40330 -104 69 6 91 60 6 82 62 34 90 90 90
40331 - 62 62 62 38 38 38 22 22 22 14 14 14
40332 - 10 10 10 10 10 10 10 10 10 10 10 10
40333 - 10 10 10 10 10 10 6 6 6 10 10 10
40334 - 10 10 10 10 10 10 10 10 10 14 14 14
40335 - 22 22 22 42 42 42 70 70 70 89 81 66
40336 - 80 54 7 104 69 6 124 80 6 137 92 6
40337 -134 86 6 116 81 8 100 82 52 86 86 86
40338 - 58 58 58 30 30 30 14 14 14 6 6 6
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 0 0 0 0 0 0 0 0 0 0 0 0
40347 - 0 0 0 6 6 6 10 10 10 14 14 14
40348 - 18 18 18 26 26 26 38 38 38 54 54 54
40349 - 70 70 70 86 86 86 94 86 76 89 81 66
40350 - 89 81 66 86 86 86 74 74 74 50 50 50
40351 - 30 30 30 14 14 14 6 6 6 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 6 6 6 18 18 18 34 34 34 58 58 58
40356 - 82 82 82 89 81 66 89 81 66 89 81 66
40357 - 94 86 66 94 86 76 74 74 74 50 50 50
40358 - 26 26 26 14 14 14 6 6 6 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 0 0 0
40366 - 0 0 0 0 0 0 0 0 0 0 0 0
40367 - 0 0 0 0 0 0 0 0 0 0 0 0
40368 - 6 6 6 6 6 6 14 14 14 18 18 18
40369 - 30 30 30 38 38 38 46 46 46 54 54 54
40370 - 50 50 50 42 42 42 30 30 30 18 18 18
40371 - 10 10 10 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 6 6 6 14 14 14 26 26 26
40376 - 38 38 38 50 50 50 58 58 58 58 58 58
40377 - 54 54 54 42 42 42 30 30 30 18 18 18
40378 - 10 10 10 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 0 0 0
40386 - 0 0 0 0 0 0 0 0 0 0 0 0
40387 - 0 0 0 0 0 0 0 0 0 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 6 6 6
40389 - 6 6 6 10 10 10 14 14 14 18 18 18
40390 - 18 18 18 14 14 14 10 10 10 6 6 6
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 6 6 6
40396 - 14 14 14 18 18 18 22 22 22 22 22 22
40397 - 18 18 18 14 14 14 10 10 10 6 6 6
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40412 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40416 +4 4 4 4 4 4
40417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40426 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40430 +4 4 4 4 4 4
40431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40440 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40444 +4 4 4 4 4 4
40445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40454 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40458 +4 4 4 4 4 4
40459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
40472 +4 4 4 4 4 4
40473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40481 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40486 +4 4 4 4 4 4
40487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40492 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40496 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40497 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40498 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40500 +4 4 4 4 4 4
40501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40506 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40507 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40510 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40511 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40512 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40513 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40514 +4 4 4 4 4 4
40515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40520 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40521 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 0 0 0 4 4 4 41 54 63 125 124 125
40525 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40526 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40527 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40528 +4 4 4 4 4 4
40529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40532 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40533 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40534 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40535 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40537 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40538 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40539 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40540 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40541 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40542 +4 4 4 4 4 4
40543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40546 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40547 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40548 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40549 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40550 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40551 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40552 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40553 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40554 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40555 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40556 +4 4 4 4 4 4
40557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40560 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40561 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40562 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40563 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40564 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40565 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40566 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40567 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40568 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40569 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40570 +4 4 4 4 4 4
40571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40573 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40574 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40575 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40576 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40577 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40578 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40579 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40580 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40581 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40582 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40583 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40584 +4 4 4 4 4 4
40585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40587 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40588 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40589 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40590 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40591 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40592 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40593 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40594 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40595 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40596 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40597 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40598 +4 4 4 4 4 4
40599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40601 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40602 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40603 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40604 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40605 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40606 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40607 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40608 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40609 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40610 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40611 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40612 +4 4 4 4 4 4
40613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40615 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40616 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40617 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40618 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40619 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40620 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40621 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40622 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40623 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40624 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40625 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40626 +4 4 4 4 4 4
40627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40628 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40629 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40630 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40631 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40632 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40633 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40634 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40635 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40636 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40637 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40638 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40639 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40640 +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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40643 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40644 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40645 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40646 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40647 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40648 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40649 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40650 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40651 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40652 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40653 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40654 +0 0 0 4 4 4
40655 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40656 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40657 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40658 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40659 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40660 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40661 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40662 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40663 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40664 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40665 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40666 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40667 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40668 +2 0 0 0 0 0
40669 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40670 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40671 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40672 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40673 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40674 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40675 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40676 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40677 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40678 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40679 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40680 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40681 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40682 +37 38 37 0 0 0
40683 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40684 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40685 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40686 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40687 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40688 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40689 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40690 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40691 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40692 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40693 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40694 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40695 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40696 +85 115 134 4 0 0
40697 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40698 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40699 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40700 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40701 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40702 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40703 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40704 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40705 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40706 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40707 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40708 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40709 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40710 +60 73 81 4 0 0
40711 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40712 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40713 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40714 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40715 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40716 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40717 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40718 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40719 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40720 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40721 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40722 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40723 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40724 +16 19 21 4 0 0
40725 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40726 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40727 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40728 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40729 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40730 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40731 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40732 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40733 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40734 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40735 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40736 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40737 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40738 +4 0 0 4 3 3
40739 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40740 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40741 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40743 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40744 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40745 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40746 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40747 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40748 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40749 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40750 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40751 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40752 +3 2 2 4 4 4
40753 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40754 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40755 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40756 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40757 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40758 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40759 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40760 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40761 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40762 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40763 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40764 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40765 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40766 +4 4 4 4 4 4
40767 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40768 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40769 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40770 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40771 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40772 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40773 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40774 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40775 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40776 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40777 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40778 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40779 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40780 +4 4 4 4 4 4
40781 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40782 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40783 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40784 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40785 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40786 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40787 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40788 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40789 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40790 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40791 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40792 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40793 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40794 +5 5 5 5 5 5
40795 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40796 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40797 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40798 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40799 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40800 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40801 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40802 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40803 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40804 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40805 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40806 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40807 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40808 +5 5 5 4 4 4
40809 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40810 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40811 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40812 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40813 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40814 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40815 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40816 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40817 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40818 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40819 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40820 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822 +4 4 4 4 4 4
40823 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40824 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40825 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40826 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40827 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40828 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40829 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40830 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40831 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40832 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40833 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40834 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836 +4 4 4 4 4 4
40837 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40838 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40839 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40840 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40841 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40842 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40843 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40844 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40845 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40846 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40847 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850 +4 4 4 4 4 4
40851 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40852 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40853 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40854 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40855 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40856 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40857 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40858 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40859 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40860 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40861 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40864 +4 4 4 4 4 4
40865 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40866 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40867 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40868 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40869 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40870 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40871 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40872 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40873 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40874 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40875 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40878 +4 4 4 4 4 4
40879 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40880 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40881 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40882 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40883 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40884 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40885 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40886 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40887 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40888 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40889 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40892 +4 4 4 4 4 4
40893 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40894 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40895 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40896 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40897 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40898 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40899 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40900 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40901 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40902 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40903 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40906 +4 4 4 4 4 4
40907 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40908 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40909 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40910 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40911 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40912 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40913 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40914 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40915 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40916 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40917 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40920 +4 4 4 4 4 4
40921 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40922 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40923 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40924 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40925 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40926 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40927 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40928 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40929 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40930 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40931 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40934 +4 4 4 4 4 4
40935 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40936 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40937 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40938 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40939 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40940 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40941 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40942 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40943 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40944 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40945 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40948 +4 4 4 4 4 4
40949 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40950 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40951 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40952 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40953 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40954 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40955 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40956 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40957 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40958 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40959 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40962 +4 4 4 4 4 4
40963 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40964 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40965 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40966 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40967 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40968 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40969 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40970 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40971 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40972 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40973 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40976 +4 4 4 4 4 4
40977 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40978 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40979 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40980 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40981 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40982 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40983 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40984 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40985 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40986 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40987 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40990 +4 4 4 4 4 4
40991 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40992 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40993 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40994 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40995 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40996 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40997 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40998 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40999 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41000 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41001 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41004 +4 4 4 4 4 4
41005 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41006 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41007 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41008 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41009 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41010 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41011 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41012 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41013 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41014 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41015 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41018 +4 4 4 4 4 4
41019 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41020 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41021 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41022 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41023 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41024 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41025 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41026 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41027 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41028 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41029 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41032 +4 4 4 4 4 4
41033 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41034 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41035 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41036 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41037 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41038 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41039 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41040 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41041 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41042 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41043 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41046 +4 4 4 4 4 4
41047 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41048 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41049 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41050 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41051 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41052 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41053 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41054 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41055 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41056 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41057 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41060 +4 4 4 4 4 4
41061 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41062 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41063 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41064 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41065 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41066 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41067 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41068 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41069 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41070 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41071 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41074 +4 4 4 4 4 4
41075 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41076 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41077 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41078 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41079 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41080 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41081 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41082 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41083 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41084 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41085 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41088 +4 4 4 4 4 4
41089 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41090 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41091 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41092 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41093 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41094 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41095 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41096 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41097 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41098 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41099 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41102 +4 4 4 4 4 4
41103 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41104 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41105 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41106 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41107 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41108 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41109 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41110 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41111 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41112 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41113 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41116 +4 4 4 4 4 4
41117 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41118 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41119 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41120 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41121 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41122 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41123 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41124 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41125 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41126 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41127 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41130 +4 4 4 4 4 4
41131 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41132 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41133 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41134 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41135 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41136 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41137 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41138 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41139 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41140 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41141 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41144 +4 4 4 4 4 4
41145 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41146 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41147 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41148 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41149 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41150 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41151 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41152 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41153 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41154 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41155 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158 +4 4 4 4 4 4
41159 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41160 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41161 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41162 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41163 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41164 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41165 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41166 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41167 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41168 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41169 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172 +4 4 4 4 4 4
41173 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41174 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41175 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41176 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41177 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41178 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41179 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41180 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41181 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41182 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41183 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4
41187 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41188 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41189 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41190 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41191 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41192 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41193 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41194 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41195 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41196 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41197 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4
41201 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41202 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41203 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41204 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41205 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41206 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41207 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41208 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41209 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41210 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41211 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4
41215 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41216 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41217 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41218 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41219 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41220 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41221 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41222 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41223 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41224 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4
41229 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41230 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41231 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41232 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41233 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41234 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41235 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41236 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41237 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41238 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4
41243 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41244 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41245 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41246 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41247 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41248 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41249 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41250 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41251 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41252 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4
41257 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41258 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41259 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41260 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41261 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41262 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41263 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41264 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41265 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41266 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270 +4 4 4 4 4 4
41271 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41272 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41273 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41274 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41275 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41276 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41277 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41278 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41279 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4
41285 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41286 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41287 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41288 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41289 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41290 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41291 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41292 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41293 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4
41299 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41300 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41301 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41302 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41303 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41304 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41305 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41306 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41307 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4
41313 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41314 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41315 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41316 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41317 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41318 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41319 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41320 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41328 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41329 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41330 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41331 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41332 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41333 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41334 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41342 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41343 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41344 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41345 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41346 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41347 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41348 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41357 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41358 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41359 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41360 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41361 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41362 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41371 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41372 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41373 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41374 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41375 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41376 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4
41383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41386 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41387 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41388 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41389 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41390 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4
41397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41400 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41401 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41402 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41403 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410 +4 4 4 4 4 4
41411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41415 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41416 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41417 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424 +4 4 4 4 4 4
41425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41428 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41429 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41430 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41431 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438 +4 4 4 4 4 4
41439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41442 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41443 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41444 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41445 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452 +4 4 4 4 4 4
41453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41457 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41458 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41459 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466 +4 4 4 4 4 4
41467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41471 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41472 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41473 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41480 +4 4 4 4 4 4
41481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41485 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41486 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41487 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41494 +4 4 4 4 4 4
41495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41499 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41500 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41508 +4 4 4 4 4 4
41509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41513 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41514 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522 +4 4 4 4 4 4
41523 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41524 index a40c05e..785c583 100644
41525 --- a/drivers/video/udlfb.c
41526 +++ b/drivers/video/udlfb.c
41527 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41528 dlfb_urb_completion(urb);
41529
41530 error:
41531 - atomic_add(bytes_sent, &dev->bytes_sent);
41532 - atomic_add(bytes_identical, &dev->bytes_identical);
41533 - atomic_add(width*height*2, &dev->bytes_rendered);
41534 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41535 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41536 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41537 end_cycles = get_cycles();
41538 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41539 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41540 >> 10)), /* Kcycles */
41541 &dev->cpu_kcycles_used);
41542
41543 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41544 dlfb_urb_completion(urb);
41545
41546 error:
41547 - atomic_add(bytes_sent, &dev->bytes_sent);
41548 - atomic_add(bytes_identical, &dev->bytes_identical);
41549 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41550 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41551 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41552 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41553 end_cycles = get_cycles();
41554 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41555 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41556 >> 10)), /* Kcycles */
41557 &dev->cpu_kcycles_used);
41558 }
41559 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41560 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41561 struct dlfb_data *dev = fb_info->par;
41562 return snprintf(buf, PAGE_SIZE, "%u\n",
41563 - atomic_read(&dev->bytes_rendered));
41564 + atomic_read_unchecked(&dev->bytes_rendered));
41565 }
41566
41567 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41568 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41569 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41570 struct dlfb_data *dev = fb_info->par;
41571 return snprintf(buf, PAGE_SIZE, "%u\n",
41572 - atomic_read(&dev->bytes_identical));
41573 + atomic_read_unchecked(&dev->bytes_identical));
41574 }
41575
41576 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41577 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41578 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41579 struct dlfb_data *dev = fb_info->par;
41580 return snprintf(buf, PAGE_SIZE, "%u\n",
41581 - atomic_read(&dev->bytes_sent));
41582 + atomic_read_unchecked(&dev->bytes_sent));
41583 }
41584
41585 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41586 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41587 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41588 struct dlfb_data *dev = fb_info->par;
41589 return snprintf(buf, PAGE_SIZE, "%u\n",
41590 - atomic_read(&dev->cpu_kcycles_used));
41591 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41592 }
41593
41594 static ssize_t edid_show(
41595 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41596 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41597 struct dlfb_data *dev = fb_info->par;
41598
41599 - atomic_set(&dev->bytes_rendered, 0);
41600 - atomic_set(&dev->bytes_identical, 0);
41601 - atomic_set(&dev->bytes_sent, 0);
41602 - atomic_set(&dev->cpu_kcycles_used, 0);
41603 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41604 + atomic_set_unchecked(&dev->bytes_identical, 0);
41605 + atomic_set_unchecked(&dev->bytes_sent, 0);
41606 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41607
41608 return count;
41609 }
41610 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41611 index 8408543..1d87895 100644
41612 --- a/drivers/video/uvesafb.c
41613 +++ b/drivers/video/uvesafb.c
41614 @@ -19,6 +19,7 @@
41615 #include <linux/io.h>
41616 #include <linux/mutex.h>
41617 #include <linux/slab.h>
41618 +#include <linux/moduleloader.h>
41619 #include <video/edid.h>
41620 #include <video/uvesafb.h>
41621 #ifdef CONFIG_X86
41622 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41623 NULL,
41624 };
41625
41626 - return call_usermodehelper(v86d_path, argv, envp, 1);
41627 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41628 }
41629
41630 /*
41631 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41632 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41633 par->pmi_setpal = par->ypan = 0;
41634 } else {
41635 +
41636 +#ifdef CONFIG_PAX_KERNEXEC
41637 +#ifdef CONFIG_MODULES
41638 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41639 +#endif
41640 + if (!par->pmi_code) {
41641 + par->pmi_setpal = par->ypan = 0;
41642 + return 0;
41643 + }
41644 +#endif
41645 +
41646 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41647 + task->t.regs.edi);
41648 +
41649 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41650 + pax_open_kernel();
41651 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41652 + pax_close_kernel();
41653 +
41654 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41655 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41656 +#else
41657 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41658 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41659 +#endif
41660 +
41661 printk(KERN_INFO "uvesafb: protected mode interface info at "
41662 "%04x:%04x\n",
41663 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41664 @@ -1828,6 +1851,11 @@ out:
41665 if (par->vbe_modes)
41666 kfree(par->vbe_modes);
41667
41668 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41669 + if (par->pmi_code)
41670 + module_free_exec(NULL, par->pmi_code);
41671 +#endif
41672 +
41673 framebuffer_release(info);
41674 return err;
41675 }
41676 @@ -1854,6 +1882,12 @@ static int uvesafb_remove(struct platform_device *dev)
41677 kfree(par->vbe_state_orig);
41678 if (par->vbe_state_saved)
41679 kfree(par->vbe_state_saved);
41680 +
41681 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41682 + if (par->pmi_code)
41683 + module_free_exec(NULL, par->pmi_code);
41684 +#endif
41685 +
41686 }
41687
41688 framebuffer_release(info);
41689 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41690 index 501b340..86bd4cf 100644
41691 --- a/drivers/video/vesafb.c
41692 +++ b/drivers/video/vesafb.c
41693 @@ -9,6 +9,7 @@
41694 */
41695
41696 #include <linux/module.h>
41697 +#include <linux/moduleloader.h>
41698 #include <linux/kernel.h>
41699 #include <linux/errno.h>
41700 #include <linux/string.h>
41701 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41702 static int vram_total __initdata; /* Set total amount of memory */
41703 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41704 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41705 -static void (*pmi_start)(void) __read_mostly;
41706 -static void (*pmi_pal) (void) __read_mostly;
41707 +static void (*pmi_start)(void) __read_only;
41708 +static void (*pmi_pal) (void) __read_only;
41709 static int depth __read_mostly;
41710 static int vga_compat __read_mostly;
41711 /* --------------------------------------------------------------------- */
41712 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41713 unsigned int size_vmode;
41714 unsigned int size_remap;
41715 unsigned int size_total;
41716 + void *pmi_code = NULL;
41717
41718 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41719 return -ENODEV;
41720 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41721 size_remap = size_total;
41722 vesafb_fix.smem_len = size_remap;
41723
41724 -#ifndef __i386__
41725 - screen_info.vesapm_seg = 0;
41726 -#endif
41727 -
41728 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41729 printk(KERN_WARNING
41730 "vesafb: cannot reserve video memory at 0x%lx\n",
41731 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41732 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41733 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41734
41735 +#ifdef __i386__
41736 +
41737 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41738 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41739 + if (!pmi_code)
41740 +#elif !defined(CONFIG_PAX_KERNEXEC)
41741 + if (0)
41742 +#endif
41743 +
41744 +#endif
41745 + screen_info.vesapm_seg = 0;
41746 +
41747 if (screen_info.vesapm_seg) {
41748 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41749 - screen_info.vesapm_seg,screen_info.vesapm_off);
41750 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41751 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41752 }
41753
41754 if (screen_info.vesapm_seg < 0xc000)
41755 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41756
41757 if (ypan || pmi_setpal) {
41758 unsigned short *pmi_base;
41759 +
41760 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41761 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41762 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41763 +
41764 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41765 + pax_open_kernel();
41766 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41767 +#else
41768 + pmi_code = pmi_base;
41769 +#endif
41770 +
41771 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41772 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41773 +
41774 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41775 + pmi_start = ktva_ktla(pmi_start);
41776 + pmi_pal = ktva_ktla(pmi_pal);
41777 + pax_close_kernel();
41778 +#endif
41779 +
41780 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41781 if (pmi_base[3]) {
41782 printk(KERN_INFO "vesafb: pmi: ports = ");
41783 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41784 info->node, info->fix.id);
41785 return 0;
41786 err:
41787 +
41788 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41789 + module_free_exec(NULL, pmi_code);
41790 +#endif
41791 +
41792 if (info->screen_base)
41793 iounmap(info->screen_base);
41794 framebuffer_release(info);
41795 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41796 index 88714ae..16c2e11 100644
41797 --- a/drivers/video/via/via_clock.h
41798 +++ b/drivers/video/via/via_clock.h
41799 @@ -56,7 +56,7 @@ struct via_clock {
41800
41801 void (*set_engine_pll_state)(u8 state);
41802 void (*set_engine_pll)(struct via_pll_config config);
41803 -};
41804 +} __no_const;
41805
41806
41807 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41808 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41809 index e56c934..fc22f4b 100644
41810 --- a/drivers/xen/xen-pciback/conf_space.h
41811 +++ b/drivers/xen/xen-pciback/conf_space.h
41812 @@ -44,15 +44,15 @@ struct config_field {
41813 struct {
41814 conf_dword_write write;
41815 conf_dword_read read;
41816 - } dw;
41817 + } __no_const dw;
41818 struct {
41819 conf_word_write write;
41820 conf_word_read read;
41821 - } w;
41822 + } __no_const w;
41823 struct {
41824 conf_byte_write write;
41825 conf_byte_read read;
41826 - } b;
41827 + } __no_const b;
41828 } u;
41829 struct list_head list;
41830 };
41831 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41832 index 014c8dd..6f3dfe6 100644
41833 --- a/fs/9p/vfs_inode.c
41834 +++ b/fs/9p/vfs_inode.c
41835 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41836 void
41837 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41838 {
41839 - char *s = nd_get_link(nd);
41840 + const char *s = nd_get_link(nd);
41841
41842 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41843 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41844 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41845 index e95d1b6..3454244 100644
41846 --- a/fs/Kconfig.binfmt
41847 +++ b/fs/Kconfig.binfmt
41848 @@ -89,7 +89,7 @@ config HAVE_AOUT
41849
41850 config BINFMT_AOUT
41851 tristate "Kernel support for a.out and ECOFF binaries"
41852 - depends on HAVE_AOUT
41853 + depends on HAVE_AOUT && BROKEN
41854 ---help---
41855 A.out (Assembler.OUTput) is a set of formats for libraries and
41856 executables used in the earliest versions of UNIX. Linux used
41857 diff --git a/fs/aio.c b/fs/aio.c
41858 index b9d64d8..86cb1d5 100644
41859 --- a/fs/aio.c
41860 +++ b/fs/aio.c
41861 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41862 size += sizeof(struct io_event) * nr_events;
41863 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41864
41865 - if (nr_pages < 0)
41866 + if (nr_pages <= 0)
41867 return -EINVAL;
41868
41869 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41870 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41871 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41872 {
41873 ssize_t ret;
41874 + struct iovec iovstack;
41875
41876 #ifdef CONFIG_COMPAT
41877 if (compat)
41878 ret = compat_rw_copy_check_uvector(type,
41879 (struct compat_iovec __user *)kiocb->ki_buf,
41880 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41881 + kiocb->ki_nbytes, 1, &iovstack,
41882 &kiocb->ki_iovec, 1);
41883 else
41884 #endif
41885 ret = rw_copy_check_uvector(type,
41886 (struct iovec __user *)kiocb->ki_buf,
41887 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41888 + kiocb->ki_nbytes, 1, &iovstack,
41889 &kiocb->ki_iovec, 1);
41890 if (ret < 0)
41891 goto out;
41892
41893 + if (kiocb->ki_iovec == &iovstack) {
41894 + kiocb->ki_inline_vec = iovstack;
41895 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41896 + }
41897 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41898 kiocb->ki_cur_seg = 0;
41899 /* ki_nbytes/left now reflect bytes instead of segs */
41900 diff --git a/fs/attr.c b/fs/attr.c
41901 index 95053ad..2cc93ca 100644
41902 --- a/fs/attr.c
41903 +++ b/fs/attr.c
41904 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41905 unsigned long limit;
41906
41907 limit = rlimit(RLIMIT_FSIZE);
41908 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41909 if (limit != RLIM_INFINITY && offset > limit)
41910 goto out_sig;
41911 if (offset > inode->i_sb->s_maxbytes)
41912 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41913 index 9c098db..c755da5 100644
41914 --- a/fs/autofs4/waitq.c
41915 +++ b/fs/autofs4/waitq.c
41916 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41917 {
41918 unsigned long sigpipe, flags;
41919 mm_segment_t fs;
41920 - const char *data = (const char *)addr;
41921 + const char __user *data = (const char __force_user *)addr;
41922 ssize_t wr = 0;
41923
41924 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41925 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41926 index 6e6d536..457113a 100644
41927 --- a/fs/befs/linuxvfs.c
41928 +++ b/fs/befs/linuxvfs.c
41929 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41930 {
41931 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41932 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41933 - char *link = nd_get_link(nd);
41934 + const char *link = nd_get_link(nd);
41935 if (!IS_ERR(link))
41936 kfree(link);
41937 }
41938 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41939 index 1ff9405..f1e376a 100644
41940 --- a/fs/binfmt_aout.c
41941 +++ b/fs/binfmt_aout.c
41942 @@ -16,6 +16,7 @@
41943 #include <linux/string.h>
41944 #include <linux/fs.h>
41945 #include <linux/file.h>
41946 +#include <linux/security.h>
41947 #include <linux/stat.h>
41948 #include <linux/fcntl.h>
41949 #include <linux/ptrace.h>
41950 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41951 #endif
41952 # define START_STACK(u) ((void __user *)u.start_stack)
41953
41954 + memset(&dump, 0, sizeof(dump));
41955 +
41956 fs = get_fs();
41957 set_fs(KERNEL_DS);
41958 has_dumped = 1;
41959 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41960
41961 /* If the size of the dump file exceeds the rlimit, then see what would happen
41962 if we wrote the stack, but not the data area. */
41963 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41964 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41965 dump.u_dsize = 0;
41966
41967 /* Make sure we have enough room to write the stack and data areas. */
41968 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41969 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41970 dump.u_ssize = 0;
41971
41972 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41973 rlim = rlimit(RLIMIT_DATA);
41974 if (rlim >= RLIM_INFINITY)
41975 rlim = ~0;
41976 +
41977 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41978 if (ex.a_data + ex.a_bss > rlim)
41979 return -ENOMEM;
41980
41981 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41982 install_exec_creds(bprm);
41983 current->flags &= ~PF_FORKNOEXEC;
41984
41985 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41986 + current->mm->pax_flags = 0UL;
41987 +#endif
41988 +
41989 +#ifdef CONFIG_PAX_PAGEEXEC
41990 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41991 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41992 +
41993 +#ifdef CONFIG_PAX_EMUTRAMP
41994 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41995 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41996 +#endif
41997 +
41998 +#ifdef CONFIG_PAX_MPROTECT
41999 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42000 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42001 +#endif
42002 +
42003 + }
42004 +#endif
42005 +
42006 if (N_MAGIC(ex) == OMAGIC) {
42007 unsigned long text_addr, map_size;
42008 loff_t pos;
42009 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42010
42011 down_write(&current->mm->mmap_sem);
42012 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42013 - PROT_READ | PROT_WRITE | PROT_EXEC,
42014 + PROT_READ | PROT_WRITE,
42015 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42016 fd_offset + ex.a_text);
42017 up_write(&current->mm->mmap_sem);
42018 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42019 index 07d096c..851a18b 100644
42020 --- a/fs/binfmt_elf.c
42021 +++ b/fs/binfmt_elf.c
42022 @@ -32,6 +32,7 @@
42023 #include <linux/elf.h>
42024 #include <linux/utsname.h>
42025 #include <linux/coredump.h>
42026 +#include <linux/xattr.h>
42027 #include <asm/uaccess.h>
42028 #include <asm/param.h>
42029 #include <asm/page.h>
42030 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42031 #define elf_core_dump NULL
42032 #endif
42033
42034 +#ifdef CONFIG_PAX_MPROTECT
42035 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42036 +#endif
42037 +
42038 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42039 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42040 #else
42041 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42042 .load_binary = load_elf_binary,
42043 .load_shlib = load_elf_library,
42044 .core_dump = elf_core_dump,
42045 +
42046 +#ifdef CONFIG_PAX_MPROTECT
42047 + .handle_mprotect= elf_handle_mprotect,
42048 +#endif
42049 +
42050 .min_coredump = ELF_EXEC_PAGESIZE,
42051 };
42052
42053 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42054
42055 static int set_brk(unsigned long start, unsigned long end)
42056 {
42057 + unsigned long e = end;
42058 +
42059 start = ELF_PAGEALIGN(start);
42060 end = ELF_PAGEALIGN(end);
42061 if (end > start) {
42062 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42063 if (BAD_ADDR(addr))
42064 return addr;
42065 }
42066 - current->mm->start_brk = current->mm->brk = end;
42067 + current->mm->start_brk = current->mm->brk = e;
42068 return 0;
42069 }
42070
42071 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42072 elf_addr_t __user *u_rand_bytes;
42073 const char *k_platform = ELF_PLATFORM;
42074 const char *k_base_platform = ELF_BASE_PLATFORM;
42075 - unsigned char k_rand_bytes[16];
42076 + u32 k_rand_bytes[4];
42077 int items;
42078 elf_addr_t *elf_info;
42079 int ei_index = 0;
42080 const struct cred *cred = current_cred();
42081 struct vm_area_struct *vma;
42082 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42083
42084 /*
42085 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42086 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42087 * Generate 16 random bytes for userspace PRNG seeding.
42088 */
42089 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42090 - u_rand_bytes = (elf_addr_t __user *)
42091 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42092 + srandom32(k_rand_bytes[0] ^ random32());
42093 + srandom32(k_rand_bytes[1] ^ random32());
42094 + srandom32(k_rand_bytes[2] ^ random32());
42095 + srandom32(k_rand_bytes[3] ^ random32());
42096 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42097 + u_rand_bytes = (elf_addr_t __user *) p;
42098 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42099 return -EFAULT;
42100
42101 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42102 return -EFAULT;
42103 current->mm->env_end = p;
42104
42105 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42106 +
42107 /* Put the elf_info on the stack in the right place. */
42108 sp = (elf_addr_t __user *)envp + 1;
42109 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42110 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42111 return -EFAULT;
42112 return 0;
42113 }
42114 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42115 {
42116 struct elf_phdr *elf_phdata;
42117 struct elf_phdr *eppnt;
42118 - unsigned long load_addr = 0;
42119 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42120 int load_addr_set = 0;
42121 unsigned long last_bss = 0, elf_bss = 0;
42122 - unsigned long error = ~0UL;
42123 + unsigned long error = -EINVAL;
42124 unsigned long total_size;
42125 int retval, i, size;
42126
42127 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42128 goto out_close;
42129 }
42130
42131 +#ifdef CONFIG_PAX_SEGMEXEC
42132 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42133 + pax_task_size = SEGMEXEC_TASK_SIZE;
42134 +#endif
42135 +
42136 eppnt = elf_phdata;
42137 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42138 if (eppnt->p_type == PT_LOAD) {
42139 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42140 k = load_addr + eppnt->p_vaddr;
42141 if (BAD_ADDR(k) ||
42142 eppnt->p_filesz > eppnt->p_memsz ||
42143 - eppnt->p_memsz > TASK_SIZE ||
42144 - TASK_SIZE - eppnt->p_memsz < k) {
42145 + eppnt->p_memsz > pax_task_size ||
42146 + pax_task_size - eppnt->p_memsz < k) {
42147 error = -ENOMEM;
42148 goto out_close;
42149 }
42150 @@ -528,6 +552,351 @@ out:
42151 return error;
42152 }
42153
42154 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42155 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42156 +{
42157 + unsigned long pax_flags = 0UL;
42158 +
42159 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42160 +
42161 +#ifdef CONFIG_PAX_PAGEEXEC
42162 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42163 + pax_flags |= MF_PAX_PAGEEXEC;
42164 +#endif
42165 +
42166 +#ifdef CONFIG_PAX_SEGMEXEC
42167 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42168 + pax_flags |= MF_PAX_SEGMEXEC;
42169 +#endif
42170 +
42171 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42172 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42173 + if ((__supported_pte_mask & _PAGE_NX))
42174 + pax_flags &= ~MF_PAX_SEGMEXEC;
42175 + else
42176 + pax_flags &= ~MF_PAX_PAGEEXEC;
42177 + }
42178 +#endif
42179 +
42180 +#ifdef CONFIG_PAX_EMUTRAMP
42181 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42182 + pax_flags |= MF_PAX_EMUTRAMP;
42183 +#endif
42184 +
42185 +#ifdef CONFIG_PAX_MPROTECT
42186 + if (elf_phdata->p_flags & PF_MPROTECT)
42187 + pax_flags |= MF_PAX_MPROTECT;
42188 +#endif
42189 +
42190 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42191 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42192 + pax_flags |= MF_PAX_RANDMMAP;
42193 +#endif
42194 +
42195 +#endif
42196 +
42197 + return pax_flags;
42198 +}
42199 +
42200 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42201 +{
42202 + unsigned long pax_flags = 0UL;
42203 +
42204 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42205 +
42206 +#ifdef CONFIG_PAX_PAGEEXEC
42207 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42208 + pax_flags |= MF_PAX_PAGEEXEC;
42209 +#endif
42210 +
42211 +#ifdef CONFIG_PAX_SEGMEXEC
42212 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42213 + pax_flags |= MF_PAX_SEGMEXEC;
42214 +#endif
42215 +
42216 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42217 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42218 + if ((__supported_pte_mask & _PAGE_NX))
42219 + pax_flags &= ~MF_PAX_SEGMEXEC;
42220 + else
42221 + pax_flags &= ~MF_PAX_PAGEEXEC;
42222 + }
42223 +#endif
42224 +
42225 +#ifdef CONFIG_PAX_EMUTRAMP
42226 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42227 + pax_flags |= MF_PAX_EMUTRAMP;
42228 +#endif
42229 +
42230 +#ifdef CONFIG_PAX_MPROTECT
42231 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42232 + pax_flags |= MF_PAX_MPROTECT;
42233 +#endif
42234 +
42235 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42236 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42237 + pax_flags |= MF_PAX_RANDMMAP;
42238 +#endif
42239 +
42240 +#endif
42241 +
42242 + return pax_flags;
42243 +}
42244 +
42245 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42246 +{
42247 + unsigned long pax_flags = 0UL;
42248 +
42249 +#ifdef CONFIG_PAX_EI_PAX
42250 +
42251 +#ifdef CONFIG_PAX_PAGEEXEC
42252 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42253 + pax_flags |= MF_PAX_PAGEEXEC;
42254 +#endif
42255 +
42256 +#ifdef CONFIG_PAX_SEGMEXEC
42257 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42258 + pax_flags |= MF_PAX_SEGMEXEC;
42259 +#endif
42260 +
42261 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42262 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42263 + if ((__supported_pte_mask & _PAGE_NX))
42264 + pax_flags &= ~MF_PAX_SEGMEXEC;
42265 + else
42266 + pax_flags &= ~MF_PAX_PAGEEXEC;
42267 + }
42268 +#endif
42269 +
42270 +#ifdef CONFIG_PAX_EMUTRAMP
42271 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42272 + pax_flags |= MF_PAX_EMUTRAMP;
42273 +#endif
42274 +
42275 +#ifdef CONFIG_PAX_MPROTECT
42276 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42277 + pax_flags |= MF_PAX_MPROTECT;
42278 +#endif
42279 +
42280 +#ifdef CONFIG_PAX_ASLR
42281 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42282 + pax_flags |= MF_PAX_RANDMMAP;
42283 +#endif
42284 +
42285 +#else
42286 +
42287 +#ifdef CONFIG_PAX_PAGEEXEC
42288 + pax_flags |= MF_PAX_PAGEEXEC;
42289 +#endif
42290 +
42291 +#ifdef CONFIG_PAX_MPROTECT
42292 + pax_flags |= MF_PAX_MPROTECT;
42293 +#endif
42294 +
42295 +#ifdef CONFIG_PAX_RANDMMAP
42296 + pax_flags |= MF_PAX_RANDMMAP;
42297 +#endif
42298 +
42299 +#ifdef CONFIG_PAX_SEGMEXEC
42300 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42301 + pax_flags &= ~MF_PAX_PAGEEXEC;
42302 + pax_flags |= MF_PAX_SEGMEXEC;
42303 + }
42304 +#endif
42305 +
42306 +#endif
42307 +
42308 + return pax_flags;
42309 +}
42310 +
42311 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42312 +{
42313 +
42314 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42315 + unsigned long i;
42316 +
42317 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42318 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42319 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42320 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42321 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42322 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42323 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42324 + return ~0UL;
42325 +
42326 +#ifdef CONFIG_PAX_SOFTMODE
42327 + if (pax_softmode)
42328 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42329 + else
42330 +#endif
42331 +
42332 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42333 + break;
42334 + }
42335 +#endif
42336 +
42337 + return ~0UL;
42338 +}
42339 +
42340 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42341 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42342 +{
42343 + unsigned long pax_flags = 0UL;
42344 +
42345 +#ifdef CONFIG_PAX_PAGEEXEC
42346 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42347 + pax_flags |= MF_PAX_PAGEEXEC;
42348 +#endif
42349 +
42350 +#ifdef CONFIG_PAX_SEGMEXEC
42351 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42352 + pax_flags |= MF_PAX_SEGMEXEC;
42353 +#endif
42354 +
42355 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42356 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42357 + if ((__supported_pte_mask & _PAGE_NX))
42358 + pax_flags &= ~MF_PAX_SEGMEXEC;
42359 + else
42360 + pax_flags &= ~MF_PAX_PAGEEXEC;
42361 + }
42362 +#endif
42363 +
42364 +#ifdef CONFIG_PAX_EMUTRAMP
42365 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42366 + pax_flags |= MF_PAX_EMUTRAMP;
42367 +#endif
42368 +
42369 +#ifdef CONFIG_PAX_MPROTECT
42370 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42371 + pax_flags |= MF_PAX_MPROTECT;
42372 +#endif
42373 +
42374 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42375 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42376 + pax_flags |= MF_PAX_RANDMMAP;
42377 +#endif
42378 +
42379 + return pax_flags;
42380 +}
42381 +
42382 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42383 +{
42384 + unsigned long pax_flags = 0UL;
42385 +
42386 +#ifdef CONFIG_PAX_PAGEEXEC
42387 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42388 + pax_flags |= MF_PAX_PAGEEXEC;
42389 +#endif
42390 +
42391 +#ifdef CONFIG_PAX_SEGMEXEC
42392 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42393 + pax_flags |= MF_PAX_SEGMEXEC;
42394 +#endif
42395 +
42396 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42397 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42398 + if ((__supported_pte_mask & _PAGE_NX))
42399 + pax_flags &= ~MF_PAX_SEGMEXEC;
42400 + else
42401 + pax_flags &= ~MF_PAX_PAGEEXEC;
42402 + }
42403 +#endif
42404 +
42405 +#ifdef CONFIG_PAX_EMUTRAMP
42406 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42407 + pax_flags |= MF_PAX_EMUTRAMP;
42408 +#endif
42409 +
42410 +#ifdef CONFIG_PAX_MPROTECT
42411 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42412 + pax_flags |= MF_PAX_MPROTECT;
42413 +#endif
42414 +
42415 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42416 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42417 + pax_flags |= MF_PAX_RANDMMAP;
42418 +#endif
42419 +
42420 + return pax_flags;
42421 +}
42422 +#endif
42423 +
42424 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42425 +{
42426 +
42427 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42428 + ssize_t xattr_size, i;
42429 + unsigned char xattr_value[5];
42430 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42431 +
42432 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42433 + if (xattr_size <= 0)
42434 + return ~0UL;
42435 +
42436 + for (i = 0; i < xattr_size; i++)
42437 + switch (xattr_value[i]) {
42438 + default:
42439 + return ~0UL;
42440 +
42441 +#define parse_flag(option1, option2, flag) \
42442 + case option1: \
42443 + pax_flags_hardmode |= MF_PAX_##flag; \
42444 + break; \
42445 + case option2: \
42446 + pax_flags_softmode |= MF_PAX_##flag; \
42447 + break;
42448 +
42449 + parse_flag('p', 'P', PAGEEXEC);
42450 + parse_flag('e', 'E', EMUTRAMP);
42451 + parse_flag('m', 'M', MPROTECT);
42452 + parse_flag('r', 'R', RANDMMAP);
42453 + parse_flag('s', 'S', SEGMEXEC);
42454 +
42455 +#undef parse_flag
42456 + }
42457 +
42458 + if (pax_flags_hardmode & pax_flags_softmode)
42459 + return ~0UL;
42460 +
42461 +#ifdef CONFIG_PAX_SOFTMODE
42462 + if (pax_softmode)
42463 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42464 + else
42465 +#endif
42466 +
42467 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42468 +#else
42469 + return ~0UL;
42470 +#endif
42471 +
42472 +}
42473 +
42474 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42475 +{
42476 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42477 +
42478 + pax_flags = pax_parse_ei_pax(elf_ex);
42479 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42480 + xattr_pax_flags = pax_parse_xattr_pax(file);
42481 +
42482 + if (pt_pax_flags == ~0UL)
42483 + pt_pax_flags = xattr_pax_flags;
42484 + else if (xattr_pax_flags == ~0UL)
42485 + xattr_pax_flags = pt_pax_flags;
42486 + if (pt_pax_flags != xattr_pax_flags)
42487 + return -EINVAL;
42488 + if (pt_pax_flags != ~0UL)
42489 + pax_flags = pt_pax_flags;
42490 +
42491 + if (0 > pax_check_flags(&pax_flags))
42492 + return -EINVAL;
42493 +
42494 + current->mm->pax_flags = pax_flags;
42495 + return 0;
42496 +}
42497 +#endif
42498 +
42499 /*
42500 * These are the functions used to load ELF style executables and shared
42501 * libraries. There is no binary dependent code anywhere else.
42502 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42503 {
42504 unsigned int random_variable = 0;
42505
42506 +#ifdef CONFIG_PAX_RANDUSTACK
42507 + if (randomize_va_space)
42508 + return stack_top - current->mm->delta_stack;
42509 +#endif
42510 +
42511 if ((current->flags & PF_RANDOMIZE) &&
42512 !(current->personality & ADDR_NO_RANDOMIZE)) {
42513 random_variable = get_random_int() & STACK_RND_MASK;
42514 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42515 unsigned long load_addr = 0, load_bias = 0;
42516 int load_addr_set = 0;
42517 char * elf_interpreter = NULL;
42518 - unsigned long error;
42519 + unsigned long error = 0;
42520 struct elf_phdr *elf_ppnt, *elf_phdata;
42521 unsigned long elf_bss, elf_brk;
42522 int retval, i;
42523 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42524 unsigned long start_code, end_code, start_data, end_data;
42525 unsigned long reloc_func_desc __maybe_unused = 0;
42526 int executable_stack = EXSTACK_DEFAULT;
42527 - unsigned long def_flags = 0;
42528 struct {
42529 struct elfhdr elf_ex;
42530 struct elfhdr interp_elf_ex;
42531 } *loc;
42532 + unsigned long pax_task_size = TASK_SIZE;
42533
42534 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42535 if (!loc) {
42536 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42537
42538 /* OK, This is the point of no return */
42539 current->flags &= ~PF_FORKNOEXEC;
42540 - current->mm->def_flags = def_flags;
42541 +
42542 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42543 + current->mm->pax_flags = 0UL;
42544 +#endif
42545 +
42546 +#ifdef CONFIG_PAX_DLRESOLVE
42547 + current->mm->call_dl_resolve = 0UL;
42548 +#endif
42549 +
42550 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42551 + current->mm->call_syscall = 0UL;
42552 +#endif
42553 +
42554 +#ifdef CONFIG_PAX_ASLR
42555 + current->mm->delta_mmap = 0UL;
42556 + current->mm->delta_stack = 0UL;
42557 +#endif
42558 +
42559 + current->mm->def_flags = 0;
42560 +
42561 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42562 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42563 + send_sig(SIGKILL, current, 0);
42564 + goto out_free_dentry;
42565 + }
42566 +#endif
42567 +
42568 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42569 + pax_set_initial_flags(bprm);
42570 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42571 + if (pax_set_initial_flags_func)
42572 + (pax_set_initial_flags_func)(bprm);
42573 +#endif
42574 +
42575 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42576 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42577 + current->mm->context.user_cs_limit = PAGE_SIZE;
42578 + current->mm->def_flags |= VM_PAGEEXEC;
42579 + }
42580 +#endif
42581 +
42582 +#ifdef CONFIG_PAX_SEGMEXEC
42583 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42584 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42585 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42586 + pax_task_size = SEGMEXEC_TASK_SIZE;
42587 + current->mm->def_flags |= VM_NOHUGEPAGE;
42588 + }
42589 +#endif
42590 +
42591 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42592 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42593 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42594 + put_cpu();
42595 + }
42596 +#endif
42597
42598 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42599 may depend on the personality. */
42600 SET_PERSONALITY(loc->elf_ex);
42601 +
42602 +#ifdef CONFIG_PAX_ASLR
42603 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42604 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42605 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42606 + }
42607 +#endif
42608 +
42609 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42610 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42611 + executable_stack = EXSTACK_DISABLE_X;
42612 + current->personality &= ~READ_IMPLIES_EXEC;
42613 + } else
42614 +#endif
42615 +
42616 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42617 current->personality |= READ_IMPLIES_EXEC;
42618
42619 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42620 #else
42621 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42622 #endif
42623 +
42624 +#ifdef CONFIG_PAX_RANDMMAP
42625 + /* PaX: randomize base address at the default exe base if requested */
42626 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42627 +#ifdef CONFIG_SPARC64
42628 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42629 +#else
42630 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42631 +#endif
42632 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42633 + elf_flags |= MAP_FIXED;
42634 + }
42635 +#endif
42636 +
42637 }
42638
42639 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42640 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42641 * allowed task size. Note that p_filesz must always be
42642 * <= p_memsz so it is only necessary to check p_memsz.
42643 */
42644 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42645 - elf_ppnt->p_memsz > TASK_SIZE ||
42646 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42647 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42648 + elf_ppnt->p_memsz > pax_task_size ||
42649 + pax_task_size - elf_ppnt->p_memsz < k) {
42650 /* set_brk can never work. Avoid overflows. */
42651 send_sig(SIGKILL, current, 0);
42652 retval = -EINVAL;
42653 @@ -881,11 +1339,36 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42654 goto out_free_dentry;
42655 }
42656 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42657 - send_sig(SIGSEGV, current, 0);
42658 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42659 - goto out_free_dentry;
42660 + /*
42661 + * This bss-zeroing can fail if the ELF
42662 + * file specifies odd protections. So
42663 + * we don't check the return value
42664 + */
42665 }
42666
42667 +#ifdef CONFIG_PAX_RANDMMAP
42668 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42669 + unsigned long start, size;
42670 +
42671 + start = ELF_PAGEALIGN(elf_brk);
42672 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42673 + down_write(&current->mm->mmap_sem);
42674 + retval = -ENOMEM;
42675 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42676 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42677 + start = do_mmap(NULL, start, size, PROT_NONE, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42678 + retval = IS_ERR_VALUE(start) ? start : 0;
42679 + }
42680 + up_write(&current->mm->mmap_sem);
42681 + if (retval == 0)
42682 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42683 + if (retval < 0) {
42684 + send_sig(SIGKILL, current, 0);
42685 + goto out_free_dentry;
42686 + }
42687 + }
42688 +#endif
42689 +
42690 if (elf_interpreter) {
42691 unsigned long uninitialized_var(interp_map_addr);
42692
42693 @@ -1098,7 +1581,7 @@ out:
42694 * Decide what to dump of a segment, part, all or none.
42695 */
42696 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42697 - unsigned long mm_flags)
42698 + unsigned long mm_flags, long signr)
42699 {
42700 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42701
42702 @@ -1132,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42703 if (vma->vm_file == NULL)
42704 return 0;
42705
42706 - if (FILTER(MAPPED_PRIVATE))
42707 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42708 goto whole;
42709
42710 /*
42711 @@ -1354,9 +1837,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42712 {
42713 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42714 int i = 0;
42715 - do
42716 + do {
42717 i += 2;
42718 - while (auxv[i - 2] != AT_NULL);
42719 + } while (auxv[i - 2] != AT_NULL);
42720 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42721 }
42722
42723 @@ -1862,14 +2345,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42724 }
42725
42726 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42727 - unsigned long mm_flags)
42728 + struct coredump_params *cprm)
42729 {
42730 struct vm_area_struct *vma;
42731 size_t size = 0;
42732
42733 for (vma = first_vma(current, gate_vma); vma != NULL;
42734 vma = next_vma(vma, gate_vma))
42735 - size += vma_dump_size(vma, mm_flags);
42736 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42737 return size;
42738 }
42739
42740 @@ -1963,7 +2446,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42741
42742 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42743
42744 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42745 + offset += elf_core_vma_data_size(gate_vma, cprm);
42746 offset += elf_core_extra_data_size();
42747 e_shoff = offset;
42748
42749 @@ -1977,10 +2460,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42750 offset = dataoff;
42751
42752 size += sizeof(*elf);
42753 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42754 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42755 goto end_coredump;
42756
42757 size += sizeof(*phdr4note);
42758 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42759 if (size > cprm->limit
42760 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42761 goto end_coredump;
42762 @@ -1994,7 +2479,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42763 phdr.p_offset = offset;
42764 phdr.p_vaddr = vma->vm_start;
42765 phdr.p_paddr = 0;
42766 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42767 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42768 phdr.p_memsz = vma->vm_end - vma->vm_start;
42769 offset += phdr.p_filesz;
42770 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42771 @@ -2005,6 +2490,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42772 phdr.p_align = ELF_EXEC_PAGESIZE;
42773
42774 size += sizeof(phdr);
42775 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42776 if (size > cprm->limit
42777 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42778 goto end_coredump;
42779 @@ -2029,7 +2515,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42780 unsigned long addr;
42781 unsigned long end;
42782
42783 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42784 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42785
42786 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42787 struct page *page;
42788 @@ -2038,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42789 page = get_dump_page(addr);
42790 if (page) {
42791 void *kaddr = kmap(page);
42792 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42793 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42794 !dump_write(cprm->file, kaddr,
42795 PAGE_SIZE);
42796 @@ -2055,6 +2542,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42797
42798 if (e_phnum == PN_XNUM) {
42799 size += sizeof(*shdr4extnum);
42800 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42801 if (size > cprm->limit
42802 || !dump_write(cprm->file, shdr4extnum,
42803 sizeof(*shdr4extnum)))
42804 @@ -2075,6 +2563,97 @@ out:
42805
42806 #endif /* CONFIG_ELF_CORE */
42807
42808 +#ifdef CONFIG_PAX_MPROTECT
42809 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42810 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42811 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42812 + *
42813 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42814 + * basis because we want to allow the common case and not the special ones.
42815 + */
42816 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42817 +{
42818 + struct elfhdr elf_h;
42819 + struct elf_phdr elf_p;
42820 + unsigned long i;
42821 + unsigned long oldflags;
42822 + bool is_textrel_rw, is_textrel_rx, is_relro;
42823 +
42824 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42825 + return;
42826 +
42827 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42828 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42829 +
42830 +#ifdef CONFIG_PAX_ELFRELOCS
42831 + /* possible TEXTREL */
42832 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42833 + 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);
42834 +#else
42835 + is_textrel_rw = false;
42836 + is_textrel_rx = false;
42837 +#endif
42838 +
42839 + /* possible RELRO */
42840 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42841 +
42842 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42843 + return;
42844 +
42845 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42846 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42847 +
42848 +#ifdef CONFIG_PAX_ETEXECRELOCS
42849 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42850 +#else
42851 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42852 +#endif
42853 +
42854 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42855 + !elf_check_arch(&elf_h) ||
42856 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42857 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42858 + return;
42859 +
42860 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42861 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42862 + return;
42863 + switch (elf_p.p_type) {
42864 + case PT_DYNAMIC:
42865 + if (!is_textrel_rw && !is_textrel_rx)
42866 + continue;
42867 + i = 0UL;
42868 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42869 + elf_dyn dyn;
42870 +
42871 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42872 + return;
42873 + if (dyn.d_tag == DT_NULL)
42874 + return;
42875 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42876 + gr_log_textrel(vma);
42877 + if (is_textrel_rw)
42878 + vma->vm_flags |= VM_MAYWRITE;
42879 + else
42880 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42881 + vma->vm_flags &= ~VM_MAYWRITE;
42882 + return;
42883 + }
42884 + i++;
42885 + }
42886 + return;
42887 +
42888 + case PT_GNU_RELRO:
42889 + if (!is_relro)
42890 + continue;
42891 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42892 + vma->vm_flags &= ~VM_MAYWRITE;
42893 + return;
42894 + }
42895 + }
42896 +}
42897 +#endif
42898 +
42899 static int __init init_elf_binfmt(void)
42900 {
42901 return register_binfmt(&elf_format);
42902 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42903 index 1bffbe0..c8c283e 100644
42904 --- a/fs/binfmt_flat.c
42905 +++ b/fs/binfmt_flat.c
42906 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42907 realdatastart = (unsigned long) -ENOMEM;
42908 printk("Unable to allocate RAM for process data, errno %d\n",
42909 (int)-realdatastart);
42910 + down_write(&current->mm->mmap_sem);
42911 do_munmap(current->mm, textpos, text_len);
42912 + up_write(&current->mm->mmap_sem);
42913 ret = realdatastart;
42914 goto err;
42915 }
42916 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42917 }
42918 if (IS_ERR_VALUE(result)) {
42919 printk("Unable to read data+bss, errno %d\n", (int)-result);
42920 + down_write(&current->mm->mmap_sem);
42921 do_munmap(current->mm, textpos, text_len);
42922 do_munmap(current->mm, realdatastart, len);
42923 + up_write(&current->mm->mmap_sem);
42924 ret = result;
42925 goto err;
42926 }
42927 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42928 }
42929 if (IS_ERR_VALUE(result)) {
42930 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42931 + down_write(&current->mm->mmap_sem);
42932 do_munmap(current->mm, textpos, text_len + data_len + extra +
42933 MAX_SHARED_LIBS * sizeof(unsigned long));
42934 + up_write(&current->mm->mmap_sem);
42935 ret = result;
42936 goto err;
42937 }
42938 diff --git a/fs/bio.c b/fs/bio.c
42939 index b980ecd..74800bf 100644
42940 --- a/fs/bio.c
42941 +++ b/fs/bio.c
42942 @@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42943 /*
42944 * Overflow, abort
42945 */
42946 - if (end < start)
42947 + if (end < start || end - start > INT_MAX - nr_pages)
42948 return ERR_PTR(-EINVAL);
42949
42950 nr_pages += end - start;
42951 @@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42952 const int read = bio_data_dir(bio) == READ;
42953 struct bio_map_data *bmd = bio->bi_private;
42954 int i;
42955 - char *p = bmd->sgvecs[0].iov_base;
42956 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42957
42958 __bio_for_each_segment(bvec, bio, i, 0) {
42959 char *addr = page_address(bvec->bv_page);
42960 diff --git a/fs/block_dev.c b/fs/block_dev.c
42961 index 5e9f198..6bf9b1c 100644
42962 --- a/fs/block_dev.c
42963 +++ b/fs/block_dev.c
42964 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42965 else if (bdev->bd_contains == bdev)
42966 return true; /* is a whole device which isn't held */
42967
42968 - else if (whole->bd_holder == bd_may_claim)
42969 + else if (whole->bd_holder == (void *)bd_may_claim)
42970 return true; /* is a partition of a device that is being partitioned */
42971 else if (whole->bd_holder != NULL)
42972 return false; /* is a partition of a held device */
42973 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42974 index d986824..af1befd 100644
42975 --- a/fs/btrfs/check-integrity.c
42976 +++ b/fs/btrfs/check-integrity.c
42977 @@ -157,7 +157,7 @@ struct btrfsic_block {
42978 union {
42979 bio_end_io_t *bio;
42980 bh_end_io_t *bh;
42981 - } orig_bio_bh_end_io;
42982 + } __no_const orig_bio_bh_end_io;
42983 int submit_bio_bh_rw;
42984 u64 flush_gen; /* only valid if !never_written */
42985 };
42986 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42987 index 0639a55..7d9e07f 100644
42988 --- a/fs/btrfs/ctree.c
42989 +++ b/fs/btrfs/ctree.c
42990 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42991 free_extent_buffer(buf);
42992 add_root_to_dirty_list(root);
42993 } else {
42994 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42995 - parent_start = parent->start;
42996 - else
42997 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42998 + if (parent)
42999 + parent_start = parent->start;
43000 + else
43001 + parent_start = 0;
43002 + } else
43003 parent_start = 0;
43004
43005 WARN_ON(trans->transid != btrfs_header_generation(parent));
43006 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43007 index 892b347..b3db246 100644
43008 --- a/fs/btrfs/inode.c
43009 +++ b/fs/btrfs/inode.c
43010 @@ -6930,7 +6930,7 @@ fail:
43011 return -ENOMEM;
43012 }
43013
43014 -static int btrfs_getattr(struct vfsmount *mnt,
43015 +int btrfs_getattr(struct vfsmount *mnt,
43016 struct dentry *dentry, struct kstat *stat)
43017 {
43018 struct inode *inode = dentry->d_inode;
43019 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43020 return 0;
43021 }
43022
43023 +EXPORT_SYMBOL(btrfs_getattr);
43024 +
43025 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43026 +{
43027 + return BTRFS_I(inode)->root->anon_dev;
43028 +}
43029 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43030 +
43031 /*
43032 * If a file is moved, it will inherit the cow and compression flags of the new
43033 * directory.
43034 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43035 index 1b36f19..5ac7360 100644
43036 --- a/fs/btrfs/ioctl.c
43037 +++ b/fs/btrfs/ioctl.c
43038 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43039 for (i = 0; i < num_types; i++) {
43040 struct btrfs_space_info *tmp;
43041
43042 + /* Don't copy in more than we allocated */
43043 if (!slot_count)
43044 break;
43045
43046 + slot_count--;
43047 +
43048 info = NULL;
43049 rcu_read_lock();
43050 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43051 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43052 memcpy(dest, &space, sizeof(space));
43053 dest++;
43054 space_args.total_spaces++;
43055 - slot_count--;
43056 }
43057 - if (!slot_count)
43058 - break;
43059 }
43060 up_read(&info->groups_sem);
43061 }
43062
43063 - user_dest = (struct btrfs_ioctl_space_info *)
43064 + user_dest = (struct btrfs_ioctl_space_info __user *)
43065 (arg + sizeof(struct btrfs_ioctl_space_args));
43066
43067 if (copy_to_user(user_dest, dest_orig, alloc_size))
43068 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43069 index 8c1aae2..1e46446 100644
43070 --- a/fs/btrfs/relocation.c
43071 +++ b/fs/btrfs/relocation.c
43072 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43073 }
43074 spin_unlock(&rc->reloc_root_tree.lock);
43075
43076 - BUG_ON((struct btrfs_root *)node->data != root);
43077 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43078
43079 if (!del) {
43080 spin_lock(&rc->reloc_root_tree.lock);
43081 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43082 index 622f469..e8d2d55 100644
43083 --- a/fs/cachefiles/bind.c
43084 +++ b/fs/cachefiles/bind.c
43085 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43086 args);
43087
43088 /* start by checking things over */
43089 - ASSERT(cache->fstop_percent >= 0 &&
43090 - cache->fstop_percent < cache->fcull_percent &&
43091 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43092 cache->fcull_percent < cache->frun_percent &&
43093 cache->frun_percent < 100);
43094
43095 - ASSERT(cache->bstop_percent >= 0 &&
43096 - cache->bstop_percent < cache->bcull_percent &&
43097 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43098 cache->bcull_percent < cache->brun_percent &&
43099 cache->brun_percent < 100);
43100
43101 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43102 index 0a1467b..6a53245 100644
43103 --- a/fs/cachefiles/daemon.c
43104 +++ b/fs/cachefiles/daemon.c
43105 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43106 if (n > buflen)
43107 return -EMSGSIZE;
43108
43109 - if (copy_to_user(_buffer, buffer, n) != 0)
43110 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43111 return -EFAULT;
43112
43113 return n;
43114 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43115 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43116 return -EIO;
43117
43118 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43119 + if (datalen > PAGE_SIZE - 1)
43120 return -EOPNOTSUPP;
43121
43122 /* drag the command string into the kernel so we can parse it */
43123 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43124 if (args[0] != '%' || args[1] != '\0')
43125 return -EINVAL;
43126
43127 - if (fstop < 0 || fstop >= cache->fcull_percent)
43128 + if (fstop >= cache->fcull_percent)
43129 return cachefiles_daemon_range_error(cache, args);
43130
43131 cache->fstop_percent = fstop;
43132 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43133 if (args[0] != '%' || args[1] != '\0')
43134 return -EINVAL;
43135
43136 - if (bstop < 0 || bstop >= cache->bcull_percent)
43137 + if (bstop >= cache->bcull_percent)
43138 return cachefiles_daemon_range_error(cache, args);
43139
43140 cache->bstop_percent = bstop;
43141 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43142 index bd6bc1b..b627b53 100644
43143 --- a/fs/cachefiles/internal.h
43144 +++ b/fs/cachefiles/internal.h
43145 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43146 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43147 struct rb_root active_nodes; /* active nodes (can't be culled) */
43148 rwlock_t active_lock; /* lock for active_nodes */
43149 - atomic_t gravecounter; /* graveyard uniquifier */
43150 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43151 unsigned frun_percent; /* when to stop culling (% files) */
43152 unsigned fcull_percent; /* when to start culling (% files) */
43153 unsigned fstop_percent; /* when to stop allocating (% files) */
43154 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43155 * proc.c
43156 */
43157 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43158 -extern atomic_t cachefiles_lookup_histogram[HZ];
43159 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43160 -extern atomic_t cachefiles_create_histogram[HZ];
43161 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43162 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43163 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43164
43165 extern int __init cachefiles_proc_init(void);
43166 extern void cachefiles_proc_cleanup(void);
43167 static inline
43168 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43169 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43170 {
43171 unsigned long jif = jiffies - start_jif;
43172 if (jif >= HZ)
43173 jif = HZ - 1;
43174 - atomic_inc(&histogram[jif]);
43175 + atomic_inc_unchecked(&histogram[jif]);
43176 }
43177
43178 #else
43179 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43180 index a0358c2..d6137f2 100644
43181 --- a/fs/cachefiles/namei.c
43182 +++ b/fs/cachefiles/namei.c
43183 @@ -318,7 +318,7 @@ try_again:
43184 /* first step is to make up a grave dentry in the graveyard */
43185 sprintf(nbuffer, "%08x%08x",
43186 (uint32_t) get_seconds(),
43187 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43188 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43189
43190 /* do the multiway lock magic */
43191 trap = lock_rename(cache->graveyard, dir);
43192 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43193 index eccd339..4c1d995 100644
43194 --- a/fs/cachefiles/proc.c
43195 +++ b/fs/cachefiles/proc.c
43196 @@ -14,9 +14,9 @@
43197 #include <linux/seq_file.h>
43198 #include "internal.h"
43199
43200 -atomic_t cachefiles_lookup_histogram[HZ];
43201 -atomic_t cachefiles_mkdir_histogram[HZ];
43202 -atomic_t cachefiles_create_histogram[HZ];
43203 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43204 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43205 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43206
43207 /*
43208 * display the latency histogram
43209 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43210 return 0;
43211 default:
43212 index = (unsigned long) v - 3;
43213 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43214 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43215 - z = atomic_read(&cachefiles_create_histogram[index]);
43216 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43217 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43218 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43219 if (x == 0 && y == 0 && z == 0)
43220 return 0;
43221
43222 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43223 index 0e3c092..818480e 100644
43224 --- a/fs/cachefiles/rdwr.c
43225 +++ b/fs/cachefiles/rdwr.c
43226 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43227 old_fs = get_fs();
43228 set_fs(KERNEL_DS);
43229 ret = file->f_op->write(
43230 - file, (const void __user *) data, len, &pos);
43231 + file, (const void __force_user *) data, len, &pos);
43232 set_fs(old_fs);
43233 kunmap(page);
43234 if (ret != len)
43235 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43236 index 3e8094b..cb3ff3d 100644
43237 --- a/fs/ceph/dir.c
43238 +++ b/fs/ceph/dir.c
43239 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43240 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43241 struct ceph_mds_client *mdsc = fsc->mdsc;
43242 unsigned frag = fpos_frag(filp->f_pos);
43243 - int off = fpos_off(filp->f_pos);
43244 + unsigned int off = fpos_off(filp->f_pos);
43245 int err;
43246 u32 ftype;
43247 struct ceph_mds_reply_info_parsed *rinfo;
43248 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43249 if (nd &&
43250 (nd->flags & LOOKUP_OPEN) &&
43251 !(nd->intent.open.flags & O_CREAT)) {
43252 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43253 + int mode = nd->intent.open.create_mode & ~current_umask();
43254 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43255 }
43256
43257 diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
43258 index cfd1ce3..6b13a74 100644
43259 --- a/fs/cifs/asn1.c
43260 +++ b/fs/cifs/asn1.c
43261 @@ -416,6 +416,9 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
43262
43263 static int
43264 asn1_oid_decode(struct asn1_ctx *ctx,
43265 + unsigned char *eoc, unsigned long **oid, unsigned int *len) __size_overflow(2);
43266 +static int
43267 +asn1_oid_decode(struct asn1_ctx *ctx,
43268 unsigned char *eoc, unsigned long **oid, unsigned int *len)
43269 {
43270 unsigned long subid;
43271 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43272 index 24b3dfc..3cd5454 100644
43273 --- a/fs/cifs/cifs_debug.c
43274 +++ b/fs/cifs/cifs_debug.c
43275 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43276
43277 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43278 #ifdef CONFIG_CIFS_STATS2
43279 - atomic_set(&totBufAllocCount, 0);
43280 - atomic_set(&totSmBufAllocCount, 0);
43281 + atomic_set_unchecked(&totBufAllocCount, 0);
43282 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43283 #endif /* CONFIG_CIFS_STATS2 */
43284 spin_lock(&cifs_tcp_ses_lock);
43285 list_for_each(tmp1, &cifs_tcp_ses_list) {
43286 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43287 tcon = list_entry(tmp3,
43288 struct cifs_tcon,
43289 tcon_list);
43290 - atomic_set(&tcon->num_smbs_sent, 0);
43291 - atomic_set(&tcon->num_writes, 0);
43292 - atomic_set(&tcon->num_reads, 0);
43293 - atomic_set(&tcon->num_oplock_brks, 0);
43294 - atomic_set(&tcon->num_opens, 0);
43295 - atomic_set(&tcon->num_posixopens, 0);
43296 - atomic_set(&tcon->num_posixmkdirs, 0);
43297 - atomic_set(&tcon->num_closes, 0);
43298 - atomic_set(&tcon->num_deletes, 0);
43299 - atomic_set(&tcon->num_mkdirs, 0);
43300 - atomic_set(&tcon->num_rmdirs, 0);
43301 - atomic_set(&tcon->num_renames, 0);
43302 - atomic_set(&tcon->num_t2renames, 0);
43303 - atomic_set(&tcon->num_ffirst, 0);
43304 - atomic_set(&tcon->num_fnext, 0);
43305 - atomic_set(&tcon->num_fclose, 0);
43306 - atomic_set(&tcon->num_hardlinks, 0);
43307 - atomic_set(&tcon->num_symlinks, 0);
43308 - atomic_set(&tcon->num_locks, 0);
43309 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43310 + atomic_set_unchecked(&tcon->num_writes, 0);
43311 + atomic_set_unchecked(&tcon->num_reads, 0);
43312 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43313 + atomic_set_unchecked(&tcon->num_opens, 0);
43314 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43315 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43316 + atomic_set_unchecked(&tcon->num_closes, 0);
43317 + atomic_set_unchecked(&tcon->num_deletes, 0);
43318 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43319 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43320 + atomic_set_unchecked(&tcon->num_renames, 0);
43321 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43322 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43323 + atomic_set_unchecked(&tcon->num_fnext, 0);
43324 + atomic_set_unchecked(&tcon->num_fclose, 0);
43325 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43326 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43327 + atomic_set_unchecked(&tcon->num_locks, 0);
43328 }
43329 }
43330 }
43331 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43332 smBufAllocCount.counter, cifs_min_small);
43333 #ifdef CONFIG_CIFS_STATS2
43334 seq_printf(m, "Total Large %d Small %d Allocations\n",
43335 - atomic_read(&totBufAllocCount),
43336 - atomic_read(&totSmBufAllocCount));
43337 + atomic_read_unchecked(&totBufAllocCount),
43338 + atomic_read_unchecked(&totSmBufAllocCount));
43339 #endif /* CONFIG_CIFS_STATS2 */
43340
43341 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43342 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43343 if (tcon->need_reconnect)
43344 seq_puts(m, "\tDISCONNECTED ");
43345 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43346 - atomic_read(&tcon->num_smbs_sent),
43347 - atomic_read(&tcon->num_oplock_brks));
43348 + atomic_read_unchecked(&tcon->num_smbs_sent),
43349 + atomic_read_unchecked(&tcon->num_oplock_brks));
43350 seq_printf(m, "\nReads: %d Bytes: %lld",
43351 - atomic_read(&tcon->num_reads),
43352 + atomic_read_unchecked(&tcon->num_reads),
43353 (long long)(tcon->bytes_read));
43354 seq_printf(m, "\nWrites: %d Bytes: %lld",
43355 - atomic_read(&tcon->num_writes),
43356 + atomic_read_unchecked(&tcon->num_writes),
43357 (long long)(tcon->bytes_written));
43358 seq_printf(m, "\nFlushes: %d",
43359 - atomic_read(&tcon->num_flushes));
43360 + atomic_read_unchecked(&tcon->num_flushes));
43361 seq_printf(m, "\nLocks: %d HardLinks: %d "
43362 "Symlinks: %d",
43363 - atomic_read(&tcon->num_locks),
43364 - atomic_read(&tcon->num_hardlinks),
43365 - atomic_read(&tcon->num_symlinks));
43366 + atomic_read_unchecked(&tcon->num_locks),
43367 + atomic_read_unchecked(&tcon->num_hardlinks),
43368 + atomic_read_unchecked(&tcon->num_symlinks));
43369 seq_printf(m, "\nOpens: %d Closes: %d "
43370 "Deletes: %d",
43371 - atomic_read(&tcon->num_opens),
43372 - atomic_read(&tcon->num_closes),
43373 - atomic_read(&tcon->num_deletes));
43374 + atomic_read_unchecked(&tcon->num_opens),
43375 + atomic_read_unchecked(&tcon->num_closes),
43376 + atomic_read_unchecked(&tcon->num_deletes));
43377 seq_printf(m, "\nPosix Opens: %d "
43378 "Posix Mkdirs: %d",
43379 - atomic_read(&tcon->num_posixopens),
43380 - atomic_read(&tcon->num_posixmkdirs));
43381 + atomic_read_unchecked(&tcon->num_posixopens),
43382 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43383 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43384 - atomic_read(&tcon->num_mkdirs),
43385 - atomic_read(&tcon->num_rmdirs));
43386 + atomic_read_unchecked(&tcon->num_mkdirs),
43387 + atomic_read_unchecked(&tcon->num_rmdirs));
43388 seq_printf(m, "\nRenames: %d T2 Renames %d",
43389 - atomic_read(&tcon->num_renames),
43390 - atomic_read(&tcon->num_t2renames));
43391 + atomic_read_unchecked(&tcon->num_renames),
43392 + atomic_read_unchecked(&tcon->num_t2renames));
43393 seq_printf(m, "\nFindFirst: %d FNext %d "
43394 "FClose %d",
43395 - atomic_read(&tcon->num_ffirst),
43396 - atomic_read(&tcon->num_fnext),
43397 - atomic_read(&tcon->num_fclose));
43398 + atomic_read_unchecked(&tcon->num_ffirst),
43399 + atomic_read_unchecked(&tcon->num_fnext),
43400 + atomic_read_unchecked(&tcon->num_fclose));
43401 }
43402 }
43403 }
43404 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43405 index 6ee1cb4..8443157 100644
43406 --- a/fs/cifs/cifsfs.c
43407 +++ b/fs/cifs/cifsfs.c
43408 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43409 cifs_req_cachep = kmem_cache_create("cifs_request",
43410 CIFSMaxBufSize +
43411 MAX_CIFS_HDR_SIZE, 0,
43412 - SLAB_HWCACHE_ALIGN, NULL);
43413 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43414 if (cifs_req_cachep == NULL)
43415 return -ENOMEM;
43416
43417 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43418 efficient to alloc 1 per page off the slab compared to 17K (5page)
43419 alloc of large cifs buffers even when page debugging is on */
43420 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43421 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43422 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43423 NULL);
43424 if (cifs_sm_req_cachep == NULL) {
43425 mempool_destroy(cifs_req_poolp);
43426 @@ -1101,8 +1101,8 @@ init_cifs(void)
43427 atomic_set(&bufAllocCount, 0);
43428 atomic_set(&smBufAllocCount, 0);
43429 #ifdef CONFIG_CIFS_STATS2
43430 - atomic_set(&totBufAllocCount, 0);
43431 - atomic_set(&totSmBufAllocCount, 0);
43432 + atomic_set_unchecked(&totBufAllocCount, 0);
43433 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43434 #endif /* CONFIG_CIFS_STATS2 */
43435
43436 atomic_set(&midCount, 0);
43437 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43438 index d47d20a..77e8b33 100644
43439 --- a/fs/cifs/cifsglob.h
43440 +++ b/fs/cifs/cifsglob.h
43441 @@ -388,28 +388,28 @@ struct cifs_tcon {
43442 __u16 Flags; /* optional support bits */
43443 enum statusEnum tidStatus;
43444 #ifdef CONFIG_CIFS_STATS
43445 - atomic_t num_smbs_sent;
43446 - atomic_t num_writes;
43447 - atomic_t num_reads;
43448 - atomic_t num_flushes;
43449 - atomic_t num_oplock_brks;
43450 - atomic_t num_opens;
43451 - atomic_t num_closes;
43452 - atomic_t num_deletes;
43453 - atomic_t num_mkdirs;
43454 - atomic_t num_posixopens;
43455 - atomic_t num_posixmkdirs;
43456 - atomic_t num_rmdirs;
43457 - atomic_t num_renames;
43458 - atomic_t num_t2renames;
43459 - atomic_t num_ffirst;
43460 - atomic_t num_fnext;
43461 - atomic_t num_fclose;
43462 - atomic_t num_hardlinks;
43463 - atomic_t num_symlinks;
43464 - atomic_t num_locks;
43465 - atomic_t num_acl_get;
43466 - atomic_t num_acl_set;
43467 + atomic_unchecked_t num_smbs_sent;
43468 + atomic_unchecked_t num_writes;
43469 + atomic_unchecked_t num_reads;
43470 + atomic_unchecked_t num_flushes;
43471 + atomic_unchecked_t num_oplock_brks;
43472 + atomic_unchecked_t num_opens;
43473 + atomic_unchecked_t num_closes;
43474 + atomic_unchecked_t num_deletes;
43475 + atomic_unchecked_t num_mkdirs;
43476 + atomic_unchecked_t num_posixopens;
43477 + atomic_unchecked_t num_posixmkdirs;
43478 + atomic_unchecked_t num_rmdirs;
43479 + atomic_unchecked_t num_renames;
43480 + atomic_unchecked_t num_t2renames;
43481 + atomic_unchecked_t num_ffirst;
43482 + atomic_unchecked_t num_fnext;
43483 + atomic_unchecked_t num_fclose;
43484 + atomic_unchecked_t num_hardlinks;
43485 + atomic_unchecked_t num_symlinks;
43486 + atomic_unchecked_t num_locks;
43487 + atomic_unchecked_t num_acl_get;
43488 + atomic_unchecked_t num_acl_set;
43489 #ifdef CONFIG_CIFS_STATS2
43490 unsigned long long time_writes;
43491 unsigned long long time_reads;
43492 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43493 }
43494
43495 #ifdef CONFIG_CIFS_STATS
43496 -#define cifs_stats_inc atomic_inc
43497 +#define cifs_stats_inc atomic_inc_unchecked
43498
43499 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43500 unsigned int bytes)
43501 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43502 /* Various Debug counters */
43503 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43504 #ifdef CONFIG_CIFS_STATS2
43505 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43506 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43507 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43508 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43509 #endif
43510 GLOBAL_EXTERN atomic_t smBufAllocCount;
43511 GLOBAL_EXTERN atomic_t midCount;
43512 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43513 index 6b0e064..94e6c3c 100644
43514 --- a/fs/cifs/link.c
43515 +++ b/fs/cifs/link.c
43516 @@ -600,7 +600,7 @@ symlink_exit:
43517
43518 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43519 {
43520 - char *p = nd_get_link(nd);
43521 + const char *p = nd_get_link(nd);
43522 if (!IS_ERR(p))
43523 kfree(p);
43524 }
43525 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43526 index 703ef5c..2a44ed5 100644
43527 --- a/fs/cifs/misc.c
43528 +++ b/fs/cifs/misc.c
43529 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43530 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43531 atomic_inc(&bufAllocCount);
43532 #ifdef CONFIG_CIFS_STATS2
43533 - atomic_inc(&totBufAllocCount);
43534 + atomic_inc_unchecked(&totBufAllocCount);
43535 #endif /* CONFIG_CIFS_STATS2 */
43536 }
43537
43538 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43539 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43540 atomic_inc(&smBufAllocCount);
43541 #ifdef CONFIG_CIFS_STATS2
43542 - atomic_inc(&totSmBufAllocCount);
43543 + atomic_inc_unchecked(&totSmBufAllocCount);
43544 #endif /* CONFIG_CIFS_STATS2 */
43545
43546 }
43547 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43548 index 6901578..d402eb5 100644
43549 --- a/fs/coda/cache.c
43550 +++ b/fs/coda/cache.c
43551 @@ -24,7 +24,7 @@
43552 #include "coda_linux.h"
43553 #include "coda_cache.h"
43554
43555 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43556 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43557
43558 /* replace or extend an acl cache hit */
43559 void coda_cache_enter(struct inode *inode, int mask)
43560 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43561 struct coda_inode_info *cii = ITOC(inode);
43562
43563 spin_lock(&cii->c_lock);
43564 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43565 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43566 if (cii->c_uid != current_fsuid()) {
43567 cii->c_uid = current_fsuid();
43568 cii->c_cached_perm = mask;
43569 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43570 {
43571 struct coda_inode_info *cii = ITOC(inode);
43572 spin_lock(&cii->c_lock);
43573 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43574 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43575 spin_unlock(&cii->c_lock);
43576 }
43577
43578 /* remove all acl caches */
43579 void coda_cache_clear_all(struct super_block *sb)
43580 {
43581 - atomic_inc(&permission_epoch);
43582 + atomic_inc_unchecked(&permission_epoch);
43583 }
43584
43585
43586 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43587 spin_lock(&cii->c_lock);
43588 hit = (mask & cii->c_cached_perm) == mask &&
43589 cii->c_uid == current_fsuid() &&
43590 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43591 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43592 spin_unlock(&cii->c_lock);
43593
43594 return hit;
43595 diff --git a/fs/compat.c b/fs/compat.c
43596 index 07880ba..3fb2862 100644
43597 --- a/fs/compat.c
43598 +++ b/fs/compat.c
43599 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43600
43601 set_fs(KERNEL_DS);
43602 /* The __user pointer cast is valid because of the set_fs() */
43603 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43604 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43605 set_fs(oldfs);
43606 /* truncating is ok because it's a user address */
43607 if (!ret)
43608 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43609 goto out;
43610
43611 ret = -EINVAL;
43612 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43613 + if (nr_segs > UIO_MAXIOV)
43614 goto out;
43615 if (nr_segs > fast_segs) {
43616 ret = -ENOMEM;
43617 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43618
43619 struct compat_readdir_callback {
43620 struct compat_old_linux_dirent __user *dirent;
43621 + struct file * file;
43622 int result;
43623 };
43624
43625 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43626 buf->result = -EOVERFLOW;
43627 return -EOVERFLOW;
43628 }
43629 +
43630 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43631 + return 0;
43632 +
43633 buf->result++;
43634 dirent = buf->dirent;
43635 if (!access_ok(VERIFY_WRITE, dirent,
43636 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43637
43638 buf.result = 0;
43639 buf.dirent = dirent;
43640 + buf.file = file;
43641
43642 error = vfs_readdir(file, compat_fillonedir, &buf);
43643 if (buf.result)
43644 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
43645 struct compat_getdents_callback {
43646 struct compat_linux_dirent __user *current_dir;
43647 struct compat_linux_dirent __user *previous;
43648 + struct file * file;
43649 int count;
43650 int error;
43651 };
43652 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43653 buf->error = -EOVERFLOW;
43654 return -EOVERFLOW;
43655 }
43656 +
43657 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43658 + return 0;
43659 +
43660 dirent = buf->previous;
43661 if (dirent) {
43662 if (__put_user(offset, &dirent->d_off))
43663 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43664 buf.previous = NULL;
43665 buf.count = count;
43666 buf.error = 0;
43667 + buf.file = file;
43668
43669 error = vfs_readdir(file, compat_filldir, &buf);
43670 if (error >= 0)
43671 @@ -990,6 +1002,7 @@ out:
43672 struct compat_getdents_callback64 {
43673 struct linux_dirent64 __user *current_dir;
43674 struct linux_dirent64 __user *previous;
43675 + struct file * file;
43676 int count;
43677 int error;
43678 };
43679 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43680 buf->error = -EINVAL; /* only used if we fail.. */
43681 if (reclen > buf->count)
43682 return -EINVAL;
43683 +
43684 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43685 + return 0;
43686 +
43687 dirent = buf->previous;
43688
43689 if (dirent) {
43690 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43691 buf.previous = NULL;
43692 buf.count = count;
43693 buf.error = 0;
43694 + buf.file = file;
43695
43696 error = vfs_readdir(file, compat_filldir64, &buf);
43697 if (error >= 0)
43698 error = buf.error;
43699 lastdirent = buf.previous;
43700 if (lastdirent) {
43701 - typeof(lastdirent->d_off) d_off = file->f_pos;
43702 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43703 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43704 error = -EFAULT;
43705 else
43706 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43707 index 112e45a..b59845b 100644
43708 --- a/fs/compat_binfmt_elf.c
43709 +++ b/fs/compat_binfmt_elf.c
43710 @@ -30,11 +30,13 @@
43711 #undef elf_phdr
43712 #undef elf_shdr
43713 #undef elf_note
43714 +#undef elf_dyn
43715 #undef elf_addr_t
43716 #define elfhdr elf32_hdr
43717 #define elf_phdr elf32_phdr
43718 #define elf_shdr elf32_shdr
43719 #define elf_note elf32_note
43720 +#define elf_dyn Elf32_Dyn
43721 #define elf_addr_t Elf32_Addr
43722
43723 /*
43724 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43725 index a26bea1..ae23e72 100644
43726 --- a/fs/compat_ioctl.c
43727 +++ b/fs/compat_ioctl.c
43728 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43729
43730 err = get_user(palp, &up->palette);
43731 err |= get_user(length, &up->length);
43732 + if (err)
43733 + return -EFAULT;
43734
43735 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43736 err = put_user(compat_ptr(palp), &up_native->palette);
43737 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43738 return -EFAULT;
43739 if (__get_user(udata, &ss32->iomem_base))
43740 return -EFAULT;
43741 - ss.iomem_base = compat_ptr(udata);
43742 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43743 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43744 __get_user(ss.port_high, &ss32->port_high))
43745 return -EFAULT;
43746 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
43747 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43748 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43749 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43750 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43751 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43752 return -EFAULT;
43753
43754 return ioctl_preallocate(file, p);
43755 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43756 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43757 {
43758 unsigned int a, b;
43759 - a = *(unsigned int *)p;
43760 - b = *(unsigned int *)q;
43761 + a = *(const unsigned int *)p;
43762 + b = *(const unsigned int *)q;
43763 if (a > b)
43764 return 1;
43765 if (a < b)
43766 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43767 index 5ddd7eb..c18bf04 100644
43768 --- a/fs/configfs/dir.c
43769 +++ b/fs/configfs/dir.c
43770 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43771 }
43772 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43773 struct configfs_dirent *next;
43774 - const char * name;
43775 + const unsigned char * name;
43776 + char d_name[sizeof(next->s_dentry->d_iname)];
43777 int len;
43778 struct inode *inode = NULL;
43779
43780 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43781 continue;
43782
43783 name = configfs_get_name(next);
43784 - len = strlen(name);
43785 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43786 + len = next->s_dentry->d_name.len;
43787 + memcpy(d_name, name, len);
43788 + name = d_name;
43789 + } else
43790 + len = strlen(name);
43791
43792 /*
43793 * We'll have a dentry and an inode for
43794 diff --git a/fs/configfs/file.c b/fs/configfs/file.c
43795 index 2b6cb23..d76e879 100644
43796 --- a/fs/configfs/file.c
43797 +++ b/fs/configfs/file.c
43798 @@ -135,6 +135,8 @@ out:
43799 */
43800
43801 static int
43802 +fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count) __size_overflow(3);
43803 +static int
43804 fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count)
43805 {
43806 int error;
43807 diff --git a/fs/dcache.c b/fs/dcache.c
43808 index 2576d14..0cec38d 100644
43809 --- a/fs/dcache.c
43810 +++ b/fs/dcache.c
43811 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
43812 static struct hlist_bl_head *dentry_hashtable __read_mostly;
43813
43814 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
43815 - unsigned long hash)
43816 + unsigned int hash)
43817 {
43818 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
43819 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
43820 + hash += (unsigned long) parent / L1_CACHE_BYTES;
43821 + hash = hash + (hash >> D_HASHBITS);
43822 return dentry_hashtable + (hash & D_HASHMASK);
43823 }
43824
43825 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
43826 mempages -= reserve;
43827
43828 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43829 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43830 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43831
43832 dcache_init();
43833 inode_init();
43834 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43835 index 956d5dd..e755e04 100644
43836 --- a/fs/debugfs/inode.c
43837 +++ b/fs/debugfs/inode.c
43838 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43839 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43840 {
43841 return debugfs_create_file(name,
43842 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43843 + S_IFDIR | S_IRWXU,
43844 +#else
43845 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43846 +#endif
43847 parent, NULL, NULL);
43848 }
43849 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43850 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43851 index ab35b11..b30af66 100644
43852 --- a/fs/ecryptfs/inode.c
43853 +++ b/fs/ecryptfs/inode.c
43854 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43855 old_fs = get_fs();
43856 set_fs(get_ds());
43857 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43858 - (char __user *)lower_buf,
43859 + (char __force_user *)lower_buf,
43860 lower_bufsiz);
43861 set_fs(old_fs);
43862 if (rc < 0)
43863 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43864 }
43865 old_fs = get_fs();
43866 set_fs(get_ds());
43867 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43868 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43869 set_fs(old_fs);
43870 if (rc < 0) {
43871 kfree(buf);
43872 @@ -733,7 +733,7 @@ out:
43873 static void
43874 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43875 {
43876 - char *buf = nd_get_link(nd);
43877 + const char *buf = nd_get_link(nd);
43878 if (!IS_ERR(buf)) {
43879 /* Free the char* */
43880 kfree(buf);
43881 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43882 index 3a06f40..f7af544 100644
43883 --- a/fs/ecryptfs/miscdev.c
43884 +++ b/fs/ecryptfs/miscdev.c
43885 @@ -345,7 +345,7 @@ check_list:
43886 goto out_unlock_msg_ctx;
43887 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43888 if (msg_ctx->msg) {
43889 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43890 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43891 goto out_unlock_msg_ctx;
43892 i += packet_length_size;
43893 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43894 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43895 index b2a34a1..162fa69 100644
43896 --- a/fs/ecryptfs/read_write.c
43897 +++ b/fs/ecryptfs/read_write.c
43898 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43899 return -EIO;
43900 fs_save = get_fs();
43901 set_fs(get_ds());
43902 - rc = vfs_write(lower_file, data, size, &offset);
43903 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43904 set_fs(fs_save);
43905 mark_inode_dirty_sync(ecryptfs_inode);
43906 return rc;
43907 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43908 return -EIO;
43909 fs_save = get_fs();
43910 set_fs(get_ds());
43911 - rc = vfs_read(lower_file, data, size, &offset);
43912 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43913 set_fs(fs_save);
43914 return rc;
43915 }
43916 diff --git a/fs/exec.c b/fs/exec.c
43917 index 153dee1..ab4ebe9 100644
43918 --- a/fs/exec.c
43919 +++ b/fs/exec.c
43920 @@ -55,6 +55,13 @@
43921 #include <linux/pipe_fs_i.h>
43922 #include <linux/oom.h>
43923 #include <linux/compat.h>
43924 +#include <linux/random.h>
43925 +#include <linux/seq_file.h>
43926 +
43927 +#ifdef CONFIG_PAX_REFCOUNT
43928 +#include <linux/kallsyms.h>
43929 +#include <linux/kdebug.h>
43930 +#endif
43931
43932 #include <asm/uaccess.h>
43933 #include <asm/mmu_context.h>
43934 @@ -63,6 +70,15 @@
43935 #include <trace/events/task.h>
43936 #include "internal.h"
43937
43938 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43939 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43940 +#endif
43941 +
43942 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43943 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43944 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43945 +#endif
43946 +
43947 int core_uses_pid;
43948 char core_pattern[CORENAME_MAX_SIZE] = "core";
43949 unsigned int core_pipe_limit;
43950 @@ -72,7 +88,7 @@ struct core_name {
43951 char *corename;
43952 int used, size;
43953 };
43954 -static atomic_t call_count = ATOMIC_INIT(1);
43955 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43956
43957 /* The maximal length of core_pattern is also specified in sysctl.c */
43958
43959 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43960 int write)
43961 {
43962 struct page *page;
43963 - int ret;
43964
43965 -#ifdef CONFIG_STACK_GROWSUP
43966 - if (write) {
43967 - ret = expand_downwards(bprm->vma, pos);
43968 - if (ret < 0)
43969 - return NULL;
43970 - }
43971 -#endif
43972 - ret = get_user_pages(current, bprm->mm, pos,
43973 - 1, write, 1, &page, NULL);
43974 - if (ret <= 0)
43975 + if (0 > expand_downwards(bprm->vma, pos))
43976 + return NULL;
43977 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43978 return NULL;
43979
43980 if (write) {
43981 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43982 if (size <= ARG_MAX)
43983 return page;
43984
43985 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43986 + // only allow 512KB for argv+env on suid/sgid binaries
43987 + // to prevent easy ASLR exhaustion
43988 + if (((bprm->cred->euid != current_euid()) ||
43989 + (bprm->cred->egid != current_egid())) &&
43990 + (size > (512 * 1024))) {
43991 + put_page(page);
43992 + return NULL;
43993 + }
43994 +#endif
43995 +
43996 /*
43997 * Limit to 1/4-th the stack size for the argv+env strings.
43998 * This ensures that:
43999 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44000 vma->vm_end = STACK_TOP_MAX;
44001 vma->vm_start = vma->vm_end - PAGE_SIZE;
44002 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44003 +
44004 +#ifdef CONFIG_PAX_SEGMEXEC
44005 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44006 +#endif
44007 +
44008 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44009 INIT_LIST_HEAD(&vma->anon_vma_chain);
44010
44011 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44012 mm->stack_vm = mm->total_vm = 1;
44013 up_write(&mm->mmap_sem);
44014 bprm->p = vma->vm_end - sizeof(void *);
44015 +
44016 +#ifdef CONFIG_PAX_RANDUSTACK
44017 + if (randomize_va_space)
44018 + bprm->p ^= random32() & ~PAGE_MASK;
44019 +#endif
44020 +
44021 return 0;
44022 err:
44023 up_write(&mm->mmap_sem);
44024 @@ -398,19 +428,7 @@ err:
44025 return err;
44026 }
44027
44028 -struct user_arg_ptr {
44029 -#ifdef CONFIG_COMPAT
44030 - bool is_compat;
44031 -#endif
44032 - union {
44033 - const char __user *const __user *native;
44034 -#ifdef CONFIG_COMPAT
44035 - compat_uptr_t __user *compat;
44036 -#endif
44037 - } ptr;
44038 -};
44039 -
44040 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44041 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44042 {
44043 const char __user *native;
44044
44045 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44046 compat_uptr_t compat;
44047
44048 if (get_user(compat, argv.ptr.compat + nr))
44049 - return ERR_PTR(-EFAULT);
44050 + return (const char __force_user *)ERR_PTR(-EFAULT);
44051
44052 return compat_ptr(compat);
44053 }
44054 #endif
44055
44056 if (get_user(native, argv.ptr.native + nr))
44057 - return ERR_PTR(-EFAULT);
44058 + return (const char __force_user *)ERR_PTR(-EFAULT);
44059
44060 return native;
44061 }
44062 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44063 if (!p)
44064 break;
44065
44066 - if (IS_ERR(p))
44067 + if (IS_ERR((const char __force_kernel *)p))
44068 return -EFAULT;
44069
44070 if (i++ >= max)
44071 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44072
44073 ret = -EFAULT;
44074 str = get_user_arg_ptr(argv, argc);
44075 - if (IS_ERR(str))
44076 + if (IS_ERR((const char __force_kernel *)str))
44077 goto out;
44078
44079 len = strnlen_user(str, MAX_ARG_STRLEN);
44080 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44081 int r;
44082 mm_segment_t oldfs = get_fs();
44083 struct user_arg_ptr argv = {
44084 - .ptr.native = (const char __user *const __user *)__argv,
44085 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44086 };
44087
44088 set_fs(KERNEL_DS);
44089 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44090 unsigned long new_end = old_end - shift;
44091 struct mmu_gather tlb;
44092
44093 - BUG_ON(new_start > new_end);
44094 + if (new_start >= new_end || new_start < mmap_min_addr)
44095 + return -ENOMEM;
44096
44097 /*
44098 * ensure there are no vmas between where we want to go
44099 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44100 if (vma != find_vma(mm, new_start))
44101 return -EFAULT;
44102
44103 +#ifdef CONFIG_PAX_SEGMEXEC
44104 + BUG_ON(pax_find_mirror_vma(vma));
44105 +#endif
44106 +
44107 /*
44108 * cover the whole range: [new_start, old_end)
44109 */
44110 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44111 stack_top = arch_align_stack(stack_top);
44112 stack_top = PAGE_ALIGN(stack_top);
44113
44114 - if (unlikely(stack_top < mmap_min_addr) ||
44115 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44116 - return -ENOMEM;
44117 -
44118 stack_shift = vma->vm_end - stack_top;
44119
44120 bprm->p -= stack_shift;
44121 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44122 bprm->exec -= stack_shift;
44123
44124 down_write(&mm->mmap_sem);
44125 +
44126 + /* Move stack pages down in memory. */
44127 + if (stack_shift) {
44128 + ret = shift_arg_pages(vma, stack_shift);
44129 + if (ret)
44130 + goto out_unlock;
44131 + }
44132 +
44133 vm_flags = VM_STACK_FLAGS;
44134
44135 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44136 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44137 + vm_flags &= ~VM_EXEC;
44138 +
44139 +#ifdef CONFIG_PAX_MPROTECT
44140 + if (mm->pax_flags & MF_PAX_MPROTECT)
44141 + vm_flags &= ~VM_MAYEXEC;
44142 +#endif
44143 +
44144 + }
44145 +#endif
44146 +
44147 /*
44148 * Adjust stack execute permissions; explicitly enable for
44149 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44150 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44151 goto out_unlock;
44152 BUG_ON(prev != vma);
44153
44154 - /* Move stack pages down in memory. */
44155 - if (stack_shift) {
44156 - ret = shift_arg_pages(vma, stack_shift);
44157 - if (ret)
44158 - goto out_unlock;
44159 - }
44160 -
44161 /* mprotect_fixup is overkill to remove the temporary stack flags */
44162 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44163
44164 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44165 old_fs = get_fs();
44166 set_fs(get_ds());
44167 /* The cast to a user pointer is valid due to the set_fs() */
44168 - result = vfs_read(file, (void __user *)addr, count, &pos);
44169 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44170 set_fs(old_fs);
44171 return result;
44172 }
44173 @@ -1252,7 +1284,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44174 }
44175 rcu_read_unlock();
44176
44177 - if (p->fs->users > n_fs) {
44178 + if (atomic_read(&p->fs->users) > n_fs) {
44179 bprm->unsafe |= LSM_UNSAFE_SHARE;
44180 } else {
44181 res = -EAGAIN;
44182 @@ -1447,6 +1479,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44183
44184 EXPORT_SYMBOL(search_binary_handler);
44185
44186 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44187 +static DEFINE_PER_CPU(u64, exec_counter);
44188 +static int __init init_exec_counters(void)
44189 +{
44190 + unsigned int cpu;
44191 +
44192 + for_each_possible_cpu(cpu) {
44193 + per_cpu(exec_counter, cpu) = (u64)cpu;
44194 + }
44195 +
44196 + return 0;
44197 +}
44198 +early_initcall(init_exec_counters);
44199 +static inline void increment_exec_counter(void)
44200 +{
44201 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44202 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44203 +}
44204 +#else
44205 +static inline void increment_exec_counter(void) {}
44206 +#endif
44207 +
44208 /*
44209 * sys_execve() executes a new program.
44210 */
44211 @@ -1455,6 +1509,11 @@ static int do_execve_common(const char *filename,
44212 struct user_arg_ptr envp,
44213 struct pt_regs *regs)
44214 {
44215 +#ifdef CONFIG_GRKERNSEC
44216 + struct file *old_exec_file;
44217 + struct acl_subject_label *old_acl;
44218 + struct rlimit old_rlim[RLIM_NLIMITS];
44219 +#endif
44220 struct linux_binprm *bprm;
44221 struct file *file;
44222 struct files_struct *displaced;
44223 @@ -1462,6 +1521,8 @@ static int do_execve_common(const char *filename,
44224 int retval;
44225 const struct cred *cred = current_cred();
44226
44227 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44228 +
44229 /*
44230 * We move the actual failure in case of RLIMIT_NPROC excess from
44231 * set*uid() to execve() because too many poorly written programs
44232 @@ -1502,12 +1563,27 @@ static int do_execve_common(const char *filename,
44233 if (IS_ERR(file))
44234 goto out_unmark;
44235
44236 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44237 + retval = -EPERM;
44238 + goto out_file;
44239 + }
44240 +
44241 sched_exec();
44242
44243 bprm->file = file;
44244 bprm->filename = filename;
44245 bprm->interp = filename;
44246
44247 + if (gr_process_user_ban()) {
44248 + retval = -EPERM;
44249 + goto out_file;
44250 + }
44251 +
44252 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44253 + retval = -EACCES;
44254 + goto out_file;
44255 + }
44256 +
44257 retval = bprm_mm_init(bprm);
44258 if (retval)
44259 goto out_file;
44260 @@ -1524,24 +1600,65 @@ static int do_execve_common(const char *filename,
44261 if (retval < 0)
44262 goto out;
44263
44264 +#ifdef CONFIG_GRKERNSEC
44265 + old_acl = current->acl;
44266 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44267 + old_exec_file = current->exec_file;
44268 + get_file(file);
44269 + current->exec_file = file;
44270 +#endif
44271 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44272 + /* limit suid stack to 8MB
44273 + we saved the old limits above and will restore them if this exec fails
44274 + */
44275 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44276 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44277 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44278 +#endif
44279 +
44280 + if (!gr_tpe_allow(file)) {
44281 + retval = -EACCES;
44282 + goto out_fail;
44283 + }
44284 +
44285 + if (gr_check_crash_exec(file)) {
44286 + retval = -EACCES;
44287 + goto out_fail;
44288 + }
44289 +
44290 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44291 + bprm->unsafe);
44292 + if (retval < 0)
44293 + goto out_fail;
44294 +
44295 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44296 if (retval < 0)
44297 - goto out;
44298 + goto out_fail;
44299
44300 bprm->exec = bprm->p;
44301 retval = copy_strings(bprm->envc, envp, bprm);
44302 if (retval < 0)
44303 - goto out;
44304 + goto out_fail;
44305
44306 retval = copy_strings(bprm->argc, argv, bprm);
44307 if (retval < 0)
44308 - goto out;
44309 + goto out_fail;
44310 +
44311 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44312 +
44313 + gr_handle_exec_args(bprm, argv);
44314
44315 retval = search_binary_handler(bprm,regs);
44316 if (retval < 0)
44317 - goto out;
44318 + goto out_fail;
44319 +#ifdef CONFIG_GRKERNSEC
44320 + if (old_exec_file)
44321 + fput(old_exec_file);
44322 +#endif
44323
44324 /* execve succeeded */
44325 +
44326 + increment_exec_counter();
44327 current->fs->in_exec = 0;
44328 current->in_execve = 0;
44329 acct_update_integrals(current);
44330 @@ -1550,6 +1667,14 @@ static int do_execve_common(const char *filename,
44331 put_files_struct(displaced);
44332 return retval;
44333
44334 +out_fail:
44335 +#ifdef CONFIG_GRKERNSEC
44336 + current->acl = old_acl;
44337 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44338 + fput(current->exec_file);
44339 + current->exec_file = old_exec_file;
44340 +#endif
44341 +
44342 out:
44343 if (bprm->mm) {
44344 acct_arg_size(bprm, 0);
44345 @@ -1623,7 +1748,7 @@ static int expand_corename(struct core_name *cn)
44346 {
44347 char *old_corename = cn->corename;
44348
44349 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44350 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44351 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44352
44353 if (!cn->corename) {
44354 @@ -1720,7 +1845,7 @@ static int format_corename(struct core_name *cn, long signr)
44355 int pid_in_pattern = 0;
44356 int err = 0;
44357
44358 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44359 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44360 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44361 cn->used = 0;
44362
44363 @@ -1817,6 +1942,228 @@ out:
44364 return ispipe;
44365 }
44366
44367 +int pax_check_flags(unsigned long *flags)
44368 +{
44369 + int retval = 0;
44370 +
44371 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44372 + if (*flags & MF_PAX_SEGMEXEC)
44373 + {
44374 + *flags &= ~MF_PAX_SEGMEXEC;
44375 + retval = -EINVAL;
44376 + }
44377 +#endif
44378 +
44379 + if ((*flags & MF_PAX_PAGEEXEC)
44380 +
44381 +#ifdef CONFIG_PAX_PAGEEXEC
44382 + && (*flags & MF_PAX_SEGMEXEC)
44383 +#endif
44384 +
44385 + )
44386 + {
44387 + *flags &= ~MF_PAX_PAGEEXEC;
44388 + retval = -EINVAL;
44389 + }
44390 +
44391 + if ((*flags & MF_PAX_MPROTECT)
44392 +
44393 +#ifdef CONFIG_PAX_MPROTECT
44394 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44395 +#endif
44396 +
44397 + )
44398 + {
44399 + *flags &= ~MF_PAX_MPROTECT;
44400 + retval = -EINVAL;
44401 + }
44402 +
44403 + if ((*flags & MF_PAX_EMUTRAMP)
44404 +
44405 +#ifdef CONFIG_PAX_EMUTRAMP
44406 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44407 +#endif
44408 +
44409 + )
44410 + {
44411 + *flags &= ~MF_PAX_EMUTRAMP;
44412 + retval = -EINVAL;
44413 + }
44414 +
44415 + return retval;
44416 +}
44417 +
44418 +EXPORT_SYMBOL(pax_check_flags);
44419 +
44420 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44421 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44422 +{
44423 + struct task_struct *tsk = current;
44424 + struct mm_struct *mm = current->mm;
44425 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44426 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44427 + char *path_exec = NULL;
44428 + char *path_fault = NULL;
44429 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44430 +
44431 + if (buffer_exec && buffer_fault) {
44432 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44433 +
44434 + down_read(&mm->mmap_sem);
44435 + vma = mm->mmap;
44436 + while (vma && (!vma_exec || !vma_fault)) {
44437 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44438 + vma_exec = vma;
44439 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44440 + vma_fault = vma;
44441 + vma = vma->vm_next;
44442 + }
44443 + if (vma_exec) {
44444 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44445 + if (IS_ERR(path_exec))
44446 + path_exec = "<path too long>";
44447 + else {
44448 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44449 + if (path_exec) {
44450 + *path_exec = 0;
44451 + path_exec = buffer_exec;
44452 + } else
44453 + path_exec = "<path too long>";
44454 + }
44455 + }
44456 + if (vma_fault) {
44457 + start = vma_fault->vm_start;
44458 + end = vma_fault->vm_end;
44459 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44460 + if (vma_fault->vm_file) {
44461 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44462 + if (IS_ERR(path_fault))
44463 + path_fault = "<path too long>";
44464 + else {
44465 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44466 + if (path_fault) {
44467 + *path_fault = 0;
44468 + path_fault = buffer_fault;
44469 + } else
44470 + path_fault = "<path too long>";
44471 + }
44472 + } else
44473 + path_fault = "<anonymous mapping>";
44474 + }
44475 + up_read(&mm->mmap_sem);
44476 + }
44477 + if (tsk->signal->curr_ip)
44478 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44479 + else
44480 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44481 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44482 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44483 + task_uid(tsk), task_euid(tsk), pc, sp);
44484 + free_page((unsigned long)buffer_exec);
44485 + free_page((unsigned long)buffer_fault);
44486 + pax_report_insns(regs, pc, sp);
44487 + do_coredump(SIGKILL, SIGKILL, regs);
44488 +}
44489 +#endif
44490 +
44491 +#ifdef CONFIG_PAX_REFCOUNT
44492 +void pax_report_refcount_overflow(struct pt_regs *regs)
44493 +{
44494 + if (current->signal->curr_ip)
44495 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44496 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44497 + else
44498 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44499 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44500 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44501 + show_regs(regs);
44502 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44503 +}
44504 +#endif
44505 +
44506 +#ifdef CONFIG_PAX_USERCOPY
44507 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44508 +int object_is_on_stack(const void *obj, unsigned long len)
44509 +{
44510 + const void * const stack = task_stack_page(current);
44511 + const void * const stackend = stack + THREAD_SIZE;
44512 +
44513 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44514 + const void *frame = NULL;
44515 + const void *oldframe;
44516 +#endif
44517 +
44518 + if (obj + len < obj)
44519 + return -1;
44520 +
44521 + if (obj + len <= stack || stackend <= obj)
44522 + return 0;
44523 +
44524 + if (obj < stack || stackend < obj + len)
44525 + return -1;
44526 +
44527 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44528 + oldframe = __builtin_frame_address(1);
44529 + if (oldframe)
44530 + frame = __builtin_frame_address(2);
44531 + /*
44532 + low ----------------------------------------------> high
44533 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44534 + ^----------------^
44535 + allow copies only within here
44536 + */
44537 + while (stack <= frame && frame < stackend) {
44538 + /* if obj + len extends past the last frame, this
44539 + check won't pass and the next frame will be 0,
44540 + causing us to bail out and correctly report
44541 + the copy as invalid
44542 + */
44543 + if (obj + len <= frame)
44544 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44545 + oldframe = frame;
44546 + frame = *(const void * const *)frame;
44547 + }
44548 + return -1;
44549 +#else
44550 + return 1;
44551 +#endif
44552 +}
44553 +
44554 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44555 +{
44556 + if (current->signal->curr_ip)
44557 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44558 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44559 + else
44560 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44561 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44562 + dump_stack();
44563 + gr_handle_kernel_exploit();
44564 + do_group_exit(SIGKILL);
44565 +}
44566 +#endif
44567 +
44568 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44569 +void pax_track_stack(void)
44570 +{
44571 + unsigned long sp = (unsigned long)&sp;
44572 + if (sp < current_thread_info()->lowest_stack &&
44573 + sp > (unsigned long)task_stack_page(current))
44574 + current_thread_info()->lowest_stack = sp;
44575 +}
44576 +EXPORT_SYMBOL(pax_track_stack);
44577 +#endif
44578 +
44579 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44580 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44581 +{
44582 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44583 + dump_stack();
44584 + do_group_exit(SIGKILL);
44585 +}
44586 +EXPORT_SYMBOL(report_size_overflow);
44587 +#endif
44588 +
44589 static int zap_process(struct task_struct *start, int exit_code)
44590 {
44591 struct task_struct *t;
44592 @@ -2014,17 +2361,17 @@ static void wait_for_dump_helpers(struct file *file)
44593 pipe = file->f_path.dentry->d_inode->i_pipe;
44594
44595 pipe_lock(pipe);
44596 - pipe->readers++;
44597 - pipe->writers--;
44598 + atomic_inc(&pipe->readers);
44599 + atomic_dec(&pipe->writers);
44600
44601 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44602 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44603 wake_up_interruptible_sync(&pipe->wait);
44604 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44605 pipe_wait(pipe);
44606 }
44607
44608 - pipe->readers--;
44609 - pipe->writers++;
44610 + atomic_dec(&pipe->readers);
44611 + atomic_inc(&pipe->writers);
44612 pipe_unlock(pipe);
44613
44614 }
44615 @@ -2085,7 +2432,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44616 int retval = 0;
44617 int flag = 0;
44618 int ispipe;
44619 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44620 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44621 struct coredump_params cprm = {
44622 .signr = signr,
44623 .regs = regs,
44624 @@ -2100,6 +2447,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44625
44626 audit_core_dumps(signr);
44627
44628 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44629 + gr_handle_brute_attach(current, cprm.mm_flags);
44630 +
44631 binfmt = mm->binfmt;
44632 if (!binfmt || !binfmt->core_dump)
44633 goto fail;
44634 @@ -2167,7 +2517,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44635 }
44636 cprm.limit = RLIM_INFINITY;
44637
44638 - dump_count = atomic_inc_return(&core_dump_count);
44639 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44640 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44641 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44642 task_tgid_vnr(current), current->comm);
44643 @@ -2194,6 +2544,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44644 } else {
44645 struct inode *inode;
44646
44647 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44648 +
44649 if (cprm.limit < binfmt->min_coredump)
44650 goto fail_unlock;
44651
44652 @@ -2237,7 +2589,7 @@ close_fail:
44653 filp_close(cprm.file, NULL);
44654 fail_dropcount:
44655 if (ispipe)
44656 - atomic_dec(&core_dump_count);
44657 + atomic_dec_unchecked(&core_dump_count);
44658 fail_unlock:
44659 kfree(cn.corename);
44660 fail_corename:
44661 @@ -2256,7 +2608,7 @@ fail:
44662 */
44663 int dump_write(struct file *file, const void *addr, int nr)
44664 {
44665 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44666 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44667 }
44668 EXPORT_SYMBOL(dump_write);
44669
44670 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44671 index a8cbe1b..fed04cb 100644
44672 --- a/fs/ext2/balloc.c
44673 +++ b/fs/ext2/balloc.c
44674 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44675
44676 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44677 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44678 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44679 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44680 sbi->s_resuid != current_fsuid() &&
44681 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44682 return 0;
44683 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44684 index a203892..4e64db5 100644
44685 --- a/fs/ext3/balloc.c
44686 +++ b/fs/ext3/balloc.c
44687 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44688
44689 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44690 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44691 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44692 + if (free_blocks < root_blocks + 1 &&
44693 !use_reservation && sbi->s_resuid != current_fsuid() &&
44694 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44695 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44696 + !capable_nolog(CAP_SYS_RESOURCE)) {
44697 return 0;
44698 }
44699 return 1;
44700 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44701 index f9e2cd8..bfdc476 100644
44702 --- a/fs/ext4/balloc.c
44703 +++ b/fs/ext4/balloc.c
44704 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44705 /* Hm, nope. Are (enough) root reserved clusters available? */
44706 if (sbi->s_resuid == current_fsuid() ||
44707 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44708 - capable(CAP_SYS_RESOURCE) ||
44709 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44710 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44711 + capable_nolog(CAP_SYS_RESOURCE)) {
44712
44713 if (free_clusters >= (nclusters + dirty_clusters))
44714 return 1;
44715 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44716 index 9983ba8..2a5272c 100644
44717 --- a/fs/ext4/ext4.h
44718 +++ b/fs/ext4/ext4.h
44719 @@ -1217,19 +1217,19 @@ struct ext4_sb_info {
44720 unsigned long s_mb_last_start;
44721
44722 /* stats for buddy allocator */
44723 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44724 - atomic_t s_bal_success; /* we found long enough chunks */
44725 - atomic_t s_bal_allocated; /* in blocks */
44726 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44727 - atomic_t s_bal_goals; /* goal hits */
44728 - atomic_t s_bal_breaks; /* too long searches */
44729 - atomic_t s_bal_2orders; /* 2^order hits */
44730 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44731 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44732 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44733 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44734 + atomic_unchecked_t s_bal_goals; /* goal hits */
44735 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44736 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44737 spinlock_t s_bal_lock;
44738 unsigned long s_mb_buddies_generated;
44739 unsigned long long s_mb_generation_time;
44740 - atomic_t s_mb_lost_chunks;
44741 - atomic_t s_mb_preallocated;
44742 - atomic_t s_mb_discarded;
44743 + atomic_unchecked_t s_mb_lost_chunks;
44744 + atomic_unchecked_t s_mb_preallocated;
44745 + atomic_unchecked_t s_mb_discarded;
44746 atomic_t s_lock_busy;
44747
44748 /* locality groups */
44749 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44750 index cb990b2..4820141 100644
44751 --- a/fs/ext4/mballoc.c
44752 +++ b/fs/ext4/mballoc.c
44753 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44754 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44755
44756 if (EXT4_SB(sb)->s_mb_stats)
44757 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44758 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44759
44760 break;
44761 }
44762 @@ -2088,7 +2088,7 @@ repeat:
44763 ac->ac_status = AC_STATUS_CONTINUE;
44764 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44765 cr = 3;
44766 - atomic_inc(&sbi->s_mb_lost_chunks);
44767 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44768 goto repeat;
44769 }
44770 }
44771 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44772 if (sbi->s_mb_stats) {
44773 ext4_msg(sb, KERN_INFO,
44774 "mballoc: %u blocks %u reqs (%u success)",
44775 - atomic_read(&sbi->s_bal_allocated),
44776 - atomic_read(&sbi->s_bal_reqs),
44777 - atomic_read(&sbi->s_bal_success));
44778 + atomic_read_unchecked(&sbi->s_bal_allocated),
44779 + atomic_read_unchecked(&sbi->s_bal_reqs),
44780 + atomic_read_unchecked(&sbi->s_bal_success));
44781 ext4_msg(sb, KERN_INFO,
44782 "mballoc: %u extents scanned, %u goal hits, "
44783 "%u 2^N hits, %u breaks, %u lost",
44784 - atomic_read(&sbi->s_bal_ex_scanned),
44785 - atomic_read(&sbi->s_bal_goals),
44786 - atomic_read(&sbi->s_bal_2orders),
44787 - atomic_read(&sbi->s_bal_breaks),
44788 - atomic_read(&sbi->s_mb_lost_chunks));
44789 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44790 + atomic_read_unchecked(&sbi->s_bal_goals),
44791 + atomic_read_unchecked(&sbi->s_bal_2orders),
44792 + atomic_read_unchecked(&sbi->s_bal_breaks),
44793 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44794 ext4_msg(sb, KERN_INFO,
44795 "mballoc: %lu generated and it took %Lu",
44796 sbi->s_mb_buddies_generated,
44797 sbi->s_mb_generation_time);
44798 ext4_msg(sb, KERN_INFO,
44799 "mballoc: %u preallocated, %u discarded",
44800 - atomic_read(&sbi->s_mb_preallocated),
44801 - atomic_read(&sbi->s_mb_discarded));
44802 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44803 + atomic_read_unchecked(&sbi->s_mb_discarded));
44804 }
44805
44806 free_percpu(sbi->s_locality_groups);
44807 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44808 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44809
44810 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44811 - atomic_inc(&sbi->s_bal_reqs);
44812 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44813 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44814 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44815 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44816 - atomic_inc(&sbi->s_bal_success);
44817 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44818 + atomic_inc_unchecked(&sbi->s_bal_success);
44819 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44820 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44821 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44822 - atomic_inc(&sbi->s_bal_goals);
44823 + atomic_inc_unchecked(&sbi->s_bal_goals);
44824 if (ac->ac_found > sbi->s_mb_max_to_scan)
44825 - atomic_inc(&sbi->s_bal_breaks);
44826 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44827 }
44828
44829 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44830 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44831 trace_ext4_mb_new_inode_pa(ac, pa);
44832
44833 ext4_mb_use_inode_pa(ac, pa);
44834 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44835 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44836
44837 ei = EXT4_I(ac->ac_inode);
44838 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44839 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44840 trace_ext4_mb_new_group_pa(ac, pa);
44841
44842 ext4_mb_use_group_pa(ac, pa);
44843 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44844 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44845
44846 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44847 lg = ac->ac_lg;
44848 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44849 * from the bitmap and continue.
44850 */
44851 }
44852 - atomic_add(free, &sbi->s_mb_discarded);
44853 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44854
44855 return err;
44856 }
44857 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44858 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44859 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44860 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44861 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44862 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44863 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44864
44865 return 0;
44866 diff --git a/fs/fcntl.c b/fs/fcntl.c
44867 index 22764c7..86372c9 100644
44868 --- a/fs/fcntl.c
44869 +++ b/fs/fcntl.c
44870 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44871 if (err)
44872 return err;
44873
44874 + if (gr_handle_chroot_fowner(pid, type))
44875 + return -ENOENT;
44876 + if (gr_check_protected_task_fowner(pid, type))
44877 + return -EACCES;
44878 +
44879 f_modown(filp, pid, type, force);
44880 return 0;
44881 }
44882 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44883
44884 static int f_setown_ex(struct file *filp, unsigned long arg)
44885 {
44886 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44887 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44888 struct f_owner_ex owner;
44889 struct pid *pid;
44890 int type;
44891 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44892
44893 static int f_getown_ex(struct file *filp, unsigned long arg)
44894 {
44895 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44896 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44897 struct f_owner_ex owner;
44898 int ret = 0;
44899
44900 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44901 switch (cmd) {
44902 case F_DUPFD:
44903 case F_DUPFD_CLOEXEC:
44904 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44905 if (arg >= rlimit(RLIMIT_NOFILE))
44906 break;
44907 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44908 diff --git a/fs/fifo.c b/fs/fifo.c
44909 index b1a524d..4ee270e 100644
44910 --- a/fs/fifo.c
44911 +++ b/fs/fifo.c
44912 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44913 */
44914 filp->f_op = &read_pipefifo_fops;
44915 pipe->r_counter++;
44916 - if (pipe->readers++ == 0)
44917 + if (atomic_inc_return(&pipe->readers) == 1)
44918 wake_up_partner(inode);
44919
44920 - if (!pipe->writers) {
44921 + if (!atomic_read(&pipe->writers)) {
44922 if ((filp->f_flags & O_NONBLOCK)) {
44923 /* suppress POLLHUP until we have
44924 * seen a writer */
44925 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44926 * errno=ENXIO when there is no process reading the FIFO.
44927 */
44928 ret = -ENXIO;
44929 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44930 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44931 goto err;
44932
44933 filp->f_op = &write_pipefifo_fops;
44934 pipe->w_counter++;
44935 - if (!pipe->writers++)
44936 + if (atomic_inc_return(&pipe->writers) == 1)
44937 wake_up_partner(inode);
44938
44939 - if (!pipe->readers) {
44940 + if (!atomic_read(&pipe->readers)) {
44941 wait_for_partner(inode, &pipe->r_counter);
44942 if (signal_pending(current))
44943 goto err_wr;
44944 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44945 */
44946 filp->f_op = &rdwr_pipefifo_fops;
44947
44948 - pipe->readers++;
44949 - pipe->writers++;
44950 + atomic_inc(&pipe->readers);
44951 + atomic_inc(&pipe->writers);
44952 pipe->r_counter++;
44953 pipe->w_counter++;
44954 - if (pipe->readers == 1 || pipe->writers == 1)
44955 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44956 wake_up_partner(inode);
44957 break;
44958
44959 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44960 return 0;
44961
44962 err_rd:
44963 - if (!--pipe->readers)
44964 + if (atomic_dec_and_test(&pipe->readers))
44965 wake_up_interruptible(&pipe->wait);
44966 ret = -ERESTARTSYS;
44967 goto err;
44968
44969 err_wr:
44970 - if (!--pipe->writers)
44971 + if (atomic_dec_and_test(&pipe->writers))
44972 wake_up_interruptible(&pipe->wait);
44973 ret = -ERESTARTSYS;
44974 goto err;
44975
44976 err:
44977 - if (!pipe->readers && !pipe->writers)
44978 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44979 free_pipe_info(inode);
44980
44981 err_nocleanup:
44982 diff --git a/fs/file.c b/fs/file.c
44983 index 4c6992d..104cdea 100644
44984 --- a/fs/file.c
44985 +++ b/fs/file.c
44986 @@ -15,6 +15,7 @@
44987 #include <linux/slab.h>
44988 #include <linux/vmalloc.h>
44989 #include <linux/file.h>
44990 +#include <linux/security.h>
44991 #include <linux/fdtable.h>
44992 #include <linux/bitops.h>
44993 #include <linux/interrupt.h>
44994 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
44995 * N.B. For clone tasks sharing a files structure, this test
44996 * will limit the total number of files that can be opened.
44997 */
44998 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44999 if (nr >= rlimit(RLIMIT_NOFILE))
45000 return -EMFILE;
45001
45002 diff --git a/fs/filesystems.c b/fs/filesystems.c
45003 index 96f2428..f5eeb8e 100644
45004 --- a/fs/filesystems.c
45005 +++ b/fs/filesystems.c
45006 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45007 int len = dot ? dot - name : strlen(name);
45008
45009 fs = __get_fs_type(name, len);
45010 +
45011 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45012 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45013 +#else
45014 if (!fs && (request_module("%.*s", len, name) == 0))
45015 +#endif
45016 fs = __get_fs_type(name, len);
45017
45018 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45019 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45020 index 78b519c..a8b4979 100644
45021 --- a/fs/fs_struct.c
45022 +++ b/fs/fs_struct.c
45023 @@ -4,6 +4,7 @@
45024 #include <linux/path.h>
45025 #include <linux/slab.h>
45026 #include <linux/fs_struct.h>
45027 +#include <linux/grsecurity.h>
45028 #include "internal.h"
45029
45030 static inline void path_get_longterm(struct path *path)
45031 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45032 old_root = fs->root;
45033 fs->root = *path;
45034 path_get_longterm(path);
45035 + gr_set_chroot_entries(current, path);
45036 write_seqcount_end(&fs->seq);
45037 spin_unlock(&fs->lock);
45038 if (old_root.dentry)
45039 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45040 && fs->root.mnt == old_root->mnt) {
45041 path_get_longterm(new_root);
45042 fs->root = *new_root;
45043 + gr_set_chroot_entries(p, new_root);
45044 count++;
45045 }
45046 if (fs->pwd.dentry == old_root->dentry
45047 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45048 spin_lock(&fs->lock);
45049 write_seqcount_begin(&fs->seq);
45050 tsk->fs = NULL;
45051 - kill = !--fs->users;
45052 + gr_clear_chroot_entries(tsk);
45053 + kill = !atomic_dec_return(&fs->users);
45054 write_seqcount_end(&fs->seq);
45055 spin_unlock(&fs->lock);
45056 task_unlock(tsk);
45057 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45058 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45059 /* We don't need to lock fs - think why ;-) */
45060 if (fs) {
45061 - fs->users = 1;
45062 + atomic_set(&fs->users, 1);
45063 fs->in_exec = 0;
45064 spin_lock_init(&fs->lock);
45065 seqcount_init(&fs->seq);
45066 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45067 spin_lock(&old->lock);
45068 fs->root = old->root;
45069 path_get_longterm(&fs->root);
45070 + /* instead of calling gr_set_chroot_entries here,
45071 + we call it from every caller of this function
45072 + */
45073 fs->pwd = old->pwd;
45074 path_get_longterm(&fs->pwd);
45075 spin_unlock(&old->lock);
45076 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45077
45078 task_lock(current);
45079 spin_lock(&fs->lock);
45080 - kill = !--fs->users;
45081 + kill = !atomic_dec_return(&fs->users);
45082 current->fs = new_fs;
45083 + gr_set_chroot_entries(current, &new_fs->root);
45084 spin_unlock(&fs->lock);
45085 task_unlock(current);
45086
45087 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45088
45089 int current_umask(void)
45090 {
45091 - return current->fs->umask;
45092 + return current->fs->umask | gr_acl_umask();
45093 }
45094 EXPORT_SYMBOL(current_umask);
45095
45096 /* to be mentioned only in INIT_TASK */
45097 struct fs_struct init_fs = {
45098 - .users = 1,
45099 + .users = ATOMIC_INIT(1),
45100 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45101 .seq = SEQCNT_ZERO,
45102 .umask = 0022,
45103 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45104 task_lock(current);
45105
45106 spin_lock(&init_fs.lock);
45107 - init_fs.users++;
45108 + atomic_inc(&init_fs.users);
45109 spin_unlock(&init_fs.lock);
45110
45111 spin_lock(&fs->lock);
45112 current->fs = &init_fs;
45113 - kill = !--fs->users;
45114 + gr_set_chroot_entries(current, &current->fs->root);
45115 + kill = !atomic_dec_return(&fs->users);
45116 spin_unlock(&fs->lock);
45117
45118 task_unlock(current);
45119 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45120 index 9905350..02eaec4 100644
45121 --- a/fs/fscache/cookie.c
45122 +++ b/fs/fscache/cookie.c
45123 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45124 parent ? (char *) parent->def->name : "<no-parent>",
45125 def->name, netfs_data);
45126
45127 - fscache_stat(&fscache_n_acquires);
45128 + fscache_stat_unchecked(&fscache_n_acquires);
45129
45130 /* if there's no parent cookie, then we don't create one here either */
45131 if (!parent) {
45132 - fscache_stat(&fscache_n_acquires_null);
45133 + fscache_stat_unchecked(&fscache_n_acquires_null);
45134 _leave(" [no parent]");
45135 return NULL;
45136 }
45137 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45138 /* allocate and initialise a cookie */
45139 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45140 if (!cookie) {
45141 - fscache_stat(&fscache_n_acquires_oom);
45142 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45143 _leave(" [ENOMEM]");
45144 return NULL;
45145 }
45146 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45147
45148 switch (cookie->def->type) {
45149 case FSCACHE_COOKIE_TYPE_INDEX:
45150 - fscache_stat(&fscache_n_cookie_index);
45151 + fscache_stat_unchecked(&fscache_n_cookie_index);
45152 break;
45153 case FSCACHE_COOKIE_TYPE_DATAFILE:
45154 - fscache_stat(&fscache_n_cookie_data);
45155 + fscache_stat_unchecked(&fscache_n_cookie_data);
45156 break;
45157 default:
45158 - fscache_stat(&fscache_n_cookie_special);
45159 + fscache_stat_unchecked(&fscache_n_cookie_special);
45160 break;
45161 }
45162
45163 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45164 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45165 atomic_dec(&parent->n_children);
45166 __fscache_cookie_put(cookie);
45167 - fscache_stat(&fscache_n_acquires_nobufs);
45168 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45169 _leave(" = NULL");
45170 return NULL;
45171 }
45172 }
45173
45174 - fscache_stat(&fscache_n_acquires_ok);
45175 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45176 _leave(" = %p", cookie);
45177 return cookie;
45178 }
45179 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45180 cache = fscache_select_cache_for_object(cookie->parent);
45181 if (!cache) {
45182 up_read(&fscache_addremove_sem);
45183 - fscache_stat(&fscache_n_acquires_no_cache);
45184 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45185 _leave(" = -ENOMEDIUM [no cache]");
45186 return -ENOMEDIUM;
45187 }
45188 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45189 object = cache->ops->alloc_object(cache, cookie);
45190 fscache_stat_d(&fscache_n_cop_alloc_object);
45191 if (IS_ERR(object)) {
45192 - fscache_stat(&fscache_n_object_no_alloc);
45193 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45194 ret = PTR_ERR(object);
45195 goto error;
45196 }
45197
45198 - fscache_stat(&fscache_n_object_alloc);
45199 + fscache_stat_unchecked(&fscache_n_object_alloc);
45200
45201 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45202
45203 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45204 struct fscache_object *object;
45205 struct hlist_node *_p;
45206
45207 - fscache_stat(&fscache_n_updates);
45208 + fscache_stat_unchecked(&fscache_n_updates);
45209
45210 if (!cookie) {
45211 - fscache_stat(&fscache_n_updates_null);
45212 + fscache_stat_unchecked(&fscache_n_updates_null);
45213 _leave(" [no cookie]");
45214 return;
45215 }
45216 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45217 struct fscache_object *object;
45218 unsigned long event;
45219
45220 - fscache_stat(&fscache_n_relinquishes);
45221 + fscache_stat_unchecked(&fscache_n_relinquishes);
45222 if (retire)
45223 - fscache_stat(&fscache_n_relinquishes_retire);
45224 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45225
45226 if (!cookie) {
45227 - fscache_stat(&fscache_n_relinquishes_null);
45228 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45229 _leave(" [no cookie]");
45230 return;
45231 }
45232 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45233
45234 /* wait for the cookie to finish being instantiated (or to fail) */
45235 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45236 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45237 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45238 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45239 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45240 }
45241 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45242 index f6aad48..88dcf26 100644
45243 --- a/fs/fscache/internal.h
45244 +++ b/fs/fscache/internal.h
45245 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45246 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45247 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45248
45249 -extern atomic_t fscache_n_op_pend;
45250 -extern atomic_t fscache_n_op_run;
45251 -extern atomic_t fscache_n_op_enqueue;
45252 -extern atomic_t fscache_n_op_deferred_release;
45253 -extern atomic_t fscache_n_op_release;
45254 -extern atomic_t fscache_n_op_gc;
45255 -extern atomic_t fscache_n_op_cancelled;
45256 -extern atomic_t fscache_n_op_rejected;
45257 +extern atomic_unchecked_t fscache_n_op_pend;
45258 +extern atomic_unchecked_t fscache_n_op_run;
45259 +extern atomic_unchecked_t fscache_n_op_enqueue;
45260 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45261 +extern atomic_unchecked_t fscache_n_op_release;
45262 +extern atomic_unchecked_t fscache_n_op_gc;
45263 +extern atomic_unchecked_t fscache_n_op_cancelled;
45264 +extern atomic_unchecked_t fscache_n_op_rejected;
45265
45266 -extern atomic_t fscache_n_attr_changed;
45267 -extern atomic_t fscache_n_attr_changed_ok;
45268 -extern atomic_t fscache_n_attr_changed_nobufs;
45269 -extern atomic_t fscache_n_attr_changed_nomem;
45270 -extern atomic_t fscache_n_attr_changed_calls;
45271 +extern atomic_unchecked_t fscache_n_attr_changed;
45272 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45273 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45274 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45275 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45276
45277 -extern atomic_t fscache_n_allocs;
45278 -extern atomic_t fscache_n_allocs_ok;
45279 -extern atomic_t fscache_n_allocs_wait;
45280 -extern atomic_t fscache_n_allocs_nobufs;
45281 -extern atomic_t fscache_n_allocs_intr;
45282 -extern atomic_t fscache_n_allocs_object_dead;
45283 -extern atomic_t fscache_n_alloc_ops;
45284 -extern atomic_t fscache_n_alloc_op_waits;
45285 +extern atomic_unchecked_t fscache_n_allocs;
45286 +extern atomic_unchecked_t fscache_n_allocs_ok;
45287 +extern atomic_unchecked_t fscache_n_allocs_wait;
45288 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45289 +extern atomic_unchecked_t fscache_n_allocs_intr;
45290 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45291 +extern atomic_unchecked_t fscache_n_alloc_ops;
45292 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45293
45294 -extern atomic_t fscache_n_retrievals;
45295 -extern atomic_t fscache_n_retrievals_ok;
45296 -extern atomic_t fscache_n_retrievals_wait;
45297 -extern atomic_t fscache_n_retrievals_nodata;
45298 -extern atomic_t fscache_n_retrievals_nobufs;
45299 -extern atomic_t fscache_n_retrievals_intr;
45300 -extern atomic_t fscache_n_retrievals_nomem;
45301 -extern atomic_t fscache_n_retrievals_object_dead;
45302 -extern atomic_t fscache_n_retrieval_ops;
45303 -extern atomic_t fscache_n_retrieval_op_waits;
45304 +extern atomic_unchecked_t fscache_n_retrievals;
45305 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45306 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45307 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45308 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45309 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45310 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45311 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45312 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45313 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45314
45315 -extern atomic_t fscache_n_stores;
45316 -extern atomic_t fscache_n_stores_ok;
45317 -extern atomic_t fscache_n_stores_again;
45318 -extern atomic_t fscache_n_stores_nobufs;
45319 -extern atomic_t fscache_n_stores_oom;
45320 -extern atomic_t fscache_n_store_ops;
45321 -extern atomic_t fscache_n_store_calls;
45322 -extern atomic_t fscache_n_store_pages;
45323 -extern atomic_t fscache_n_store_radix_deletes;
45324 -extern atomic_t fscache_n_store_pages_over_limit;
45325 +extern atomic_unchecked_t fscache_n_stores;
45326 +extern atomic_unchecked_t fscache_n_stores_ok;
45327 +extern atomic_unchecked_t fscache_n_stores_again;
45328 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45329 +extern atomic_unchecked_t fscache_n_stores_oom;
45330 +extern atomic_unchecked_t fscache_n_store_ops;
45331 +extern atomic_unchecked_t fscache_n_store_calls;
45332 +extern atomic_unchecked_t fscache_n_store_pages;
45333 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45334 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45335
45336 -extern atomic_t fscache_n_store_vmscan_not_storing;
45337 -extern atomic_t fscache_n_store_vmscan_gone;
45338 -extern atomic_t fscache_n_store_vmscan_busy;
45339 -extern atomic_t fscache_n_store_vmscan_cancelled;
45340 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45341 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45342 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45343 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45344
45345 -extern atomic_t fscache_n_marks;
45346 -extern atomic_t fscache_n_uncaches;
45347 +extern atomic_unchecked_t fscache_n_marks;
45348 +extern atomic_unchecked_t fscache_n_uncaches;
45349
45350 -extern atomic_t fscache_n_acquires;
45351 -extern atomic_t fscache_n_acquires_null;
45352 -extern atomic_t fscache_n_acquires_no_cache;
45353 -extern atomic_t fscache_n_acquires_ok;
45354 -extern atomic_t fscache_n_acquires_nobufs;
45355 -extern atomic_t fscache_n_acquires_oom;
45356 +extern atomic_unchecked_t fscache_n_acquires;
45357 +extern atomic_unchecked_t fscache_n_acquires_null;
45358 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45359 +extern atomic_unchecked_t fscache_n_acquires_ok;
45360 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45361 +extern atomic_unchecked_t fscache_n_acquires_oom;
45362
45363 -extern atomic_t fscache_n_updates;
45364 -extern atomic_t fscache_n_updates_null;
45365 -extern atomic_t fscache_n_updates_run;
45366 +extern atomic_unchecked_t fscache_n_updates;
45367 +extern atomic_unchecked_t fscache_n_updates_null;
45368 +extern atomic_unchecked_t fscache_n_updates_run;
45369
45370 -extern atomic_t fscache_n_relinquishes;
45371 -extern atomic_t fscache_n_relinquishes_null;
45372 -extern atomic_t fscache_n_relinquishes_waitcrt;
45373 -extern atomic_t fscache_n_relinquishes_retire;
45374 +extern atomic_unchecked_t fscache_n_relinquishes;
45375 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45376 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45377 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45378
45379 -extern atomic_t fscache_n_cookie_index;
45380 -extern atomic_t fscache_n_cookie_data;
45381 -extern atomic_t fscache_n_cookie_special;
45382 +extern atomic_unchecked_t fscache_n_cookie_index;
45383 +extern atomic_unchecked_t fscache_n_cookie_data;
45384 +extern atomic_unchecked_t fscache_n_cookie_special;
45385
45386 -extern atomic_t fscache_n_object_alloc;
45387 -extern atomic_t fscache_n_object_no_alloc;
45388 -extern atomic_t fscache_n_object_lookups;
45389 -extern atomic_t fscache_n_object_lookups_negative;
45390 -extern atomic_t fscache_n_object_lookups_positive;
45391 -extern atomic_t fscache_n_object_lookups_timed_out;
45392 -extern atomic_t fscache_n_object_created;
45393 -extern atomic_t fscache_n_object_avail;
45394 -extern atomic_t fscache_n_object_dead;
45395 +extern atomic_unchecked_t fscache_n_object_alloc;
45396 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45397 +extern atomic_unchecked_t fscache_n_object_lookups;
45398 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45399 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45400 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45401 +extern atomic_unchecked_t fscache_n_object_created;
45402 +extern atomic_unchecked_t fscache_n_object_avail;
45403 +extern atomic_unchecked_t fscache_n_object_dead;
45404
45405 -extern atomic_t fscache_n_checkaux_none;
45406 -extern atomic_t fscache_n_checkaux_okay;
45407 -extern atomic_t fscache_n_checkaux_update;
45408 -extern atomic_t fscache_n_checkaux_obsolete;
45409 +extern atomic_unchecked_t fscache_n_checkaux_none;
45410 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45411 +extern atomic_unchecked_t fscache_n_checkaux_update;
45412 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45413
45414 extern atomic_t fscache_n_cop_alloc_object;
45415 extern atomic_t fscache_n_cop_lookup_object;
45416 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45417 atomic_inc(stat);
45418 }
45419
45420 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45421 +{
45422 + atomic_inc_unchecked(stat);
45423 +}
45424 +
45425 static inline void fscache_stat_d(atomic_t *stat)
45426 {
45427 atomic_dec(stat);
45428 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45429
45430 #define __fscache_stat(stat) (NULL)
45431 #define fscache_stat(stat) do {} while (0)
45432 +#define fscache_stat_unchecked(stat) do {} while (0)
45433 #define fscache_stat_d(stat) do {} while (0)
45434 #endif
45435
45436 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45437 index b6b897c..0ffff9c 100644
45438 --- a/fs/fscache/object.c
45439 +++ b/fs/fscache/object.c
45440 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45441 /* update the object metadata on disk */
45442 case FSCACHE_OBJECT_UPDATING:
45443 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45444 - fscache_stat(&fscache_n_updates_run);
45445 + fscache_stat_unchecked(&fscache_n_updates_run);
45446 fscache_stat(&fscache_n_cop_update_object);
45447 object->cache->ops->update_object(object);
45448 fscache_stat_d(&fscache_n_cop_update_object);
45449 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45450 spin_lock(&object->lock);
45451 object->state = FSCACHE_OBJECT_DEAD;
45452 spin_unlock(&object->lock);
45453 - fscache_stat(&fscache_n_object_dead);
45454 + fscache_stat_unchecked(&fscache_n_object_dead);
45455 goto terminal_transit;
45456
45457 /* handle the parent cache of this object being withdrawn from
45458 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45459 spin_lock(&object->lock);
45460 object->state = FSCACHE_OBJECT_DEAD;
45461 spin_unlock(&object->lock);
45462 - fscache_stat(&fscache_n_object_dead);
45463 + fscache_stat_unchecked(&fscache_n_object_dead);
45464 goto terminal_transit;
45465
45466 /* complain about the object being woken up once it is
45467 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45468 parent->cookie->def->name, cookie->def->name,
45469 object->cache->tag->name);
45470
45471 - fscache_stat(&fscache_n_object_lookups);
45472 + fscache_stat_unchecked(&fscache_n_object_lookups);
45473 fscache_stat(&fscache_n_cop_lookup_object);
45474 ret = object->cache->ops->lookup_object(object);
45475 fscache_stat_d(&fscache_n_cop_lookup_object);
45476 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45477 if (ret == -ETIMEDOUT) {
45478 /* probably stuck behind another object, so move this one to
45479 * the back of the queue */
45480 - fscache_stat(&fscache_n_object_lookups_timed_out);
45481 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45482 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45483 }
45484
45485 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45486
45487 spin_lock(&object->lock);
45488 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45489 - fscache_stat(&fscache_n_object_lookups_negative);
45490 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45491
45492 /* transit here to allow write requests to begin stacking up
45493 * and read requests to begin returning ENODATA */
45494 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45495 * result, in which case there may be data available */
45496 spin_lock(&object->lock);
45497 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45498 - fscache_stat(&fscache_n_object_lookups_positive);
45499 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45500
45501 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45502
45503 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45504 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45505 } else {
45506 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45507 - fscache_stat(&fscache_n_object_created);
45508 + fscache_stat_unchecked(&fscache_n_object_created);
45509
45510 object->state = FSCACHE_OBJECT_AVAILABLE;
45511 spin_unlock(&object->lock);
45512 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45513 fscache_enqueue_dependents(object);
45514
45515 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45516 - fscache_stat(&fscache_n_object_avail);
45517 + fscache_stat_unchecked(&fscache_n_object_avail);
45518
45519 _leave("");
45520 }
45521 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45522 enum fscache_checkaux result;
45523
45524 if (!object->cookie->def->check_aux) {
45525 - fscache_stat(&fscache_n_checkaux_none);
45526 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45527 return FSCACHE_CHECKAUX_OKAY;
45528 }
45529
45530 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45531 switch (result) {
45532 /* entry okay as is */
45533 case FSCACHE_CHECKAUX_OKAY:
45534 - fscache_stat(&fscache_n_checkaux_okay);
45535 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45536 break;
45537
45538 /* entry requires update */
45539 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45540 - fscache_stat(&fscache_n_checkaux_update);
45541 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45542 break;
45543
45544 /* entry requires deletion */
45545 case FSCACHE_CHECKAUX_OBSOLETE:
45546 - fscache_stat(&fscache_n_checkaux_obsolete);
45547 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45548 break;
45549
45550 default:
45551 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45552 index 30afdfa..2256596 100644
45553 --- a/fs/fscache/operation.c
45554 +++ b/fs/fscache/operation.c
45555 @@ -17,7 +17,7 @@
45556 #include <linux/slab.h>
45557 #include "internal.h"
45558
45559 -atomic_t fscache_op_debug_id;
45560 +atomic_unchecked_t fscache_op_debug_id;
45561 EXPORT_SYMBOL(fscache_op_debug_id);
45562
45563 /**
45564 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45565 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45566 ASSERTCMP(atomic_read(&op->usage), >, 0);
45567
45568 - fscache_stat(&fscache_n_op_enqueue);
45569 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45570 switch (op->flags & FSCACHE_OP_TYPE) {
45571 case FSCACHE_OP_ASYNC:
45572 _debug("queue async");
45573 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45574 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45575 if (op->processor)
45576 fscache_enqueue_operation(op);
45577 - fscache_stat(&fscache_n_op_run);
45578 + fscache_stat_unchecked(&fscache_n_op_run);
45579 }
45580
45581 /*
45582 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45583 if (object->n_ops > 1) {
45584 atomic_inc(&op->usage);
45585 list_add_tail(&op->pend_link, &object->pending_ops);
45586 - fscache_stat(&fscache_n_op_pend);
45587 + fscache_stat_unchecked(&fscache_n_op_pend);
45588 } else if (!list_empty(&object->pending_ops)) {
45589 atomic_inc(&op->usage);
45590 list_add_tail(&op->pend_link, &object->pending_ops);
45591 - fscache_stat(&fscache_n_op_pend);
45592 + fscache_stat_unchecked(&fscache_n_op_pend);
45593 fscache_start_operations(object);
45594 } else {
45595 ASSERTCMP(object->n_in_progress, ==, 0);
45596 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45597 object->n_exclusive++; /* reads and writes must wait */
45598 atomic_inc(&op->usage);
45599 list_add_tail(&op->pend_link, &object->pending_ops);
45600 - fscache_stat(&fscache_n_op_pend);
45601 + fscache_stat_unchecked(&fscache_n_op_pend);
45602 ret = 0;
45603 } else {
45604 /* not allowed to submit ops in any other state */
45605 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45606 if (object->n_exclusive > 0) {
45607 atomic_inc(&op->usage);
45608 list_add_tail(&op->pend_link, &object->pending_ops);
45609 - fscache_stat(&fscache_n_op_pend);
45610 + fscache_stat_unchecked(&fscache_n_op_pend);
45611 } else if (!list_empty(&object->pending_ops)) {
45612 atomic_inc(&op->usage);
45613 list_add_tail(&op->pend_link, &object->pending_ops);
45614 - fscache_stat(&fscache_n_op_pend);
45615 + fscache_stat_unchecked(&fscache_n_op_pend);
45616 fscache_start_operations(object);
45617 } else {
45618 ASSERTCMP(object->n_exclusive, ==, 0);
45619 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45620 object->n_ops++;
45621 atomic_inc(&op->usage);
45622 list_add_tail(&op->pend_link, &object->pending_ops);
45623 - fscache_stat(&fscache_n_op_pend);
45624 + fscache_stat_unchecked(&fscache_n_op_pend);
45625 ret = 0;
45626 } else if (object->state == FSCACHE_OBJECT_DYING ||
45627 object->state == FSCACHE_OBJECT_LC_DYING ||
45628 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45629 - fscache_stat(&fscache_n_op_rejected);
45630 + fscache_stat_unchecked(&fscache_n_op_rejected);
45631 ret = -ENOBUFS;
45632 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45633 fscache_report_unexpected_submission(object, op, ostate);
45634 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45635
45636 ret = -EBUSY;
45637 if (!list_empty(&op->pend_link)) {
45638 - fscache_stat(&fscache_n_op_cancelled);
45639 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45640 list_del_init(&op->pend_link);
45641 object->n_ops--;
45642 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45643 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45644 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45645 BUG();
45646
45647 - fscache_stat(&fscache_n_op_release);
45648 + fscache_stat_unchecked(&fscache_n_op_release);
45649
45650 if (op->release) {
45651 op->release(op);
45652 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45653 * lock, and defer it otherwise */
45654 if (!spin_trylock(&object->lock)) {
45655 _debug("defer put");
45656 - fscache_stat(&fscache_n_op_deferred_release);
45657 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45658
45659 cache = object->cache;
45660 spin_lock(&cache->op_gc_list_lock);
45661 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45662
45663 _debug("GC DEFERRED REL OBJ%x OP%x",
45664 object->debug_id, op->debug_id);
45665 - fscache_stat(&fscache_n_op_gc);
45666 + fscache_stat_unchecked(&fscache_n_op_gc);
45667
45668 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45669
45670 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45671 index 3f7a59b..cf196cc 100644
45672 --- a/fs/fscache/page.c
45673 +++ b/fs/fscache/page.c
45674 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45675 val = radix_tree_lookup(&cookie->stores, page->index);
45676 if (!val) {
45677 rcu_read_unlock();
45678 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45679 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45680 __fscache_uncache_page(cookie, page);
45681 return true;
45682 }
45683 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45684 spin_unlock(&cookie->stores_lock);
45685
45686 if (xpage) {
45687 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45688 - fscache_stat(&fscache_n_store_radix_deletes);
45689 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45690 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45691 ASSERTCMP(xpage, ==, page);
45692 } else {
45693 - fscache_stat(&fscache_n_store_vmscan_gone);
45694 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45695 }
45696
45697 wake_up_bit(&cookie->flags, 0);
45698 @@ -107,7 +107,7 @@ page_busy:
45699 /* we might want to wait here, but that could deadlock the allocator as
45700 * the work threads writing to the cache may all end up sleeping
45701 * on memory allocation */
45702 - fscache_stat(&fscache_n_store_vmscan_busy);
45703 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45704 return false;
45705 }
45706 EXPORT_SYMBOL(__fscache_maybe_release_page);
45707 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45708 FSCACHE_COOKIE_STORING_TAG);
45709 if (!radix_tree_tag_get(&cookie->stores, page->index,
45710 FSCACHE_COOKIE_PENDING_TAG)) {
45711 - fscache_stat(&fscache_n_store_radix_deletes);
45712 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45713 xpage = radix_tree_delete(&cookie->stores, page->index);
45714 }
45715 spin_unlock(&cookie->stores_lock);
45716 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45717
45718 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45719
45720 - fscache_stat(&fscache_n_attr_changed_calls);
45721 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45722
45723 if (fscache_object_is_active(object)) {
45724 fscache_stat(&fscache_n_cop_attr_changed);
45725 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45726
45727 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45728
45729 - fscache_stat(&fscache_n_attr_changed);
45730 + fscache_stat_unchecked(&fscache_n_attr_changed);
45731
45732 op = kzalloc(sizeof(*op), GFP_KERNEL);
45733 if (!op) {
45734 - fscache_stat(&fscache_n_attr_changed_nomem);
45735 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45736 _leave(" = -ENOMEM");
45737 return -ENOMEM;
45738 }
45739 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45740 if (fscache_submit_exclusive_op(object, op) < 0)
45741 goto nobufs;
45742 spin_unlock(&cookie->lock);
45743 - fscache_stat(&fscache_n_attr_changed_ok);
45744 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45745 fscache_put_operation(op);
45746 _leave(" = 0");
45747 return 0;
45748 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45749 nobufs:
45750 spin_unlock(&cookie->lock);
45751 kfree(op);
45752 - fscache_stat(&fscache_n_attr_changed_nobufs);
45753 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45754 _leave(" = %d", -ENOBUFS);
45755 return -ENOBUFS;
45756 }
45757 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45758 /* allocate a retrieval operation and attempt to submit it */
45759 op = kzalloc(sizeof(*op), GFP_NOIO);
45760 if (!op) {
45761 - fscache_stat(&fscache_n_retrievals_nomem);
45762 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45763 return NULL;
45764 }
45765
45766 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45767 return 0;
45768 }
45769
45770 - fscache_stat(&fscache_n_retrievals_wait);
45771 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45772
45773 jif = jiffies;
45774 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45775 fscache_wait_bit_interruptible,
45776 TASK_INTERRUPTIBLE) != 0) {
45777 - fscache_stat(&fscache_n_retrievals_intr);
45778 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45779 _leave(" = -ERESTARTSYS");
45780 return -ERESTARTSYS;
45781 }
45782 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45783 */
45784 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45785 struct fscache_retrieval *op,
45786 - atomic_t *stat_op_waits,
45787 - atomic_t *stat_object_dead)
45788 + atomic_unchecked_t *stat_op_waits,
45789 + atomic_unchecked_t *stat_object_dead)
45790 {
45791 int ret;
45792
45793 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45794 goto check_if_dead;
45795
45796 _debug(">>> WT");
45797 - fscache_stat(stat_op_waits);
45798 + fscache_stat_unchecked(stat_op_waits);
45799 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45800 fscache_wait_bit_interruptible,
45801 TASK_INTERRUPTIBLE) < 0) {
45802 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45803
45804 check_if_dead:
45805 if (unlikely(fscache_object_is_dead(object))) {
45806 - fscache_stat(stat_object_dead);
45807 + fscache_stat_unchecked(stat_object_dead);
45808 return -ENOBUFS;
45809 }
45810 return 0;
45811 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45812
45813 _enter("%p,%p,,,", cookie, page);
45814
45815 - fscache_stat(&fscache_n_retrievals);
45816 + fscache_stat_unchecked(&fscache_n_retrievals);
45817
45818 if (hlist_empty(&cookie->backing_objects))
45819 goto nobufs;
45820 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45821 goto nobufs_unlock;
45822 spin_unlock(&cookie->lock);
45823
45824 - fscache_stat(&fscache_n_retrieval_ops);
45825 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45826
45827 /* pin the netfs read context in case we need to do the actual netfs
45828 * read because we've encountered a cache read failure */
45829 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45830
45831 error:
45832 if (ret == -ENOMEM)
45833 - fscache_stat(&fscache_n_retrievals_nomem);
45834 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45835 else if (ret == -ERESTARTSYS)
45836 - fscache_stat(&fscache_n_retrievals_intr);
45837 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45838 else if (ret == -ENODATA)
45839 - fscache_stat(&fscache_n_retrievals_nodata);
45840 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45841 else if (ret < 0)
45842 - fscache_stat(&fscache_n_retrievals_nobufs);
45843 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45844 else
45845 - fscache_stat(&fscache_n_retrievals_ok);
45846 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45847
45848 fscache_put_retrieval(op);
45849 _leave(" = %d", ret);
45850 @@ -429,7 +429,7 @@ nobufs_unlock:
45851 spin_unlock(&cookie->lock);
45852 kfree(op);
45853 nobufs:
45854 - fscache_stat(&fscache_n_retrievals_nobufs);
45855 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45856 _leave(" = -ENOBUFS");
45857 return -ENOBUFS;
45858 }
45859 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45860
45861 _enter("%p,,%d,,,", cookie, *nr_pages);
45862
45863 - fscache_stat(&fscache_n_retrievals);
45864 + fscache_stat_unchecked(&fscache_n_retrievals);
45865
45866 if (hlist_empty(&cookie->backing_objects))
45867 goto nobufs;
45868 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45869 goto nobufs_unlock;
45870 spin_unlock(&cookie->lock);
45871
45872 - fscache_stat(&fscache_n_retrieval_ops);
45873 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45874
45875 /* pin the netfs read context in case we need to do the actual netfs
45876 * read because we've encountered a cache read failure */
45877 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45878
45879 error:
45880 if (ret == -ENOMEM)
45881 - fscache_stat(&fscache_n_retrievals_nomem);
45882 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45883 else if (ret == -ERESTARTSYS)
45884 - fscache_stat(&fscache_n_retrievals_intr);
45885 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45886 else if (ret == -ENODATA)
45887 - fscache_stat(&fscache_n_retrievals_nodata);
45888 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45889 else if (ret < 0)
45890 - fscache_stat(&fscache_n_retrievals_nobufs);
45891 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45892 else
45893 - fscache_stat(&fscache_n_retrievals_ok);
45894 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45895
45896 fscache_put_retrieval(op);
45897 _leave(" = %d", ret);
45898 @@ -545,7 +545,7 @@ nobufs_unlock:
45899 spin_unlock(&cookie->lock);
45900 kfree(op);
45901 nobufs:
45902 - fscache_stat(&fscache_n_retrievals_nobufs);
45903 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45904 _leave(" = -ENOBUFS");
45905 return -ENOBUFS;
45906 }
45907 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45908
45909 _enter("%p,%p,,,", cookie, page);
45910
45911 - fscache_stat(&fscache_n_allocs);
45912 + fscache_stat_unchecked(&fscache_n_allocs);
45913
45914 if (hlist_empty(&cookie->backing_objects))
45915 goto nobufs;
45916 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45917 goto nobufs_unlock;
45918 spin_unlock(&cookie->lock);
45919
45920 - fscache_stat(&fscache_n_alloc_ops);
45921 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45922
45923 ret = fscache_wait_for_retrieval_activation(
45924 object, op,
45925 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45926
45927 error:
45928 if (ret == -ERESTARTSYS)
45929 - fscache_stat(&fscache_n_allocs_intr);
45930 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45931 else if (ret < 0)
45932 - fscache_stat(&fscache_n_allocs_nobufs);
45933 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45934 else
45935 - fscache_stat(&fscache_n_allocs_ok);
45936 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45937
45938 fscache_put_retrieval(op);
45939 _leave(" = %d", ret);
45940 @@ -625,7 +625,7 @@ nobufs_unlock:
45941 spin_unlock(&cookie->lock);
45942 kfree(op);
45943 nobufs:
45944 - fscache_stat(&fscache_n_allocs_nobufs);
45945 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45946 _leave(" = -ENOBUFS");
45947 return -ENOBUFS;
45948 }
45949 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45950
45951 spin_lock(&cookie->stores_lock);
45952
45953 - fscache_stat(&fscache_n_store_calls);
45954 + fscache_stat_unchecked(&fscache_n_store_calls);
45955
45956 /* find a page to store */
45957 page = NULL;
45958 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45959 page = results[0];
45960 _debug("gang %d [%lx]", n, page->index);
45961 if (page->index > op->store_limit) {
45962 - fscache_stat(&fscache_n_store_pages_over_limit);
45963 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45964 goto superseded;
45965 }
45966
45967 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45968 spin_unlock(&cookie->stores_lock);
45969 spin_unlock(&object->lock);
45970
45971 - fscache_stat(&fscache_n_store_pages);
45972 + fscache_stat_unchecked(&fscache_n_store_pages);
45973 fscache_stat(&fscache_n_cop_write_page);
45974 ret = object->cache->ops->write_page(op, page);
45975 fscache_stat_d(&fscache_n_cop_write_page);
45976 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45977 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45978 ASSERT(PageFsCache(page));
45979
45980 - fscache_stat(&fscache_n_stores);
45981 + fscache_stat_unchecked(&fscache_n_stores);
45982
45983 op = kzalloc(sizeof(*op), GFP_NOIO);
45984 if (!op)
45985 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45986 spin_unlock(&cookie->stores_lock);
45987 spin_unlock(&object->lock);
45988
45989 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45990 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45991 op->store_limit = object->store_limit;
45992
45993 if (fscache_submit_op(object, &op->op) < 0)
45994 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45995
45996 spin_unlock(&cookie->lock);
45997 radix_tree_preload_end();
45998 - fscache_stat(&fscache_n_store_ops);
45999 - fscache_stat(&fscache_n_stores_ok);
46000 + fscache_stat_unchecked(&fscache_n_store_ops);
46001 + fscache_stat_unchecked(&fscache_n_stores_ok);
46002
46003 /* the work queue now carries its own ref on the object */
46004 fscache_put_operation(&op->op);
46005 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46006 return 0;
46007
46008 already_queued:
46009 - fscache_stat(&fscache_n_stores_again);
46010 + fscache_stat_unchecked(&fscache_n_stores_again);
46011 already_pending:
46012 spin_unlock(&cookie->stores_lock);
46013 spin_unlock(&object->lock);
46014 spin_unlock(&cookie->lock);
46015 radix_tree_preload_end();
46016 kfree(op);
46017 - fscache_stat(&fscache_n_stores_ok);
46018 + fscache_stat_unchecked(&fscache_n_stores_ok);
46019 _leave(" = 0");
46020 return 0;
46021
46022 @@ -851,14 +851,14 @@ nobufs:
46023 spin_unlock(&cookie->lock);
46024 radix_tree_preload_end();
46025 kfree(op);
46026 - fscache_stat(&fscache_n_stores_nobufs);
46027 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46028 _leave(" = -ENOBUFS");
46029 return -ENOBUFS;
46030
46031 nomem_free:
46032 kfree(op);
46033 nomem:
46034 - fscache_stat(&fscache_n_stores_oom);
46035 + fscache_stat_unchecked(&fscache_n_stores_oom);
46036 _leave(" = -ENOMEM");
46037 return -ENOMEM;
46038 }
46039 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46040 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46041 ASSERTCMP(page, !=, NULL);
46042
46043 - fscache_stat(&fscache_n_uncaches);
46044 + fscache_stat_unchecked(&fscache_n_uncaches);
46045
46046 /* cache withdrawal may beat us to it */
46047 if (!PageFsCache(page))
46048 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46049 unsigned long loop;
46050
46051 #ifdef CONFIG_FSCACHE_STATS
46052 - atomic_add(pagevec->nr, &fscache_n_marks);
46053 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46054 #endif
46055
46056 for (loop = 0; loop < pagevec->nr; loop++) {
46057 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46058 index 4765190..2a067f2 100644
46059 --- a/fs/fscache/stats.c
46060 +++ b/fs/fscache/stats.c
46061 @@ -18,95 +18,95 @@
46062 /*
46063 * operation counters
46064 */
46065 -atomic_t fscache_n_op_pend;
46066 -atomic_t fscache_n_op_run;
46067 -atomic_t fscache_n_op_enqueue;
46068 -atomic_t fscache_n_op_requeue;
46069 -atomic_t fscache_n_op_deferred_release;
46070 -atomic_t fscache_n_op_release;
46071 -atomic_t fscache_n_op_gc;
46072 -atomic_t fscache_n_op_cancelled;
46073 -atomic_t fscache_n_op_rejected;
46074 +atomic_unchecked_t fscache_n_op_pend;
46075 +atomic_unchecked_t fscache_n_op_run;
46076 +atomic_unchecked_t fscache_n_op_enqueue;
46077 +atomic_unchecked_t fscache_n_op_requeue;
46078 +atomic_unchecked_t fscache_n_op_deferred_release;
46079 +atomic_unchecked_t fscache_n_op_release;
46080 +atomic_unchecked_t fscache_n_op_gc;
46081 +atomic_unchecked_t fscache_n_op_cancelled;
46082 +atomic_unchecked_t fscache_n_op_rejected;
46083
46084 -atomic_t fscache_n_attr_changed;
46085 -atomic_t fscache_n_attr_changed_ok;
46086 -atomic_t fscache_n_attr_changed_nobufs;
46087 -atomic_t fscache_n_attr_changed_nomem;
46088 -atomic_t fscache_n_attr_changed_calls;
46089 +atomic_unchecked_t fscache_n_attr_changed;
46090 +atomic_unchecked_t fscache_n_attr_changed_ok;
46091 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46092 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46093 +atomic_unchecked_t fscache_n_attr_changed_calls;
46094
46095 -atomic_t fscache_n_allocs;
46096 -atomic_t fscache_n_allocs_ok;
46097 -atomic_t fscache_n_allocs_wait;
46098 -atomic_t fscache_n_allocs_nobufs;
46099 -atomic_t fscache_n_allocs_intr;
46100 -atomic_t fscache_n_allocs_object_dead;
46101 -atomic_t fscache_n_alloc_ops;
46102 -atomic_t fscache_n_alloc_op_waits;
46103 +atomic_unchecked_t fscache_n_allocs;
46104 +atomic_unchecked_t fscache_n_allocs_ok;
46105 +atomic_unchecked_t fscache_n_allocs_wait;
46106 +atomic_unchecked_t fscache_n_allocs_nobufs;
46107 +atomic_unchecked_t fscache_n_allocs_intr;
46108 +atomic_unchecked_t fscache_n_allocs_object_dead;
46109 +atomic_unchecked_t fscache_n_alloc_ops;
46110 +atomic_unchecked_t fscache_n_alloc_op_waits;
46111
46112 -atomic_t fscache_n_retrievals;
46113 -atomic_t fscache_n_retrievals_ok;
46114 -atomic_t fscache_n_retrievals_wait;
46115 -atomic_t fscache_n_retrievals_nodata;
46116 -atomic_t fscache_n_retrievals_nobufs;
46117 -atomic_t fscache_n_retrievals_intr;
46118 -atomic_t fscache_n_retrievals_nomem;
46119 -atomic_t fscache_n_retrievals_object_dead;
46120 -atomic_t fscache_n_retrieval_ops;
46121 -atomic_t fscache_n_retrieval_op_waits;
46122 +atomic_unchecked_t fscache_n_retrievals;
46123 +atomic_unchecked_t fscache_n_retrievals_ok;
46124 +atomic_unchecked_t fscache_n_retrievals_wait;
46125 +atomic_unchecked_t fscache_n_retrievals_nodata;
46126 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46127 +atomic_unchecked_t fscache_n_retrievals_intr;
46128 +atomic_unchecked_t fscache_n_retrievals_nomem;
46129 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46130 +atomic_unchecked_t fscache_n_retrieval_ops;
46131 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46132
46133 -atomic_t fscache_n_stores;
46134 -atomic_t fscache_n_stores_ok;
46135 -atomic_t fscache_n_stores_again;
46136 -atomic_t fscache_n_stores_nobufs;
46137 -atomic_t fscache_n_stores_oom;
46138 -atomic_t fscache_n_store_ops;
46139 -atomic_t fscache_n_store_calls;
46140 -atomic_t fscache_n_store_pages;
46141 -atomic_t fscache_n_store_radix_deletes;
46142 -atomic_t fscache_n_store_pages_over_limit;
46143 +atomic_unchecked_t fscache_n_stores;
46144 +atomic_unchecked_t fscache_n_stores_ok;
46145 +atomic_unchecked_t fscache_n_stores_again;
46146 +atomic_unchecked_t fscache_n_stores_nobufs;
46147 +atomic_unchecked_t fscache_n_stores_oom;
46148 +atomic_unchecked_t fscache_n_store_ops;
46149 +atomic_unchecked_t fscache_n_store_calls;
46150 +atomic_unchecked_t fscache_n_store_pages;
46151 +atomic_unchecked_t fscache_n_store_radix_deletes;
46152 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46153
46154 -atomic_t fscache_n_store_vmscan_not_storing;
46155 -atomic_t fscache_n_store_vmscan_gone;
46156 -atomic_t fscache_n_store_vmscan_busy;
46157 -atomic_t fscache_n_store_vmscan_cancelled;
46158 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46159 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46160 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46161 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46162
46163 -atomic_t fscache_n_marks;
46164 -atomic_t fscache_n_uncaches;
46165 +atomic_unchecked_t fscache_n_marks;
46166 +atomic_unchecked_t fscache_n_uncaches;
46167
46168 -atomic_t fscache_n_acquires;
46169 -atomic_t fscache_n_acquires_null;
46170 -atomic_t fscache_n_acquires_no_cache;
46171 -atomic_t fscache_n_acquires_ok;
46172 -atomic_t fscache_n_acquires_nobufs;
46173 -atomic_t fscache_n_acquires_oom;
46174 +atomic_unchecked_t fscache_n_acquires;
46175 +atomic_unchecked_t fscache_n_acquires_null;
46176 +atomic_unchecked_t fscache_n_acquires_no_cache;
46177 +atomic_unchecked_t fscache_n_acquires_ok;
46178 +atomic_unchecked_t fscache_n_acquires_nobufs;
46179 +atomic_unchecked_t fscache_n_acquires_oom;
46180
46181 -atomic_t fscache_n_updates;
46182 -atomic_t fscache_n_updates_null;
46183 -atomic_t fscache_n_updates_run;
46184 +atomic_unchecked_t fscache_n_updates;
46185 +atomic_unchecked_t fscache_n_updates_null;
46186 +atomic_unchecked_t fscache_n_updates_run;
46187
46188 -atomic_t fscache_n_relinquishes;
46189 -atomic_t fscache_n_relinquishes_null;
46190 -atomic_t fscache_n_relinquishes_waitcrt;
46191 -atomic_t fscache_n_relinquishes_retire;
46192 +atomic_unchecked_t fscache_n_relinquishes;
46193 +atomic_unchecked_t fscache_n_relinquishes_null;
46194 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46195 +atomic_unchecked_t fscache_n_relinquishes_retire;
46196
46197 -atomic_t fscache_n_cookie_index;
46198 -atomic_t fscache_n_cookie_data;
46199 -atomic_t fscache_n_cookie_special;
46200 +atomic_unchecked_t fscache_n_cookie_index;
46201 +atomic_unchecked_t fscache_n_cookie_data;
46202 +atomic_unchecked_t fscache_n_cookie_special;
46203
46204 -atomic_t fscache_n_object_alloc;
46205 -atomic_t fscache_n_object_no_alloc;
46206 -atomic_t fscache_n_object_lookups;
46207 -atomic_t fscache_n_object_lookups_negative;
46208 -atomic_t fscache_n_object_lookups_positive;
46209 -atomic_t fscache_n_object_lookups_timed_out;
46210 -atomic_t fscache_n_object_created;
46211 -atomic_t fscache_n_object_avail;
46212 -atomic_t fscache_n_object_dead;
46213 +atomic_unchecked_t fscache_n_object_alloc;
46214 +atomic_unchecked_t fscache_n_object_no_alloc;
46215 +atomic_unchecked_t fscache_n_object_lookups;
46216 +atomic_unchecked_t fscache_n_object_lookups_negative;
46217 +atomic_unchecked_t fscache_n_object_lookups_positive;
46218 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46219 +atomic_unchecked_t fscache_n_object_created;
46220 +atomic_unchecked_t fscache_n_object_avail;
46221 +atomic_unchecked_t fscache_n_object_dead;
46222
46223 -atomic_t fscache_n_checkaux_none;
46224 -atomic_t fscache_n_checkaux_okay;
46225 -atomic_t fscache_n_checkaux_update;
46226 -atomic_t fscache_n_checkaux_obsolete;
46227 +atomic_unchecked_t fscache_n_checkaux_none;
46228 +atomic_unchecked_t fscache_n_checkaux_okay;
46229 +atomic_unchecked_t fscache_n_checkaux_update;
46230 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46231
46232 atomic_t fscache_n_cop_alloc_object;
46233 atomic_t fscache_n_cop_lookup_object;
46234 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46235 seq_puts(m, "FS-Cache statistics\n");
46236
46237 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46238 - atomic_read(&fscache_n_cookie_index),
46239 - atomic_read(&fscache_n_cookie_data),
46240 - atomic_read(&fscache_n_cookie_special));
46241 + atomic_read_unchecked(&fscache_n_cookie_index),
46242 + atomic_read_unchecked(&fscache_n_cookie_data),
46243 + atomic_read_unchecked(&fscache_n_cookie_special));
46244
46245 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46246 - atomic_read(&fscache_n_object_alloc),
46247 - atomic_read(&fscache_n_object_no_alloc),
46248 - atomic_read(&fscache_n_object_avail),
46249 - atomic_read(&fscache_n_object_dead));
46250 + atomic_read_unchecked(&fscache_n_object_alloc),
46251 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46252 + atomic_read_unchecked(&fscache_n_object_avail),
46253 + atomic_read_unchecked(&fscache_n_object_dead));
46254 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46255 - atomic_read(&fscache_n_checkaux_none),
46256 - atomic_read(&fscache_n_checkaux_okay),
46257 - atomic_read(&fscache_n_checkaux_update),
46258 - atomic_read(&fscache_n_checkaux_obsolete));
46259 + atomic_read_unchecked(&fscache_n_checkaux_none),
46260 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46261 + atomic_read_unchecked(&fscache_n_checkaux_update),
46262 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46263
46264 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46265 - atomic_read(&fscache_n_marks),
46266 - atomic_read(&fscache_n_uncaches));
46267 + atomic_read_unchecked(&fscache_n_marks),
46268 + atomic_read_unchecked(&fscache_n_uncaches));
46269
46270 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46271 " oom=%u\n",
46272 - atomic_read(&fscache_n_acquires),
46273 - atomic_read(&fscache_n_acquires_null),
46274 - atomic_read(&fscache_n_acquires_no_cache),
46275 - atomic_read(&fscache_n_acquires_ok),
46276 - atomic_read(&fscache_n_acquires_nobufs),
46277 - atomic_read(&fscache_n_acquires_oom));
46278 + atomic_read_unchecked(&fscache_n_acquires),
46279 + atomic_read_unchecked(&fscache_n_acquires_null),
46280 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46281 + atomic_read_unchecked(&fscache_n_acquires_ok),
46282 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46283 + atomic_read_unchecked(&fscache_n_acquires_oom));
46284
46285 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46286 - atomic_read(&fscache_n_object_lookups),
46287 - atomic_read(&fscache_n_object_lookups_negative),
46288 - atomic_read(&fscache_n_object_lookups_positive),
46289 - atomic_read(&fscache_n_object_created),
46290 - atomic_read(&fscache_n_object_lookups_timed_out));
46291 + atomic_read_unchecked(&fscache_n_object_lookups),
46292 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46293 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46294 + atomic_read_unchecked(&fscache_n_object_created),
46295 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46296
46297 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46298 - atomic_read(&fscache_n_updates),
46299 - atomic_read(&fscache_n_updates_null),
46300 - atomic_read(&fscache_n_updates_run));
46301 + atomic_read_unchecked(&fscache_n_updates),
46302 + atomic_read_unchecked(&fscache_n_updates_null),
46303 + atomic_read_unchecked(&fscache_n_updates_run));
46304
46305 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46306 - atomic_read(&fscache_n_relinquishes),
46307 - atomic_read(&fscache_n_relinquishes_null),
46308 - atomic_read(&fscache_n_relinquishes_waitcrt),
46309 - atomic_read(&fscache_n_relinquishes_retire));
46310 + atomic_read_unchecked(&fscache_n_relinquishes),
46311 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46312 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46313 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46314
46315 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46316 - atomic_read(&fscache_n_attr_changed),
46317 - atomic_read(&fscache_n_attr_changed_ok),
46318 - atomic_read(&fscache_n_attr_changed_nobufs),
46319 - atomic_read(&fscache_n_attr_changed_nomem),
46320 - atomic_read(&fscache_n_attr_changed_calls));
46321 + atomic_read_unchecked(&fscache_n_attr_changed),
46322 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46323 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46324 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46325 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46326
46327 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46328 - atomic_read(&fscache_n_allocs),
46329 - atomic_read(&fscache_n_allocs_ok),
46330 - atomic_read(&fscache_n_allocs_wait),
46331 - atomic_read(&fscache_n_allocs_nobufs),
46332 - atomic_read(&fscache_n_allocs_intr));
46333 + atomic_read_unchecked(&fscache_n_allocs),
46334 + atomic_read_unchecked(&fscache_n_allocs_ok),
46335 + atomic_read_unchecked(&fscache_n_allocs_wait),
46336 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46337 + atomic_read_unchecked(&fscache_n_allocs_intr));
46338 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46339 - atomic_read(&fscache_n_alloc_ops),
46340 - atomic_read(&fscache_n_alloc_op_waits),
46341 - atomic_read(&fscache_n_allocs_object_dead));
46342 + atomic_read_unchecked(&fscache_n_alloc_ops),
46343 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46344 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46345
46346 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46347 " int=%u oom=%u\n",
46348 - atomic_read(&fscache_n_retrievals),
46349 - atomic_read(&fscache_n_retrievals_ok),
46350 - atomic_read(&fscache_n_retrievals_wait),
46351 - atomic_read(&fscache_n_retrievals_nodata),
46352 - atomic_read(&fscache_n_retrievals_nobufs),
46353 - atomic_read(&fscache_n_retrievals_intr),
46354 - atomic_read(&fscache_n_retrievals_nomem));
46355 + atomic_read_unchecked(&fscache_n_retrievals),
46356 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46357 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46358 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46359 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46360 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46361 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46362 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46363 - atomic_read(&fscache_n_retrieval_ops),
46364 - atomic_read(&fscache_n_retrieval_op_waits),
46365 - atomic_read(&fscache_n_retrievals_object_dead));
46366 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46367 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46368 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46369
46370 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46371 - atomic_read(&fscache_n_stores),
46372 - atomic_read(&fscache_n_stores_ok),
46373 - atomic_read(&fscache_n_stores_again),
46374 - atomic_read(&fscache_n_stores_nobufs),
46375 - atomic_read(&fscache_n_stores_oom));
46376 + atomic_read_unchecked(&fscache_n_stores),
46377 + atomic_read_unchecked(&fscache_n_stores_ok),
46378 + atomic_read_unchecked(&fscache_n_stores_again),
46379 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46380 + atomic_read_unchecked(&fscache_n_stores_oom));
46381 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46382 - atomic_read(&fscache_n_store_ops),
46383 - atomic_read(&fscache_n_store_calls),
46384 - atomic_read(&fscache_n_store_pages),
46385 - atomic_read(&fscache_n_store_radix_deletes),
46386 - atomic_read(&fscache_n_store_pages_over_limit));
46387 + atomic_read_unchecked(&fscache_n_store_ops),
46388 + atomic_read_unchecked(&fscache_n_store_calls),
46389 + atomic_read_unchecked(&fscache_n_store_pages),
46390 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46391 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46392
46393 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46394 - atomic_read(&fscache_n_store_vmscan_not_storing),
46395 - atomic_read(&fscache_n_store_vmscan_gone),
46396 - atomic_read(&fscache_n_store_vmscan_busy),
46397 - atomic_read(&fscache_n_store_vmscan_cancelled));
46398 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46399 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46400 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46401 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46402
46403 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46404 - atomic_read(&fscache_n_op_pend),
46405 - atomic_read(&fscache_n_op_run),
46406 - atomic_read(&fscache_n_op_enqueue),
46407 - atomic_read(&fscache_n_op_cancelled),
46408 - atomic_read(&fscache_n_op_rejected));
46409 + atomic_read_unchecked(&fscache_n_op_pend),
46410 + atomic_read_unchecked(&fscache_n_op_run),
46411 + atomic_read_unchecked(&fscache_n_op_enqueue),
46412 + atomic_read_unchecked(&fscache_n_op_cancelled),
46413 + atomic_read_unchecked(&fscache_n_op_rejected));
46414 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46415 - atomic_read(&fscache_n_op_deferred_release),
46416 - atomic_read(&fscache_n_op_release),
46417 - atomic_read(&fscache_n_op_gc));
46418 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46419 + atomic_read_unchecked(&fscache_n_op_release),
46420 + atomic_read_unchecked(&fscache_n_op_gc));
46421
46422 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46423 atomic_read(&fscache_n_cop_alloc_object),
46424 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46425 index 3426521..3b75162 100644
46426 --- a/fs/fuse/cuse.c
46427 +++ b/fs/fuse/cuse.c
46428 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46429 INIT_LIST_HEAD(&cuse_conntbl[i]);
46430
46431 /* inherit and extend fuse_dev_operations */
46432 - cuse_channel_fops = fuse_dev_operations;
46433 - cuse_channel_fops.owner = THIS_MODULE;
46434 - cuse_channel_fops.open = cuse_channel_open;
46435 - cuse_channel_fops.release = cuse_channel_release;
46436 + pax_open_kernel();
46437 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46438 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46439 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46440 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46441 + pax_close_kernel();
46442
46443 cuse_class = class_create(THIS_MODULE, "cuse");
46444 if (IS_ERR(cuse_class))
46445 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46446 index 5f3368a..8306426 100644
46447 --- a/fs/fuse/dev.c
46448 +++ b/fs/fuse/dev.c
46449 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46450 ret = 0;
46451 pipe_lock(pipe);
46452
46453 - if (!pipe->readers) {
46454 + if (!atomic_read(&pipe->readers)) {
46455 send_sig(SIGPIPE, current, 0);
46456 if (!ret)
46457 ret = -EPIPE;
46458 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46459 index 2066328..f5add3b 100644
46460 --- a/fs/fuse/dir.c
46461 +++ b/fs/fuse/dir.c
46462 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46463 return link;
46464 }
46465
46466 -static void free_link(char *link)
46467 +static void free_link(const char *link)
46468 {
46469 if (!IS_ERR(link))
46470 free_page((unsigned long) link);
46471 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46472 index 5698746..6086012 100644
46473 --- a/fs/gfs2/inode.c
46474 +++ b/fs/gfs2/inode.c
46475 @@ -1487,7 +1487,7 @@ out:
46476
46477 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46478 {
46479 - char *s = nd_get_link(nd);
46480 + const char *s = nd_get_link(nd);
46481 if (!IS_ERR(s))
46482 kfree(s);
46483 }
46484 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46485 index 3645cd3..786809c 100644
46486 --- a/fs/hugetlbfs/inode.c
46487 +++ b/fs/hugetlbfs/inode.c
46488 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46489 .kill_sb = kill_litter_super,
46490 };
46491
46492 -static struct vfsmount *hugetlbfs_vfsmount;
46493 +struct vfsmount *hugetlbfs_vfsmount;
46494
46495 static int can_do_hugetlb_shm(void)
46496 {
46497 diff --git a/fs/inode.c b/fs/inode.c
46498 index 83ab215..8842101 100644
46499 --- a/fs/inode.c
46500 +++ b/fs/inode.c
46501 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46502
46503 #ifdef CONFIG_SMP
46504 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46505 - static atomic_t shared_last_ino;
46506 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46507 + static atomic_unchecked_t shared_last_ino;
46508 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46509
46510 res = next - LAST_INO_BATCH;
46511 }
46512 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46513 index eafb8d3..f423d37 100644
46514 --- a/fs/jffs2/erase.c
46515 +++ b/fs/jffs2/erase.c
46516 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46517 struct jffs2_unknown_node marker = {
46518 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46519 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46520 - .totlen = cpu_to_je32(c->cleanmarker_size)
46521 + .totlen = cpu_to_je32(c->cleanmarker_size),
46522 + .hdr_crc = cpu_to_je32(0)
46523 };
46524
46525 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46526 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46527 index 30e8f47..21f600c 100644
46528 --- a/fs/jffs2/wbuf.c
46529 +++ b/fs/jffs2/wbuf.c
46530 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46531 {
46532 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46533 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46534 - .totlen = constant_cpu_to_je32(8)
46535 + .totlen = constant_cpu_to_je32(8),
46536 + .hdr_crc = constant_cpu_to_je32(0)
46537 };
46538
46539 /*
46540 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46541 index 682bca6..86b8e6e 100644
46542 --- a/fs/jfs/super.c
46543 +++ b/fs/jfs/super.c
46544 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46545
46546 jfs_inode_cachep =
46547 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46548 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46549 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46550 init_once);
46551 if (jfs_inode_cachep == NULL)
46552 return -ENOMEM;
46553 diff --git a/fs/libfs.c b/fs/libfs.c
46554 index 5b2dbb3..7442d54 100644
46555 --- a/fs/libfs.c
46556 +++ b/fs/libfs.c
46557 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46558
46559 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46560 struct dentry *next;
46561 + char d_name[sizeof(next->d_iname)];
46562 + const unsigned char *name;
46563 +
46564 next = list_entry(p, struct dentry, d_u.d_child);
46565 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46566 if (!simple_positive(next)) {
46567 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46568
46569 spin_unlock(&next->d_lock);
46570 spin_unlock(&dentry->d_lock);
46571 - if (filldir(dirent, next->d_name.name,
46572 + name = next->d_name.name;
46573 + if (name == next->d_iname) {
46574 + memcpy(d_name, name, next->d_name.len);
46575 + name = d_name;
46576 + }
46577 + if (filldir(dirent, name,
46578 next->d_name.len, filp->f_pos,
46579 next->d_inode->i_ino,
46580 dt_type(next->d_inode)) < 0)
46581 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46582 index 8392cb8..80d6193 100644
46583 --- a/fs/lockd/clntproc.c
46584 +++ b/fs/lockd/clntproc.c
46585 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46586 /*
46587 * Cookie counter for NLM requests
46588 */
46589 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46590 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46591
46592 void nlmclnt_next_cookie(struct nlm_cookie *c)
46593 {
46594 - u32 cookie = atomic_inc_return(&nlm_cookie);
46595 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46596
46597 memcpy(c->data, &cookie, 4);
46598 c->len=4;
46599 diff --git a/fs/locks.c b/fs/locks.c
46600 index 0d68f1f..f216b79 100644
46601 --- a/fs/locks.c
46602 +++ b/fs/locks.c
46603 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46604 return;
46605
46606 if (filp->f_op && filp->f_op->flock) {
46607 - struct file_lock fl = {
46608 + struct file_lock flock = {
46609 .fl_pid = current->tgid,
46610 .fl_file = filp,
46611 .fl_flags = FL_FLOCK,
46612 .fl_type = F_UNLCK,
46613 .fl_end = OFFSET_MAX,
46614 };
46615 - filp->f_op->flock(filp, F_SETLKW, &fl);
46616 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46617 - fl.fl_ops->fl_release_private(&fl);
46618 + filp->f_op->flock(filp, F_SETLKW, &flock);
46619 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46620 + flock.fl_ops->fl_release_private(&flock);
46621 }
46622
46623 lock_flocks();
46624 diff --git a/fs/namei.c b/fs/namei.c
46625 index 46ea9cc..c7cf3a3 100644
46626 --- a/fs/namei.c
46627 +++ b/fs/namei.c
46628 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46629 if (ret != -EACCES)
46630 return ret;
46631
46632 +#ifdef CONFIG_GRKERNSEC
46633 + /* we'll block if we have to log due to a denied capability use */
46634 + if (mask & MAY_NOT_BLOCK)
46635 + return -ECHILD;
46636 +#endif
46637 +
46638 if (S_ISDIR(inode->i_mode)) {
46639 /* DACs are overridable for directories */
46640 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46641 - return 0;
46642 if (!(mask & MAY_WRITE))
46643 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46644 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46645 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46646 return 0;
46647 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46648 + return 0;
46649 return -EACCES;
46650 }
46651 /*
46652 + * Searching includes executable on directories, else just read.
46653 + */
46654 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46655 + if (mask == MAY_READ)
46656 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46657 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46658 + return 0;
46659 +
46660 + /*
46661 * Read/write DACs are always overridable.
46662 * Executable DACs are overridable when there is
46663 * at least one exec bit set.
46664 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46665 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46666 return 0;
46667
46668 - /*
46669 - * Searching includes executable on directories, else just read.
46670 - */
46671 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46672 - if (mask == MAY_READ)
46673 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46674 - return 0;
46675 -
46676 return -EACCES;
46677 }
46678
46679 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46680 return error;
46681 }
46682
46683 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46684 + dentry->d_inode, dentry, nd->path.mnt)) {
46685 + error = -EACCES;
46686 + *p = ERR_PTR(error); /* no ->put_link(), please */
46687 + path_put(&nd->path);
46688 + return error;
46689 + }
46690 +
46691 nd->last_type = LAST_BIND;
46692 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46693 error = PTR_ERR(*p);
46694 if (!IS_ERR(*p)) {
46695 - char *s = nd_get_link(nd);
46696 + const char *s = nd_get_link(nd);
46697 error = 0;
46698 if (s)
46699 error = __vfs_follow_link(nd, s);
46700 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
46701 if (!err)
46702 err = complete_walk(nd);
46703
46704 + if (!(nd->flags & LOOKUP_PARENT)) {
46705 +#ifdef CONFIG_GRKERNSEC
46706 + if (flags & LOOKUP_RCU) {
46707 + if (!err)
46708 + path_put(&nd->path);
46709 + err = -ECHILD;
46710 + } else
46711 +#endif
46712 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46713 + if (!err)
46714 + path_put(&nd->path);
46715 + err = -ENOENT;
46716 + }
46717 + }
46718 +
46719 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46720 if (!nd->inode->i_op->lookup) {
46721 path_put(&nd->path);
46722 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
46723 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46724
46725 if (likely(!retval)) {
46726 + if (*name != '/' && nd->path.dentry && nd->inode) {
46727 +#ifdef CONFIG_GRKERNSEC
46728 + if (flags & LOOKUP_RCU)
46729 + return -ECHILD;
46730 +#endif
46731 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46732 + return -ENOENT;
46733 + }
46734 +
46735 if (unlikely(!audit_dummy_context())) {
46736 if (nd->path.dentry && nd->inode)
46737 audit_inode(name, nd->path.dentry);
46738 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46739 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46740 return -EPERM;
46741
46742 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46743 + return -EPERM;
46744 + if (gr_handle_rawio(inode))
46745 + return -EPERM;
46746 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46747 + return -EACCES;
46748 +
46749 return 0;
46750 }
46751
46752 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46753 error = complete_walk(nd);
46754 if (error)
46755 return ERR_PTR(error);
46756 +#ifdef CONFIG_GRKERNSEC
46757 + if (nd->flags & LOOKUP_RCU) {
46758 + error = -ECHILD;
46759 + goto exit;
46760 + }
46761 +#endif
46762 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46763 + error = -ENOENT;
46764 + goto exit;
46765 + }
46766 audit_inode(pathname, nd->path.dentry);
46767 if (open_flag & O_CREAT) {
46768 error = -EISDIR;
46769 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46770 error = complete_walk(nd);
46771 if (error)
46772 return ERR_PTR(error);
46773 +#ifdef CONFIG_GRKERNSEC
46774 + if (nd->flags & LOOKUP_RCU) {
46775 + error = -ECHILD;
46776 + goto exit;
46777 + }
46778 +#endif
46779 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46780 + error = -ENOENT;
46781 + goto exit;
46782 + }
46783 audit_inode(pathname, dir);
46784 goto ok;
46785 }
46786 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46787 error = complete_walk(nd);
46788 if (error)
46789 return ERR_PTR(error);
46790 +#ifdef CONFIG_GRKERNSEC
46791 + if (nd->flags & LOOKUP_RCU) {
46792 + error = -ECHILD;
46793 + goto exit;
46794 + }
46795 +#endif
46796 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46797 + error = -ENOENT;
46798 + goto exit;
46799 + }
46800
46801 error = -ENOTDIR;
46802 if (nd->flags & LOOKUP_DIRECTORY) {
46803 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46804 /* Negative dentry, just create the file */
46805 if (!dentry->d_inode) {
46806 umode_t mode = op->mode;
46807 +
46808 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46809 + error = -EACCES;
46810 + goto exit_mutex_unlock;
46811 + }
46812 +
46813 if (!IS_POSIXACL(dir->d_inode))
46814 mode &= ~current_umask();
46815 /*
46816 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46817 error = vfs_create(dir->d_inode, dentry, mode, nd);
46818 if (error)
46819 goto exit_mutex_unlock;
46820 + else
46821 + gr_handle_create(path->dentry, path->mnt);
46822 mutex_unlock(&dir->d_inode->i_mutex);
46823 dput(nd->path.dentry);
46824 nd->path.dentry = dentry;
46825 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46826 /*
46827 * It already exists.
46828 */
46829 +
46830 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46831 + error = -ENOENT;
46832 + goto exit_mutex_unlock;
46833 + }
46834 +
46835 + /* only check if O_CREAT is specified, all other checks need to go
46836 + into may_open */
46837 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46838 + error = -EACCES;
46839 + goto exit_mutex_unlock;
46840 + }
46841 +
46842 mutex_unlock(&dir->d_inode->i_mutex);
46843 audit_inode(pathname, path->dentry);
46844
46845 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46846 *path = nd.path;
46847 return dentry;
46848 eexist:
46849 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46850 + dput(dentry);
46851 + dentry = ERR_PTR(-ENOENT);
46852 + goto fail;
46853 + }
46854 dput(dentry);
46855 dentry = ERR_PTR(-EEXIST);
46856 fail:
46857 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46858 }
46859 EXPORT_SYMBOL(user_path_create);
46860
46861 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46862 +{
46863 + char *tmp = getname(pathname);
46864 + struct dentry *res;
46865 + if (IS_ERR(tmp))
46866 + return ERR_CAST(tmp);
46867 + res = kern_path_create(dfd, tmp, path, is_dir);
46868 + if (IS_ERR(res))
46869 + putname(tmp);
46870 + else
46871 + *to = tmp;
46872 + return res;
46873 +}
46874 +
46875 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46876 {
46877 int error = may_create(dir, dentry);
46878 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46879 error = mnt_want_write(path.mnt);
46880 if (error)
46881 goto out_dput;
46882 +
46883 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46884 + error = -EPERM;
46885 + goto out_drop_write;
46886 + }
46887 +
46888 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46889 + error = -EACCES;
46890 + goto out_drop_write;
46891 + }
46892 +
46893 error = security_path_mknod(&path, dentry, mode, dev);
46894 if (error)
46895 goto out_drop_write;
46896 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46897 }
46898 out_drop_write:
46899 mnt_drop_write(path.mnt);
46900 +
46901 + if (!error)
46902 + gr_handle_create(dentry, path.mnt);
46903 out_dput:
46904 dput(dentry);
46905 mutex_unlock(&path.dentry->d_inode->i_mutex);
46906 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46907 error = mnt_want_write(path.mnt);
46908 if (error)
46909 goto out_dput;
46910 +
46911 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46912 + error = -EACCES;
46913 + goto out_drop_write;
46914 + }
46915 +
46916 error = security_path_mkdir(&path, dentry, mode);
46917 if (error)
46918 goto out_drop_write;
46919 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46920 out_drop_write:
46921 mnt_drop_write(path.mnt);
46922 +
46923 + if (!error)
46924 + gr_handle_create(dentry, path.mnt);
46925 out_dput:
46926 dput(dentry);
46927 mutex_unlock(&path.dentry->d_inode->i_mutex);
46928 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46929 char * name;
46930 struct dentry *dentry;
46931 struct nameidata nd;
46932 + ino_t saved_ino = 0;
46933 + dev_t saved_dev = 0;
46934
46935 error = user_path_parent(dfd, pathname, &nd, &name);
46936 if (error)
46937 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46938 error = -ENOENT;
46939 goto exit3;
46940 }
46941 +
46942 + saved_ino = dentry->d_inode->i_ino;
46943 + saved_dev = gr_get_dev_from_dentry(dentry);
46944 +
46945 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46946 + error = -EACCES;
46947 + goto exit3;
46948 + }
46949 +
46950 error = mnt_want_write(nd.path.mnt);
46951 if (error)
46952 goto exit3;
46953 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46954 if (error)
46955 goto exit4;
46956 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46957 + if (!error && (saved_dev || saved_ino))
46958 + gr_handle_delete(saved_ino, saved_dev);
46959 exit4:
46960 mnt_drop_write(nd.path.mnt);
46961 exit3:
46962 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46963 struct dentry *dentry;
46964 struct nameidata nd;
46965 struct inode *inode = NULL;
46966 + ino_t saved_ino = 0;
46967 + dev_t saved_dev = 0;
46968
46969 error = user_path_parent(dfd, pathname, &nd, &name);
46970 if (error)
46971 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46972 if (!inode)
46973 goto slashes;
46974 ihold(inode);
46975 +
46976 + if (inode->i_nlink <= 1) {
46977 + saved_ino = inode->i_ino;
46978 + saved_dev = gr_get_dev_from_dentry(dentry);
46979 + }
46980 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46981 + error = -EACCES;
46982 + goto exit2;
46983 + }
46984 +
46985 error = mnt_want_write(nd.path.mnt);
46986 if (error)
46987 goto exit2;
46988 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46989 if (error)
46990 goto exit3;
46991 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46992 + if (!error && (saved_ino || saved_dev))
46993 + gr_handle_delete(saved_ino, saved_dev);
46994 exit3:
46995 mnt_drop_write(nd.path.mnt);
46996 exit2:
46997 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46998 error = mnt_want_write(path.mnt);
46999 if (error)
47000 goto out_dput;
47001 +
47002 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47003 + error = -EACCES;
47004 + goto out_drop_write;
47005 + }
47006 +
47007 error = security_path_symlink(&path, dentry, from);
47008 if (error)
47009 goto out_drop_write;
47010 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47011 + if (!error)
47012 + gr_handle_create(dentry, path.mnt);
47013 out_drop_write:
47014 mnt_drop_write(path.mnt);
47015 out_dput:
47016 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47017 {
47018 struct dentry *new_dentry;
47019 struct path old_path, new_path;
47020 + char *to = NULL;
47021 int how = 0;
47022 int error;
47023
47024 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47025 if (error)
47026 return error;
47027
47028 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47029 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47030 error = PTR_ERR(new_dentry);
47031 if (IS_ERR(new_dentry))
47032 goto out;
47033 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47034 error = mnt_want_write(new_path.mnt);
47035 if (error)
47036 goto out_dput;
47037 +
47038 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47039 + old_path.dentry->d_inode,
47040 + old_path.dentry->d_inode->i_mode, to)) {
47041 + error = -EACCES;
47042 + goto out_drop_write;
47043 + }
47044 +
47045 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47046 + old_path.dentry, old_path.mnt, to)) {
47047 + error = -EACCES;
47048 + goto out_drop_write;
47049 + }
47050 +
47051 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47052 if (error)
47053 goto out_drop_write;
47054 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47055 + if (!error)
47056 + gr_handle_create(new_dentry, new_path.mnt);
47057 out_drop_write:
47058 mnt_drop_write(new_path.mnt);
47059 out_dput:
47060 + putname(to);
47061 dput(new_dentry);
47062 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47063 path_put(&new_path);
47064 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47065 if (new_dentry == trap)
47066 goto exit5;
47067
47068 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47069 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47070 + to);
47071 + if (error)
47072 + goto exit5;
47073 +
47074 error = mnt_want_write(oldnd.path.mnt);
47075 if (error)
47076 goto exit5;
47077 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47078 goto exit6;
47079 error = vfs_rename(old_dir->d_inode, old_dentry,
47080 new_dir->d_inode, new_dentry);
47081 + if (!error)
47082 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47083 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47084 exit6:
47085 mnt_drop_write(oldnd.path.mnt);
47086 exit5:
47087 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47088
47089 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47090 {
47091 + char tmpbuf[64];
47092 + const char *newlink;
47093 int len;
47094
47095 len = PTR_ERR(link);
47096 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47097 len = strlen(link);
47098 if (len > (unsigned) buflen)
47099 len = buflen;
47100 - if (copy_to_user(buffer, link, len))
47101 +
47102 + if (len < sizeof(tmpbuf)) {
47103 + memcpy(tmpbuf, link, len);
47104 + newlink = tmpbuf;
47105 + } else
47106 + newlink = link;
47107 +
47108 + if (copy_to_user(buffer, newlink, len))
47109 len = -EFAULT;
47110 out:
47111 return len;
47112 diff --git a/fs/namespace.c b/fs/namespace.c
47113 index e608199..9609cb9 100644
47114 --- a/fs/namespace.c
47115 +++ b/fs/namespace.c
47116 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47117 if (!(sb->s_flags & MS_RDONLY))
47118 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47119 up_write(&sb->s_umount);
47120 +
47121 + gr_log_remount(mnt->mnt_devname, retval);
47122 +
47123 return retval;
47124 }
47125
47126 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47127 br_write_unlock(vfsmount_lock);
47128 up_write(&namespace_sem);
47129 release_mounts(&umount_list);
47130 +
47131 + gr_log_unmount(mnt->mnt_devname, retval);
47132 +
47133 return retval;
47134 }
47135
47136 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47137 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47138 MS_STRICTATIME);
47139
47140 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47141 + retval = -EPERM;
47142 + goto dput_out;
47143 + }
47144 +
47145 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47146 + retval = -EPERM;
47147 + goto dput_out;
47148 + }
47149 +
47150 if (flags & MS_REMOUNT)
47151 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47152 data_page);
47153 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47154 dev_name, data_page);
47155 dput_out:
47156 path_put(&path);
47157 +
47158 + gr_log_mount(dev_name, dir_name, retval);
47159 +
47160 return retval;
47161 }
47162
47163 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47164 if (error)
47165 goto out2;
47166
47167 + if (gr_handle_chroot_pivot()) {
47168 + error = -EPERM;
47169 + goto out2;
47170 + }
47171 +
47172 get_fs_root(current->fs, &root);
47173 error = lock_mount(&old);
47174 if (error)
47175 diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
47176 index 32c0658..b1c2045e 100644
47177 --- a/fs/ncpfs/ncplib_kernel.h
47178 +++ b/fs/ncpfs/ncplib_kernel.h
47179 @@ -130,7 +130,7 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
47180 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
47181 const unsigned char *, unsigned int, int);
47182 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47183 - const unsigned char *, unsigned int, int);
47184 + const unsigned char *, unsigned int, int) __size_overflow(5);
47185
47186 #define NCP_ESC ':'
47187 #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
47188 @@ -146,7 +146,7 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47189 int ncp__io2vol(unsigned char *, unsigned int *,
47190 const unsigned char *, unsigned int, int);
47191 int ncp__vol2io(unsigned char *, unsigned int *,
47192 - const unsigned char *, unsigned int, int);
47193 + const unsigned char *, unsigned int, int) __size_overflow(5);
47194
47195 #define NCP_IO_TABLE(sb) NULL
47196 #define ncp_tolower(t, c) tolower(c)
47197 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47198 index f649fba..236bf92 100644
47199 --- a/fs/nfs/inode.c
47200 +++ b/fs/nfs/inode.c
47201 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47202 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47203 nfsi->attrtimeo_timestamp = jiffies;
47204
47205 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47206 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47207 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47208 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47209 else
47210 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47211 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47212 }
47213
47214 -static atomic_long_t nfs_attr_generation_counter;
47215 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47216
47217 static unsigned long nfs_read_attr_generation_counter(void)
47218 {
47219 - return atomic_long_read(&nfs_attr_generation_counter);
47220 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47221 }
47222
47223 unsigned long nfs_inc_attr_generation_counter(void)
47224 {
47225 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47226 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47227 }
47228
47229 void nfs_fattr_init(struct nfs_fattr *fattr)
47230 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47231 index edf6d3e..bdd1da7 100644
47232 --- a/fs/nfsd/vfs.c
47233 +++ b/fs/nfsd/vfs.c
47234 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47235 } else {
47236 oldfs = get_fs();
47237 set_fs(KERNEL_DS);
47238 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47239 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47240 set_fs(oldfs);
47241 }
47242
47243 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47244
47245 /* Write the data. */
47246 oldfs = get_fs(); set_fs(KERNEL_DS);
47247 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47248 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47249 set_fs(oldfs);
47250 if (host_err < 0)
47251 goto out_nfserr;
47252 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47253 */
47254
47255 oldfs = get_fs(); set_fs(KERNEL_DS);
47256 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47257 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47258 set_fs(oldfs);
47259
47260 if (host_err < 0)
47261 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47262 index 3568c8a..e0240d8 100644
47263 --- a/fs/notify/fanotify/fanotify_user.c
47264 +++ b/fs/notify/fanotify/fanotify_user.c
47265 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47266 goto out_close_fd;
47267
47268 ret = -EFAULT;
47269 - if (copy_to_user(buf, &fanotify_event_metadata,
47270 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47271 + copy_to_user(buf, &fanotify_event_metadata,
47272 fanotify_event_metadata.event_len))
47273 goto out_kill_access_response;
47274
47275 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47276 index ee18815..7aa5d01 100644
47277 --- a/fs/notify/notification.c
47278 +++ b/fs/notify/notification.c
47279 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47280 * get set to 0 so it will never get 'freed'
47281 */
47282 static struct fsnotify_event *q_overflow_event;
47283 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47284 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47285
47286 /**
47287 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47288 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47289 */
47290 u32 fsnotify_get_cookie(void)
47291 {
47292 - return atomic_inc_return(&fsnotify_sync_cookie);
47293 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47294 }
47295 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47296
47297 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47298 index 99e3610..02c1068 100644
47299 --- a/fs/ntfs/dir.c
47300 +++ b/fs/ntfs/dir.c
47301 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47302 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47303 ~(s64)(ndir->itype.index.block_size - 1)));
47304 /* Bounds checks. */
47305 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47306 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47307 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47308 "inode 0x%lx or driver bug.", vdir->i_ino);
47309 goto err_out;
47310 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47311 index c587e2d..3641eaa 100644
47312 --- a/fs/ntfs/file.c
47313 +++ b/fs/ntfs/file.c
47314 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47315 #endif /* NTFS_RW */
47316 };
47317
47318 -const struct file_operations ntfs_empty_file_ops = {};
47319 +const struct file_operations ntfs_empty_file_ops __read_only;
47320
47321 -const struct inode_operations ntfs_empty_inode_ops = {};
47322 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47323 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47324 index 210c352..a174f83 100644
47325 --- a/fs/ocfs2/localalloc.c
47326 +++ b/fs/ocfs2/localalloc.c
47327 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47328 goto bail;
47329 }
47330
47331 - atomic_inc(&osb->alloc_stats.moves);
47332 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47333
47334 bail:
47335 if (handle)
47336 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47337 index d355e6e..578d905 100644
47338 --- a/fs/ocfs2/ocfs2.h
47339 +++ b/fs/ocfs2/ocfs2.h
47340 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47341
47342 struct ocfs2_alloc_stats
47343 {
47344 - atomic_t moves;
47345 - atomic_t local_data;
47346 - atomic_t bitmap_data;
47347 - atomic_t bg_allocs;
47348 - atomic_t bg_extends;
47349 + atomic_unchecked_t moves;
47350 + atomic_unchecked_t local_data;
47351 + atomic_unchecked_t bitmap_data;
47352 + atomic_unchecked_t bg_allocs;
47353 + atomic_unchecked_t bg_extends;
47354 };
47355
47356 enum ocfs2_local_alloc_state
47357 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47358 index ba5d97e..c77db25 100644
47359 --- a/fs/ocfs2/suballoc.c
47360 +++ b/fs/ocfs2/suballoc.c
47361 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47362 mlog_errno(status);
47363 goto bail;
47364 }
47365 - atomic_inc(&osb->alloc_stats.bg_extends);
47366 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47367
47368 /* You should never ask for this much metadata */
47369 BUG_ON(bits_wanted >
47370 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47371 mlog_errno(status);
47372 goto bail;
47373 }
47374 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47375 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47376
47377 *suballoc_loc = res.sr_bg_blkno;
47378 *suballoc_bit_start = res.sr_bit_offset;
47379 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47380 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47381 res->sr_bits);
47382
47383 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47384 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47385
47386 BUG_ON(res->sr_bits != 1);
47387
47388 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47389 mlog_errno(status);
47390 goto bail;
47391 }
47392 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47393 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47394
47395 BUG_ON(res.sr_bits != 1);
47396
47397 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47398 cluster_start,
47399 num_clusters);
47400 if (!status)
47401 - atomic_inc(&osb->alloc_stats.local_data);
47402 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47403 } else {
47404 if (min_clusters > (osb->bitmap_cpg - 1)) {
47405 /* The only paths asking for contiguousness
47406 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47407 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47408 res.sr_bg_blkno,
47409 res.sr_bit_offset);
47410 - atomic_inc(&osb->alloc_stats.bitmap_data);
47411 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47412 *num_clusters = res.sr_bits;
47413 }
47414 }
47415 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47416 index 604e12c..8426483 100644
47417 --- a/fs/ocfs2/super.c
47418 +++ b/fs/ocfs2/super.c
47419 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47420 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47421 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47422 "Stats",
47423 - atomic_read(&osb->alloc_stats.bitmap_data),
47424 - atomic_read(&osb->alloc_stats.local_data),
47425 - atomic_read(&osb->alloc_stats.bg_allocs),
47426 - atomic_read(&osb->alloc_stats.moves),
47427 - atomic_read(&osb->alloc_stats.bg_extends));
47428 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47429 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47430 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47431 + atomic_read_unchecked(&osb->alloc_stats.moves),
47432 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47433
47434 out += snprintf(buf + out, len - out,
47435 "%10s => State: %u Descriptor: %llu Size: %u bits "
47436 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47437 spin_lock_init(&osb->osb_xattr_lock);
47438 ocfs2_init_steal_slots(osb);
47439
47440 - atomic_set(&osb->alloc_stats.moves, 0);
47441 - atomic_set(&osb->alloc_stats.local_data, 0);
47442 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47443 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47444 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47445 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47446 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47447 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47448 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47449 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47450
47451 /* Copy the blockcheck stats from the superblock probe */
47452 osb->osb_ecc_stats = *stats;
47453 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47454 index 5d22872..523db20 100644
47455 --- a/fs/ocfs2/symlink.c
47456 +++ b/fs/ocfs2/symlink.c
47457 @@ -142,7 +142,7 @@ bail:
47458
47459 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47460 {
47461 - char *link = nd_get_link(nd);
47462 + const char *link = nd_get_link(nd);
47463 if (!IS_ERR(link))
47464 kfree(link);
47465 }
47466 diff --git a/fs/open.c b/fs/open.c
47467 index 77becc0..aad7bd9 100644
47468 --- a/fs/open.c
47469 +++ b/fs/open.c
47470 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47471 error = locks_verify_truncate(inode, NULL, length);
47472 if (!error)
47473 error = security_path_truncate(&path);
47474 +
47475 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47476 + error = -EACCES;
47477 +
47478 if (!error)
47479 error = do_truncate(path.dentry, length, 0, NULL);
47480
47481 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47482 if (__mnt_is_readonly(path.mnt))
47483 res = -EROFS;
47484
47485 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47486 + res = -EACCES;
47487 +
47488 out_path_release:
47489 path_put(&path);
47490 out:
47491 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47492 if (error)
47493 goto dput_and_out;
47494
47495 + gr_log_chdir(path.dentry, path.mnt);
47496 +
47497 set_fs_pwd(current->fs, &path);
47498
47499 dput_and_out:
47500 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47501 goto out_putf;
47502
47503 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47504 +
47505 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47506 + error = -EPERM;
47507 +
47508 + if (!error)
47509 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47510 +
47511 if (!error)
47512 set_fs_pwd(current->fs, &file->f_path);
47513 out_putf:
47514 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47515 if (error)
47516 goto dput_and_out;
47517
47518 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47519 + goto dput_and_out;
47520 +
47521 set_fs_root(current->fs, &path);
47522 +
47523 + gr_handle_chroot_chdir(&path);
47524 +
47525 error = 0;
47526 dput_and_out:
47527 path_put(&path);
47528 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47529 if (error)
47530 return error;
47531 mutex_lock(&inode->i_mutex);
47532 +
47533 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47534 + error = -EACCES;
47535 + goto out_unlock;
47536 + }
47537 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47538 + error = -EACCES;
47539 + goto out_unlock;
47540 + }
47541 +
47542 error = security_path_chmod(path, mode);
47543 if (error)
47544 goto out_unlock;
47545 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47546 int error;
47547 struct iattr newattrs;
47548
47549 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47550 + return -EACCES;
47551 +
47552 newattrs.ia_valid = ATTR_CTIME;
47553 if (user != (uid_t) -1) {
47554 newattrs.ia_valid |= ATTR_UID;
47555 diff --git a/fs/pipe.c b/fs/pipe.c
47556 index a932ced..6495412 100644
47557 --- a/fs/pipe.c
47558 +++ b/fs/pipe.c
47559 @@ -420,9 +420,9 @@ redo:
47560 }
47561 if (bufs) /* More to do? */
47562 continue;
47563 - if (!pipe->writers)
47564 + if (!atomic_read(&pipe->writers))
47565 break;
47566 - if (!pipe->waiting_writers) {
47567 + if (!atomic_read(&pipe->waiting_writers)) {
47568 /* syscall merging: Usually we must not sleep
47569 * if O_NONBLOCK is set, or if we got some data.
47570 * But if a writer sleeps in kernel space, then
47571 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47572 mutex_lock(&inode->i_mutex);
47573 pipe = inode->i_pipe;
47574
47575 - if (!pipe->readers) {
47576 + if (!atomic_read(&pipe->readers)) {
47577 send_sig(SIGPIPE, current, 0);
47578 ret = -EPIPE;
47579 goto out;
47580 @@ -530,7 +530,7 @@ redo1:
47581 for (;;) {
47582 int bufs;
47583
47584 - if (!pipe->readers) {
47585 + if (!atomic_read(&pipe->readers)) {
47586 send_sig(SIGPIPE, current, 0);
47587 if (!ret)
47588 ret = -EPIPE;
47589 @@ -616,9 +616,9 @@ redo2:
47590 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47591 do_wakeup = 0;
47592 }
47593 - pipe->waiting_writers++;
47594 + atomic_inc(&pipe->waiting_writers);
47595 pipe_wait(pipe);
47596 - pipe->waiting_writers--;
47597 + atomic_dec(&pipe->waiting_writers);
47598 }
47599 out:
47600 mutex_unlock(&inode->i_mutex);
47601 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47602 mask = 0;
47603 if (filp->f_mode & FMODE_READ) {
47604 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47605 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47606 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47607 mask |= POLLHUP;
47608 }
47609
47610 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47611 * Most Unices do not set POLLERR for FIFOs but on Linux they
47612 * behave exactly like pipes for poll().
47613 */
47614 - if (!pipe->readers)
47615 + if (!atomic_read(&pipe->readers))
47616 mask |= POLLERR;
47617 }
47618
47619 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47620
47621 mutex_lock(&inode->i_mutex);
47622 pipe = inode->i_pipe;
47623 - pipe->readers -= decr;
47624 - pipe->writers -= decw;
47625 + atomic_sub(decr, &pipe->readers);
47626 + atomic_sub(decw, &pipe->writers);
47627
47628 - if (!pipe->readers && !pipe->writers) {
47629 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47630 free_pipe_info(inode);
47631 } else {
47632 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47633 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47634
47635 if (inode->i_pipe) {
47636 ret = 0;
47637 - inode->i_pipe->readers++;
47638 + atomic_inc(&inode->i_pipe->readers);
47639 }
47640
47641 mutex_unlock(&inode->i_mutex);
47642 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47643
47644 if (inode->i_pipe) {
47645 ret = 0;
47646 - inode->i_pipe->writers++;
47647 + atomic_inc(&inode->i_pipe->writers);
47648 }
47649
47650 mutex_unlock(&inode->i_mutex);
47651 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47652 if (inode->i_pipe) {
47653 ret = 0;
47654 if (filp->f_mode & FMODE_READ)
47655 - inode->i_pipe->readers++;
47656 + atomic_inc(&inode->i_pipe->readers);
47657 if (filp->f_mode & FMODE_WRITE)
47658 - inode->i_pipe->writers++;
47659 + atomic_inc(&inode->i_pipe->writers);
47660 }
47661
47662 mutex_unlock(&inode->i_mutex);
47663 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
47664 inode->i_pipe = NULL;
47665 }
47666
47667 -static struct vfsmount *pipe_mnt __read_mostly;
47668 +struct vfsmount *pipe_mnt __read_mostly;
47669
47670 /*
47671 * pipefs_dname() is called from d_path().
47672 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
47673 goto fail_iput;
47674 inode->i_pipe = pipe;
47675
47676 - pipe->readers = pipe->writers = 1;
47677 + atomic_set(&pipe->readers, 1);
47678 + atomic_set(&pipe->writers, 1);
47679 inode->i_fop = &rdwr_pipefifo_fops;
47680
47681 /*
47682 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47683 index 15af622..0e9f4467 100644
47684 --- a/fs/proc/Kconfig
47685 +++ b/fs/proc/Kconfig
47686 @@ -30,12 +30,12 @@ config PROC_FS
47687
47688 config PROC_KCORE
47689 bool "/proc/kcore support" if !ARM
47690 - depends on PROC_FS && MMU
47691 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47692
47693 config PROC_VMCORE
47694 bool "/proc/vmcore support"
47695 - depends on PROC_FS && CRASH_DUMP
47696 - default y
47697 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47698 + default n
47699 help
47700 Exports the dump image of crashed kernel in ELF format.
47701
47702 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47703 limited in memory.
47704
47705 config PROC_PAGE_MONITOR
47706 - default y
47707 - depends on PROC_FS && MMU
47708 + default n
47709 + depends on PROC_FS && MMU && !GRKERNSEC
47710 bool "Enable /proc page monitoring" if EXPERT
47711 help
47712 Various /proc files exist to monitor process memory utilization:
47713 diff --git a/fs/proc/array.c b/fs/proc/array.c
47714 index c602b8d..a7de642 100644
47715 --- a/fs/proc/array.c
47716 +++ b/fs/proc/array.c
47717 @@ -60,6 +60,7 @@
47718 #include <linux/tty.h>
47719 #include <linux/string.h>
47720 #include <linux/mman.h>
47721 +#include <linux/grsecurity.h>
47722 #include <linux/proc_fs.h>
47723 #include <linux/ioport.h>
47724 #include <linux/uaccess.h>
47725 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47726 seq_putc(m, '\n');
47727 }
47728
47729 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47730 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47731 +{
47732 + if (p->mm)
47733 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47734 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47735 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47736 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47737 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47738 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47739 + else
47740 + seq_printf(m, "PaX:\t-----\n");
47741 +}
47742 +#endif
47743 +
47744 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47745 struct pid *pid, struct task_struct *task)
47746 {
47747 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47748 task_cpus_allowed(m, task);
47749 cpuset_task_status_allowed(m, task);
47750 task_context_switch_counts(m, task);
47751 +
47752 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47753 + task_pax(m, task);
47754 +#endif
47755 +
47756 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47757 + task_grsec_rbac(m, task);
47758 +#endif
47759 +
47760 return 0;
47761 }
47762
47763 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47764 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47765 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47766 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47767 +#endif
47768 +
47769 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47770 struct pid *pid, struct task_struct *task, int whole)
47771 {
47772 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47773 char tcomm[sizeof(task->comm)];
47774 unsigned long flags;
47775
47776 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47777 + if (current->exec_id != m->exec_id) {
47778 + gr_log_badprocpid("stat");
47779 + return 0;
47780 + }
47781 +#endif
47782 +
47783 state = *get_task_state(task);
47784 vsize = eip = esp = 0;
47785 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47786 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47787 gtime = task->gtime;
47788 }
47789
47790 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47791 + if (PAX_RAND_FLAGS(mm)) {
47792 + eip = 0;
47793 + esp = 0;
47794 + wchan = 0;
47795 + }
47796 +#endif
47797 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47798 + wchan = 0;
47799 + eip =0;
47800 + esp =0;
47801 +#endif
47802 +
47803 /* scale priority and nice values from timeslices to -20..20 */
47804 /* to make it look like a "normal" Unix priority/nice value */
47805 priority = task_prio(task);
47806 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47807 vsize,
47808 mm ? get_mm_rss(mm) : 0,
47809 rsslim,
47810 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47811 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47812 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47813 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47814 +#else
47815 mm ? (permitted ? mm->start_code : 1) : 0,
47816 mm ? (permitted ? mm->end_code : 1) : 0,
47817 (permitted && mm) ? mm->start_stack : 0,
47818 +#endif
47819 esp,
47820 eip,
47821 /* The signal information here is obsolete.
47822 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47823 struct pid *pid, struct task_struct *task)
47824 {
47825 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47826 - struct mm_struct *mm = get_task_mm(task);
47827 + struct mm_struct *mm;
47828
47829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47830 + if (current->exec_id != m->exec_id) {
47831 + gr_log_badprocpid("statm");
47832 + return 0;
47833 + }
47834 +#endif
47835 + mm = get_task_mm(task);
47836 if (mm) {
47837 size = task_statm(mm, &shared, &text, &data, &resident);
47838 mmput(mm);
47839 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47840
47841 return 0;
47842 }
47843 +
47844 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47845 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47846 +{
47847 + u32 curr_ip = 0;
47848 + unsigned long flags;
47849 +
47850 + if (lock_task_sighand(task, &flags)) {
47851 + curr_ip = task->signal->curr_ip;
47852 + unlock_task_sighand(task, &flags);
47853 + }
47854 +
47855 + return sprintf(buffer, "%pI4\n", &curr_ip);
47856 +}
47857 +#endif
47858 diff --git a/fs/proc/base.c b/fs/proc/base.c
47859 index d4548dd..d101f84 100644
47860 --- a/fs/proc/base.c
47861 +++ b/fs/proc/base.c
47862 @@ -109,6 +109,14 @@ struct pid_entry {
47863 union proc_op op;
47864 };
47865
47866 +struct getdents_callback {
47867 + struct linux_dirent __user * current_dir;
47868 + struct linux_dirent __user * previous;
47869 + struct file * file;
47870 + int count;
47871 + int error;
47872 +};
47873 +
47874 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47875 .name = (NAME), \
47876 .len = sizeof(NAME) - 1, \
47877 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47878 if (!mm->arg_end)
47879 goto out_mm; /* Shh! No looking before we're done */
47880
47881 + if (gr_acl_handle_procpidmem(task))
47882 + goto out_mm;
47883 +
47884 len = mm->arg_end - mm->arg_start;
47885
47886 if (len > PAGE_SIZE)
47887 @@ -240,12 +251,28 @@ out:
47888 return res;
47889 }
47890
47891 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47892 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47893 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47894 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47895 +#endif
47896 +
47897 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47898 {
47899 struct mm_struct *mm = mm_for_maps(task);
47900 int res = PTR_ERR(mm);
47901 if (mm && !IS_ERR(mm)) {
47902 unsigned int nwords = 0;
47903 +
47904 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47905 + /* allow if we're currently ptracing this task */
47906 + if (PAX_RAND_FLAGS(mm) &&
47907 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47908 + mmput(mm);
47909 + return 0;
47910 + }
47911 +#endif
47912 +
47913 do {
47914 nwords += 2;
47915 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47916 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47917 }
47918
47919
47920 -#ifdef CONFIG_KALLSYMS
47921 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47922 /*
47923 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47924 * Returns the resolved symbol. If that fails, simply return the address.
47925 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47926 mutex_unlock(&task->signal->cred_guard_mutex);
47927 }
47928
47929 -#ifdef CONFIG_STACKTRACE
47930 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47931
47932 #define MAX_STACK_TRACE_DEPTH 64
47933
47934 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47935 return count;
47936 }
47937
47938 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47939 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47940 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47941 {
47942 long nr;
47943 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47944 /************************************************************************/
47945
47946 /* permission checks */
47947 -static int proc_fd_access_allowed(struct inode *inode)
47948 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47949 {
47950 struct task_struct *task;
47951 int allowed = 0;
47952 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47953 */
47954 task = get_proc_task(inode);
47955 if (task) {
47956 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47957 + if (log)
47958 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47959 + else
47960 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47961 put_task_struct(task);
47962 }
47963 return allowed;
47964 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47965 struct task_struct *task,
47966 int hide_pid_min)
47967 {
47968 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47969 + return false;
47970 +
47971 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47972 + rcu_read_lock();
47973 + {
47974 + const struct cred *tmpcred = current_cred();
47975 + const struct cred *cred = __task_cred(task);
47976 +
47977 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47978 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47979 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47980 +#endif
47981 + ) {
47982 + rcu_read_unlock();
47983 + return true;
47984 + }
47985 + }
47986 + rcu_read_unlock();
47987 +
47988 + if (!pid->hide_pid)
47989 + return false;
47990 +#endif
47991 +
47992 if (pid->hide_pid < hide_pid_min)
47993 return true;
47994 if (in_group_p(pid->pid_gid))
47995 return true;
47996 +
47997 return ptrace_may_access(task, PTRACE_MODE_READ);
47998 }
47999
48000 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48001 put_task_struct(task);
48002
48003 if (!has_perms) {
48004 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48005 + {
48006 +#else
48007 if (pid->hide_pid == 2) {
48008 +#endif
48009 /*
48010 * Let's make getdents(), stat(), and open()
48011 * consistent with each other. If a process
48012 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
48013 file->f_mode |= FMODE_UNSIGNED_OFFSET;
48014 file->private_data = mm;
48015
48016 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48017 + file->f_version = current->exec_id;
48018 +#endif
48019 +
48020 return 0;
48021 }
48022
48023 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48024 ssize_t copied;
48025 char *page;
48026
48027 +#ifdef CONFIG_GRKERNSEC
48028 + if (write)
48029 + return -EPERM;
48030 +#endif
48031 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48032 + if (file->f_version != current->exec_id) {
48033 + gr_log_badprocpid("mem");
48034 + return 0;
48035 + }
48036 +#endif
48037 +
48038 if (!mm)
48039 return 0;
48040
48041 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48042 if (!task)
48043 goto out_no_task;
48044
48045 + if (gr_acl_handle_procpidmem(task))
48046 + goto out;
48047 +
48048 ret = -ENOMEM;
48049 page = (char *)__get_free_page(GFP_TEMPORARY);
48050 if (!page)
48051 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48052 path_put(&nd->path);
48053
48054 /* Are we allowed to snoop on the tasks file descriptors? */
48055 - if (!proc_fd_access_allowed(inode))
48056 + if (!proc_fd_access_allowed(inode, 0))
48057 goto out;
48058
48059 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48060 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48061 struct path path;
48062
48063 /* Are we allowed to snoop on the tasks file descriptors? */
48064 - if (!proc_fd_access_allowed(inode))
48065 - goto out;
48066 + /* logging this is needed for learning on chromium to work properly,
48067 + but we don't want to flood the logs from 'ps' which does a readlink
48068 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48069 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48070 + */
48071 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48072 + if (!proc_fd_access_allowed(inode,0))
48073 + goto out;
48074 + } else {
48075 + if (!proc_fd_access_allowed(inode,1))
48076 + goto out;
48077 + }
48078
48079 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48080 if (error)
48081 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48082 rcu_read_lock();
48083 cred = __task_cred(task);
48084 inode->i_uid = cred->euid;
48085 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48086 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48087 +#else
48088 inode->i_gid = cred->egid;
48089 +#endif
48090 rcu_read_unlock();
48091 }
48092 security_task_to_inode(task, inode);
48093 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48094 return -ENOENT;
48095 }
48096 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48097 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48098 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48099 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48100 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48101 +#endif
48102 task_dumpable(task)) {
48103 cred = __task_cred(task);
48104 stat->uid = cred->euid;
48105 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48106 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48107 +#else
48108 stat->gid = cred->egid;
48109 +#endif
48110 }
48111 }
48112 rcu_read_unlock();
48113 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48114
48115 if (task) {
48116 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48117 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48118 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48119 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48120 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48121 +#endif
48122 task_dumpable(task)) {
48123 rcu_read_lock();
48124 cred = __task_cred(task);
48125 inode->i_uid = cred->euid;
48126 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48127 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48128 +#else
48129 inode->i_gid = cred->egid;
48130 +#endif
48131 rcu_read_unlock();
48132 } else {
48133 inode->i_uid = 0;
48134 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48135 int fd = proc_fd(inode);
48136
48137 if (task) {
48138 - files = get_files_struct(task);
48139 + if (!gr_acl_handle_procpidmem(task))
48140 + files = get_files_struct(task);
48141 put_task_struct(task);
48142 }
48143 if (files) {
48144 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48145 */
48146 static int proc_fd_permission(struct inode *inode, int mask)
48147 {
48148 + struct task_struct *task;
48149 int rv = generic_permission(inode, mask);
48150 - if (rv == 0)
48151 - return 0;
48152 +
48153 if (task_pid(current) == proc_pid(inode))
48154 rv = 0;
48155 +
48156 + task = get_proc_task(inode);
48157 + if (task == NULL)
48158 + return rv;
48159 +
48160 + if (gr_acl_handle_procpidmem(task))
48161 + rv = -EACCES;
48162 +
48163 + put_task_struct(task);
48164 +
48165 return rv;
48166 }
48167
48168 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48169 if (!task)
48170 goto out_no_task;
48171
48172 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48173 + goto out;
48174 +
48175 /*
48176 * Yes, it does not scale. And it should not. Don't add
48177 * new entries into /proc/<tgid>/ without very good reasons.
48178 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48179 if (!task)
48180 goto out_no_task;
48181
48182 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48183 + goto out;
48184 +
48185 ret = 0;
48186 i = filp->f_pos;
48187 switch (i) {
48188 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48189 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48190 void *cookie)
48191 {
48192 - char *s = nd_get_link(nd);
48193 + const char *s = nd_get_link(nd);
48194 if (!IS_ERR(s))
48195 __putname(s);
48196 }
48197 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48198 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48199 #endif
48200 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48201 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48202 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48203 INF("syscall", S_IRUGO, proc_pid_syscall),
48204 #endif
48205 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48206 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48207 #ifdef CONFIG_SECURITY
48208 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48209 #endif
48210 -#ifdef CONFIG_KALLSYMS
48211 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48212 INF("wchan", S_IRUGO, proc_pid_wchan),
48213 #endif
48214 -#ifdef CONFIG_STACKTRACE
48215 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48216 ONE("stack", S_IRUGO, proc_pid_stack),
48217 #endif
48218 #ifdef CONFIG_SCHEDSTATS
48219 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48220 #ifdef CONFIG_HARDWALL
48221 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48222 #endif
48223 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48224 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48225 +#endif
48226 };
48227
48228 static int proc_tgid_base_readdir(struct file * filp,
48229 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48230 if (!inode)
48231 goto out;
48232
48233 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48234 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48235 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48236 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48237 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48238 +#else
48239 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48240 +#endif
48241 inode->i_op = &proc_tgid_base_inode_operations;
48242 inode->i_fop = &proc_tgid_base_operations;
48243 inode->i_flags|=S_IMMUTABLE;
48244 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48245 if (!task)
48246 goto out;
48247
48248 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48249 + goto out_put_task;
48250 +
48251 result = proc_pid_instantiate(dir, dentry, task, NULL);
48252 +out_put_task:
48253 put_task_struct(task);
48254 out:
48255 return result;
48256 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48257 static int fake_filldir(void *buf, const char *name, int namelen,
48258 loff_t offset, u64 ino, unsigned d_type)
48259 {
48260 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48261 + __buf->error = -EINVAL;
48262 return 0;
48263 }
48264
48265 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48266 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48267 #endif
48268 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48269 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48270 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48271 INF("syscall", S_IRUGO, proc_pid_syscall),
48272 #endif
48273 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48274 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48275 #ifdef CONFIG_SECURITY
48276 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48277 #endif
48278 -#ifdef CONFIG_KALLSYMS
48279 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48280 INF("wchan", S_IRUGO, proc_pid_wchan),
48281 #endif
48282 -#ifdef CONFIG_STACKTRACE
48283 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48284 ONE("stack", S_IRUGO, proc_pid_stack),
48285 #endif
48286 #ifdef CONFIG_SCHEDSTATS
48287 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48288 index 82676e3..5f8518a 100644
48289 --- a/fs/proc/cmdline.c
48290 +++ b/fs/proc/cmdline.c
48291 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48292
48293 static int __init proc_cmdline_init(void)
48294 {
48295 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48296 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48297 +#else
48298 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48299 +#endif
48300 return 0;
48301 }
48302 module_init(proc_cmdline_init);
48303 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48304 index b143471..bb105e5 100644
48305 --- a/fs/proc/devices.c
48306 +++ b/fs/proc/devices.c
48307 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48308
48309 static int __init proc_devices_init(void)
48310 {
48311 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48312 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48313 +#else
48314 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48315 +#endif
48316 return 0;
48317 }
48318 module_init(proc_devices_init);
48319 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48320 index 84fd323..f698a32 100644
48321 --- a/fs/proc/inode.c
48322 +++ b/fs/proc/inode.c
48323 @@ -21,12 +21,18 @@
48324 #include <linux/seq_file.h>
48325 #include <linux/slab.h>
48326 #include <linux/mount.h>
48327 +#include <linux/grsecurity.h>
48328
48329 #include <asm/system.h>
48330 #include <asm/uaccess.h>
48331
48332 #include "internal.h"
48333
48334 +#ifdef CONFIG_PROC_SYSCTL
48335 +extern const struct inode_operations proc_sys_inode_operations;
48336 +extern const struct inode_operations proc_sys_dir_operations;
48337 +#endif
48338 +
48339 static void proc_evict_inode(struct inode *inode)
48340 {
48341 struct proc_dir_entry *de;
48342 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48343 ns_ops = PROC_I(inode)->ns_ops;
48344 if (ns_ops && ns_ops->put)
48345 ns_ops->put(PROC_I(inode)->ns);
48346 +
48347 +#ifdef CONFIG_PROC_SYSCTL
48348 + if (inode->i_op == &proc_sys_inode_operations ||
48349 + inode->i_op == &proc_sys_dir_operations)
48350 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48351 +#endif
48352 +
48353 }
48354
48355 static struct kmem_cache * proc_inode_cachep;
48356 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48357 if (de->mode) {
48358 inode->i_mode = de->mode;
48359 inode->i_uid = de->uid;
48360 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48361 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48362 +#else
48363 inode->i_gid = de->gid;
48364 +#endif
48365 }
48366 if (de->size)
48367 inode->i_size = de->size;
48368 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48369 index 2925775..4f08fae 100644
48370 --- a/fs/proc/internal.h
48371 +++ b/fs/proc/internal.h
48372 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48373 struct pid *pid, struct task_struct *task);
48374 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48375 struct pid *pid, struct task_struct *task);
48376 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48377 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48378 +#endif
48379 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48380
48381 extern const struct file_operations proc_maps_operations;
48382 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48383 index d245cb2..f4e8498 100644
48384 --- a/fs/proc/kcore.c
48385 +++ b/fs/proc/kcore.c
48386 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48387 * the addresses in the elf_phdr on our list.
48388 */
48389 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48390 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48391 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48392 + if (tsz > buflen)
48393 tsz = buflen;
48394 -
48395 +
48396 while (buflen) {
48397 struct kcore_list *m;
48398
48399 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48400 kfree(elf_buf);
48401 } else {
48402 if (kern_addr_valid(start)) {
48403 - unsigned long n;
48404 + char *elf_buf;
48405 + mm_segment_t oldfs;
48406
48407 - n = copy_to_user(buffer, (char *)start, tsz);
48408 - /*
48409 - * We cannot distingush between fault on source
48410 - * and fault on destination. When this happens
48411 - * we clear too and hope it will trigger the
48412 - * EFAULT again.
48413 - */
48414 - if (n) {
48415 - if (clear_user(buffer + tsz - n,
48416 - n))
48417 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48418 + if (!elf_buf)
48419 + return -ENOMEM;
48420 + oldfs = get_fs();
48421 + set_fs(KERNEL_DS);
48422 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48423 + set_fs(oldfs);
48424 + if (copy_to_user(buffer, elf_buf, tsz)) {
48425 + kfree(elf_buf);
48426 return -EFAULT;
48427 + }
48428 }
48429 + set_fs(oldfs);
48430 + kfree(elf_buf);
48431 } else {
48432 if (clear_user(buffer, tsz))
48433 return -EFAULT;
48434 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48435
48436 static int open_kcore(struct inode *inode, struct file *filp)
48437 {
48438 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48439 + return -EPERM;
48440 +#endif
48441 if (!capable(CAP_SYS_RAWIO))
48442 return -EPERM;
48443 if (kcore_need_update)
48444 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48445 index 80e4645..53e5fcf 100644
48446 --- a/fs/proc/meminfo.c
48447 +++ b/fs/proc/meminfo.c
48448 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48449 vmi.used >> 10,
48450 vmi.largest_chunk >> 10
48451 #ifdef CONFIG_MEMORY_FAILURE
48452 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48453 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48454 #endif
48455 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48456 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48457 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48458 index b1822dd..df622cb 100644
48459 --- a/fs/proc/nommu.c
48460 +++ b/fs/proc/nommu.c
48461 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48462 if (len < 1)
48463 len = 1;
48464 seq_printf(m, "%*c", len, ' ');
48465 - seq_path(m, &file->f_path, "");
48466 + seq_path(m, &file->f_path, "\n\\");
48467 }
48468
48469 seq_putc(m, '\n');
48470 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48471 index 06e1cc1..177cd98 100644
48472 --- a/fs/proc/proc_net.c
48473 +++ b/fs/proc/proc_net.c
48474 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48475 struct task_struct *task;
48476 struct nsproxy *ns;
48477 struct net *net = NULL;
48478 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48479 + const struct cred *cred = current_cred();
48480 +#endif
48481 +
48482 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48483 + if (cred->fsuid)
48484 + return net;
48485 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48486 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48487 + return net;
48488 +#endif
48489
48490 rcu_read_lock();
48491 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48492 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48493 index 53c3bce..10ad159 100644
48494 --- a/fs/proc/proc_sysctl.c
48495 +++ b/fs/proc/proc_sysctl.c
48496 @@ -9,11 +9,13 @@
48497 #include <linux/namei.h>
48498 #include "internal.h"
48499
48500 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48501 +
48502 static const struct dentry_operations proc_sys_dentry_operations;
48503 static const struct file_operations proc_sys_file_operations;
48504 -static const struct inode_operations proc_sys_inode_operations;
48505 +const struct inode_operations proc_sys_inode_operations;
48506 static const struct file_operations proc_sys_dir_file_operations;
48507 -static const struct inode_operations proc_sys_dir_operations;
48508 +const struct inode_operations proc_sys_dir_operations;
48509
48510 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48511 {
48512 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48513
48514 err = NULL;
48515 d_set_d_op(dentry, &proc_sys_dentry_operations);
48516 +
48517 + gr_handle_proc_create(dentry, inode);
48518 +
48519 d_add(dentry, inode);
48520
48521 + if (gr_handle_sysctl(p, MAY_EXEC))
48522 + err = ERR_PTR(-ENOENT);
48523 +
48524 out:
48525 sysctl_head_finish(head);
48526 return err;
48527 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48528 if (!table->proc_handler)
48529 goto out;
48530
48531 +#ifdef CONFIG_GRKERNSEC
48532 + error = -EPERM;
48533 + if (write && !capable(CAP_SYS_ADMIN))
48534 + goto out;
48535 +#endif
48536 +
48537 /* careful: calling conventions are nasty here */
48538 res = count;
48539 error = table->proc_handler(table, write, buf, &res, ppos);
48540 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48541 return -ENOMEM;
48542 } else {
48543 d_set_d_op(child, &proc_sys_dentry_operations);
48544 +
48545 + gr_handle_proc_create(child, inode);
48546 +
48547 d_add(child, inode);
48548 }
48549 } else {
48550 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48551 if (*pos < file->f_pos)
48552 continue;
48553
48554 + if (gr_handle_sysctl(table, 0))
48555 + continue;
48556 +
48557 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48558 if (res)
48559 return res;
48560 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48561 if (IS_ERR(head))
48562 return PTR_ERR(head);
48563
48564 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48565 + return -ENOENT;
48566 +
48567 generic_fillattr(inode, stat);
48568 if (table)
48569 stat->mode = (stat->mode & S_IFMT) | table->mode;
48570 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48571 .llseek = generic_file_llseek,
48572 };
48573
48574 -static const struct inode_operations proc_sys_inode_operations = {
48575 +const struct inode_operations proc_sys_inode_operations = {
48576 .permission = proc_sys_permission,
48577 .setattr = proc_sys_setattr,
48578 .getattr = proc_sys_getattr,
48579 };
48580
48581 -static const struct inode_operations proc_sys_dir_operations = {
48582 +const struct inode_operations proc_sys_dir_operations = {
48583 .lookup = proc_sys_lookup,
48584 .permission = proc_sys_permission,
48585 .setattr = proc_sys_setattr,
48586 diff --git a/fs/proc/root.c b/fs/proc/root.c
48587 index 46a15d8..335631a 100644
48588 --- a/fs/proc/root.c
48589 +++ b/fs/proc/root.c
48590 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
48591 #ifdef CONFIG_PROC_DEVICETREE
48592 proc_device_tree_init();
48593 #endif
48594 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48595 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48596 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48597 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48598 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48599 +#endif
48600 +#else
48601 proc_mkdir("bus", NULL);
48602 +#endif
48603 proc_sys_init();
48604 }
48605
48606 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48607 index 3efa725..23c925b 100644
48608 --- a/fs/proc/task_mmu.c
48609 +++ b/fs/proc/task_mmu.c
48610 @@ -11,6 +11,7 @@
48611 #include <linux/rmap.h>
48612 #include <linux/swap.h>
48613 #include <linux/swapops.h>
48614 +#include <linux/grsecurity.h>
48615
48616 #include <asm/elf.h>
48617 #include <asm/uaccess.h>
48618 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48619 "VmExe:\t%8lu kB\n"
48620 "VmLib:\t%8lu kB\n"
48621 "VmPTE:\t%8lu kB\n"
48622 - "VmSwap:\t%8lu kB\n",
48623 - hiwater_vm << (PAGE_SHIFT-10),
48624 + "VmSwap:\t%8lu kB\n"
48625 +
48626 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48627 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48628 +#endif
48629 +
48630 + ,hiwater_vm << (PAGE_SHIFT-10),
48631 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48632 mm->locked_vm << (PAGE_SHIFT-10),
48633 mm->pinned_vm << (PAGE_SHIFT-10),
48634 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48635 data << (PAGE_SHIFT-10),
48636 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48637 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48638 - swap << (PAGE_SHIFT-10));
48639 + swap << (PAGE_SHIFT-10)
48640 +
48641 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48642 + , mm->context.user_cs_base, mm->context.user_cs_limit
48643 +#endif
48644 +
48645 + );
48646 }
48647
48648 unsigned long task_vsize(struct mm_struct *mm)
48649 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48650 return ret;
48651 }
48652
48653 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48654 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48655 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48656 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48657 +#endif
48658 +
48659 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48660 {
48661 struct mm_struct *mm = vma->vm_mm;
48662 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48663 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48664 }
48665
48666 - /* We don't show the stack guard page in /proc/maps */
48667 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48668 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48669 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48670 +#else
48671 start = vma->vm_start;
48672 - if (stack_guard_page_start(vma, start))
48673 - start += PAGE_SIZE;
48674 end = vma->vm_end;
48675 - if (stack_guard_page_end(vma, end))
48676 - end -= PAGE_SIZE;
48677 +#endif
48678
48679 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48680 start,
48681 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48682 flags & VM_WRITE ? 'w' : '-',
48683 flags & VM_EXEC ? 'x' : '-',
48684 flags & VM_MAYSHARE ? 's' : 'p',
48685 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48686 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48687 +#else
48688 pgoff,
48689 +#endif
48690 MAJOR(dev), MINOR(dev), ino, &len);
48691
48692 /*
48693 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48694 */
48695 if (file) {
48696 pad_len_spaces(m, len);
48697 - seq_path(m, &file->f_path, "\n");
48698 + seq_path(m, &file->f_path, "\n\\");
48699 } else {
48700 const char *name = arch_vma_name(vma);
48701 if (!name) {
48702 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48703 if (vma->vm_start <= mm->brk &&
48704 vma->vm_end >= mm->start_brk) {
48705 name = "[heap]";
48706 - } else if (vma->vm_start <= mm->start_stack &&
48707 - vma->vm_end >= mm->start_stack) {
48708 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48709 + (vma->vm_start <= mm->start_stack &&
48710 + vma->vm_end >= mm->start_stack)) {
48711 name = "[stack]";
48712 }
48713 } else {
48714 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48715 struct proc_maps_private *priv = m->private;
48716 struct task_struct *task = priv->task;
48717
48718 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48719 + if (current->exec_id != m->exec_id) {
48720 + gr_log_badprocpid("maps");
48721 + return 0;
48722 + }
48723 +#endif
48724 +
48725 show_map_vma(m, vma);
48726
48727 if (m->count < m->size) /* vma is copied successfully */
48728 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
48729 .private = &mss,
48730 };
48731
48732 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48733 + if (current->exec_id != m->exec_id) {
48734 + gr_log_badprocpid("smaps");
48735 + return 0;
48736 + }
48737 +#endif
48738 memset(&mss, 0, sizeof mss);
48739 - mss.vma = vma;
48740 - /* mmap_sem is held in m_start */
48741 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48742 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48743 -
48744 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48745 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48746 +#endif
48747 + mss.vma = vma;
48748 + /* mmap_sem is held in m_start */
48749 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48750 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48751 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48752 + }
48753 +#endif
48754 show_map_vma(m, vma);
48755
48756 seq_printf(m,
48757 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
48758 "KernelPageSize: %8lu kB\n"
48759 "MMUPageSize: %8lu kB\n"
48760 "Locked: %8lu kB\n",
48761 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48762 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48763 +#else
48764 (vma->vm_end - vma->vm_start) >> 10,
48765 +#endif
48766 mss.resident >> 10,
48767 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48768 mss.shared_clean >> 10,
48769 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48770 int n;
48771 char buffer[50];
48772
48773 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48774 + if (current->exec_id != m->exec_id) {
48775 + gr_log_badprocpid("numa_maps");
48776 + return 0;
48777 + }
48778 +#endif
48779 +
48780 if (!mm)
48781 return 0;
48782
48783 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48784 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48785 mpol_cond_put(pol);
48786
48787 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48788 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48789 +#else
48790 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48791 +#endif
48792
48793 if (file) {
48794 seq_printf(m, " file=");
48795 - seq_path(m, &file->f_path, "\n\t= ");
48796 + seq_path(m, &file->f_path, "\n\t\\= ");
48797 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48798 seq_printf(m, " heap");
48799 } else if (vma->vm_start <= mm->start_stack &&
48800 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48801 index 980de54..2a4db5f 100644
48802 --- a/fs/proc/task_nommu.c
48803 +++ b/fs/proc/task_nommu.c
48804 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48805 else
48806 bytes += kobjsize(mm);
48807
48808 - if (current->fs && current->fs->users > 1)
48809 + if (current->fs && atomic_read(&current->fs->users) > 1)
48810 sbytes += kobjsize(current->fs);
48811 else
48812 bytes += kobjsize(current->fs);
48813 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48814
48815 if (file) {
48816 pad_len_spaces(m, len);
48817 - seq_path(m, &file->f_path, "");
48818 + seq_path(m, &file->f_path, "\n\\");
48819 } else if (mm) {
48820 if (vma->vm_start <= mm->start_stack &&
48821 vma->vm_end >= mm->start_stack) {
48822 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48823 index d67908b..d13f6a6 100644
48824 --- a/fs/quota/netlink.c
48825 +++ b/fs/quota/netlink.c
48826 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48827 void quota_send_warning(short type, unsigned int id, dev_t dev,
48828 const char warntype)
48829 {
48830 - static atomic_t seq;
48831 + static atomic_unchecked_t seq;
48832 struct sk_buff *skb;
48833 void *msg_head;
48834 int ret;
48835 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48836 "VFS: Not enough memory to send quota warning.\n");
48837 return;
48838 }
48839 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48840 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48841 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48842 if (!msg_head) {
48843 printk(KERN_ERR
48844 diff --git a/fs/readdir.c b/fs/readdir.c
48845 index 356f715..c918d38 100644
48846 --- a/fs/readdir.c
48847 +++ b/fs/readdir.c
48848 @@ -17,6 +17,7 @@
48849 #include <linux/security.h>
48850 #include <linux/syscalls.h>
48851 #include <linux/unistd.h>
48852 +#include <linux/namei.h>
48853
48854 #include <asm/uaccess.h>
48855
48856 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48857
48858 struct readdir_callback {
48859 struct old_linux_dirent __user * dirent;
48860 + struct file * file;
48861 int result;
48862 };
48863
48864 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48865 buf->result = -EOVERFLOW;
48866 return -EOVERFLOW;
48867 }
48868 +
48869 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48870 + return 0;
48871 +
48872 buf->result++;
48873 dirent = buf->dirent;
48874 if (!access_ok(VERIFY_WRITE, dirent,
48875 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48876
48877 buf.result = 0;
48878 buf.dirent = dirent;
48879 + buf.file = file;
48880
48881 error = vfs_readdir(file, fillonedir, &buf);
48882 if (buf.result)
48883 @@ -142,6 +149,7 @@ struct linux_dirent {
48884 struct getdents_callback {
48885 struct linux_dirent __user * current_dir;
48886 struct linux_dirent __user * previous;
48887 + struct file * file;
48888 int count;
48889 int error;
48890 };
48891 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48892 buf->error = -EOVERFLOW;
48893 return -EOVERFLOW;
48894 }
48895 +
48896 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48897 + return 0;
48898 +
48899 dirent = buf->previous;
48900 if (dirent) {
48901 if (__put_user(offset, &dirent->d_off))
48902 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48903 buf.previous = NULL;
48904 buf.count = count;
48905 buf.error = 0;
48906 + buf.file = file;
48907
48908 error = vfs_readdir(file, filldir, &buf);
48909 if (error >= 0)
48910 @@ -229,6 +242,7 @@ out:
48911 struct getdents_callback64 {
48912 struct linux_dirent64 __user * current_dir;
48913 struct linux_dirent64 __user * previous;
48914 + struct file *file;
48915 int count;
48916 int error;
48917 };
48918 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48919 buf->error = -EINVAL; /* only used if we fail.. */
48920 if (reclen > buf->count)
48921 return -EINVAL;
48922 +
48923 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48924 + return 0;
48925 +
48926 dirent = buf->previous;
48927 if (dirent) {
48928 if (__put_user(offset, &dirent->d_off))
48929 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48930
48931 buf.current_dir = dirent;
48932 buf.previous = NULL;
48933 + buf.file = file;
48934 buf.count = count;
48935 buf.error = 0;
48936
48937 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48938 error = buf.error;
48939 lastdirent = buf.previous;
48940 if (lastdirent) {
48941 - typeof(lastdirent->d_off) d_off = file->f_pos;
48942 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48943 if (__put_user(d_off, &lastdirent->d_off))
48944 error = -EFAULT;
48945 else
48946 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48947 index 60c0804..d814f98 100644
48948 --- a/fs/reiserfs/do_balan.c
48949 +++ b/fs/reiserfs/do_balan.c
48950 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48951 return;
48952 }
48953
48954 - atomic_inc(&(fs_generation(tb->tb_sb)));
48955 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48956 do_balance_starts(tb);
48957
48958 /* balance leaf returns 0 except if combining L R and S into
48959 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48960 index 7a99811..a7c96c4 100644
48961 --- a/fs/reiserfs/procfs.c
48962 +++ b/fs/reiserfs/procfs.c
48963 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48964 "SMALL_TAILS " : "NO_TAILS ",
48965 replay_only(sb) ? "REPLAY_ONLY " : "",
48966 convert_reiserfs(sb) ? "CONV " : "",
48967 - atomic_read(&r->s_generation_counter),
48968 + atomic_read_unchecked(&r->s_generation_counter),
48969 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48970 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48971 SF(s_good_search_by_key_reada), SF(s_bmaps),
48972 diff --git a/fs/select.c b/fs/select.c
48973 index e782258..3b4b44c 100644
48974 --- a/fs/select.c
48975 +++ b/fs/select.c
48976 @@ -20,6 +20,7 @@
48977 #include <linux/module.h>
48978 #include <linux/slab.h>
48979 #include <linux/poll.h>
48980 +#include <linux/security.h>
48981 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48982 #include <linux/file.h>
48983 #include <linux/fdtable.h>
48984 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48985 struct poll_list *walk = head;
48986 unsigned long todo = nfds;
48987
48988 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48989 if (nfds > rlimit(RLIMIT_NOFILE))
48990 return -EINVAL;
48991
48992 diff --git a/fs/seq_file.c b/fs/seq_file.c
48993 index 4023d6b..ab46c6a 100644
48994 --- a/fs/seq_file.c
48995 +++ b/fs/seq_file.c
48996 @@ -9,6 +9,7 @@
48997 #include <linux/module.h>
48998 #include <linux/seq_file.h>
48999 #include <linux/slab.h>
49000 +#include <linux/sched.h>
49001
49002 #include <asm/uaccess.h>
49003 #include <asm/page.h>
49004 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49005 memset(p, 0, sizeof(*p));
49006 mutex_init(&p->lock);
49007 p->op = op;
49008 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49009 + p->exec_id = current->exec_id;
49010 +#endif
49011
49012 /*
49013 * Wrappers around seq_open(e.g. swaps_open) need to be
49014 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49015 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49016 void *data)
49017 {
49018 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49019 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49020 int res = -ENOMEM;
49021
49022 if (op) {
49023 diff --git a/fs/splice.c b/fs/splice.c
49024 index 1ec0493..d6ab5c2 100644
49025 --- a/fs/splice.c
49026 +++ b/fs/splice.c
49027 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49028 pipe_lock(pipe);
49029
49030 for (;;) {
49031 - if (!pipe->readers) {
49032 + if (!atomic_read(&pipe->readers)) {
49033 send_sig(SIGPIPE, current, 0);
49034 if (!ret)
49035 ret = -EPIPE;
49036 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49037 do_wakeup = 0;
49038 }
49039
49040 - pipe->waiting_writers++;
49041 + atomic_inc(&pipe->waiting_writers);
49042 pipe_wait(pipe);
49043 - pipe->waiting_writers--;
49044 + atomic_dec(&pipe->waiting_writers);
49045 }
49046
49047 pipe_unlock(pipe);
49048 @@ -559,7 +559,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49049 old_fs = get_fs();
49050 set_fs(get_ds());
49051 /* The cast to a user pointer is valid due to the set_fs() */
49052 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49053 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49054 set_fs(old_fs);
49055
49056 return res;
49057 @@ -574,7 +574,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49058 old_fs = get_fs();
49059 set_fs(get_ds());
49060 /* The cast to a user pointer is valid due to the set_fs() */
49061 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49062 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49063 set_fs(old_fs);
49064
49065 return res;
49066 @@ -625,7 +625,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49067 goto err;
49068
49069 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49070 - vec[i].iov_base = (void __user *) page_address(page);
49071 + vec[i].iov_base = (void __force_user *) page_address(page);
49072 vec[i].iov_len = this_len;
49073 spd.pages[i] = page;
49074 spd.nr_pages++;
49075 @@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49076 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49077 {
49078 while (!pipe->nrbufs) {
49079 - if (!pipe->writers)
49080 + if (!atomic_read(&pipe->writers))
49081 return 0;
49082
49083 - if (!pipe->waiting_writers && sd->num_spliced)
49084 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49085 return 0;
49086
49087 if (sd->flags & SPLICE_F_NONBLOCK)
49088 @@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49089 * out of the pipe right after the splice_to_pipe(). So set
49090 * PIPE_READERS appropriately.
49091 */
49092 - pipe->readers = 1;
49093 + atomic_set(&pipe->readers, 1);
49094
49095 current->splice_pipe = pipe;
49096 }
49097 @@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49098 ret = -ERESTARTSYS;
49099 break;
49100 }
49101 - if (!pipe->writers)
49102 + if (!atomic_read(&pipe->writers))
49103 break;
49104 - if (!pipe->waiting_writers) {
49105 + if (!atomic_read(&pipe->waiting_writers)) {
49106 if (flags & SPLICE_F_NONBLOCK) {
49107 ret = -EAGAIN;
49108 break;
49109 @@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49110 pipe_lock(pipe);
49111
49112 while (pipe->nrbufs >= pipe->buffers) {
49113 - if (!pipe->readers) {
49114 + if (!atomic_read(&pipe->readers)) {
49115 send_sig(SIGPIPE, current, 0);
49116 ret = -EPIPE;
49117 break;
49118 @@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49119 ret = -ERESTARTSYS;
49120 break;
49121 }
49122 - pipe->waiting_writers++;
49123 + atomic_inc(&pipe->waiting_writers);
49124 pipe_wait(pipe);
49125 - pipe->waiting_writers--;
49126 + atomic_dec(&pipe->waiting_writers);
49127 }
49128
49129 pipe_unlock(pipe);
49130 @@ -1818,14 +1818,14 @@ retry:
49131 pipe_double_lock(ipipe, opipe);
49132
49133 do {
49134 - if (!opipe->readers) {
49135 + if (!atomic_read(&opipe->readers)) {
49136 send_sig(SIGPIPE, current, 0);
49137 if (!ret)
49138 ret = -EPIPE;
49139 break;
49140 }
49141
49142 - if (!ipipe->nrbufs && !ipipe->writers)
49143 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49144 break;
49145
49146 /*
49147 @@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49148 pipe_double_lock(ipipe, opipe);
49149
49150 do {
49151 - if (!opipe->readers) {
49152 + if (!atomic_read(&opipe->readers)) {
49153 send_sig(SIGPIPE, current, 0);
49154 if (!ret)
49155 ret = -EPIPE;
49156 @@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49157 * return EAGAIN if we have the potential of some data in the
49158 * future, otherwise just return 0
49159 */
49160 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49161 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49162 ret = -EAGAIN;
49163
49164 pipe_unlock(ipipe);
49165 diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
49166 index a475983..9c6a1f0 100644
49167 --- a/fs/sysfs/bin.c
49168 +++ b/fs/sysfs/bin.c
49169 @@ -67,6 +67,8 @@ fill_read(struct file *file, char *buffer, loff_t off, size_t count)
49170 }
49171
49172 static ssize_t
49173 +read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) __size_overflow(3);
49174 +static ssize_t
49175 read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
49176 {
49177 struct bin_buffer *bb = file->private_data;
49178 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49179 index 7fdf6a7..e6cd8ad 100644
49180 --- a/fs/sysfs/dir.c
49181 +++ b/fs/sysfs/dir.c
49182 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49183 struct sysfs_dirent *sd;
49184 int rc;
49185
49186 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49187 + const char *parent_name = parent_sd->s_name;
49188 +
49189 + mode = S_IFDIR | S_IRWXU;
49190 +
49191 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49192 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49193 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49194 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49195 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49196 +#endif
49197 +
49198 /* allocate */
49199 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49200 if (!sd)
49201 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49202 index 00012e3..8392349 100644
49203 --- a/fs/sysfs/file.c
49204 +++ b/fs/sysfs/file.c
49205 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49206
49207 struct sysfs_open_dirent {
49208 atomic_t refcnt;
49209 - atomic_t event;
49210 + atomic_unchecked_t event;
49211 wait_queue_head_t poll;
49212 struct list_head buffers; /* goes through sysfs_buffer.list */
49213 };
49214 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49215 if (!sysfs_get_active(attr_sd))
49216 return -ENODEV;
49217
49218 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49219 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49220 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49221
49222 sysfs_put_active(attr_sd);
49223 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49224 return -ENOMEM;
49225
49226 atomic_set(&new_od->refcnt, 0);
49227 - atomic_set(&new_od->event, 1);
49228 + atomic_set_unchecked(&new_od->event, 1);
49229 init_waitqueue_head(&new_od->poll);
49230 INIT_LIST_HEAD(&new_od->buffers);
49231 goto retry;
49232 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49233
49234 sysfs_put_active(attr_sd);
49235
49236 - if (buffer->event != atomic_read(&od->event))
49237 + if (buffer->event != atomic_read_unchecked(&od->event))
49238 goto trigger;
49239
49240 return DEFAULT_POLLMASK;
49241 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49242
49243 od = sd->s_attr.open;
49244 if (od) {
49245 - atomic_inc(&od->event);
49246 + atomic_inc_unchecked(&od->event);
49247 wake_up_interruptible(&od->poll);
49248 }
49249
49250 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49251 index a7ac78f..02158e1 100644
49252 --- a/fs/sysfs/symlink.c
49253 +++ b/fs/sysfs/symlink.c
49254 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49255
49256 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49257 {
49258 - char *page = nd_get_link(nd);
49259 + const char *page = nd_get_link(nd);
49260 if (!IS_ERR(page))
49261 free_page((unsigned long)page);
49262 }
49263 diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
49264 index f922cba..062fb02 100644
49265 --- a/fs/ubifs/debug.c
49266 +++ b/fs/ubifs/debug.c
49267 @@ -2819,6 +2819,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
49268 * debugfs file. Returns %0 or %1 in case of success and a negative error code
49269 * in case of failure.
49270 */
49271 +static int interpret_user_input(const char __user *u, size_t count) __size_overflow(2);
49272 static int interpret_user_input(const char __user *u, size_t count)
49273 {
49274 size_t buf_size;
49275 @@ -2837,6 +2838,8 @@ static int interpret_user_input(const char __user *u, size_t count)
49276 }
49277
49278 static ssize_t dfs_file_write(struct file *file, const char __user *u,
49279 + size_t count, loff_t *ppos) __size_overflow(3);
49280 +static ssize_t dfs_file_write(struct file *file, const char __user *u,
49281 size_t count, loff_t *ppos)
49282 {
49283 struct ubifs_info *c = file->private_data;
49284 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49285 index c175b4d..8f36a16 100644
49286 --- a/fs/udf/misc.c
49287 +++ b/fs/udf/misc.c
49288 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49289
49290 u8 udf_tag_checksum(const struct tag *t)
49291 {
49292 - u8 *data = (u8 *)t;
49293 + const u8 *data = (const u8 *)t;
49294 u8 checksum = 0;
49295 int i;
49296 for (i = 0; i < sizeof(struct tag); ++i)
49297 diff --git a/fs/utimes.c b/fs/utimes.c
49298 index ba653f3..06ea4b1 100644
49299 --- a/fs/utimes.c
49300 +++ b/fs/utimes.c
49301 @@ -1,6 +1,7 @@
49302 #include <linux/compiler.h>
49303 #include <linux/file.h>
49304 #include <linux/fs.h>
49305 +#include <linux/security.h>
49306 #include <linux/linkage.h>
49307 #include <linux/mount.h>
49308 #include <linux/namei.h>
49309 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49310 goto mnt_drop_write_and_out;
49311 }
49312 }
49313 +
49314 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49315 + error = -EACCES;
49316 + goto mnt_drop_write_and_out;
49317 + }
49318 +
49319 mutex_lock(&inode->i_mutex);
49320 error = notify_change(path->dentry, &newattrs);
49321 mutex_unlock(&inode->i_mutex);
49322 diff --git a/fs/xattr.c b/fs/xattr.c
49323 index 82f4337..236473c 100644
49324 --- a/fs/xattr.c
49325 +++ b/fs/xattr.c
49326 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49327 * Extended attribute SET operations
49328 */
49329 static long
49330 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49331 +setxattr(struct path *path, const char __user *name, const void __user *value,
49332 size_t size, int flags)
49333 {
49334 int error;
49335 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49336 return PTR_ERR(kvalue);
49337 }
49338
49339 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49340 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49341 + error = -EACCES;
49342 + goto out;
49343 + }
49344 +
49345 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49346 +out:
49347 kfree(kvalue);
49348 return error;
49349 }
49350 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49351 return error;
49352 error = mnt_want_write(path.mnt);
49353 if (!error) {
49354 - error = setxattr(path.dentry, name, value, size, flags);
49355 + error = setxattr(&path, name, value, size, flags);
49356 mnt_drop_write(path.mnt);
49357 }
49358 path_put(&path);
49359 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49360 return error;
49361 error = mnt_want_write(path.mnt);
49362 if (!error) {
49363 - error = setxattr(path.dentry, name, value, size, flags);
49364 + error = setxattr(&path, name, value, size, flags);
49365 mnt_drop_write(path.mnt);
49366 }
49367 path_put(&path);
49368 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49369 const void __user *,value, size_t, size, int, flags)
49370 {
49371 struct file *f;
49372 - struct dentry *dentry;
49373 int error = -EBADF;
49374
49375 f = fget(fd);
49376 if (!f)
49377 return error;
49378 - dentry = f->f_path.dentry;
49379 - audit_inode(NULL, dentry);
49380 + audit_inode(NULL, f->f_path.dentry);
49381 error = mnt_want_write_file(f);
49382 if (!error) {
49383 - error = setxattr(dentry, name, value, size, flags);
49384 + error = setxattr(&f->f_path, name, value, size, flags);
49385 mnt_drop_write_file(f);
49386 }
49387 fput(f);
49388 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49389 index 8d5a506..7f62712 100644
49390 --- a/fs/xattr_acl.c
49391 +++ b/fs/xattr_acl.c
49392 @@ -17,8 +17,8 @@
49393 struct posix_acl *
49394 posix_acl_from_xattr(const void *value, size_t size)
49395 {
49396 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49397 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49398 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49399 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49400 int count;
49401 struct posix_acl *acl;
49402 struct posix_acl_entry *acl_e;
49403 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49404 index 188ef2f..adcf864 100644
49405 --- a/fs/xfs/xfs_bmap.c
49406 +++ b/fs/xfs/xfs_bmap.c
49407 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49408 int nmap,
49409 int ret_nmap);
49410 #else
49411 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49412 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49413 #endif /* DEBUG */
49414
49415 STATIC int
49416 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49417 index 79d05e8..e3e5861 100644
49418 --- a/fs/xfs/xfs_dir2_sf.c
49419 +++ b/fs/xfs/xfs_dir2_sf.c
49420 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49421 }
49422
49423 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49424 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49425 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49426 + char name[sfep->namelen];
49427 + memcpy(name, sfep->name, sfep->namelen);
49428 + if (filldir(dirent, name, sfep->namelen,
49429 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49430 + *offset = off & 0x7fffffff;
49431 + return 0;
49432 + }
49433 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49434 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49435 *offset = off & 0x7fffffff;
49436 return 0;
49437 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49438 index 76f3ca5..f57f712 100644
49439 --- a/fs/xfs/xfs_ioctl.c
49440 +++ b/fs/xfs/xfs_ioctl.c
49441 @@ -128,7 +128,7 @@ xfs_find_handle(
49442 }
49443
49444 error = -EFAULT;
49445 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49446 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49447 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49448 goto out_put;
49449
49450 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49451 index ab30253..4d86958 100644
49452 --- a/fs/xfs/xfs_iops.c
49453 +++ b/fs/xfs/xfs_iops.c
49454 @@ -447,7 +447,7 @@ xfs_vn_put_link(
49455 struct nameidata *nd,
49456 void *p)
49457 {
49458 - char *s = nd_get_link(nd);
49459 + const char *s = nd_get_link(nd);
49460
49461 if (!IS_ERR(s))
49462 kfree(s);
49463 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49464 new file mode 100644
49465 index 0000000..4089e05
49466 --- /dev/null
49467 +++ b/grsecurity/Kconfig
49468 @@ -0,0 +1,1078 @@
49469 +#
49470 +# grecurity configuration
49471 +#
49472 +
49473 +menu "Grsecurity"
49474 +
49475 +config GRKERNSEC
49476 + bool "Grsecurity"
49477 + select CRYPTO
49478 + select CRYPTO_SHA256
49479 + help
49480 + If you say Y here, you will be able to configure many features
49481 + that will enhance the security of your system. It is highly
49482 + recommended that you say Y here and read through the help
49483 + for each option so that you fully understand the features and
49484 + can evaluate their usefulness for your machine.
49485 +
49486 +choice
49487 + prompt "Security Level"
49488 + depends on GRKERNSEC
49489 + default GRKERNSEC_CUSTOM
49490 +
49491 +config GRKERNSEC_LOW
49492 + bool "Low"
49493 + select GRKERNSEC_LINK
49494 + select GRKERNSEC_FIFO
49495 + select GRKERNSEC_RANDNET
49496 + select GRKERNSEC_DMESG
49497 + select GRKERNSEC_CHROOT
49498 + select GRKERNSEC_CHROOT_CHDIR
49499 +
49500 + help
49501 + If you choose this option, several of the grsecurity options will
49502 + be enabled that will give you greater protection against a number
49503 + of attacks, while assuring that none of your software will have any
49504 + conflicts with the additional security measures. If you run a lot
49505 + of unusual software, or you are having problems with the higher
49506 + security levels, you should say Y here. With this option, the
49507 + following features are enabled:
49508 +
49509 + - Linking restrictions
49510 + - FIFO restrictions
49511 + - Restricted dmesg
49512 + - Enforced chdir("/") on chroot
49513 + - Runtime module disabling
49514 +
49515 +config GRKERNSEC_MEDIUM
49516 + bool "Medium"
49517 + select PAX
49518 + select PAX_EI_PAX
49519 + select PAX_PT_PAX_FLAGS
49520 + select PAX_HAVE_ACL_FLAGS
49521 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49522 + select GRKERNSEC_CHROOT
49523 + select GRKERNSEC_CHROOT_SYSCTL
49524 + select GRKERNSEC_LINK
49525 + select GRKERNSEC_FIFO
49526 + select GRKERNSEC_DMESG
49527 + select GRKERNSEC_RANDNET
49528 + select GRKERNSEC_FORKFAIL
49529 + select GRKERNSEC_TIME
49530 + select GRKERNSEC_SIGNAL
49531 + select GRKERNSEC_CHROOT
49532 + select GRKERNSEC_CHROOT_UNIX
49533 + select GRKERNSEC_CHROOT_MOUNT
49534 + select GRKERNSEC_CHROOT_PIVOT
49535 + select GRKERNSEC_CHROOT_DOUBLE
49536 + select GRKERNSEC_CHROOT_CHDIR
49537 + select GRKERNSEC_CHROOT_MKNOD
49538 + select GRKERNSEC_PROC
49539 + select GRKERNSEC_PROC_USERGROUP
49540 + select PAX_RANDUSTACK
49541 + select PAX_ASLR
49542 + select PAX_RANDMMAP
49543 + select PAX_REFCOUNT if (X86 || SPARC64)
49544 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49545 +
49546 + help
49547 + If you say Y here, several features in addition to those included
49548 + in the low additional security level will be enabled. These
49549 + features provide even more security to your system, though in rare
49550 + cases they may be incompatible with very old or poorly written
49551 + software. If you enable this option, make sure that your auth
49552 + service (identd) is running as gid 1001. With this option,
49553 + the following features (in addition to those provided in the
49554 + low additional security level) will be enabled:
49555 +
49556 + - Failed fork logging
49557 + - Time change logging
49558 + - Signal logging
49559 + - Deny mounts in chroot
49560 + - Deny double chrooting
49561 + - Deny sysctl writes in chroot
49562 + - Deny mknod in chroot
49563 + - Deny access to abstract AF_UNIX sockets out of chroot
49564 + - Deny pivot_root in chroot
49565 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49566 + - /proc restrictions with special GID set to 10 (usually wheel)
49567 + - Address Space Layout Randomization (ASLR)
49568 + - Prevent exploitation of most refcount overflows
49569 + - Bounds checking of copying between the kernel and userland
49570 +
49571 +config GRKERNSEC_HIGH
49572 + bool "High"
49573 + select GRKERNSEC_LINK
49574 + select GRKERNSEC_FIFO
49575 + select GRKERNSEC_DMESG
49576 + select GRKERNSEC_FORKFAIL
49577 + select GRKERNSEC_TIME
49578 + select GRKERNSEC_SIGNAL
49579 + select GRKERNSEC_CHROOT
49580 + select GRKERNSEC_CHROOT_SHMAT
49581 + select GRKERNSEC_CHROOT_UNIX
49582 + select GRKERNSEC_CHROOT_MOUNT
49583 + select GRKERNSEC_CHROOT_FCHDIR
49584 + select GRKERNSEC_CHROOT_PIVOT
49585 + select GRKERNSEC_CHROOT_DOUBLE
49586 + select GRKERNSEC_CHROOT_CHDIR
49587 + select GRKERNSEC_CHROOT_MKNOD
49588 + select GRKERNSEC_CHROOT_CAPS
49589 + select GRKERNSEC_CHROOT_SYSCTL
49590 + select GRKERNSEC_CHROOT_FINDTASK
49591 + select GRKERNSEC_SYSFS_RESTRICT
49592 + select GRKERNSEC_PROC
49593 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49594 + select GRKERNSEC_HIDESYM
49595 + select GRKERNSEC_BRUTE
49596 + select GRKERNSEC_PROC_USERGROUP
49597 + select GRKERNSEC_KMEM
49598 + select GRKERNSEC_RESLOG
49599 + select GRKERNSEC_RANDNET
49600 + select GRKERNSEC_PROC_ADD
49601 + select GRKERNSEC_CHROOT_CHMOD
49602 + select GRKERNSEC_CHROOT_NICE
49603 + select GRKERNSEC_SETXID
49604 + select GRKERNSEC_AUDIT_MOUNT
49605 + select GRKERNSEC_MODHARDEN if (MODULES)
49606 + select GRKERNSEC_HARDEN_PTRACE
49607 + select GRKERNSEC_PTRACE_READEXEC
49608 + select GRKERNSEC_VM86 if (X86_32)
49609 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49610 + select PAX
49611 + select PAX_RANDUSTACK
49612 + select PAX_ASLR
49613 + select PAX_RANDMMAP
49614 + select PAX_NOEXEC
49615 + select PAX_MPROTECT
49616 + select PAX_EI_PAX
49617 + select PAX_PT_PAX_FLAGS
49618 + select PAX_HAVE_ACL_FLAGS
49619 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49620 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
49621 + select PAX_RANDKSTACK if (X86_TSC && X86)
49622 + select PAX_SEGMEXEC if (X86_32)
49623 + select PAX_PAGEEXEC
49624 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49625 + select PAX_EMUTRAMP if (PARISC)
49626 + select PAX_EMUSIGRT if (PARISC)
49627 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49628 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49629 + select PAX_REFCOUNT if (X86 || SPARC64)
49630 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49631 + help
49632 + If you say Y here, many of the features of grsecurity will be
49633 + enabled, which will protect you against many kinds of attacks
49634 + against your system. The heightened security comes at a cost
49635 + of an increased chance of incompatibilities with rare software
49636 + on your machine. Since this security level enables PaX, you should
49637 + view <http://pax.grsecurity.net> and read about the PaX
49638 + project. While you are there, download chpax and run it on
49639 + binaries that cause problems with PaX. Also remember that
49640 + since the /proc restrictions are enabled, you must run your
49641 + identd as gid 1001. This security level enables the following
49642 + features in addition to those listed in the low and medium
49643 + security levels:
49644 +
49645 + - Additional /proc restrictions
49646 + - Chmod restrictions in chroot
49647 + - No signals, ptrace, or viewing of processes outside of chroot
49648 + - Capability restrictions in chroot
49649 + - Deny fchdir out of chroot
49650 + - Priority restrictions in chroot
49651 + - Segmentation-based implementation of PaX
49652 + - Mprotect restrictions
49653 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49654 + - Kernel stack randomization
49655 + - Mount/unmount/remount logging
49656 + - Kernel symbol hiding
49657 + - Hardening of module auto-loading
49658 + - Ptrace restrictions
49659 + - Restricted vm86 mode
49660 + - Restricted sysfs/debugfs
49661 + - Active kernel exploit response
49662 +
49663 +config GRKERNSEC_CUSTOM
49664 + bool "Custom"
49665 + help
49666 + If you say Y here, you will be able to configure every grsecurity
49667 + option, which allows you to enable many more features that aren't
49668 + covered in the basic security levels. These additional features
49669 + include TPE, socket restrictions, and the sysctl system for
49670 + grsecurity. It is advised that you read through the help for
49671 + each option to determine its usefulness in your situation.
49672 +
49673 +endchoice
49674 +
49675 +menu "Memory Protections"
49676 +depends on GRKERNSEC
49677 +
49678 +config GRKERNSEC_KMEM
49679 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49680 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49681 + help
49682 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49683 + be written to or read from to modify or leak the contents of the running
49684 + kernel. /dev/port will also not be allowed to be opened. If you have module
49685 + support disabled, enabling this will close up four ways that are
49686 + currently used to insert malicious code into the running kernel.
49687 + Even with all these features enabled, we still highly recommend that
49688 + you use the RBAC system, as it is still possible for an attacker to
49689 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49690 + If you are not using XFree86, you may be able to stop this additional
49691 + case by enabling the 'Disable privileged I/O' option. Though nothing
49692 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49693 + but only to video memory, which is the only writing we allow in this
49694 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49695 + not be allowed to mprotect it with PROT_WRITE later.
49696 + It is highly recommended that you say Y here if you meet all the
49697 + conditions above.
49698 +
49699 +config GRKERNSEC_VM86
49700 + bool "Restrict VM86 mode"
49701 + depends on X86_32
49702 +
49703 + help
49704 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49705 + make use of a special execution mode on 32bit x86 processors called
49706 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49707 + video cards and will still work with this option enabled. The purpose
49708 + of the option is to prevent exploitation of emulation errors in
49709 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49710 + Nearly all users should be able to enable this option.
49711 +
49712 +config GRKERNSEC_IO
49713 + bool "Disable privileged I/O"
49714 + depends on X86
49715 + select RTC_CLASS
49716 + select RTC_INTF_DEV
49717 + select RTC_DRV_CMOS
49718 +
49719 + help
49720 + If you say Y here, all ioperm and iopl calls will return an error.
49721 + Ioperm and iopl can be used to modify the running kernel.
49722 + Unfortunately, some programs need this access to operate properly,
49723 + the most notable of which are XFree86 and hwclock. hwclock can be
49724 + remedied by having RTC support in the kernel, so real-time
49725 + clock support is enabled if this option is enabled, to ensure
49726 + that hwclock operates correctly. XFree86 still will not
49727 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49728 + IF YOU USE XFree86. If you use XFree86 and you still want to
49729 + protect your kernel against modification, use the RBAC system.
49730 +
49731 +config GRKERNSEC_PROC_MEMMAP
49732 + bool "Harden ASLR against information leaks and entropy reduction"
49733 + default y if (PAX_NOEXEC || PAX_ASLR)
49734 + depends on PAX_NOEXEC || PAX_ASLR
49735 + help
49736 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49737 + give no information about the addresses of its mappings if
49738 + PaX features that rely on random addresses are enabled on the task.
49739 + In addition to sanitizing this information and disabling other
49740 + dangerous sources of information, this option causes reads of sensitive
49741 + /proc/<pid> entries where the file descriptor was opened in a different
49742 + task than the one performing the read. Such attempts are logged.
49743 + This option also limits argv/env strings for suid/sgid binaries
49744 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49745 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49746 + binaries to prevent alternative mmap layouts from being abused.
49747 +
49748 + If you use PaX it is essential that you say Y here as it closes up
49749 + several holes that make full ASLR useless locally.
49750 +
49751 +config GRKERNSEC_BRUTE
49752 + bool "Deter exploit bruteforcing"
49753 + help
49754 + If you say Y here, attempts to bruteforce exploits against forking
49755 + daemons such as apache or sshd, as well as against suid/sgid binaries
49756 + will be deterred. When a child of a forking daemon is killed by PaX
49757 + or crashes due to an illegal instruction or other suspicious signal,
49758 + the parent process will be delayed 30 seconds upon every subsequent
49759 + fork until the administrator is able to assess the situation and
49760 + restart the daemon.
49761 + In the suid/sgid case, the attempt is logged, the user has all their
49762 + processes terminated, and they are prevented from executing any further
49763 + processes for 15 minutes.
49764 + It is recommended that you also enable signal logging in the auditing
49765 + section so that logs are generated when a process triggers a suspicious
49766 + signal.
49767 + If the sysctl option is enabled, a sysctl option with name
49768 + "deter_bruteforce" is created.
49769 +
49770 +
49771 +config GRKERNSEC_MODHARDEN
49772 + bool "Harden module auto-loading"
49773 + depends on MODULES
49774 + help
49775 + If you say Y here, module auto-loading in response to use of some
49776 + feature implemented by an unloaded module will be restricted to
49777 + root users. Enabling this option helps defend against attacks
49778 + by unprivileged users who abuse the auto-loading behavior to
49779 + cause a vulnerable module to load that is then exploited.
49780 +
49781 + If this option prevents a legitimate use of auto-loading for a
49782 + non-root user, the administrator can execute modprobe manually
49783 + with the exact name of the module mentioned in the alert log.
49784 + Alternatively, the administrator can add the module to the list
49785 + of modules loaded at boot by modifying init scripts.
49786 +
49787 + Modification of init scripts will most likely be needed on
49788 + Ubuntu servers with encrypted home directory support enabled,
49789 + as the first non-root user logging in will cause the ecb(aes),
49790 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49791 +
49792 +config GRKERNSEC_HIDESYM
49793 + bool "Hide kernel symbols"
49794 + help
49795 + If you say Y here, getting information on loaded modules, and
49796 + displaying all kernel symbols through a syscall will be restricted
49797 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49798 + /proc/kallsyms will be restricted to the root user. The RBAC
49799 + system can hide that entry even from root.
49800 +
49801 + This option also prevents leaking of kernel addresses through
49802 + several /proc entries.
49803 +
49804 + Note that this option is only effective provided the following
49805 + conditions are met:
49806 + 1) The kernel using grsecurity is not precompiled by some distribution
49807 + 2) You have also enabled GRKERNSEC_DMESG
49808 + 3) You are using the RBAC system and hiding other files such as your
49809 + kernel image and System.map. Alternatively, enabling this option
49810 + causes the permissions on /boot, /lib/modules, and the kernel
49811 + source directory to change at compile time to prevent
49812 + reading by non-root users.
49813 + If the above conditions are met, this option will aid in providing a
49814 + useful protection against local kernel exploitation of overflows
49815 + and arbitrary read/write vulnerabilities.
49816 +
49817 +config GRKERNSEC_KERN_LOCKOUT
49818 + bool "Active kernel exploit response"
49819 + depends on X86 || ARM || PPC || SPARC
49820 + help
49821 + If you say Y here, when a PaX alert is triggered due to suspicious
49822 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49823 + or an OOPs occurs due to bad memory accesses, instead of just
49824 + terminating the offending process (and potentially allowing
49825 + a subsequent exploit from the same user), we will take one of two
49826 + actions:
49827 + If the user was root, we will panic the system
49828 + If the user was non-root, we will log the attempt, terminate
49829 + all processes owned by the user, then prevent them from creating
49830 + any new processes until the system is restarted
49831 + This deters repeated kernel exploitation/bruteforcing attempts
49832 + and is useful for later forensics.
49833 +
49834 +endmenu
49835 +menu "Role Based Access Control Options"
49836 +depends on GRKERNSEC
49837 +
49838 +config GRKERNSEC_RBAC_DEBUG
49839 + bool
49840 +
49841 +config GRKERNSEC_NO_RBAC
49842 + bool "Disable RBAC system"
49843 + help
49844 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49845 + preventing the RBAC system from being enabled. You should only say Y
49846 + here if you have no intention of using the RBAC system, so as to prevent
49847 + an attacker with root access from misusing the RBAC system to hide files
49848 + and processes when loadable module support and /dev/[k]mem have been
49849 + locked down.
49850 +
49851 +config GRKERNSEC_ACL_HIDEKERN
49852 + bool "Hide kernel processes"
49853 + help
49854 + If you say Y here, all kernel threads will be hidden to all
49855 + processes but those whose subject has the "view hidden processes"
49856 + flag.
49857 +
49858 +config GRKERNSEC_ACL_MAXTRIES
49859 + int "Maximum tries before password lockout"
49860 + default 3
49861 + help
49862 + This option enforces the maximum number of times a user can attempt
49863 + to authorize themselves with the grsecurity RBAC system before being
49864 + denied the ability to attempt authorization again for a specified time.
49865 + The lower the number, the harder it will be to brute-force a password.
49866 +
49867 +config GRKERNSEC_ACL_TIMEOUT
49868 + int "Time to wait after max password tries, in seconds"
49869 + default 30
49870 + help
49871 + This option specifies the time the user must wait after attempting to
49872 + authorize to the RBAC system with the maximum number of invalid
49873 + passwords. The higher the number, the harder it will be to brute-force
49874 + a password.
49875 +
49876 +endmenu
49877 +menu "Filesystem Protections"
49878 +depends on GRKERNSEC
49879 +
49880 +config GRKERNSEC_PROC
49881 + bool "Proc restrictions"
49882 + help
49883 + If you say Y here, the permissions of the /proc filesystem
49884 + will be altered to enhance system security and privacy. You MUST
49885 + choose either a user only restriction or a user and group restriction.
49886 + Depending upon the option you choose, you can either restrict users to
49887 + see only the processes they themselves run, or choose a group that can
49888 + view all processes and files normally restricted to root if you choose
49889 + the "restrict to user only" option. NOTE: If you're running identd or
49890 + ntpd as a non-root user, you will have to run it as the group you
49891 + specify here.
49892 +
49893 +config GRKERNSEC_PROC_USER
49894 + bool "Restrict /proc to user only"
49895 + depends on GRKERNSEC_PROC
49896 + help
49897 + If you say Y here, non-root users will only be able to view their own
49898 + processes, and restricts them from viewing network-related information,
49899 + and viewing kernel symbol and module information.
49900 +
49901 +config GRKERNSEC_PROC_USERGROUP
49902 + bool "Allow special group"
49903 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49904 + help
49905 + If you say Y here, you will be able to select a group that will be
49906 + able to view all processes and network-related information. If you've
49907 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49908 + remain hidden. This option is useful if you want to run identd as
49909 + a non-root user.
49910 +
49911 +config GRKERNSEC_PROC_GID
49912 + int "GID for special group"
49913 + depends on GRKERNSEC_PROC_USERGROUP
49914 + default 1001
49915 +
49916 +config GRKERNSEC_PROC_ADD
49917 + bool "Additional restrictions"
49918 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49919 + help
49920 + If you say Y here, additional restrictions will be placed on
49921 + /proc that keep normal users from viewing device information and
49922 + slabinfo information that could be useful for exploits.
49923 +
49924 +config GRKERNSEC_LINK
49925 + bool "Linking restrictions"
49926 + help
49927 + If you say Y here, /tmp race exploits will be prevented, since users
49928 + will no longer be able to follow symlinks owned by other users in
49929 + world-writable +t directories (e.g. /tmp), unless the owner of the
49930 + symlink is the owner of the directory. users will also not be
49931 + able to hardlink to files they do not own. If the sysctl option is
49932 + enabled, a sysctl option with name "linking_restrictions" is created.
49933 +
49934 +config GRKERNSEC_FIFO
49935 + bool "FIFO restrictions"
49936 + help
49937 + If you say Y here, users will not be able to write to FIFOs they don't
49938 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49939 + the FIFO is the same owner of the directory it's held in. If the sysctl
49940 + option is enabled, a sysctl option with name "fifo_restrictions" is
49941 + created.
49942 +
49943 +config GRKERNSEC_SYSFS_RESTRICT
49944 + bool "Sysfs/debugfs restriction"
49945 + depends on SYSFS
49946 + help
49947 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49948 + any filesystem normally mounted under it (e.g. debugfs) will be
49949 + mostly accessible only by root. These filesystems generally provide access
49950 + to hardware and debug information that isn't appropriate for unprivileged
49951 + users of the system. Sysfs and debugfs have also become a large source
49952 + of new vulnerabilities, ranging from infoleaks to local compromise.
49953 + There has been very little oversight with an eye toward security involved
49954 + in adding new exporters of information to these filesystems, so their
49955 + use is discouraged.
49956 + For reasons of compatibility, a few directories have been whitelisted
49957 + for access by non-root users:
49958 + /sys/fs/selinux
49959 + /sys/fs/fuse
49960 + /sys/devices/system/cpu
49961 +
49962 +config GRKERNSEC_ROFS
49963 + bool "Runtime read-only mount protection"
49964 + help
49965 + If you say Y here, a sysctl option with name "romount_protect" will
49966 + be created. By setting this option to 1 at runtime, filesystems
49967 + will be protected in the following ways:
49968 + * No new writable mounts will be allowed
49969 + * Existing read-only mounts won't be able to be remounted read/write
49970 + * Write operations will be denied on all block devices
49971 + This option acts independently of grsec_lock: once it is set to 1,
49972 + it cannot be turned off. Therefore, please be mindful of the resulting
49973 + behavior if this option is enabled in an init script on a read-only
49974 + filesystem. This feature is mainly intended for secure embedded systems.
49975 +
49976 +config GRKERNSEC_CHROOT
49977 + bool "Chroot jail restrictions"
49978 + help
49979 + If you say Y here, you will be able to choose several options that will
49980 + make breaking out of a chrooted jail much more difficult. If you
49981 + encounter no software incompatibilities with the following options, it
49982 + is recommended that you enable each one.
49983 +
49984 +config GRKERNSEC_CHROOT_MOUNT
49985 + bool "Deny mounts"
49986 + depends on GRKERNSEC_CHROOT
49987 + help
49988 + If you say Y here, processes inside a chroot will not be able to
49989 + mount or remount filesystems. If the sysctl option is enabled, a
49990 + sysctl option with name "chroot_deny_mount" is created.
49991 +
49992 +config GRKERNSEC_CHROOT_DOUBLE
49993 + bool "Deny double-chroots"
49994 + depends on GRKERNSEC_CHROOT
49995 + help
49996 + If you say Y here, processes inside a chroot will not be able to chroot
49997 + again outside the chroot. This is a widely used method of breaking
49998 + out of a chroot jail and should not be allowed. If the sysctl
49999 + option is enabled, a sysctl option with name
50000 + "chroot_deny_chroot" is created.
50001 +
50002 +config GRKERNSEC_CHROOT_PIVOT
50003 + bool "Deny pivot_root in chroot"
50004 + depends on GRKERNSEC_CHROOT
50005 + help
50006 + If you say Y here, processes inside a chroot will not be able to use
50007 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50008 + works similar to chroot in that it changes the root filesystem. This
50009 + function could be misused in a chrooted process to attempt to break out
50010 + of the chroot, and therefore should not be allowed. If the sysctl
50011 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50012 + created.
50013 +
50014 +config GRKERNSEC_CHROOT_CHDIR
50015 + bool "Enforce chdir(\"/\") on all chroots"
50016 + depends on GRKERNSEC_CHROOT
50017 + help
50018 + If you say Y here, the current working directory of all newly-chrooted
50019 + applications will be set to the the root directory of the chroot.
50020 + The man page on chroot(2) states:
50021 + Note that this call does not change the current working
50022 + directory, so that `.' can be outside the tree rooted at
50023 + `/'. In particular, the super-user can escape from a
50024 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50025 +
50026 + It is recommended that you say Y here, since it's not known to break
50027 + any software. If the sysctl option is enabled, a sysctl option with
50028 + name "chroot_enforce_chdir" is created.
50029 +
50030 +config GRKERNSEC_CHROOT_CHMOD
50031 + bool "Deny (f)chmod +s"
50032 + depends on GRKERNSEC_CHROOT
50033 + help
50034 + If you say Y here, processes inside a chroot will not be able to chmod
50035 + or fchmod files to make them have suid or sgid bits. This protects
50036 + against another published method of breaking a chroot. If the sysctl
50037 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50038 + created.
50039 +
50040 +config GRKERNSEC_CHROOT_FCHDIR
50041 + bool "Deny fchdir out of chroot"
50042 + depends on GRKERNSEC_CHROOT
50043 + help
50044 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50045 + to a file descriptor of the chrooting process that points to a directory
50046 + outside the filesystem will be stopped. If the sysctl option
50047 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50048 +
50049 +config GRKERNSEC_CHROOT_MKNOD
50050 + bool "Deny mknod"
50051 + depends on GRKERNSEC_CHROOT
50052 + help
50053 + If you say Y here, processes inside a chroot will not be allowed to
50054 + mknod. The problem with using mknod inside a chroot is that it
50055 + would allow an attacker to create a device entry that is the same
50056 + as one on the physical root of your system, which could range from
50057 + anything from the console device to a device for your harddrive (which
50058 + they could then use to wipe the drive or steal data). It is recommended
50059 + that you say Y here, unless you run into software incompatibilities.
50060 + If the sysctl option is enabled, a sysctl option with name
50061 + "chroot_deny_mknod" is created.
50062 +
50063 +config GRKERNSEC_CHROOT_SHMAT
50064 + bool "Deny shmat() out of chroot"
50065 + depends on GRKERNSEC_CHROOT
50066 + help
50067 + If you say Y here, processes inside a chroot will not be able to attach
50068 + to shared memory segments that were created outside of the chroot jail.
50069 + It is recommended that you say Y here. If the sysctl option is enabled,
50070 + a sysctl option with name "chroot_deny_shmat" is created.
50071 +
50072 +config GRKERNSEC_CHROOT_UNIX
50073 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50074 + depends on GRKERNSEC_CHROOT
50075 + help
50076 + If you say Y here, processes inside a chroot will not be able to
50077 + connect to abstract (meaning not belonging to a filesystem) Unix
50078 + domain sockets that were bound outside of a chroot. It is recommended
50079 + that you say Y here. If the sysctl option is enabled, a sysctl option
50080 + with name "chroot_deny_unix" is created.
50081 +
50082 +config GRKERNSEC_CHROOT_FINDTASK
50083 + bool "Protect outside processes"
50084 + depends on GRKERNSEC_CHROOT
50085 + help
50086 + If you say Y here, processes inside a chroot will not be able to
50087 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50088 + getsid, or view any process outside of the chroot. If the sysctl
50089 + option is enabled, a sysctl option with name "chroot_findtask" is
50090 + created.
50091 +
50092 +config GRKERNSEC_CHROOT_NICE
50093 + bool "Restrict priority changes"
50094 + depends on GRKERNSEC_CHROOT
50095 + help
50096 + If you say Y here, processes inside a chroot will not be able to raise
50097 + the priority of processes in the chroot, or alter the priority of
50098 + processes outside the chroot. This provides more security than simply
50099 + removing CAP_SYS_NICE from the process' capability set. If the
50100 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50101 + is created.
50102 +
50103 +config GRKERNSEC_CHROOT_SYSCTL
50104 + bool "Deny sysctl writes"
50105 + depends on GRKERNSEC_CHROOT
50106 + help
50107 + If you say Y here, an attacker in a chroot will not be able to
50108 + write to sysctl entries, either by sysctl(2) or through a /proc
50109 + interface. It is strongly recommended that you say Y here. If the
50110 + sysctl option is enabled, a sysctl option with name
50111 + "chroot_deny_sysctl" is created.
50112 +
50113 +config GRKERNSEC_CHROOT_CAPS
50114 + bool "Capability restrictions"
50115 + depends on GRKERNSEC_CHROOT
50116 + help
50117 + If you say Y here, the capabilities on all processes within a
50118 + chroot jail will be lowered to stop module insertion, raw i/o,
50119 + system and net admin tasks, rebooting the system, modifying immutable
50120 + files, modifying IPC owned by another, and changing the system time.
50121 + This is left an option because it can break some apps. Disable this
50122 + if your chrooted apps are having problems performing those kinds of
50123 + tasks. If the sysctl option is enabled, a sysctl option with
50124 + name "chroot_caps" is created.
50125 +
50126 +endmenu
50127 +menu "Kernel Auditing"
50128 +depends on GRKERNSEC
50129 +
50130 +config GRKERNSEC_AUDIT_GROUP
50131 + bool "Single group for auditing"
50132 + help
50133 + If you say Y here, the exec, chdir, and (un)mount logging features
50134 + will only operate on a group you specify. This option is recommended
50135 + if you only want to watch certain users instead of having a large
50136 + amount of logs from the entire system. If the sysctl option is enabled,
50137 + a sysctl option with name "audit_group" is created.
50138 +
50139 +config GRKERNSEC_AUDIT_GID
50140 + int "GID for auditing"
50141 + depends on GRKERNSEC_AUDIT_GROUP
50142 + default 1007
50143 +
50144 +config GRKERNSEC_EXECLOG
50145 + bool "Exec logging"
50146 + help
50147 + If you say Y here, all execve() calls will be logged (since the
50148 + other exec*() calls are frontends to execve(), all execution
50149 + will be logged). Useful for shell-servers that like to keep track
50150 + of their users. If the sysctl option is enabled, a sysctl option with
50151 + name "exec_logging" is created.
50152 + WARNING: This option when enabled will produce a LOT of logs, especially
50153 + on an active system.
50154 +
50155 +config GRKERNSEC_RESLOG
50156 + bool "Resource logging"
50157 + help
50158 + If you say Y here, all attempts to overstep resource limits will
50159 + be logged with the resource name, the requested size, and the current
50160 + limit. It is highly recommended that you say Y here. If the sysctl
50161 + option is enabled, a sysctl option with name "resource_logging" is
50162 + created. If the RBAC system is enabled, the sysctl value is ignored.
50163 +
50164 +config GRKERNSEC_CHROOT_EXECLOG
50165 + bool "Log execs within chroot"
50166 + help
50167 + If you say Y here, all executions inside a chroot jail will be logged
50168 + to syslog. This can cause a large amount of logs if certain
50169 + applications (eg. djb's daemontools) are installed on the system, and
50170 + is therefore left as an option. If the sysctl option is enabled, a
50171 + sysctl option with name "chroot_execlog" is created.
50172 +
50173 +config GRKERNSEC_AUDIT_PTRACE
50174 + bool "Ptrace logging"
50175 + help
50176 + If you say Y here, all attempts to attach to a process via ptrace
50177 + will be logged. If the sysctl option is enabled, a sysctl option
50178 + with name "audit_ptrace" is created.
50179 +
50180 +config GRKERNSEC_AUDIT_CHDIR
50181 + bool "Chdir logging"
50182 + help
50183 + If you say Y here, all chdir() calls will be logged. If the sysctl
50184 + option is enabled, a sysctl option with name "audit_chdir" is created.
50185 +
50186 +config GRKERNSEC_AUDIT_MOUNT
50187 + bool "(Un)Mount logging"
50188 + help
50189 + If you say Y here, all mounts and unmounts will be logged. If the
50190 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50191 + created.
50192 +
50193 +config GRKERNSEC_SIGNAL
50194 + bool "Signal logging"
50195 + help
50196 + If you say Y here, certain important signals will be logged, such as
50197 + SIGSEGV, which will as a result inform you of when a error in a program
50198 + occurred, which in some cases could mean a possible exploit attempt.
50199 + If the sysctl option is enabled, a sysctl option with name
50200 + "signal_logging" is created.
50201 +
50202 +config GRKERNSEC_FORKFAIL
50203 + bool "Fork failure logging"
50204 + help
50205 + If you say Y here, all failed fork() attempts will be logged.
50206 + This could suggest a fork bomb, or someone attempting to overstep
50207 + their process limit. If the sysctl option is enabled, a sysctl option
50208 + with name "forkfail_logging" is created.
50209 +
50210 +config GRKERNSEC_TIME
50211 + bool "Time change logging"
50212 + help
50213 + If you say Y here, any changes of the system clock will be logged.
50214 + If the sysctl option is enabled, a sysctl option with name
50215 + "timechange_logging" is created.
50216 +
50217 +config GRKERNSEC_PROC_IPADDR
50218 + bool "/proc/<pid>/ipaddr support"
50219 + help
50220 + If you say Y here, a new entry will be added to each /proc/<pid>
50221 + directory that contains the IP address of the person using the task.
50222 + The IP is carried across local TCP and AF_UNIX stream sockets.
50223 + This information can be useful for IDS/IPSes to perform remote response
50224 + to a local attack. The entry is readable by only the owner of the
50225 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50226 + the RBAC system), and thus does not create privacy concerns.
50227 +
50228 +config GRKERNSEC_RWXMAP_LOG
50229 + bool 'Denied RWX mmap/mprotect logging'
50230 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50231 + help
50232 + If you say Y here, calls to mmap() and mprotect() with explicit
50233 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50234 + denied by the PAX_MPROTECT feature. If the sysctl option is
50235 + enabled, a sysctl option with name "rwxmap_logging" is created.
50236 +
50237 +config GRKERNSEC_AUDIT_TEXTREL
50238 + bool 'ELF text relocations logging (READ HELP)'
50239 + depends on PAX_MPROTECT
50240 + help
50241 + If you say Y here, text relocations will be logged with the filename
50242 + of the offending library or binary. The purpose of the feature is
50243 + to help Linux distribution developers get rid of libraries and
50244 + binaries that need text relocations which hinder the future progress
50245 + of PaX. Only Linux distribution developers should say Y here, and
50246 + never on a production machine, as this option creates an information
50247 + leak that could aid an attacker in defeating the randomization of
50248 + a single memory region. If the sysctl option is enabled, a sysctl
50249 + option with name "audit_textrel" is created.
50250 +
50251 +endmenu
50252 +
50253 +menu "Executable Protections"
50254 +depends on GRKERNSEC
50255 +
50256 +config GRKERNSEC_DMESG
50257 + bool "Dmesg(8) restriction"
50258 + help
50259 + If you say Y here, non-root users will not be able to use dmesg(8)
50260 + to view up to the last 4kb of messages in the kernel's log buffer.
50261 + The kernel's log buffer often contains kernel addresses and other
50262 + identifying information useful to an attacker in fingerprinting a
50263 + system for a targeted exploit.
50264 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50265 + created.
50266 +
50267 +config GRKERNSEC_HARDEN_PTRACE
50268 + bool "Deter ptrace-based process snooping"
50269 + help
50270 + If you say Y here, TTY sniffers and other malicious monitoring
50271 + programs implemented through ptrace will be defeated. If you
50272 + have been using the RBAC system, this option has already been
50273 + enabled for several years for all users, with the ability to make
50274 + fine-grained exceptions.
50275 +
50276 + This option only affects the ability of non-root users to ptrace
50277 + processes that are not a descendent of the ptracing process.
50278 + This means that strace ./binary and gdb ./binary will still work,
50279 + but attaching to arbitrary processes will not. If the sysctl
50280 + option is enabled, a sysctl option with name "harden_ptrace" is
50281 + created.
50282 +
50283 +config GRKERNSEC_PTRACE_READEXEC
50284 + bool "Require read access to ptrace sensitive binaries"
50285 + help
50286 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50287 + binaries. This option is useful in environments that
50288 + remove the read bits (e.g. file mode 4711) from suid binaries to
50289 + prevent infoleaking of their contents. This option adds
50290 + consistency to the use of that file mode, as the binary could normally
50291 + be read out when run without privileges while ptracing.
50292 +
50293 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50294 + is created.
50295 +
50296 +config GRKERNSEC_SETXID
50297 + bool "Enforce consistent multithreaded privileges"
50298 + help
50299 + If you say Y here, a change from a root uid to a non-root uid
50300 + in a multithreaded application will cause the resulting uids,
50301 + gids, supplementary groups, and capabilities in that thread
50302 + to be propagated to the other threads of the process. In most
50303 + cases this is unnecessary, as glibc will emulate this behavior
50304 + on behalf of the application. Other libcs do not act in the
50305 + same way, allowing the other threads of the process to continue
50306 + running with root privileges. If the sysctl option is enabled,
50307 + a sysctl option with name "consistent_setxid" is created.
50308 +
50309 +config GRKERNSEC_TPE
50310 + bool "Trusted Path Execution (TPE)"
50311 + help
50312 + If you say Y here, you will be able to choose a gid to add to the
50313 + supplementary groups of users you want to mark as "untrusted."
50314 + These users will not be able to execute any files that are not in
50315 + root-owned directories writable only by root. If the sysctl option
50316 + is enabled, a sysctl option with name "tpe" is created.
50317 +
50318 +config GRKERNSEC_TPE_ALL
50319 + bool "Partially restrict all non-root users"
50320 + depends on GRKERNSEC_TPE
50321 + help
50322 + If you say Y here, all non-root users will be covered under
50323 + a weaker TPE restriction. This is separate from, and in addition to,
50324 + the main TPE options that you have selected elsewhere. Thus, if a
50325 + "trusted" GID is chosen, this restriction applies to even that GID.
50326 + Under this restriction, all non-root users will only be allowed to
50327 + execute files in directories they own that are not group or
50328 + world-writable, or in directories owned by root and writable only by
50329 + root. If the sysctl option is enabled, a sysctl option with name
50330 + "tpe_restrict_all" is created.
50331 +
50332 +config GRKERNSEC_TPE_INVERT
50333 + bool "Invert GID option"
50334 + depends on GRKERNSEC_TPE
50335 + help
50336 + If you say Y here, the group you specify in the TPE configuration will
50337 + decide what group TPE restrictions will be *disabled* for. This
50338 + option is useful if you want TPE restrictions to be applied to most
50339 + users on the system. If the sysctl option is enabled, a sysctl option
50340 + with name "tpe_invert" is created. Unlike other sysctl options, this
50341 + entry will default to on for backward-compatibility.
50342 +
50343 +config GRKERNSEC_TPE_GID
50344 + int "GID for untrusted users"
50345 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50346 + default 1005
50347 + help
50348 + Setting this GID determines what group TPE restrictions will be
50349 + *enabled* for. If the sysctl option is enabled, a sysctl option
50350 + with name "tpe_gid" is created.
50351 +
50352 +config GRKERNSEC_TPE_GID
50353 + int "GID for trusted users"
50354 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50355 + default 1005
50356 + help
50357 + Setting this GID determines what group TPE restrictions will be
50358 + *disabled* for. If the sysctl option is enabled, a sysctl option
50359 + with name "tpe_gid" is created.
50360 +
50361 +endmenu
50362 +menu "Network Protections"
50363 +depends on GRKERNSEC
50364 +
50365 +config GRKERNSEC_RANDNET
50366 + bool "Larger entropy pools"
50367 + help
50368 + If you say Y here, the entropy pools used for many features of Linux
50369 + and grsecurity will be doubled in size. Since several grsecurity
50370 + features use additional randomness, it is recommended that you say Y
50371 + here. Saying Y here has a similar effect as modifying
50372 + /proc/sys/kernel/random/poolsize.
50373 +
50374 +config GRKERNSEC_BLACKHOLE
50375 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50376 + depends on NET
50377 + help
50378 + If you say Y here, neither TCP resets nor ICMP
50379 + destination-unreachable packets will be sent in response to packets
50380 + sent to ports for which no associated listening process exists.
50381 + This feature supports both IPV4 and IPV6 and exempts the
50382 + loopback interface from blackholing. Enabling this feature
50383 + makes a host more resilient to DoS attacks and reduces network
50384 + visibility against scanners.
50385 +
50386 + The blackhole feature as-implemented is equivalent to the FreeBSD
50387 + blackhole feature, as it prevents RST responses to all packets, not
50388 + just SYNs. Under most application behavior this causes no
50389 + problems, but applications (like haproxy) may not close certain
50390 + connections in a way that cleanly terminates them on the remote
50391 + end, leaving the remote host in LAST_ACK state. Because of this
50392 + side-effect and to prevent intentional LAST_ACK DoSes, this
50393 + feature also adds automatic mitigation against such attacks.
50394 + The mitigation drastically reduces the amount of time a socket
50395 + can spend in LAST_ACK state. If you're using haproxy and not
50396 + all servers it connects to have this option enabled, consider
50397 + disabling this feature on the haproxy host.
50398 +
50399 + If the sysctl option is enabled, two sysctl options with names
50400 + "ip_blackhole" and "lastack_retries" will be created.
50401 + While "ip_blackhole" takes the standard zero/non-zero on/off
50402 + toggle, "lastack_retries" uses the same kinds of values as
50403 + "tcp_retries1" and "tcp_retries2". The default value of 4
50404 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50405 + state.
50406 +
50407 +config GRKERNSEC_SOCKET
50408 + bool "Socket restrictions"
50409 + depends on NET
50410 + help
50411 + If you say Y here, you will be able to choose from several options.
50412 + If you assign a GID on your system and add it to the supplementary
50413 + groups of users you want to restrict socket access to, this patch
50414 + will perform up to three things, based on the option(s) you choose.
50415 +
50416 +config GRKERNSEC_SOCKET_ALL
50417 + bool "Deny any sockets to group"
50418 + depends on GRKERNSEC_SOCKET
50419 + help
50420 + If you say Y here, you will be able to choose a GID of whose users will
50421 + be unable to connect to other hosts from your machine or run server
50422 + applications from your machine. If the sysctl option is enabled, a
50423 + sysctl option with name "socket_all" is created.
50424 +
50425 +config GRKERNSEC_SOCKET_ALL_GID
50426 + int "GID to deny all sockets for"
50427 + depends on GRKERNSEC_SOCKET_ALL
50428 + default 1004
50429 + help
50430 + Here you can choose the GID to disable socket access for. Remember to
50431 + add the users you want socket access disabled for to the GID
50432 + specified here. If the sysctl option is enabled, a sysctl option
50433 + with name "socket_all_gid" is created.
50434 +
50435 +config GRKERNSEC_SOCKET_CLIENT
50436 + bool "Deny client sockets to group"
50437 + depends on GRKERNSEC_SOCKET
50438 + help
50439 + If you say Y here, you will be able to choose a GID of whose users will
50440 + be unable to connect to other hosts from your machine, but will be
50441 + able to run servers. If this option is enabled, all users in the group
50442 + you specify will have to use passive mode when initiating ftp transfers
50443 + from the shell on your machine. If the sysctl option is enabled, a
50444 + sysctl option with name "socket_client" is created.
50445 +
50446 +config GRKERNSEC_SOCKET_CLIENT_GID
50447 + int "GID to deny client sockets for"
50448 + depends on GRKERNSEC_SOCKET_CLIENT
50449 + default 1003
50450 + help
50451 + Here you can choose the GID to disable client socket access for.
50452 + Remember to add the users you want client socket access disabled for to
50453 + the GID specified here. If the sysctl option is enabled, a sysctl
50454 + option with name "socket_client_gid" is created.
50455 +
50456 +config GRKERNSEC_SOCKET_SERVER
50457 + bool "Deny server sockets to group"
50458 + depends on GRKERNSEC_SOCKET
50459 + help
50460 + If you say Y here, you will be able to choose a GID of whose users will
50461 + be unable to run server applications from your machine. If the sysctl
50462 + option is enabled, a sysctl option with name "socket_server" is created.
50463 +
50464 +config GRKERNSEC_SOCKET_SERVER_GID
50465 + int "GID to deny server sockets for"
50466 + depends on GRKERNSEC_SOCKET_SERVER
50467 + default 1002
50468 + help
50469 + Here you can choose the GID to disable server socket access for.
50470 + Remember to add the users you want server socket access disabled for to
50471 + the GID specified here. If the sysctl option is enabled, a sysctl
50472 + option with name "socket_server_gid" is created.
50473 +
50474 +endmenu
50475 +menu "Sysctl support"
50476 +depends on GRKERNSEC && SYSCTL
50477 +
50478 +config GRKERNSEC_SYSCTL
50479 + bool "Sysctl support"
50480 + help
50481 + If you say Y here, you will be able to change the options that
50482 + grsecurity runs with at bootup, without having to recompile your
50483 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50484 + to enable (1) or disable (0) various features. All the sysctl entries
50485 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50486 + All features enabled in the kernel configuration are disabled at boot
50487 + if you do not say Y to the "Turn on features by default" option.
50488 + All options should be set at startup, and the grsec_lock entry should
50489 + be set to a non-zero value after all the options are set.
50490 + *THIS IS EXTREMELY IMPORTANT*
50491 +
50492 +config GRKERNSEC_SYSCTL_DISTRO
50493 + bool "Extra sysctl support for distro makers (READ HELP)"
50494 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50495 + help
50496 + If you say Y here, additional sysctl options will be created
50497 + for features that affect processes running as root. Therefore,
50498 + it is critical when using this option that the grsec_lock entry be
50499 + enabled after boot. Only distros with prebuilt kernel packages
50500 + with this option enabled that can ensure grsec_lock is enabled
50501 + after boot should use this option.
50502 + *Failure to set grsec_lock after boot makes all grsec features
50503 + this option covers useless*
50504 +
50505 + Currently this option creates the following sysctl entries:
50506 + "Disable Privileged I/O": "disable_priv_io"
50507 +
50508 +config GRKERNSEC_SYSCTL_ON
50509 + bool "Turn on features by default"
50510 + depends on GRKERNSEC_SYSCTL
50511 + help
50512 + If you say Y here, instead of having all features enabled in the
50513 + kernel configuration disabled at boot time, the features will be
50514 + enabled at boot time. It is recommended you say Y here unless
50515 + there is some reason you would want all sysctl-tunable features to
50516 + be disabled by default. As mentioned elsewhere, it is important
50517 + to enable the grsec_lock entry once you have finished modifying
50518 + the sysctl entries.
50519 +
50520 +endmenu
50521 +menu "Logging Options"
50522 +depends on GRKERNSEC
50523 +
50524 +config GRKERNSEC_FLOODTIME
50525 + int "Seconds in between log messages (minimum)"
50526 + default 10
50527 + help
50528 + This option allows you to enforce the number of seconds between
50529 + grsecurity log messages. The default should be suitable for most
50530 + people, however, if you choose to change it, choose a value small enough
50531 + to allow informative logs to be produced, but large enough to
50532 + prevent flooding.
50533 +
50534 +config GRKERNSEC_FLOODBURST
50535 + int "Number of messages in a burst (maximum)"
50536 + default 6
50537 + help
50538 + This option allows you to choose the maximum number of messages allowed
50539 + within the flood time interval you chose in a separate option. The
50540 + default should be suitable for most people, however if you find that
50541 + many of your logs are being interpreted as flooding, you may want to
50542 + raise this value.
50543 +
50544 +endmenu
50545 +
50546 +endmenu
50547 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50548 new file mode 100644
50549 index 0000000..1b9afa9
50550 --- /dev/null
50551 +++ b/grsecurity/Makefile
50552 @@ -0,0 +1,38 @@
50553 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50554 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50555 +# into an RBAC system
50556 +#
50557 +# All code in this directory and various hooks inserted throughout the kernel
50558 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50559 +# under the GPL v2 or higher
50560 +
50561 +KBUILD_CFLAGS += -Werror
50562 +
50563 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50564 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50565 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50566 +
50567 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50568 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50569 + gracl_learn.o grsec_log.o
50570 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50571 +
50572 +ifdef CONFIG_NET
50573 +obj-y += grsec_sock.o
50574 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50575 +endif
50576 +
50577 +ifndef CONFIG_GRKERNSEC
50578 +obj-y += grsec_disabled.o
50579 +endif
50580 +
50581 +ifdef CONFIG_GRKERNSEC_HIDESYM
50582 +extra-y := grsec_hidesym.o
50583 +$(obj)/grsec_hidesym.o:
50584 + @-chmod -f 500 /boot
50585 + @-chmod -f 500 /lib/modules
50586 + @-chmod -f 500 /lib64/modules
50587 + @-chmod -f 500 /lib32/modules
50588 + @-chmod -f 700 .
50589 + @echo ' grsec: protected kernel image paths'
50590 +endif
50591 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50592 new file mode 100644
50593 index 0000000..42813ac
50594 --- /dev/null
50595 +++ b/grsecurity/gracl.c
50596 @@ -0,0 +1,4192 @@
50597 +#include <linux/kernel.h>
50598 +#include <linux/module.h>
50599 +#include <linux/sched.h>
50600 +#include <linux/mm.h>
50601 +#include <linux/file.h>
50602 +#include <linux/fs.h>
50603 +#include <linux/namei.h>
50604 +#include <linux/mount.h>
50605 +#include <linux/tty.h>
50606 +#include <linux/proc_fs.h>
50607 +#include <linux/lglock.h>
50608 +#include <linux/slab.h>
50609 +#include <linux/vmalloc.h>
50610 +#include <linux/types.h>
50611 +#include <linux/sysctl.h>
50612 +#include <linux/netdevice.h>
50613 +#include <linux/ptrace.h>
50614 +#include <linux/gracl.h>
50615 +#include <linux/gralloc.h>
50616 +#include <linux/security.h>
50617 +#include <linux/grinternal.h>
50618 +#include <linux/pid_namespace.h>
50619 +#include <linux/fdtable.h>
50620 +#include <linux/percpu.h>
50621 +#include "../fs/mount.h"
50622 +
50623 +#include <asm/uaccess.h>
50624 +#include <asm/errno.h>
50625 +#include <asm/mman.h>
50626 +
50627 +static struct acl_role_db acl_role_set;
50628 +static struct name_db name_set;
50629 +static struct inodev_db inodev_set;
50630 +
50631 +/* for keeping track of userspace pointers used for subjects, so we
50632 + can share references in the kernel as well
50633 +*/
50634 +
50635 +static struct path real_root;
50636 +
50637 +static struct acl_subj_map_db subj_map_set;
50638 +
50639 +static struct acl_role_label *default_role;
50640 +
50641 +static struct acl_role_label *role_list;
50642 +
50643 +static u16 acl_sp_role_value;
50644 +
50645 +extern char *gr_shared_page[4];
50646 +static DEFINE_MUTEX(gr_dev_mutex);
50647 +DEFINE_RWLOCK(gr_inode_lock);
50648 +
50649 +struct gr_arg *gr_usermode;
50650 +
50651 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50652 +
50653 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50654 +extern void gr_clear_learn_entries(void);
50655 +
50656 +#ifdef CONFIG_GRKERNSEC_RESLOG
50657 +extern void gr_log_resource(const struct task_struct *task,
50658 + const int res, const unsigned long wanted, const int gt);
50659 +#endif
50660 +
50661 +unsigned char *gr_system_salt;
50662 +unsigned char *gr_system_sum;
50663 +
50664 +static struct sprole_pw **acl_special_roles = NULL;
50665 +static __u16 num_sprole_pws = 0;
50666 +
50667 +static struct acl_role_label *kernel_role = NULL;
50668 +
50669 +static unsigned int gr_auth_attempts = 0;
50670 +static unsigned long gr_auth_expires = 0UL;
50671 +
50672 +#ifdef CONFIG_NET
50673 +extern struct vfsmount *sock_mnt;
50674 +#endif
50675 +
50676 +extern struct vfsmount *pipe_mnt;
50677 +extern struct vfsmount *shm_mnt;
50678 +#ifdef CONFIG_HUGETLBFS
50679 +extern struct vfsmount *hugetlbfs_vfsmount;
50680 +#endif
50681 +
50682 +static struct acl_object_label *fakefs_obj_rw;
50683 +static struct acl_object_label *fakefs_obj_rwx;
50684 +
50685 +extern int gr_init_uidset(void);
50686 +extern void gr_free_uidset(void);
50687 +extern void gr_remove_uid(uid_t uid);
50688 +extern int gr_find_uid(uid_t uid);
50689 +
50690 +DECLARE_BRLOCK(vfsmount_lock);
50691 +
50692 +__inline__ int
50693 +gr_acl_is_enabled(void)
50694 +{
50695 + return (gr_status & GR_READY);
50696 +}
50697 +
50698 +#ifdef CONFIG_BTRFS_FS
50699 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50700 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50701 +#endif
50702 +
50703 +static inline dev_t __get_dev(const struct dentry *dentry)
50704 +{
50705 +#ifdef CONFIG_BTRFS_FS
50706 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50707 + return get_btrfs_dev_from_inode(dentry->d_inode);
50708 + else
50709 +#endif
50710 + return dentry->d_inode->i_sb->s_dev;
50711 +}
50712 +
50713 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50714 +{
50715 + return __get_dev(dentry);
50716 +}
50717 +
50718 +static char gr_task_roletype_to_char(struct task_struct *task)
50719 +{
50720 + switch (task->role->roletype &
50721 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50722 + GR_ROLE_SPECIAL)) {
50723 + case GR_ROLE_DEFAULT:
50724 + return 'D';
50725 + case GR_ROLE_USER:
50726 + return 'U';
50727 + case GR_ROLE_GROUP:
50728 + return 'G';
50729 + case GR_ROLE_SPECIAL:
50730 + return 'S';
50731 + }
50732 +
50733 + return 'X';
50734 +}
50735 +
50736 +char gr_roletype_to_char(void)
50737 +{
50738 + return gr_task_roletype_to_char(current);
50739 +}
50740 +
50741 +__inline__ int
50742 +gr_acl_tpe_check(void)
50743 +{
50744 + if (unlikely(!(gr_status & GR_READY)))
50745 + return 0;
50746 + if (current->role->roletype & GR_ROLE_TPE)
50747 + return 1;
50748 + else
50749 + return 0;
50750 +}
50751 +
50752 +int
50753 +gr_handle_rawio(const struct inode *inode)
50754 +{
50755 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50756 + if (inode && S_ISBLK(inode->i_mode) &&
50757 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50758 + !capable(CAP_SYS_RAWIO))
50759 + return 1;
50760 +#endif
50761 + return 0;
50762 +}
50763 +
50764 +static int
50765 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50766 +{
50767 + if (likely(lena != lenb))
50768 + return 0;
50769 +
50770 + return !memcmp(a, b, lena);
50771 +}
50772 +
50773 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50774 +{
50775 + *buflen -= namelen;
50776 + if (*buflen < 0)
50777 + return -ENAMETOOLONG;
50778 + *buffer -= namelen;
50779 + memcpy(*buffer, str, namelen);
50780 + return 0;
50781 +}
50782 +
50783 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50784 +{
50785 + return prepend(buffer, buflen, name->name, name->len);
50786 +}
50787 +
50788 +static int prepend_path(const struct path *path, struct path *root,
50789 + char **buffer, int *buflen)
50790 +{
50791 + struct dentry *dentry = path->dentry;
50792 + struct vfsmount *vfsmnt = path->mnt;
50793 + struct mount *mnt = real_mount(vfsmnt);
50794 + bool slash = false;
50795 + int error = 0;
50796 +
50797 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50798 + struct dentry * parent;
50799 +
50800 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50801 + /* Global root? */
50802 + if (!mnt_has_parent(mnt)) {
50803 + goto out;
50804 + }
50805 + dentry = mnt->mnt_mountpoint;
50806 + mnt = mnt->mnt_parent;
50807 + vfsmnt = &mnt->mnt;
50808 + continue;
50809 + }
50810 + parent = dentry->d_parent;
50811 + prefetch(parent);
50812 + spin_lock(&dentry->d_lock);
50813 + error = prepend_name(buffer, buflen, &dentry->d_name);
50814 + spin_unlock(&dentry->d_lock);
50815 + if (!error)
50816 + error = prepend(buffer, buflen, "/", 1);
50817 + if (error)
50818 + break;
50819 +
50820 + slash = true;
50821 + dentry = parent;
50822 + }
50823 +
50824 +out:
50825 + if (!error && !slash)
50826 + error = prepend(buffer, buflen, "/", 1);
50827 +
50828 + return error;
50829 +}
50830 +
50831 +/* this must be called with vfsmount_lock and rename_lock held */
50832 +
50833 +static char *__our_d_path(const struct path *path, struct path *root,
50834 + char *buf, int buflen)
50835 +{
50836 + char *res = buf + buflen;
50837 + int error;
50838 +
50839 + prepend(&res, &buflen, "\0", 1);
50840 + error = prepend_path(path, root, &res, &buflen);
50841 + if (error)
50842 + return ERR_PTR(error);
50843 +
50844 + return res;
50845 +}
50846 +
50847 +static char *
50848 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50849 +{
50850 + char *retval;
50851 +
50852 + retval = __our_d_path(path, root, buf, buflen);
50853 + if (unlikely(IS_ERR(retval)))
50854 + retval = strcpy(buf, "<path too long>");
50855 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50856 + retval[1] = '\0';
50857 +
50858 + return retval;
50859 +}
50860 +
50861 +static char *
50862 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50863 + char *buf, int buflen)
50864 +{
50865 + struct path path;
50866 + char *res;
50867 +
50868 + path.dentry = (struct dentry *)dentry;
50869 + path.mnt = (struct vfsmount *)vfsmnt;
50870 +
50871 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50872 + by the RBAC system */
50873 + res = gen_full_path(&path, &real_root, buf, buflen);
50874 +
50875 + return res;
50876 +}
50877 +
50878 +static char *
50879 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50880 + char *buf, int buflen)
50881 +{
50882 + char *res;
50883 + struct path path;
50884 + struct path root;
50885 + struct task_struct *reaper = &init_task;
50886 +
50887 + path.dentry = (struct dentry *)dentry;
50888 + path.mnt = (struct vfsmount *)vfsmnt;
50889 +
50890 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50891 + get_fs_root(reaper->fs, &root);
50892 +
50893 + write_seqlock(&rename_lock);
50894 + br_read_lock(vfsmount_lock);
50895 + res = gen_full_path(&path, &root, buf, buflen);
50896 + br_read_unlock(vfsmount_lock);
50897 + write_sequnlock(&rename_lock);
50898 +
50899 + path_put(&root);
50900 + return res;
50901 +}
50902 +
50903 +static char *
50904 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50905 +{
50906 + char *ret;
50907 + write_seqlock(&rename_lock);
50908 + br_read_lock(vfsmount_lock);
50909 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50910 + PAGE_SIZE);
50911 + br_read_unlock(vfsmount_lock);
50912 + write_sequnlock(&rename_lock);
50913 + return ret;
50914 +}
50915 +
50916 +static char *
50917 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50918 +{
50919 + char *ret;
50920 + char *buf;
50921 + int buflen;
50922 +
50923 + write_seqlock(&rename_lock);
50924 + br_read_lock(vfsmount_lock);
50925 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50926 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50927 + buflen = (int)(ret - buf);
50928 + if (buflen >= 5)
50929 + prepend(&ret, &buflen, "/proc", 5);
50930 + else
50931 + ret = strcpy(buf, "<path too long>");
50932 + br_read_unlock(vfsmount_lock);
50933 + write_sequnlock(&rename_lock);
50934 + return ret;
50935 +}
50936 +
50937 +char *
50938 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50939 +{
50940 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50941 + PAGE_SIZE);
50942 +}
50943 +
50944 +char *
50945 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50946 +{
50947 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50948 + PAGE_SIZE);
50949 +}
50950 +
50951 +char *
50952 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50953 +{
50954 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50955 + PAGE_SIZE);
50956 +}
50957 +
50958 +char *
50959 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50960 +{
50961 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50962 + PAGE_SIZE);
50963 +}
50964 +
50965 +char *
50966 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50967 +{
50968 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50969 + PAGE_SIZE);
50970 +}
50971 +
50972 +__inline__ __u32
50973 +to_gr_audit(const __u32 reqmode)
50974 +{
50975 + /* masks off auditable permission flags, then shifts them to create
50976 + auditing flags, and adds the special case of append auditing if
50977 + we're requesting write */
50978 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50979 +}
50980 +
50981 +struct acl_subject_label *
50982 +lookup_subject_map(const struct acl_subject_label *userp)
50983 +{
50984 + unsigned int index = shash(userp, subj_map_set.s_size);
50985 + struct subject_map *match;
50986 +
50987 + match = subj_map_set.s_hash[index];
50988 +
50989 + while (match && match->user != userp)
50990 + match = match->next;
50991 +
50992 + if (match != NULL)
50993 + return match->kernel;
50994 + else
50995 + return NULL;
50996 +}
50997 +
50998 +static void
50999 +insert_subj_map_entry(struct subject_map *subjmap)
51000 +{
51001 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51002 + struct subject_map **curr;
51003 +
51004 + subjmap->prev = NULL;
51005 +
51006 + curr = &subj_map_set.s_hash[index];
51007 + if (*curr != NULL)
51008 + (*curr)->prev = subjmap;
51009 +
51010 + subjmap->next = *curr;
51011 + *curr = subjmap;
51012 +
51013 + return;
51014 +}
51015 +
51016 +static struct acl_role_label *
51017 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51018 + const gid_t gid)
51019 +{
51020 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51021 + struct acl_role_label *match;
51022 + struct role_allowed_ip *ipp;
51023 + unsigned int x;
51024 + u32 curr_ip = task->signal->curr_ip;
51025 +
51026 + task->signal->saved_ip = curr_ip;
51027 +
51028 + match = acl_role_set.r_hash[index];
51029 +
51030 + while (match) {
51031 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51032 + for (x = 0; x < match->domain_child_num; x++) {
51033 + if (match->domain_children[x] == uid)
51034 + goto found;
51035 + }
51036 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51037 + break;
51038 + match = match->next;
51039 + }
51040 +found:
51041 + if (match == NULL) {
51042 + try_group:
51043 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51044 + match = acl_role_set.r_hash[index];
51045 +
51046 + while (match) {
51047 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51048 + for (x = 0; x < match->domain_child_num; x++) {
51049 + if (match->domain_children[x] == gid)
51050 + goto found2;
51051 + }
51052 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51053 + break;
51054 + match = match->next;
51055 + }
51056 +found2:
51057 + if (match == NULL)
51058 + match = default_role;
51059 + if (match->allowed_ips == NULL)
51060 + return match;
51061 + else {
51062 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51063 + if (likely
51064 + ((ntohl(curr_ip) & ipp->netmask) ==
51065 + (ntohl(ipp->addr) & ipp->netmask)))
51066 + return match;
51067 + }
51068 + match = default_role;
51069 + }
51070 + } else if (match->allowed_ips == NULL) {
51071 + return match;
51072 + } else {
51073 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51074 + if (likely
51075 + ((ntohl(curr_ip) & ipp->netmask) ==
51076 + (ntohl(ipp->addr) & ipp->netmask)))
51077 + return match;
51078 + }
51079 + goto try_group;
51080 + }
51081 +
51082 + return match;
51083 +}
51084 +
51085 +struct acl_subject_label *
51086 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51087 + const struct acl_role_label *role)
51088 +{
51089 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51090 + struct acl_subject_label *match;
51091 +
51092 + match = role->subj_hash[index];
51093 +
51094 + while (match && (match->inode != ino || match->device != dev ||
51095 + (match->mode & GR_DELETED))) {
51096 + match = match->next;
51097 + }
51098 +
51099 + if (match && !(match->mode & GR_DELETED))
51100 + return match;
51101 + else
51102 + return NULL;
51103 +}
51104 +
51105 +struct acl_subject_label *
51106 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51107 + const struct acl_role_label *role)
51108 +{
51109 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51110 + struct acl_subject_label *match;
51111 +
51112 + match = role->subj_hash[index];
51113 +
51114 + while (match && (match->inode != ino || match->device != dev ||
51115 + !(match->mode & GR_DELETED))) {
51116 + match = match->next;
51117 + }
51118 +
51119 + if (match && (match->mode & GR_DELETED))
51120 + return match;
51121 + else
51122 + return NULL;
51123 +}
51124 +
51125 +static struct acl_object_label *
51126 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51127 + const struct acl_subject_label *subj)
51128 +{
51129 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51130 + struct acl_object_label *match;
51131 +
51132 + match = subj->obj_hash[index];
51133 +
51134 + while (match && (match->inode != ino || match->device != dev ||
51135 + (match->mode & GR_DELETED))) {
51136 + match = match->next;
51137 + }
51138 +
51139 + if (match && !(match->mode & GR_DELETED))
51140 + return match;
51141 + else
51142 + return NULL;
51143 +}
51144 +
51145 +static struct acl_object_label *
51146 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51147 + const struct acl_subject_label *subj)
51148 +{
51149 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51150 + struct acl_object_label *match;
51151 +
51152 + match = subj->obj_hash[index];
51153 +
51154 + while (match && (match->inode != ino || match->device != dev ||
51155 + !(match->mode & GR_DELETED))) {
51156 + match = match->next;
51157 + }
51158 +
51159 + if (match && (match->mode & GR_DELETED))
51160 + return match;
51161 +
51162 + match = subj->obj_hash[index];
51163 +
51164 + while (match && (match->inode != ino || match->device != dev ||
51165 + (match->mode & GR_DELETED))) {
51166 + match = match->next;
51167 + }
51168 +
51169 + if (match && !(match->mode & GR_DELETED))
51170 + return match;
51171 + else
51172 + return NULL;
51173 +}
51174 +
51175 +static struct name_entry *
51176 +lookup_name_entry(const char *name)
51177 +{
51178 + unsigned int len = strlen(name);
51179 + unsigned int key = full_name_hash(name, len);
51180 + unsigned int index = key % name_set.n_size;
51181 + struct name_entry *match;
51182 +
51183 + match = name_set.n_hash[index];
51184 +
51185 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51186 + match = match->next;
51187 +
51188 + return match;
51189 +}
51190 +
51191 +static struct name_entry *
51192 +lookup_name_entry_create(const char *name)
51193 +{
51194 + unsigned int len = strlen(name);
51195 + unsigned int key = full_name_hash(name, len);
51196 + unsigned int index = key % name_set.n_size;
51197 + struct name_entry *match;
51198 +
51199 + match = name_set.n_hash[index];
51200 +
51201 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51202 + !match->deleted))
51203 + match = match->next;
51204 +
51205 + if (match && match->deleted)
51206 + return match;
51207 +
51208 + match = name_set.n_hash[index];
51209 +
51210 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51211 + match->deleted))
51212 + match = match->next;
51213 +
51214 + if (match && !match->deleted)
51215 + return match;
51216 + else
51217 + return NULL;
51218 +}
51219 +
51220 +static struct inodev_entry *
51221 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51222 +{
51223 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51224 + struct inodev_entry *match;
51225 +
51226 + match = inodev_set.i_hash[index];
51227 +
51228 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51229 + match = match->next;
51230 +
51231 + return match;
51232 +}
51233 +
51234 +static void
51235 +insert_inodev_entry(struct inodev_entry *entry)
51236 +{
51237 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51238 + inodev_set.i_size);
51239 + struct inodev_entry **curr;
51240 +
51241 + entry->prev = NULL;
51242 +
51243 + curr = &inodev_set.i_hash[index];
51244 + if (*curr != NULL)
51245 + (*curr)->prev = entry;
51246 +
51247 + entry->next = *curr;
51248 + *curr = entry;
51249 +
51250 + return;
51251 +}
51252 +
51253 +static void
51254 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51255 +{
51256 + unsigned int index =
51257 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51258 + struct acl_role_label **curr;
51259 + struct acl_role_label *tmp, *tmp2;
51260 +
51261 + curr = &acl_role_set.r_hash[index];
51262 +
51263 + /* simple case, slot is empty, just set it to our role */
51264 + if (*curr == NULL) {
51265 + *curr = role;
51266 + } else {
51267 + /* example:
51268 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51269 + 2 -> 3
51270 + */
51271 + /* first check to see if we can already be reached via this slot */
51272 + tmp = *curr;
51273 + while (tmp && tmp != role)
51274 + tmp = tmp->next;
51275 + if (tmp == role) {
51276 + /* we don't need to add ourselves to this slot's chain */
51277 + return;
51278 + }
51279 + /* we need to add ourselves to this chain, two cases */
51280 + if (role->next == NULL) {
51281 + /* simple case, append the current chain to our role */
51282 + role->next = *curr;
51283 + *curr = role;
51284 + } else {
51285 + /* 1 -> 2 -> 3 -> 4
51286 + 2 -> 3 -> 4
51287 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51288 + */
51289 + /* trickier case: walk our role's chain until we find
51290 + the role for the start of the current slot's chain */
51291 + tmp = role;
51292 + tmp2 = *curr;
51293 + while (tmp->next && tmp->next != tmp2)
51294 + tmp = tmp->next;
51295 + if (tmp->next == tmp2) {
51296 + /* from example above, we found 3, so just
51297 + replace this slot's chain with ours */
51298 + *curr = role;
51299 + } else {
51300 + /* we didn't find a subset of our role's chain
51301 + in the current slot's chain, so append their
51302 + chain to ours, and set us as the first role in
51303 + the slot's chain
51304 +
51305 + we could fold this case with the case above,
51306 + but making it explicit for clarity
51307 + */
51308 + tmp->next = tmp2;
51309 + *curr = role;
51310 + }
51311 + }
51312 + }
51313 +
51314 + return;
51315 +}
51316 +
51317 +static void
51318 +insert_acl_role_label(struct acl_role_label *role)
51319 +{
51320 + int i;
51321 +
51322 + if (role_list == NULL) {
51323 + role_list = role;
51324 + role->prev = NULL;
51325 + } else {
51326 + role->prev = role_list;
51327 + role_list = role;
51328 + }
51329 +
51330 + /* used for hash chains */
51331 + role->next = NULL;
51332 +
51333 + if (role->roletype & GR_ROLE_DOMAIN) {
51334 + for (i = 0; i < role->domain_child_num; i++)
51335 + __insert_acl_role_label(role, role->domain_children[i]);
51336 + } else
51337 + __insert_acl_role_label(role, role->uidgid);
51338 +}
51339 +
51340 +static int
51341 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51342 +{
51343 + struct name_entry **curr, *nentry;
51344 + struct inodev_entry *ientry;
51345 + unsigned int len = strlen(name);
51346 + unsigned int key = full_name_hash(name, len);
51347 + unsigned int index = key % name_set.n_size;
51348 +
51349 + curr = &name_set.n_hash[index];
51350 +
51351 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51352 + curr = &((*curr)->next);
51353 +
51354 + if (*curr != NULL)
51355 + return 1;
51356 +
51357 + nentry = acl_alloc(sizeof (struct name_entry));
51358 + if (nentry == NULL)
51359 + return 0;
51360 + ientry = acl_alloc(sizeof (struct inodev_entry));
51361 + if (ientry == NULL)
51362 + return 0;
51363 + ientry->nentry = nentry;
51364 +
51365 + nentry->key = key;
51366 + nentry->name = name;
51367 + nentry->inode = inode;
51368 + nentry->device = device;
51369 + nentry->len = len;
51370 + nentry->deleted = deleted;
51371 +
51372 + nentry->prev = NULL;
51373 + curr = &name_set.n_hash[index];
51374 + if (*curr != NULL)
51375 + (*curr)->prev = nentry;
51376 + nentry->next = *curr;
51377 + *curr = nentry;
51378 +
51379 + /* insert us into the table searchable by inode/dev */
51380 + insert_inodev_entry(ientry);
51381 +
51382 + return 1;
51383 +}
51384 +
51385 +static void
51386 +insert_acl_obj_label(struct acl_object_label *obj,
51387 + struct acl_subject_label *subj)
51388 +{
51389 + unsigned int index =
51390 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51391 + struct acl_object_label **curr;
51392 +
51393 +
51394 + obj->prev = NULL;
51395 +
51396 + curr = &subj->obj_hash[index];
51397 + if (*curr != NULL)
51398 + (*curr)->prev = obj;
51399 +
51400 + obj->next = *curr;
51401 + *curr = obj;
51402 +
51403 + return;
51404 +}
51405 +
51406 +static void
51407 +insert_acl_subj_label(struct acl_subject_label *obj,
51408 + struct acl_role_label *role)
51409 +{
51410 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51411 + struct acl_subject_label **curr;
51412 +
51413 + obj->prev = NULL;
51414 +
51415 + curr = &role->subj_hash[index];
51416 + if (*curr != NULL)
51417 + (*curr)->prev = obj;
51418 +
51419 + obj->next = *curr;
51420 + *curr = obj;
51421 +
51422 + return;
51423 +}
51424 +
51425 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51426 +
51427 +static void *
51428 +create_table(__u32 * len, int elementsize)
51429 +{
51430 + unsigned int table_sizes[] = {
51431 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51432 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51433 + 4194301, 8388593, 16777213, 33554393, 67108859
51434 + };
51435 + void *newtable = NULL;
51436 + unsigned int pwr = 0;
51437 +
51438 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51439 + table_sizes[pwr] <= *len)
51440 + pwr++;
51441 +
51442 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51443 + return newtable;
51444 +
51445 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51446 + newtable =
51447 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51448 + else
51449 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51450 +
51451 + *len = table_sizes[pwr];
51452 +
51453 + return newtable;
51454 +}
51455 +
51456 +static int
51457 +init_variables(const struct gr_arg *arg)
51458 +{
51459 + struct task_struct *reaper = &init_task;
51460 + unsigned int stacksize;
51461 +
51462 + subj_map_set.s_size = arg->role_db.num_subjects;
51463 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51464 + name_set.n_size = arg->role_db.num_objects;
51465 + inodev_set.i_size = arg->role_db.num_objects;
51466 +
51467 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51468 + !name_set.n_size || !inodev_set.i_size)
51469 + return 1;
51470 +
51471 + if (!gr_init_uidset())
51472 + return 1;
51473 +
51474 + /* set up the stack that holds allocation info */
51475 +
51476 + stacksize = arg->role_db.num_pointers + 5;
51477 +
51478 + if (!acl_alloc_stack_init(stacksize))
51479 + return 1;
51480 +
51481 + /* grab reference for the real root dentry and vfsmount */
51482 + get_fs_root(reaper->fs, &real_root);
51483 +
51484 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51485 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51486 +#endif
51487 +
51488 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51489 + if (fakefs_obj_rw == NULL)
51490 + return 1;
51491 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51492 +
51493 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51494 + if (fakefs_obj_rwx == NULL)
51495 + return 1;
51496 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51497 +
51498 + subj_map_set.s_hash =
51499 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51500 + acl_role_set.r_hash =
51501 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51502 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51503 + inodev_set.i_hash =
51504 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51505 +
51506 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51507 + !name_set.n_hash || !inodev_set.i_hash)
51508 + return 1;
51509 +
51510 + memset(subj_map_set.s_hash, 0,
51511 + sizeof(struct subject_map *) * subj_map_set.s_size);
51512 + memset(acl_role_set.r_hash, 0,
51513 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51514 + memset(name_set.n_hash, 0,
51515 + sizeof (struct name_entry *) * name_set.n_size);
51516 + memset(inodev_set.i_hash, 0,
51517 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51518 +
51519 + return 0;
51520 +}
51521 +
51522 +/* free information not needed after startup
51523 + currently contains user->kernel pointer mappings for subjects
51524 +*/
51525 +
51526 +static void
51527 +free_init_variables(void)
51528 +{
51529 + __u32 i;
51530 +
51531 + if (subj_map_set.s_hash) {
51532 + for (i = 0; i < subj_map_set.s_size; i++) {
51533 + if (subj_map_set.s_hash[i]) {
51534 + kfree(subj_map_set.s_hash[i]);
51535 + subj_map_set.s_hash[i] = NULL;
51536 + }
51537 + }
51538 +
51539 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51540 + PAGE_SIZE)
51541 + kfree(subj_map_set.s_hash);
51542 + else
51543 + vfree(subj_map_set.s_hash);
51544 + }
51545 +
51546 + return;
51547 +}
51548 +
51549 +static void
51550 +free_variables(void)
51551 +{
51552 + struct acl_subject_label *s;
51553 + struct acl_role_label *r;
51554 + struct task_struct *task, *task2;
51555 + unsigned int x;
51556 +
51557 + gr_clear_learn_entries();
51558 +
51559 + read_lock(&tasklist_lock);
51560 + do_each_thread(task2, task) {
51561 + task->acl_sp_role = 0;
51562 + task->acl_role_id = 0;
51563 + task->acl = NULL;
51564 + task->role = NULL;
51565 + } while_each_thread(task2, task);
51566 + read_unlock(&tasklist_lock);
51567 +
51568 + /* release the reference to the real root dentry and vfsmount */
51569 + path_put(&real_root);
51570 + memset(&real_root, 0, sizeof(real_root));
51571 +
51572 + /* free all object hash tables */
51573 +
51574 + FOR_EACH_ROLE_START(r)
51575 + if (r->subj_hash == NULL)
51576 + goto next_role;
51577 + FOR_EACH_SUBJECT_START(r, s, x)
51578 + if (s->obj_hash == NULL)
51579 + break;
51580 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51581 + kfree(s->obj_hash);
51582 + else
51583 + vfree(s->obj_hash);
51584 + FOR_EACH_SUBJECT_END(s, x)
51585 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51586 + if (s->obj_hash == NULL)
51587 + break;
51588 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51589 + kfree(s->obj_hash);
51590 + else
51591 + vfree(s->obj_hash);
51592 + FOR_EACH_NESTED_SUBJECT_END(s)
51593 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51594 + kfree(r->subj_hash);
51595 + else
51596 + vfree(r->subj_hash);
51597 + r->subj_hash = NULL;
51598 +next_role:
51599 + FOR_EACH_ROLE_END(r)
51600 +
51601 + acl_free_all();
51602 +
51603 + if (acl_role_set.r_hash) {
51604 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51605 + PAGE_SIZE)
51606 + kfree(acl_role_set.r_hash);
51607 + else
51608 + vfree(acl_role_set.r_hash);
51609 + }
51610 + if (name_set.n_hash) {
51611 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51612 + PAGE_SIZE)
51613 + kfree(name_set.n_hash);
51614 + else
51615 + vfree(name_set.n_hash);
51616 + }
51617 +
51618 + if (inodev_set.i_hash) {
51619 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51620 + PAGE_SIZE)
51621 + kfree(inodev_set.i_hash);
51622 + else
51623 + vfree(inodev_set.i_hash);
51624 + }
51625 +
51626 + gr_free_uidset();
51627 +
51628 + memset(&name_set, 0, sizeof (struct name_db));
51629 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51630 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51631 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51632 +
51633 + default_role = NULL;
51634 + kernel_role = NULL;
51635 + role_list = NULL;
51636 +
51637 + return;
51638 +}
51639 +
51640 +static __u32
51641 +count_user_objs(struct acl_object_label *userp)
51642 +{
51643 + struct acl_object_label o_tmp;
51644 + __u32 num = 0;
51645 +
51646 + while (userp) {
51647 + if (copy_from_user(&o_tmp, userp,
51648 + sizeof (struct acl_object_label)))
51649 + break;
51650 +
51651 + userp = o_tmp.prev;
51652 + num++;
51653 + }
51654 +
51655 + return num;
51656 +}
51657 +
51658 +static struct acl_subject_label *
51659 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51660 +
51661 +static int
51662 +copy_user_glob(struct acl_object_label *obj)
51663 +{
51664 + struct acl_object_label *g_tmp, **guser;
51665 + unsigned int len;
51666 + char *tmp;
51667 +
51668 + if (obj->globbed == NULL)
51669 + return 0;
51670 +
51671 + guser = &obj->globbed;
51672 + while (*guser) {
51673 + g_tmp = (struct acl_object_label *)
51674 + acl_alloc(sizeof (struct acl_object_label));
51675 + if (g_tmp == NULL)
51676 + return -ENOMEM;
51677 +
51678 + if (copy_from_user(g_tmp, *guser,
51679 + sizeof (struct acl_object_label)))
51680 + return -EFAULT;
51681 +
51682 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51683 +
51684 + if (!len || len >= PATH_MAX)
51685 + return -EINVAL;
51686 +
51687 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51688 + return -ENOMEM;
51689 +
51690 + if (copy_from_user(tmp, g_tmp->filename, len))
51691 + return -EFAULT;
51692 + tmp[len-1] = '\0';
51693 + g_tmp->filename = tmp;
51694 +
51695 + *guser = g_tmp;
51696 + guser = &(g_tmp->next);
51697 + }
51698 +
51699 + return 0;
51700 +}
51701 +
51702 +static int
51703 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51704 + struct acl_role_label *role)
51705 +{
51706 + struct acl_object_label *o_tmp;
51707 + unsigned int len;
51708 + int ret;
51709 + char *tmp;
51710 +
51711 + while (userp) {
51712 + if ((o_tmp = (struct acl_object_label *)
51713 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51714 + return -ENOMEM;
51715 +
51716 + if (copy_from_user(o_tmp, userp,
51717 + sizeof (struct acl_object_label)))
51718 + return -EFAULT;
51719 +
51720 + userp = o_tmp->prev;
51721 +
51722 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51723 +
51724 + if (!len || len >= PATH_MAX)
51725 + return -EINVAL;
51726 +
51727 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51728 + return -ENOMEM;
51729 +
51730 + if (copy_from_user(tmp, o_tmp->filename, len))
51731 + return -EFAULT;
51732 + tmp[len-1] = '\0';
51733 + o_tmp->filename = tmp;
51734 +
51735 + insert_acl_obj_label(o_tmp, subj);
51736 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51737 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51738 + return -ENOMEM;
51739 +
51740 + ret = copy_user_glob(o_tmp);
51741 + if (ret)
51742 + return ret;
51743 +
51744 + if (o_tmp->nested) {
51745 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51746 + if (IS_ERR(o_tmp->nested))
51747 + return PTR_ERR(o_tmp->nested);
51748 +
51749 + /* insert into nested subject list */
51750 + o_tmp->nested->next = role->hash->first;
51751 + role->hash->first = o_tmp->nested;
51752 + }
51753 + }
51754 +
51755 + return 0;
51756 +}
51757 +
51758 +static __u32
51759 +count_user_subjs(struct acl_subject_label *userp)
51760 +{
51761 + struct acl_subject_label s_tmp;
51762 + __u32 num = 0;
51763 +
51764 + while (userp) {
51765 + if (copy_from_user(&s_tmp, userp,
51766 + sizeof (struct acl_subject_label)))
51767 + break;
51768 +
51769 + userp = s_tmp.prev;
51770 + /* do not count nested subjects against this count, since
51771 + they are not included in the hash table, but are
51772 + attached to objects. We have already counted
51773 + the subjects in userspace for the allocation
51774 + stack
51775 + */
51776 + if (!(s_tmp.mode & GR_NESTED))
51777 + num++;
51778 + }
51779 +
51780 + return num;
51781 +}
51782 +
51783 +static int
51784 +copy_user_allowedips(struct acl_role_label *rolep)
51785 +{
51786 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51787 +
51788 + ruserip = rolep->allowed_ips;
51789 +
51790 + while (ruserip) {
51791 + rlast = rtmp;
51792 +
51793 + if ((rtmp = (struct role_allowed_ip *)
51794 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51795 + return -ENOMEM;
51796 +
51797 + if (copy_from_user(rtmp, ruserip,
51798 + sizeof (struct role_allowed_ip)))
51799 + return -EFAULT;
51800 +
51801 + ruserip = rtmp->prev;
51802 +
51803 + if (!rlast) {
51804 + rtmp->prev = NULL;
51805 + rolep->allowed_ips = rtmp;
51806 + } else {
51807 + rlast->next = rtmp;
51808 + rtmp->prev = rlast;
51809 + }
51810 +
51811 + if (!ruserip)
51812 + rtmp->next = NULL;
51813 + }
51814 +
51815 + return 0;
51816 +}
51817 +
51818 +static int
51819 +copy_user_transitions(struct acl_role_label *rolep)
51820 +{
51821 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51822 +
51823 + unsigned int len;
51824 + char *tmp;
51825 +
51826 + rusertp = rolep->transitions;
51827 +
51828 + while (rusertp) {
51829 + rlast = rtmp;
51830 +
51831 + if ((rtmp = (struct role_transition *)
51832 + acl_alloc(sizeof (struct role_transition))) == NULL)
51833 + return -ENOMEM;
51834 +
51835 + if (copy_from_user(rtmp, rusertp,
51836 + sizeof (struct role_transition)))
51837 + return -EFAULT;
51838 +
51839 + rusertp = rtmp->prev;
51840 +
51841 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51842 +
51843 + if (!len || len >= GR_SPROLE_LEN)
51844 + return -EINVAL;
51845 +
51846 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51847 + return -ENOMEM;
51848 +
51849 + if (copy_from_user(tmp, rtmp->rolename, len))
51850 + return -EFAULT;
51851 + tmp[len-1] = '\0';
51852 + rtmp->rolename = tmp;
51853 +
51854 + if (!rlast) {
51855 + rtmp->prev = NULL;
51856 + rolep->transitions = rtmp;
51857 + } else {
51858 + rlast->next = rtmp;
51859 + rtmp->prev = rlast;
51860 + }
51861 +
51862 + if (!rusertp)
51863 + rtmp->next = NULL;
51864 + }
51865 +
51866 + return 0;
51867 +}
51868 +
51869 +static struct acl_subject_label *
51870 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51871 +{
51872 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51873 + unsigned int len;
51874 + char *tmp;
51875 + __u32 num_objs;
51876 + struct acl_ip_label **i_tmp, *i_utmp2;
51877 + struct gr_hash_struct ghash;
51878 + struct subject_map *subjmap;
51879 + unsigned int i_num;
51880 + int err;
51881 +
51882 + s_tmp = lookup_subject_map(userp);
51883 +
51884 + /* we've already copied this subject into the kernel, just return
51885 + the reference to it, and don't copy it over again
51886 + */
51887 + if (s_tmp)
51888 + return(s_tmp);
51889 +
51890 + if ((s_tmp = (struct acl_subject_label *)
51891 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51892 + return ERR_PTR(-ENOMEM);
51893 +
51894 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51895 + if (subjmap == NULL)
51896 + return ERR_PTR(-ENOMEM);
51897 +
51898 + subjmap->user = userp;
51899 + subjmap->kernel = s_tmp;
51900 + insert_subj_map_entry(subjmap);
51901 +
51902 + if (copy_from_user(s_tmp, userp,
51903 + sizeof (struct acl_subject_label)))
51904 + return ERR_PTR(-EFAULT);
51905 +
51906 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51907 +
51908 + if (!len || len >= PATH_MAX)
51909 + return ERR_PTR(-EINVAL);
51910 +
51911 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51912 + return ERR_PTR(-ENOMEM);
51913 +
51914 + if (copy_from_user(tmp, s_tmp->filename, len))
51915 + return ERR_PTR(-EFAULT);
51916 + tmp[len-1] = '\0';
51917 + s_tmp->filename = tmp;
51918 +
51919 + if (!strcmp(s_tmp->filename, "/"))
51920 + role->root_label = s_tmp;
51921 +
51922 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51923 + return ERR_PTR(-EFAULT);
51924 +
51925 + /* copy user and group transition tables */
51926 +
51927 + if (s_tmp->user_trans_num) {
51928 + uid_t *uidlist;
51929 +
51930 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51931 + if (uidlist == NULL)
51932 + return ERR_PTR(-ENOMEM);
51933 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51934 + return ERR_PTR(-EFAULT);
51935 +
51936 + s_tmp->user_transitions = uidlist;
51937 + }
51938 +
51939 + if (s_tmp->group_trans_num) {
51940 + gid_t *gidlist;
51941 +
51942 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51943 + if (gidlist == NULL)
51944 + return ERR_PTR(-ENOMEM);
51945 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51946 + return ERR_PTR(-EFAULT);
51947 +
51948 + s_tmp->group_transitions = gidlist;
51949 + }
51950 +
51951 + /* set up object hash table */
51952 + num_objs = count_user_objs(ghash.first);
51953 +
51954 + s_tmp->obj_hash_size = num_objs;
51955 + s_tmp->obj_hash =
51956 + (struct acl_object_label **)
51957 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51958 +
51959 + if (!s_tmp->obj_hash)
51960 + return ERR_PTR(-ENOMEM);
51961 +
51962 + memset(s_tmp->obj_hash, 0,
51963 + s_tmp->obj_hash_size *
51964 + sizeof (struct acl_object_label *));
51965 +
51966 + /* add in objects */
51967 + err = copy_user_objs(ghash.first, s_tmp, role);
51968 +
51969 + if (err)
51970 + return ERR_PTR(err);
51971 +
51972 + /* set pointer for parent subject */
51973 + if (s_tmp->parent_subject) {
51974 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51975 +
51976 + if (IS_ERR(s_tmp2))
51977 + return s_tmp2;
51978 +
51979 + s_tmp->parent_subject = s_tmp2;
51980 + }
51981 +
51982 + /* add in ip acls */
51983 +
51984 + if (!s_tmp->ip_num) {
51985 + s_tmp->ips = NULL;
51986 + goto insert;
51987 + }
51988 +
51989 + i_tmp =
51990 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51991 + sizeof (struct acl_ip_label *));
51992 +
51993 + if (!i_tmp)
51994 + return ERR_PTR(-ENOMEM);
51995 +
51996 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51997 + *(i_tmp + i_num) =
51998 + (struct acl_ip_label *)
51999 + acl_alloc(sizeof (struct acl_ip_label));
52000 + if (!*(i_tmp + i_num))
52001 + return ERR_PTR(-ENOMEM);
52002 +
52003 + if (copy_from_user
52004 + (&i_utmp2, s_tmp->ips + i_num,
52005 + sizeof (struct acl_ip_label *)))
52006 + return ERR_PTR(-EFAULT);
52007 +
52008 + if (copy_from_user
52009 + (*(i_tmp + i_num), i_utmp2,
52010 + sizeof (struct acl_ip_label)))
52011 + return ERR_PTR(-EFAULT);
52012 +
52013 + if ((*(i_tmp + i_num))->iface == NULL)
52014 + continue;
52015 +
52016 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52017 + if (!len || len >= IFNAMSIZ)
52018 + return ERR_PTR(-EINVAL);
52019 + tmp = acl_alloc(len);
52020 + if (tmp == NULL)
52021 + return ERR_PTR(-ENOMEM);
52022 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52023 + return ERR_PTR(-EFAULT);
52024 + (*(i_tmp + i_num))->iface = tmp;
52025 + }
52026 +
52027 + s_tmp->ips = i_tmp;
52028 +
52029 +insert:
52030 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52031 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52032 + return ERR_PTR(-ENOMEM);
52033 +
52034 + return s_tmp;
52035 +}
52036 +
52037 +static int
52038 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52039 +{
52040 + struct acl_subject_label s_pre;
52041 + struct acl_subject_label * ret;
52042 + int err;
52043 +
52044 + while (userp) {
52045 + if (copy_from_user(&s_pre, userp,
52046 + sizeof (struct acl_subject_label)))
52047 + return -EFAULT;
52048 +
52049 + /* do not add nested subjects here, add
52050 + while parsing objects
52051 + */
52052 +
52053 + if (s_pre.mode & GR_NESTED) {
52054 + userp = s_pre.prev;
52055 + continue;
52056 + }
52057 +
52058 + ret = do_copy_user_subj(userp, role);
52059 +
52060 + err = PTR_ERR(ret);
52061 + if (IS_ERR(ret))
52062 + return err;
52063 +
52064 + insert_acl_subj_label(ret, role);
52065 +
52066 + userp = s_pre.prev;
52067 + }
52068 +
52069 + return 0;
52070 +}
52071 +
52072 +static int
52073 +copy_user_acl(struct gr_arg *arg)
52074 +{
52075 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52076 + struct sprole_pw *sptmp;
52077 + struct gr_hash_struct *ghash;
52078 + uid_t *domainlist;
52079 + unsigned int r_num;
52080 + unsigned int len;
52081 + char *tmp;
52082 + int err = 0;
52083 + __u16 i;
52084 + __u32 num_subjs;
52085 +
52086 + /* we need a default and kernel role */
52087 + if (arg->role_db.num_roles < 2)
52088 + return -EINVAL;
52089 +
52090 + /* copy special role authentication info from userspace */
52091 +
52092 + num_sprole_pws = arg->num_sprole_pws;
52093 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52094 +
52095 + if (!acl_special_roles && num_sprole_pws)
52096 + return -ENOMEM;
52097 +
52098 + for (i = 0; i < num_sprole_pws; i++) {
52099 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52100 + if (!sptmp)
52101 + return -ENOMEM;
52102 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52103 + sizeof (struct sprole_pw)))
52104 + return -EFAULT;
52105 +
52106 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52107 +
52108 + if (!len || len >= GR_SPROLE_LEN)
52109 + return -EINVAL;
52110 +
52111 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52112 + return -ENOMEM;
52113 +
52114 + if (copy_from_user(tmp, sptmp->rolename, len))
52115 + return -EFAULT;
52116 +
52117 + tmp[len-1] = '\0';
52118 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52119 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52120 +#endif
52121 + sptmp->rolename = tmp;
52122 + acl_special_roles[i] = sptmp;
52123 + }
52124 +
52125 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52126 +
52127 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52128 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52129 +
52130 + if (!r_tmp)
52131 + return -ENOMEM;
52132 +
52133 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52134 + sizeof (struct acl_role_label *)))
52135 + return -EFAULT;
52136 +
52137 + if (copy_from_user(r_tmp, r_utmp2,
52138 + sizeof (struct acl_role_label)))
52139 + return -EFAULT;
52140 +
52141 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52142 +
52143 + if (!len || len >= PATH_MAX)
52144 + return -EINVAL;
52145 +
52146 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52147 + return -ENOMEM;
52148 +
52149 + if (copy_from_user(tmp, r_tmp->rolename, len))
52150 + return -EFAULT;
52151 +
52152 + tmp[len-1] = '\0';
52153 + r_tmp->rolename = tmp;
52154 +
52155 + if (!strcmp(r_tmp->rolename, "default")
52156 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52157 + default_role = r_tmp;
52158 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52159 + kernel_role = r_tmp;
52160 + }
52161 +
52162 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52163 + return -ENOMEM;
52164 +
52165 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52166 + return -EFAULT;
52167 +
52168 + r_tmp->hash = ghash;
52169 +
52170 + num_subjs = count_user_subjs(r_tmp->hash->first);
52171 +
52172 + r_tmp->subj_hash_size = num_subjs;
52173 + r_tmp->subj_hash =
52174 + (struct acl_subject_label **)
52175 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52176 +
52177 + if (!r_tmp->subj_hash)
52178 + return -ENOMEM;
52179 +
52180 + err = copy_user_allowedips(r_tmp);
52181 + if (err)
52182 + return err;
52183 +
52184 + /* copy domain info */
52185 + if (r_tmp->domain_children != NULL) {
52186 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52187 + if (domainlist == NULL)
52188 + return -ENOMEM;
52189 +
52190 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52191 + return -EFAULT;
52192 +
52193 + r_tmp->domain_children = domainlist;
52194 + }
52195 +
52196 + err = copy_user_transitions(r_tmp);
52197 + if (err)
52198 + return err;
52199 +
52200 + memset(r_tmp->subj_hash, 0,
52201 + r_tmp->subj_hash_size *
52202 + sizeof (struct acl_subject_label *));
52203 +
52204 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52205 +
52206 + if (err)
52207 + return err;
52208 +
52209 + /* set nested subject list to null */
52210 + r_tmp->hash->first = NULL;
52211 +
52212 + insert_acl_role_label(r_tmp);
52213 + }
52214 +
52215 + if (default_role == NULL || kernel_role == NULL)
52216 + return -EINVAL;
52217 +
52218 + return err;
52219 +}
52220 +
52221 +static int
52222 +gracl_init(struct gr_arg *args)
52223 +{
52224 + int error = 0;
52225 +
52226 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52227 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52228 +
52229 + if (init_variables(args)) {
52230 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52231 + error = -ENOMEM;
52232 + free_variables();
52233 + goto out;
52234 + }
52235 +
52236 + error = copy_user_acl(args);
52237 + free_init_variables();
52238 + if (error) {
52239 + free_variables();
52240 + goto out;
52241 + }
52242 +
52243 + if ((error = gr_set_acls(0))) {
52244 + free_variables();
52245 + goto out;
52246 + }
52247 +
52248 + pax_open_kernel();
52249 + gr_status |= GR_READY;
52250 + pax_close_kernel();
52251 +
52252 + out:
52253 + return error;
52254 +}
52255 +
52256 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52257 +
52258 +static int
52259 +glob_match(const char *p, const char *n)
52260 +{
52261 + char c;
52262 +
52263 + while ((c = *p++) != '\0') {
52264 + switch (c) {
52265 + case '?':
52266 + if (*n == '\0')
52267 + return 1;
52268 + else if (*n == '/')
52269 + return 1;
52270 + break;
52271 + case '\\':
52272 + if (*n != c)
52273 + return 1;
52274 + break;
52275 + case '*':
52276 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52277 + if (*n == '/')
52278 + return 1;
52279 + else if (c == '?') {
52280 + if (*n == '\0')
52281 + return 1;
52282 + else
52283 + ++n;
52284 + }
52285 + }
52286 + if (c == '\0') {
52287 + return 0;
52288 + } else {
52289 + const char *endp;
52290 +
52291 + if ((endp = strchr(n, '/')) == NULL)
52292 + endp = n + strlen(n);
52293 +
52294 + if (c == '[') {
52295 + for (--p; n < endp; ++n)
52296 + if (!glob_match(p, n))
52297 + return 0;
52298 + } else if (c == '/') {
52299 + while (*n != '\0' && *n != '/')
52300 + ++n;
52301 + if (*n == '/' && !glob_match(p, n + 1))
52302 + return 0;
52303 + } else {
52304 + for (--p; n < endp; ++n)
52305 + if (*n == c && !glob_match(p, n))
52306 + return 0;
52307 + }
52308 +
52309 + return 1;
52310 + }
52311 + case '[':
52312 + {
52313 + int not;
52314 + char cold;
52315 +
52316 + if (*n == '\0' || *n == '/')
52317 + return 1;
52318 +
52319 + not = (*p == '!' || *p == '^');
52320 + if (not)
52321 + ++p;
52322 +
52323 + c = *p++;
52324 + for (;;) {
52325 + unsigned char fn = (unsigned char)*n;
52326 +
52327 + if (c == '\0')
52328 + return 1;
52329 + else {
52330 + if (c == fn)
52331 + goto matched;
52332 + cold = c;
52333 + c = *p++;
52334 +
52335 + if (c == '-' && *p != ']') {
52336 + unsigned char cend = *p++;
52337 +
52338 + if (cend == '\0')
52339 + return 1;
52340 +
52341 + if (cold <= fn && fn <= cend)
52342 + goto matched;
52343 +
52344 + c = *p++;
52345 + }
52346 + }
52347 +
52348 + if (c == ']')
52349 + break;
52350 + }
52351 + if (!not)
52352 + return 1;
52353 + break;
52354 + matched:
52355 + while (c != ']') {
52356 + if (c == '\0')
52357 + return 1;
52358 +
52359 + c = *p++;
52360 + }
52361 + if (not)
52362 + return 1;
52363 + }
52364 + break;
52365 + default:
52366 + if (c != *n)
52367 + return 1;
52368 + }
52369 +
52370 + ++n;
52371 + }
52372 +
52373 + if (*n == '\0')
52374 + return 0;
52375 +
52376 + if (*n == '/')
52377 + return 0;
52378 +
52379 + return 1;
52380 +}
52381 +
52382 +static struct acl_object_label *
52383 +chk_glob_label(struct acl_object_label *globbed,
52384 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52385 +{
52386 + struct acl_object_label *tmp;
52387 +
52388 + if (*path == NULL)
52389 + *path = gr_to_filename_nolock(dentry, mnt);
52390 +
52391 + tmp = globbed;
52392 +
52393 + while (tmp) {
52394 + if (!glob_match(tmp->filename, *path))
52395 + return tmp;
52396 + tmp = tmp->next;
52397 + }
52398 +
52399 + return NULL;
52400 +}
52401 +
52402 +static struct acl_object_label *
52403 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52404 + const ino_t curr_ino, const dev_t curr_dev,
52405 + const struct acl_subject_label *subj, char **path, const int checkglob)
52406 +{
52407 + struct acl_subject_label *tmpsubj;
52408 + struct acl_object_label *retval;
52409 + struct acl_object_label *retval2;
52410 +
52411 + tmpsubj = (struct acl_subject_label *) subj;
52412 + read_lock(&gr_inode_lock);
52413 + do {
52414 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52415 + if (retval) {
52416 + if (checkglob && retval->globbed) {
52417 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52418 + if (retval2)
52419 + retval = retval2;
52420 + }
52421 + break;
52422 + }
52423 + } while ((tmpsubj = tmpsubj->parent_subject));
52424 + read_unlock(&gr_inode_lock);
52425 +
52426 + return retval;
52427 +}
52428 +
52429 +static __inline__ struct acl_object_label *
52430 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52431 + struct dentry *curr_dentry,
52432 + const struct acl_subject_label *subj, char **path, const int checkglob)
52433 +{
52434 + int newglob = checkglob;
52435 + ino_t inode;
52436 + dev_t device;
52437 +
52438 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52439 + as we don't want a / * rule to match instead of the / object
52440 + don't do this for create lookups that call this function though, since they're looking up
52441 + on the parent and thus need globbing checks on all paths
52442 + */
52443 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52444 + newglob = GR_NO_GLOB;
52445 +
52446 + spin_lock(&curr_dentry->d_lock);
52447 + inode = curr_dentry->d_inode->i_ino;
52448 + device = __get_dev(curr_dentry);
52449 + spin_unlock(&curr_dentry->d_lock);
52450 +
52451 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52452 +}
52453 +
52454 +static struct acl_object_label *
52455 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52456 + const struct acl_subject_label *subj, char *path, const int checkglob)
52457 +{
52458 + struct dentry *dentry = (struct dentry *) l_dentry;
52459 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52460 + struct mount *real_mnt = real_mount(mnt);
52461 + struct acl_object_label *retval;
52462 + struct dentry *parent;
52463 +
52464 + write_seqlock(&rename_lock);
52465 + br_read_lock(vfsmount_lock);
52466 +
52467 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52468 +#ifdef CONFIG_NET
52469 + mnt == sock_mnt ||
52470 +#endif
52471 +#ifdef CONFIG_HUGETLBFS
52472 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52473 +#endif
52474 + /* ignore Eric Biederman */
52475 + IS_PRIVATE(l_dentry->d_inode))) {
52476 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52477 + goto out;
52478 + }
52479 +
52480 + for (;;) {
52481 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52482 + break;
52483 +
52484 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52485 + if (!mnt_has_parent(real_mnt))
52486 + break;
52487 +
52488 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52489 + if (retval != NULL)
52490 + goto out;
52491 +
52492 + dentry = real_mnt->mnt_mountpoint;
52493 + real_mnt = real_mnt->mnt_parent;
52494 + mnt = &real_mnt->mnt;
52495 + continue;
52496 + }
52497 +
52498 + parent = dentry->d_parent;
52499 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52500 + if (retval != NULL)
52501 + goto out;
52502 +
52503 + dentry = parent;
52504 + }
52505 +
52506 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52507 +
52508 + /* real_root is pinned so we don't have to hold a reference */
52509 + if (retval == NULL)
52510 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52511 +out:
52512 + br_read_unlock(vfsmount_lock);
52513 + write_sequnlock(&rename_lock);
52514 +
52515 + BUG_ON(retval == NULL);
52516 +
52517 + return retval;
52518 +}
52519 +
52520 +static __inline__ struct acl_object_label *
52521 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52522 + const struct acl_subject_label *subj)
52523 +{
52524 + char *path = NULL;
52525 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52526 +}
52527 +
52528 +static __inline__ struct acl_object_label *
52529 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52530 + const struct acl_subject_label *subj)
52531 +{
52532 + char *path = NULL;
52533 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52534 +}
52535 +
52536 +static __inline__ struct acl_object_label *
52537 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52538 + const struct acl_subject_label *subj, char *path)
52539 +{
52540 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52541 +}
52542 +
52543 +static struct acl_subject_label *
52544 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52545 + const struct acl_role_label *role)
52546 +{
52547 + struct dentry *dentry = (struct dentry *) l_dentry;
52548 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52549 + struct mount *real_mnt = real_mount(mnt);
52550 + struct acl_subject_label *retval;
52551 + struct dentry *parent;
52552 +
52553 + write_seqlock(&rename_lock);
52554 + br_read_lock(vfsmount_lock);
52555 +
52556 + for (;;) {
52557 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52558 + break;
52559 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52560 + if (!mnt_has_parent(real_mnt))
52561 + break;
52562 +
52563 + spin_lock(&dentry->d_lock);
52564 + read_lock(&gr_inode_lock);
52565 + retval =
52566 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52567 + __get_dev(dentry), role);
52568 + read_unlock(&gr_inode_lock);
52569 + spin_unlock(&dentry->d_lock);
52570 + if (retval != NULL)
52571 + goto out;
52572 +
52573 + dentry = real_mnt->mnt_mountpoint;
52574 + real_mnt = real_mnt->mnt_parent;
52575 + mnt = &real_mnt->mnt;
52576 + continue;
52577 + }
52578 +
52579 + spin_lock(&dentry->d_lock);
52580 + read_lock(&gr_inode_lock);
52581 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52582 + __get_dev(dentry), role);
52583 + read_unlock(&gr_inode_lock);
52584 + parent = dentry->d_parent;
52585 + spin_unlock(&dentry->d_lock);
52586 +
52587 + if (retval != NULL)
52588 + goto out;
52589 +
52590 + dentry = parent;
52591 + }
52592 +
52593 + spin_lock(&dentry->d_lock);
52594 + read_lock(&gr_inode_lock);
52595 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52596 + __get_dev(dentry), role);
52597 + read_unlock(&gr_inode_lock);
52598 + spin_unlock(&dentry->d_lock);
52599 +
52600 + if (unlikely(retval == NULL)) {
52601 + /* real_root is pinned, we don't need to hold a reference */
52602 + read_lock(&gr_inode_lock);
52603 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52604 + __get_dev(real_root.dentry), role);
52605 + read_unlock(&gr_inode_lock);
52606 + }
52607 +out:
52608 + br_read_unlock(vfsmount_lock);
52609 + write_sequnlock(&rename_lock);
52610 +
52611 + BUG_ON(retval == NULL);
52612 +
52613 + return retval;
52614 +}
52615 +
52616 +static void
52617 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52618 +{
52619 + struct task_struct *task = current;
52620 + const struct cred *cred = current_cred();
52621 +
52622 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52623 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52624 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52625 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52626 +
52627 + return;
52628 +}
52629 +
52630 +static void
52631 +gr_log_learn_sysctl(const char *path, const __u32 mode)
52632 +{
52633 + struct task_struct *task = current;
52634 + const struct cred *cred = current_cred();
52635 +
52636 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52637 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52638 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52639 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52640 +
52641 + return;
52642 +}
52643 +
52644 +static void
52645 +gr_log_learn_id_change(const char type, const unsigned int real,
52646 + const unsigned int effective, const unsigned int fs)
52647 +{
52648 + struct task_struct *task = current;
52649 + const struct cred *cred = current_cred();
52650 +
52651 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52652 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52653 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52654 + type, real, effective, fs, &task->signal->saved_ip);
52655 +
52656 + return;
52657 +}
52658 +
52659 +__u32
52660 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52661 + const struct vfsmount * mnt)
52662 +{
52663 + __u32 retval = mode;
52664 + struct acl_subject_label *curracl;
52665 + struct acl_object_label *currobj;
52666 +
52667 + if (unlikely(!(gr_status & GR_READY)))
52668 + return (mode & ~GR_AUDITS);
52669 +
52670 + curracl = current->acl;
52671 +
52672 + currobj = chk_obj_label(dentry, mnt, curracl);
52673 + retval = currobj->mode & mode;
52674 +
52675 + /* if we're opening a specified transfer file for writing
52676 + (e.g. /dev/initctl), then transfer our role to init
52677 + */
52678 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52679 + current->role->roletype & GR_ROLE_PERSIST)) {
52680 + struct task_struct *task = init_pid_ns.child_reaper;
52681 +
52682 + if (task->role != current->role) {
52683 + task->acl_sp_role = 0;
52684 + task->acl_role_id = current->acl_role_id;
52685 + task->role = current->role;
52686 + rcu_read_lock();
52687 + read_lock(&grsec_exec_file_lock);
52688 + gr_apply_subject_to_task(task);
52689 + read_unlock(&grsec_exec_file_lock);
52690 + rcu_read_unlock();
52691 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52692 + }
52693 + }
52694 +
52695 + if (unlikely
52696 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52697 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52698 + __u32 new_mode = mode;
52699 +
52700 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52701 +
52702 + retval = new_mode;
52703 +
52704 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52705 + new_mode |= GR_INHERIT;
52706 +
52707 + if (!(mode & GR_NOLEARN))
52708 + gr_log_learn(dentry, mnt, new_mode);
52709 + }
52710 +
52711 + return retval;
52712 +}
52713 +
52714 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52715 + const struct dentry *parent,
52716 + const struct vfsmount *mnt)
52717 +{
52718 + struct name_entry *match;
52719 + struct acl_object_label *matchpo;
52720 + struct acl_subject_label *curracl;
52721 + char *path;
52722 +
52723 + if (unlikely(!(gr_status & GR_READY)))
52724 + return NULL;
52725 +
52726 + preempt_disable();
52727 + path = gr_to_filename_rbac(new_dentry, mnt);
52728 + match = lookup_name_entry_create(path);
52729 +
52730 + curracl = current->acl;
52731 +
52732 + if (match) {
52733 + read_lock(&gr_inode_lock);
52734 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52735 + read_unlock(&gr_inode_lock);
52736 +
52737 + if (matchpo) {
52738 + preempt_enable();
52739 + return matchpo;
52740 + }
52741 + }
52742 +
52743 + // lookup parent
52744 +
52745 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52746 +
52747 + preempt_enable();
52748 + return matchpo;
52749 +}
52750 +
52751 +__u32
52752 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52753 + const struct vfsmount * mnt, const __u32 mode)
52754 +{
52755 + struct acl_object_label *matchpo;
52756 + __u32 retval;
52757 +
52758 + if (unlikely(!(gr_status & GR_READY)))
52759 + return (mode & ~GR_AUDITS);
52760 +
52761 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52762 +
52763 + retval = matchpo->mode & mode;
52764 +
52765 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52766 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52767 + __u32 new_mode = mode;
52768 +
52769 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52770 +
52771 + gr_log_learn(new_dentry, mnt, new_mode);
52772 + return new_mode;
52773 + }
52774 +
52775 + return retval;
52776 +}
52777 +
52778 +__u32
52779 +gr_check_link(const struct dentry * new_dentry,
52780 + const struct dentry * parent_dentry,
52781 + const struct vfsmount * parent_mnt,
52782 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52783 +{
52784 + struct acl_object_label *obj;
52785 + __u32 oldmode, newmode;
52786 + __u32 needmode;
52787 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52788 + GR_DELETE | GR_INHERIT;
52789 +
52790 + if (unlikely(!(gr_status & GR_READY)))
52791 + return (GR_CREATE | GR_LINK);
52792 +
52793 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52794 + oldmode = obj->mode;
52795 +
52796 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52797 + newmode = obj->mode;
52798 +
52799 + needmode = newmode & checkmodes;
52800 +
52801 + // old name for hardlink must have at least the permissions of the new name
52802 + if ((oldmode & needmode) != needmode)
52803 + goto bad;
52804 +
52805 + // if old name had restrictions/auditing, make sure the new name does as well
52806 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52807 +
52808 + // don't allow hardlinking of suid/sgid files without permission
52809 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52810 + needmode |= GR_SETID;
52811 +
52812 + if ((newmode & needmode) != needmode)
52813 + goto bad;
52814 +
52815 + // enforce minimum permissions
52816 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52817 + return newmode;
52818 +bad:
52819 + needmode = oldmode;
52820 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52821 + needmode |= GR_SETID;
52822 +
52823 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52824 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52825 + return (GR_CREATE | GR_LINK);
52826 + } else if (newmode & GR_SUPPRESS)
52827 + return GR_SUPPRESS;
52828 + else
52829 + return 0;
52830 +}
52831 +
52832 +int
52833 +gr_check_hidden_task(const struct task_struct *task)
52834 +{
52835 + if (unlikely(!(gr_status & GR_READY)))
52836 + return 0;
52837 +
52838 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52839 + return 1;
52840 +
52841 + return 0;
52842 +}
52843 +
52844 +int
52845 +gr_check_protected_task(const struct task_struct *task)
52846 +{
52847 + if (unlikely(!(gr_status & GR_READY) || !task))
52848 + return 0;
52849 +
52850 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52851 + task->acl != current->acl)
52852 + return 1;
52853 +
52854 + return 0;
52855 +}
52856 +
52857 +int
52858 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52859 +{
52860 + struct task_struct *p;
52861 + int ret = 0;
52862 +
52863 + if (unlikely(!(gr_status & GR_READY) || !pid))
52864 + return ret;
52865 +
52866 + read_lock(&tasklist_lock);
52867 + do_each_pid_task(pid, type, p) {
52868 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52869 + p->acl != current->acl) {
52870 + ret = 1;
52871 + goto out;
52872 + }
52873 + } while_each_pid_task(pid, type, p);
52874 +out:
52875 + read_unlock(&tasklist_lock);
52876 +
52877 + return ret;
52878 +}
52879 +
52880 +void
52881 +gr_copy_label(struct task_struct *tsk)
52882 +{
52883 + /* plain copying of fields is already done by dup_task_struct */
52884 + tsk->signal->used_accept = 0;
52885 + tsk->acl_sp_role = 0;
52886 + //tsk->acl_role_id = current->acl_role_id;
52887 + //tsk->acl = current->acl;
52888 + //tsk->role = current->role;
52889 + tsk->signal->curr_ip = current->signal->curr_ip;
52890 + tsk->signal->saved_ip = current->signal->saved_ip;
52891 + if (current->exec_file)
52892 + get_file(current->exec_file);
52893 + //tsk->exec_file = current->exec_file;
52894 + //tsk->is_writable = current->is_writable;
52895 + if (unlikely(current->signal->used_accept)) {
52896 + current->signal->curr_ip = 0;
52897 + current->signal->saved_ip = 0;
52898 + }
52899 +
52900 + return;
52901 +}
52902 +
52903 +static void
52904 +gr_set_proc_res(struct task_struct *task)
52905 +{
52906 + struct acl_subject_label *proc;
52907 + unsigned short i;
52908 +
52909 + proc = task->acl;
52910 +
52911 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52912 + return;
52913 +
52914 + for (i = 0; i < RLIM_NLIMITS; i++) {
52915 + if (!(proc->resmask & (1 << i)))
52916 + continue;
52917 +
52918 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52919 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52920 + }
52921 +
52922 + return;
52923 +}
52924 +
52925 +extern int __gr_process_user_ban(struct user_struct *user);
52926 +
52927 +int
52928 +gr_check_user_change(int real, int effective, int fs)
52929 +{
52930 + unsigned int i;
52931 + __u16 num;
52932 + uid_t *uidlist;
52933 + int curuid;
52934 + int realok = 0;
52935 + int effectiveok = 0;
52936 + int fsok = 0;
52937 +
52938 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52939 + struct user_struct *user;
52940 +
52941 + if (real == -1)
52942 + goto skipit;
52943 +
52944 + user = find_user(real);
52945 + if (user == NULL)
52946 + goto skipit;
52947 +
52948 + if (__gr_process_user_ban(user)) {
52949 + /* for find_user */
52950 + free_uid(user);
52951 + return 1;
52952 + }
52953 +
52954 + /* for find_user */
52955 + free_uid(user);
52956 +
52957 +skipit:
52958 +#endif
52959 +
52960 + if (unlikely(!(gr_status & GR_READY)))
52961 + return 0;
52962 +
52963 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52964 + gr_log_learn_id_change('u', real, effective, fs);
52965 +
52966 + num = current->acl->user_trans_num;
52967 + uidlist = current->acl->user_transitions;
52968 +
52969 + if (uidlist == NULL)
52970 + return 0;
52971 +
52972 + if (real == -1)
52973 + realok = 1;
52974 + if (effective == -1)
52975 + effectiveok = 1;
52976 + if (fs == -1)
52977 + fsok = 1;
52978 +
52979 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52980 + for (i = 0; i < num; i++) {
52981 + curuid = (int)uidlist[i];
52982 + if (real == curuid)
52983 + realok = 1;
52984 + if (effective == curuid)
52985 + effectiveok = 1;
52986 + if (fs == curuid)
52987 + fsok = 1;
52988 + }
52989 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52990 + for (i = 0; i < num; i++) {
52991 + curuid = (int)uidlist[i];
52992 + if (real == curuid)
52993 + break;
52994 + if (effective == curuid)
52995 + break;
52996 + if (fs == curuid)
52997 + break;
52998 + }
52999 + /* not in deny list */
53000 + if (i == num) {
53001 + realok = 1;
53002 + effectiveok = 1;
53003 + fsok = 1;
53004 + }
53005 + }
53006 +
53007 + if (realok && effectiveok && fsok)
53008 + return 0;
53009 + else {
53010 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53011 + return 1;
53012 + }
53013 +}
53014 +
53015 +int
53016 +gr_check_group_change(int real, int effective, int fs)
53017 +{
53018 + unsigned int i;
53019 + __u16 num;
53020 + gid_t *gidlist;
53021 + int curgid;
53022 + int realok = 0;
53023 + int effectiveok = 0;
53024 + int fsok = 0;
53025 +
53026 + if (unlikely(!(gr_status & GR_READY)))
53027 + return 0;
53028 +
53029 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53030 + gr_log_learn_id_change('g', real, effective, fs);
53031 +
53032 + num = current->acl->group_trans_num;
53033 + gidlist = current->acl->group_transitions;
53034 +
53035 + if (gidlist == NULL)
53036 + return 0;
53037 +
53038 + if (real == -1)
53039 + realok = 1;
53040 + if (effective == -1)
53041 + effectiveok = 1;
53042 + if (fs == -1)
53043 + fsok = 1;
53044 +
53045 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53046 + for (i = 0; i < num; i++) {
53047 + curgid = (int)gidlist[i];
53048 + if (real == curgid)
53049 + realok = 1;
53050 + if (effective == curgid)
53051 + effectiveok = 1;
53052 + if (fs == curgid)
53053 + fsok = 1;
53054 + }
53055 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53056 + for (i = 0; i < num; i++) {
53057 + curgid = (int)gidlist[i];
53058 + if (real == curgid)
53059 + break;
53060 + if (effective == curgid)
53061 + break;
53062 + if (fs == curgid)
53063 + break;
53064 + }
53065 + /* not in deny list */
53066 + if (i == num) {
53067 + realok = 1;
53068 + effectiveok = 1;
53069 + fsok = 1;
53070 + }
53071 + }
53072 +
53073 + if (realok && effectiveok && fsok)
53074 + return 0;
53075 + else {
53076 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53077 + return 1;
53078 + }
53079 +}
53080 +
53081 +extern int gr_acl_is_capable(const int cap);
53082 +
53083 +void
53084 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53085 +{
53086 + struct acl_role_label *role = task->role;
53087 + struct acl_subject_label *subj = NULL;
53088 + struct acl_object_label *obj;
53089 + struct file *filp;
53090 +
53091 + if (unlikely(!(gr_status & GR_READY)))
53092 + return;
53093 +
53094 + filp = task->exec_file;
53095 +
53096 + /* kernel process, we'll give them the kernel role */
53097 + if (unlikely(!filp)) {
53098 + task->role = kernel_role;
53099 + task->acl = kernel_role->root_label;
53100 + return;
53101 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53102 + role = lookup_acl_role_label(task, uid, gid);
53103 +
53104 + /* don't change the role if we're not a privileged process */
53105 + if (role && task->role != role &&
53106 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53107 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53108 + return;
53109 +
53110 + /* perform subject lookup in possibly new role
53111 + we can use this result below in the case where role == task->role
53112 + */
53113 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53114 +
53115 + /* if we changed uid/gid, but result in the same role
53116 + and are using inheritance, don't lose the inherited subject
53117 + if current subject is other than what normal lookup
53118 + would result in, we arrived via inheritance, don't
53119 + lose subject
53120 + */
53121 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53122 + (subj == task->acl)))
53123 + task->acl = subj;
53124 +
53125 + task->role = role;
53126 +
53127 + task->is_writable = 0;
53128 +
53129 + /* ignore additional mmap checks for processes that are writable
53130 + by the default ACL */
53131 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53132 + if (unlikely(obj->mode & GR_WRITE))
53133 + task->is_writable = 1;
53134 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53135 + if (unlikely(obj->mode & GR_WRITE))
53136 + task->is_writable = 1;
53137 +
53138 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53139 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53140 +#endif
53141 +
53142 + gr_set_proc_res(task);
53143 +
53144 + return;
53145 +}
53146 +
53147 +int
53148 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53149 + const int unsafe_flags)
53150 +{
53151 + struct task_struct *task = current;
53152 + struct acl_subject_label *newacl;
53153 + struct acl_object_label *obj;
53154 + __u32 retmode;
53155 +
53156 + if (unlikely(!(gr_status & GR_READY)))
53157 + return 0;
53158 +
53159 + newacl = chk_subj_label(dentry, mnt, task->role);
53160 +
53161 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53162 + did an exec
53163 + */
53164 + rcu_read_lock();
53165 + read_lock(&tasklist_lock);
53166 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53167 + (task->parent->acl->mode & GR_POVERRIDE))) {
53168 + read_unlock(&tasklist_lock);
53169 + rcu_read_unlock();
53170 + goto skip_check;
53171 + }
53172 + read_unlock(&tasklist_lock);
53173 + rcu_read_unlock();
53174 +
53175 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53176 + !(task->role->roletype & GR_ROLE_GOD) &&
53177 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53178 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53179 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53180 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53181 + else
53182 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53183 + return -EACCES;
53184 + }
53185 +
53186 +skip_check:
53187 +
53188 + obj = chk_obj_label(dentry, mnt, task->acl);
53189 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53190 +
53191 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53192 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53193 + if (obj->nested)
53194 + task->acl = obj->nested;
53195 + else
53196 + task->acl = newacl;
53197 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53198 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53199 +
53200 + task->is_writable = 0;
53201 +
53202 + /* ignore additional mmap checks for processes that are writable
53203 + by the default ACL */
53204 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53205 + if (unlikely(obj->mode & GR_WRITE))
53206 + task->is_writable = 1;
53207 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53208 + if (unlikely(obj->mode & GR_WRITE))
53209 + task->is_writable = 1;
53210 +
53211 + gr_set_proc_res(task);
53212 +
53213 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53214 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53215 +#endif
53216 + return 0;
53217 +}
53218 +
53219 +/* always called with valid inodev ptr */
53220 +static void
53221 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53222 +{
53223 + struct acl_object_label *matchpo;
53224 + struct acl_subject_label *matchps;
53225 + struct acl_subject_label *subj;
53226 + struct acl_role_label *role;
53227 + unsigned int x;
53228 +
53229 + FOR_EACH_ROLE_START(role)
53230 + FOR_EACH_SUBJECT_START(role, subj, x)
53231 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53232 + matchpo->mode |= GR_DELETED;
53233 + FOR_EACH_SUBJECT_END(subj,x)
53234 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53235 + if (subj->inode == ino && subj->device == dev)
53236 + subj->mode |= GR_DELETED;
53237 + FOR_EACH_NESTED_SUBJECT_END(subj)
53238 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53239 + matchps->mode |= GR_DELETED;
53240 + FOR_EACH_ROLE_END(role)
53241 +
53242 + inodev->nentry->deleted = 1;
53243 +
53244 + return;
53245 +}
53246 +
53247 +void
53248 +gr_handle_delete(const ino_t ino, const dev_t dev)
53249 +{
53250 + struct inodev_entry *inodev;
53251 +
53252 + if (unlikely(!(gr_status & GR_READY)))
53253 + return;
53254 +
53255 + write_lock(&gr_inode_lock);
53256 + inodev = lookup_inodev_entry(ino, dev);
53257 + if (inodev != NULL)
53258 + do_handle_delete(inodev, ino, dev);
53259 + write_unlock(&gr_inode_lock);
53260 +
53261 + return;
53262 +}
53263 +
53264 +static void
53265 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53266 + const ino_t newinode, const dev_t newdevice,
53267 + struct acl_subject_label *subj)
53268 +{
53269 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53270 + struct acl_object_label *match;
53271 +
53272 + match = subj->obj_hash[index];
53273 +
53274 + while (match && (match->inode != oldinode ||
53275 + match->device != olddevice ||
53276 + !(match->mode & GR_DELETED)))
53277 + match = match->next;
53278 +
53279 + if (match && (match->inode == oldinode)
53280 + && (match->device == olddevice)
53281 + && (match->mode & GR_DELETED)) {
53282 + if (match->prev == NULL) {
53283 + subj->obj_hash[index] = match->next;
53284 + if (match->next != NULL)
53285 + match->next->prev = NULL;
53286 + } else {
53287 + match->prev->next = match->next;
53288 + if (match->next != NULL)
53289 + match->next->prev = match->prev;
53290 + }
53291 + match->prev = NULL;
53292 + match->next = NULL;
53293 + match->inode = newinode;
53294 + match->device = newdevice;
53295 + match->mode &= ~GR_DELETED;
53296 +
53297 + insert_acl_obj_label(match, subj);
53298 + }
53299 +
53300 + return;
53301 +}
53302 +
53303 +static void
53304 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53305 + const ino_t newinode, const dev_t newdevice,
53306 + struct acl_role_label *role)
53307 +{
53308 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53309 + struct acl_subject_label *match;
53310 +
53311 + match = role->subj_hash[index];
53312 +
53313 + while (match && (match->inode != oldinode ||
53314 + match->device != olddevice ||
53315 + !(match->mode & GR_DELETED)))
53316 + match = match->next;
53317 +
53318 + if (match && (match->inode == oldinode)
53319 + && (match->device == olddevice)
53320 + && (match->mode & GR_DELETED)) {
53321 + if (match->prev == NULL) {
53322 + role->subj_hash[index] = match->next;
53323 + if (match->next != NULL)
53324 + match->next->prev = NULL;
53325 + } else {
53326 + match->prev->next = match->next;
53327 + if (match->next != NULL)
53328 + match->next->prev = match->prev;
53329 + }
53330 + match->prev = NULL;
53331 + match->next = NULL;
53332 + match->inode = newinode;
53333 + match->device = newdevice;
53334 + match->mode &= ~GR_DELETED;
53335 +
53336 + insert_acl_subj_label(match, role);
53337 + }
53338 +
53339 + return;
53340 +}
53341 +
53342 +static void
53343 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53344 + const ino_t newinode, const dev_t newdevice)
53345 +{
53346 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53347 + struct inodev_entry *match;
53348 +
53349 + match = inodev_set.i_hash[index];
53350 +
53351 + while (match && (match->nentry->inode != oldinode ||
53352 + match->nentry->device != olddevice || !match->nentry->deleted))
53353 + match = match->next;
53354 +
53355 + if (match && (match->nentry->inode == oldinode)
53356 + && (match->nentry->device == olddevice) &&
53357 + match->nentry->deleted) {
53358 + if (match->prev == NULL) {
53359 + inodev_set.i_hash[index] = match->next;
53360 + if (match->next != NULL)
53361 + match->next->prev = NULL;
53362 + } else {
53363 + match->prev->next = match->next;
53364 + if (match->next != NULL)
53365 + match->next->prev = match->prev;
53366 + }
53367 + match->prev = NULL;
53368 + match->next = NULL;
53369 + match->nentry->inode = newinode;
53370 + match->nentry->device = newdevice;
53371 + match->nentry->deleted = 0;
53372 +
53373 + insert_inodev_entry(match);
53374 + }
53375 +
53376 + return;
53377 +}
53378 +
53379 +static void
53380 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53381 +{
53382 + struct acl_subject_label *subj;
53383 + struct acl_role_label *role;
53384 + unsigned int x;
53385 +
53386 + FOR_EACH_ROLE_START(role)
53387 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53388 +
53389 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53390 + if ((subj->inode == ino) && (subj->device == dev)) {
53391 + subj->inode = ino;
53392 + subj->device = dev;
53393 + }
53394 + FOR_EACH_NESTED_SUBJECT_END(subj)
53395 + FOR_EACH_SUBJECT_START(role, subj, x)
53396 + update_acl_obj_label(matchn->inode, matchn->device,
53397 + ino, dev, subj);
53398 + FOR_EACH_SUBJECT_END(subj,x)
53399 + FOR_EACH_ROLE_END(role)
53400 +
53401 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53402 +
53403 + return;
53404 +}
53405 +
53406 +static void
53407 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53408 + const struct vfsmount *mnt)
53409 +{
53410 + ino_t ino = dentry->d_inode->i_ino;
53411 + dev_t dev = __get_dev(dentry);
53412 +
53413 + __do_handle_create(matchn, ino, dev);
53414 +
53415 + return;
53416 +}
53417 +
53418 +void
53419 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53420 +{
53421 + struct name_entry *matchn;
53422 +
53423 + if (unlikely(!(gr_status & GR_READY)))
53424 + return;
53425 +
53426 + preempt_disable();
53427 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53428 +
53429 + if (unlikely((unsigned long)matchn)) {
53430 + write_lock(&gr_inode_lock);
53431 + do_handle_create(matchn, dentry, mnt);
53432 + write_unlock(&gr_inode_lock);
53433 + }
53434 + preempt_enable();
53435 +
53436 + return;
53437 +}
53438 +
53439 +void
53440 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53441 +{
53442 + struct name_entry *matchn;
53443 +
53444 + if (unlikely(!(gr_status & GR_READY)))
53445 + return;
53446 +
53447 + preempt_disable();
53448 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53449 +
53450 + if (unlikely((unsigned long)matchn)) {
53451 + write_lock(&gr_inode_lock);
53452 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53453 + write_unlock(&gr_inode_lock);
53454 + }
53455 + preempt_enable();
53456 +
53457 + return;
53458 +}
53459 +
53460 +void
53461 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53462 + struct dentry *old_dentry,
53463 + struct dentry *new_dentry,
53464 + struct vfsmount *mnt, const __u8 replace)
53465 +{
53466 + struct name_entry *matchn;
53467 + struct inodev_entry *inodev;
53468 + struct inode *inode = new_dentry->d_inode;
53469 + ino_t old_ino = old_dentry->d_inode->i_ino;
53470 + dev_t old_dev = __get_dev(old_dentry);
53471 +
53472 + /* vfs_rename swaps the name and parent link for old_dentry and
53473 + new_dentry
53474 + at this point, old_dentry has the new name, parent link, and inode
53475 + for the renamed file
53476 + if a file is being replaced by a rename, new_dentry has the inode
53477 + and name for the replaced file
53478 + */
53479 +
53480 + if (unlikely(!(gr_status & GR_READY)))
53481 + return;
53482 +
53483 + preempt_disable();
53484 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53485 +
53486 + /* we wouldn't have to check d_inode if it weren't for
53487 + NFS silly-renaming
53488 + */
53489 +
53490 + write_lock(&gr_inode_lock);
53491 + if (unlikely(replace && inode)) {
53492 + ino_t new_ino = inode->i_ino;
53493 + dev_t new_dev = __get_dev(new_dentry);
53494 +
53495 + inodev = lookup_inodev_entry(new_ino, new_dev);
53496 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53497 + do_handle_delete(inodev, new_ino, new_dev);
53498 + }
53499 +
53500 + inodev = lookup_inodev_entry(old_ino, old_dev);
53501 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53502 + do_handle_delete(inodev, old_ino, old_dev);
53503 +
53504 + if (unlikely((unsigned long)matchn))
53505 + do_handle_create(matchn, old_dentry, mnt);
53506 +
53507 + write_unlock(&gr_inode_lock);
53508 + preempt_enable();
53509 +
53510 + return;
53511 +}
53512 +
53513 +static int
53514 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53515 + unsigned char **sum)
53516 +{
53517 + struct acl_role_label *r;
53518 + struct role_allowed_ip *ipp;
53519 + struct role_transition *trans;
53520 + unsigned int i;
53521 + int found = 0;
53522 + u32 curr_ip = current->signal->curr_ip;
53523 +
53524 + current->signal->saved_ip = curr_ip;
53525 +
53526 + /* check transition table */
53527 +
53528 + for (trans = current->role->transitions; trans; trans = trans->next) {
53529 + if (!strcmp(rolename, trans->rolename)) {
53530 + found = 1;
53531 + break;
53532 + }
53533 + }
53534 +
53535 + if (!found)
53536 + return 0;
53537 +
53538 + /* handle special roles that do not require authentication
53539 + and check ip */
53540 +
53541 + FOR_EACH_ROLE_START(r)
53542 + if (!strcmp(rolename, r->rolename) &&
53543 + (r->roletype & GR_ROLE_SPECIAL)) {
53544 + found = 0;
53545 + if (r->allowed_ips != NULL) {
53546 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53547 + if ((ntohl(curr_ip) & ipp->netmask) ==
53548 + (ntohl(ipp->addr) & ipp->netmask))
53549 + found = 1;
53550 + }
53551 + } else
53552 + found = 2;
53553 + if (!found)
53554 + return 0;
53555 +
53556 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53557 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53558 + *salt = NULL;
53559 + *sum = NULL;
53560 + return 1;
53561 + }
53562 + }
53563 + FOR_EACH_ROLE_END(r)
53564 +
53565 + for (i = 0; i < num_sprole_pws; i++) {
53566 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53567 + *salt = acl_special_roles[i]->salt;
53568 + *sum = acl_special_roles[i]->sum;
53569 + return 1;
53570 + }
53571 + }
53572 +
53573 + return 0;
53574 +}
53575 +
53576 +static void
53577 +assign_special_role(char *rolename)
53578 +{
53579 + struct acl_object_label *obj;
53580 + struct acl_role_label *r;
53581 + struct acl_role_label *assigned = NULL;
53582 + struct task_struct *tsk;
53583 + struct file *filp;
53584 +
53585 + FOR_EACH_ROLE_START(r)
53586 + if (!strcmp(rolename, r->rolename) &&
53587 + (r->roletype & GR_ROLE_SPECIAL)) {
53588 + assigned = r;
53589 + break;
53590 + }
53591 + FOR_EACH_ROLE_END(r)
53592 +
53593 + if (!assigned)
53594 + return;
53595 +
53596 + read_lock(&tasklist_lock);
53597 + read_lock(&grsec_exec_file_lock);
53598 +
53599 + tsk = current->real_parent;
53600 + if (tsk == NULL)
53601 + goto out_unlock;
53602 +
53603 + filp = tsk->exec_file;
53604 + if (filp == NULL)
53605 + goto out_unlock;
53606 +
53607 + tsk->is_writable = 0;
53608 +
53609 + tsk->acl_sp_role = 1;
53610 + tsk->acl_role_id = ++acl_sp_role_value;
53611 + tsk->role = assigned;
53612 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53613 +
53614 + /* ignore additional mmap checks for processes that are writable
53615 + by the default ACL */
53616 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53617 + if (unlikely(obj->mode & GR_WRITE))
53618 + tsk->is_writable = 1;
53619 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53620 + if (unlikely(obj->mode & GR_WRITE))
53621 + tsk->is_writable = 1;
53622 +
53623 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53624 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53625 +#endif
53626 +
53627 +out_unlock:
53628 + read_unlock(&grsec_exec_file_lock);
53629 + read_unlock(&tasklist_lock);
53630 + return;
53631 +}
53632 +
53633 +int gr_check_secure_terminal(struct task_struct *task)
53634 +{
53635 + struct task_struct *p, *p2, *p3;
53636 + struct files_struct *files;
53637 + struct fdtable *fdt;
53638 + struct file *our_file = NULL, *file;
53639 + int i;
53640 +
53641 + if (task->signal->tty == NULL)
53642 + return 1;
53643 +
53644 + files = get_files_struct(task);
53645 + if (files != NULL) {
53646 + rcu_read_lock();
53647 + fdt = files_fdtable(files);
53648 + for (i=0; i < fdt->max_fds; i++) {
53649 + file = fcheck_files(files, i);
53650 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53651 + get_file(file);
53652 + our_file = file;
53653 + }
53654 + }
53655 + rcu_read_unlock();
53656 + put_files_struct(files);
53657 + }
53658 +
53659 + if (our_file == NULL)
53660 + return 1;
53661 +
53662 + read_lock(&tasklist_lock);
53663 + do_each_thread(p2, p) {
53664 + files = get_files_struct(p);
53665 + if (files == NULL ||
53666 + (p->signal && p->signal->tty == task->signal->tty)) {
53667 + if (files != NULL)
53668 + put_files_struct(files);
53669 + continue;
53670 + }
53671 + rcu_read_lock();
53672 + fdt = files_fdtable(files);
53673 + for (i=0; i < fdt->max_fds; i++) {
53674 + file = fcheck_files(files, i);
53675 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53676 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53677 + p3 = task;
53678 + while (p3->pid > 0) {
53679 + if (p3 == p)
53680 + break;
53681 + p3 = p3->real_parent;
53682 + }
53683 + if (p3 == p)
53684 + break;
53685 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53686 + gr_handle_alertkill(p);
53687 + rcu_read_unlock();
53688 + put_files_struct(files);
53689 + read_unlock(&tasklist_lock);
53690 + fput(our_file);
53691 + return 0;
53692 + }
53693 + }
53694 + rcu_read_unlock();
53695 + put_files_struct(files);
53696 + } while_each_thread(p2, p);
53697 + read_unlock(&tasklist_lock);
53698 +
53699 + fput(our_file);
53700 + return 1;
53701 +}
53702 +
53703 +ssize_t
53704 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53705 +{
53706 + struct gr_arg_wrapper uwrap;
53707 + unsigned char *sprole_salt = NULL;
53708 + unsigned char *sprole_sum = NULL;
53709 + int error = sizeof (struct gr_arg_wrapper);
53710 + int error2 = 0;
53711 +
53712 + mutex_lock(&gr_dev_mutex);
53713 +
53714 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53715 + error = -EPERM;
53716 + goto out;
53717 + }
53718 +
53719 + if (count != sizeof (struct gr_arg_wrapper)) {
53720 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53721 + error = -EINVAL;
53722 + goto out;
53723 + }
53724 +
53725 +
53726 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53727 + gr_auth_expires = 0;
53728 + gr_auth_attempts = 0;
53729 + }
53730 +
53731 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53732 + error = -EFAULT;
53733 + goto out;
53734 + }
53735 +
53736 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53737 + error = -EINVAL;
53738 + goto out;
53739 + }
53740 +
53741 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53742 + error = -EFAULT;
53743 + goto out;
53744 + }
53745 +
53746 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53747 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53748 + time_after(gr_auth_expires, get_seconds())) {
53749 + error = -EBUSY;
53750 + goto out;
53751 + }
53752 +
53753 + /* if non-root trying to do anything other than use a special role,
53754 + do not attempt authentication, do not count towards authentication
53755 + locking
53756 + */
53757 +
53758 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53759 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53760 + current_uid()) {
53761 + error = -EPERM;
53762 + goto out;
53763 + }
53764 +
53765 + /* ensure pw and special role name are null terminated */
53766 +
53767 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53768 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53769 +
53770 + /* Okay.
53771 + * We have our enough of the argument structure..(we have yet
53772 + * to copy_from_user the tables themselves) . Copy the tables
53773 + * only if we need them, i.e. for loading operations. */
53774 +
53775 + switch (gr_usermode->mode) {
53776 + case GR_STATUS:
53777 + if (gr_status & GR_READY) {
53778 + error = 1;
53779 + if (!gr_check_secure_terminal(current))
53780 + error = 3;
53781 + } else
53782 + error = 2;
53783 + goto out;
53784 + case GR_SHUTDOWN:
53785 + if ((gr_status & GR_READY)
53786 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53787 + pax_open_kernel();
53788 + gr_status &= ~GR_READY;
53789 + pax_close_kernel();
53790 +
53791 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53792 + free_variables();
53793 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53794 + memset(gr_system_salt, 0, GR_SALT_LEN);
53795 + memset(gr_system_sum, 0, GR_SHA_LEN);
53796 + } else if (gr_status & GR_READY) {
53797 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53798 + error = -EPERM;
53799 + } else {
53800 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53801 + error = -EAGAIN;
53802 + }
53803 + break;
53804 + case GR_ENABLE:
53805 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53806 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53807 + else {
53808 + if (gr_status & GR_READY)
53809 + error = -EAGAIN;
53810 + else
53811 + error = error2;
53812 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53813 + }
53814 + break;
53815 + case GR_RELOAD:
53816 + if (!(gr_status & GR_READY)) {
53817 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53818 + error = -EAGAIN;
53819 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53820 + preempt_disable();
53821 +
53822 + pax_open_kernel();
53823 + gr_status &= ~GR_READY;
53824 + pax_close_kernel();
53825 +
53826 + free_variables();
53827 + if (!(error2 = gracl_init(gr_usermode))) {
53828 + preempt_enable();
53829 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53830 + } else {
53831 + preempt_enable();
53832 + error = error2;
53833 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53834 + }
53835 + } else {
53836 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53837 + error = -EPERM;
53838 + }
53839 + break;
53840 + case GR_SEGVMOD:
53841 + if (unlikely(!(gr_status & GR_READY))) {
53842 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53843 + error = -EAGAIN;
53844 + break;
53845 + }
53846 +
53847 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53848 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53849 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53850 + struct acl_subject_label *segvacl;
53851 + segvacl =
53852 + lookup_acl_subj_label(gr_usermode->segv_inode,
53853 + gr_usermode->segv_device,
53854 + current->role);
53855 + if (segvacl) {
53856 + segvacl->crashes = 0;
53857 + segvacl->expires = 0;
53858 + }
53859 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53860 + gr_remove_uid(gr_usermode->segv_uid);
53861 + }
53862 + } else {
53863 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53864 + error = -EPERM;
53865 + }
53866 + break;
53867 + case GR_SPROLE:
53868 + case GR_SPROLEPAM:
53869 + if (unlikely(!(gr_status & GR_READY))) {
53870 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53871 + error = -EAGAIN;
53872 + break;
53873 + }
53874 +
53875 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53876 + current->role->expires = 0;
53877 + current->role->auth_attempts = 0;
53878 + }
53879 +
53880 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53881 + time_after(current->role->expires, get_seconds())) {
53882 + error = -EBUSY;
53883 + goto out;
53884 + }
53885 +
53886 + if (lookup_special_role_auth
53887 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53888 + && ((!sprole_salt && !sprole_sum)
53889 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53890 + char *p = "";
53891 + assign_special_role(gr_usermode->sp_role);
53892 + read_lock(&tasklist_lock);
53893 + if (current->real_parent)
53894 + p = current->real_parent->role->rolename;
53895 + read_unlock(&tasklist_lock);
53896 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53897 + p, acl_sp_role_value);
53898 + } else {
53899 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53900 + error = -EPERM;
53901 + if(!(current->role->auth_attempts++))
53902 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53903 +
53904 + goto out;
53905 + }
53906 + break;
53907 + case GR_UNSPROLE:
53908 + if (unlikely(!(gr_status & GR_READY))) {
53909 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53910 + error = -EAGAIN;
53911 + break;
53912 + }
53913 +
53914 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53915 + char *p = "";
53916 + int i = 0;
53917 +
53918 + read_lock(&tasklist_lock);
53919 + if (current->real_parent) {
53920 + p = current->real_parent->role->rolename;
53921 + i = current->real_parent->acl_role_id;
53922 + }
53923 + read_unlock(&tasklist_lock);
53924 +
53925 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53926 + gr_set_acls(1);
53927 + } else {
53928 + error = -EPERM;
53929 + goto out;
53930 + }
53931 + break;
53932 + default:
53933 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53934 + error = -EINVAL;
53935 + break;
53936 + }
53937 +
53938 + if (error != -EPERM)
53939 + goto out;
53940 +
53941 + if(!(gr_auth_attempts++))
53942 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53943 +
53944 + out:
53945 + mutex_unlock(&gr_dev_mutex);
53946 + return error;
53947 +}
53948 +
53949 +/* must be called with
53950 + rcu_read_lock();
53951 + read_lock(&tasklist_lock);
53952 + read_lock(&grsec_exec_file_lock);
53953 +*/
53954 +int gr_apply_subject_to_task(struct task_struct *task)
53955 +{
53956 + struct acl_object_label *obj;
53957 + char *tmpname;
53958 + struct acl_subject_label *tmpsubj;
53959 + struct file *filp;
53960 + struct name_entry *nmatch;
53961 +
53962 + filp = task->exec_file;
53963 + if (filp == NULL)
53964 + return 0;
53965 +
53966 + /* the following is to apply the correct subject
53967 + on binaries running when the RBAC system
53968 + is enabled, when the binaries have been
53969 + replaced or deleted since their execution
53970 + -----
53971 + when the RBAC system starts, the inode/dev
53972 + from exec_file will be one the RBAC system
53973 + is unaware of. It only knows the inode/dev
53974 + of the present file on disk, or the absence
53975 + of it.
53976 + */
53977 + preempt_disable();
53978 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53979 +
53980 + nmatch = lookup_name_entry(tmpname);
53981 + preempt_enable();
53982 + tmpsubj = NULL;
53983 + if (nmatch) {
53984 + if (nmatch->deleted)
53985 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53986 + else
53987 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53988 + if (tmpsubj != NULL)
53989 + task->acl = tmpsubj;
53990 + }
53991 + if (tmpsubj == NULL)
53992 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53993 + task->role);
53994 + if (task->acl) {
53995 + task->is_writable = 0;
53996 + /* ignore additional mmap checks for processes that are writable
53997 + by the default ACL */
53998 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53999 + if (unlikely(obj->mode & GR_WRITE))
54000 + task->is_writable = 1;
54001 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54002 + if (unlikely(obj->mode & GR_WRITE))
54003 + task->is_writable = 1;
54004 +
54005 + gr_set_proc_res(task);
54006 +
54007 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54008 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54009 +#endif
54010 + } else {
54011 + return 1;
54012 + }
54013 +
54014 + return 0;
54015 +}
54016 +
54017 +int
54018 +gr_set_acls(const int type)
54019 +{
54020 + struct task_struct *task, *task2;
54021 + struct acl_role_label *role = current->role;
54022 + __u16 acl_role_id = current->acl_role_id;
54023 + const struct cred *cred;
54024 + int ret;
54025 +
54026 + rcu_read_lock();
54027 + read_lock(&tasklist_lock);
54028 + read_lock(&grsec_exec_file_lock);
54029 + do_each_thread(task2, task) {
54030 + /* check to see if we're called from the exit handler,
54031 + if so, only replace ACLs that have inherited the admin
54032 + ACL */
54033 +
54034 + if (type && (task->role != role ||
54035 + task->acl_role_id != acl_role_id))
54036 + continue;
54037 +
54038 + task->acl_role_id = 0;
54039 + task->acl_sp_role = 0;
54040 +
54041 + if (task->exec_file) {
54042 + cred = __task_cred(task);
54043 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54044 + ret = gr_apply_subject_to_task(task);
54045 + if (ret) {
54046 + read_unlock(&grsec_exec_file_lock);
54047 + read_unlock(&tasklist_lock);
54048 + rcu_read_unlock();
54049 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54050 + return ret;
54051 + }
54052 + } else {
54053 + // it's a kernel process
54054 + task->role = kernel_role;
54055 + task->acl = kernel_role->root_label;
54056 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54057 + task->acl->mode &= ~GR_PROCFIND;
54058 +#endif
54059 + }
54060 + } while_each_thread(task2, task);
54061 + read_unlock(&grsec_exec_file_lock);
54062 + read_unlock(&tasklist_lock);
54063 + rcu_read_unlock();
54064 +
54065 + return 0;
54066 +}
54067 +
54068 +void
54069 +gr_learn_resource(const struct task_struct *task,
54070 + const int res, const unsigned long wanted, const int gt)
54071 +{
54072 + struct acl_subject_label *acl;
54073 + const struct cred *cred;
54074 +
54075 + if (unlikely((gr_status & GR_READY) &&
54076 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54077 + goto skip_reslog;
54078 +
54079 +#ifdef CONFIG_GRKERNSEC_RESLOG
54080 + gr_log_resource(task, res, wanted, gt);
54081 +#endif
54082 + skip_reslog:
54083 +
54084 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54085 + return;
54086 +
54087 + acl = task->acl;
54088 +
54089 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54090 + !(acl->resmask & (1 << (unsigned short) res))))
54091 + return;
54092 +
54093 + if (wanted >= acl->res[res].rlim_cur) {
54094 + unsigned long res_add;
54095 +
54096 + res_add = wanted;
54097 + switch (res) {
54098 + case RLIMIT_CPU:
54099 + res_add += GR_RLIM_CPU_BUMP;
54100 + break;
54101 + case RLIMIT_FSIZE:
54102 + res_add += GR_RLIM_FSIZE_BUMP;
54103 + break;
54104 + case RLIMIT_DATA:
54105 + res_add += GR_RLIM_DATA_BUMP;
54106 + break;
54107 + case RLIMIT_STACK:
54108 + res_add += GR_RLIM_STACK_BUMP;
54109 + break;
54110 + case RLIMIT_CORE:
54111 + res_add += GR_RLIM_CORE_BUMP;
54112 + break;
54113 + case RLIMIT_RSS:
54114 + res_add += GR_RLIM_RSS_BUMP;
54115 + break;
54116 + case RLIMIT_NPROC:
54117 + res_add += GR_RLIM_NPROC_BUMP;
54118 + break;
54119 + case RLIMIT_NOFILE:
54120 + res_add += GR_RLIM_NOFILE_BUMP;
54121 + break;
54122 + case RLIMIT_MEMLOCK:
54123 + res_add += GR_RLIM_MEMLOCK_BUMP;
54124 + break;
54125 + case RLIMIT_AS:
54126 + res_add += GR_RLIM_AS_BUMP;
54127 + break;
54128 + case RLIMIT_LOCKS:
54129 + res_add += GR_RLIM_LOCKS_BUMP;
54130 + break;
54131 + case RLIMIT_SIGPENDING:
54132 + res_add += GR_RLIM_SIGPENDING_BUMP;
54133 + break;
54134 + case RLIMIT_MSGQUEUE:
54135 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54136 + break;
54137 + case RLIMIT_NICE:
54138 + res_add += GR_RLIM_NICE_BUMP;
54139 + break;
54140 + case RLIMIT_RTPRIO:
54141 + res_add += GR_RLIM_RTPRIO_BUMP;
54142 + break;
54143 + case RLIMIT_RTTIME:
54144 + res_add += GR_RLIM_RTTIME_BUMP;
54145 + break;
54146 + }
54147 +
54148 + acl->res[res].rlim_cur = res_add;
54149 +
54150 + if (wanted > acl->res[res].rlim_max)
54151 + acl->res[res].rlim_max = res_add;
54152 +
54153 + /* only log the subject filename, since resource logging is supported for
54154 + single-subject learning only */
54155 + rcu_read_lock();
54156 + cred = __task_cred(task);
54157 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54158 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54159 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54160 + "", (unsigned long) res, &task->signal->saved_ip);
54161 + rcu_read_unlock();
54162 + }
54163 +
54164 + return;
54165 +}
54166 +
54167 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54168 +void
54169 +pax_set_initial_flags(struct linux_binprm *bprm)
54170 +{
54171 + struct task_struct *task = current;
54172 + struct acl_subject_label *proc;
54173 + unsigned long flags;
54174 +
54175 + if (unlikely(!(gr_status & GR_READY)))
54176 + return;
54177 +
54178 + flags = pax_get_flags(task);
54179 +
54180 + proc = task->acl;
54181 +
54182 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54183 + flags &= ~MF_PAX_PAGEEXEC;
54184 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54185 + flags &= ~MF_PAX_SEGMEXEC;
54186 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54187 + flags &= ~MF_PAX_RANDMMAP;
54188 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54189 + flags &= ~MF_PAX_EMUTRAMP;
54190 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54191 + flags &= ~MF_PAX_MPROTECT;
54192 +
54193 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54194 + flags |= MF_PAX_PAGEEXEC;
54195 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54196 + flags |= MF_PAX_SEGMEXEC;
54197 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54198 + flags |= MF_PAX_RANDMMAP;
54199 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54200 + flags |= MF_PAX_EMUTRAMP;
54201 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54202 + flags |= MF_PAX_MPROTECT;
54203 +
54204 + pax_set_flags(task, flags);
54205 +
54206 + return;
54207 +}
54208 +#endif
54209 +
54210 +#ifdef CONFIG_SYSCTL
54211 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54212 + system to save 35kb of memory */
54213 +
54214 +/* we modify the passed in filename, but adjust it back before returning */
54215 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54216 +{
54217 + struct name_entry *nmatch;
54218 + char *p, *lastp = NULL;
54219 + struct acl_object_label *obj = NULL, *tmp;
54220 + struct acl_subject_label *tmpsubj;
54221 + char c = '\0';
54222 +
54223 + read_lock(&gr_inode_lock);
54224 +
54225 + p = name + len - 1;
54226 + do {
54227 + nmatch = lookup_name_entry(name);
54228 + if (lastp != NULL)
54229 + *lastp = c;
54230 +
54231 + if (nmatch == NULL)
54232 + goto next_component;
54233 + tmpsubj = current->acl;
54234 + do {
54235 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54236 + if (obj != NULL) {
54237 + tmp = obj->globbed;
54238 + while (tmp) {
54239 + if (!glob_match(tmp->filename, name)) {
54240 + obj = tmp;
54241 + goto found_obj;
54242 + }
54243 + tmp = tmp->next;
54244 + }
54245 + goto found_obj;
54246 + }
54247 + } while ((tmpsubj = tmpsubj->parent_subject));
54248 +next_component:
54249 + /* end case */
54250 + if (p == name)
54251 + break;
54252 +
54253 + while (*p != '/')
54254 + p--;
54255 + if (p == name)
54256 + lastp = p + 1;
54257 + else {
54258 + lastp = p;
54259 + p--;
54260 + }
54261 + c = *lastp;
54262 + *lastp = '\0';
54263 + } while (1);
54264 +found_obj:
54265 + read_unlock(&gr_inode_lock);
54266 + /* obj returned will always be non-null */
54267 + return obj;
54268 +}
54269 +
54270 +/* returns 0 when allowing, non-zero on error
54271 + op of 0 is used for readdir, so we don't log the names of hidden files
54272 +*/
54273 +__u32
54274 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54275 +{
54276 + struct ctl_table *tmp;
54277 + const char *proc_sys = "/proc/sys";
54278 + char *path;
54279 + struct acl_object_label *obj;
54280 + unsigned short len = 0, pos = 0, depth = 0, i;
54281 + __u32 err = 0;
54282 + __u32 mode = 0;
54283 +
54284 + if (unlikely(!(gr_status & GR_READY)))
54285 + return 0;
54286 +
54287 + /* for now, ignore operations on non-sysctl entries if it's not a
54288 + readdir*/
54289 + if (table->child != NULL && op != 0)
54290 + return 0;
54291 +
54292 + mode |= GR_FIND;
54293 + /* it's only a read if it's an entry, read on dirs is for readdir */
54294 + if (op & MAY_READ)
54295 + mode |= GR_READ;
54296 + if (op & MAY_WRITE)
54297 + mode |= GR_WRITE;
54298 +
54299 + preempt_disable();
54300 +
54301 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54302 +
54303 + /* it's only a read/write if it's an actual entry, not a dir
54304 + (which are opened for readdir)
54305 + */
54306 +
54307 + /* convert the requested sysctl entry into a pathname */
54308 +
54309 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54310 + len += strlen(tmp->procname);
54311 + len++;
54312 + depth++;
54313 + }
54314 +
54315 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54316 + /* deny */
54317 + goto out;
54318 + }
54319 +
54320 + memset(path, 0, PAGE_SIZE);
54321 +
54322 + memcpy(path, proc_sys, strlen(proc_sys));
54323 +
54324 + pos += strlen(proc_sys);
54325 +
54326 + for (; depth > 0; depth--) {
54327 + path[pos] = '/';
54328 + pos++;
54329 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54330 + if (depth == i) {
54331 + memcpy(path + pos, tmp->procname,
54332 + strlen(tmp->procname));
54333 + pos += strlen(tmp->procname);
54334 + }
54335 + i++;
54336 + }
54337 + }
54338 +
54339 + obj = gr_lookup_by_name(path, pos);
54340 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54341 +
54342 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54343 + ((err & mode) != mode))) {
54344 + __u32 new_mode = mode;
54345 +
54346 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54347 +
54348 + err = 0;
54349 + gr_log_learn_sysctl(path, new_mode);
54350 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54351 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54352 + err = -ENOENT;
54353 + } else if (!(err & GR_FIND)) {
54354 + err = -ENOENT;
54355 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54356 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54357 + path, (mode & GR_READ) ? " reading" : "",
54358 + (mode & GR_WRITE) ? " writing" : "");
54359 + err = -EACCES;
54360 + } else if ((err & mode) != mode) {
54361 + err = -EACCES;
54362 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54363 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54364 + path, (mode & GR_READ) ? " reading" : "",
54365 + (mode & GR_WRITE) ? " writing" : "");
54366 + err = 0;
54367 + } else
54368 + err = 0;
54369 +
54370 + out:
54371 + preempt_enable();
54372 +
54373 + return err;
54374 +}
54375 +#endif
54376 +
54377 +int
54378 +gr_handle_proc_ptrace(struct task_struct *task)
54379 +{
54380 + struct file *filp;
54381 + struct task_struct *tmp = task;
54382 + struct task_struct *curtemp = current;
54383 + __u32 retmode;
54384 +
54385 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54386 + if (unlikely(!(gr_status & GR_READY)))
54387 + return 0;
54388 +#endif
54389 +
54390 + read_lock(&tasklist_lock);
54391 + read_lock(&grsec_exec_file_lock);
54392 + filp = task->exec_file;
54393 +
54394 + while (tmp->pid > 0) {
54395 + if (tmp == curtemp)
54396 + break;
54397 + tmp = tmp->real_parent;
54398 + }
54399 +
54400 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54401 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54402 + read_unlock(&grsec_exec_file_lock);
54403 + read_unlock(&tasklist_lock);
54404 + return 1;
54405 + }
54406 +
54407 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54408 + if (!(gr_status & GR_READY)) {
54409 + read_unlock(&grsec_exec_file_lock);
54410 + read_unlock(&tasklist_lock);
54411 + return 0;
54412 + }
54413 +#endif
54414 +
54415 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54416 + read_unlock(&grsec_exec_file_lock);
54417 + read_unlock(&tasklist_lock);
54418 +
54419 + if (retmode & GR_NOPTRACE)
54420 + return 1;
54421 +
54422 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54423 + && (current->acl != task->acl || (current->acl != current->role->root_label
54424 + && current->pid != task->pid)))
54425 + return 1;
54426 +
54427 + return 0;
54428 +}
54429 +
54430 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54431 +{
54432 + if (unlikely(!(gr_status & GR_READY)))
54433 + return;
54434 +
54435 + if (!(current->role->roletype & GR_ROLE_GOD))
54436 + return;
54437 +
54438 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54439 + p->role->rolename, gr_task_roletype_to_char(p),
54440 + p->acl->filename);
54441 +}
54442 +
54443 +int
54444 +gr_handle_ptrace(struct task_struct *task, const long request)
54445 +{
54446 + struct task_struct *tmp = task;
54447 + struct task_struct *curtemp = current;
54448 + __u32 retmode;
54449 +
54450 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54451 + if (unlikely(!(gr_status & GR_READY)))
54452 + return 0;
54453 +#endif
54454 +
54455 + read_lock(&tasklist_lock);
54456 + while (tmp->pid > 0) {
54457 + if (tmp == curtemp)
54458 + break;
54459 + tmp = tmp->real_parent;
54460 + }
54461 +
54462 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54463 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54464 + read_unlock(&tasklist_lock);
54465 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54466 + return 1;
54467 + }
54468 + read_unlock(&tasklist_lock);
54469 +
54470 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54471 + if (!(gr_status & GR_READY))
54472 + return 0;
54473 +#endif
54474 +
54475 + read_lock(&grsec_exec_file_lock);
54476 + if (unlikely(!task->exec_file)) {
54477 + read_unlock(&grsec_exec_file_lock);
54478 + return 0;
54479 + }
54480 +
54481 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54482 + read_unlock(&grsec_exec_file_lock);
54483 +
54484 + if (retmode & GR_NOPTRACE) {
54485 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54486 + return 1;
54487 + }
54488 +
54489 + if (retmode & GR_PTRACERD) {
54490 + switch (request) {
54491 + case PTRACE_SEIZE:
54492 + case PTRACE_POKETEXT:
54493 + case PTRACE_POKEDATA:
54494 + case PTRACE_POKEUSR:
54495 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54496 + case PTRACE_SETREGS:
54497 + case PTRACE_SETFPREGS:
54498 +#endif
54499 +#ifdef CONFIG_X86
54500 + case PTRACE_SETFPXREGS:
54501 +#endif
54502 +#ifdef CONFIG_ALTIVEC
54503 + case PTRACE_SETVRREGS:
54504 +#endif
54505 + return 1;
54506 + default:
54507 + return 0;
54508 + }
54509 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54510 + !(current->role->roletype & GR_ROLE_GOD) &&
54511 + (current->acl != task->acl)) {
54512 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54513 + return 1;
54514 + }
54515 +
54516 + return 0;
54517 +}
54518 +
54519 +static int is_writable_mmap(const struct file *filp)
54520 +{
54521 + struct task_struct *task = current;
54522 + struct acl_object_label *obj, *obj2;
54523 +
54524 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54525 + !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))) {
54526 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54527 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54528 + task->role->root_label);
54529 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54530 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54531 + return 1;
54532 + }
54533 + }
54534 + return 0;
54535 +}
54536 +
54537 +int
54538 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54539 +{
54540 + __u32 mode;
54541 +
54542 + if (unlikely(!file || !(prot & PROT_EXEC)))
54543 + return 1;
54544 +
54545 + if (is_writable_mmap(file))
54546 + return 0;
54547 +
54548 + mode =
54549 + gr_search_file(file->f_path.dentry,
54550 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54551 + file->f_path.mnt);
54552 +
54553 + if (!gr_tpe_allow(file))
54554 + return 0;
54555 +
54556 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54557 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54558 + return 0;
54559 + } else if (unlikely(!(mode & GR_EXEC))) {
54560 + return 0;
54561 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54562 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54563 + return 1;
54564 + }
54565 +
54566 + return 1;
54567 +}
54568 +
54569 +int
54570 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54571 +{
54572 + __u32 mode;
54573 +
54574 + if (unlikely(!file || !(prot & PROT_EXEC)))
54575 + return 1;
54576 +
54577 + if (is_writable_mmap(file))
54578 + return 0;
54579 +
54580 + mode =
54581 + gr_search_file(file->f_path.dentry,
54582 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54583 + file->f_path.mnt);
54584 +
54585 + if (!gr_tpe_allow(file))
54586 + return 0;
54587 +
54588 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54589 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54590 + return 0;
54591 + } else if (unlikely(!(mode & GR_EXEC))) {
54592 + return 0;
54593 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54594 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54595 + return 1;
54596 + }
54597 +
54598 + return 1;
54599 +}
54600 +
54601 +void
54602 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54603 +{
54604 + unsigned long runtime;
54605 + unsigned long cputime;
54606 + unsigned int wday, cday;
54607 + __u8 whr, chr;
54608 + __u8 wmin, cmin;
54609 + __u8 wsec, csec;
54610 + struct timespec timeval;
54611 +
54612 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54613 + !(task->acl->mode & GR_PROCACCT)))
54614 + return;
54615 +
54616 + do_posix_clock_monotonic_gettime(&timeval);
54617 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54618 + wday = runtime / (3600 * 24);
54619 + runtime -= wday * (3600 * 24);
54620 + whr = runtime / 3600;
54621 + runtime -= whr * 3600;
54622 + wmin = runtime / 60;
54623 + runtime -= wmin * 60;
54624 + wsec = runtime;
54625 +
54626 + cputime = (task->utime + task->stime) / HZ;
54627 + cday = cputime / (3600 * 24);
54628 + cputime -= cday * (3600 * 24);
54629 + chr = cputime / 3600;
54630 + cputime -= chr * 3600;
54631 + cmin = cputime / 60;
54632 + cputime -= cmin * 60;
54633 + csec = cputime;
54634 +
54635 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54636 +
54637 + return;
54638 +}
54639 +
54640 +void gr_set_kernel_label(struct task_struct *task)
54641 +{
54642 + if (gr_status & GR_READY) {
54643 + task->role = kernel_role;
54644 + task->acl = kernel_role->root_label;
54645 + }
54646 + return;
54647 +}
54648 +
54649 +#ifdef CONFIG_TASKSTATS
54650 +int gr_is_taskstats_denied(int pid)
54651 +{
54652 + struct task_struct *task;
54653 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54654 + const struct cred *cred;
54655 +#endif
54656 + int ret = 0;
54657 +
54658 + /* restrict taskstats viewing to un-chrooted root users
54659 + who have the 'view' subject flag if the RBAC system is enabled
54660 + */
54661 +
54662 + rcu_read_lock();
54663 + read_lock(&tasklist_lock);
54664 + task = find_task_by_vpid(pid);
54665 + if (task) {
54666 +#ifdef CONFIG_GRKERNSEC_CHROOT
54667 + if (proc_is_chrooted(task))
54668 + ret = -EACCES;
54669 +#endif
54670 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54671 + cred = __task_cred(task);
54672 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54673 + if (cred->uid != 0)
54674 + ret = -EACCES;
54675 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54676 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54677 + ret = -EACCES;
54678 +#endif
54679 +#endif
54680 + if (gr_status & GR_READY) {
54681 + if (!(task->acl->mode & GR_VIEW))
54682 + ret = -EACCES;
54683 + }
54684 + } else
54685 + ret = -ENOENT;
54686 +
54687 + read_unlock(&tasklist_lock);
54688 + rcu_read_unlock();
54689 +
54690 + return ret;
54691 +}
54692 +#endif
54693 +
54694 +/* AUXV entries are filled via a descendant of search_binary_handler
54695 + after we've already applied the subject for the target
54696 +*/
54697 +int gr_acl_enable_at_secure(void)
54698 +{
54699 + if (unlikely(!(gr_status & GR_READY)))
54700 + return 0;
54701 +
54702 + if (current->acl->mode & GR_ATSECURE)
54703 + return 1;
54704 +
54705 + return 0;
54706 +}
54707 +
54708 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54709 +{
54710 + struct task_struct *task = current;
54711 + struct dentry *dentry = file->f_path.dentry;
54712 + struct vfsmount *mnt = file->f_path.mnt;
54713 + struct acl_object_label *obj, *tmp;
54714 + struct acl_subject_label *subj;
54715 + unsigned int bufsize;
54716 + int is_not_root;
54717 + char *path;
54718 + dev_t dev = __get_dev(dentry);
54719 +
54720 + if (unlikely(!(gr_status & GR_READY)))
54721 + return 1;
54722 +
54723 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54724 + return 1;
54725 +
54726 + /* ignore Eric Biederman */
54727 + if (IS_PRIVATE(dentry->d_inode))
54728 + return 1;
54729 +
54730 + subj = task->acl;
54731 + do {
54732 + obj = lookup_acl_obj_label(ino, dev, subj);
54733 + if (obj != NULL)
54734 + return (obj->mode & GR_FIND) ? 1 : 0;
54735 + } while ((subj = subj->parent_subject));
54736 +
54737 + /* this is purely an optimization since we're looking for an object
54738 + for the directory we're doing a readdir on
54739 + if it's possible for any globbed object to match the entry we're
54740 + filling into the directory, then the object we find here will be
54741 + an anchor point with attached globbed objects
54742 + */
54743 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54744 + if (obj->globbed == NULL)
54745 + return (obj->mode & GR_FIND) ? 1 : 0;
54746 +
54747 + is_not_root = ((obj->filename[0] == '/') &&
54748 + (obj->filename[1] == '\0')) ? 0 : 1;
54749 + bufsize = PAGE_SIZE - namelen - is_not_root;
54750 +
54751 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54752 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54753 + return 1;
54754 +
54755 + preempt_disable();
54756 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54757 + bufsize);
54758 +
54759 + bufsize = strlen(path);
54760 +
54761 + /* if base is "/", don't append an additional slash */
54762 + if (is_not_root)
54763 + *(path + bufsize) = '/';
54764 + memcpy(path + bufsize + is_not_root, name, namelen);
54765 + *(path + bufsize + namelen + is_not_root) = '\0';
54766 +
54767 + tmp = obj->globbed;
54768 + while (tmp) {
54769 + if (!glob_match(tmp->filename, path)) {
54770 + preempt_enable();
54771 + return (tmp->mode & GR_FIND) ? 1 : 0;
54772 + }
54773 + tmp = tmp->next;
54774 + }
54775 + preempt_enable();
54776 + return (obj->mode & GR_FIND) ? 1 : 0;
54777 +}
54778 +
54779 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54780 +EXPORT_SYMBOL(gr_acl_is_enabled);
54781 +#endif
54782 +EXPORT_SYMBOL(gr_learn_resource);
54783 +EXPORT_SYMBOL(gr_set_kernel_label);
54784 +#ifdef CONFIG_SECURITY
54785 +EXPORT_SYMBOL(gr_check_user_change);
54786 +EXPORT_SYMBOL(gr_check_group_change);
54787 +#endif
54788 +
54789 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54790 new file mode 100644
54791 index 0000000..34fefda
54792 --- /dev/null
54793 +++ b/grsecurity/gracl_alloc.c
54794 @@ -0,0 +1,105 @@
54795 +#include <linux/kernel.h>
54796 +#include <linux/mm.h>
54797 +#include <linux/slab.h>
54798 +#include <linux/vmalloc.h>
54799 +#include <linux/gracl.h>
54800 +#include <linux/grsecurity.h>
54801 +
54802 +static unsigned long alloc_stack_next = 1;
54803 +static unsigned long alloc_stack_size = 1;
54804 +static void **alloc_stack;
54805 +
54806 +static __inline__ int
54807 +alloc_pop(void)
54808 +{
54809 + if (alloc_stack_next == 1)
54810 + return 0;
54811 +
54812 + kfree(alloc_stack[alloc_stack_next - 2]);
54813 +
54814 + alloc_stack_next--;
54815 +
54816 + return 1;
54817 +}
54818 +
54819 +static __inline__ int
54820 +alloc_push(void *buf)
54821 +{
54822 + if (alloc_stack_next >= alloc_stack_size)
54823 + return 1;
54824 +
54825 + alloc_stack[alloc_stack_next - 1] = buf;
54826 +
54827 + alloc_stack_next++;
54828 +
54829 + return 0;
54830 +}
54831 +
54832 +void *
54833 +acl_alloc(unsigned long len)
54834 +{
54835 + void *ret = NULL;
54836 +
54837 + if (!len || len > PAGE_SIZE)
54838 + goto out;
54839 +
54840 + ret = kmalloc(len, GFP_KERNEL);
54841 +
54842 + if (ret) {
54843 + if (alloc_push(ret)) {
54844 + kfree(ret);
54845 + ret = NULL;
54846 + }
54847 + }
54848 +
54849 +out:
54850 + return ret;
54851 +}
54852 +
54853 +void *
54854 +acl_alloc_num(unsigned long num, unsigned long len)
54855 +{
54856 + if (!len || (num > (PAGE_SIZE / len)))
54857 + return NULL;
54858 +
54859 + return acl_alloc(num * len);
54860 +}
54861 +
54862 +void
54863 +acl_free_all(void)
54864 +{
54865 + if (gr_acl_is_enabled() || !alloc_stack)
54866 + return;
54867 +
54868 + while (alloc_pop()) ;
54869 +
54870 + if (alloc_stack) {
54871 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54872 + kfree(alloc_stack);
54873 + else
54874 + vfree(alloc_stack);
54875 + }
54876 +
54877 + alloc_stack = NULL;
54878 + alloc_stack_size = 1;
54879 + alloc_stack_next = 1;
54880 +
54881 + return;
54882 +}
54883 +
54884 +int
54885 +acl_alloc_stack_init(unsigned long size)
54886 +{
54887 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54888 + alloc_stack =
54889 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54890 + else
54891 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54892 +
54893 + alloc_stack_size = size;
54894 +
54895 + if (!alloc_stack)
54896 + return 0;
54897 + else
54898 + return 1;
54899 +}
54900 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54901 new file mode 100644
54902 index 0000000..6d21049
54903 --- /dev/null
54904 +++ b/grsecurity/gracl_cap.c
54905 @@ -0,0 +1,110 @@
54906 +#include <linux/kernel.h>
54907 +#include <linux/module.h>
54908 +#include <linux/sched.h>
54909 +#include <linux/gracl.h>
54910 +#include <linux/grsecurity.h>
54911 +#include <linux/grinternal.h>
54912 +
54913 +extern const char *captab_log[];
54914 +extern int captab_log_entries;
54915 +
54916 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54917 +{
54918 + struct acl_subject_label *curracl;
54919 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54920 + kernel_cap_t cap_audit = __cap_empty_set;
54921 +
54922 + if (!gr_acl_is_enabled())
54923 + return 1;
54924 +
54925 + curracl = task->acl;
54926 +
54927 + cap_drop = curracl->cap_lower;
54928 + cap_mask = curracl->cap_mask;
54929 + cap_audit = curracl->cap_invert_audit;
54930 +
54931 + while ((curracl = curracl->parent_subject)) {
54932 + /* if the cap isn't specified in the current computed mask but is specified in the
54933 + current level subject, and is lowered in the current level subject, then add
54934 + it to the set of dropped capabilities
54935 + otherwise, add the current level subject's mask to the current computed mask
54936 + */
54937 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54938 + cap_raise(cap_mask, cap);
54939 + if (cap_raised(curracl->cap_lower, cap))
54940 + cap_raise(cap_drop, cap);
54941 + if (cap_raised(curracl->cap_invert_audit, cap))
54942 + cap_raise(cap_audit, cap);
54943 + }
54944 + }
54945 +
54946 + if (!cap_raised(cap_drop, cap)) {
54947 + if (cap_raised(cap_audit, cap))
54948 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54949 + return 1;
54950 + }
54951 +
54952 + curracl = task->acl;
54953 +
54954 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54955 + && cap_raised(cred->cap_effective, cap)) {
54956 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54957 + task->role->roletype, cred->uid,
54958 + cred->gid, task->exec_file ?
54959 + gr_to_filename(task->exec_file->f_path.dentry,
54960 + task->exec_file->f_path.mnt) : curracl->filename,
54961 + curracl->filename, 0UL,
54962 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54963 + return 1;
54964 + }
54965 +
54966 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54967 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54968 +
54969 + return 0;
54970 +}
54971 +
54972 +int
54973 +gr_acl_is_capable(const int cap)
54974 +{
54975 + return gr_task_acl_is_capable(current, current_cred(), cap);
54976 +}
54977 +
54978 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54979 +{
54980 + struct acl_subject_label *curracl;
54981 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54982 +
54983 + if (!gr_acl_is_enabled())
54984 + return 1;
54985 +
54986 + curracl = task->acl;
54987 +
54988 + cap_drop = curracl->cap_lower;
54989 + cap_mask = curracl->cap_mask;
54990 +
54991 + while ((curracl = curracl->parent_subject)) {
54992 + /* if the cap isn't specified in the current computed mask but is specified in the
54993 + current level subject, and is lowered in the current level subject, then add
54994 + it to the set of dropped capabilities
54995 + otherwise, add the current level subject's mask to the current computed mask
54996 + */
54997 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54998 + cap_raise(cap_mask, cap);
54999 + if (cap_raised(curracl->cap_lower, cap))
55000 + cap_raise(cap_drop, cap);
55001 + }
55002 + }
55003 +
55004 + if (!cap_raised(cap_drop, cap))
55005 + return 1;
55006 +
55007 + return 0;
55008 +}
55009 +
55010 +int
55011 +gr_acl_is_capable_nolog(const int cap)
55012 +{
55013 + return gr_task_acl_is_capable_nolog(current, cap);
55014 +}
55015 +
55016 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55017 new file mode 100644
55018 index 0000000..88d0e87
55019 --- /dev/null
55020 +++ b/grsecurity/gracl_fs.c
55021 @@ -0,0 +1,435 @@
55022 +#include <linux/kernel.h>
55023 +#include <linux/sched.h>
55024 +#include <linux/types.h>
55025 +#include <linux/fs.h>
55026 +#include <linux/file.h>
55027 +#include <linux/stat.h>
55028 +#include <linux/grsecurity.h>
55029 +#include <linux/grinternal.h>
55030 +#include <linux/gracl.h>
55031 +
55032 +umode_t
55033 +gr_acl_umask(void)
55034 +{
55035 + if (unlikely(!gr_acl_is_enabled()))
55036 + return 0;
55037 +
55038 + return current->role->umask;
55039 +}
55040 +
55041 +__u32
55042 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55043 + const struct vfsmount * mnt)
55044 +{
55045 + __u32 mode;
55046 +
55047 + if (unlikely(!dentry->d_inode))
55048 + return GR_FIND;
55049 +
55050 + mode =
55051 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55052 +
55053 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55054 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55055 + return mode;
55056 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55057 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55058 + return 0;
55059 + } else if (unlikely(!(mode & GR_FIND)))
55060 + return 0;
55061 +
55062 + return GR_FIND;
55063 +}
55064 +
55065 +__u32
55066 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55067 + int acc_mode)
55068 +{
55069 + __u32 reqmode = GR_FIND;
55070 + __u32 mode;
55071 +
55072 + if (unlikely(!dentry->d_inode))
55073 + return reqmode;
55074 +
55075 + if (acc_mode & MAY_APPEND)
55076 + reqmode |= GR_APPEND;
55077 + else if (acc_mode & MAY_WRITE)
55078 + reqmode |= GR_WRITE;
55079 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55080 + reqmode |= GR_READ;
55081 +
55082 + mode =
55083 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55084 + mnt);
55085 +
55086 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55087 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55088 + reqmode & GR_READ ? " reading" : "",
55089 + reqmode & GR_WRITE ? " writing" : reqmode &
55090 + GR_APPEND ? " appending" : "");
55091 + return reqmode;
55092 + } else
55093 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55094 + {
55095 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55096 + reqmode & GR_READ ? " reading" : "",
55097 + reqmode & GR_WRITE ? " writing" : reqmode &
55098 + GR_APPEND ? " appending" : "");
55099 + return 0;
55100 + } else if (unlikely((mode & reqmode) != reqmode))
55101 + return 0;
55102 +
55103 + return reqmode;
55104 +}
55105 +
55106 +__u32
55107 +gr_acl_handle_creat(const struct dentry * dentry,
55108 + const struct dentry * p_dentry,
55109 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55110 + const int imode)
55111 +{
55112 + __u32 reqmode = GR_WRITE | GR_CREATE;
55113 + __u32 mode;
55114 +
55115 + if (acc_mode & MAY_APPEND)
55116 + reqmode |= GR_APPEND;
55117 + // if a directory was required or the directory already exists, then
55118 + // don't count this open as a read
55119 + if ((acc_mode & MAY_READ) &&
55120 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55121 + reqmode |= GR_READ;
55122 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55123 + reqmode |= GR_SETID;
55124 +
55125 + mode =
55126 + gr_check_create(dentry, p_dentry, p_mnt,
55127 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55128 +
55129 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55130 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55131 + reqmode & GR_READ ? " reading" : "",
55132 + reqmode & GR_WRITE ? " writing" : reqmode &
55133 + GR_APPEND ? " appending" : "");
55134 + return reqmode;
55135 + } else
55136 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55137 + {
55138 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55139 + reqmode & GR_READ ? " reading" : "",
55140 + reqmode & GR_WRITE ? " writing" : reqmode &
55141 + GR_APPEND ? " appending" : "");
55142 + return 0;
55143 + } else if (unlikely((mode & reqmode) != reqmode))
55144 + return 0;
55145 +
55146 + return reqmode;
55147 +}
55148 +
55149 +__u32
55150 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55151 + const int fmode)
55152 +{
55153 + __u32 mode, reqmode = GR_FIND;
55154 +
55155 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55156 + reqmode |= GR_EXEC;
55157 + if (fmode & S_IWOTH)
55158 + reqmode |= GR_WRITE;
55159 + if (fmode & S_IROTH)
55160 + reqmode |= GR_READ;
55161 +
55162 + mode =
55163 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55164 + mnt);
55165 +
55166 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55167 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55168 + reqmode & GR_READ ? " reading" : "",
55169 + reqmode & GR_WRITE ? " writing" : "",
55170 + reqmode & GR_EXEC ? " executing" : "");
55171 + return reqmode;
55172 + } else
55173 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55174 + {
55175 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55176 + reqmode & GR_READ ? " reading" : "",
55177 + reqmode & GR_WRITE ? " writing" : "",
55178 + reqmode & GR_EXEC ? " executing" : "");
55179 + return 0;
55180 + } else if (unlikely((mode & reqmode) != reqmode))
55181 + return 0;
55182 +
55183 + return reqmode;
55184 +}
55185 +
55186 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55187 +{
55188 + __u32 mode;
55189 +
55190 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55191 +
55192 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55193 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55194 + return mode;
55195 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55196 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55197 + return 0;
55198 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55199 + return 0;
55200 +
55201 + return (reqmode);
55202 +}
55203 +
55204 +__u32
55205 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55206 +{
55207 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55208 +}
55209 +
55210 +__u32
55211 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55212 +{
55213 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55214 +}
55215 +
55216 +__u32
55217 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55218 +{
55219 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55220 +}
55221 +
55222 +__u32
55223 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55224 +{
55225 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55226 +}
55227 +
55228 +__u32
55229 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55230 + umode_t *modeptr)
55231 +{
55232 + umode_t mode;
55233 +
55234 + *modeptr &= ~gr_acl_umask();
55235 + mode = *modeptr;
55236 +
55237 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55238 + return 1;
55239 +
55240 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55241 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55242 + GR_CHMOD_ACL_MSG);
55243 + } else {
55244 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55245 + }
55246 +}
55247 +
55248 +__u32
55249 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55250 +{
55251 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55252 +}
55253 +
55254 +__u32
55255 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55256 +{
55257 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55258 +}
55259 +
55260 +__u32
55261 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55262 +{
55263 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55264 +}
55265 +
55266 +__u32
55267 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55268 +{
55269 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55270 + GR_UNIXCONNECT_ACL_MSG);
55271 +}
55272 +
55273 +/* hardlinks require at minimum create and link permission,
55274 + any additional privilege required is based on the
55275 + privilege of the file being linked to
55276 +*/
55277 +__u32
55278 +gr_acl_handle_link(const struct dentry * new_dentry,
55279 + const struct dentry * parent_dentry,
55280 + const struct vfsmount * parent_mnt,
55281 + const struct dentry * old_dentry,
55282 + const struct vfsmount * old_mnt, const char *to)
55283 +{
55284 + __u32 mode;
55285 + __u32 needmode = GR_CREATE | GR_LINK;
55286 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55287 +
55288 + mode =
55289 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55290 + old_mnt);
55291 +
55292 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55293 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55294 + return mode;
55295 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55296 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55297 + return 0;
55298 + } else if (unlikely((mode & needmode) != needmode))
55299 + return 0;
55300 +
55301 + return 1;
55302 +}
55303 +
55304 +__u32
55305 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55306 + const struct dentry * parent_dentry,
55307 + const struct vfsmount * parent_mnt, const char *from)
55308 +{
55309 + __u32 needmode = GR_WRITE | GR_CREATE;
55310 + __u32 mode;
55311 +
55312 + mode =
55313 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55314 + GR_CREATE | GR_AUDIT_CREATE |
55315 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55316 +
55317 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55318 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55319 + return mode;
55320 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55321 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55322 + return 0;
55323 + } else if (unlikely((mode & needmode) != needmode))
55324 + return 0;
55325 +
55326 + return (GR_WRITE | GR_CREATE);
55327 +}
55328 +
55329 +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)
55330 +{
55331 + __u32 mode;
55332 +
55333 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55334 +
55335 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55336 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55337 + return mode;
55338 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55339 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55340 + return 0;
55341 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55342 + return 0;
55343 +
55344 + return (reqmode);
55345 +}
55346 +
55347 +__u32
55348 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55349 + const struct dentry * parent_dentry,
55350 + const struct vfsmount * parent_mnt,
55351 + const int mode)
55352 +{
55353 + __u32 reqmode = GR_WRITE | GR_CREATE;
55354 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55355 + reqmode |= GR_SETID;
55356 +
55357 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55358 + reqmode, GR_MKNOD_ACL_MSG);
55359 +}
55360 +
55361 +__u32
55362 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55363 + const struct dentry *parent_dentry,
55364 + const struct vfsmount *parent_mnt)
55365 +{
55366 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55367 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55368 +}
55369 +
55370 +#define RENAME_CHECK_SUCCESS(old, new) \
55371 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55372 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55373 +
55374 +int
55375 +gr_acl_handle_rename(struct dentry *new_dentry,
55376 + struct dentry *parent_dentry,
55377 + const struct vfsmount *parent_mnt,
55378 + struct dentry *old_dentry,
55379 + struct inode *old_parent_inode,
55380 + struct vfsmount *old_mnt, const char *newname)
55381 +{
55382 + __u32 comp1, comp2;
55383 + int error = 0;
55384 +
55385 + if (unlikely(!gr_acl_is_enabled()))
55386 + return 0;
55387 +
55388 + if (!new_dentry->d_inode) {
55389 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55390 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55391 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55392 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55393 + GR_DELETE | GR_AUDIT_DELETE |
55394 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55395 + GR_SUPPRESS, old_mnt);
55396 + } else {
55397 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55398 + GR_CREATE | GR_DELETE |
55399 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55400 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55401 + GR_SUPPRESS, parent_mnt);
55402 + comp2 =
55403 + gr_search_file(old_dentry,
55404 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55405 + GR_DELETE | GR_AUDIT_DELETE |
55406 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55407 + }
55408 +
55409 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55410 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55411 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55412 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55413 + && !(comp2 & GR_SUPPRESS)) {
55414 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55415 + error = -EACCES;
55416 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55417 + error = -EACCES;
55418 +
55419 + return error;
55420 +}
55421 +
55422 +void
55423 +gr_acl_handle_exit(void)
55424 +{
55425 + u16 id;
55426 + char *rolename;
55427 + struct file *exec_file;
55428 +
55429 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55430 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55431 + id = current->acl_role_id;
55432 + rolename = current->role->rolename;
55433 + gr_set_acls(1);
55434 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55435 + }
55436 +
55437 + write_lock(&grsec_exec_file_lock);
55438 + exec_file = current->exec_file;
55439 + current->exec_file = NULL;
55440 + write_unlock(&grsec_exec_file_lock);
55441 +
55442 + if (exec_file)
55443 + fput(exec_file);
55444 +}
55445 +
55446 +int
55447 +gr_acl_handle_procpidmem(const struct task_struct *task)
55448 +{
55449 + if (unlikely(!gr_acl_is_enabled()))
55450 + return 0;
55451 +
55452 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55453 + return -EACCES;
55454 +
55455 + return 0;
55456 +}
55457 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55458 new file mode 100644
55459 index 0000000..58800a7
55460 --- /dev/null
55461 +++ b/grsecurity/gracl_ip.c
55462 @@ -0,0 +1,384 @@
55463 +#include <linux/kernel.h>
55464 +#include <asm/uaccess.h>
55465 +#include <asm/errno.h>
55466 +#include <net/sock.h>
55467 +#include <linux/file.h>
55468 +#include <linux/fs.h>
55469 +#include <linux/net.h>
55470 +#include <linux/in.h>
55471 +#include <linux/skbuff.h>
55472 +#include <linux/ip.h>
55473 +#include <linux/udp.h>
55474 +#include <linux/types.h>
55475 +#include <linux/sched.h>
55476 +#include <linux/netdevice.h>
55477 +#include <linux/inetdevice.h>
55478 +#include <linux/gracl.h>
55479 +#include <linux/grsecurity.h>
55480 +#include <linux/grinternal.h>
55481 +
55482 +#define GR_BIND 0x01
55483 +#define GR_CONNECT 0x02
55484 +#define GR_INVERT 0x04
55485 +#define GR_BINDOVERRIDE 0x08
55486 +#define GR_CONNECTOVERRIDE 0x10
55487 +#define GR_SOCK_FAMILY 0x20
55488 +
55489 +static const char * gr_protocols[IPPROTO_MAX] = {
55490 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55491 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55492 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55493 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55494 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55495 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55496 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55497 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55498 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55499 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55500 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55501 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55502 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55503 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55504 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55505 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55506 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55507 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55508 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55509 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55510 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55511 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55512 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55513 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55514 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55515 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55516 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55517 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55518 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55519 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55520 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55521 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55522 + };
55523 +
55524 +static const char * gr_socktypes[SOCK_MAX] = {
55525 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55526 + "unknown:7", "unknown:8", "unknown:9", "packet"
55527 + };
55528 +
55529 +static const char * gr_sockfamilies[AF_MAX+1] = {
55530 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55531 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55532 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55533 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55534 + };
55535 +
55536 +const char *
55537 +gr_proto_to_name(unsigned char proto)
55538 +{
55539 + return gr_protocols[proto];
55540 +}
55541 +
55542 +const char *
55543 +gr_socktype_to_name(unsigned char type)
55544 +{
55545 + return gr_socktypes[type];
55546 +}
55547 +
55548 +const char *
55549 +gr_sockfamily_to_name(unsigned char family)
55550 +{
55551 + return gr_sockfamilies[family];
55552 +}
55553 +
55554 +int
55555 +gr_search_socket(const int domain, const int type, const int protocol)
55556 +{
55557 + struct acl_subject_label *curr;
55558 + const struct cred *cred = current_cred();
55559 +
55560 + if (unlikely(!gr_acl_is_enabled()))
55561 + goto exit;
55562 +
55563 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55564 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55565 + goto exit; // let the kernel handle it
55566 +
55567 + curr = current->acl;
55568 +
55569 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55570 + /* the family is allowed, if this is PF_INET allow it only if
55571 + the extra sock type/protocol checks pass */
55572 + if (domain == PF_INET)
55573 + goto inet_check;
55574 + goto exit;
55575 + } else {
55576 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55577 + __u32 fakeip = 0;
55578 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55579 + current->role->roletype, cred->uid,
55580 + cred->gid, current->exec_file ?
55581 + gr_to_filename(current->exec_file->f_path.dentry,
55582 + current->exec_file->f_path.mnt) :
55583 + curr->filename, curr->filename,
55584 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55585 + &current->signal->saved_ip);
55586 + goto exit;
55587 + }
55588 + goto exit_fail;
55589 + }
55590 +
55591 +inet_check:
55592 + /* the rest of this checking is for IPv4 only */
55593 + if (!curr->ips)
55594 + goto exit;
55595 +
55596 + if ((curr->ip_type & (1 << type)) &&
55597 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55598 + goto exit;
55599 +
55600 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55601 + /* we don't place acls on raw sockets , and sometimes
55602 + dgram/ip sockets are opened for ioctl and not
55603 + bind/connect, so we'll fake a bind learn log */
55604 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55605 + __u32 fakeip = 0;
55606 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55607 + current->role->roletype, cred->uid,
55608 + cred->gid, current->exec_file ?
55609 + gr_to_filename(current->exec_file->f_path.dentry,
55610 + current->exec_file->f_path.mnt) :
55611 + curr->filename, curr->filename,
55612 + &fakeip, 0, type,
55613 + protocol, GR_CONNECT, &current->signal->saved_ip);
55614 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55615 + __u32 fakeip = 0;
55616 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55617 + current->role->roletype, cred->uid,
55618 + cred->gid, current->exec_file ?
55619 + gr_to_filename(current->exec_file->f_path.dentry,
55620 + current->exec_file->f_path.mnt) :
55621 + curr->filename, curr->filename,
55622 + &fakeip, 0, type,
55623 + protocol, GR_BIND, &current->signal->saved_ip);
55624 + }
55625 + /* we'll log when they use connect or bind */
55626 + goto exit;
55627 + }
55628 +
55629 +exit_fail:
55630 + if (domain == PF_INET)
55631 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55632 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55633 + else
55634 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55635 + gr_socktype_to_name(type), protocol);
55636 +
55637 + return 0;
55638 +exit:
55639 + return 1;
55640 +}
55641 +
55642 +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)
55643 +{
55644 + if ((ip->mode & mode) &&
55645 + (ip_port >= ip->low) &&
55646 + (ip_port <= ip->high) &&
55647 + ((ntohl(ip_addr) & our_netmask) ==
55648 + (ntohl(our_addr) & our_netmask))
55649 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55650 + && (ip->type & (1 << type))) {
55651 + if (ip->mode & GR_INVERT)
55652 + return 2; // specifically denied
55653 + else
55654 + return 1; // allowed
55655 + }
55656 +
55657 + return 0; // not specifically allowed, may continue parsing
55658 +}
55659 +
55660 +static int
55661 +gr_search_connectbind(const int full_mode, struct sock *sk,
55662 + struct sockaddr_in *addr, const int type)
55663 +{
55664 + char iface[IFNAMSIZ] = {0};
55665 + struct acl_subject_label *curr;
55666 + struct acl_ip_label *ip;
55667 + struct inet_sock *isk;
55668 + struct net_device *dev;
55669 + struct in_device *idev;
55670 + unsigned long i;
55671 + int ret;
55672 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55673 + __u32 ip_addr = 0;
55674 + __u32 our_addr;
55675 + __u32 our_netmask;
55676 + char *p;
55677 + __u16 ip_port = 0;
55678 + const struct cred *cred = current_cred();
55679 +
55680 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55681 + return 0;
55682 +
55683 + curr = current->acl;
55684 + isk = inet_sk(sk);
55685 +
55686 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55687 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55688 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55689 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55690 + struct sockaddr_in saddr;
55691 + int err;
55692 +
55693 + saddr.sin_family = AF_INET;
55694 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55695 + saddr.sin_port = isk->inet_sport;
55696 +
55697 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55698 + if (err)
55699 + return err;
55700 +
55701 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55702 + if (err)
55703 + return err;
55704 + }
55705 +
55706 + if (!curr->ips)
55707 + return 0;
55708 +
55709 + ip_addr = addr->sin_addr.s_addr;
55710 + ip_port = ntohs(addr->sin_port);
55711 +
55712 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55713 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55714 + current->role->roletype, cred->uid,
55715 + cred->gid, current->exec_file ?
55716 + gr_to_filename(current->exec_file->f_path.dentry,
55717 + current->exec_file->f_path.mnt) :
55718 + curr->filename, curr->filename,
55719 + &ip_addr, ip_port, type,
55720 + sk->sk_protocol, mode, &current->signal->saved_ip);
55721 + return 0;
55722 + }
55723 +
55724 + for (i = 0; i < curr->ip_num; i++) {
55725 + ip = *(curr->ips + i);
55726 + if (ip->iface != NULL) {
55727 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55728 + p = strchr(iface, ':');
55729 + if (p != NULL)
55730 + *p = '\0';
55731 + dev = dev_get_by_name(sock_net(sk), iface);
55732 + if (dev == NULL)
55733 + continue;
55734 + idev = in_dev_get(dev);
55735 + if (idev == NULL) {
55736 + dev_put(dev);
55737 + continue;
55738 + }
55739 + rcu_read_lock();
55740 + for_ifa(idev) {
55741 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55742 + our_addr = ifa->ifa_address;
55743 + our_netmask = 0xffffffff;
55744 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55745 + if (ret == 1) {
55746 + rcu_read_unlock();
55747 + in_dev_put(idev);
55748 + dev_put(dev);
55749 + return 0;
55750 + } else if (ret == 2) {
55751 + rcu_read_unlock();
55752 + in_dev_put(idev);
55753 + dev_put(dev);
55754 + goto denied;
55755 + }
55756 + }
55757 + } endfor_ifa(idev);
55758 + rcu_read_unlock();
55759 + in_dev_put(idev);
55760 + dev_put(dev);
55761 + } else {
55762 + our_addr = ip->addr;
55763 + our_netmask = ip->netmask;
55764 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55765 + if (ret == 1)
55766 + return 0;
55767 + else if (ret == 2)
55768 + goto denied;
55769 + }
55770 + }
55771 +
55772 +denied:
55773 + if (mode == GR_BIND)
55774 + 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));
55775 + else if (mode == GR_CONNECT)
55776 + 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));
55777 +
55778 + return -EACCES;
55779 +}
55780 +
55781 +int
55782 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55783 +{
55784 + /* always allow disconnection of dgram sockets with connect */
55785 + if (addr->sin_family == AF_UNSPEC)
55786 + return 0;
55787 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55788 +}
55789 +
55790 +int
55791 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55792 +{
55793 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55794 +}
55795 +
55796 +int gr_search_listen(struct socket *sock)
55797 +{
55798 + struct sock *sk = sock->sk;
55799 + struct sockaddr_in addr;
55800 +
55801 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55802 + addr.sin_port = inet_sk(sk)->inet_sport;
55803 +
55804 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55805 +}
55806 +
55807 +int gr_search_accept(struct socket *sock)
55808 +{
55809 + struct sock *sk = sock->sk;
55810 + struct sockaddr_in addr;
55811 +
55812 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55813 + addr.sin_port = inet_sk(sk)->inet_sport;
55814 +
55815 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55816 +}
55817 +
55818 +int
55819 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55820 +{
55821 + if (addr)
55822 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55823 + else {
55824 + struct sockaddr_in sin;
55825 + const struct inet_sock *inet = inet_sk(sk);
55826 +
55827 + sin.sin_addr.s_addr = inet->inet_daddr;
55828 + sin.sin_port = inet->inet_dport;
55829 +
55830 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55831 + }
55832 +}
55833 +
55834 +int
55835 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55836 +{
55837 + struct sockaddr_in sin;
55838 +
55839 + if (unlikely(skb->len < sizeof (struct udphdr)))
55840 + return 0; // skip this packet
55841 +
55842 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55843 + sin.sin_port = udp_hdr(skb)->source;
55844 +
55845 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55846 +}
55847 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55848 new file mode 100644
55849 index 0000000..25f54ef
55850 --- /dev/null
55851 +++ b/grsecurity/gracl_learn.c
55852 @@ -0,0 +1,207 @@
55853 +#include <linux/kernel.h>
55854 +#include <linux/mm.h>
55855 +#include <linux/sched.h>
55856 +#include <linux/poll.h>
55857 +#include <linux/string.h>
55858 +#include <linux/file.h>
55859 +#include <linux/types.h>
55860 +#include <linux/vmalloc.h>
55861 +#include <linux/grinternal.h>
55862 +
55863 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55864 + size_t count, loff_t *ppos);
55865 +extern int gr_acl_is_enabled(void);
55866 +
55867 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55868 +static int gr_learn_attached;
55869 +
55870 +/* use a 512k buffer */
55871 +#define LEARN_BUFFER_SIZE (512 * 1024)
55872 +
55873 +static DEFINE_SPINLOCK(gr_learn_lock);
55874 +static DEFINE_MUTEX(gr_learn_user_mutex);
55875 +
55876 +/* we need to maintain two buffers, so that the kernel context of grlearn
55877 + uses a semaphore around the userspace copying, and the other kernel contexts
55878 + use a spinlock when copying into the buffer, since they cannot sleep
55879 +*/
55880 +static char *learn_buffer;
55881 +static char *learn_buffer_user;
55882 +static int learn_buffer_len;
55883 +static int learn_buffer_user_len;
55884 +
55885 +static ssize_t
55886 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55887 +{
55888 + DECLARE_WAITQUEUE(wait, current);
55889 + ssize_t retval = 0;
55890 +
55891 + add_wait_queue(&learn_wait, &wait);
55892 + set_current_state(TASK_INTERRUPTIBLE);
55893 + do {
55894 + mutex_lock(&gr_learn_user_mutex);
55895 + spin_lock(&gr_learn_lock);
55896 + if (learn_buffer_len)
55897 + break;
55898 + spin_unlock(&gr_learn_lock);
55899 + mutex_unlock(&gr_learn_user_mutex);
55900 + if (file->f_flags & O_NONBLOCK) {
55901 + retval = -EAGAIN;
55902 + goto out;
55903 + }
55904 + if (signal_pending(current)) {
55905 + retval = -ERESTARTSYS;
55906 + goto out;
55907 + }
55908 +
55909 + schedule();
55910 + } while (1);
55911 +
55912 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55913 + learn_buffer_user_len = learn_buffer_len;
55914 + retval = learn_buffer_len;
55915 + learn_buffer_len = 0;
55916 +
55917 + spin_unlock(&gr_learn_lock);
55918 +
55919 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55920 + retval = -EFAULT;
55921 +
55922 + mutex_unlock(&gr_learn_user_mutex);
55923 +out:
55924 + set_current_state(TASK_RUNNING);
55925 + remove_wait_queue(&learn_wait, &wait);
55926 + return retval;
55927 +}
55928 +
55929 +static unsigned int
55930 +poll_learn(struct file * file, poll_table * wait)
55931 +{
55932 + poll_wait(file, &learn_wait, wait);
55933 +
55934 + if (learn_buffer_len)
55935 + return (POLLIN | POLLRDNORM);
55936 +
55937 + return 0;
55938 +}
55939 +
55940 +void
55941 +gr_clear_learn_entries(void)
55942 +{
55943 + char *tmp;
55944 +
55945 + mutex_lock(&gr_learn_user_mutex);
55946 + spin_lock(&gr_learn_lock);
55947 + tmp = learn_buffer;
55948 + learn_buffer = NULL;
55949 + spin_unlock(&gr_learn_lock);
55950 + if (tmp)
55951 + vfree(tmp);
55952 + if (learn_buffer_user != NULL) {
55953 + vfree(learn_buffer_user);
55954 + learn_buffer_user = NULL;
55955 + }
55956 + learn_buffer_len = 0;
55957 + mutex_unlock(&gr_learn_user_mutex);
55958 +
55959 + return;
55960 +}
55961 +
55962 +void
55963 +gr_add_learn_entry(const char *fmt, ...)
55964 +{
55965 + va_list args;
55966 + unsigned int len;
55967 +
55968 + if (!gr_learn_attached)
55969 + return;
55970 +
55971 + spin_lock(&gr_learn_lock);
55972 +
55973 + /* leave a gap at the end so we know when it's "full" but don't have to
55974 + compute the exact length of the string we're trying to append
55975 + */
55976 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55977 + spin_unlock(&gr_learn_lock);
55978 + wake_up_interruptible(&learn_wait);
55979 + return;
55980 + }
55981 + if (learn_buffer == NULL) {
55982 + spin_unlock(&gr_learn_lock);
55983 + return;
55984 + }
55985 +
55986 + va_start(args, fmt);
55987 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55988 + va_end(args);
55989 +
55990 + learn_buffer_len += len + 1;
55991 +
55992 + spin_unlock(&gr_learn_lock);
55993 + wake_up_interruptible(&learn_wait);
55994 +
55995 + return;
55996 +}
55997 +
55998 +static int
55999 +open_learn(struct inode *inode, struct file *file)
56000 +{
56001 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56002 + return -EBUSY;
56003 + if (file->f_mode & FMODE_READ) {
56004 + int retval = 0;
56005 + mutex_lock(&gr_learn_user_mutex);
56006 + if (learn_buffer == NULL)
56007 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56008 + if (learn_buffer_user == NULL)
56009 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56010 + if (learn_buffer == NULL) {
56011 + retval = -ENOMEM;
56012 + goto out_error;
56013 + }
56014 + if (learn_buffer_user == NULL) {
56015 + retval = -ENOMEM;
56016 + goto out_error;
56017 + }
56018 + learn_buffer_len = 0;
56019 + learn_buffer_user_len = 0;
56020 + gr_learn_attached = 1;
56021 +out_error:
56022 + mutex_unlock(&gr_learn_user_mutex);
56023 + return retval;
56024 + }
56025 + return 0;
56026 +}
56027 +
56028 +static int
56029 +close_learn(struct inode *inode, struct file *file)
56030 +{
56031 + if (file->f_mode & FMODE_READ) {
56032 + char *tmp = NULL;
56033 + mutex_lock(&gr_learn_user_mutex);
56034 + spin_lock(&gr_learn_lock);
56035 + tmp = learn_buffer;
56036 + learn_buffer = NULL;
56037 + spin_unlock(&gr_learn_lock);
56038 + if (tmp)
56039 + vfree(tmp);
56040 + if (learn_buffer_user != NULL) {
56041 + vfree(learn_buffer_user);
56042 + learn_buffer_user = NULL;
56043 + }
56044 + learn_buffer_len = 0;
56045 + learn_buffer_user_len = 0;
56046 + gr_learn_attached = 0;
56047 + mutex_unlock(&gr_learn_user_mutex);
56048 + }
56049 +
56050 + return 0;
56051 +}
56052 +
56053 +const struct file_operations grsec_fops = {
56054 + .read = read_learn,
56055 + .write = write_grsec_handler,
56056 + .open = open_learn,
56057 + .release = close_learn,
56058 + .poll = poll_learn,
56059 +};
56060 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56061 new file mode 100644
56062 index 0000000..39645c9
56063 --- /dev/null
56064 +++ b/grsecurity/gracl_res.c
56065 @@ -0,0 +1,68 @@
56066 +#include <linux/kernel.h>
56067 +#include <linux/sched.h>
56068 +#include <linux/gracl.h>
56069 +#include <linux/grinternal.h>
56070 +
56071 +static const char *restab_log[] = {
56072 + [RLIMIT_CPU] = "RLIMIT_CPU",
56073 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56074 + [RLIMIT_DATA] = "RLIMIT_DATA",
56075 + [RLIMIT_STACK] = "RLIMIT_STACK",
56076 + [RLIMIT_CORE] = "RLIMIT_CORE",
56077 + [RLIMIT_RSS] = "RLIMIT_RSS",
56078 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56079 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56080 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56081 + [RLIMIT_AS] = "RLIMIT_AS",
56082 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56083 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56084 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56085 + [RLIMIT_NICE] = "RLIMIT_NICE",
56086 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56087 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56088 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56089 +};
56090 +
56091 +void
56092 +gr_log_resource(const struct task_struct *task,
56093 + const int res, const unsigned long wanted, const int gt)
56094 +{
56095 + const struct cred *cred;
56096 + unsigned long rlim;
56097 +
56098 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56099 + return;
56100 +
56101 + // not yet supported resource
56102 + if (unlikely(!restab_log[res]))
56103 + return;
56104 +
56105 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56106 + rlim = task_rlimit_max(task, res);
56107 + else
56108 + rlim = task_rlimit(task, res);
56109 +
56110 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56111 + return;
56112 +
56113 + rcu_read_lock();
56114 + cred = __task_cred(task);
56115 +
56116 + if (res == RLIMIT_NPROC &&
56117 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56118 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56119 + goto out_rcu_unlock;
56120 + else if (res == RLIMIT_MEMLOCK &&
56121 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56122 + goto out_rcu_unlock;
56123 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56124 + goto out_rcu_unlock;
56125 + rcu_read_unlock();
56126 +
56127 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56128 +
56129 + return;
56130 +out_rcu_unlock:
56131 + rcu_read_unlock();
56132 + return;
56133 +}
56134 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56135 new file mode 100644
56136 index 0000000..5556be3
56137 --- /dev/null
56138 +++ b/grsecurity/gracl_segv.c
56139 @@ -0,0 +1,299 @@
56140 +#include <linux/kernel.h>
56141 +#include <linux/mm.h>
56142 +#include <asm/uaccess.h>
56143 +#include <asm/errno.h>
56144 +#include <asm/mman.h>
56145 +#include <net/sock.h>
56146 +#include <linux/file.h>
56147 +#include <linux/fs.h>
56148 +#include <linux/net.h>
56149 +#include <linux/in.h>
56150 +#include <linux/slab.h>
56151 +#include <linux/types.h>
56152 +#include <linux/sched.h>
56153 +#include <linux/timer.h>
56154 +#include <linux/gracl.h>
56155 +#include <linux/grsecurity.h>
56156 +#include <linux/grinternal.h>
56157 +
56158 +static struct crash_uid *uid_set;
56159 +static unsigned short uid_used;
56160 +static DEFINE_SPINLOCK(gr_uid_lock);
56161 +extern rwlock_t gr_inode_lock;
56162 +extern struct acl_subject_label *
56163 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56164 + struct acl_role_label *role);
56165 +
56166 +#ifdef CONFIG_BTRFS_FS
56167 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56168 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56169 +#endif
56170 +
56171 +static inline dev_t __get_dev(const struct dentry *dentry)
56172 +{
56173 +#ifdef CONFIG_BTRFS_FS
56174 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56175 + return get_btrfs_dev_from_inode(dentry->d_inode);
56176 + else
56177 +#endif
56178 + return dentry->d_inode->i_sb->s_dev;
56179 +}
56180 +
56181 +int
56182 +gr_init_uidset(void)
56183 +{
56184 + uid_set =
56185 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56186 + uid_used = 0;
56187 +
56188 + return uid_set ? 1 : 0;
56189 +}
56190 +
56191 +void
56192 +gr_free_uidset(void)
56193 +{
56194 + if (uid_set)
56195 + kfree(uid_set);
56196 +
56197 + return;
56198 +}
56199 +
56200 +int
56201 +gr_find_uid(const uid_t uid)
56202 +{
56203 + struct crash_uid *tmp = uid_set;
56204 + uid_t buid;
56205 + int low = 0, high = uid_used - 1, mid;
56206 +
56207 + while (high >= low) {
56208 + mid = (low + high) >> 1;
56209 + buid = tmp[mid].uid;
56210 + if (buid == uid)
56211 + return mid;
56212 + if (buid > uid)
56213 + high = mid - 1;
56214 + if (buid < uid)
56215 + low = mid + 1;
56216 + }
56217 +
56218 + return -1;
56219 +}
56220 +
56221 +static __inline__ void
56222 +gr_insertsort(void)
56223 +{
56224 + unsigned short i, j;
56225 + struct crash_uid index;
56226 +
56227 + for (i = 1; i < uid_used; i++) {
56228 + index = uid_set[i];
56229 + j = i;
56230 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56231 + uid_set[j] = uid_set[j - 1];
56232 + j--;
56233 + }
56234 + uid_set[j] = index;
56235 + }
56236 +
56237 + return;
56238 +}
56239 +
56240 +static __inline__ void
56241 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56242 +{
56243 + int loc;
56244 +
56245 + if (uid_used == GR_UIDTABLE_MAX)
56246 + return;
56247 +
56248 + loc = gr_find_uid(uid);
56249 +
56250 + if (loc >= 0) {
56251 + uid_set[loc].expires = expires;
56252 + return;
56253 + }
56254 +
56255 + uid_set[uid_used].uid = uid;
56256 + uid_set[uid_used].expires = expires;
56257 + uid_used++;
56258 +
56259 + gr_insertsort();
56260 +
56261 + return;
56262 +}
56263 +
56264 +void
56265 +gr_remove_uid(const unsigned short loc)
56266 +{
56267 + unsigned short i;
56268 +
56269 + for (i = loc + 1; i < uid_used; i++)
56270 + uid_set[i - 1] = uid_set[i];
56271 +
56272 + uid_used--;
56273 +
56274 + return;
56275 +}
56276 +
56277 +int
56278 +gr_check_crash_uid(const uid_t uid)
56279 +{
56280 + int loc;
56281 + int ret = 0;
56282 +
56283 + if (unlikely(!gr_acl_is_enabled()))
56284 + return 0;
56285 +
56286 + spin_lock(&gr_uid_lock);
56287 + loc = gr_find_uid(uid);
56288 +
56289 + if (loc < 0)
56290 + goto out_unlock;
56291 +
56292 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56293 + gr_remove_uid(loc);
56294 + else
56295 + ret = 1;
56296 +
56297 +out_unlock:
56298 + spin_unlock(&gr_uid_lock);
56299 + return ret;
56300 +}
56301 +
56302 +static __inline__ int
56303 +proc_is_setxid(const struct cred *cred)
56304 +{
56305 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56306 + cred->uid != cred->fsuid)
56307 + return 1;
56308 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56309 + cred->gid != cred->fsgid)
56310 + return 1;
56311 +
56312 + return 0;
56313 +}
56314 +
56315 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56316 +
56317 +void
56318 +gr_handle_crash(struct task_struct *task, const int sig)
56319 +{
56320 + struct acl_subject_label *curr;
56321 + struct task_struct *tsk, *tsk2;
56322 + const struct cred *cred;
56323 + const struct cred *cred2;
56324 +
56325 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56326 + return;
56327 +
56328 + if (unlikely(!gr_acl_is_enabled()))
56329 + return;
56330 +
56331 + curr = task->acl;
56332 +
56333 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56334 + return;
56335 +
56336 + if (time_before_eq(curr->expires, get_seconds())) {
56337 + curr->expires = 0;
56338 + curr->crashes = 0;
56339 + }
56340 +
56341 + curr->crashes++;
56342 +
56343 + if (!curr->expires)
56344 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56345 +
56346 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56347 + time_after(curr->expires, get_seconds())) {
56348 + rcu_read_lock();
56349 + cred = __task_cred(task);
56350 + if (cred->uid && proc_is_setxid(cred)) {
56351 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56352 + spin_lock(&gr_uid_lock);
56353 + gr_insert_uid(cred->uid, curr->expires);
56354 + spin_unlock(&gr_uid_lock);
56355 + curr->expires = 0;
56356 + curr->crashes = 0;
56357 + read_lock(&tasklist_lock);
56358 + do_each_thread(tsk2, tsk) {
56359 + cred2 = __task_cred(tsk);
56360 + if (tsk != task && cred2->uid == cred->uid)
56361 + gr_fake_force_sig(SIGKILL, tsk);
56362 + } while_each_thread(tsk2, tsk);
56363 + read_unlock(&tasklist_lock);
56364 + } else {
56365 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56366 + read_lock(&tasklist_lock);
56367 + read_lock(&grsec_exec_file_lock);
56368 + do_each_thread(tsk2, tsk) {
56369 + if (likely(tsk != task)) {
56370 + // if this thread has the same subject as the one that triggered
56371 + // RES_CRASH and it's the same binary, kill it
56372 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56373 + gr_fake_force_sig(SIGKILL, tsk);
56374 + }
56375 + } while_each_thread(tsk2, tsk);
56376 + read_unlock(&grsec_exec_file_lock);
56377 + read_unlock(&tasklist_lock);
56378 + }
56379 + rcu_read_unlock();
56380 + }
56381 +
56382 + return;
56383 +}
56384 +
56385 +int
56386 +gr_check_crash_exec(const struct file *filp)
56387 +{
56388 + struct acl_subject_label *curr;
56389 +
56390 + if (unlikely(!gr_acl_is_enabled()))
56391 + return 0;
56392 +
56393 + read_lock(&gr_inode_lock);
56394 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56395 + __get_dev(filp->f_path.dentry),
56396 + current->role);
56397 + read_unlock(&gr_inode_lock);
56398 +
56399 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56400 + (!curr->crashes && !curr->expires))
56401 + return 0;
56402 +
56403 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56404 + time_after(curr->expires, get_seconds()))
56405 + return 1;
56406 + else if (time_before_eq(curr->expires, get_seconds())) {
56407 + curr->crashes = 0;
56408 + curr->expires = 0;
56409 + }
56410 +
56411 + return 0;
56412 +}
56413 +
56414 +void
56415 +gr_handle_alertkill(struct task_struct *task)
56416 +{
56417 + struct acl_subject_label *curracl;
56418 + __u32 curr_ip;
56419 + struct task_struct *p, *p2;
56420 +
56421 + if (unlikely(!gr_acl_is_enabled()))
56422 + return;
56423 +
56424 + curracl = task->acl;
56425 + curr_ip = task->signal->curr_ip;
56426 +
56427 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56428 + read_lock(&tasklist_lock);
56429 + do_each_thread(p2, p) {
56430 + if (p->signal->curr_ip == curr_ip)
56431 + gr_fake_force_sig(SIGKILL, p);
56432 + } while_each_thread(p2, p);
56433 + read_unlock(&tasklist_lock);
56434 + } else if (curracl->mode & GR_KILLPROC)
56435 + gr_fake_force_sig(SIGKILL, task);
56436 +
56437 + return;
56438 +}
56439 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56440 new file mode 100644
56441 index 0000000..9d83a69
56442 --- /dev/null
56443 +++ b/grsecurity/gracl_shm.c
56444 @@ -0,0 +1,40 @@
56445 +#include <linux/kernel.h>
56446 +#include <linux/mm.h>
56447 +#include <linux/sched.h>
56448 +#include <linux/file.h>
56449 +#include <linux/ipc.h>
56450 +#include <linux/gracl.h>
56451 +#include <linux/grsecurity.h>
56452 +#include <linux/grinternal.h>
56453 +
56454 +int
56455 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56456 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56457 +{
56458 + struct task_struct *task;
56459 +
56460 + if (!gr_acl_is_enabled())
56461 + return 1;
56462 +
56463 + rcu_read_lock();
56464 + read_lock(&tasklist_lock);
56465 +
56466 + task = find_task_by_vpid(shm_cprid);
56467 +
56468 + if (unlikely(!task))
56469 + task = find_task_by_vpid(shm_lapid);
56470 +
56471 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56472 + (task->pid == shm_lapid)) &&
56473 + (task->acl->mode & GR_PROTSHM) &&
56474 + (task->acl != current->acl))) {
56475 + read_unlock(&tasklist_lock);
56476 + rcu_read_unlock();
56477 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56478 + return 0;
56479 + }
56480 + read_unlock(&tasklist_lock);
56481 + rcu_read_unlock();
56482 +
56483 + return 1;
56484 +}
56485 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56486 new file mode 100644
56487 index 0000000..bc0be01
56488 --- /dev/null
56489 +++ b/grsecurity/grsec_chdir.c
56490 @@ -0,0 +1,19 @@
56491 +#include <linux/kernel.h>
56492 +#include <linux/sched.h>
56493 +#include <linux/fs.h>
56494 +#include <linux/file.h>
56495 +#include <linux/grsecurity.h>
56496 +#include <linux/grinternal.h>
56497 +
56498 +void
56499 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56500 +{
56501 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56502 + if ((grsec_enable_chdir && grsec_enable_group &&
56503 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56504 + !grsec_enable_group)) {
56505 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56506 + }
56507 +#endif
56508 + return;
56509 +}
56510 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56511 new file mode 100644
56512 index 0000000..9807ee2
56513 --- /dev/null
56514 +++ b/grsecurity/grsec_chroot.c
56515 @@ -0,0 +1,368 @@
56516 +#include <linux/kernel.h>
56517 +#include <linux/module.h>
56518 +#include <linux/sched.h>
56519 +#include <linux/file.h>
56520 +#include <linux/fs.h>
56521 +#include <linux/mount.h>
56522 +#include <linux/types.h>
56523 +#include "../fs/mount.h"
56524 +#include <linux/grsecurity.h>
56525 +#include <linux/grinternal.h>
56526 +
56527 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56528 +{
56529 +#ifdef CONFIG_GRKERNSEC
56530 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56531 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56532 + task->gr_is_chrooted = 1;
56533 + else
56534 + task->gr_is_chrooted = 0;
56535 +
56536 + task->gr_chroot_dentry = path->dentry;
56537 +#endif
56538 + return;
56539 +}
56540 +
56541 +void gr_clear_chroot_entries(struct task_struct *task)
56542 +{
56543 +#ifdef CONFIG_GRKERNSEC
56544 + task->gr_is_chrooted = 0;
56545 + task->gr_chroot_dentry = NULL;
56546 +#endif
56547 + return;
56548 +}
56549 +
56550 +int
56551 +gr_handle_chroot_unix(const pid_t pid)
56552 +{
56553 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56554 + struct task_struct *p;
56555 +
56556 + if (unlikely(!grsec_enable_chroot_unix))
56557 + return 1;
56558 +
56559 + if (likely(!proc_is_chrooted(current)))
56560 + return 1;
56561 +
56562 + rcu_read_lock();
56563 + read_lock(&tasklist_lock);
56564 + p = find_task_by_vpid_unrestricted(pid);
56565 + if (unlikely(p && !have_same_root(current, p))) {
56566 + read_unlock(&tasklist_lock);
56567 + rcu_read_unlock();
56568 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56569 + return 0;
56570 + }
56571 + read_unlock(&tasklist_lock);
56572 + rcu_read_unlock();
56573 +#endif
56574 + return 1;
56575 +}
56576 +
56577 +int
56578 +gr_handle_chroot_nice(void)
56579 +{
56580 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56581 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56582 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56583 + return -EPERM;
56584 + }
56585 +#endif
56586 + return 0;
56587 +}
56588 +
56589 +int
56590 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56591 +{
56592 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56593 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56594 + && proc_is_chrooted(current)) {
56595 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56596 + return -EACCES;
56597 + }
56598 +#endif
56599 + return 0;
56600 +}
56601 +
56602 +int
56603 +gr_handle_chroot_rawio(const struct inode *inode)
56604 +{
56605 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56606 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56607 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56608 + return 1;
56609 +#endif
56610 + return 0;
56611 +}
56612 +
56613 +int
56614 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56615 +{
56616 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56617 + struct task_struct *p;
56618 + int ret = 0;
56619 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56620 + return ret;
56621 +
56622 + read_lock(&tasklist_lock);
56623 + do_each_pid_task(pid, type, p) {
56624 + if (!have_same_root(current, p)) {
56625 + ret = 1;
56626 + goto out;
56627 + }
56628 + } while_each_pid_task(pid, type, p);
56629 +out:
56630 + read_unlock(&tasklist_lock);
56631 + return ret;
56632 +#endif
56633 + return 0;
56634 +}
56635 +
56636 +int
56637 +gr_pid_is_chrooted(struct task_struct *p)
56638 +{
56639 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56640 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56641 + return 0;
56642 +
56643 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56644 + !have_same_root(current, p)) {
56645 + return 1;
56646 + }
56647 +#endif
56648 + return 0;
56649 +}
56650 +
56651 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56652 +
56653 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56654 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56655 +{
56656 + struct path path, currentroot;
56657 + int ret = 0;
56658 +
56659 + path.dentry = (struct dentry *)u_dentry;
56660 + path.mnt = (struct vfsmount *)u_mnt;
56661 + get_fs_root(current->fs, &currentroot);
56662 + if (path_is_under(&path, &currentroot))
56663 + ret = 1;
56664 + path_put(&currentroot);
56665 +
56666 + return ret;
56667 +}
56668 +#endif
56669 +
56670 +int
56671 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56672 +{
56673 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56674 + if (!grsec_enable_chroot_fchdir)
56675 + return 1;
56676 +
56677 + if (!proc_is_chrooted(current))
56678 + return 1;
56679 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56680 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56681 + return 0;
56682 + }
56683 +#endif
56684 + return 1;
56685 +}
56686 +
56687 +int
56688 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56689 + const time_t shm_createtime)
56690 +{
56691 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56692 + struct task_struct *p;
56693 + time_t starttime;
56694 +
56695 + if (unlikely(!grsec_enable_chroot_shmat))
56696 + return 1;
56697 +
56698 + if (likely(!proc_is_chrooted(current)))
56699 + return 1;
56700 +
56701 + rcu_read_lock();
56702 + read_lock(&tasklist_lock);
56703 +
56704 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56705 + starttime = p->start_time.tv_sec;
56706 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56707 + if (have_same_root(current, p)) {
56708 + goto allow;
56709 + } else {
56710 + read_unlock(&tasklist_lock);
56711 + rcu_read_unlock();
56712 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56713 + return 0;
56714 + }
56715 + }
56716 + /* creator exited, pid reuse, fall through to next check */
56717 + }
56718 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56719 + if (unlikely(!have_same_root(current, p))) {
56720 + read_unlock(&tasklist_lock);
56721 + rcu_read_unlock();
56722 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56723 + return 0;
56724 + }
56725 + }
56726 +
56727 +allow:
56728 + read_unlock(&tasklist_lock);
56729 + rcu_read_unlock();
56730 +#endif
56731 + return 1;
56732 +}
56733 +
56734 +void
56735 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56736 +{
56737 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56738 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56739 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56740 +#endif
56741 + return;
56742 +}
56743 +
56744 +int
56745 +gr_handle_chroot_mknod(const struct dentry *dentry,
56746 + const struct vfsmount *mnt, const int mode)
56747 +{
56748 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56749 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56750 + proc_is_chrooted(current)) {
56751 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56752 + return -EPERM;
56753 + }
56754 +#endif
56755 + return 0;
56756 +}
56757 +
56758 +int
56759 +gr_handle_chroot_mount(const struct dentry *dentry,
56760 + const struct vfsmount *mnt, const char *dev_name)
56761 +{
56762 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56763 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56764 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56765 + return -EPERM;
56766 + }
56767 +#endif
56768 + return 0;
56769 +}
56770 +
56771 +int
56772 +gr_handle_chroot_pivot(void)
56773 +{
56774 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56775 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56776 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56777 + return -EPERM;
56778 + }
56779 +#endif
56780 + return 0;
56781 +}
56782 +
56783 +int
56784 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56785 +{
56786 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56787 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56788 + !gr_is_outside_chroot(dentry, mnt)) {
56789 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56790 + return -EPERM;
56791 + }
56792 +#endif
56793 + return 0;
56794 +}
56795 +
56796 +extern const char *captab_log[];
56797 +extern int captab_log_entries;
56798 +
56799 +int
56800 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56801 +{
56802 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56803 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56804 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56805 + if (cap_raised(chroot_caps, cap)) {
56806 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56807 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56808 + }
56809 + return 0;
56810 + }
56811 + }
56812 +#endif
56813 + return 1;
56814 +}
56815 +
56816 +int
56817 +gr_chroot_is_capable(const int cap)
56818 +{
56819 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56820 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56821 +#endif
56822 + return 1;
56823 +}
56824 +
56825 +int
56826 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56827 +{
56828 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56829 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56830 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56831 + if (cap_raised(chroot_caps, cap)) {
56832 + return 0;
56833 + }
56834 + }
56835 +#endif
56836 + return 1;
56837 +}
56838 +
56839 +int
56840 +gr_chroot_is_capable_nolog(const int cap)
56841 +{
56842 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56843 + return gr_task_chroot_is_capable_nolog(current, cap);
56844 +#endif
56845 + return 1;
56846 +}
56847 +
56848 +int
56849 +gr_handle_chroot_sysctl(const int op)
56850 +{
56851 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56852 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56853 + proc_is_chrooted(current))
56854 + return -EACCES;
56855 +#endif
56856 + return 0;
56857 +}
56858 +
56859 +void
56860 +gr_handle_chroot_chdir(struct path *path)
56861 +{
56862 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56863 + if (grsec_enable_chroot_chdir)
56864 + set_fs_pwd(current->fs, path);
56865 +#endif
56866 + return;
56867 +}
56868 +
56869 +int
56870 +gr_handle_chroot_chmod(const struct dentry *dentry,
56871 + const struct vfsmount *mnt, const int mode)
56872 +{
56873 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56874 + /* allow chmod +s on directories, but not files */
56875 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56876 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56877 + proc_is_chrooted(current)) {
56878 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56879 + return -EPERM;
56880 + }
56881 +#endif
56882 + return 0;
56883 +}
56884 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56885 new file mode 100644
56886 index 0000000..213ad8b
56887 --- /dev/null
56888 +++ b/grsecurity/grsec_disabled.c
56889 @@ -0,0 +1,437 @@
56890 +#include <linux/kernel.h>
56891 +#include <linux/module.h>
56892 +#include <linux/sched.h>
56893 +#include <linux/file.h>
56894 +#include <linux/fs.h>
56895 +#include <linux/kdev_t.h>
56896 +#include <linux/net.h>
56897 +#include <linux/in.h>
56898 +#include <linux/ip.h>
56899 +#include <linux/skbuff.h>
56900 +#include <linux/sysctl.h>
56901 +
56902 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56903 +void
56904 +pax_set_initial_flags(struct linux_binprm *bprm)
56905 +{
56906 + return;
56907 +}
56908 +#endif
56909 +
56910 +#ifdef CONFIG_SYSCTL
56911 +__u32
56912 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56913 +{
56914 + return 0;
56915 +}
56916 +#endif
56917 +
56918 +#ifdef CONFIG_TASKSTATS
56919 +int gr_is_taskstats_denied(int pid)
56920 +{
56921 + return 0;
56922 +}
56923 +#endif
56924 +
56925 +int
56926 +gr_acl_is_enabled(void)
56927 +{
56928 + return 0;
56929 +}
56930 +
56931 +void
56932 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56933 +{
56934 + return;
56935 +}
56936 +
56937 +int
56938 +gr_handle_rawio(const struct inode *inode)
56939 +{
56940 + return 0;
56941 +}
56942 +
56943 +void
56944 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56945 +{
56946 + return;
56947 +}
56948 +
56949 +int
56950 +gr_handle_ptrace(struct task_struct *task, const long request)
56951 +{
56952 + return 0;
56953 +}
56954 +
56955 +int
56956 +gr_handle_proc_ptrace(struct task_struct *task)
56957 +{
56958 + return 0;
56959 +}
56960 +
56961 +void
56962 +gr_learn_resource(const struct task_struct *task,
56963 + const int res, const unsigned long wanted, const int gt)
56964 +{
56965 + return;
56966 +}
56967 +
56968 +int
56969 +gr_set_acls(const int type)
56970 +{
56971 + return 0;
56972 +}
56973 +
56974 +int
56975 +gr_check_hidden_task(const struct task_struct *tsk)
56976 +{
56977 + return 0;
56978 +}
56979 +
56980 +int
56981 +gr_check_protected_task(const struct task_struct *task)
56982 +{
56983 + return 0;
56984 +}
56985 +
56986 +int
56987 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56988 +{
56989 + return 0;
56990 +}
56991 +
56992 +void
56993 +gr_copy_label(struct task_struct *tsk)
56994 +{
56995 + return;
56996 +}
56997 +
56998 +void
56999 +gr_set_pax_flags(struct task_struct *task)
57000 +{
57001 + return;
57002 +}
57003 +
57004 +int
57005 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57006 + const int unsafe_share)
57007 +{
57008 + return 0;
57009 +}
57010 +
57011 +void
57012 +gr_handle_delete(const ino_t ino, const dev_t dev)
57013 +{
57014 + return;
57015 +}
57016 +
57017 +void
57018 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57019 +{
57020 + return;
57021 +}
57022 +
57023 +void
57024 +gr_handle_crash(struct task_struct *task, const int sig)
57025 +{
57026 + return;
57027 +}
57028 +
57029 +int
57030 +gr_check_crash_exec(const struct file *filp)
57031 +{
57032 + return 0;
57033 +}
57034 +
57035 +int
57036 +gr_check_crash_uid(const uid_t uid)
57037 +{
57038 + return 0;
57039 +}
57040 +
57041 +void
57042 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57043 + struct dentry *old_dentry,
57044 + struct dentry *new_dentry,
57045 + struct vfsmount *mnt, const __u8 replace)
57046 +{
57047 + return;
57048 +}
57049 +
57050 +int
57051 +gr_search_socket(const int family, const int type, const int protocol)
57052 +{
57053 + return 1;
57054 +}
57055 +
57056 +int
57057 +gr_search_connectbind(const int mode, const struct socket *sock,
57058 + const struct sockaddr_in *addr)
57059 +{
57060 + return 0;
57061 +}
57062 +
57063 +void
57064 +gr_handle_alertkill(struct task_struct *task)
57065 +{
57066 + return;
57067 +}
57068 +
57069 +__u32
57070 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57071 +{
57072 + return 1;
57073 +}
57074 +
57075 +__u32
57076 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57077 + const struct vfsmount * mnt)
57078 +{
57079 + return 1;
57080 +}
57081 +
57082 +__u32
57083 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57084 + int acc_mode)
57085 +{
57086 + return 1;
57087 +}
57088 +
57089 +__u32
57090 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57091 +{
57092 + return 1;
57093 +}
57094 +
57095 +__u32
57096 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57097 +{
57098 + return 1;
57099 +}
57100 +
57101 +int
57102 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57103 + unsigned int *vm_flags)
57104 +{
57105 + return 1;
57106 +}
57107 +
57108 +__u32
57109 +gr_acl_handle_truncate(const struct dentry * dentry,
57110 + const struct vfsmount * mnt)
57111 +{
57112 + return 1;
57113 +}
57114 +
57115 +__u32
57116 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57117 +{
57118 + return 1;
57119 +}
57120 +
57121 +__u32
57122 +gr_acl_handle_access(const struct dentry * dentry,
57123 + const struct vfsmount * mnt, const int fmode)
57124 +{
57125 + return 1;
57126 +}
57127 +
57128 +__u32
57129 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57130 + umode_t *mode)
57131 +{
57132 + return 1;
57133 +}
57134 +
57135 +__u32
57136 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57137 +{
57138 + return 1;
57139 +}
57140 +
57141 +__u32
57142 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57143 +{
57144 + return 1;
57145 +}
57146 +
57147 +void
57148 +grsecurity_init(void)
57149 +{
57150 + return;
57151 +}
57152 +
57153 +umode_t gr_acl_umask(void)
57154 +{
57155 + return 0;
57156 +}
57157 +
57158 +__u32
57159 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57160 + const struct dentry * parent_dentry,
57161 + const struct vfsmount * parent_mnt,
57162 + const int mode)
57163 +{
57164 + return 1;
57165 +}
57166 +
57167 +__u32
57168 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57169 + const struct dentry * parent_dentry,
57170 + const struct vfsmount * parent_mnt)
57171 +{
57172 + return 1;
57173 +}
57174 +
57175 +__u32
57176 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57177 + const struct dentry * parent_dentry,
57178 + const struct vfsmount * parent_mnt, const char *from)
57179 +{
57180 + return 1;
57181 +}
57182 +
57183 +__u32
57184 +gr_acl_handle_link(const struct dentry * new_dentry,
57185 + const struct dentry * parent_dentry,
57186 + const struct vfsmount * parent_mnt,
57187 + const struct dentry * old_dentry,
57188 + const struct vfsmount * old_mnt, const char *to)
57189 +{
57190 + return 1;
57191 +}
57192 +
57193 +int
57194 +gr_acl_handle_rename(const struct dentry *new_dentry,
57195 + const struct dentry *parent_dentry,
57196 + const struct vfsmount *parent_mnt,
57197 + const struct dentry *old_dentry,
57198 + const struct inode *old_parent_inode,
57199 + const struct vfsmount *old_mnt, const char *newname)
57200 +{
57201 + return 0;
57202 +}
57203 +
57204 +int
57205 +gr_acl_handle_filldir(const struct file *file, const char *name,
57206 + const int namelen, const ino_t ino)
57207 +{
57208 + return 1;
57209 +}
57210 +
57211 +int
57212 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57213 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57214 +{
57215 + return 1;
57216 +}
57217 +
57218 +int
57219 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57220 +{
57221 + return 0;
57222 +}
57223 +
57224 +int
57225 +gr_search_accept(const struct socket *sock)
57226 +{
57227 + return 0;
57228 +}
57229 +
57230 +int
57231 +gr_search_listen(const struct socket *sock)
57232 +{
57233 + return 0;
57234 +}
57235 +
57236 +int
57237 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57238 +{
57239 + return 0;
57240 +}
57241 +
57242 +__u32
57243 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57244 +{
57245 + return 1;
57246 +}
57247 +
57248 +__u32
57249 +gr_acl_handle_creat(const struct dentry * dentry,
57250 + const struct dentry * p_dentry,
57251 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57252 + const int imode)
57253 +{
57254 + return 1;
57255 +}
57256 +
57257 +void
57258 +gr_acl_handle_exit(void)
57259 +{
57260 + return;
57261 +}
57262 +
57263 +int
57264 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57265 +{
57266 + return 1;
57267 +}
57268 +
57269 +void
57270 +gr_set_role_label(const uid_t uid, const gid_t gid)
57271 +{
57272 + return;
57273 +}
57274 +
57275 +int
57276 +gr_acl_handle_procpidmem(const struct task_struct *task)
57277 +{
57278 + return 0;
57279 +}
57280 +
57281 +int
57282 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57283 +{
57284 + return 0;
57285 +}
57286 +
57287 +int
57288 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57289 +{
57290 + return 0;
57291 +}
57292 +
57293 +void
57294 +gr_set_kernel_label(struct task_struct *task)
57295 +{
57296 + return;
57297 +}
57298 +
57299 +int
57300 +gr_check_user_change(int real, int effective, int fs)
57301 +{
57302 + return 0;
57303 +}
57304 +
57305 +int
57306 +gr_check_group_change(int real, int effective, int fs)
57307 +{
57308 + return 0;
57309 +}
57310 +
57311 +int gr_acl_enable_at_secure(void)
57312 +{
57313 + return 0;
57314 +}
57315 +
57316 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57317 +{
57318 + return dentry->d_inode->i_sb->s_dev;
57319 +}
57320 +
57321 +EXPORT_SYMBOL(gr_learn_resource);
57322 +EXPORT_SYMBOL(gr_set_kernel_label);
57323 +#ifdef CONFIG_SECURITY
57324 +EXPORT_SYMBOL(gr_check_user_change);
57325 +EXPORT_SYMBOL(gr_check_group_change);
57326 +#endif
57327 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57328 new file mode 100644
57329 index 0000000..abfa971
57330 --- /dev/null
57331 +++ b/grsecurity/grsec_exec.c
57332 @@ -0,0 +1,174 @@
57333 +#include <linux/kernel.h>
57334 +#include <linux/sched.h>
57335 +#include <linux/file.h>
57336 +#include <linux/binfmts.h>
57337 +#include <linux/fs.h>
57338 +#include <linux/types.h>
57339 +#include <linux/grdefs.h>
57340 +#include <linux/grsecurity.h>
57341 +#include <linux/grinternal.h>
57342 +#include <linux/capability.h>
57343 +#include <linux/module.h>
57344 +
57345 +#include <asm/uaccess.h>
57346 +
57347 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57348 +static char gr_exec_arg_buf[132];
57349 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57350 +#endif
57351 +
57352 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57353 +
57354 +void
57355 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57356 +{
57357 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57358 + char *grarg = gr_exec_arg_buf;
57359 + unsigned int i, x, execlen = 0;
57360 + char c;
57361 +
57362 + if (!((grsec_enable_execlog && grsec_enable_group &&
57363 + in_group_p(grsec_audit_gid))
57364 + || (grsec_enable_execlog && !grsec_enable_group)))
57365 + return;
57366 +
57367 + mutex_lock(&gr_exec_arg_mutex);
57368 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57369 +
57370 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57371 + const char __user *p;
57372 + unsigned int len;
57373 +
57374 + p = get_user_arg_ptr(argv, i);
57375 + if (IS_ERR(p))
57376 + goto log;
57377 +
57378 + len = strnlen_user(p, 128 - execlen);
57379 + if (len > 128 - execlen)
57380 + len = 128 - execlen;
57381 + else if (len > 0)
57382 + len--;
57383 + if (copy_from_user(grarg + execlen, p, len))
57384 + goto log;
57385 +
57386 + /* rewrite unprintable characters */
57387 + for (x = 0; x < len; x++) {
57388 + c = *(grarg + execlen + x);
57389 + if (c < 32 || c > 126)
57390 + *(grarg + execlen + x) = ' ';
57391 + }
57392 +
57393 + execlen += len;
57394 + *(grarg + execlen) = ' ';
57395 + *(grarg + execlen + 1) = '\0';
57396 + execlen++;
57397 + }
57398 +
57399 + log:
57400 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57401 + bprm->file->f_path.mnt, grarg);
57402 + mutex_unlock(&gr_exec_arg_mutex);
57403 +#endif
57404 + return;
57405 +}
57406 +
57407 +#ifdef CONFIG_GRKERNSEC
57408 +extern int gr_acl_is_capable(const int cap);
57409 +extern int gr_acl_is_capable_nolog(const int cap);
57410 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57411 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57412 +extern int gr_chroot_is_capable(const int cap);
57413 +extern int gr_chroot_is_capable_nolog(const int cap);
57414 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57415 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57416 +#endif
57417 +
57418 +const char *captab_log[] = {
57419 + "CAP_CHOWN",
57420 + "CAP_DAC_OVERRIDE",
57421 + "CAP_DAC_READ_SEARCH",
57422 + "CAP_FOWNER",
57423 + "CAP_FSETID",
57424 + "CAP_KILL",
57425 + "CAP_SETGID",
57426 + "CAP_SETUID",
57427 + "CAP_SETPCAP",
57428 + "CAP_LINUX_IMMUTABLE",
57429 + "CAP_NET_BIND_SERVICE",
57430 + "CAP_NET_BROADCAST",
57431 + "CAP_NET_ADMIN",
57432 + "CAP_NET_RAW",
57433 + "CAP_IPC_LOCK",
57434 + "CAP_IPC_OWNER",
57435 + "CAP_SYS_MODULE",
57436 + "CAP_SYS_RAWIO",
57437 + "CAP_SYS_CHROOT",
57438 + "CAP_SYS_PTRACE",
57439 + "CAP_SYS_PACCT",
57440 + "CAP_SYS_ADMIN",
57441 + "CAP_SYS_BOOT",
57442 + "CAP_SYS_NICE",
57443 + "CAP_SYS_RESOURCE",
57444 + "CAP_SYS_TIME",
57445 + "CAP_SYS_TTY_CONFIG",
57446 + "CAP_MKNOD",
57447 + "CAP_LEASE",
57448 + "CAP_AUDIT_WRITE",
57449 + "CAP_AUDIT_CONTROL",
57450 + "CAP_SETFCAP",
57451 + "CAP_MAC_OVERRIDE",
57452 + "CAP_MAC_ADMIN",
57453 + "CAP_SYSLOG",
57454 + "CAP_WAKE_ALARM"
57455 +};
57456 +
57457 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57458 +
57459 +int gr_is_capable(const int cap)
57460 +{
57461 +#ifdef CONFIG_GRKERNSEC
57462 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57463 + return 1;
57464 + return 0;
57465 +#else
57466 + return 1;
57467 +#endif
57468 +}
57469 +
57470 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57471 +{
57472 +#ifdef CONFIG_GRKERNSEC
57473 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57474 + return 1;
57475 + return 0;
57476 +#else
57477 + return 1;
57478 +#endif
57479 +}
57480 +
57481 +int gr_is_capable_nolog(const int cap)
57482 +{
57483 +#ifdef CONFIG_GRKERNSEC
57484 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57485 + return 1;
57486 + return 0;
57487 +#else
57488 + return 1;
57489 +#endif
57490 +}
57491 +
57492 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57493 +{
57494 +#ifdef CONFIG_GRKERNSEC
57495 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57496 + return 1;
57497 + return 0;
57498 +#else
57499 + return 1;
57500 +#endif
57501 +}
57502 +
57503 +EXPORT_SYMBOL(gr_is_capable);
57504 +EXPORT_SYMBOL(gr_is_capable_nolog);
57505 +EXPORT_SYMBOL(gr_task_is_capable);
57506 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57507 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57508 new file mode 100644
57509 index 0000000..d3ee748
57510 --- /dev/null
57511 +++ b/grsecurity/grsec_fifo.c
57512 @@ -0,0 +1,24 @@
57513 +#include <linux/kernel.h>
57514 +#include <linux/sched.h>
57515 +#include <linux/fs.h>
57516 +#include <linux/file.h>
57517 +#include <linux/grinternal.h>
57518 +
57519 +int
57520 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57521 + const struct dentry *dir, const int flag, const int acc_mode)
57522 +{
57523 +#ifdef CONFIG_GRKERNSEC_FIFO
57524 + const struct cred *cred = current_cred();
57525 +
57526 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57527 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57528 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57529 + (cred->fsuid != dentry->d_inode->i_uid)) {
57530 + if (!inode_permission(dentry->d_inode, acc_mode))
57531 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57532 + return -EACCES;
57533 + }
57534 +#endif
57535 + return 0;
57536 +}
57537 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57538 new file mode 100644
57539 index 0000000..8ca18bf
57540 --- /dev/null
57541 +++ b/grsecurity/grsec_fork.c
57542 @@ -0,0 +1,23 @@
57543 +#include <linux/kernel.h>
57544 +#include <linux/sched.h>
57545 +#include <linux/grsecurity.h>
57546 +#include <linux/grinternal.h>
57547 +#include <linux/errno.h>
57548 +
57549 +void
57550 +gr_log_forkfail(const int retval)
57551 +{
57552 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57553 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57554 + switch (retval) {
57555 + case -EAGAIN:
57556 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57557 + break;
57558 + case -ENOMEM:
57559 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57560 + break;
57561 + }
57562 + }
57563 +#endif
57564 + return;
57565 +}
57566 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57567 new file mode 100644
57568 index 0000000..01ddde4
57569 --- /dev/null
57570 +++ b/grsecurity/grsec_init.c
57571 @@ -0,0 +1,277 @@
57572 +#include <linux/kernel.h>
57573 +#include <linux/sched.h>
57574 +#include <linux/mm.h>
57575 +#include <linux/gracl.h>
57576 +#include <linux/slab.h>
57577 +#include <linux/vmalloc.h>
57578 +#include <linux/percpu.h>
57579 +#include <linux/module.h>
57580 +
57581 +int grsec_enable_ptrace_readexec;
57582 +int grsec_enable_setxid;
57583 +int grsec_enable_brute;
57584 +int grsec_enable_link;
57585 +int grsec_enable_dmesg;
57586 +int grsec_enable_harden_ptrace;
57587 +int grsec_enable_fifo;
57588 +int grsec_enable_execlog;
57589 +int grsec_enable_signal;
57590 +int grsec_enable_forkfail;
57591 +int grsec_enable_audit_ptrace;
57592 +int grsec_enable_time;
57593 +int grsec_enable_audit_textrel;
57594 +int grsec_enable_group;
57595 +int grsec_audit_gid;
57596 +int grsec_enable_chdir;
57597 +int grsec_enable_mount;
57598 +int grsec_enable_rofs;
57599 +int grsec_enable_chroot_findtask;
57600 +int grsec_enable_chroot_mount;
57601 +int grsec_enable_chroot_shmat;
57602 +int grsec_enable_chroot_fchdir;
57603 +int grsec_enable_chroot_double;
57604 +int grsec_enable_chroot_pivot;
57605 +int grsec_enable_chroot_chdir;
57606 +int grsec_enable_chroot_chmod;
57607 +int grsec_enable_chroot_mknod;
57608 +int grsec_enable_chroot_nice;
57609 +int grsec_enable_chroot_execlog;
57610 +int grsec_enable_chroot_caps;
57611 +int grsec_enable_chroot_sysctl;
57612 +int grsec_enable_chroot_unix;
57613 +int grsec_enable_tpe;
57614 +int grsec_tpe_gid;
57615 +int grsec_enable_blackhole;
57616 +#ifdef CONFIG_IPV6_MODULE
57617 +EXPORT_SYMBOL(grsec_enable_blackhole);
57618 +#endif
57619 +int grsec_lastack_retries;
57620 +int grsec_enable_tpe_all;
57621 +int grsec_enable_tpe_invert;
57622 +int grsec_enable_socket_all;
57623 +int grsec_socket_all_gid;
57624 +int grsec_enable_socket_client;
57625 +int grsec_socket_client_gid;
57626 +int grsec_enable_socket_server;
57627 +int grsec_socket_server_gid;
57628 +int grsec_resource_logging;
57629 +int grsec_disable_privio;
57630 +int grsec_enable_log_rwxmaps;
57631 +int grsec_lock;
57632 +
57633 +DEFINE_SPINLOCK(grsec_alert_lock);
57634 +unsigned long grsec_alert_wtime = 0;
57635 +unsigned long grsec_alert_fyet = 0;
57636 +
57637 +DEFINE_SPINLOCK(grsec_audit_lock);
57638 +
57639 +DEFINE_RWLOCK(grsec_exec_file_lock);
57640 +
57641 +char *gr_shared_page[4];
57642 +
57643 +char *gr_alert_log_fmt;
57644 +char *gr_audit_log_fmt;
57645 +char *gr_alert_log_buf;
57646 +char *gr_audit_log_buf;
57647 +
57648 +extern struct gr_arg *gr_usermode;
57649 +extern unsigned char *gr_system_salt;
57650 +extern unsigned char *gr_system_sum;
57651 +
57652 +void __init
57653 +grsecurity_init(void)
57654 +{
57655 + int j;
57656 + /* create the per-cpu shared pages */
57657 +
57658 +#ifdef CONFIG_X86
57659 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57660 +#endif
57661 +
57662 + for (j = 0; j < 4; j++) {
57663 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57664 + if (gr_shared_page[j] == NULL) {
57665 + panic("Unable to allocate grsecurity shared page");
57666 + return;
57667 + }
57668 + }
57669 +
57670 + /* allocate log buffers */
57671 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57672 + if (!gr_alert_log_fmt) {
57673 + panic("Unable to allocate grsecurity alert log format buffer");
57674 + return;
57675 + }
57676 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57677 + if (!gr_audit_log_fmt) {
57678 + panic("Unable to allocate grsecurity audit log format buffer");
57679 + return;
57680 + }
57681 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57682 + if (!gr_alert_log_buf) {
57683 + panic("Unable to allocate grsecurity alert log buffer");
57684 + return;
57685 + }
57686 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57687 + if (!gr_audit_log_buf) {
57688 + panic("Unable to allocate grsecurity audit log buffer");
57689 + return;
57690 + }
57691 +
57692 + /* allocate memory for authentication structure */
57693 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57694 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57695 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57696 +
57697 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57698 + panic("Unable to allocate grsecurity authentication structure");
57699 + return;
57700 + }
57701 +
57702 +
57703 +#ifdef CONFIG_GRKERNSEC_IO
57704 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57705 + grsec_disable_privio = 1;
57706 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57707 + grsec_disable_privio = 1;
57708 +#else
57709 + grsec_disable_privio = 0;
57710 +#endif
57711 +#endif
57712 +
57713 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57714 + /* for backward compatibility, tpe_invert always defaults to on if
57715 + enabled in the kernel
57716 + */
57717 + grsec_enable_tpe_invert = 1;
57718 +#endif
57719 +
57720 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57721 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57722 + grsec_lock = 1;
57723 +#endif
57724 +
57725 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57726 + grsec_enable_audit_textrel = 1;
57727 +#endif
57728 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57729 + grsec_enable_log_rwxmaps = 1;
57730 +#endif
57731 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57732 + grsec_enable_group = 1;
57733 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57734 +#endif
57735 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57736 + grsec_enable_ptrace_readexec = 1;
57737 +#endif
57738 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57739 + grsec_enable_chdir = 1;
57740 +#endif
57741 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57742 + grsec_enable_harden_ptrace = 1;
57743 +#endif
57744 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57745 + grsec_enable_mount = 1;
57746 +#endif
57747 +#ifdef CONFIG_GRKERNSEC_LINK
57748 + grsec_enable_link = 1;
57749 +#endif
57750 +#ifdef CONFIG_GRKERNSEC_BRUTE
57751 + grsec_enable_brute = 1;
57752 +#endif
57753 +#ifdef CONFIG_GRKERNSEC_DMESG
57754 + grsec_enable_dmesg = 1;
57755 +#endif
57756 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57757 + grsec_enable_blackhole = 1;
57758 + grsec_lastack_retries = 4;
57759 +#endif
57760 +#ifdef CONFIG_GRKERNSEC_FIFO
57761 + grsec_enable_fifo = 1;
57762 +#endif
57763 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57764 + grsec_enable_execlog = 1;
57765 +#endif
57766 +#ifdef CONFIG_GRKERNSEC_SETXID
57767 + grsec_enable_setxid = 1;
57768 +#endif
57769 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57770 + grsec_enable_signal = 1;
57771 +#endif
57772 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57773 + grsec_enable_forkfail = 1;
57774 +#endif
57775 +#ifdef CONFIG_GRKERNSEC_TIME
57776 + grsec_enable_time = 1;
57777 +#endif
57778 +#ifdef CONFIG_GRKERNSEC_RESLOG
57779 + grsec_resource_logging = 1;
57780 +#endif
57781 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57782 + grsec_enable_chroot_findtask = 1;
57783 +#endif
57784 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57785 + grsec_enable_chroot_unix = 1;
57786 +#endif
57787 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57788 + grsec_enable_chroot_mount = 1;
57789 +#endif
57790 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57791 + grsec_enable_chroot_fchdir = 1;
57792 +#endif
57793 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57794 + grsec_enable_chroot_shmat = 1;
57795 +#endif
57796 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57797 + grsec_enable_audit_ptrace = 1;
57798 +#endif
57799 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57800 + grsec_enable_chroot_double = 1;
57801 +#endif
57802 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57803 + grsec_enable_chroot_pivot = 1;
57804 +#endif
57805 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57806 + grsec_enable_chroot_chdir = 1;
57807 +#endif
57808 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57809 + grsec_enable_chroot_chmod = 1;
57810 +#endif
57811 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57812 + grsec_enable_chroot_mknod = 1;
57813 +#endif
57814 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57815 + grsec_enable_chroot_nice = 1;
57816 +#endif
57817 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57818 + grsec_enable_chroot_execlog = 1;
57819 +#endif
57820 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57821 + grsec_enable_chroot_caps = 1;
57822 +#endif
57823 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57824 + grsec_enable_chroot_sysctl = 1;
57825 +#endif
57826 +#ifdef CONFIG_GRKERNSEC_TPE
57827 + grsec_enable_tpe = 1;
57828 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57829 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57830 + grsec_enable_tpe_all = 1;
57831 +#endif
57832 +#endif
57833 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57834 + grsec_enable_socket_all = 1;
57835 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57836 +#endif
57837 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57838 + grsec_enable_socket_client = 1;
57839 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57840 +#endif
57841 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57842 + grsec_enable_socket_server = 1;
57843 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57844 +#endif
57845 +#endif
57846 +
57847 + return;
57848 +}
57849 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57850 new file mode 100644
57851 index 0000000..3efe141
57852 --- /dev/null
57853 +++ b/grsecurity/grsec_link.c
57854 @@ -0,0 +1,43 @@
57855 +#include <linux/kernel.h>
57856 +#include <linux/sched.h>
57857 +#include <linux/fs.h>
57858 +#include <linux/file.h>
57859 +#include <linux/grinternal.h>
57860 +
57861 +int
57862 +gr_handle_follow_link(const struct inode *parent,
57863 + const struct inode *inode,
57864 + const struct dentry *dentry, const struct vfsmount *mnt)
57865 +{
57866 +#ifdef CONFIG_GRKERNSEC_LINK
57867 + const struct cred *cred = current_cred();
57868 +
57869 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57870 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57871 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57872 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57873 + return -EACCES;
57874 + }
57875 +#endif
57876 + return 0;
57877 +}
57878 +
57879 +int
57880 +gr_handle_hardlink(const struct dentry *dentry,
57881 + const struct vfsmount *mnt,
57882 + struct inode *inode, const int mode, const char *to)
57883 +{
57884 +#ifdef CONFIG_GRKERNSEC_LINK
57885 + const struct cred *cred = current_cred();
57886 +
57887 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57888 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57889 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57890 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57891 + !capable(CAP_FOWNER) && cred->uid) {
57892 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57893 + return -EPERM;
57894 + }
57895 +#endif
57896 + return 0;
57897 +}
57898 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57899 new file mode 100644
57900 index 0000000..a45d2e9
57901 --- /dev/null
57902 +++ b/grsecurity/grsec_log.c
57903 @@ -0,0 +1,322 @@
57904 +#include <linux/kernel.h>
57905 +#include <linux/sched.h>
57906 +#include <linux/file.h>
57907 +#include <linux/tty.h>
57908 +#include <linux/fs.h>
57909 +#include <linux/grinternal.h>
57910 +
57911 +#ifdef CONFIG_TREE_PREEMPT_RCU
57912 +#define DISABLE_PREEMPT() preempt_disable()
57913 +#define ENABLE_PREEMPT() preempt_enable()
57914 +#else
57915 +#define DISABLE_PREEMPT()
57916 +#define ENABLE_PREEMPT()
57917 +#endif
57918 +
57919 +#define BEGIN_LOCKS(x) \
57920 + DISABLE_PREEMPT(); \
57921 + rcu_read_lock(); \
57922 + read_lock(&tasklist_lock); \
57923 + read_lock(&grsec_exec_file_lock); \
57924 + if (x != GR_DO_AUDIT) \
57925 + spin_lock(&grsec_alert_lock); \
57926 + else \
57927 + spin_lock(&grsec_audit_lock)
57928 +
57929 +#define END_LOCKS(x) \
57930 + if (x != GR_DO_AUDIT) \
57931 + spin_unlock(&grsec_alert_lock); \
57932 + else \
57933 + spin_unlock(&grsec_audit_lock); \
57934 + read_unlock(&grsec_exec_file_lock); \
57935 + read_unlock(&tasklist_lock); \
57936 + rcu_read_unlock(); \
57937 + ENABLE_PREEMPT(); \
57938 + if (x == GR_DONT_AUDIT) \
57939 + gr_handle_alertkill(current)
57940 +
57941 +enum {
57942 + FLOODING,
57943 + NO_FLOODING
57944 +};
57945 +
57946 +extern char *gr_alert_log_fmt;
57947 +extern char *gr_audit_log_fmt;
57948 +extern char *gr_alert_log_buf;
57949 +extern char *gr_audit_log_buf;
57950 +
57951 +static int gr_log_start(int audit)
57952 +{
57953 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57954 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57955 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57956 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57957 + unsigned long curr_secs = get_seconds();
57958 +
57959 + if (audit == GR_DO_AUDIT)
57960 + goto set_fmt;
57961 +
57962 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57963 + grsec_alert_wtime = curr_secs;
57964 + grsec_alert_fyet = 0;
57965 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57966 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57967 + grsec_alert_fyet++;
57968 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57969 + grsec_alert_wtime = curr_secs;
57970 + grsec_alert_fyet++;
57971 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57972 + return FLOODING;
57973 + }
57974 + else return FLOODING;
57975 +
57976 +set_fmt:
57977 +#endif
57978 + memset(buf, 0, PAGE_SIZE);
57979 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57980 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57981 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57982 + } else if (current->signal->curr_ip) {
57983 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57984 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57985 + } else if (gr_acl_is_enabled()) {
57986 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57987 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57988 + } else {
57989 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57990 + strcpy(buf, fmt);
57991 + }
57992 +
57993 + return NO_FLOODING;
57994 +}
57995 +
57996 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57997 + __attribute__ ((format (printf, 2, 0)));
57998 +
57999 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58000 +{
58001 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58002 + unsigned int len = strlen(buf);
58003 +
58004 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58005 +
58006 + return;
58007 +}
58008 +
58009 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58010 + __attribute__ ((format (printf, 2, 3)));
58011 +
58012 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58013 +{
58014 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58015 + unsigned int len = strlen(buf);
58016 + va_list ap;
58017 +
58018 + va_start(ap, msg);
58019 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58020 + va_end(ap);
58021 +
58022 + return;
58023 +}
58024 +
58025 +static void gr_log_end(int audit, int append_default)
58026 +{
58027 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58028 +
58029 + if (append_default) {
58030 + unsigned int len = strlen(buf);
58031 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58032 + }
58033 +
58034 + printk("%s\n", buf);
58035 +
58036 + return;
58037 +}
58038 +
58039 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58040 +{
58041 + int logtype;
58042 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58043 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58044 + void *voidptr = NULL;
58045 + int num1 = 0, num2 = 0;
58046 + unsigned long ulong1 = 0, ulong2 = 0;
58047 + struct dentry *dentry = NULL;
58048 + struct vfsmount *mnt = NULL;
58049 + struct file *file = NULL;
58050 + struct task_struct *task = NULL;
58051 + const struct cred *cred, *pcred;
58052 + va_list ap;
58053 +
58054 + BEGIN_LOCKS(audit);
58055 + logtype = gr_log_start(audit);
58056 + if (logtype == FLOODING) {
58057 + END_LOCKS(audit);
58058 + return;
58059 + }
58060 + va_start(ap, argtypes);
58061 + switch (argtypes) {
58062 + case GR_TTYSNIFF:
58063 + task = va_arg(ap, struct task_struct *);
58064 + 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);
58065 + break;
58066 + case GR_SYSCTL_HIDDEN:
58067 + str1 = va_arg(ap, char *);
58068 + gr_log_middle_varargs(audit, msg, result, str1);
58069 + break;
58070 + case GR_RBAC:
58071 + dentry = va_arg(ap, struct dentry *);
58072 + mnt = va_arg(ap, struct vfsmount *);
58073 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58074 + break;
58075 + case GR_RBAC_STR:
58076 + dentry = va_arg(ap, struct dentry *);
58077 + mnt = va_arg(ap, struct vfsmount *);
58078 + str1 = va_arg(ap, char *);
58079 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58080 + break;
58081 + case GR_STR_RBAC:
58082 + str1 = va_arg(ap, char *);
58083 + dentry = va_arg(ap, struct dentry *);
58084 + mnt = va_arg(ap, struct vfsmount *);
58085 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58086 + break;
58087 + case GR_RBAC_MODE2:
58088 + dentry = va_arg(ap, struct dentry *);
58089 + mnt = va_arg(ap, struct vfsmount *);
58090 + str1 = va_arg(ap, char *);
58091 + str2 = va_arg(ap, char *);
58092 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58093 + break;
58094 + case GR_RBAC_MODE3:
58095 + dentry = va_arg(ap, struct dentry *);
58096 + mnt = va_arg(ap, struct vfsmount *);
58097 + str1 = va_arg(ap, char *);
58098 + str2 = va_arg(ap, char *);
58099 + str3 = va_arg(ap, char *);
58100 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58101 + break;
58102 + case GR_FILENAME:
58103 + dentry = va_arg(ap, struct dentry *);
58104 + mnt = va_arg(ap, struct vfsmount *);
58105 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58106 + break;
58107 + case GR_STR_FILENAME:
58108 + str1 = va_arg(ap, char *);
58109 + dentry = va_arg(ap, struct dentry *);
58110 + mnt = va_arg(ap, struct vfsmount *);
58111 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58112 + break;
58113 + case GR_FILENAME_STR:
58114 + dentry = va_arg(ap, struct dentry *);
58115 + mnt = va_arg(ap, struct vfsmount *);
58116 + str1 = va_arg(ap, char *);
58117 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58118 + break;
58119 + case GR_FILENAME_TWO_INT:
58120 + dentry = va_arg(ap, struct dentry *);
58121 + mnt = va_arg(ap, struct vfsmount *);
58122 + num1 = va_arg(ap, int);
58123 + num2 = va_arg(ap, int);
58124 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58125 + break;
58126 + case GR_FILENAME_TWO_INT_STR:
58127 + dentry = va_arg(ap, struct dentry *);
58128 + mnt = va_arg(ap, struct vfsmount *);
58129 + num1 = va_arg(ap, int);
58130 + num2 = va_arg(ap, int);
58131 + str1 = va_arg(ap, char *);
58132 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58133 + break;
58134 + case GR_TEXTREL:
58135 + file = va_arg(ap, struct file *);
58136 + ulong1 = va_arg(ap, unsigned long);
58137 + ulong2 = va_arg(ap, unsigned long);
58138 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58139 + break;
58140 + case GR_PTRACE:
58141 + task = va_arg(ap, struct task_struct *);
58142 + 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);
58143 + break;
58144 + case GR_RESOURCE:
58145 + task = va_arg(ap, struct task_struct *);
58146 + cred = __task_cred(task);
58147 + pcred = __task_cred(task->real_parent);
58148 + ulong1 = va_arg(ap, unsigned long);
58149 + str1 = va_arg(ap, char *);
58150 + ulong2 = va_arg(ap, unsigned long);
58151 + 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);
58152 + break;
58153 + case GR_CAP:
58154 + task = va_arg(ap, struct task_struct *);
58155 + cred = __task_cred(task);
58156 + pcred = __task_cred(task->real_parent);
58157 + str1 = va_arg(ap, char *);
58158 + 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);
58159 + break;
58160 + case GR_SIG:
58161 + str1 = va_arg(ap, char *);
58162 + voidptr = va_arg(ap, void *);
58163 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58164 + break;
58165 + case GR_SIG2:
58166 + task = va_arg(ap, struct task_struct *);
58167 + cred = __task_cred(task);
58168 + pcred = __task_cred(task->real_parent);
58169 + num1 = va_arg(ap, int);
58170 + 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);
58171 + break;
58172 + case GR_CRASH1:
58173 + task = va_arg(ap, struct task_struct *);
58174 + cred = __task_cred(task);
58175 + pcred = __task_cred(task->real_parent);
58176 + ulong1 = va_arg(ap, unsigned long);
58177 + 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);
58178 + break;
58179 + case GR_CRASH2:
58180 + task = va_arg(ap, struct task_struct *);
58181 + cred = __task_cred(task);
58182 + pcred = __task_cred(task->real_parent);
58183 + ulong1 = va_arg(ap, unsigned long);
58184 + 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);
58185 + break;
58186 + case GR_RWXMAP:
58187 + file = va_arg(ap, struct file *);
58188 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58189 + break;
58190 + case GR_PSACCT:
58191 + {
58192 + unsigned int wday, cday;
58193 + __u8 whr, chr;
58194 + __u8 wmin, cmin;
58195 + __u8 wsec, csec;
58196 + char cur_tty[64] = { 0 };
58197 + char parent_tty[64] = { 0 };
58198 +
58199 + task = va_arg(ap, struct task_struct *);
58200 + wday = va_arg(ap, unsigned int);
58201 + cday = va_arg(ap, unsigned int);
58202 + whr = va_arg(ap, int);
58203 + chr = va_arg(ap, int);
58204 + wmin = va_arg(ap, int);
58205 + cmin = va_arg(ap, int);
58206 + wsec = va_arg(ap, int);
58207 + csec = va_arg(ap, int);
58208 + ulong1 = va_arg(ap, unsigned long);
58209 + cred = __task_cred(task);
58210 + pcred = __task_cred(task->real_parent);
58211 +
58212 + 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);
58213 + }
58214 + break;
58215 + default:
58216 + gr_log_middle(audit, msg, ap);
58217 + }
58218 + va_end(ap);
58219 + // these don't need DEFAULTSECARGS printed on the end
58220 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58221 + gr_log_end(audit, 0);
58222 + else
58223 + gr_log_end(audit, 1);
58224 + END_LOCKS(audit);
58225 +}
58226 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58227 new file mode 100644
58228 index 0000000..f536303
58229 --- /dev/null
58230 +++ b/grsecurity/grsec_mem.c
58231 @@ -0,0 +1,40 @@
58232 +#include <linux/kernel.h>
58233 +#include <linux/sched.h>
58234 +#include <linux/mm.h>
58235 +#include <linux/mman.h>
58236 +#include <linux/grinternal.h>
58237 +
58238 +void
58239 +gr_handle_ioperm(void)
58240 +{
58241 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58242 + return;
58243 +}
58244 +
58245 +void
58246 +gr_handle_iopl(void)
58247 +{
58248 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58249 + return;
58250 +}
58251 +
58252 +void
58253 +gr_handle_mem_readwrite(u64 from, u64 to)
58254 +{
58255 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58256 + return;
58257 +}
58258 +
58259 +void
58260 +gr_handle_vm86(void)
58261 +{
58262 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58263 + return;
58264 +}
58265 +
58266 +void
58267 +gr_log_badprocpid(const char *entry)
58268 +{
58269 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58270 + return;
58271 +}
58272 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58273 new file mode 100644
58274 index 0000000..2131422
58275 --- /dev/null
58276 +++ b/grsecurity/grsec_mount.c
58277 @@ -0,0 +1,62 @@
58278 +#include <linux/kernel.h>
58279 +#include <linux/sched.h>
58280 +#include <linux/mount.h>
58281 +#include <linux/grsecurity.h>
58282 +#include <linux/grinternal.h>
58283 +
58284 +void
58285 +gr_log_remount(const char *devname, const int retval)
58286 +{
58287 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58288 + if (grsec_enable_mount && (retval >= 0))
58289 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58290 +#endif
58291 + return;
58292 +}
58293 +
58294 +void
58295 +gr_log_unmount(const char *devname, const int retval)
58296 +{
58297 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58298 + if (grsec_enable_mount && (retval >= 0))
58299 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58300 +#endif
58301 + return;
58302 +}
58303 +
58304 +void
58305 +gr_log_mount(const char *from, const char *to, const int retval)
58306 +{
58307 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58308 + if (grsec_enable_mount && (retval >= 0))
58309 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58310 +#endif
58311 + return;
58312 +}
58313 +
58314 +int
58315 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58316 +{
58317 +#ifdef CONFIG_GRKERNSEC_ROFS
58318 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58319 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58320 + return -EPERM;
58321 + } else
58322 + return 0;
58323 +#endif
58324 + return 0;
58325 +}
58326 +
58327 +int
58328 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58329 +{
58330 +#ifdef CONFIG_GRKERNSEC_ROFS
58331 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58332 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58333 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58334 + return -EPERM;
58335 + } else
58336 + return 0;
58337 +#endif
58338 + return 0;
58339 +}
58340 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58341 new file mode 100644
58342 index 0000000..a3b12a0
58343 --- /dev/null
58344 +++ b/grsecurity/grsec_pax.c
58345 @@ -0,0 +1,36 @@
58346 +#include <linux/kernel.h>
58347 +#include <linux/sched.h>
58348 +#include <linux/mm.h>
58349 +#include <linux/file.h>
58350 +#include <linux/grinternal.h>
58351 +#include <linux/grsecurity.h>
58352 +
58353 +void
58354 +gr_log_textrel(struct vm_area_struct * vma)
58355 +{
58356 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58357 + if (grsec_enable_audit_textrel)
58358 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58359 +#endif
58360 + return;
58361 +}
58362 +
58363 +void
58364 +gr_log_rwxmmap(struct file *file)
58365 +{
58366 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58367 + if (grsec_enable_log_rwxmaps)
58368 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58369 +#endif
58370 + return;
58371 +}
58372 +
58373 +void
58374 +gr_log_rwxmprotect(struct file *file)
58375 +{
58376 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58377 + if (grsec_enable_log_rwxmaps)
58378 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58379 +#endif
58380 + return;
58381 +}
58382 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58383 new file mode 100644
58384 index 0000000..f7f29aa
58385 --- /dev/null
58386 +++ b/grsecurity/grsec_ptrace.c
58387 @@ -0,0 +1,30 @@
58388 +#include <linux/kernel.h>
58389 +#include <linux/sched.h>
58390 +#include <linux/grinternal.h>
58391 +#include <linux/security.h>
58392 +
58393 +void
58394 +gr_audit_ptrace(struct task_struct *task)
58395 +{
58396 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58397 + if (grsec_enable_audit_ptrace)
58398 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58399 +#endif
58400 + return;
58401 +}
58402 +
58403 +int
58404 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58405 +{
58406 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58407 + const struct dentry *dentry = file->f_path.dentry;
58408 + const struct vfsmount *mnt = file->f_path.mnt;
58409 +
58410 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58411 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58412 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58413 + return -EACCES;
58414 + }
58415 +#endif
58416 + return 0;
58417 +}
58418 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58419 new file mode 100644
58420 index 0000000..7a5b2de
58421 --- /dev/null
58422 +++ b/grsecurity/grsec_sig.c
58423 @@ -0,0 +1,207 @@
58424 +#include <linux/kernel.h>
58425 +#include <linux/sched.h>
58426 +#include <linux/delay.h>
58427 +#include <linux/grsecurity.h>
58428 +#include <linux/grinternal.h>
58429 +#include <linux/hardirq.h>
58430 +
58431 +char *signames[] = {
58432 + [SIGSEGV] = "Segmentation fault",
58433 + [SIGILL] = "Illegal instruction",
58434 + [SIGABRT] = "Abort",
58435 + [SIGBUS] = "Invalid alignment/Bus error"
58436 +};
58437 +
58438 +void
58439 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58440 +{
58441 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58442 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58443 + (sig == SIGABRT) || (sig == SIGBUS))) {
58444 + if (t->pid == current->pid) {
58445 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58446 + } else {
58447 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58448 + }
58449 + }
58450 +#endif
58451 + return;
58452 +}
58453 +
58454 +int
58455 +gr_handle_signal(const struct task_struct *p, const int sig)
58456 +{
58457 +#ifdef CONFIG_GRKERNSEC
58458 + /* ignore the 0 signal for protected task checks */
58459 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58460 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58461 + return -EPERM;
58462 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58463 + return -EPERM;
58464 + }
58465 +#endif
58466 + return 0;
58467 +}
58468 +
58469 +#ifdef CONFIG_GRKERNSEC
58470 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58471 +
58472 +int gr_fake_force_sig(int sig, struct task_struct *t)
58473 +{
58474 + unsigned long int flags;
58475 + int ret, blocked, ignored;
58476 + struct k_sigaction *action;
58477 +
58478 + spin_lock_irqsave(&t->sighand->siglock, flags);
58479 + action = &t->sighand->action[sig-1];
58480 + ignored = action->sa.sa_handler == SIG_IGN;
58481 + blocked = sigismember(&t->blocked, sig);
58482 + if (blocked || ignored) {
58483 + action->sa.sa_handler = SIG_DFL;
58484 + if (blocked) {
58485 + sigdelset(&t->blocked, sig);
58486 + recalc_sigpending_and_wake(t);
58487 + }
58488 + }
58489 + if (action->sa.sa_handler == SIG_DFL)
58490 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58491 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58492 +
58493 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58494 +
58495 + return ret;
58496 +}
58497 +#endif
58498 +
58499 +#ifdef CONFIG_GRKERNSEC_BRUTE
58500 +#define GR_USER_BAN_TIME (15 * 60)
58501 +
58502 +static int __get_dumpable(unsigned long mm_flags)
58503 +{
58504 + int ret;
58505 +
58506 + ret = mm_flags & MMF_DUMPABLE_MASK;
58507 + return (ret >= 2) ? 2 : ret;
58508 +}
58509 +#endif
58510 +
58511 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58512 +{
58513 +#ifdef CONFIG_GRKERNSEC_BRUTE
58514 + uid_t uid = 0;
58515 +
58516 + if (!grsec_enable_brute)
58517 + return;
58518 +
58519 + rcu_read_lock();
58520 + read_lock(&tasklist_lock);
58521 + read_lock(&grsec_exec_file_lock);
58522 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58523 + p->real_parent->brute = 1;
58524 + else {
58525 + const struct cred *cred = __task_cred(p), *cred2;
58526 + struct task_struct *tsk, *tsk2;
58527 +
58528 + if (!__get_dumpable(mm_flags) && cred->uid) {
58529 + struct user_struct *user;
58530 +
58531 + uid = cred->uid;
58532 +
58533 + /* this is put upon execution past expiration */
58534 + user = find_user(uid);
58535 + if (user == NULL)
58536 + goto unlock;
58537 + user->banned = 1;
58538 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58539 + if (user->ban_expires == ~0UL)
58540 + user->ban_expires--;
58541 +
58542 + do_each_thread(tsk2, tsk) {
58543 + cred2 = __task_cred(tsk);
58544 + if (tsk != p && cred2->uid == uid)
58545 + gr_fake_force_sig(SIGKILL, tsk);
58546 + } while_each_thread(tsk2, tsk);
58547 + }
58548 + }
58549 +unlock:
58550 + read_unlock(&grsec_exec_file_lock);
58551 + read_unlock(&tasklist_lock);
58552 + rcu_read_unlock();
58553 +
58554 + if (uid)
58555 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58556 +
58557 +#endif
58558 + return;
58559 +}
58560 +
58561 +void gr_handle_brute_check(void)
58562 +{
58563 +#ifdef CONFIG_GRKERNSEC_BRUTE
58564 + if (current->brute)
58565 + msleep(30 * 1000);
58566 +#endif
58567 + return;
58568 +}
58569 +
58570 +void gr_handle_kernel_exploit(void)
58571 +{
58572 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58573 + const struct cred *cred;
58574 + struct task_struct *tsk, *tsk2;
58575 + struct user_struct *user;
58576 + uid_t uid;
58577 +
58578 + if (in_irq() || in_serving_softirq() || in_nmi())
58579 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58580 +
58581 + uid = current_uid();
58582 +
58583 + if (uid == 0)
58584 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58585 + else {
58586 + /* kill all the processes of this user, hold a reference
58587 + to their creds struct, and prevent them from creating
58588 + another process until system reset
58589 + */
58590 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58591 + /* we intentionally leak this ref */
58592 + user = get_uid(current->cred->user);
58593 + if (user) {
58594 + user->banned = 1;
58595 + user->ban_expires = ~0UL;
58596 + }
58597 +
58598 + read_lock(&tasklist_lock);
58599 + do_each_thread(tsk2, tsk) {
58600 + cred = __task_cred(tsk);
58601 + if (cred->uid == uid)
58602 + gr_fake_force_sig(SIGKILL, tsk);
58603 + } while_each_thread(tsk2, tsk);
58604 + read_unlock(&tasklist_lock);
58605 + }
58606 +#endif
58607 +}
58608 +
58609 +int __gr_process_user_ban(struct user_struct *user)
58610 +{
58611 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58612 + if (unlikely(user->banned)) {
58613 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58614 + user->banned = 0;
58615 + user->ban_expires = 0;
58616 + free_uid(user);
58617 + } else
58618 + return -EPERM;
58619 + }
58620 +#endif
58621 + return 0;
58622 +}
58623 +
58624 +int gr_process_user_ban(void)
58625 +{
58626 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58627 + return __gr_process_user_ban(current->cred->user);
58628 +#endif
58629 + return 0;
58630 +}
58631 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58632 new file mode 100644
58633 index 0000000..4030d57
58634 --- /dev/null
58635 +++ b/grsecurity/grsec_sock.c
58636 @@ -0,0 +1,244 @@
58637 +#include <linux/kernel.h>
58638 +#include <linux/module.h>
58639 +#include <linux/sched.h>
58640 +#include <linux/file.h>
58641 +#include <linux/net.h>
58642 +#include <linux/in.h>
58643 +#include <linux/ip.h>
58644 +#include <net/sock.h>
58645 +#include <net/inet_sock.h>
58646 +#include <linux/grsecurity.h>
58647 +#include <linux/grinternal.h>
58648 +#include <linux/gracl.h>
58649 +
58650 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58651 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58652 +
58653 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58654 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58655 +
58656 +#ifdef CONFIG_UNIX_MODULE
58657 +EXPORT_SYMBOL(gr_acl_handle_unix);
58658 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58659 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58660 +EXPORT_SYMBOL(gr_handle_create);
58661 +#endif
58662 +
58663 +#ifdef CONFIG_GRKERNSEC
58664 +#define gr_conn_table_size 32749
58665 +struct conn_table_entry {
58666 + struct conn_table_entry *next;
58667 + struct signal_struct *sig;
58668 +};
58669 +
58670 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58671 +DEFINE_SPINLOCK(gr_conn_table_lock);
58672 +
58673 +extern const char * gr_socktype_to_name(unsigned char type);
58674 +extern const char * gr_proto_to_name(unsigned char proto);
58675 +extern const char * gr_sockfamily_to_name(unsigned char family);
58676 +
58677 +static __inline__ int
58678 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58679 +{
58680 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58681 +}
58682 +
58683 +static __inline__ int
58684 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58685 + __u16 sport, __u16 dport)
58686 +{
58687 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58688 + sig->gr_sport == sport && sig->gr_dport == dport))
58689 + return 1;
58690 + else
58691 + return 0;
58692 +}
58693 +
58694 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58695 +{
58696 + struct conn_table_entry **match;
58697 + unsigned int index;
58698 +
58699 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58700 + sig->gr_sport, sig->gr_dport,
58701 + gr_conn_table_size);
58702 +
58703 + newent->sig = sig;
58704 +
58705 + match = &gr_conn_table[index];
58706 + newent->next = *match;
58707 + *match = newent;
58708 +
58709 + return;
58710 +}
58711 +
58712 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58713 +{
58714 + struct conn_table_entry *match, *last = NULL;
58715 + unsigned int index;
58716 +
58717 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58718 + sig->gr_sport, sig->gr_dport,
58719 + gr_conn_table_size);
58720 +
58721 + match = gr_conn_table[index];
58722 + while (match && !conn_match(match->sig,
58723 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58724 + sig->gr_dport)) {
58725 + last = match;
58726 + match = match->next;
58727 + }
58728 +
58729 + if (match) {
58730 + if (last)
58731 + last->next = match->next;
58732 + else
58733 + gr_conn_table[index] = NULL;
58734 + kfree(match);
58735 + }
58736 +
58737 + return;
58738 +}
58739 +
58740 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58741 + __u16 sport, __u16 dport)
58742 +{
58743 + struct conn_table_entry *match;
58744 + unsigned int index;
58745 +
58746 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58747 +
58748 + match = gr_conn_table[index];
58749 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58750 + match = match->next;
58751 +
58752 + if (match)
58753 + return match->sig;
58754 + else
58755 + return NULL;
58756 +}
58757 +
58758 +#endif
58759 +
58760 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58761 +{
58762 +#ifdef CONFIG_GRKERNSEC
58763 + struct signal_struct *sig = task->signal;
58764 + struct conn_table_entry *newent;
58765 +
58766 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58767 + if (newent == NULL)
58768 + return;
58769 + /* no bh lock needed since we are called with bh disabled */
58770 + spin_lock(&gr_conn_table_lock);
58771 + gr_del_task_from_ip_table_nolock(sig);
58772 + sig->gr_saddr = inet->inet_rcv_saddr;
58773 + sig->gr_daddr = inet->inet_daddr;
58774 + sig->gr_sport = inet->inet_sport;
58775 + sig->gr_dport = inet->inet_dport;
58776 + gr_add_to_task_ip_table_nolock(sig, newent);
58777 + spin_unlock(&gr_conn_table_lock);
58778 +#endif
58779 + return;
58780 +}
58781 +
58782 +void gr_del_task_from_ip_table(struct task_struct *task)
58783 +{
58784 +#ifdef CONFIG_GRKERNSEC
58785 + spin_lock_bh(&gr_conn_table_lock);
58786 + gr_del_task_from_ip_table_nolock(task->signal);
58787 + spin_unlock_bh(&gr_conn_table_lock);
58788 +#endif
58789 + return;
58790 +}
58791 +
58792 +void
58793 +gr_attach_curr_ip(const struct sock *sk)
58794 +{
58795 +#ifdef CONFIG_GRKERNSEC
58796 + struct signal_struct *p, *set;
58797 + const struct inet_sock *inet = inet_sk(sk);
58798 +
58799 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58800 + return;
58801 +
58802 + set = current->signal;
58803 +
58804 + spin_lock_bh(&gr_conn_table_lock);
58805 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58806 + inet->inet_dport, inet->inet_sport);
58807 + if (unlikely(p != NULL)) {
58808 + set->curr_ip = p->curr_ip;
58809 + set->used_accept = 1;
58810 + gr_del_task_from_ip_table_nolock(p);
58811 + spin_unlock_bh(&gr_conn_table_lock);
58812 + return;
58813 + }
58814 + spin_unlock_bh(&gr_conn_table_lock);
58815 +
58816 + set->curr_ip = inet->inet_daddr;
58817 + set->used_accept = 1;
58818 +#endif
58819 + return;
58820 +}
58821 +
58822 +int
58823 +gr_handle_sock_all(const int family, const int type, const int protocol)
58824 +{
58825 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58826 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58827 + (family != AF_UNIX)) {
58828 + if (family == AF_INET)
58829 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58830 + else
58831 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58832 + return -EACCES;
58833 + }
58834 +#endif
58835 + return 0;
58836 +}
58837 +
58838 +int
58839 +gr_handle_sock_server(const struct sockaddr *sck)
58840 +{
58841 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58842 + if (grsec_enable_socket_server &&
58843 + in_group_p(grsec_socket_server_gid) &&
58844 + sck && (sck->sa_family != AF_UNIX) &&
58845 + (sck->sa_family != AF_LOCAL)) {
58846 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58847 + return -EACCES;
58848 + }
58849 +#endif
58850 + return 0;
58851 +}
58852 +
58853 +int
58854 +gr_handle_sock_server_other(const struct sock *sck)
58855 +{
58856 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58857 + if (grsec_enable_socket_server &&
58858 + in_group_p(grsec_socket_server_gid) &&
58859 + sck && (sck->sk_family != AF_UNIX) &&
58860 + (sck->sk_family != AF_LOCAL)) {
58861 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58862 + return -EACCES;
58863 + }
58864 +#endif
58865 + return 0;
58866 +}
58867 +
58868 +int
58869 +gr_handle_sock_client(const struct sockaddr *sck)
58870 +{
58871 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58872 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58873 + sck && (sck->sa_family != AF_UNIX) &&
58874 + (sck->sa_family != AF_LOCAL)) {
58875 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58876 + return -EACCES;
58877 + }
58878 +#endif
58879 + return 0;
58880 +}
58881 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58882 new file mode 100644
58883 index 0000000..a1aedd7
58884 --- /dev/null
58885 +++ b/grsecurity/grsec_sysctl.c
58886 @@ -0,0 +1,451 @@
58887 +#include <linux/kernel.h>
58888 +#include <linux/sched.h>
58889 +#include <linux/sysctl.h>
58890 +#include <linux/grsecurity.h>
58891 +#include <linux/grinternal.h>
58892 +
58893 +int
58894 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58895 +{
58896 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58897 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58898 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58899 + return -EACCES;
58900 + }
58901 +#endif
58902 + return 0;
58903 +}
58904 +
58905 +#ifdef CONFIG_GRKERNSEC_ROFS
58906 +static int __maybe_unused one = 1;
58907 +#endif
58908 +
58909 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58910 +struct ctl_table grsecurity_table[] = {
58911 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58912 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58913 +#ifdef CONFIG_GRKERNSEC_IO
58914 + {
58915 + .procname = "disable_priv_io",
58916 + .data = &grsec_disable_privio,
58917 + .maxlen = sizeof(int),
58918 + .mode = 0600,
58919 + .proc_handler = &proc_dointvec,
58920 + },
58921 +#endif
58922 +#endif
58923 +#ifdef CONFIG_GRKERNSEC_LINK
58924 + {
58925 + .procname = "linking_restrictions",
58926 + .data = &grsec_enable_link,
58927 + .maxlen = sizeof(int),
58928 + .mode = 0600,
58929 + .proc_handler = &proc_dointvec,
58930 + },
58931 +#endif
58932 +#ifdef CONFIG_GRKERNSEC_BRUTE
58933 + {
58934 + .procname = "deter_bruteforce",
58935 + .data = &grsec_enable_brute,
58936 + .maxlen = sizeof(int),
58937 + .mode = 0600,
58938 + .proc_handler = &proc_dointvec,
58939 + },
58940 +#endif
58941 +#ifdef CONFIG_GRKERNSEC_FIFO
58942 + {
58943 + .procname = "fifo_restrictions",
58944 + .data = &grsec_enable_fifo,
58945 + .maxlen = sizeof(int),
58946 + .mode = 0600,
58947 + .proc_handler = &proc_dointvec,
58948 + },
58949 +#endif
58950 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58951 + {
58952 + .procname = "ptrace_readexec",
58953 + .data = &grsec_enable_ptrace_readexec,
58954 + .maxlen = sizeof(int),
58955 + .mode = 0600,
58956 + .proc_handler = &proc_dointvec,
58957 + },
58958 +#endif
58959 +#ifdef CONFIG_GRKERNSEC_SETXID
58960 + {
58961 + .procname = "consistent_setxid",
58962 + .data = &grsec_enable_setxid,
58963 + .maxlen = sizeof(int),
58964 + .mode = 0600,
58965 + .proc_handler = &proc_dointvec,
58966 + },
58967 +#endif
58968 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58969 + {
58970 + .procname = "ip_blackhole",
58971 + .data = &grsec_enable_blackhole,
58972 + .maxlen = sizeof(int),
58973 + .mode = 0600,
58974 + .proc_handler = &proc_dointvec,
58975 + },
58976 + {
58977 + .procname = "lastack_retries",
58978 + .data = &grsec_lastack_retries,
58979 + .maxlen = sizeof(int),
58980 + .mode = 0600,
58981 + .proc_handler = &proc_dointvec,
58982 + },
58983 +#endif
58984 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58985 + {
58986 + .procname = "exec_logging",
58987 + .data = &grsec_enable_execlog,
58988 + .maxlen = sizeof(int),
58989 + .mode = 0600,
58990 + .proc_handler = &proc_dointvec,
58991 + },
58992 +#endif
58993 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58994 + {
58995 + .procname = "rwxmap_logging",
58996 + .data = &grsec_enable_log_rwxmaps,
58997 + .maxlen = sizeof(int),
58998 + .mode = 0600,
58999 + .proc_handler = &proc_dointvec,
59000 + },
59001 +#endif
59002 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59003 + {
59004 + .procname = "signal_logging",
59005 + .data = &grsec_enable_signal,
59006 + .maxlen = sizeof(int),
59007 + .mode = 0600,
59008 + .proc_handler = &proc_dointvec,
59009 + },
59010 +#endif
59011 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59012 + {
59013 + .procname = "forkfail_logging",
59014 + .data = &grsec_enable_forkfail,
59015 + .maxlen = sizeof(int),
59016 + .mode = 0600,
59017 + .proc_handler = &proc_dointvec,
59018 + },
59019 +#endif
59020 +#ifdef CONFIG_GRKERNSEC_TIME
59021 + {
59022 + .procname = "timechange_logging",
59023 + .data = &grsec_enable_time,
59024 + .maxlen = sizeof(int),
59025 + .mode = 0600,
59026 + .proc_handler = &proc_dointvec,
59027 + },
59028 +#endif
59029 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59030 + {
59031 + .procname = "chroot_deny_shmat",
59032 + .data = &grsec_enable_chroot_shmat,
59033 + .maxlen = sizeof(int),
59034 + .mode = 0600,
59035 + .proc_handler = &proc_dointvec,
59036 + },
59037 +#endif
59038 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59039 + {
59040 + .procname = "chroot_deny_unix",
59041 + .data = &grsec_enable_chroot_unix,
59042 + .maxlen = sizeof(int),
59043 + .mode = 0600,
59044 + .proc_handler = &proc_dointvec,
59045 + },
59046 +#endif
59047 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59048 + {
59049 + .procname = "chroot_deny_mount",
59050 + .data = &grsec_enable_chroot_mount,
59051 + .maxlen = sizeof(int),
59052 + .mode = 0600,
59053 + .proc_handler = &proc_dointvec,
59054 + },
59055 +#endif
59056 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59057 + {
59058 + .procname = "chroot_deny_fchdir",
59059 + .data = &grsec_enable_chroot_fchdir,
59060 + .maxlen = sizeof(int),
59061 + .mode = 0600,
59062 + .proc_handler = &proc_dointvec,
59063 + },
59064 +#endif
59065 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59066 + {
59067 + .procname = "chroot_deny_chroot",
59068 + .data = &grsec_enable_chroot_double,
59069 + .maxlen = sizeof(int),
59070 + .mode = 0600,
59071 + .proc_handler = &proc_dointvec,
59072 + },
59073 +#endif
59074 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59075 + {
59076 + .procname = "chroot_deny_pivot",
59077 + .data = &grsec_enable_chroot_pivot,
59078 + .maxlen = sizeof(int),
59079 + .mode = 0600,
59080 + .proc_handler = &proc_dointvec,
59081 + },
59082 +#endif
59083 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59084 + {
59085 + .procname = "chroot_enforce_chdir",
59086 + .data = &grsec_enable_chroot_chdir,
59087 + .maxlen = sizeof(int),
59088 + .mode = 0600,
59089 + .proc_handler = &proc_dointvec,
59090 + },
59091 +#endif
59092 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59093 + {
59094 + .procname = "chroot_deny_chmod",
59095 + .data = &grsec_enable_chroot_chmod,
59096 + .maxlen = sizeof(int),
59097 + .mode = 0600,
59098 + .proc_handler = &proc_dointvec,
59099 + },
59100 +#endif
59101 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59102 + {
59103 + .procname = "chroot_deny_mknod",
59104 + .data = &grsec_enable_chroot_mknod,
59105 + .maxlen = sizeof(int),
59106 + .mode = 0600,
59107 + .proc_handler = &proc_dointvec,
59108 + },
59109 +#endif
59110 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59111 + {
59112 + .procname = "chroot_restrict_nice",
59113 + .data = &grsec_enable_chroot_nice,
59114 + .maxlen = sizeof(int),
59115 + .mode = 0600,
59116 + .proc_handler = &proc_dointvec,
59117 + },
59118 +#endif
59119 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59120 + {
59121 + .procname = "chroot_execlog",
59122 + .data = &grsec_enable_chroot_execlog,
59123 + .maxlen = sizeof(int),
59124 + .mode = 0600,
59125 + .proc_handler = &proc_dointvec,
59126 + },
59127 +#endif
59128 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59129 + {
59130 + .procname = "chroot_caps",
59131 + .data = &grsec_enable_chroot_caps,
59132 + .maxlen = sizeof(int),
59133 + .mode = 0600,
59134 + .proc_handler = &proc_dointvec,
59135 + },
59136 +#endif
59137 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59138 + {
59139 + .procname = "chroot_deny_sysctl",
59140 + .data = &grsec_enable_chroot_sysctl,
59141 + .maxlen = sizeof(int),
59142 + .mode = 0600,
59143 + .proc_handler = &proc_dointvec,
59144 + },
59145 +#endif
59146 +#ifdef CONFIG_GRKERNSEC_TPE
59147 + {
59148 + .procname = "tpe",
59149 + .data = &grsec_enable_tpe,
59150 + .maxlen = sizeof(int),
59151 + .mode = 0600,
59152 + .proc_handler = &proc_dointvec,
59153 + },
59154 + {
59155 + .procname = "tpe_gid",
59156 + .data = &grsec_tpe_gid,
59157 + .maxlen = sizeof(int),
59158 + .mode = 0600,
59159 + .proc_handler = &proc_dointvec,
59160 + },
59161 +#endif
59162 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59163 + {
59164 + .procname = "tpe_invert",
59165 + .data = &grsec_enable_tpe_invert,
59166 + .maxlen = sizeof(int),
59167 + .mode = 0600,
59168 + .proc_handler = &proc_dointvec,
59169 + },
59170 +#endif
59171 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59172 + {
59173 + .procname = "tpe_restrict_all",
59174 + .data = &grsec_enable_tpe_all,
59175 + .maxlen = sizeof(int),
59176 + .mode = 0600,
59177 + .proc_handler = &proc_dointvec,
59178 + },
59179 +#endif
59180 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59181 + {
59182 + .procname = "socket_all",
59183 + .data = &grsec_enable_socket_all,
59184 + .maxlen = sizeof(int),
59185 + .mode = 0600,
59186 + .proc_handler = &proc_dointvec,
59187 + },
59188 + {
59189 + .procname = "socket_all_gid",
59190 + .data = &grsec_socket_all_gid,
59191 + .maxlen = sizeof(int),
59192 + .mode = 0600,
59193 + .proc_handler = &proc_dointvec,
59194 + },
59195 +#endif
59196 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59197 + {
59198 + .procname = "socket_client",
59199 + .data = &grsec_enable_socket_client,
59200 + .maxlen = sizeof(int),
59201 + .mode = 0600,
59202 + .proc_handler = &proc_dointvec,
59203 + },
59204 + {
59205 + .procname = "socket_client_gid",
59206 + .data = &grsec_socket_client_gid,
59207 + .maxlen = sizeof(int),
59208 + .mode = 0600,
59209 + .proc_handler = &proc_dointvec,
59210 + },
59211 +#endif
59212 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59213 + {
59214 + .procname = "socket_server",
59215 + .data = &grsec_enable_socket_server,
59216 + .maxlen = sizeof(int),
59217 + .mode = 0600,
59218 + .proc_handler = &proc_dointvec,
59219 + },
59220 + {
59221 + .procname = "socket_server_gid",
59222 + .data = &grsec_socket_server_gid,
59223 + .maxlen = sizeof(int),
59224 + .mode = 0600,
59225 + .proc_handler = &proc_dointvec,
59226 + },
59227 +#endif
59228 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59229 + {
59230 + .procname = "audit_group",
59231 + .data = &grsec_enable_group,
59232 + .maxlen = sizeof(int),
59233 + .mode = 0600,
59234 + .proc_handler = &proc_dointvec,
59235 + },
59236 + {
59237 + .procname = "audit_gid",
59238 + .data = &grsec_audit_gid,
59239 + .maxlen = sizeof(int),
59240 + .mode = 0600,
59241 + .proc_handler = &proc_dointvec,
59242 + },
59243 +#endif
59244 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59245 + {
59246 + .procname = "audit_chdir",
59247 + .data = &grsec_enable_chdir,
59248 + .maxlen = sizeof(int),
59249 + .mode = 0600,
59250 + .proc_handler = &proc_dointvec,
59251 + },
59252 +#endif
59253 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59254 + {
59255 + .procname = "audit_mount",
59256 + .data = &grsec_enable_mount,
59257 + .maxlen = sizeof(int),
59258 + .mode = 0600,
59259 + .proc_handler = &proc_dointvec,
59260 + },
59261 +#endif
59262 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59263 + {
59264 + .procname = "audit_textrel",
59265 + .data = &grsec_enable_audit_textrel,
59266 + .maxlen = sizeof(int),
59267 + .mode = 0600,
59268 + .proc_handler = &proc_dointvec,
59269 + },
59270 +#endif
59271 +#ifdef CONFIG_GRKERNSEC_DMESG
59272 + {
59273 + .procname = "dmesg",
59274 + .data = &grsec_enable_dmesg,
59275 + .maxlen = sizeof(int),
59276 + .mode = 0600,
59277 + .proc_handler = &proc_dointvec,
59278 + },
59279 +#endif
59280 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59281 + {
59282 + .procname = "chroot_findtask",
59283 + .data = &grsec_enable_chroot_findtask,
59284 + .maxlen = sizeof(int),
59285 + .mode = 0600,
59286 + .proc_handler = &proc_dointvec,
59287 + },
59288 +#endif
59289 +#ifdef CONFIG_GRKERNSEC_RESLOG
59290 + {
59291 + .procname = "resource_logging",
59292 + .data = &grsec_resource_logging,
59293 + .maxlen = sizeof(int),
59294 + .mode = 0600,
59295 + .proc_handler = &proc_dointvec,
59296 + },
59297 +#endif
59298 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59299 + {
59300 + .procname = "audit_ptrace",
59301 + .data = &grsec_enable_audit_ptrace,
59302 + .maxlen = sizeof(int),
59303 + .mode = 0600,
59304 + .proc_handler = &proc_dointvec,
59305 + },
59306 +#endif
59307 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59308 + {
59309 + .procname = "harden_ptrace",
59310 + .data = &grsec_enable_harden_ptrace,
59311 + .maxlen = sizeof(int),
59312 + .mode = 0600,
59313 + .proc_handler = &proc_dointvec,
59314 + },
59315 +#endif
59316 + {
59317 + .procname = "grsec_lock",
59318 + .data = &grsec_lock,
59319 + .maxlen = sizeof(int),
59320 + .mode = 0600,
59321 + .proc_handler = &proc_dointvec,
59322 + },
59323 +#endif
59324 +#ifdef CONFIG_GRKERNSEC_ROFS
59325 + {
59326 + .procname = "romount_protect",
59327 + .data = &grsec_enable_rofs,
59328 + .maxlen = sizeof(int),
59329 + .mode = 0600,
59330 + .proc_handler = &proc_dointvec_minmax,
59331 + .extra1 = &one,
59332 + .extra2 = &one,
59333 + },
59334 +#endif
59335 + { }
59336 +};
59337 +#endif
59338 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59339 new file mode 100644
59340 index 0000000..0dc13c3
59341 --- /dev/null
59342 +++ b/grsecurity/grsec_time.c
59343 @@ -0,0 +1,16 @@
59344 +#include <linux/kernel.h>
59345 +#include <linux/sched.h>
59346 +#include <linux/grinternal.h>
59347 +#include <linux/module.h>
59348 +
59349 +void
59350 +gr_log_timechange(void)
59351 +{
59352 +#ifdef CONFIG_GRKERNSEC_TIME
59353 + if (grsec_enable_time)
59354 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59355 +#endif
59356 + return;
59357 +}
59358 +
59359 +EXPORT_SYMBOL(gr_log_timechange);
59360 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59361 new file mode 100644
59362 index 0000000..07e0dc0
59363 --- /dev/null
59364 +++ b/grsecurity/grsec_tpe.c
59365 @@ -0,0 +1,73 @@
59366 +#include <linux/kernel.h>
59367 +#include <linux/sched.h>
59368 +#include <linux/file.h>
59369 +#include <linux/fs.h>
59370 +#include <linux/grinternal.h>
59371 +
59372 +extern int gr_acl_tpe_check(void);
59373 +
59374 +int
59375 +gr_tpe_allow(const struct file *file)
59376 +{
59377 +#ifdef CONFIG_GRKERNSEC
59378 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59379 + const struct cred *cred = current_cred();
59380 + char *msg = NULL;
59381 + char *msg2 = NULL;
59382 +
59383 + // never restrict root
59384 + if (!cred->uid)
59385 + return 1;
59386 +
59387 + if (grsec_enable_tpe) {
59388 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59389 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59390 + msg = "not being in trusted group";
59391 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59392 + msg = "being in untrusted group";
59393 +#else
59394 + if (in_group_p(grsec_tpe_gid))
59395 + msg = "being in untrusted group";
59396 +#endif
59397 + }
59398 + if (!msg && gr_acl_tpe_check())
59399 + msg = "being in untrusted role";
59400 +
59401 + // not in any affected group/role
59402 + if (!msg)
59403 + goto next_check;
59404 +
59405 + if (inode->i_uid)
59406 + msg2 = "file in non-root-owned directory";
59407 + else if (inode->i_mode & S_IWOTH)
59408 + msg2 = "file in world-writable directory";
59409 + else if (inode->i_mode & S_IWGRP)
59410 + msg2 = "file in group-writable directory";
59411 +
59412 + if (msg && msg2) {
59413 + char fullmsg[70] = {0};
59414 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59415 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59416 + return 0;
59417 + }
59418 + msg = NULL;
59419 +next_check:
59420 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59421 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59422 + return 1;
59423 +
59424 + if (inode->i_uid && (inode->i_uid != cred->uid))
59425 + msg = "directory not owned by user";
59426 + else if (inode->i_mode & S_IWOTH)
59427 + msg = "file in world-writable directory";
59428 + else if (inode->i_mode & S_IWGRP)
59429 + msg = "file in group-writable directory";
59430 +
59431 + if (msg) {
59432 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59433 + return 0;
59434 + }
59435 +#endif
59436 +#endif
59437 + return 1;
59438 +}
59439 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59440 new file mode 100644
59441 index 0000000..9f7b1ac
59442 --- /dev/null
59443 +++ b/grsecurity/grsum.c
59444 @@ -0,0 +1,61 @@
59445 +#include <linux/err.h>
59446 +#include <linux/kernel.h>
59447 +#include <linux/sched.h>
59448 +#include <linux/mm.h>
59449 +#include <linux/scatterlist.h>
59450 +#include <linux/crypto.h>
59451 +#include <linux/gracl.h>
59452 +
59453 +
59454 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59455 +#error "crypto and sha256 must be built into the kernel"
59456 +#endif
59457 +
59458 +int
59459 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59460 +{
59461 + char *p;
59462 + struct crypto_hash *tfm;
59463 + struct hash_desc desc;
59464 + struct scatterlist sg;
59465 + unsigned char temp_sum[GR_SHA_LEN];
59466 + volatile int retval = 0;
59467 + volatile int dummy = 0;
59468 + unsigned int i;
59469 +
59470 + sg_init_table(&sg, 1);
59471 +
59472 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59473 + if (IS_ERR(tfm)) {
59474 + /* should never happen, since sha256 should be built in */
59475 + return 1;
59476 + }
59477 +
59478 + desc.tfm = tfm;
59479 + desc.flags = 0;
59480 +
59481 + crypto_hash_init(&desc);
59482 +
59483 + p = salt;
59484 + sg_set_buf(&sg, p, GR_SALT_LEN);
59485 + crypto_hash_update(&desc, &sg, sg.length);
59486 +
59487 + p = entry->pw;
59488 + sg_set_buf(&sg, p, strlen(p));
59489 +
59490 + crypto_hash_update(&desc, &sg, sg.length);
59491 +
59492 + crypto_hash_final(&desc, temp_sum);
59493 +
59494 + memset(entry->pw, 0, GR_PW_LEN);
59495 +
59496 + for (i = 0; i < GR_SHA_LEN; i++)
59497 + if (sum[i] != temp_sum[i])
59498 + retval = 1;
59499 + else
59500 + dummy = 1; // waste a cycle
59501 +
59502 + crypto_free_hash(tfm);
59503 +
59504 + return retval;
59505 +}
59506 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59507 index 6cd5b64..f620d2d 100644
59508 --- a/include/acpi/acpi_bus.h
59509 +++ b/include/acpi/acpi_bus.h
59510 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59511 acpi_op_bind bind;
59512 acpi_op_unbind unbind;
59513 acpi_op_notify notify;
59514 -};
59515 +} __no_const;
59516
59517 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59518
59519 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59520 index b7babf0..71e4e74 100644
59521 --- a/include/asm-generic/atomic-long.h
59522 +++ b/include/asm-generic/atomic-long.h
59523 @@ -22,6 +22,12 @@
59524
59525 typedef atomic64_t atomic_long_t;
59526
59527 +#ifdef CONFIG_PAX_REFCOUNT
59528 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59529 +#else
59530 +typedef atomic64_t atomic_long_unchecked_t;
59531 +#endif
59532 +
59533 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59534
59535 static inline long atomic_long_read(atomic_long_t *l)
59536 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59537 return (long)atomic64_read(v);
59538 }
59539
59540 +#ifdef CONFIG_PAX_REFCOUNT
59541 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59542 +{
59543 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59544 +
59545 + return (long)atomic64_read_unchecked(v);
59546 +}
59547 +#endif
59548 +
59549 static inline void atomic_long_set(atomic_long_t *l, long i)
59550 {
59551 atomic64_t *v = (atomic64_t *)l;
59552 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59553 atomic64_set(v, i);
59554 }
59555
59556 +#ifdef CONFIG_PAX_REFCOUNT
59557 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59558 +{
59559 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59560 +
59561 + atomic64_set_unchecked(v, i);
59562 +}
59563 +#endif
59564 +
59565 static inline void atomic_long_inc(atomic_long_t *l)
59566 {
59567 atomic64_t *v = (atomic64_t *)l;
59568 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59569 atomic64_inc(v);
59570 }
59571
59572 +#ifdef CONFIG_PAX_REFCOUNT
59573 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59574 +{
59575 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59576 +
59577 + atomic64_inc_unchecked(v);
59578 +}
59579 +#endif
59580 +
59581 static inline void atomic_long_dec(atomic_long_t *l)
59582 {
59583 atomic64_t *v = (atomic64_t *)l;
59584 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59585 atomic64_dec(v);
59586 }
59587
59588 +#ifdef CONFIG_PAX_REFCOUNT
59589 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59590 +{
59591 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59592 +
59593 + atomic64_dec_unchecked(v);
59594 +}
59595 +#endif
59596 +
59597 static inline void atomic_long_add(long i, atomic_long_t *l)
59598 {
59599 atomic64_t *v = (atomic64_t *)l;
59600 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59601 atomic64_add(i, v);
59602 }
59603
59604 +#ifdef CONFIG_PAX_REFCOUNT
59605 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59606 +{
59607 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59608 +
59609 + atomic64_add_unchecked(i, v);
59610 +}
59611 +#endif
59612 +
59613 static inline void atomic_long_sub(long i, atomic_long_t *l)
59614 {
59615 atomic64_t *v = (atomic64_t *)l;
59616 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59617 atomic64_sub(i, v);
59618 }
59619
59620 +#ifdef CONFIG_PAX_REFCOUNT
59621 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59622 +{
59623 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59624 +
59625 + atomic64_sub_unchecked(i, v);
59626 +}
59627 +#endif
59628 +
59629 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59630 {
59631 atomic64_t *v = (atomic64_t *)l;
59632 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59633 return (long)atomic64_inc_return(v);
59634 }
59635
59636 +#ifdef CONFIG_PAX_REFCOUNT
59637 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59638 +{
59639 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59640 +
59641 + return (long)atomic64_inc_return_unchecked(v);
59642 +}
59643 +#endif
59644 +
59645 static inline long atomic_long_dec_return(atomic_long_t *l)
59646 {
59647 atomic64_t *v = (atomic64_t *)l;
59648 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59649
59650 typedef atomic_t atomic_long_t;
59651
59652 +#ifdef CONFIG_PAX_REFCOUNT
59653 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59654 +#else
59655 +typedef atomic_t atomic_long_unchecked_t;
59656 +#endif
59657 +
59658 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59659 static inline long atomic_long_read(atomic_long_t *l)
59660 {
59661 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59662 return (long)atomic_read(v);
59663 }
59664
59665 +#ifdef CONFIG_PAX_REFCOUNT
59666 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59667 +{
59668 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59669 +
59670 + return (long)atomic_read_unchecked(v);
59671 +}
59672 +#endif
59673 +
59674 static inline void atomic_long_set(atomic_long_t *l, long i)
59675 {
59676 atomic_t *v = (atomic_t *)l;
59677 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59678 atomic_set(v, i);
59679 }
59680
59681 +#ifdef CONFIG_PAX_REFCOUNT
59682 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59683 +{
59684 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59685 +
59686 + atomic_set_unchecked(v, i);
59687 +}
59688 +#endif
59689 +
59690 static inline void atomic_long_inc(atomic_long_t *l)
59691 {
59692 atomic_t *v = (atomic_t *)l;
59693 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59694 atomic_inc(v);
59695 }
59696
59697 +#ifdef CONFIG_PAX_REFCOUNT
59698 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59699 +{
59700 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59701 +
59702 + atomic_inc_unchecked(v);
59703 +}
59704 +#endif
59705 +
59706 static inline void atomic_long_dec(atomic_long_t *l)
59707 {
59708 atomic_t *v = (atomic_t *)l;
59709 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59710 atomic_dec(v);
59711 }
59712
59713 +#ifdef CONFIG_PAX_REFCOUNT
59714 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59715 +{
59716 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59717 +
59718 + atomic_dec_unchecked(v);
59719 +}
59720 +#endif
59721 +
59722 static inline void atomic_long_add(long i, atomic_long_t *l)
59723 {
59724 atomic_t *v = (atomic_t *)l;
59725 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59726 atomic_add(i, v);
59727 }
59728
59729 +#ifdef CONFIG_PAX_REFCOUNT
59730 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59731 +{
59732 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59733 +
59734 + atomic_add_unchecked(i, v);
59735 +}
59736 +#endif
59737 +
59738 static inline void atomic_long_sub(long i, atomic_long_t *l)
59739 {
59740 atomic_t *v = (atomic_t *)l;
59741 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59742 atomic_sub(i, v);
59743 }
59744
59745 +#ifdef CONFIG_PAX_REFCOUNT
59746 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59747 +{
59748 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59749 +
59750 + atomic_sub_unchecked(i, v);
59751 +}
59752 +#endif
59753 +
59754 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59755 {
59756 atomic_t *v = (atomic_t *)l;
59757 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59758 return (long)atomic_inc_return(v);
59759 }
59760
59761 +#ifdef CONFIG_PAX_REFCOUNT
59762 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59763 +{
59764 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59765 +
59766 + return (long)atomic_inc_return_unchecked(v);
59767 +}
59768 +#endif
59769 +
59770 static inline long atomic_long_dec_return(atomic_long_t *l)
59771 {
59772 atomic_t *v = (atomic_t *)l;
59773 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59774
59775 #endif /* BITS_PER_LONG == 64 */
59776
59777 +#ifdef CONFIG_PAX_REFCOUNT
59778 +static inline void pax_refcount_needs_these_functions(void)
59779 +{
59780 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59781 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59782 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59783 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59784 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59785 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59786 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59787 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59788 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59789 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59790 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59791 +
59792 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59793 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59794 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59795 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59796 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59797 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59798 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59799 +}
59800 +#else
59801 +#define atomic_read_unchecked(v) atomic_read(v)
59802 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59803 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59804 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59805 +#define atomic_inc_unchecked(v) atomic_inc(v)
59806 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59807 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59808 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59809 +#define atomic_dec_unchecked(v) atomic_dec(v)
59810 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59811 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59812 +
59813 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59814 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59815 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59816 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59817 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59818 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59819 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59820 +#endif
59821 +
59822 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59823 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59824 index b18ce4f..2ee2843 100644
59825 --- a/include/asm-generic/atomic64.h
59826 +++ b/include/asm-generic/atomic64.h
59827 @@ -16,6 +16,8 @@ typedef struct {
59828 long long counter;
59829 } atomic64_t;
59830
59831 +typedef atomic64_t atomic64_unchecked_t;
59832 +
59833 #define ATOMIC64_INIT(i) { (i) }
59834
59835 extern long long atomic64_read(const atomic64_t *v);
59836 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59837 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59838 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59839
59840 +#define atomic64_read_unchecked(v) atomic64_read(v)
59841 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59842 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59843 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59844 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59845 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59846 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59847 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59848 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59849 +
59850 #endif /* _ASM_GENERIC_ATOMIC64_H */
59851 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59852 index 1bfcfe5..e04c5c9 100644
59853 --- a/include/asm-generic/cache.h
59854 +++ b/include/asm-generic/cache.h
59855 @@ -6,7 +6,7 @@
59856 * cache lines need to provide their own cache.h.
59857 */
59858
59859 -#define L1_CACHE_SHIFT 5
59860 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59861 +#define L1_CACHE_SHIFT 5UL
59862 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59863
59864 #endif /* __ASM_GENERIC_CACHE_H */
59865 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59866 index 0d68a1e..b74a761 100644
59867 --- a/include/asm-generic/emergency-restart.h
59868 +++ b/include/asm-generic/emergency-restart.h
59869 @@ -1,7 +1,7 @@
59870 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59871 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59872
59873 -static inline void machine_emergency_restart(void)
59874 +static inline __noreturn void machine_emergency_restart(void)
59875 {
59876 machine_restart(NULL);
59877 }
59878 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59879 index 0232ccb..13d9165 100644
59880 --- a/include/asm-generic/kmap_types.h
59881 +++ b/include/asm-generic/kmap_types.h
59882 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59883 KMAP_D(17) KM_NMI,
59884 KMAP_D(18) KM_NMI_PTE,
59885 KMAP_D(19) KM_KDB,
59886 +KMAP_D(20) KM_CLEARPAGE,
59887 /*
59888 * Remember to update debug_kmap_atomic() when adding new kmap types!
59889 */
59890 -KMAP_D(20) KM_TYPE_NR
59891 +KMAP_D(21) KM_TYPE_NR
59892 };
59893
59894 #undef KMAP_D
59895 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59896 index 9ceb03b..2efbcbd 100644
59897 --- a/include/asm-generic/local.h
59898 +++ b/include/asm-generic/local.h
59899 @@ -39,6 +39,7 @@ typedef struct
59900 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59901 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59902 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59903 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59904
59905 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59906 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59907 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59908 index 725612b..9cc513a 100644
59909 --- a/include/asm-generic/pgtable-nopmd.h
59910 +++ b/include/asm-generic/pgtable-nopmd.h
59911 @@ -1,14 +1,19 @@
59912 #ifndef _PGTABLE_NOPMD_H
59913 #define _PGTABLE_NOPMD_H
59914
59915 -#ifndef __ASSEMBLY__
59916 -
59917 #include <asm-generic/pgtable-nopud.h>
59918
59919 -struct mm_struct;
59920 -
59921 #define __PAGETABLE_PMD_FOLDED
59922
59923 +#define PMD_SHIFT PUD_SHIFT
59924 +#define PTRS_PER_PMD 1
59925 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59926 +#define PMD_MASK (~(PMD_SIZE-1))
59927 +
59928 +#ifndef __ASSEMBLY__
59929 +
59930 +struct mm_struct;
59931 +
59932 /*
59933 * Having the pmd type consist of a pud gets the size right, and allows
59934 * us to conceptually access the pud entry that this pmd is folded into
59935 @@ -16,11 +21,6 @@ struct mm_struct;
59936 */
59937 typedef struct { pud_t pud; } pmd_t;
59938
59939 -#define PMD_SHIFT PUD_SHIFT
59940 -#define PTRS_PER_PMD 1
59941 -#define PMD_SIZE (1UL << PMD_SHIFT)
59942 -#define PMD_MASK (~(PMD_SIZE-1))
59943 -
59944 /*
59945 * The "pud_xxx()" functions here are trivial for a folded two-level
59946 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59947 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59948 index 810431d..ccc3638 100644
59949 --- a/include/asm-generic/pgtable-nopud.h
59950 +++ b/include/asm-generic/pgtable-nopud.h
59951 @@ -1,10 +1,15 @@
59952 #ifndef _PGTABLE_NOPUD_H
59953 #define _PGTABLE_NOPUD_H
59954
59955 -#ifndef __ASSEMBLY__
59956 -
59957 #define __PAGETABLE_PUD_FOLDED
59958
59959 +#define PUD_SHIFT PGDIR_SHIFT
59960 +#define PTRS_PER_PUD 1
59961 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59962 +#define PUD_MASK (~(PUD_SIZE-1))
59963 +
59964 +#ifndef __ASSEMBLY__
59965 +
59966 /*
59967 * Having the pud type consist of a pgd gets the size right, and allows
59968 * us to conceptually access the pgd entry that this pud is folded into
59969 @@ -12,11 +17,6 @@
59970 */
59971 typedef struct { pgd_t pgd; } pud_t;
59972
59973 -#define PUD_SHIFT PGDIR_SHIFT
59974 -#define PTRS_PER_PUD 1
59975 -#define PUD_SIZE (1UL << PUD_SHIFT)
59976 -#define PUD_MASK (~(PUD_SIZE-1))
59977 -
59978 /*
59979 * The "pgd_xxx()" functions here are trivial for a folded two-level
59980 * setup: the pud is never bad, and a pud always exists (as it's folded
59981 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59982 index a03c098..7e5b223 100644
59983 --- a/include/asm-generic/pgtable.h
59984 +++ b/include/asm-generic/pgtable.h
59985 @@ -502,6 +502,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59986 #endif
59987 }
59988
59989 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59990 +static inline unsigned long pax_open_kernel(void) { return 0; }
59991 +#endif
59992 +
59993 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59994 +static inline unsigned long pax_close_kernel(void) { return 0; }
59995 +#endif
59996 +
59997 #endif /* CONFIG_MMU */
59998
59999 #endif /* !__ASSEMBLY__ */
60000 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
60001 index 9788568..510dece 100644
60002 --- a/include/asm-generic/uaccess.h
60003 +++ b/include/asm-generic/uaccess.h
60004 @@ -76,6 +76,8 @@ extern unsigned long search_exception_table(unsigned long);
60005 */
60006 #ifndef __copy_from_user
60007 static inline __must_check long __copy_from_user(void *to,
60008 + const void __user * from, unsigned long n) __size_overflow(3);
60009 +static inline __must_check long __copy_from_user(void *to,
60010 const void __user * from, unsigned long n)
60011 {
60012 if (__builtin_constant_p(n)) {
60013 @@ -106,6 +108,8 @@ static inline __must_check long __copy_from_user(void *to,
60014
60015 #ifndef __copy_to_user
60016 static inline __must_check long __copy_to_user(void __user *to,
60017 + const void *from, unsigned long n) __size_overflow(3);
60018 +static inline __must_check long __copy_to_user(void __user *to,
60019 const void *from, unsigned long n)
60020 {
60021 if (__builtin_constant_p(n)) {
60022 @@ -224,6 +228,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
60023 -EFAULT; \
60024 })
60025
60026 +static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) __size_overflow(1);
60027 static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
60028 {
60029 size = __copy_from_user(x, ptr, size);
60030 @@ -240,6 +245,7 @@ extern int __get_user_bad(void) __attribute__((noreturn));
60031 #define __copy_to_user_inatomic __copy_to_user
60032 #endif
60033
60034 +static inline long copy_from_user(void *to, const void __user * from, unsigned long n) __size_overflow(3);
60035 static inline long copy_from_user(void *to,
60036 const void __user * from, unsigned long n)
60037 {
60038 @@ -250,6 +256,7 @@ static inline long copy_from_user(void *to,
60039 return n;
60040 }
60041
60042 +static inline long copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
60043 static inline long copy_to_user(void __user *to,
60044 const void *from, unsigned long n)
60045 {
60046 @@ -314,6 +321,8 @@ static inline long strlen_user(const char __user *src)
60047 */
60048 #ifndef __clear_user
60049 static inline __must_check unsigned long
60050 +__clear_user(void __user *to, unsigned long n) __size_overflow(2);
60051 +static inline __must_check unsigned long
60052 __clear_user(void __user *to, unsigned long n)
60053 {
60054 memset((void __force *)to, 0, n);
60055 @@ -322,6 +331,8 @@ __clear_user(void __user *to, unsigned long n)
60056 #endif
60057
60058 static inline __must_check unsigned long
60059 +clear_user(void __user *to, unsigned long n) __size_overflow(2);
60060 +static inline __must_check unsigned long
60061 clear_user(void __user *to, unsigned long n)
60062 {
60063 might_sleep();
60064 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60065 index b5e2e4c..6a5373e 100644
60066 --- a/include/asm-generic/vmlinux.lds.h
60067 +++ b/include/asm-generic/vmlinux.lds.h
60068 @@ -217,6 +217,7 @@
60069 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60070 VMLINUX_SYMBOL(__start_rodata) = .; \
60071 *(.rodata) *(.rodata.*) \
60072 + *(.data..read_only) \
60073 *(__vermagic) /* Kernel version magic */ \
60074 . = ALIGN(8); \
60075 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60076 @@ -722,17 +723,18 @@
60077 * section in the linker script will go there too. @phdr should have
60078 * a leading colon.
60079 *
60080 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60081 + * Note that this macros defines per_cpu_load as an absolute symbol.
60082 * If there is no need to put the percpu section at a predetermined
60083 * address, use PERCPU_SECTION.
60084 */
60085 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60086 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60087 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60088 + per_cpu_load = .; \
60089 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60090 - LOAD_OFFSET) { \
60091 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60092 PERCPU_INPUT(cacheline) \
60093 } phdr \
60094 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60095 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60096
60097 /**
60098 * PERCPU_SECTION - define output section for percpu area, simple version
60099 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60100 index 92f0981..d44a37c 100644
60101 --- a/include/drm/drmP.h
60102 +++ b/include/drm/drmP.h
60103 @@ -72,6 +72,7 @@
60104 #include <linux/workqueue.h>
60105 #include <linux/poll.h>
60106 #include <asm/pgalloc.h>
60107 +#include <asm/local.h>
60108 #include "drm.h"
60109
60110 #include <linux/idr.h>
60111 @@ -1038,7 +1039,7 @@ struct drm_device {
60112
60113 /** \name Usage Counters */
60114 /*@{ */
60115 - int open_count; /**< Outstanding files open */
60116 + local_t open_count; /**< Outstanding files open */
60117 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60118 atomic_t vma_count; /**< Outstanding vma areas open */
60119 int buf_use; /**< Buffers in use -- cannot alloc */
60120 @@ -1049,7 +1050,7 @@ struct drm_device {
60121 /*@{ */
60122 unsigned long counters;
60123 enum drm_stat_type types[15];
60124 - atomic_t counts[15];
60125 + atomic_unchecked_t counts[15];
60126 /*@} */
60127
60128 struct list_head filelist;
60129 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60130 index 37515d1..34fa8b0 100644
60131 --- a/include/drm/drm_crtc_helper.h
60132 +++ b/include/drm/drm_crtc_helper.h
60133 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60134
60135 /* disable crtc when not in use - more explicit than dpms off */
60136 void (*disable)(struct drm_crtc *crtc);
60137 -};
60138 +} __no_const;
60139
60140 struct drm_encoder_helper_funcs {
60141 void (*dpms)(struct drm_encoder *encoder, int mode);
60142 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60143 struct drm_connector *connector);
60144 /* disable encoder when not in use - more explicit than dpms off */
60145 void (*disable)(struct drm_encoder *encoder);
60146 -};
60147 +} __no_const;
60148
60149 struct drm_connector_helper_funcs {
60150 int (*get_modes)(struct drm_connector *connector);
60151 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60152 index 26c1f78..6722682 100644
60153 --- a/include/drm/ttm/ttm_memory.h
60154 +++ b/include/drm/ttm/ttm_memory.h
60155 @@ -47,7 +47,7 @@
60156
60157 struct ttm_mem_shrink {
60158 int (*do_shrink) (struct ttm_mem_shrink *);
60159 -};
60160 +} __no_const;
60161
60162 /**
60163 * struct ttm_mem_global - Global memory accounting structure.
60164 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60165 index e86dfca..40cc55f 100644
60166 --- a/include/linux/a.out.h
60167 +++ b/include/linux/a.out.h
60168 @@ -39,6 +39,14 @@ enum machine_type {
60169 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60170 };
60171
60172 +/* Constants for the N_FLAGS field */
60173 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60174 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60175 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60176 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60177 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60178 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60179 +
60180 #if !defined (N_MAGIC)
60181 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60182 #endif
60183 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60184 index f4ff882..84b53a6 100644
60185 --- a/include/linux/atmdev.h
60186 +++ b/include/linux/atmdev.h
60187 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60188 #endif
60189
60190 struct k_atm_aal_stats {
60191 -#define __HANDLE_ITEM(i) atomic_t i
60192 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60193 __AAL_STAT_ITEMS
60194 #undef __HANDLE_ITEM
60195 };
60196 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60197 index 0092102..8a801b4 100644
60198 --- a/include/linux/binfmts.h
60199 +++ b/include/linux/binfmts.h
60200 @@ -89,6 +89,7 @@ struct linux_binfmt {
60201 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60202 int (*load_shlib)(struct file *);
60203 int (*core_dump)(struct coredump_params *cprm);
60204 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60205 unsigned long min_coredump; /* minimal dump size */
60206 };
60207
60208 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60209 index 606cf33..b72c577 100644
60210 --- a/include/linux/blkdev.h
60211 +++ b/include/linux/blkdev.h
60212 @@ -1379,7 +1379,7 @@ struct block_device_operations {
60213 /* this callback is with swap_lock and sometimes page table lock held */
60214 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60215 struct module *owner;
60216 -};
60217 +} __do_const;
60218
60219 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60220 unsigned long);
60221 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60222 index 4d1a074..88f929a 100644
60223 --- a/include/linux/blktrace_api.h
60224 +++ b/include/linux/blktrace_api.h
60225 @@ -162,7 +162,7 @@ struct blk_trace {
60226 struct dentry *dir;
60227 struct dentry *dropped_file;
60228 struct dentry *msg_file;
60229 - atomic_t dropped;
60230 + atomic_unchecked_t dropped;
60231 };
60232
60233 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60234 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60235 index 83195fb..0b0f77d 100644
60236 --- a/include/linux/byteorder/little_endian.h
60237 +++ b/include/linux/byteorder/little_endian.h
60238 @@ -42,51 +42,51 @@
60239
60240 static inline __le64 __cpu_to_le64p(const __u64 *p)
60241 {
60242 - return (__force __le64)*p;
60243 + return (__force const __le64)*p;
60244 }
60245 static inline __u64 __le64_to_cpup(const __le64 *p)
60246 {
60247 - return (__force __u64)*p;
60248 + return (__force const __u64)*p;
60249 }
60250 static inline __le32 __cpu_to_le32p(const __u32 *p)
60251 {
60252 - return (__force __le32)*p;
60253 + return (__force const __le32)*p;
60254 }
60255 static inline __u32 __le32_to_cpup(const __le32 *p)
60256 {
60257 - return (__force __u32)*p;
60258 + return (__force const __u32)*p;
60259 }
60260 static inline __le16 __cpu_to_le16p(const __u16 *p)
60261 {
60262 - return (__force __le16)*p;
60263 + return (__force const __le16)*p;
60264 }
60265 static inline __u16 __le16_to_cpup(const __le16 *p)
60266 {
60267 - return (__force __u16)*p;
60268 + return (__force const __u16)*p;
60269 }
60270 static inline __be64 __cpu_to_be64p(const __u64 *p)
60271 {
60272 - return (__force __be64)__swab64p(p);
60273 + return (__force const __be64)__swab64p(p);
60274 }
60275 static inline __u64 __be64_to_cpup(const __be64 *p)
60276 {
60277 - return __swab64p((__u64 *)p);
60278 + return __swab64p((const __u64 *)p);
60279 }
60280 static inline __be32 __cpu_to_be32p(const __u32 *p)
60281 {
60282 - return (__force __be32)__swab32p(p);
60283 + return (__force const __be32)__swab32p(p);
60284 }
60285 static inline __u32 __be32_to_cpup(const __be32 *p)
60286 {
60287 - return __swab32p((__u32 *)p);
60288 + return __swab32p((const __u32 *)p);
60289 }
60290 static inline __be16 __cpu_to_be16p(const __u16 *p)
60291 {
60292 - return (__force __be16)__swab16p(p);
60293 + return (__force const __be16)__swab16p(p);
60294 }
60295 static inline __u16 __be16_to_cpup(const __be16 *p)
60296 {
60297 - return __swab16p((__u16 *)p);
60298 + return __swab16p((const __u16 *)p);
60299 }
60300 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60301 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60302 diff --git a/include/linux/cache.h b/include/linux/cache.h
60303 index 4c57065..4307975 100644
60304 --- a/include/linux/cache.h
60305 +++ b/include/linux/cache.h
60306 @@ -16,6 +16,10 @@
60307 #define __read_mostly
60308 #endif
60309
60310 +#ifndef __read_only
60311 +#define __read_only __read_mostly
60312 +#endif
60313 +
60314 #ifndef ____cacheline_aligned
60315 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60316 #endif
60317 diff --git a/include/linux/capability.h b/include/linux/capability.h
60318 index 12d52de..b5f7fa7 100644
60319 --- a/include/linux/capability.h
60320 +++ b/include/linux/capability.h
60321 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60322 extern bool capable(int cap);
60323 extern bool ns_capable(struct user_namespace *ns, int cap);
60324 extern bool nsown_capable(int cap);
60325 +extern bool capable_nolog(int cap);
60326 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60327
60328 /* audit system wants to get cap info from files as well */
60329 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60330 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60331 index 04ffb2e..6799180 100644
60332 --- a/include/linux/cleancache.h
60333 +++ b/include/linux/cleancache.h
60334 @@ -31,7 +31,7 @@ struct cleancache_ops {
60335 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60336 void (*flush_inode)(int, struct cleancache_filekey);
60337 void (*flush_fs)(int);
60338 -};
60339 +} __no_const;
60340
60341 extern struct cleancache_ops
60342 cleancache_register_ops(struct cleancache_ops *ops);
60343 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60344 index 2f40791..567b215 100644
60345 --- a/include/linux/compiler-gcc4.h
60346 +++ b/include/linux/compiler-gcc4.h
60347 @@ -32,6 +32,15 @@
60348 #define __linktime_error(message) __attribute__((__error__(message)))
60349
60350 #if __GNUC_MINOR__ >= 5
60351 +
60352 +#ifdef CONSTIFY_PLUGIN
60353 +#define __no_const __attribute__((no_const))
60354 +#define __do_const __attribute__((do_const))
60355 +#endif
60356 +
60357 +#ifdef SIZE_OVERFLOW_PLUGIN
60358 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60359 +#endif
60360 /*
60361 * Mark a position in code as unreachable. This can be used to
60362 * suppress control flow warnings after asm blocks that transfer
60363 @@ -47,6 +56,11 @@
60364 #define __noclone __attribute__((__noclone__))
60365
60366 #endif
60367 +
60368 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60369 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60370 +#define __bos0(ptr) __bos((ptr), 0)
60371 +#define __bos1(ptr) __bos((ptr), 1)
60372 #endif
60373
60374 #if __GNUC_MINOR__ > 0
60375 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60376 index 4a24354..ecaff7a 100644
60377 --- a/include/linux/compiler.h
60378 +++ b/include/linux/compiler.h
60379 @@ -5,31 +5,62 @@
60380
60381 #ifdef __CHECKER__
60382 # define __user __attribute__((noderef, address_space(1)))
60383 +# define __force_user __force __user
60384 # define __kernel __attribute__((address_space(0)))
60385 +# define __force_kernel __force __kernel
60386 # define __safe __attribute__((safe))
60387 # define __force __attribute__((force))
60388 # define __nocast __attribute__((nocast))
60389 # define __iomem __attribute__((noderef, address_space(2)))
60390 +# define __force_iomem __force __iomem
60391 # define __acquires(x) __attribute__((context(x,0,1)))
60392 # define __releases(x) __attribute__((context(x,1,0)))
60393 # define __acquire(x) __context__(x,1)
60394 # define __release(x) __context__(x,-1)
60395 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60396 # define __percpu __attribute__((noderef, address_space(3)))
60397 +# define __force_percpu __force __percpu
60398 #ifdef CONFIG_SPARSE_RCU_POINTER
60399 # define __rcu __attribute__((noderef, address_space(4)))
60400 +# define __force_rcu __force __rcu
60401 #else
60402 # define __rcu
60403 +# define __force_rcu
60404 #endif
60405 extern void __chk_user_ptr(const volatile void __user *);
60406 extern void __chk_io_ptr(const volatile void __iomem *);
60407 +#elif defined(CHECKER_PLUGIN)
60408 +//# define __user
60409 +//# define __force_user
60410 +//# define __kernel
60411 +//# define __force_kernel
60412 +# define __safe
60413 +# define __force
60414 +# define __nocast
60415 +# define __iomem
60416 +# define __force_iomem
60417 +# define __chk_user_ptr(x) (void)0
60418 +# define __chk_io_ptr(x) (void)0
60419 +# define __builtin_warning(x, y...) (1)
60420 +# define __acquires(x)
60421 +# define __releases(x)
60422 +# define __acquire(x) (void)0
60423 +# define __release(x) (void)0
60424 +# define __cond_lock(x,c) (c)
60425 +# define __percpu
60426 +# define __force_percpu
60427 +# define __rcu
60428 +# define __force_rcu
60429 #else
60430 # define __user
60431 +# define __force_user
60432 # define __kernel
60433 +# define __force_kernel
60434 # define __safe
60435 # define __force
60436 # define __nocast
60437 # define __iomem
60438 +# define __force_iomem
60439 # define __chk_user_ptr(x) (void)0
60440 # define __chk_io_ptr(x) (void)0
60441 # define __builtin_warning(x, y...) (1)
60442 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60443 # define __release(x) (void)0
60444 # define __cond_lock(x,c) (c)
60445 # define __percpu
60446 +# define __force_percpu
60447 # define __rcu
60448 +# define __force_rcu
60449 #endif
60450
60451 #ifdef __KERNEL__
60452 @@ -264,6 +297,17 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60453 # define __attribute_const__ /* unimplemented */
60454 #endif
60455
60456 +#ifndef __no_const
60457 +# define __no_const
60458 +#endif
60459 +
60460 +#ifndef __do_const
60461 +# define __do_const
60462 +#endif
60463 +
60464 +#ifndef __size_overflow
60465 +# define __size_overflow(...)
60466 +#endif
60467 /*
60468 * Tell gcc if a function is cold. The compiler will assume any path
60469 * directly leading to the call is unlikely.
60470 @@ -273,6 +317,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60471 #define __cold
60472 #endif
60473
60474 +#ifndef __alloc_size
60475 +#define __alloc_size(...)
60476 +#endif
60477 +
60478 +#ifndef __bos
60479 +#define __bos(ptr, arg)
60480 +#endif
60481 +
60482 +#ifndef __bos0
60483 +#define __bos0(ptr)
60484 +#endif
60485 +
60486 +#ifndef __bos1
60487 +#define __bos1(ptr)
60488 +#endif
60489 +
60490 /* Simple shorthand for a section definition */
60491 #ifndef __section
60492 # define __section(S) __attribute__ ((__section__(#S)))
60493 @@ -308,6 +368,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60494 * use is to mediate communication between process-level code and irq/NMI
60495 * handlers, all running on the same CPU.
60496 */
60497 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60498 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60499 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60500
60501 #endif /* __LINUX_COMPILER_H */
60502 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60503 index e9eaec5..bfeb9bb 100644
60504 --- a/include/linux/cpuset.h
60505 +++ b/include/linux/cpuset.h
60506 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60507 * nodemask.
60508 */
60509 smp_mb();
60510 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60511 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60512 }
60513
60514 static inline void set_mems_allowed(nodemask_t nodemask)
60515 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
60516 index b936763..48685ee 100644
60517 --- a/include/linux/crash_dump.h
60518 +++ b/include/linux/crash_dump.h
60519 @@ -14,7 +14,7 @@ extern unsigned long long elfcorehdr_addr;
60520 extern unsigned long long elfcorehdr_size;
60521
60522 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
60523 - unsigned long, int);
60524 + unsigned long, int) __size_overflow(3);
60525
60526 /* Architecture code defines this if there are other possible ELF
60527 * machine types, e.g. on bi-arch capable hardware. */
60528 diff --git a/include/linux/cred.h b/include/linux/cred.h
60529 index adadf71..6af5560 100644
60530 --- a/include/linux/cred.h
60531 +++ b/include/linux/cred.h
60532 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60533 static inline void validate_process_creds(void)
60534 {
60535 }
60536 +static inline void validate_task_creds(struct task_struct *task)
60537 +{
60538 +}
60539 #endif
60540
60541 /**
60542 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60543 index 8a94217..15d49e3 100644
60544 --- a/include/linux/crypto.h
60545 +++ b/include/linux/crypto.h
60546 @@ -365,7 +365,7 @@ struct cipher_tfm {
60547 const u8 *key, unsigned int keylen);
60548 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60549 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60550 -};
60551 +} __no_const;
60552
60553 struct hash_tfm {
60554 int (*init)(struct hash_desc *desc);
60555 @@ -386,13 +386,13 @@ struct compress_tfm {
60556 int (*cot_decompress)(struct crypto_tfm *tfm,
60557 const u8 *src, unsigned int slen,
60558 u8 *dst, unsigned int *dlen);
60559 -};
60560 +} __no_const;
60561
60562 struct rng_tfm {
60563 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60564 unsigned int dlen);
60565 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60566 -};
60567 +} __no_const;
60568
60569 #define crt_ablkcipher crt_u.ablkcipher
60570 #define crt_aead crt_u.aead
60571 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60572 index 7925bf0..d5143d2 100644
60573 --- a/include/linux/decompress/mm.h
60574 +++ b/include/linux/decompress/mm.h
60575 @@ -77,7 +77,7 @@ static void free(void *where)
60576 * warnings when not needed (indeed large_malloc / large_free are not
60577 * needed by inflate */
60578
60579 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60580 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60581 #define free(a) kfree(a)
60582
60583 #define large_malloc(a) vmalloc(a)
60584 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60585 index e13117c..e9fc938 100644
60586 --- a/include/linux/dma-mapping.h
60587 +++ b/include/linux/dma-mapping.h
60588 @@ -46,7 +46,7 @@ struct dma_map_ops {
60589 u64 (*get_required_mask)(struct device *dev);
60590 #endif
60591 int is_phys;
60592 -};
60593 +} __do_const;
60594
60595 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60596
60597 diff --git a/include/linux/efi.h b/include/linux/efi.h
60598 index 37c3007..92ab679 100644
60599 --- a/include/linux/efi.h
60600 +++ b/include/linux/efi.h
60601 @@ -580,7 +580,7 @@ struct efivar_operations {
60602 efi_get_variable_t *get_variable;
60603 efi_get_next_variable_t *get_next_variable;
60604 efi_set_variable_t *set_variable;
60605 -};
60606 +} __no_const;
60607
60608 struct efivars {
60609 /*
60610 diff --git a/include/linux/elf.h b/include/linux/elf.h
60611 index 999b4f5..57753b4 100644
60612 --- a/include/linux/elf.h
60613 +++ b/include/linux/elf.h
60614 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60615 #define PT_GNU_EH_FRAME 0x6474e550
60616
60617 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60618 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60619 +
60620 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60621 +
60622 +/* Constants for the e_flags field */
60623 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60624 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60625 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60626 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60627 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60628 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60629
60630 /*
60631 * Extended Numbering
60632 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60633 #define DT_DEBUG 21
60634 #define DT_TEXTREL 22
60635 #define DT_JMPREL 23
60636 +#define DT_FLAGS 30
60637 + #define DF_TEXTREL 0x00000004
60638 #define DT_ENCODING 32
60639 #define OLD_DT_LOOS 0x60000000
60640 #define DT_LOOS 0x6000000d
60641 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60642 #define PF_W 0x2
60643 #define PF_X 0x1
60644
60645 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60646 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60647 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60648 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60649 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60650 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60651 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60652 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60653 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60654 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60655 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60656 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60657 +
60658 typedef struct elf32_phdr{
60659 Elf32_Word p_type;
60660 Elf32_Off p_offset;
60661 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60662 #define EI_OSABI 7
60663 #define EI_PAD 8
60664
60665 +#define EI_PAX 14
60666 +
60667 #define ELFMAG0 0x7f /* EI_MAG */
60668 #define ELFMAG1 'E'
60669 #define ELFMAG2 'L'
60670 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60671 #define elf_note elf32_note
60672 #define elf_addr_t Elf32_Off
60673 #define Elf_Half Elf32_Half
60674 +#define elf_dyn Elf32_Dyn
60675
60676 #else
60677
60678 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60679 #define elf_note elf64_note
60680 #define elf_addr_t Elf64_Off
60681 #define Elf_Half Elf64_Half
60682 +#define elf_dyn Elf64_Dyn
60683
60684 #endif
60685
60686 diff --git a/include/linux/filter.h b/include/linux/filter.h
60687 index 8eeb205..d59bfa2 100644
60688 --- a/include/linux/filter.h
60689 +++ b/include/linux/filter.h
60690 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60691
60692 struct sk_buff;
60693 struct sock;
60694 +struct bpf_jit_work;
60695
60696 struct sk_filter
60697 {
60698 @@ -141,6 +142,9 @@ struct sk_filter
60699 unsigned int len; /* Number of filter blocks */
60700 unsigned int (*bpf_func)(const struct sk_buff *skb,
60701 const struct sock_filter *filter);
60702 +#ifdef CONFIG_BPF_JIT
60703 + struct bpf_jit_work *work;
60704 +#endif
60705 struct rcu_head rcu;
60706 struct sock_filter insns[0];
60707 };
60708 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60709 index 84ccf8e..2e9b14c 100644
60710 --- a/include/linux/firewire.h
60711 +++ b/include/linux/firewire.h
60712 @@ -428,7 +428,7 @@ struct fw_iso_context {
60713 union {
60714 fw_iso_callback_t sc;
60715 fw_iso_mc_callback_t mc;
60716 - } callback;
60717 + } __no_const callback;
60718 void *callback_data;
60719 };
60720
60721 diff --git a/include/linux/fs.h b/include/linux/fs.h
60722 index f4b6e06..d6ba573 100644
60723 --- a/include/linux/fs.h
60724 +++ b/include/linux/fs.h
60725 @@ -1628,7 +1628,8 @@ struct file_operations {
60726 int (*setlease)(struct file *, long, struct file_lock **);
60727 long (*fallocate)(struct file *file, int mode, loff_t offset,
60728 loff_t len);
60729 -};
60730 +} __do_const;
60731 +typedef struct file_operations __no_const file_operations_no_const;
60732
60733 struct inode_operations {
60734 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60735 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60736 index 003dc0f..3c4ea97 100644
60737 --- a/include/linux/fs_struct.h
60738 +++ b/include/linux/fs_struct.h
60739 @@ -6,7 +6,7 @@
60740 #include <linux/seqlock.h>
60741
60742 struct fs_struct {
60743 - int users;
60744 + atomic_t users;
60745 spinlock_t lock;
60746 seqcount_t seq;
60747 int umask;
60748 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60749 index ce31408..b1ad003 100644
60750 --- a/include/linux/fscache-cache.h
60751 +++ b/include/linux/fscache-cache.h
60752 @@ -102,7 +102,7 @@ struct fscache_operation {
60753 fscache_operation_release_t release;
60754 };
60755
60756 -extern atomic_t fscache_op_debug_id;
60757 +extern atomic_unchecked_t fscache_op_debug_id;
60758 extern void fscache_op_work_func(struct work_struct *work);
60759
60760 extern void fscache_enqueue_operation(struct fscache_operation *);
60761 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60762 {
60763 INIT_WORK(&op->work, fscache_op_work_func);
60764 atomic_set(&op->usage, 1);
60765 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60766 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60767 op->processor = processor;
60768 op->release = release;
60769 INIT_LIST_HEAD(&op->pend_link);
60770 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60771 index 2a53f10..0187fdf 100644
60772 --- a/include/linux/fsnotify.h
60773 +++ b/include/linux/fsnotify.h
60774 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60775 */
60776 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60777 {
60778 - return kstrdup(name, GFP_KERNEL);
60779 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60780 }
60781
60782 /*
60783 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60784 index 91d0e0a3..035666b 100644
60785 --- a/include/linux/fsnotify_backend.h
60786 +++ b/include/linux/fsnotify_backend.h
60787 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60788 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60789 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60790 };
60791 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60792
60793 /*
60794 * A group is a "thing" that wants to receive notification about filesystem
60795 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60796 index c3da42d..c70e0df 100644
60797 --- a/include/linux/ftrace_event.h
60798 +++ b/include/linux/ftrace_event.h
60799 @@ -97,7 +97,7 @@ struct trace_event_functions {
60800 trace_print_func raw;
60801 trace_print_func hex;
60802 trace_print_func binary;
60803 -};
60804 +} __no_const;
60805
60806 struct trace_event {
60807 struct hlist_node node;
60808 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60809 extern int trace_add_event_call(struct ftrace_event_call *call);
60810 extern void trace_remove_event_call(struct ftrace_event_call *call);
60811
60812 -#define is_signed_type(type) (((type)(-1)) < 0)
60813 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60814
60815 int trace_set_clr_event(const char *system, const char *event, int set);
60816
60817 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60818 index e61d319..0da8505 100644
60819 --- a/include/linux/genhd.h
60820 +++ b/include/linux/genhd.h
60821 @@ -185,7 +185,7 @@ struct gendisk {
60822 struct kobject *slave_dir;
60823
60824 struct timer_rand_state *random;
60825 - atomic_t sync_io; /* RAID */
60826 + atomic_unchecked_t sync_io; /* RAID */
60827 struct disk_events *ev;
60828 #ifdef CONFIG_BLK_DEV_INTEGRITY
60829 struct blk_integrity *integrity;
60830 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60831 new file mode 100644
60832 index 0000000..8a130b6
60833 --- /dev/null
60834 +++ b/include/linux/gracl.h
60835 @@ -0,0 +1,319 @@
60836 +#ifndef GR_ACL_H
60837 +#define GR_ACL_H
60838 +
60839 +#include <linux/grdefs.h>
60840 +#include <linux/resource.h>
60841 +#include <linux/capability.h>
60842 +#include <linux/dcache.h>
60843 +#include <asm/resource.h>
60844 +
60845 +/* Major status information */
60846 +
60847 +#define GR_VERSION "grsecurity 2.9"
60848 +#define GRSECURITY_VERSION 0x2900
60849 +
60850 +enum {
60851 + GR_SHUTDOWN = 0,
60852 + GR_ENABLE = 1,
60853 + GR_SPROLE = 2,
60854 + GR_RELOAD = 3,
60855 + GR_SEGVMOD = 4,
60856 + GR_STATUS = 5,
60857 + GR_UNSPROLE = 6,
60858 + GR_PASSSET = 7,
60859 + GR_SPROLEPAM = 8,
60860 +};
60861 +
60862 +/* Password setup definitions
60863 + * kernel/grhash.c */
60864 +enum {
60865 + GR_PW_LEN = 128,
60866 + GR_SALT_LEN = 16,
60867 + GR_SHA_LEN = 32,
60868 +};
60869 +
60870 +enum {
60871 + GR_SPROLE_LEN = 64,
60872 +};
60873 +
60874 +enum {
60875 + GR_NO_GLOB = 0,
60876 + GR_REG_GLOB,
60877 + GR_CREATE_GLOB
60878 +};
60879 +
60880 +#define GR_NLIMITS 32
60881 +
60882 +/* Begin Data Structures */
60883 +
60884 +struct sprole_pw {
60885 + unsigned char *rolename;
60886 + unsigned char salt[GR_SALT_LEN];
60887 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60888 +};
60889 +
60890 +struct name_entry {
60891 + __u32 key;
60892 + ino_t inode;
60893 + dev_t device;
60894 + char *name;
60895 + __u16 len;
60896 + __u8 deleted;
60897 + struct name_entry *prev;
60898 + struct name_entry *next;
60899 +};
60900 +
60901 +struct inodev_entry {
60902 + struct name_entry *nentry;
60903 + struct inodev_entry *prev;
60904 + struct inodev_entry *next;
60905 +};
60906 +
60907 +struct acl_role_db {
60908 + struct acl_role_label **r_hash;
60909 + __u32 r_size;
60910 +};
60911 +
60912 +struct inodev_db {
60913 + struct inodev_entry **i_hash;
60914 + __u32 i_size;
60915 +};
60916 +
60917 +struct name_db {
60918 + struct name_entry **n_hash;
60919 + __u32 n_size;
60920 +};
60921 +
60922 +struct crash_uid {
60923 + uid_t uid;
60924 + unsigned long expires;
60925 +};
60926 +
60927 +struct gr_hash_struct {
60928 + void **table;
60929 + void **nametable;
60930 + void *first;
60931 + __u32 table_size;
60932 + __u32 used_size;
60933 + int type;
60934 +};
60935 +
60936 +/* Userspace Grsecurity ACL data structures */
60937 +
60938 +struct acl_subject_label {
60939 + char *filename;
60940 + ino_t inode;
60941 + dev_t device;
60942 + __u32 mode;
60943 + kernel_cap_t cap_mask;
60944 + kernel_cap_t cap_lower;
60945 + kernel_cap_t cap_invert_audit;
60946 +
60947 + struct rlimit res[GR_NLIMITS];
60948 + __u32 resmask;
60949 +
60950 + __u8 user_trans_type;
60951 + __u8 group_trans_type;
60952 + uid_t *user_transitions;
60953 + gid_t *group_transitions;
60954 + __u16 user_trans_num;
60955 + __u16 group_trans_num;
60956 +
60957 + __u32 sock_families[2];
60958 + __u32 ip_proto[8];
60959 + __u32 ip_type;
60960 + struct acl_ip_label **ips;
60961 + __u32 ip_num;
60962 + __u32 inaddr_any_override;
60963 +
60964 + __u32 crashes;
60965 + unsigned long expires;
60966 +
60967 + struct acl_subject_label *parent_subject;
60968 + struct gr_hash_struct *hash;
60969 + struct acl_subject_label *prev;
60970 + struct acl_subject_label *next;
60971 +
60972 + struct acl_object_label **obj_hash;
60973 + __u32 obj_hash_size;
60974 + __u16 pax_flags;
60975 +};
60976 +
60977 +struct role_allowed_ip {
60978 + __u32 addr;
60979 + __u32 netmask;
60980 +
60981 + struct role_allowed_ip *prev;
60982 + struct role_allowed_ip *next;
60983 +};
60984 +
60985 +struct role_transition {
60986 + char *rolename;
60987 +
60988 + struct role_transition *prev;
60989 + struct role_transition *next;
60990 +};
60991 +
60992 +struct acl_role_label {
60993 + char *rolename;
60994 + uid_t uidgid;
60995 + __u16 roletype;
60996 +
60997 + __u16 auth_attempts;
60998 + unsigned long expires;
60999 +
61000 + struct acl_subject_label *root_label;
61001 + struct gr_hash_struct *hash;
61002 +
61003 + struct acl_role_label *prev;
61004 + struct acl_role_label *next;
61005 +
61006 + struct role_transition *transitions;
61007 + struct role_allowed_ip *allowed_ips;
61008 + uid_t *domain_children;
61009 + __u16 domain_child_num;
61010 +
61011 + umode_t umask;
61012 +
61013 + struct acl_subject_label **subj_hash;
61014 + __u32 subj_hash_size;
61015 +};
61016 +
61017 +struct user_acl_role_db {
61018 + struct acl_role_label **r_table;
61019 + __u32 num_pointers; /* Number of allocations to track */
61020 + __u32 num_roles; /* Number of roles */
61021 + __u32 num_domain_children; /* Number of domain children */
61022 + __u32 num_subjects; /* Number of subjects */
61023 + __u32 num_objects; /* Number of objects */
61024 +};
61025 +
61026 +struct acl_object_label {
61027 + char *filename;
61028 + ino_t inode;
61029 + dev_t device;
61030 + __u32 mode;
61031 +
61032 + struct acl_subject_label *nested;
61033 + struct acl_object_label *globbed;
61034 +
61035 + /* next two structures not used */
61036 +
61037 + struct acl_object_label *prev;
61038 + struct acl_object_label *next;
61039 +};
61040 +
61041 +struct acl_ip_label {
61042 + char *iface;
61043 + __u32 addr;
61044 + __u32 netmask;
61045 + __u16 low, high;
61046 + __u8 mode;
61047 + __u32 type;
61048 + __u32 proto[8];
61049 +
61050 + /* next two structures not used */
61051 +
61052 + struct acl_ip_label *prev;
61053 + struct acl_ip_label *next;
61054 +};
61055 +
61056 +struct gr_arg {
61057 + struct user_acl_role_db role_db;
61058 + unsigned char pw[GR_PW_LEN];
61059 + unsigned char salt[GR_SALT_LEN];
61060 + unsigned char sum[GR_SHA_LEN];
61061 + unsigned char sp_role[GR_SPROLE_LEN];
61062 + struct sprole_pw *sprole_pws;
61063 + dev_t segv_device;
61064 + ino_t segv_inode;
61065 + uid_t segv_uid;
61066 + __u16 num_sprole_pws;
61067 + __u16 mode;
61068 +};
61069 +
61070 +struct gr_arg_wrapper {
61071 + struct gr_arg *arg;
61072 + __u32 version;
61073 + __u32 size;
61074 +};
61075 +
61076 +struct subject_map {
61077 + struct acl_subject_label *user;
61078 + struct acl_subject_label *kernel;
61079 + struct subject_map *prev;
61080 + struct subject_map *next;
61081 +};
61082 +
61083 +struct acl_subj_map_db {
61084 + struct subject_map **s_hash;
61085 + __u32 s_size;
61086 +};
61087 +
61088 +/* End Data Structures Section */
61089 +
61090 +/* Hash functions generated by empirical testing by Brad Spengler
61091 + Makes good use of the low bits of the inode. Generally 0-1 times
61092 + in loop for successful match. 0-3 for unsuccessful match.
61093 + Shift/add algorithm with modulus of table size and an XOR*/
61094 +
61095 +static __inline__ unsigned int
61096 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61097 +{
61098 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61099 +}
61100 +
61101 + static __inline__ unsigned int
61102 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61103 +{
61104 + return ((const unsigned long)userp % sz);
61105 +}
61106 +
61107 +static __inline__ unsigned int
61108 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61109 +{
61110 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61111 +}
61112 +
61113 +static __inline__ unsigned int
61114 +nhash(const char *name, const __u16 len, const unsigned int sz)
61115 +{
61116 + return full_name_hash((const unsigned char *)name, len) % sz;
61117 +}
61118 +
61119 +#define FOR_EACH_ROLE_START(role) \
61120 + role = role_list; \
61121 + while (role) {
61122 +
61123 +#define FOR_EACH_ROLE_END(role) \
61124 + role = role->prev; \
61125 + }
61126 +
61127 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61128 + subj = NULL; \
61129 + iter = 0; \
61130 + while (iter < role->subj_hash_size) { \
61131 + if (subj == NULL) \
61132 + subj = role->subj_hash[iter]; \
61133 + if (subj == NULL) { \
61134 + iter++; \
61135 + continue; \
61136 + }
61137 +
61138 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61139 + subj = subj->next; \
61140 + if (subj == NULL) \
61141 + iter++; \
61142 + }
61143 +
61144 +
61145 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61146 + subj = role->hash->first; \
61147 + while (subj != NULL) {
61148 +
61149 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61150 + subj = subj->next; \
61151 + }
61152 +
61153 +#endif
61154 +
61155 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61156 new file mode 100644
61157 index 0000000..323ecf2
61158 --- /dev/null
61159 +++ b/include/linux/gralloc.h
61160 @@ -0,0 +1,9 @@
61161 +#ifndef __GRALLOC_H
61162 +#define __GRALLOC_H
61163 +
61164 +void acl_free_all(void);
61165 +int acl_alloc_stack_init(unsigned long size);
61166 +void *acl_alloc(unsigned long len);
61167 +void *acl_alloc_num(unsigned long num, unsigned long len);
61168 +
61169 +#endif
61170 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61171 new file mode 100644
61172 index 0000000..b30e9bc
61173 --- /dev/null
61174 +++ b/include/linux/grdefs.h
61175 @@ -0,0 +1,140 @@
61176 +#ifndef GRDEFS_H
61177 +#define GRDEFS_H
61178 +
61179 +/* Begin grsecurity status declarations */
61180 +
61181 +enum {
61182 + GR_READY = 0x01,
61183 + GR_STATUS_INIT = 0x00 // disabled state
61184 +};
61185 +
61186 +/* Begin ACL declarations */
61187 +
61188 +/* Role flags */
61189 +
61190 +enum {
61191 + GR_ROLE_USER = 0x0001,
61192 + GR_ROLE_GROUP = 0x0002,
61193 + GR_ROLE_DEFAULT = 0x0004,
61194 + GR_ROLE_SPECIAL = 0x0008,
61195 + GR_ROLE_AUTH = 0x0010,
61196 + GR_ROLE_NOPW = 0x0020,
61197 + GR_ROLE_GOD = 0x0040,
61198 + GR_ROLE_LEARN = 0x0080,
61199 + GR_ROLE_TPE = 0x0100,
61200 + GR_ROLE_DOMAIN = 0x0200,
61201 + GR_ROLE_PAM = 0x0400,
61202 + GR_ROLE_PERSIST = 0x0800
61203 +};
61204 +
61205 +/* ACL Subject and Object mode flags */
61206 +enum {
61207 + GR_DELETED = 0x80000000
61208 +};
61209 +
61210 +/* ACL Object-only mode flags */
61211 +enum {
61212 + GR_READ = 0x00000001,
61213 + GR_APPEND = 0x00000002,
61214 + GR_WRITE = 0x00000004,
61215 + GR_EXEC = 0x00000008,
61216 + GR_FIND = 0x00000010,
61217 + GR_INHERIT = 0x00000020,
61218 + GR_SETID = 0x00000040,
61219 + GR_CREATE = 0x00000080,
61220 + GR_DELETE = 0x00000100,
61221 + GR_LINK = 0x00000200,
61222 + GR_AUDIT_READ = 0x00000400,
61223 + GR_AUDIT_APPEND = 0x00000800,
61224 + GR_AUDIT_WRITE = 0x00001000,
61225 + GR_AUDIT_EXEC = 0x00002000,
61226 + GR_AUDIT_FIND = 0x00004000,
61227 + GR_AUDIT_INHERIT= 0x00008000,
61228 + GR_AUDIT_SETID = 0x00010000,
61229 + GR_AUDIT_CREATE = 0x00020000,
61230 + GR_AUDIT_DELETE = 0x00040000,
61231 + GR_AUDIT_LINK = 0x00080000,
61232 + GR_PTRACERD = 0x00100000,
61233 + GR_NOPTRACE = 0x00200000,
61234 + GR_SUPPRESS = 0x00400000,
61235 + GR_NOLEARN = 0x00800000,
61236 + GR_INIT_TRANSFER= 0x01000000
61237 +};
61238 +
61239 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61240 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61241 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61242 +
61243 +/* ACL subject-only mode flags */
61244 +enum {
61245 + GR_KILL = 0x00000001,
61246 + GR_VIEW = 0x00000002,
61247 + GR_PROTECTED = 0x00000004,
61248 + GR_LEARN = 0x00000008,
61249 + GR_OVERRIDE = 0x00000010,
61250 + /* just a placeholder, this mode is only used in userspace */
61251 + GR_DUMMY = 0x00000020,
61252 + GR_PROTSHM = 0x00000040,
61253 + GR_KILLPROC = 0x00000080,
61254 + GR_KILLIPPROC = 0x00000100,
61255 + /* just a placeholder, this mode is only used in userspace */
61256 + GR_NOTROJAN = 0x00000200,
61257 + GR_PROTPROCFD = 0x00000400,
61258 + GR_PROCACCT = 0x00000800,
61259 + GR_RELAXPTRACE = 0x00001000,
61260 + GR_NESTED = 0x00002000,
61261 + GR_INHERITLEARN = 0x00004000,
61262 + GR_PROCFIND = 0x00008000,
61263 + GR_POVERRIDE = 0x00010000,
61264 + GR_KERNELAUTH = 0x00020000,
61265 + GR_ATSECURE = 0x00040000,
61266 + GR_SHMEXEC = 0x00080000
61267 +};
61268 +
61269 +enum {
61270 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61271 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61272 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61273 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61274 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61275 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61276 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61277 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61278 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61279 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61280 +};
61281 +
61282 +enum {
61283 + GR_ID_USER = 0x01,
61284 + GR_ID_GROUP = 0x02,
61285 +};
61286 +
61287 +enum {
61288 + GR_ID_ALLOW = 0x01,
61289 + GR_ID_DENY = 0x02,
61290 +};
61291 +
61292 +#define GR_CRASH_RES 31
61293 +#define GR_UIDTABLE_MAX 500
61294 +
61295 +/* begin resource learning section */
61296 +enum {
61297 + GR_RLIM_CPU_BUMP = 60,
61298 + GR_RLIM_FSIZE_BUMP = 50000,
61299 + GR_RLIM_DATA_BUMP = 10000,
61300 + GR_RLIM_STACK_BUMP = 1000,
61301 + GR_RLIM_CORE_BUMP = 10000,
61302 + GR_RLIM_RSS_BUMP = 500000,
61303 + GR_RLIM_NPROC_BUMP = 1,
61304 + GR_RLIM_NOFILE_BUMP = 5,
61305 + GR_RLIM_MEMLOCK_BUMP = 50000,
61306 + GR_RLIM_AS_BUMP = 500000,
61307 + GR_RLIM_LOCKS_BUMP = 2,
61308 + GR_RLIM_SIGPENDING_BUMP = 5,
61309 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61310 + GR_RLIM_NICE_BUMP = 1,
61311 + GR_RLIM_RTPRIO_BUMP = 1,
61312 + GR_RLIM_RTTIME_BUMP = 1000000
61313 +};
61314 +
61315 +#endif
61316 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61317 new file mode 100644
61318 index 0000000..da390f1
61319 --- /dev/null
61320 +++ b/include/linux/grinternal.h
61321 @@ -0,0 +1,221 @@
61322 +#ifndef __GRINTERNAL_H
61323 +#define __GRINTERNAL_H
61324 +
61325 +#ifdef CONFIG_GRKERNSEC
61326 +
61327 +#include <linux/fs.h>
61328 +#include <linux/mnt_namespace.h>
61329 +#include <linux/nsproxy.h>
61330 +#include <linux/gracl.h>
61331 +#include <linux/grdefs.h>
61332 +#include <linux/grmsg.h>
61333 +
61334 +void gr_add_learn_entry(const char *fmt, ...)
61335 + __attribute__ ((format (printf, 1, 2)));
61336 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61337 + const struct vfsmount *mnt);
61338 +__u32 gr_check_create(const struct dentry *new_dentry,
61339 + const struct dentry *parent,
61340 + const struct vfsmount *mnt, const __u32 mode);
61341 +int gr_check_protected_task(const struct task_struct *task);
61342 +__u32 to_gr_audit(const __u32 reqmode);
61343 +int gr_set_acls(const int type);
61344 +int gr_apply_subject_to_task(struct task_struct *task);
61345 +int gr_acl_is_enabled(void);
61346 +char gr_roletype_to_char(void);
61347 +
61348 +void gr_handle_alertkill(struct task_struct *task);
61349 +char *gr_to_filename(const struct dentry *dentry,
61350 + const struct vfsmount *mnt);
61351 +char *gr_to_filename1(const struct dentry *dentry,
61352 + const struct vfsmount *mnt);
61353 +char *gr_to_filename2(const struct dentry *dentry,
61354 + const struct vfsmount *mnt);
61355 +char *gr_to_filename3(const struct dentry *dentry,
61356 + const struct vfsmount *mnt);
61357 +
61358 +extern int grsec_enable_ptrace_readexec;
61359 +extern int grsec_enable_harden_ptrace;
61360 +extern int grsec_enable_link;
61361 +extern int grsec_enable_fifo;
61362 +extern int grsec_enable_execve;
61363 +extern int grsec_enable_shm;
61364 +extern int grsec_enable_execlog;
61365 +extern int grsec_enable_signal;
61366 +extern int grsec_enable_audit_ptrace;
61367 +extern int grsec_enable_forkfail;
61368 +extern int grsec_enable_time;
61369 +extern int grsec_enable_rofs;
61370 +extern int grsec_enable_chroot_shmat;
61371 +extern int grsec_enable_chroot_mount;
61372 +extern int grsec_enable_chroot_double;
61373 +extern int grsec_enable_chroot_pivot;
61374 +extern int grsec_enable_chroot_chdir;
61375 +extern int grsec_enable_chroot_chmod;
61376 +extern int grsec_enable_chroot_mknod;
61377 +extern int grsec_enable_chroot_fchdir;
61378 +extern int grsec_enable_chroot_nice;
61379 +extern int grsec_enable_chroot_execlog;
61380 +extern int grsec_enable_chroot_caps;
61381 +extern int grsec_enable_chroot_sysctl;
61382 +extern int grsec_enable_chroot_unix;
61383 +extern int grsec_enable_tpe;
61384 +extern int grsec_tpe_gid;
61385 +extern int grsec_enable_tpe_all;
61386 +extern int grsec_enable_tpe_invert;
61387 +extern int grsec_enable_socket_all;
61388 +extern int grsec_socket_all_gid;
61389 +extern int grsec_enable_socket_client;
61390 +extern int grsec_socket_client_gid;
61391 +extern int grsec_enable_socket_server;
61392 +extern int grsec_socket_server_gid;
61393 +extern int grsec_audit_gid;
61394 +extern int grsec_enable_group;
61395 +extern int grsec_enable_audit_textrel;
61396 +extern int grsec_enable_log_rwxmaps;
61397 +extern int grsec_enable_mount;
61398 +extern int grsec_enable_chdir;
61399 +extern int grsec_resource_logging;
61400 +extern int grsec_enable_blackhole;
61401 +extern int grsec_lastack_retries;
61402 +extern int grsec_enable_brute;
61403 +extern int grsec_lock;
61404 +
61405 +extern spinlock_t grsec_alert_lock;
61406 +extern unsigned long grsec_alert_wtime;
61407 +extern unsigned long grsec_alert_fyet;
61408 +
61409 +extern spinlock_t grsec_audit_lock;
61410 +
61411 +extern rwlock_t grsec_exec_file_lock;
61412 +
61413 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61414 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61415 + (tsk)->exec_file->f_vfsmnt) : "/")
61416 +
61417 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61418 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61419 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61420 +
61421 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61422 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61423 + (tsk)->exec_file->f_vfsmnt) : "/")
61424 +
61425 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61426 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61427 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61428 +
61429 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61430 +
61431 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61432 +
61433 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61434 + (task)->pid, (cred)->uid, \
61435 + (cred)->euid, (cred)->gid, (cred)->egid, \
61436 + gr_parent_task_fullpath(task), \
61437 + (task)->real_parent->comm, (task)->real_parent->pid, \
61438 + (pcred)->uid, (pcred)->euid, \
61439 + (pcred)->gid, (pcred)->egid
61440 +
61441 +#define GR_CHROOT_CAPS {{ \
61442 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61443 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61444 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61445 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61446 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61447 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61448 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61449 +
61450 +#define security_learn(normal_msg,args...) \
61451 +({ \
61452 + read_lock(&grsec_exec_file_lock); \
61453 + gr_add_learn_entry(normal_msg "\n", ## args); \
61454 + read_unlock(&grsec_exec_file_lock); \
61455 +})
61456 +
61457 +enum {
61458 + GR_DO_AUDIT,
61459 + GR_DONT_AUDIT,
61460 + /* used for non-audit messages that we shouldn't kill the task on */
61461 + GR_DONT_AUDIT_GOOD
61462 +};
61463 +
61464 +enum {
61465 + GR_TTYSNIFF,
61466 + GR_RBAC,
61467 + GR_RBAC_STR,
61468 + GR_STR_RBAC,
61469 + GR_RBAC_MODE2,
61470 + GR_RBAC_MODE3,
61471 + GR_FILENAME,
61472 + GR_SYSCTL_HIDDEN,
61473 + GR_NOARGS,
61474 + GR_ONE_INT,
61475 + GR_ONE_INT_TWO_STR,
61476 + GR_ONE_STR,
61477 + GR_STR_INT,
61478 + GR_TWO_STR_INT,
61479 + GR_TWO_INT,
61480 + GR_TWO_U64,
61481 + GR_THREE_INT,
61482 + GR_FIVE_INT_TWO_STR,
61483 + GR_TWO_STR,
61484 + GR_THREE_STR,
61485 + GR_FOUR_STR,
61486 + GR_STR_FILENAME,
61487 + GR_FILENAME_STR,
61488 + GR_FILENAME_TWO_INT,
61489 + GR_FILENAME_TWO_INT_STR,
61490 + GR_TEXTREL,
61491 + GR_PTRACE,
61492 + GR_RESOURCE,
61493 + GR_CAP,
61494 + GR_SIG,
61495 + GR_SIG2,
61496 + GR_CRASH1,
61497 + GR_CRASH2,
61498 + GR_PSACCT,
61499 + GR_RWXMAP
61500 +};
61501 +
61502 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61503 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61504 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61505 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61506 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61507 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61508 +#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)
61509 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61510 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61511 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61512 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61513 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61514 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61515 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61516 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61517 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61518 +#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)
61519 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61520 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61521 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61522 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61523 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61524 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61525 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61526 +#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)
61527 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61528 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61529 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61530 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61531 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61532 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61533 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61534 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61535 +#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)
61536 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61537 +
61538 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61539 +
61540 +#endif
61541 +
61542 +#endif
61543 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61544 new file mode 100644
61545 index 0000000..ae576a1
61546 --- /dev/null
61547 +++ b/include/linux/grmsg.h
61548 @@ -0,0 +1,109 @@
61549 +#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"
61550 +#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"
61551 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61552 +#define GR_STOPMOD_MSG "denied modification of module state by "
61553 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61554 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61555 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61556 +#define GR_IOPL_MSG "denied use of iopl() by "
61557 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61558 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61559 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61560 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61561 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61562 +#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"
61563 +#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"
61564 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61565 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61566 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61567 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61568 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61569 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61570 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61571 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61572 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61573 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61574 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61575 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61576 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61577 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61578 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61579 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61580 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61581 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61582 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61583 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61584 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61585 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61586 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61587 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61588 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61589 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61590 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61591 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61592 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61593 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61594 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61595 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61596 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61597 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61598 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61599 +#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"
61600 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61601 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61602 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61603 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61604 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61605 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61606 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61607 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61608 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61609 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61610 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61611 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61612 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61613 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61614 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61615 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61616 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61617 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61618 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61619 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61620 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61621 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61622 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61623 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61624 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61625 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61626 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61627 +#define GR_TIME_MSG "time set by "
61628 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61629 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61630 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61631 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61632 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61633 +#define GR_BIND_MSG "denied bind() by "
61634 +#define GR_CONNECT_MSG "denied connect() by "
61635 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61636 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61637 +#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"
61638 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61639 +#define GR_CAP_ACL_MSG "use of %s denied for "
61640 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61641 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61642 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61643 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61644 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61645 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61646 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61647 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61648 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61649 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61650 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61651 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61652 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61653 +#define GR_VM86_MSG "denied use of vm86 by "
61654 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61655 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61656 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61657 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61658 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61659 new file mode 100644
61660 index 0000000..acd05db
61661 --- /dev/null
61662 +++ b/include/linux/grsecurity.h
61663 @@ -0,0 +1,232 @@
61664 +#ifndef GR_SECURITY_H
61665 +#define GR_SECURITY_H
61666 +#include <linux/fs.h>
61667 +#include <linux/fs_struct.h>
61668 +#include <linux/binfmts.h>
61669 +#include <linux/gracl.h>
61670 +
61671 +/* notify of brain-dead configs */
61672 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61673 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61674 +#endif
61675 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61676 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61677 +#endif
61678 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61679 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61680 +#endif
61681 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61682 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61683 +#endif
61684 +
61685 +#include <linux/compat.h>
61686 +
61687 +struct user_arg_ptr {
61688 +#ifdef CONFIG_COMPAT
61689 + bool is_compat;
61690 +#endif
61691 + union {
61692 + const char __user *const __user *native;
61693 +#ifdef CONFIG_COMPAT
61694 + compat_uptr_t __user *compat;
61695 +#endif
61696 + } ptr;
61697 +};
61698 +
61699 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61700 +void gr_handle_brute_check(void);
61701 +void gr_handle_kernel_exploit(void);
61702 +int gr_process_user_ban(void);
61703 +
61704 +char gr_roletype_to_char(void);
61705 +
61706 +int gr_acl_enable_at_secure(void);
61707 +
61708 +int gr_check_user_change(int real, int effective, int fs);
61709 +int gr_check_group_change(int real, int effective, int fs);
61710 +
61711 +void gr_del_task_from_ip_table(struct task_struct *p);
61712 +
61713 +int gr_pid_is_chrooted(struct task_struct *p);
61714 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61715 +int gr_handle_chroot_nice(void);
61716 +int gr_handle_chroot_sysctl(const int op);
61717 +int gr_handle_chroot_setpriority(struct task_struct *p,
61718 + const int niceval);
61719 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61720 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61721 + const struct vfsmount *mnt);
61722 +void gr_handle_chroot_chdir(struct path *path);
61723 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61724 + const struct vfsmount *mnt, const int mode);
61725 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61726 + const struct vfsmount *mnt, const int mode);
61727 +int gr_handle_chroot_mount(const struct dentry *dentry,
61728 + const struct vfsmount *mnt,
61729 + const char *dev_name);
61730 +int gr_handle_chroot_pivot(void);
61731 +int gr_handle_chroot_unix(const pid_t pid);
61732 +
61733 +int gr_handle_rawio(const struct inode *inode);
61734 +
61735 +void gr_handle_ioperm(void);
61736 +void gr_handle_iopl(void);
61737 +
61738 +umode_t gr_acl_umask(void);
61739 +
61740 +int gr_tpe_allow(const struct file *file);
61741 +
61742 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61743 +void gr_clear_chroot_entries(struct task_struct *task);
61744 +
61745 +void gr_log_forkfail(const int retval);
61746 +void gr_log_timechange(void);
61747 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61748 +void gr_log_chdir(const struct dentry *dentry,
61749 + const struct vfsmount *mnt);
61750 +void gr_log_chroot_exec(const struct dentry *dentry,
61751 + const struct vfsmount *mnt);
61752 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61753 +void gr_log_remount(const char *devname, const int retval);
61754 +void gr_log_unmount(const char *devname, const int retval);
61755 +void gr_log_mount(const char *from, const char *to, const int retval);
61756 +void gr_log_textrel(struct vm_area_struct *vma);
61757 +void gr_log_rwxmmap(struct file *file);
61758 +void gr_log_rwxmprotect(struct file *file);
61759 +
61760 +int gr_handle_follow_link(const struct inode *parent,
61761 + const struct inode *inode,
61762 + const struct dentry *dentry,
61763 + const struct vfsmount *mnt);
61764 +int gr_handle_fifo(const struct dentry *dentry,
61765 + const struct vfsmount *mnt,
61766 + const struct dentry *dir, const int flag,
61767 + const int acc_mode);
61768 +int gr_handle_hardlink(const struct dentry *dentry,
61769 + const struct vfsmount *mnt,
61770 + struct inode *inode,
61771 + const int mode, const char *to);
61772 +
61773 +int gr_is_capable(const int cap);
61774 +int gr_is_capable_nolog(const int cap);
61775 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61776 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61777 +
61778 +void gr_learn_resource(const struct task_struct *task, const int limit,
61779 + const unsigned long wanted, const int gt);
61780 +void gr_copy_label(struct task_struct *tsk);
61781 +void gr_handle_crash(struct task_struct *task, const int sig);
61782 +int gr_handle_signal(const struct task_struct *p, const int sig);
61783 +int gr_check_crash_uid(const uid_t uid);
61784 +int gr_check_protected_task(const struct task_struct *task);
61785 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61786 +int gr_acl_handle_mmap(const struct file *file,
61787 + const unsigned long prot);
61788 +int gr_acl_handle_mprotect(const struct file *file,
61789 + const unsigned long prot);
61790 +int gr_check_hidden_task(const struct task_struct *tsk);
61791 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61792 + const struct vfsmount *mnt);
61793 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61794 + const struct vfsmount *mnt);
61795 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61796 + const struct vfsmount *mnt, const int fmode);
61797 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61798 + const struct vfsmount *mnt, umode_t *mode);
61799 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61800 + const struct vfsmount *mnt);
61801 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61802 + const struct vfsmount *mnt);
61803 +int gr_handle_ptrace(struct task_struct *task, const long request);
61804 +int gr_handle_proc_ptrace(struct task_struct *task);
61805 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61806 + const struct vfsmount *mnt);
61807 +int gr_check_crash_exec(const struct file *filp);
61808 +int gr_acl_is_enabled(void);
61809 +void gr_set_kernel_label(struct task_struct *task);
61810 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61811 + const gid_t gid);
61812 +int gr_set_proc_label(const struct dentry *dentry,
61813 + const struct vfsmount *mnt,
61814 + const int unsafe_flags);
61815 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61816 + const struct vfsmount *mnt);
61817 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61818 + const struct vfsmount *mnt, int acc_mode);
61819 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61820 + const struct dentry *p_dentry,
61821 + const struct vfsmount *p_mnt,
61822 + int open_flags, int acc_mode, const int imode);
61823 +void gr_handle_create(const struct dentry *dentry,
61824 + const struct vfsmount *mnt);
61825 +void gr_handle_proc_create(const struct dentry *dentry,
61826 + const struct inode *inode);
61827 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61828 + const struct dentry *parent_dentry,
61829 + const struct vfsmount *parent_mnt,
61830 + const int mode);
61831 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61832 + const struct dentry *parent_dentry,
61833 + const struct vfsmount *parent_mnt);
61834 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61835 + const struct vfsmount *mnt);
61836 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61837 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61838 + const struct vfsmount *mnt);
61839 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61840 + const struct dentry *parent_dentry,
61841 + const struct vfsmount *parent_mnt,
61842 + const char *from);
61843 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61844 + const struct dentry *parent_dentry,
61845 + const struct vfsmount *parent_mnt,
61846 + const struct dentry *old_dentry,
61847 + const struct vfsmount *old_mnt, const char *to);
61848 +int gr_acl_handle_rename(struct dentry *new_dentry,
61849 + struct dentry *parent_dentry,
61850 + const struct vfsmount *parent_mnt,
61851 + struct dentry *old_dentry,
61852 + struct inode *old_parent_inode,
61853 + struct vfsmount *old_mnt, const char *newname);
61854 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61855 + struct dentry *old_dentry,
61856 + struct dentry *new_dentry,
61857 + struct vfsmount *mnt, const __u8 replace);
61858 +__u32 gr_check_link(const struct dentry *new_dentry,
61859 + const struct dentry *parent_dentry,
61860 + const struct vfsmount *parent_mnt,
61861 + const struct dentry *old_dentry,
61862 + const struct vfsmount *old_mnt);
61863 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61864 + const unsigned int namelen, const ino_t ino);
61865 +
61866 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61867 + const struct vfsmount *mnt);
61868 +void gr_acl_handle_exit(void);
61869 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61870 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61871 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61872 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61873 +void gr_audit_ptrace(struct task_struct *task);
61874 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61875 +
61876 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61877 +
61878 +#ifdef CONFIG_GRKERNSEC
61879 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61880 +void gr_handle_vm86(void);
61881 +void gr_handle_mem_readwrite(u64 from, u64 to);
61882 +
61883 +void gr_log_badprocpid(const char *entry);
61884 +
61885 +extern int grsec_enable_dmesg;
61886 +extern int grsec_disable_privio;
61887 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61888 +extern int grsec_enable_chroot_findtask;
61889 +#endif
61890 +#ifdef CONFIG_GRKERNSEC_SETXID
61891 +extern int grsec_enable_setxid;
61892 +#endif
61893 +#endif
61894 +
61895 +#endif
61896 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61897 new file mode 100644
61898 index 0000000..e7ffaaf
61899 --- /dev/null
61900 +++ b/include/linux/grsock.h
61901 @@ -0,0 +1,19 @@
61902 +#ifndef __GRSOCK_H
61903 +#define __GRSOCK_H
61904 +
61905 +extern void gr_attach_curr_ip(const struct sock *sk);
61906 +extern int gr_handle_sock_all(const int family, const int type,
61907 + const int protocol);
61908 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61909 +extern int gr_handle_sock_server_other(const struct sock *sck);
61910 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61911 +extern int gr_search_connect(struct socket * sock,
61912 + struct sockaddr_in * addr);
61913 +extern int gr_search_bind(struct socket * sock,
61914 + struct sockaddr_in * addr);
61915 +extern int gr_search_listen(struct socket * sock);
61916 +extern int gr_search_accept(struct socket * sock);
61917 +extern int gr_search_socket(const int domain, const int type,
61918 + const int protocol);
61919 +
61920 +#endif
61921 diff --git a/include/linux/hid.h b/include/linux/hid.h
61922 index 3a95da6..51986f1 100644
61923 --- a/include/linux/hid.h
61924 +++ b/include/linux/hid.h
61925 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61926 unsigned int code, int value);
61927
61928 int (*parse)(struct hid_device *hdev);
61929 -};
61930 +} __no_const;
61931
61932 #define PM_HINT_FULLON 1<<5
61933 #define PM_HINT_NORMAL 1<<1
61934 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61935 index 3a93f73..b19d0b3 100644
61936 --- a/include/linux/highmem.h
61937 +++ b/include/linux/highmem.h
61938 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61939 kunmap_atomic(kaddr, KM_USER0);
61940 }
61941
61942 +static inline void sanitize_highpage(struct page *page)
61943 +{
61944 + void *kaddr;
61945 + unsigned long flags;
61946 +
61947 + local_irq_save(flags);
61948 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
61949 + clear_page(kaddr);
61950 + kunmap_atomic(kaddr, KM_CLEARPAGE);
61951 + local_irq_restore(flags);
61952 +}
61953 +
61954 static inline void zero_user_segments(struct page *page,
61955 unsigned start1, unsigned end1,
61956 unsigned start2, unsigned end2)
61957 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61958 index 8e25a91..551b161 100644
61959 --- a/include/linux/i2c.h
61960 +++ b/include/linux/i2c.h
61961 @@ -364,6 +364,7 @@ struct i2c_algorithm {
61962 /* To determine what the adapter supports */
61963 u32 (*functionality) (struct i2c_adapter *);
61964 };
61965 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61966
61967 /*
61968 * i2c_adapter is the structure used to identify a physical i2c bus along
61969 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61970 index a6deef4..c56a7f2 100644
61971 --- a/include/linux/i2o.h
61972 +++ b/include/linux/i2o.h
61973 @@ -564,7 +564,7 @@ struct i2o_controller {
61974 struct i2o_device *exec; /* Executive */
61975 #if BITS_PER_LONG == 64
61976 spinlock_t context_list_lock; /* lock for context_list */
61977 - atomic_t context_list_counter; /* needed for unique contexts */
61978 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61979 struct list_head context_list; /* list of context id's
61980 and pointers */
61981 #endif
61982 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61983 index 58404b0..439ed95 100644
61984 --- a/include/linux/if_team.h
61985 +++ b/include/linux/if_team.h
61986 @@ -64,6 +64,7 @@ struct team_mode_ops {
61987 void (*port_leave)(struct team *team, struct team_port *port);
61988 void (*port_change_mac)(struct team *team, struct team_port *port);
61989 };
61990 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61991
61992 enum team_option_type {
61993 TEAM_OPTION_TYPE_U32,
61994 @@ -112,7 +113,7 @@ struct team {
61995 struct list_head option_list;
61996
61997 const struct team_mode *mode;
61998 - struct team_mode_ops ops;
61999 + team_mode_ops_no_const ops;
62000 long mode_priv[TEAM_MODE_PRIV_LONGS];
62001 };
62002
62003 diff --git a/include/linux/init.h b/include/linux/init.h
62004 index 6b95109..4aca62c 100644
62005 --- a/include/linux/init.h
62006 +++ b/include/linux/init.h
62007 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
62008
62009 /* Each module must use one module_init(). */
62010 #define module_init(initfn) \
62011 - static inline initcall_t __inittest(void) \
62012 + static inline __used initcall_t __inittest(void) \
62013 { return initfn; } \
62014 int init_module(void) __attribute__((alias(#initfn)));
62015
62016 /* This is only required if you want to be unloadable. */
62017 #define module_exit(exitfn) \
62018 - static inline exitcall_t __exittest(void) \
62019 + static inline __used exitcall_t __exittest(void) \
62020 { return exitfn; } \
62021 void cleanup_module(void) __attribute__((alias(#exitfn)));
62022
62023 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62024 index 9c66b1a..a3fdded 100644
62025 --- a/include/linux/init_task.h
62026 +++ b/include/linux/init_task.h
62027 @@ -127,6 +127,12 @@ extern struct cred init_cred;
62028
62029 #define INIT_TASK_COMM "swapper"
62030
62031 +#ifdef CONFIG_X86
62032 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62033 +#else
62034 +#define INIT_TASK_THREAD_INFO
62035 +#endif
62036 +
62037 /*
62038 * INIT_TASK is used to set up the first task table, touch at
62039 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62040 @@ -165,6 +171,7 @@ extern struct cred init_cred;
62041 RCU_INIT_POINTER(.cred, &init_cred), \
62042 .comm = INIT_TASK_COMM, \
62043 .thread = INIT_THREAD, \
62044 + INIT_TASK_THREAD_INFO \
62045 .fs = &init_fs, \
62046 .files = &init_files, \
62047 .signal = &init_signals, \
62048 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62049 index e6ca56d..8583707 100644
62050 --- a/include/linux/intel-iommu.h
62051 +++ b/include/linux/intel-iommu.h
62052 @@ -296,7 +296,7 @@ struct iommu_flush {
62053 u8 fm, u64 type);
62054 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62055 unsigned int size_order, u64 type);
62056 -};
62057 +} __no_const;
62058
62059 enum {
62060 SR_DMAR_FECTL_REG,
62061 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62062 index a64b00e..464d8bc 100644
62063 --- a/include/linux/interrupt.h
62064 +++ b/include/linux/interrupt.h
62065 @@ -441,7 +441,7 @@ enum
62066 /* map softirq index to softirq name. update 'softirq_to_name' in
62067 * kernel/softirq.c when adding a new softirq.
62068 */
62069 -extern char *softirq_to_name[NR_SOFTIRQS];
62070 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62071
62072 /* softirq mask and active fields moved to irq_cpustat_t in
62073 * asm/hardirq.h to get better cache usage. KAO
62074 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62075
62076 struct softirq_action
62077 {
62078 - void (*action)(struct softirq_action *);
62079 + void (*action)(void);
62080 };
62081
62082 asmlinkage void do_softirq(void);
62083 asmlinkage void __do_softirq(void);
62084 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62085 +extern void open_softirq(int nr, void (*action)(void));
62086 extern void softirq_init(void);
62087 static inline void __raise_softirq_irqoff(unsigned int nr)
62088 {
62089 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62090 index 3875719..4cd454c 100644
62091 --- a/include/linux/kallsyms.h
62092 +++ b/include/linux/kallsyms.h
62093 @@ -15,7 +15,8 @@
62094
62095 struct module;
62096
62097 -#ifdef CONFIG_KALLSYMS
62098 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62099 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62100 /* Lookup the address for a symbol. Returns 0 if not found. */
62101 unsigned long kallsyms_lookup_name(const char *name);
62102
62103 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62104 /* Stupid that this does nothing, but I didn't create this mess. */
62105 #define __print_symbol(fmt, addr)
62106 #endif /*CONFIG_KALLSYMS*/
62107 +#else /* when included by kallsyms.c, vsnprintf.c, or
62108 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62109 +extern void __print_symbol(const char *fmt, unsigned long address);
62110 +extern int sprint_backtrace(char *buffer, unsigned long address);
62111 +extern int sprint_symbol(char *buffer, unsigned long address);
62112 +const char *kallsyms_lookup(unsigned long addr,
62113 + unsigned long *symbolsize,
62114 + unsigned long *offset,
62115 + char **modname, char *namebuf);
62116 +#endif
62117
62118 /* This macro allows us to keep printk typechecking */
62119 static __printf(1, 2)
62120 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62121 index c4d2fc1..5df9c19 100644
62122 --- a/include/linux/kgdb.h
62123 +++ b/include/linux/kgdb.h
62124 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62125 extern int kgdb_io_module_registered;
62126
62127 extern atomic_t kgdb_setting_breakpoint;
62128 -extern atomic_t kgdb_cpu_doing_single_step;
62129 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62130
62131 extern struct task_struct *kgdb_usethread;
62132 extern struct task_struct *kgdb_contthread;
62133 @@ -252,7 +252,7 @@ struct kgdb_arch {
62134 void (*disable_hw_break)(struct pt_regs *regs);
62135 void (*remove_all_hw_break)(void);
62136 void (*correct_hw_break)(void);
62137 -};
62138 +} __do_const;
62139
62140 /**
62141 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62142 @@ -277,7 +277,7 @@ struct kgdb_io {
62143 void (*pre_exception) (void);
62144 void (*post_exception) (void);
62145 int is_console;
62146 -};
62147 +} __do_const;
62148
62149 extern struct kgdb_arch arch_kgdb_ops;
62150
62151 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62152 index 0fb48ef..1b680b2 100644
62153 --- a/include/linux/kmod.h
62154 +++ b/include/linux/kmod.h
62155 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62156 * usually useless though. */
62157 extern __printf(2, 3)
62158 int __request_module(bool wait, const char *name, ...);
62159 +extern __printf(3, 4)
62160 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62161 #define request_module(mod...) __request_module(true, mod)
62162 #define request_module_nowait(mod...) __request_module(false, mod)
62163 #define try_then_request_module(x, mod...) \
62164 diff --git a/include/linux/kref.h b/include/linux/kref.h
62165 index 9c07dce..a92fa71 100644
62166 --- a/include/linux/kref.h
62167 +++ b/include/linux/kref.h
62168 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62169 static inline int kref_sub(struct kref *kref, unsigned int count,
62170 void (*release)(struct kref *kref))
62171 {
62172 - WARN_ON(release == NULL);
62173 + BUG_ON(release == NULL);
62174
62175 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62176 release(kref);
62177 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62178 index 900c763..098aefa 100644
62179 --- a/include/linux/kvm_host.h
62180 +++ b/include/linux/kvm_host.h
62181 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62182 void vcpu_load(struct kvm_vcpu *vcpu);
62183 void vcpu_put(struct kvm_vcpu *vcpu);
62184
62185 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62186 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62187 struct module *module);
62188 void kvm_exit(void);
62189
62190 @@ -416,20 +416,20 @@ void kvm_get_pfn(pfn_t pfn);
62191 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
62192 int len);
62193 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
62194 - unsigned long len);
62195 -int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
62196 + unsigned long len) __size_overflow(4);
62197 +int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) __size_overflow(2,4);
62198 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62199 - void *data, unsigned long len);
62200 + void *data, unsigned long len) __size_overflow(4);
62201 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
62202 int offset, int len);
62203 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
62204 - unsigned long len);
62205 + unsigned long len) __size_overflow(2,4);
62206 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62207 - void *data, unsigned long len);
62208 + void *data, unsigned long len) __size_overflow(4);
62209 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62210 gpa_t gpa);
62211 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
62212 -int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
62213 +int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) __size_overflow(2,3);
62214 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
62215 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
62216 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
62217 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62218 struct kvm_guest_debug *dbg);
62219 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62220
62221 -int kvm_arch_init(void *opaque);
62222 +int kvm_arch_init(const void *opaque);
62223 void kvm_arch_exit(void);
62224
62225 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62226 @@ -593,6 +593,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
62227
62228 #ifdef CONFIG_IOMMU_API
62229 int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
62230 +void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
62231 int kvm_iommu_map_guest(struct kvm *kvm);
62232 int kvm_iommu_unmap_guest(struct kvm *kvm);
62233 int kvm_assign_device(struct kvm *kvm,
62234 @@ -606,6 +607,11 @@ static inline int kvm_iommu_map_pages(struct kvm *kvm,
62235 return 0;
62236 }
62237
62238 +static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
62239 + struct kvm_memory_slot *slot)
62240 +{
62241 +}
62242 +
62243 static inline int kvm_iommu_map_guest(struct kvm *kvm)
62244 {
62245 return -ENODEV;
62246 @@ -721,7 +727,7 @@ int kvm_setup_default_irq_routing(struct kvm *kvm);
62247 int kvm_set_irq_routing(struct kvm *kvm,
62248 const struct kvm_irq_routing_entry *entries,
62249 unsigned nr,
62250 - unsigned flags);
62251 + unsigned flags) __size_overflow(3);
62252 void kvm_free_irq_routing(struct kvm *kvm);
62253
62254 #else
62255 diff --git a/include/linux/libata.h b/include/linux/libata.h
62256 index cafc09a..d7e7829 100644
62257 --- a/include/linux/libata.h
62258 +++ b/include/linux/libata.h
62259 @@ -909,7 +909,7 @@ struct ata_port_operations {
62260 * fields must be pointers.
62261 */
62262 const struct ata_port_operations *inherits;
62263 -};
62264 +} __do_const;
62265
62266 struct ata_port_info {
62267 unsigned long flags;
62268 diff --git a/include/linux/mca.h b/include/linux/mca.h
62269 index 3797270..7765ede 100644
62270 --- a/include/linux/mca.h
62271 +++ b/include/linux/mca.h
62272 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62273 int region);
62274 void * (*mca_transform_memory)(struct mca_device *,
62275 void *memory);
62276 -};
62277 +} __no_const;
62278
62279 struct mca_bus {
62280 u64 default_dma_mask;
62281 diff --git a/include/linux/memory.h b/include/linux/memory.h
62282 index 1ac7f6e..a5794d0 100644
62283 --- a/include/linux/memory.h
62284 +++ b/include/linux/memory.h
62285 @@ -143,7 +143,7 @@ struct memory_accessor {
62286 size_t count);
62287 ssize_t (*write)(struct memory_accessor *, const char *buf,
62288 off_t offset, size_t count);
62289 -};
62290 +} __no_const;
62291
62292 /*
62293 * Kernel text modification mutex, used for code patching. Users of this lock
62294 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62295 index 9970337..9444122 100644
62296 --- a/include/linux/mfd/abx500.h
62297 +++ b/include/linux/mfd/abx500.h
62298 @@ -188,6 +188,7 @@ struct abx500_ops {
62299 int (*event_registers_startup_state_get) (struct device *, u8 *);
62300 int (*startup_irq_enabled) (struct device *, unsigned int);
62301 };
62302 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62303
62304 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62305 void abx500_remove_ops(struct device *dev);
62306 diff --git a/include/linux/mm.h b/include/linux/mm.h
62307 index 17b27cd..467ba2f 100644
62308 --- a/include/linux/mm.h
62309 +++ b/include/linux/mm.h
62310 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62311
62312 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62313 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62314 +
62315 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62316 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62317 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62318 +#else
62319 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62320 +#endif
62321 +
62322 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62323 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62324
62325 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62326 int set_page_dirty_lock(struct page *page);
62327 int clear_page_dirty_for_io(struct page *page);
62328
62329 -/* Is the vma a continuation of the stack vma above it? */
62330 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62331 -{
62332 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62333 -}
62334 -
62335 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62336 - unsigned long addr)
62337 -{
62338 - return (vma->vm_flags & VM_GROWSDOWN) &&
62339 - (vma->vm_start == addr) &&
62340 - !vma_growsdown(vma->vm_prev, addr);
62341 -}
62342 -
62343 -/* Is the vma a continuation of the stack vma below it? */
62344 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62345 -{
62346 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62347 -}
62348 -
62349 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62350 - unsigned long addr)
62351 -{
62352 - return (vma->vm_flags & VM_GROWSUP) &&
62353 - (vma->vm_end == addr) &&
62354 - !vma_growsup(vma->vm_next, addr);
62355 -}
62356 -
62357 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62358 unsigned long old_addr, struct vm_area_struct *new_vma,
62359 unsigned long new_addr, unsigned long len);
62360 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62361 }
62362 #endif
62363
62364 +#ifdef CONFIG_MMU
62365 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62366 +#else
62367 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62368 +{
62369 + return __pgprot(0);
62370 +}
62371 +#endif
62372 +
62373 int vma_wants_writenotify(struct vm_area_struct *vma);
62374
62375 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62376 @@ -1409,6 +1397,7 @@ out:
62377 }
62378
62379 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62380 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62381
62382 extern unsigned long do_brk(unsigned long, unsigned long);
62383
62384 @@ -1466,6 +1455,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62385 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62386 struct vm_area_struct **pprev);
62387
62388 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62389 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62390 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62391 +
62392 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62393 NULL if none. Assume start_addr < end_addr. */
62394 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62395 @@ -1494,15 +1487,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62396 return vma;
62397 }
62398
62399 -#ifdef CONFIG_MMU
62400 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62401 -#else
62402 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62403 -{
62404 - return __pgprot(0);
62405 -}
62406 -#endif
62407 -
62408 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62409 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62410 unsigned long pfn, unsigned long size, pgprot_t);
62411 @@ -1606,7 +1590,7 @@ extern int unpoison_memory(unsigned long pfn);
62412 extern int sysctl_memory_failure_early_kill;
62413 extern int sysctl_memory_failure_recovery;
62414 extern void shake_page(struct page *p, int access);
62415 -extern atomic_long_t mce_bad_pages;
62416 +extern atomic_long_unchecked_t mce_bad_pages;
62417 extern int soft_offline_page(struct page *page, int flags);
62418
62419 extern void dump_page(struct page *page);
62420 @@ -1637,5 +1621,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62421 static inline bool page_is_guard(struct page *page) { return false; }
62422 #endif /* CONFIG_DEBUG_PAGEALLOC */
62423
62424 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62425 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62426 +#else
62427 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62428 +#endif
62429 +
62430 #endif /* __KERNEL__ */
62431 #endif /* _LINUX_MM_H */
62432 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62433 index 3cc3062..efeaeb7 100644
62434 --- a/include/linux/mm_types.h
62435 +++ b/include/linux/mm_types.h
62436 @@ -252,6 +252,8 @@ struct vm_area_struct {
62437 #ifdef CONFIG_NUMA
62438 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62439 #endif
62440 +
62441 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62442 };
62443
62444 struct core_thread {
62445 @@ -326,7 +328,7 @@ struct mm_struct {
62446 unsigned long def_flags;
62447 unsigned long nr_ptes; /* Page table pages */
62448 unsigned long start_code, end_code, start_data, end_data;
62449 - unsigned long start_brk, brk, start_stack;
62450 + unsigned long brk_gap, start_brk, brk, start_stack;
62451 unsigned long arg_start, arg_end, env_start, env_end;
62452
62453 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62454 @@ -388,6 +390,24 @@ struct mm_struct {
62455 #ifdef CONFIG_CPUMASK_OFFSTACK
62456 struct cpumask cpumask_allocation;
62457 #endif
62458 +
62459 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS) || defined(CONFIG_PAX_HAVE_ACL_FLAGS) || defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62460 + unsigned long pax_flags;
62461 +#endif
62462 +
62463 +#ifdef CONFIG_PAX_DLRESOLVE
62464 + unsigned long call_dl_resolve;
62465 +#endif
62466 +
62467 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62468 + unsigned long call_syscall;
62469 +#endif
62470 +
62471 +#ifdef CONFIG_PAX_ASLR
62472 + unsigned long delta_mmap; /* randomized offset */
62473 + unsigned long delta_stack; /* randomized offset */
62474 +#endif
62475 +
62476 };
62477
62478 static inline void mm_init_cpumask(struct mm_struct *mm)
62479 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62480 index 1d1b1e1..2a13c78 100644
62481 --- a/include/linux/mmu_notifier.h
62482 +++ b/include/linux/mmu_notifier.h
62483 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62484 */
62485 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62486 ({ \
62487 - pte_t __pte; \
62488 + pte_t ___pte; \
62489 struct vm_area_struct *___vma = __vma; \
62490 unsigned long ___address = __address; \
62491 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62492 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62493 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62494 - __pte; \
62495 + ___pte; \
62496 })
62497
62498 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62499 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62500 index 650ba2f..af0a58c 100644
62501 --- a/include/linux/mmzone.h
62502 +++ b/include/linux/mmzone.h
62503 @@ -379,7 +379,7 @@ struct zone {
62504 unsigned long flags; /* zone flags, see below */
62505
62506 /* Zone statistics */
62507 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62508 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62509
62510 /*
62511 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62512 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62513 index 83ac071..2656e0e 100644
62514 --- a/include/linux/mod_devicetable.h
62515 +++ b/include/linux/mod_devicetable.h
62516 @@ -12,7 +12,7 @@
62517 typedef unsigned long kernel_ulong_t;
62518 #endif
62519
62520 -#define PCI_ANY_ID (~0)
62521 +#define PCI_ANY_ID ((__u16)~0)
62522
62523 struct pci_device_id {
62524 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62525 @@ -131,7 +131,7 @@ struct usb_device_id {
62526 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62527 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62528
62529 -#define HID_ANY_ID (~0)
62530 +#define HID_ANY_ID (~0U)
62531
62532 struct hid_device_id {
62533 __u16 bus;
62534 diff --git a/include/linux/module.h b/include/linux/module.h
62535 index 4598bf0..e069d7f 100644
62536 --- a/include/linux/module.h
62537 +++ b/include/linux/module.h
62538 @@ -17,6 +17,7 @@
62539 #include <linux/moduleparam.h>
62540 #include <linux/tracepoint.h>
62541 #include <linux/export.h>
62542 +#include <linux/fs.h>
62543
62544 #include <linux/percpu.h>
62545 #include <asm/module.h>
62546 @@ -275,19 +276,16 @@ struct module
62547 int (*init)(void);
62548
62549 /* If this is non-NULL, vfree after init() returns */
62550 - void *module_init;
62551 + void *module_init_rx, *module_init_rw;
62552
62553 /* Here is the actual code + data, vfree'd on unload. */
62554 - void *module_core;
62555 + void *module_core_rx, *module_core_rw;
62556
62557 /* Here are the sizes of the init and core sections */
62558 - unsigned int init_size, core_size;
62559 + unsigned int init_size_rw, core_size_rw;
62560
62561 /* The size of the executable code in each section. */
62562 - unsigned int init_text_size, core_text_size;
62563 -
62564 - /* Size of RO sections of the module (text+rodata) */
62565 - unsigned int init_ro_size, core_ro_size;
62566 + unsigned int init_size_rx, core_size_rx;
62567
62568 /* Arch-specific module values */
62569 struct mod_arch_specific arch;
62570 @@ -343,6 +341,10 @@ struct module
62571 #ifdef CONFIG_EVENT_TRACING
62572 struct ftrace_event_call **trace_events;
62573 unsigned int num_trace_events;
62574 + struct file_operations trace_id;
62575 + struct file_operations trace_enable;
62576 + struct file_operations trace_format;
62577 + struct file_operations trace_filter;
62578 #endif
62579 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62580 unsigned int num_ftrace_callsites;
62581 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62582 bool is_module_percpu_address(unsigned long addr);
62583 bool is_module_text_address(unsigned long addr);
62584
62585 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62586 +{
62587 +
62588 +#ifdef CONFIG_PAX_KERNEXEC
62589 + if (ktla_ktva(addr) >= (unsigned long)start &&
62590 + ktla_ktva(addr) < (unsigned long)start + size)
62591 + return 1;
62592 +#endif
62593 +
62594 + return ((void *)addr >= start && (void *)addr < start + size);
62595 +}
62596 +
62597 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62598 +{
62599 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62600 +}
62601 +
62602 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62603 +{
62604 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62605 +}
62606 +
62607 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62608 +{
62609 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62610 +}
62611 +
62612 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62613 +{
62614 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62615 +}
62616 +
62617 static inline int within_module_core(unsigned long addr, struct module *mod)
62618 {
62619 - return (unsigned long)mod->module_core <= addr &&
62620 - addr < (unsigned long)mod->module_core + mod->core_size;
62621 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62622 }
62623
62624 static inline int within_module_init(unsigned long addr, struct module *mod)
62625 {
62626 - return (unsigned long)mod->module_init <= addr &&
62627 - addr < (unsigned long)mod->module_init + mod->init_size;
62628 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62629 }
62630
62631 /* Search for module by name: must hold module_mutex. */
62632 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62633 index b2be02e..72d2f78 100644
62634 --- a/include/linux/moduleloader.h
62635 +++ b/include/linux/moduleloader.h
62636 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62637
62638 /* Allocator used for allocating struct module, core sections and init
62639 sections. Returns NULL on failure. */
62640 -void *module_alloc(unsigned long size);
62641 +void *module_alloc(unsigned long size) __size_overflow(1);
62642 +
62643 +#ifdef CONFIG_PAX_KERNEXEC
62644 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62645 +#else
62646 +#define module_alloc_exec(x) module_alloc(x)
62647 +#endif
62648
62649 /* Free memory returned from module_alloc. */
62650 void module_free(struct module *mod, void *module_region);
62651
62652 +#ifdef CONFIG_PAX_KERNEXEC
62653 +void module_free_exec(struct module *mod, void *module_region);
62654 +#else
62655 +#define module_free_exec(x, y) module_free((x), (y))
62656 +#endif
62657 +
62658 /* Apply the given relocation to the (simplified) ELF. Return -error
62659 or 0. */
62660 int apply_relocate(Elf_Shdr *sechdrs,
62661 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62662 index c47f4d6..23f9bdb 100644
62663 --- a/include/linux/moduleparam.h
62664 +++ b/include/linux/moduleparam.h
62665 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62666 * @len is usually just sizeof(string).
62667 */
62668 #define module_param_string(name, string, len, perm) \
62669 - static const struct kparam_string __param_string_##name \
62670 + static const struct kparam_string __param_string_##name __used \
62671 = { len, string }; \
62672 __module_param_call(MODULE_PARAM_PREFIX, name, \
62673 &param_ops_string, \
62674 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62675 */
62676 #define module_param_array_named(name, array, type, nump, perm) \
62677 param_check_##type(name, &(array)[0]); \
62678 - static const struct kparam_array __param_arr_##name \
62679 + static const struct kparam_array __param_arr_##name __used \
62680 = { .max = ARRAY_SIZE(array), .num = nump, \
62681 .ops = &param_ops_##type, \
62682 .elemsize = sizeof(array[0]), .elem = array }; \
62683 diff --git a/include/linux/namei.h b/include/linux/namei.h
62684 index ffc0213..2c1f2cb 100644
62685 --- a/include/linux/namei.h
62686 +++ b/include/linux/namei.h
62687 @@ -24,7 +24,7 @@ struct nameidata {
62688 unsigned seq;
62689 int last_type;
62690 unsigned depth;
62691 - char *saved_names[MAX_NESTED_LINKS + 1];
62692 + const char *saved_names[MAX_NESTED_LINKS + 1];
62693
62694 /* Intent data */
62695 union {
62696 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62697 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62698 extern void unlock_rename(struct dentry *, struct dentry *);
62699
62700 -static inline void nd_set_link(struct nameidata *nd, char *path)
62701 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62702 {
62703 nd->saved_names[nd->depth] = path;
62704 }
62705
62706 -static inline char *nd_get_link(struct nameidata *nd)
62707 +static inline const char *nd_get_link(const struct nameidata *nd)
62708 {
62709 return nd->saved_names[nd->depth];
62710 }
62711 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62712 index 0eac07c..a59f6a8 100644
62713 --- a/include/linux/netdevice.h
62714 +++ b/include/linux/netdevice.h
62715 @@ -1002,6 +1002,7 @@ struct net_device_ops {
62716 int (*ndo_neigh_construct)(struct neighbour *n);
62717 void (*ndo_neigh_destroy)(struct neighbour *n);
62718 };
62719 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62720
62721 /*
62722 * The DEVICE structure.
62723 @@ -1063,7 +1064,7 @@ struct net_device {
62724 int iflink;
62725
62726 struct net_device_stats stats;
62727 - atomic_long_t rx_dropped; /* dropped packets by core network
62728 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62729 * Do not use this in drivers.
62730 */
62731
62732 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62733 new file mode 100644
62734 index 0000000..33f4af8
62735 --- /dev/null
62736 +++ b/include/linux/netfilter/xt_gradm.h
62737 @@ -0,0 +1,9 @@
62738 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62739 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62740 +
62741 +struct xt_gradm_mtinfo {
62742 + __u16 flags;
62743 + __u16 invflags;
62744 +};
62745 +
62746 +#endif
62747 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62748 index c65a18a..0c05f3a 100644
62749 --- a/include/linux/of_pdt.h
62750 +++ b/include/linux/of_pdt.h
62751 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62752
62753 /* return 0 on success; fill in 'len' with number of bytes in path */
62754 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62755 -};
62756 +} __no_const;
62757
62758 extern void *prom_early_alloc(unsigned long size);
62759
62760 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62761 index a4c5624..2dabfb7 100644
62762 --- a/include/linux/oprofile.h
62763 +++ b/include/linux/oprofile.h
62764 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62765 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62766 char const * name, ulong * val);
62767
62768 -/** Create a file for read-only access to an atomic_t. */
62769 +/** Create a file for read-only access to an atomic_unchecked_t. */
62770 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62771 - char const * name, atomic_t * val);
62772 + char const * name, atomic_unchecked_t * val);
62773
62774 /** create a directory */
62775 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62776 @@ -163,7 +163,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
62777 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
62778 * Returns 0 on success, < 0 on error.
62779 */
62780 -int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
62781 +int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) __size_overflow(3);
62782
62783 /** lock for read/write safety */
62784 extern raw_spinlock_t oprofilefs_lock;
62785 diff --git a/include/linux/padata.h b/include/linux/padata.h
62786 index 4633b2f..988bc08 100644
62787 --- a/include/linux/padata.h
62788 +++ b/include/linux/padata.h
62789 @@ -129,7 +129,7 @@ struct parallel_data {
62790 struct padata_instance *pinst;
62791 struct padata_parallel_queue __percpu *pqueue;
62792 struct padata_serial_queue __percpu *squeue;
62793 - atomic_t seq_nr;
62794 + atomic_unchecked_t seq_nr;
62795 atomic_t reorder_objects;
62796 atomic_t refcnt;
62797 unsigned int max_seq_nr;
62798 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62799 index abb2776..d8b8e15 100644
62800 --- a/include/linux/perf_event.h
62801 +++ b/include/linux/perf_event.h
62802 @@ -750,8 +750,8 @@ struct perf_event {
62803
62804 enum perf_event_active_state state;
62805 unsigned int attach_state;
62806 - local64_t count;
62807 - atomic64_t child_count;
62808 + local64_t count; /* PaX: fix it one day */
62809 + atomic64_unchecked_t child_count;
62810
62811 /*
62812 * These are the total time in nanoseconds that the event
62813 @@ -802,8 +802,8 @@ struct perf_event {
62814 * These accumulate total time (in nanoseconds) that children
62815 * events have been enabled and running, respectively.
62816 */
62817 - atomic64_t child_total_time_enabled;
62818 - atomic64_t child_total_time_running;
62819 + atomic64_unchecked_t child_total_time_enabled;
62820 + atomic64_unchecked_t child_total_time_running;
62821
62822 /*
62823 * Protect attach/detach and child_list:
62824 diff --git a/include/linux/personality.h b/include/linux/personality.h
62825 index 8fc7dd1a..c19d89e 100644
62826 --- a/include/linux/personality.h
62827 +++ b/include/linux/personality.h
62828 @@ -44,6 +44,7 @@ enum {
62829 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62830 ADDR_NO_RANDOMIZE | \
62831 ADDR_COMPAT_LAYOUT | \
62832 + ADDR_LIMIT_3GB | \
62833 MMAP_PAGE_ZERO)
62834
62835 /*
62836 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62837 index 77257c9..51d473a 100644
62838 --- a/include/linux/pipe_fs_i.h
62839 +++ b/include/linux/pipe_fs_i.h
62840 @@ -46,9 +46,9 @@ struct pipe_buffer {
62841 struct pipe_inode_info {
62842 wait_queue_head_t wait;
62843 unsigned int nrbufs, curbuf, buffers;
62844 - unsigned int readers;
62845 - unsigned int writers;
62846 - unsigned int waiting_writers;
62847 + atomic_t readers;
62848 + atomic_t writers;
62849 + atomic_t waiting_writers;
62850 unsigned int r_counter;
62851 unsigned int w_counter;
62852 struct page *tmp_page;
62853 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62854 index 609daae..5392427 100644
62855 --- a/include/linux/pm_runtime.h
62856 +++ b/include/linux/pm_runtime.h
62857 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62858
62859 static inline void pm_runtime_mark_last_busy(struct device *dev)
62860 {
62861 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62862 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62863 }
62864
62865 #else /* !CONFIG_PM_RUNTIME */
62866 diff --git a/include/linux/poison.h b/include/linux/poison.h
62867 index 2110a81..13a11bb 100644
62868 --- a/include/linux/poison.h
62869 +++ b/include/linux/poison.h
62870 @@ -19,8 +19,8 @@
62871 * under normal circumstances, used to verify that nobody uses
62872 * non-initialized list entries.
62873 */
62874 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62875 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62876 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62877 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62878
62879 /********** include/linux/timer.h **********/
62880 /*
62881 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62882 index 58969b2..ead129b 100644
62883 --- a/include/linux/preempt.h
62884 +++ b/include/linux/preempt.h
62885 @@ -123,7 +123,7 @@ struct preempt_ops {
62886 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62887 void (*sched_out)(struct preempt_notifier *notifier,
62888 struct task_struct *next);
62889 -};
62890 +} __no_const;
62891
62892 /**
62893 * preempt_notifier - key for installing preemption notifiers
62894 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62895 index 85c5073..51fac8b 100644
62896 --- a/include/linux/proc_fs.h
62897 +++ b/include/linux/proc_fs.h
62898 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62899 return proc_create_data(name, mode, parent, proc_fops, NULL);
62900 }
62901
62902 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62903 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62904 +{
62905 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62906 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62907 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62908 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62909 +#else
62910 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62911 +#endif
62912 +}
62913 +
62914 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62915 umode_t mode, struct proc_dir_entry *base,
62916 read_proc_t *read_proc, void * data)
62917 @@ -258,7 +270,7 @@ union proc_op {
62918 int (*proc_show)(struct seq_file *m,
62919 struct pid_namespace *ns, struct pid *pid,
62920 struct task_struct *task);
62921 -};
62922 +} __no_const;
62923
62924 struct ctl_table_header;
62925 struct ctl_table;
62926 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62927 index c2f1f6a..6fdb196 100644
62928 --- a/include/linux/ptrace.h
62929 +++ b/include/linux/ptrace.h
62930 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
62931 if (unlikely(ptrace_event_enabled(current, event))) {
62932 current->ptrace_message = message;
62933 ptrace_notify((event << 8) | SIGTRAP);
62934 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
62935 + } else if (event == PTRACE_EVENT_EXEC) {
62936 /* legacy EXEC report via SIGTRAP */
62937 - send_sig(SIGTRAP, current, 0);
62938 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
62939 + send_sig(SIGTRAP, current, 0);
62940 }
62941 }
62942
62943 diff --git a/include/linux/random.h b/include/linux/random.h
62944 index 8f74538..02a1012 100644
62945 --- a/include/linux/random.h
62946 +++ b/include/linux/random.h
62947 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62948
62949 u32 prandom32(struct rnd_state *);
62950
62951 +static inline unsigned long pax_get_random_long(void)
62952 +{
62953 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62954 +}
62955 +
62956 /*
62957 * Handle minimum values for seeds
62958 */
62959 static inline u32 __seed(u32 x, u32 m)
62960 {
62961 - return (x < m) ? x + m : x;
62962 + return (x <= m) ? x + m + 1 : x;
62963 }
62964
62965 /**
62966 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62967 index e0879a7..a12f962 100644
62968 --- a/include/linux/reboot.h
62969 +++ b/include/linux/reboot.h
62970 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62971 * Architecture-specific implementations of sys_reboot commands.
62972 */
62973
62974 -extern void machine_restart(char *cmd);
62975 -extern void machine_halt(void);
62976 -extern void machine_power_off(void);
62977 +extern void machine_restart(char *cmd) __noreturn;
62978 +extern void machine_halt(void) __noreturn;
62979 +extern void machine_power_off(void) __noreturn;
62980
62981 extern void machine_shutdown(void);
62982 struct pt_regs;
62983 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62984 */
62985
62986 extern void kernel_restart_prepare(char *cmd);
62987 -extern void kernel_restart(char *cmd);
62988 -extern void kernel_halt(void);
62989 -extern void kernel_power_off(void);
62990 +extern void kernel_restart(char *cmd) __noreturn;
62991 +extern void kernel_halt(void) __noreturn;
62992 +extern void kernel_power_off(void) __noreturn;
62993
62994 extern int C_A_D; /* for sysctl */
62995 void ctrl_alt_del(void);
62996 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62997 * Emergency restart, callable from an interrupt handler.
62998 */
62999
63000 -extern void emergency_restart(void);
63001 +extern void emergency_restart(void) __noreturn;
63002 #include <asm/emergency-restart.h>
63003
63004 #endif
63005 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
63006 index 2213ddc..650212a 100644
63007 --- a/include/linux/reiserfs_fs.h
63008 +++ b/include/linux/reiserfs_fs.h
63009 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63010 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63011
63012 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63013 -#define get_generation(s) atomic_read (&fs_generation(s))
63014 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63015 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63016 #define __fs_changed(gen,s) (gen != get_generation (s))
63017 #define fs_changed(gen,s) \
63018 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63019 index 8c9e85c..1698e9a 100644
63020 --- a/include/linux/reiserfs_fs_sb.h
63021 +++ b/include/linux/reiserfs_fs_sb.h
63022 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63023 /* Comment? -Hans */
63024 wait_queue_head_t s_wait;
63025 /* To be obsoleted soon by per buffer seals.. -Hans */
63026 - atomic_t s_generation_counter; // increased by one every time the
63027 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63028 // tree gets re-balanced
63029 unsigned long s_properties; /* File system properties. Currently holds
63030 on-disk FS format */
63031 diff --git a/include/linux/relay.h b/include/linux/relay.h
63032 index a822fd7..62b70f6 100644
63033 --- a/include/linux/relay.h
63034 +++ b/include/linux/relay.h
63035 @@ -159,7 +159,7 @@ struct rchan_callbacks
63036 * The callback should return 0 if successful, negative if not.
63037 */
63038 int (*remove_buf_file)(struct dentry *dentry);
63039 -};
63040 +} __no_const;
63041
63042 /*
63043 * CONFIG_RELAY kernel API, kernel/relay.c
63044 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63045 index c6c6084..5bf1212 100644
63046 --- a/include/linux/rfkill.h
63047 +++ b/include/linux/rfkill.h
63048 @@ -147,6 +147,7 @@ struct rfkill_ops {
63049 void (*query)(struct rfkill *rfkill, void *data);
63050 int (*set_block)(void *data, bool blocked);
63051 };
63052 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63053
63054 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63055 /**
63056 diff --git a/include/linux/rio.h b/include/linux/rio.h
63057 index 4d50611..c6858a2 100644
63058 --- a/include/linux/rio.h
63059 +++ b/include/linux/rio.h
63060 @@ -315,7 +315,7 @@ struct rio_ops {
63061 int mbox, void *buffer, size_t len);
63062 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63063 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63064 -};
63065 +} __no_const;
63066
63067 #define RIO_RESOURCE_MEM 0x00000100
63068 #define RIO_RESOURCE_DOORBELL 0x00000200
63069 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63070 index 1cdd62a..e399f0d 100644
63071 --- a/include/linux/rmap.h
63072 +++ b/include/linux/rmap.h
63073 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63074 void anon_vma_init(void); /* create anon_vma_cachep */
63075 int anon_vma_prepare(struct vm_area_struct *);
63076 void unlink_anon_vmas(struct vm_area_struct *);
63077 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63078 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63079 void anon_vma_moveto_tail(struct vm_area_struct *);
63080 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63081 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63082 void __anon_vma_link(struct vm_area_struct *);
63083
63084 static inline void anon_vma_merge(struct vm_area_struct *vma,
63085 diff --git a/include/linux/sched.h b/include/linux/sched.h
63086 index 0657368..765f70f 100644
63087 --- a/include/linux/sched.h
63088 +++ b/include/linux/sched.h
63089 @@ -101,6 +101,7 @@ struct bio_list;
63090 struct fs_struct;
63091 struct perf_event_context;
63092 struct blk_plug;
63093 +struct linux_binprm;
63094
63095 /*
63096 * List of flags we want to share for kernel threads,
63097 @@ -382,10 +383,13 @@ struct user_namespace;
63098 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63099
63100 extern int sysctl_max_map_count;
63101 +extern unsigned long sysctl_heap_stack_gap;
63102
63103 #include <linux/aio.h>
63104
63105 #ifdef CONFIG_MMU
63106 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63107 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63108 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63109 extern unsigned long
63110 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63111 @@ -631,6 +635,17 @@ struct signal_struct {
63112 #ifdef CONFIG_TASKSTATS
63113 struct taskstats *stats;
63114 #endif
63115 +
63116 +#ifdef CONFIG_GRKERNSEC
63117 + u32 curr_ip;
63118 + u32 saved_ip;
63119 + u32 gr_saddr;
63120 + u32 gr_daddr;
63121 + u16 gr_sport;
63122 + u16 gr_dport;
63123 + u8 used_accept:1;
63124 +#endif
63125 +
63126 #ifdef CONFIG_AUDIT
63127 unsigned audit_tty;
63128 struct tty_audit_buf *tty_audit_buf;
63129 @@ -714,6 +729,11 @@ struct user_struct {
63130 struct key *session_keyring; /* UID's default session keyring */
63131 #endif
63132
63133 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63134 + unsigned int banned;
63135 + unsigned long ban_expires;
63136 +#endif
63137 +
63138 /* Hash table maintenance information */
63139 struct hlist_node uidhash_node;
63140 uid_t uid;
63141 @@ -1354,8 +1374,8 @@ struct task_struct {
63142 struct list_head thread_group;
63143
63144 struct completion *vfork_done; /* for vfork() */
63145 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63146 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63147 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63148 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63149
63150 cputime_t utime, stime, utimescaled, stimescaled;
63151 cputime_t gtime;
63152 @@ -1371,13 +1391,6 @@ struct task_struct {
63153 struct task_cputime cputime_expires;
63154 struct list_head cpu_timers[3];
63155
63156 -/* process credentials */
63157 - const struct cred __rcu *real_cred; /* objective and real subjective task
63158 - * credentials (COW) */
63159 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63160 - * credentials (COW) */
63161 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63162 -
63163 char comm[TASK_COMM_LEN]; /* executable name excluding path
63164 - access with [gs]et_task_comm (which lock
63165 it with task_lock())
63166 @@ -1394,8 +1407,16 @@ struct task_struct {
63167 #endif
63168 /* CPU-specific state of this task */
63169 struct thread_struct thread;
63170 +/* thread_info moved to task_struct */
63171 +#ifdef CONFIG_X86
63172 + struct thread_info tinfo;
63173 +#endif
63174 /* filesystem information */
63175 struct fs_struct *fs;
63176 +
63177 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63178 + * credentials (COW) */
63179 +
63180 /* open file information */
63181 struct files_struct *files;
63182 /* namespaces */
63183 @@ -1442,6 +1463,11 @@ struct task_struct {
63184 struct rt_mutex_waiter *pi_blocked_on;
63185 #endif
63186
63187 +/* process credentials */
63188 + const struct cred __rcu *real_cred; /* objective and real subjective task
63189 + * credentials (COW) */
63190 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63191 +
63192 #ifdef CONFIG_DEBUG_MUTEXES
63193 /* mutex deadlock detection */
63194 struct mutex_waiter *blocked_on;
63195 @@ -1558,6 +1584,27 @@ struct task_struct {
63196 unsigned long default_timer_slack_ns;
63197
63198 struct list_head *scm_work_list;
63199 +
63200 +#ifdef CONFIG_GRKERNSEC
63201 + /* grsecurity */
63202 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63203 + u64 exec_id;
63204 +#endif
63205 +#ifdef CONFIG_GRKERNSEC_SETXID
63206 + const struct cred *delayed_cred;
63207 +#endif
63208 + struct dentry *gr_chroot_dentry;
63209 + struct acl_subject_label *acl;
63210 + struct acl_role_label *role;
63211 + struct file *exec_file;
63212 + u16 acl_role_id;
63213 + /* is this the task that authenticated to the special role */
63214 + u8 acl_sp_role;
63215 + u8 is_writable;
63216 + u8 brute;
63217 + u8 gr_is_chrooted;
63218 +#endif
63219 +
63220 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63221 /* Index of current stored address in ret_stack */
63222 int curr_ret_stack;
63223 @@ -1592,6 +1639,51 @@ struct task_struct {
63224 #endif
63225 };
63226
63227 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63228 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63229 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63230 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63231 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63232 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63233 +
63234 +#ifdef CONFIG_PAX_SOFTMODE
63235 +extern int pax_softmode;
63236 +#endif
63237 +
63238 +extern int pax_check_flags(unsigned long *);
63239 +
63240 +/* if tsk != current then task_lock must be held on it */
63241 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63242 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63243 +{
63244 + if (likely(tsk->mm))
63245 + return tsk->mm->pax_flags;
63246 + else
63247 + return 0UL;
63248 +}
63249 +
63250 +/* if tsk != current then task_lock must be held on it */
63251 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63252 +{
63253 + if (likely(tsk->mm)) {
63254 + tsk->mm->pax_flags = flags;
63255 + return 0;
63256 + }
63257 + return -EINVAL;
63258 +}
63259 +#endif
63260 +
63261 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63262 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63263 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63264 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63265 +#endif
63266 +
63267 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63268 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63269 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63270 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63271 +
63272 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63273 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63274
63275 @@ -2104,7 +2196,9 @@ void yield(void);
63276 extern struct exec_domain default_exec_domain;
63277
63278 union thread_union {
63279 +#ifndef CONFIG_X86
63280 struct thread_info thread_info;
63281 +#endif
63282 unsigned long stack[THREAD_SIZE/sizeof(long)];
63283 };
63284
63285 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63286 */
63287
63288 extern struct task_struct *find_task_by_vpid(pid_t nr);
63289 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63290 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63291 struct pid_namespace *ns);
63292
63293 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63294 extern void exit_itimers(struct signal_struct *);
63295 extern void flush_itimer_signals(void);
63296
63297 -extern void do_group_exit(int);
63298 +extern __noreturn void do_group_exit(int);
63299
63300 extern void daemonize(const char *, ...);
63301 extern int allow_signal(int);
63302 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63303
63304 #endif
63305
63306 -static inline int object_is_on_stack(void *obj)
63307 +static inline int object_starts_on_stack(void *obj)
63308 {
63309 - void *stack = task_stack_page(current);
63310 + const void *stack = task_stack_page(current);
63311
63312 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63313 }
63314
63315 +#ifdef CONFIG_PAX_USERCOPY
63316 +extern int object_is_on_stack(const void *obj, unsigned long len);
63317 +#endif
63318 +
63319 extern void thread_info_cache_init(void);
63320
63321 #ifdef CONFIG_DEBUG_STACK_USAGE
63322 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63323 index 899fbb4..1cb4138 100644
63324 --- a/include/linux/screen_info.h
63325 +++ b/include/linux/screen_info.h
63326 @@ -43,7 +43,8 @@ struct screen_info {
63327 __u16 pages; /* 0x32 */
63328 __u16 vesa_attributes; /* 0x34 */
63329 __u32 capabilities; /* 0x36 */
63330 - __u8 _reserved[6]; /* 0x3a */
63331 + __u16 vesapm_size; /* 0x3a */
63332 + __u8 _reserved[4]; /* 0x3c */
63333 } __attribute__((packed));
63334
63335 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63336 diff --git a/include/linux/security.h b/include/linux/security.h
63337 index 83c18e8..2d98860 100644
63338 --- a/include/linux/security.h
63339 +++ b/include/linux/security.h
63340 @@ -37,6 +37,7 @@
63341 #include <linux/xfrm.h>
63342 #include <linux/slab.h>
63343 #include <linux/xattr.h>
63344 +#include <linux/grsecurity.h>
63345 #include <net/flow.h>
63346
63347 /* Maximum number of letters for an LSM name string */
63348 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63349 index 44f1514..2bbf6c1 100644
63350 --- a/include/linux/seq_file.h
63351 +++ b/include/linux/seq_file.h
63352 @@ -24,6 +24,9 @@ struct seq_file {
63353 struct mutex lock;
63354 const struct seq_operations *op;
63355 int poll_event;
63356 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63357 + u64 exec_id;
63358 +#endif
63359 void *private;
63360 };
63361
63362 @@ -33,6 +36,7 @@ struct seq_operations {
63363 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63364 int (*show) (struct seq_file *m, void *v);
63365 };
63366 +typedef struct seq_operations __no_const seq_operations_no_const;
63367
63368 #define SEQ_SKIP 1
63369
63370 diff --git a/include/linux/shm.h b/include/linux/shm.h
63371 index 92808b8..c28cac4 100644
63372 --- a/include/linux/shm.h
63373 +++ b/include/linux/shm.h
63374 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63375
63376 /* The task created the shm object. NULL if the task is dead. */
63377 struct task_struct *shm_creator;
63378 +#ifdef CONFIG_GRKERNSEC
63379 + time_t shm_createtime;
63380 + pid_t shm_lapid;
63381 +#endif
63382 };
63383
63384 /* shm_mode upper byte flags */
63385 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63386 index ae86ade..2b51468 100644
63387 --- a/include/linux/skbuff.h
63388 +++ b/include/linux/skbuff.h
63389 @@ -654,7 +654,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63390 */
63391 static inline int skb_queue_empty(const struct sk_buff_head *list)
63392 {
63393 - return list->next == (struct sk_buff *)list;
63394 + return list->next == (const struct sk_buff *)list;
63395 }
63396
63397 /**
63398 @@ -667,7 +667,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63399 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63400 const struct sk_buff *skb)
63401 {
63402 - return skb->next == (struct sk_buff *)list;
63403 + return skb->next == (const struct sk_buff *)list;
63404 }
63405
63406 /**
63407 @@ -680,7 +680,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63408 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63409 const struct sk_buff *skb)
63410 {
63411 - return skb->prev == (struct sk_buff *)list;
63412 + return skb->prev == (const struct sk_buff *)list;
63413 }
63414
63415 /**
63416 @@ -1545,7 +1545,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63417 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63418 */
63419 #ifndef NET_SKB_PAD
63420 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63421 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63422 #endif
63423
63424 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63425 diff --git a/include/linux/slab.h b/include/linux/slab.h
63426 index 573c809..07e1f43 100644
63427 --- a/include/linux/slab.h
63428 +++ b/include/linux/slab.h
63429 @@ -11,12 +11,20 @@
63430
63431 #include <linux/gfp.h>
63432 #include <linux/types.h>
63433 +#include <linux/err.h>
63434
63435 /*
63436 * Flags to pass to kmem_cache_create().
63437 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63438 */
63439 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63440 +
63441 +#ifdef CONFIG_PAX_USERCOPY
63442 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63443 +#else
63444 +#define SLAB_USERCOPY 0x00000000UL
63445 +#endif
63446 +
63447 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63448 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63449 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63450 @@ -87,10 +95,13 @@
63451 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63452 * Both make kfree a no-op.
63453 */
63454 -#define ZERO_SIZE_PTR ((void *)16)
63455 +#define ZERO_SIZE_PTR \
63456 +({ \
63457 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63458 + (void *)(-MAX_ERRNO-1L); \
63459 +})
63460
63461 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63462 - (unsigned long)ZERO_SIZE_PTR)
63463 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63464
63465 /*
63466 * struct kmem_cache related prototypes
63467 @@ -156,11 +167,12 @@ unsigned int kmem_cache_size(struct kmem_cache *);
63468 /*
63469 * Common kmalloc functions provided by all allocators
63470 */
63471 -void * __must_check __krealloc(const void *, size_t, gfp_t);
63472 -void * __must_check krealloc(const void *, size_t, gfp_t);
63473 +void * __must_check __krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63474 +void * __must_check krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63475 void kfree(const void *);
63476 void kzfree(const void *);
63477 size_t ksize(const void *);
63478 +void check_object_size(const void *ptr, unsigned long n, bool to);
63479
63480 /*
63481 * Allocator specific definitions. These are mainly used to establish optimized
63482 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63483 */
63484 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63485 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63486 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63487 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63488 #define kmalloc_track_caller(size, flags) \
63489 __kmalloc_track_caller(size, flags, _RET_IP_)
63490 #else
63491 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63492 */
63493 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63494 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63495 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63496 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63497 #define kmalloc_node_track_caller(size, flags, node) \
63498 __kmalloc_node_track_caller(size, flags, node, \
63499 _RET_IP_)
63500 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63501 index fbd1117..c0bd874 100644
63502 --- a/include/linux/slab_def.h
63503 +++ b/include/linux/slab_def.h
63504 @@ -66,10 +66,10 @@ struct kmem_cache {
63505 unsigned long node_allocs;
63506 unsigned long node_frees;
63507 unsigned long node_overflow;
63508 - atomic_t allochit;
63509 - atomic_t allocmiss;
63510 - atomic_t freehit;
63511 - atomic_t freemiss;
63512 + atomic_unchecked_t allochit;
63513 + atomic_unchecked_t allocmiss;
63514 + atomic_unchecked_t freehit;
63515 + atomic_unchecked_t freemiss;
63516
63517 /*
63518 * If debugging is enabled, then the allocator can add additional
63519 @@ -107,7 +107,7 @@ struct cache_sizes {
63520 extern struct cache_sizes malloc_sizes[];
63521
63522 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63523 -void *__kmalloc(size_t size, gfp_t flags);
63524 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63525
63526 #ifdef CONFIG_TRACING
63527 extern void *kmem_cache_alloc_trace(size_t size,
63528 @@ -125,6 +125,7 @@ static inline size_t slab_buffer_size(struct kmem_cache *cachep)
63529 }
63530 #endif
63531
63532 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63533 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63534 {
63535 struct kmem_cache *cachep;
63536 @@ -160,7 +161,7 @@ found:
63537 }
63538
63539 #ifdef CONFIG_NUMA
63540 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63541 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63542 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63543
63544 #ifdef CONFIG_TRACING
63545 @@ -179,6 +180,7 @@ kmem_cache_alloc_node_trace(size_t size,
63546 }
63547 #endif
63548
63549 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63550 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63551 {
63552 struct kmem_cache *cachep;
63553 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63554 index 0ec00b3..65e7e0e 100644
63555 --- a/include/linux/slob_def.h
63556 +++ b/include/linux/slob_def.h
63557 @@ -9,8 +9,9 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63558 return kmem_cache_alloc_node(cachep, flags, -1);
63559 }
63560
63561 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63562 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63563
63564 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63565 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63566 {
63567 return __kmalloc_node(size, flags, node);
63568 @@ -24,11 +25,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63569 * kmalloc is the normal method of allocating memory
63570 * in the kernel.
63571 */
63572 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63573 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63574 {
63575 return __kmalloc_node(size, flags, -1);
63576 }
63577
63578 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63579 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63580 {
63581 return kmalloc(size, flags);
63582 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63583 index a32bcfd..d26bd6e 100644
63584 --- a/include/linux/slub_def.h
63585 +++ b/include/linux/slub_def.h
63586 @@ -89,7 +89,7 @@ struct kmem_cache {
63587 struct kmem_cache_order_objects max;
63588 struct kmem_cache_order_objects min;
63589 gfp_t allocflags; /* gfp flags to use on each alloc */
63590 - int refcount; /* Refcount for slab cache destroy */
63591 + atomic_t refcount; /* Refcount for slab cache destroy */
63592 void (*ctor)(void *);
63593 int inuse; /* Offset to metadata */
63594 int align; /* Alignment */
63595 @@ -204,6 +204,7 @@ static __always_inline int kmalloc_index(size_t size)
63596 * This ought to end up with a global pointer to the right cache
63597 * in kmalloc_caches.
63598 */
63599 +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) __size_overflow(1);
63600 static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63601 {
63602 int index = kmalloc_index(size);
63603 @@ -215,9 +216,11 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63604 }
63605
63606 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63607 -void *__kmalloc(size_t size, gfp_t flags);
63608 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63609
63610 static __always_inline void *
63611 +kmalloc_order(size_t size, gfp_t flags, unsigned int order) __size_overflow(1);
63612 +static __always_inline void *
63613 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63614 {
63615 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
63616 @@ -256,12 +259,14 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63617 }
63618 #endif
63619
63620 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63621 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63622 {
63623 unsigned int order = get_order(size);
63624 return kmalloc_order_trace(size, flags, order);
63625 }
63626
63627 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63628 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63629 {
63630 if (__builtin_constant_p(size)) {
63631 @@ -281,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63632 }
63633
63634 #ifdef CONFIG_NUMA
63635 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63636 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63637 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63638
63639 #ifdef CONFIG_TRACING
63640 @@ -298,6 +303,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
63641 }
63642 #endif
63643
63644 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63645 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63646 {
63647 if (__builtin_constant_p(size) &&
63648 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63649 index de8832d..0147b46 100644
63650 --- a/include/linux/sonet.h
63651 +++ b/include/linux/sonet.h
63652 @@ -61,7 +61,7 @@ struct sonet_stats {
63653 #include <linux/atomic.h>
63654
63655 struct k_sonet_stats {
63656 -#define __HANDLE_ITEM(i) atomic_t i
63657 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63658 __SONET_ITEMS
63659 #undef __HANDLE_ITEM
63660 };
63661 diff --git a/include/linux/stddef.h b/include/linux/stddef.h
63662 index 6a40c76..1747b67 100644
63663 --- a/include/linux/stddef.h
63664 +++ b/include/linux/stddef.h
63665 @@ -3,14 +3,10 @@
63666
63667 #include <linux/compiler.h>
63668
63669 +#ifdef __KERNEL__
63670 +
63671 #undef NULL
63672 -#if defined(__cplusplus)
63673 -#define NULL 0
63674 -#else
63675 #define NULL ((void *)0)
63676 -#endif
63677 -
63678 -#ifdef __KERNEL__
63679
63680 enum {
63681 false = 0,
63682 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63683 index 2c5993a..b0e79f0 100644
63684 --- a/include/linux/sunrpc/clnt.h
63685 +++ b/include/linux/sunrpc/clnt.h
63686 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63687 {
63688 switch (sap->sa_family) {
63689 case AF_INET:
63690 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63691 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63692 case AF_INET6:
63693 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63694 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63695 }
63696 return 0;
63697 }
63698 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63699 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63700 const struct sockaddr *src)
63701 {
63702 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63703 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63704 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63705
63706 dsin->sin_family = ssin->sin_family;
63707 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63708 if (sa->sa_family != AF_INET6)
63709 return 0;
63710
63711 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63712 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63713 }
63714
63715 #endif /* __KERNEL__ */
63716 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63717 index e775689..9e206d9 100644
63718 --- a/include/linux/sunrpc/sched.h
63719 +++ b/include/linux/sunrpc/sched.h
63720 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63721 void (*rpc_call_done)(struct rpc_task *, void *);
63722 void (*rpc_release)(void *);
63723 };
63724 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63725
63726 struct rpc_task_setup {
63727 struct rpc_task *task;
63728 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63729 index c14fe86..393245e 100644
63730 --- a/include/linux/sunrpc/svc_rdma.h
63731 +++ b/include/linux/sunrpc/svc_rdma.h
63732 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63733 extern unsigned int svcrdma_max_requests;
63734 extern unsigned int svcrdma_max_req_size;
63735
63736 -extern atomic_t rdma_stat_recv;
63737 -extern atomic_t rdma_stat_read;
63738 -extern atomic_t rdma_stat_write;
63739 -extern atomic_t rdma_stat_sq_starve;
63740 -extern atomic_t rdma_stat_rq_starve;
63741 -extern atomic_t rdma_stat_rq_poll;
63742 -extern atomic_t rdma_stat_rq_prod;
63743 -extern atomic_t rdma_stat_sq_poll;
63744 -extern atomic_t rdma_stat_sq_prod;
63745 +extern atomic_unchecked_t rdma_stat_recv;
63746 +extern atomic_unchecked_t rdma_stat_read;
63747 +extern atomic_unchecked_t rdma_stat_write;
63748 +extern atomic_unchecked_t rdma_stat_sq_starve;
63749 +extern atomic_unchecked_t rdma_stat_rq_starve;
63750 +extern atomic_unchecked_t rdma_stat_rq_poll;
63751 +extern atomic_unchecked_t rdma_stat_rq_prod;
63752 +extern atomic_unchecked_t rdma_stat_sq_poll;
63753 +extern atomic_unchecked_t rdma_stat_sq_prod;
63754
63755 #define RPCRDMA_VERSION 1
63756
63757 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63758 index bb9127d..34ab358 100644
63759 --- a/include/linux/sysctl.h
63760 +++ b/include/linux/sysctl.h
63761 @@ -155,7 +155,11 @@ enum
63762 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63763 };
63764
63765 -
63766 +#ifdef CONFIG_PAX_SOFTMODE
63767 +enum {
63768 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63769 +};
63770 +#endif
63771
63772 /* CTL_VM names: */
63773 enum
63774 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63775
63776 extern int proc_dostring(struct ctl_table *, int,
63777 void __user *, size_t *, loff_t *);
63778 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63779 + void __user *, size_t *, loff_t *);
63780 extern int proc_dointvec(struct ctl_table *, int,
63781 void __user *, size_t *, loff_t *);
63782 extern int proc_dointvec_minmax(struct ctl_table *, int,
63783 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63784 index a71a292..51bd91d 100644
63785 --- a/include/linux/tracehook.h
63786 +++ b/include/linux/tracehook.h
63787 @@ -54,12 +54,12 @@ struct linux_binprm;
63788 /*
63789 * ptrace report for syscall entry and exit looks identical.
63790 */
63791 -static inline void ptrace_report_syscall(struct pt_regs *regs)
63792 +static inline int ptrace_report_syscall(struct pt_regs *regs)
63793 {
63794 int ptrace = current->ptrace;
63795
63796 if (!(ptrace & PT_PTRACED))
63797 - return;
63798 + return 0;
63799
63800 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
63801
63802 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63803 send_sig(current->exit_code, current, 1);
63804 current->exit_code = 0;
63805 }
63806 +
63807 + return fatal_signal_pending(current);
63808 }
63809
63810 /**
63811 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63812 static inline __must_check int tracehook_report_syscall_entry(
63813 struct pt_regs *regs)
63814 {
63815 - ptrace_report_syscall(regs);
63816 - return 0;
63817 + return ptrace_report_syscall(regs);
63818 }
63819
63820 /**
63821 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63822 index ff7dc08..893e1bd 100644
63823 --- a/include/linux/tty_ldisc.h
63824 +++ b/include/linux/tty_ldisc.h
63825 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63826
63827 struct module *owner;
63828
63829 - int refcount;
63830 + atomic_t refcount;
63831 };
63832
63833 struct tty_ldisc {
63834 diff --git a/include/linux/types.h b/include/linux/types.h
63835 index e5fa503..df6e8a4 100644
63836 --- a/include/linux/types.h
63837 +++ b/include/linux/types.h
63838 @@ -214,10 +214,26 @@ typedef struct {
63839 int counter;
63840 } atomic_t;
63841
63842 +#ifdef CONFIG_PAX_REFCOUNT
63843 +typedef struct {
63844 + int counter;
63845 +} atomic_unchecked_t;
63846 +#else
63847 +typedef atomic_t atomic_unchecked_t;
63848 +#endif
63849 +
63850 #ifdef CONFIG_64BIT
63851 typedef struct {
63852 long counter;
63853 } atomic64_t;
63854 +
63855 +#ifdef CONFIG_PAX_REFCOUNT
63856 +typedef struct {
63857 + long counter;
63858 +} atomic64_unchecked_t;
63859 +#else
63860 +typedef atomic64_t atomic64_unchecked_t;
63861 +#endif
63862 #endif
63863
63864 struct list_head {
63865 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63866 index 5ca0951..53a2fff 100644
63867 --- a/include/linux/uaccess.h
63868 +++ b/include/linux/uaccess.h
63869 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63870 long ret; \
63871 mm_segment_t old_fs = get_fs(); \
63872 \
63873 - set_fs(KERNEL_DS); \
63874 pagefault_disable(); \
63875 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63876 - pagefault_enable(); \
63877 + set_fs(KERNEL_DS); \
63878 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63879 set_fs(old_fs); \
63880 + pagefault_enable(); \
63881 ret; \
63882 })
63883
63884 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *dst, const void *src, size_t size);
63885 * Safely write to address @dst from the buffer at @src. If a kernel fault
63886 * happens, handle that and return -EFAULT.
63887 */
63888 -extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
63889 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size) __size_overflow(3);
63890 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
63891
63892 #endif /* __LINUX_UACCESS_H__ */
63893 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63894 index 99c1b4d..bb94261 100644
63895 --- a/include/linux/unaligned/access_ok.h
63896 +++ b/include/linux/unaligned/access_ok.h
63897 @@ -6,32 +6,32 @@
63898
63899 static inline u16 get_unaligned_le16(const void *p)
63900 {
63901 - return le16_to_cpup((__le16 *)p);
63902 + return le16_to_cpup((const __le16 *)p);
63903 }
63904
63905 static inline u32 get_unaligned_le32(const void *p)
63906 {
63907 - return le32_to_cpup((__le32 *)p);
63908 + return le32_to_cpup((const __le32 *)p);
63909 }
63910
63911 static inline u64 get_unaligned_le64(const void *p)
63912 {
63913 - return le64_to_cpup((__le64 *)p);
63914 + return le64_to_cpup((const __le64 *)p);
63915 }
63916
63917 static inline u16 get_unaligned_be16(const void *p)
63918 {
63919 - return be16_to_cpup((__be16 *)p);
63920 + return be16_to_cpup((const __be16 *)p);
63921 }
63922
63923 static inline u32 get_unaligned_be32(const void *p)
63924 {
63925 - return be32_to_cpup((__be32 *)p);
63926 + return be32_to_cpup((const __be32 *)p);
63927 }
63928
63929 static inline u64 get_unaligned_be64(const void *p)
63930 {
63931 - return be64_to_cpup((__be64 *)p);
63932 + return be64_to_cpup((const __be64 *)p);
63933 }
63934
63935 static inline void put_unaligned_le16(u16 val, void *p)
63936 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63937 index 0d3f988..000f101 100644
63938 --- a/include/linux/usb/renesas_usbhs.h
63939 +++ b/include/linux/usb/renesas_usbhs.h
63940 @@ -39,7 +39,7 @@ enum {
63941 */
63942 struct renesas_usbhs_driver_callback {
63943 int (*notify_hotplug)(struct platform_device *pdev);
63944 -};
63945 +} __no_const;
63946
63947 /*
63948 * callback functions for platform
63949 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63950 * VBUS control is needed for Host
63951 */
63952 int (*set_vbus)(struct platform_device *pdev, int enable);
63953 -};
63954 +} __no_const;
63955
63956 /*
63957 * parameters for renesas usbhs
63958 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63959 index 6f8fbcf..8259001 100644
63960 --- a/include/linux/vermagic.h
63961 +++ b/include/linux/vermagic.h
63962 @@ -25,9 +25,35 @@
63963 #define MODULE_ARCH_VERMAGIC ""
63964 #endif
63965
63966 +#ifdef CONFIG_PAX_REFCOUNT
63967 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63968 +#else
63969 +#define MODULE_PAX_REFCOUNT ""
63970 +#endif
63971 +
63972 +#ifdef CONSTIFY_PLUGIN
63973 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63974 +#else
63975 +#define MODULE_CONSTIFY_PLUGIN ""
63976 +#endif
63977 +
63978 +#ifdef STACKLEAK_PLUGIN
63979 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63980 +#else
63981 +#define MODULE_STACKLEAK_PLUGIN ""
63982 +#endif
63983 +
63984 +#ifdef CONFIG_GRKERNSEC
63985 +#define MODULE_GRSEC "GRSEC "
63986 +#else
63987 +#define MODULE_GRSEC ""
63988 +#endif
63989 +
63990 #define VERMAGIC_STRING \
63991 UTS_RELEASE " " \
63992 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63993 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63994 - MODULE_ARCH_VERMAGIC
63995 + MODULE_ARCH_VERMAGIC \
63996 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63997 + MODULE_GRSEC
63998
63999 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64000 index dcdfc2b..cce598d 100644
64001 --- a/include/linux/vmalloc.h
64002 +++ b/include/linux/vmalloc.h
64003 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64004 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64005 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64006 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64007 +
64008 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64009 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64010 +#endif
64011 +
64012 /* bits [20..32] reserved for arch specific ioremap internals */
64013
64014 /*
64015 @@ -51,18 +56,18 @@ static inline void vmalloc_init(void)
64016 }
64017 #endif
64018
64019 -extern void *vmalloc(unsigned long size);
64020 -extern void *vzalloc(unsigned long size);
64021 -extern void *vmalloc_user(unsigned long size);
64022 -extern void *vmalloc_node(unsigned long size, int node);
64023 -extern void *vzalloc_node(unsigned long size, int node);
64024 -extern void *vmalloc_exec(unsigned long size);
64025 -extern void *vmalloc_32(unsigned long size);
64026 -extern void *vmalloc_32_user(unsigned long size);
64027 -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64028 +extern void *vmalloc(unsigned long size) __size_overflow(1);
64029 +extern void *vzalloc(unsigned long size) __size_overflow(1);
64030 +extern void *vmalloc_user(unsigned long size) __size_overflow(1);
64031 +extern void *vmalloc_node(unsigned long size, int node) __size_overflow(1);
64032 +extern void *vzalloc_node(unsigned long size, int node) __size_overflow(1);
64033 +extern void *vmalloc_exec(unsigned long size) __size_overflow(1);
64034 +extern void *vmalloc_32(unsigned long size) __size_overflow(1);
64035 +extern void *vmalloc_32_user(unsigned long size) __size_overflow(1);
64036 +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __size_overflow(1);
64037 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64038 unsigned long start, unsigned long end, gfp_t gfp_mask,
64039 - pgprot_t prot, int node, void *caller);
64040 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64041 extern void vfree(const void *addr);
64042
64043 extern void *vmap(struct page **pages, unsigned int count,
64044 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64045 extern void free_vm_area(struct vm_struct *area);
64046
64047 /* for /dev/kmem */
64048 -extern long vread(char *buf, char *addr, unsigned long count);
64049 -extern long vwrite(char *buf, char *addr, unsigned long count);
64050 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64051 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64052
64053 /*
64054 * Internals. Dont't use..
64055 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64056 index 65efb92..137adbb 100644
64057 --- a/include/linux/vmstat.h
64058 +++ b/include/linux/vmstat.h
64059 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64060 /*
64061 * Zone based page accounting with per cpu differentials.
64062 */
64063 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64064 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64065
64066 static inline void zone_page_state_add(long x, struct zone *zone,
64067 enum zone_stat_item item)
64068 {
64069 - atomic_long_add(x, &zone->vm_stat[item]);
64070 - atomic_long_add(x, &vm_stat[item]);
64071 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64072 + atomic_long_add_unchecked(x, &vm_stat[item]);
64073 }
64074
64075 static inline unsigned long global_page_state(enum zone_stat_item item)
64076 {
64077 - long x = atomic_long_read(&vm_stat[item]);
64078 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64079 #ifdef CONFIG_SMP
64080 if (x < 0)
64081 x = 0;
64082 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64083 static inline unsigned long zone_page_state(struct zone *zone,
64084 enum zone_stat_item item)
64085 {
64086 - long x = atomic_long_read(&zone->vm_stat[item]);
64087 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64088 #ifdef CONFIG_SMP
64089 if (x < 0)
64090 x = 0;
64091 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64092 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64093 enum zone_stat_item item)
64094 {
64095 - long x = atomic_long_read(&zone->vm_stat[item]);
64096 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64097
64098 #ifdef CONFIG_SMP
64099 int cpu;
64100 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64101
64102 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64103 {
64104 - atomic_long_inc(&zone->vm_stat[item]);
64105 - atomic_long_inc(&vm_stat[item]);
64106 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64107 + atomic_long_inc_unchecked(&vm_stat[item]);
64108 }
64109
64110 static inline void __inc_zone_page_state(struct page *page,
64111 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64112
64113 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64114 {
64115 - atomic_long_dec(&zone->vm_stat[item]);
64116 - atomic_long_dec(&vm_stat[item]);
64117 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64118 + atomic_long_dec_unchecked(&vm_stat[item]);
64119 }
64120
64121 static inline void __dec_zone_page_state(struct page *page,
64122 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64123 index e5d1220..ef6e406 100644
64124 --- a/include/linux/xattr.h
64125 +++ b/include/linux/xattr.h
64126 @@ -57,6 +57,11 @@
64127 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64128 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64129
64130 +/* User namespace */
64131 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64132 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64133 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64134 +
64135 #ifdef __KERNEL__
64136
64137 #include <linux/types.h>
64138 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64139 index 4aeff96..b378cdc 100644
64140 --- a/include/media/saa7146_vv.h
64141 +++ b/include/media/saa7146_vv.h
64142 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64143 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64144
64145 /* the extension can override this */
64146 - struct v4l2_ioctl_ops ops;
64147 + v4l2_ioctl_ops_no_const ops;
64148 /* pointer to the saa7146 core ops */
64149 const struct v4l2_ioctl_ops *core_ops;
64150
64151 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64152 index c7c40f1..4f01585 100644
64153 --- a/include/media/v4l2-dev.h
64154 +++ b/include/media/v4l2-dev.h
64155 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64156
64157
64158 struct v4l2_file_operations {
64159 - struct module *owner;
64160 + struct module * const owner;
64161 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64162 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64163 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64164 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64165 int (*open) (struct file *);
64166 int (*release) (struct file *);
64167 };
64168 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64169
64170 /*
64171 * Newer version of video_device, handled by videodev2.c
64172 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64173 index 3f5d60f..44210ed 100644
64174 --- a/include/media/v4l2-ioctl.h
64175 +++ b/include/media/v4l2-ioctl.h
64176 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64177 long (*vidioc_default) (struct file *file, void *fh,
64178 bool valid_prio, int cmd, void *arg);
64179 };
64180 -
64181 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64182
64183 /* v4l debugging and diagnostics */
64184
64185 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64186 index 8d55251..dfe5b0a 100644
64187 --- a/include/net/caif/caif_hsi.h
64188 +++ b/include/net/caif/caif_hsi.h
64189 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64190 void (*rx_done_cb) (struct cfhsi_drv *drv);
64191 void (*wake_up_cb) (struct cfhsi_drv *drv);
64192 void (*wake_down_cb) (struct cfhsi_drv *drv);
64193 -};
64194 +} __no_const;
64195
64196 /* Structure implemented by HSI device. */
64197 struct cfhsi_dev {
64198 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64199 index 9e5425b..8136ffc 100644
64200 --- a/include/net/caif/cfctrl.h
64201 +++ b/include/net/caif/cfctrl.h
64202 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64203 void (*radioset_rsp)(void);
64204 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64205 struct cflayer *client_layer);
64206 -};
64207 +} __no_const;
64208
64209 /* Link Setup Parameters for CAIF-Links. */
64210 struct cfctrl_link_param {
64211 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64212 struct cfctrl {
64213 struct cfsrvl serv;
64214 struct cfctrl_rsp res;
64215 - atomic_t req_seq_no;
64216 - atomic_t rsp_seq_no;
64217 + atomic_unchecked_t req_seq_no;
64218 + atomic_unchecked_t rsp_seq_no;
64219 struct list_head list;
64220 /* Protects from simultaneous access to first_req list */
64221 spinlock_t info_list_lock;
64222 diff --git a/include/net/flow.h b/include/net/flow.h
64223 index 6c469db..7743b8e 100644
64224 --- a/include/net/flow.h
64225 +++ b/include/net/flow.h
64226 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64227
64228 extern void flow_cache_flush(void);
64229 extern void flow_cache_flush_deferred(void);
64230 -extern atomic_t flow_cache_genid;
64231 +extern atomic_unchecked_t flow_cache_genid;
64232
64233 #endif
64234 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64235 index b94765e..053f68b 100644
64236 --- a/include/net/inetpeer.h
64237 +++ b/include/net/inetpeer.h
64238 @@ -48,8 +48,8 @@ struct inet_peer {
64239 */
64240 union {
64241 struct {
64242 - atomic_t rid; /* Frag reception counter */
64243 - atomic_t ip_id_count; /* IP ID for the next packet */
64244 + atomic_unchecked_t rid; /* Frag reception counter */
64245 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64246 __u32 tcp_ts;
64247 __u32 tcp_ts_stamp;
64248 };
64249 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64250 more++;
64251 inet_peer_refcheck(p);
64252 do {
64253 - old = atomic_read(&p->ip_id_count);
64254 + old = atomic_read_unchecked(&p->ip_id_count);
64255 new = old + more;
64256 if (!new)
64257 new = 1;
64258 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64259 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64260 return new;
64261 }
64262
64263 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64264 index 10422ef..662570f 100644
64265 --- a/include/net/ip_fib.h
64266 +++ b/include/net/ip_fib.h
64267 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64268
64269 #define FIB_RES_SADDR(net, res) \
64270 ((FIB_RES_NH(res).nh_saddr_genid == \
64271 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64272 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64273 FIB_RES_NH(res).nh_saddr : \
64274 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64275 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64276 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64277 index ebe517f..1bd286b 100644
64278 --- a/include/net/ip_vs.h
64279 +++ b/include/net/ip_vs.h
64280 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64281 struct ip_vs_conn *control; /* Master control connection */
64282 atomic_t n_control; /* Number of controlled ones */
64283 struct ip_vs_dest *dest; /* real server */
64284 - atomic_t in_pkts; /* incoming packet counter */
64285 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64286
64287 /* packet transmitter for different forwarding methods. If it
64288 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64289 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64290 __be16 port; /* port number of the server */
64291 union nf_inet_addr addr; /* IP address of the server */
64292 volatile unsigned flags; /* dest status flags */
64293 - atomic_t conn_flags; /* flags to copy to conn */
64294 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64295 atomic_t weight; /* server weight */
64296
64297 atomic_t refcnt; /* reference counter */
64298 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64299 index 69b610a..fe3962c 100644
64300 --- a/include/net/irda/ircomm_core.h
64301 +++ b/include/net/irda/ircomm_core.h
64302 @@ -51,7 +51,7 @@ typedef struct {
64303 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64304 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64305 struct ircomm_info *);
64306 -} call_t;
64307 +} __no_const call_t;
64308
64309 struct ircomm_cb {
64310 irda_queue_t queue;
64311 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64312 index 59ba38bc..d515662 100644
64313 --- a/include/net/irda/ircomm_tty.h
64314 +++ b/include/net/irda/ircomm_tty.h
64315 @@ -35,6 +35,7 @@
64316 #include <linux/termios.h>
64317 #include <linux/timer.h>
64318 #include <linux/tty.h> /* struct tty_struct */
64319 +#include <asm/local.h>
64320
64321 #include <net/irda/irias_object.h>
64322 #include <net/irda/ircomm_core.h>
64323 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64324 unsigned short close_delay;
64325 unsigned short closing_wait; /* time to wait before closing */
64326
64327 - int open_count;
64328 - int blocked_open; /* # of blocked opens */
64329 + local_t open_count;
64330 + local_t blocked_open; /* # of blocked opens */
64331
64332 /* Protect concurent access to :
64333 * o self->open_count
64334 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64335 index 0954ec9..7413562 100644
64336 --- a/include/net/iucv/af_iucv.h
64337 +++ b/include/net/iucv/af_iucv.h
64338 @@ -138,7 +138,7 @@ struct iucv_sock {
64339 struct iucv_sock_list {
64340 struct hlist_head head;
64341 rwlock_t lock;
64342 - atomic_t autobind_name;
64343 + atomic_unchecked_t autobind_name;
64344 };
64345
64346 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64347 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64348 index 34c996f..bb3b4d4 100644
64349 --- a/include/net/neighbour.h
64350 +++ b/include/net/neighbour.h
64351 @@ -123,7 +123,7 @@ struct neigh_ops {
64352 void (*error_report)(struct neighbour *, struct sk_buff *);
64353 int (*output)(struct neighbour *, struct sk_buff *);
64354 int (*connected_output)(struct neighbour *, struct sk_buff *);
64355 -};
64356 +} __do_const;
64357
64358 struct pneigh_entry {
64359 struct pneigh_entry *next;
64360 diff --git a/include/net/netlink.h b/include/net/netlink.h
64361 index cb1f350..3279d2c 100644
64362 --- a/include/net/netlink.h
64363 +++ b/include/net/netlink.h
64364 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64365 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64366 {
64367 if (mark)
64368 - skb_trim(skb, (unsigned char *) mark - skb->data);
64369 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64370 }
64371
64372 /**
64373 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64374 index bbd023a..97c6d0d 100644
64375 --- a/include/net/netns/ipv4.h
64376 +++ b/include/net/netns/ipv4.h
64377 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64378 unsigned int sysctl_ping_group_range[2];
64379 long sysctl_tcp_mem[3];
64380
64381 - atomic_t rt_genid;
64382 - atomic_t dev_addr_genid;
64383 + atomic_unchecked_t rt_genid;
64384 + atomic_unchecked_t dev_addr_genid;
64385
64386 #ifdef CONFIG_IP_MROUTE
64387 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64388 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64389 index d368561..96aaa17 100644
64390 --- a/include/net/sctp/sctp.h
64391 +++ b/include/net/sctp/sctp.h
64392 @@ -318,9 +318,9 @@ do { \
64393
64394 #else /* SCTP_DEBUG */
64395
64396 -#define SCTP_DEBUG_PRINTK(whatever...)
64397 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64398 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64399 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64400 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64401 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64402 #define SCTP_ENABLE_DEBUG
64403 #define SCTP_DISABLE_DEBUG
64404 #define SCTP_ASSERT(expr, str, func)
64405 diff --git a/include/net/sock.h b/include/net/sock.h
64406 index 91c1c8b..15ae923 100644
64407 --- a/include/net/sock.h
64408 +++ b/include/net/sock.h
64409 @@ -299,7 +299,7 @@ struct sock {
64410 #ifdef CONFIG_RPS
64411 __u32 sk_rxhash;
64412 #endif
64413 - atomic_t sk_drops;
64414 + atomic_unchecked_t sk_drops;
64415 int sk_rcvbuf;
64416
64417 struct sk_filter __rcu *sk_filter;
64418 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64419 }
64420
64421 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64422 - char __user *from, char *to,
64423 + char __user *from, unsigned char *to,
64424 int copy, int offset)
64425 {
64426 if (skb->ip_summed == CHECKSUM_NONE) {
64427 diff --git a/include/net/tcp.h b/include/net/tcp.h
64428 index 2d80c29..aa07caf 100644
64429 --- a/include/net/tcp.h
64430 +++ b/include/net/tcp.h
64431 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64432 char *name;
64433 sa_family_t family;
64434 const struct file_operations *seq_fops;
64435 - struct seq_operations seq_ops;
64436 + seq_operations_no_const seq_ops;
64437 };
64438
64439 struct tcp_iter_state {
64440 diff --git a/include/net/udp.h b/include/net/udp.h
64441 index e39592f..fef9680 100644
64442 --- a/include/net/udp.h
64443 +++ b/include/net/udp.h
64444 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64445 sa_family_t family;
64446 struct udp_table *udp_table;
64447 const struct file_operations *seq_fops;
64448 - struct seq_operations seq_ops;
64449 + seq_operations_no_const seq_ops;
64450 };
64451
64452 struct udp_iter_state {
64453 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64454 index 89174e2..1f82598 100644
64455 --- a/include/net/xfrm.h
64456 +++ b/include/net/xfrm.h
64457 @@ -505,7 +505,7 @@ struct xfrm_policy {
64458 struct timer_list timer;
64459
64460 struct flow_cache_object flo;
64461 - atomic_t genid;
64462 + atomic_unchecked_t genid;
64463 u32 priority;
64464 u32 index;
64465 struct xfrm_mark mark;
64466 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64467 index 1a046b1..ee0bef0 100644
64468 --- a/include/rdma/iw_cm.h
64469 +++ b/include/rdma/iw_cm.h
64470 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64471 int backlog);
64472
64473 int (*destroy_listen)(struct iw_cm_id *cm_id);
64474 -};
64475 +} __no_const;
64476
64477 /**
64478 * iw_create_cm_id - Create an IW CM identifier.
64479 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64480 index 6a3922f..0b73022 100644
64481 --- a/include/scsi/libfc.h
64482 +++ b/include/scsi/libfc.h
64483 @@ -748,6 +748,7 @@ struct libfc_function_template {
64484 */
64485 void (*disc_stop_final) (struct fc_lport *);
64486 };
64487 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64488
64489 /**
64490 * struct fc_disc - Discovery context
64491 @@ -851,7 +852,7 @@ struct fc_lport {
64492 struct fc_vport *vport;
64493
64494 /* Operational Information */
64495 - struct libfc_function_template tt;
64496 + libfc_function_template_no_const tt;
64497 u8 link_up;
64498 u8 qfull;
64499 enum fc_lport_state state;
64500 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64501 index 77273f2..dd4031f 100644
64502 --- a/include/scsi/scsi_device.h
64503 +++ b/include/scsi/scsi_device.h
64504 @@ -161,9 +161,9 @@ struct scsi_device {
64505 unsigned int max_device_blocked; /* what device_blocked counts down from */
64506 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64507
64508 - atomic_t iorequest_cnt;
64509 - atomic_t iodone_cnt;
64510 - atomic_t ioerr_cnt;
64511 + atomic_unchecked_t iorequest_cnt;
64512 + atomic_unchecked_t iodone_cnt;
64513 + atomic_unchecked_t ioerr_cnt;
64514
64515 struct device sdev_gendev,
64516 sdev_dev;
64517 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64518 index 2a65167..91e01f8 100644
64519 --- a/include/scsi/scsi_transport_fc.h
64520 +++ b/include/scsi/scsi_transport_fc.h
64521 @@ -711,7 +711,7 @@ struct fc_function_template {
64522 unsigned long show_host_system_hostname:1;
64523
64524 unsigned long disable_target_scan:1;
64525 -};
64526 +} __do_const;
64527
64528
64529 /**
64530 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64531 index 030b87c..98a6954 100644
64532 --- a/include/sound/ak4xxx-adda.h
64533 +++ b/include/sound/ak4xxx-adda.h
64534 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64535 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64536 unsigned char val);
64537 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64538 -};
64539 +} __no_const;
64540
64541 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64542
64543 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64544 index 8c05e47..2b5df97 100644
64545 --- a/include/sound/hwdep.h
64546 +++ b/include/sound/hwdep.h
64547 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64548 struct snd_hwdep_dsp_status *status);
64549 int (*dsp_load)(struct snd_hwdep *hw,
64550 struct snd_hwdep_dsp_image *image);
64551 -};
64552 +} __no_const;
64553
64554 struct snd_hwdep {
64555 struct snd_card *card;
64556 diff --git a/include/sound/info.h b/include/sound/info.h
64557 index 9ca1a49..aba1728 100644
64558 --- a/include/sound/info.h
64559 +++ b/include/sound/info.h
64560 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64561 struct snd_info_buffer *buffer);
64562 void (*write)(struct snd_info_entry *entry,
64563 struct snd_info_buffer *buffer);
64564 -};
64565 +} __no_const;
64566
64567 struct snd_info_entry_ops {
64568 int (*open)(struct snd_info_entry *entry,
64569 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64570 index 0cf91b2..b70cae4 100644
64571 --- a/include/sound/pcm.h
64572 +++ b/include/sound/pcm.h
64573 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64574 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64575 int (*ack)(struct snd_pcm_substream *substream);
64576 };
64577 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64578
64579 /*
64580 *
64581 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64582 index af1b49e..a5d55a5 100644
64583 --- a/include/sound/sb16_csp.h
64584 +++ b/include/sound/sb16_csp.h
64585 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64586 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64587 int (*csp_stop) (struct snd_sb_csp * p);
64588 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64589 -};
64590 +} __no_const;
64591
64592 /*
64593 * CSP private data
64594 diff --git a/include/sound/soc.h b/include/sound/soc.h
64595 index 0992dff..bb366fe 100644
64596 --- a/include/sound/soc.h
64597 +++ b/include/sound/soc.h
64598 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
64599 /* platform IO - used for platform DAPM */
64600 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64601 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64602 -};
64603 +} __do_const;
64604
64605 struct snd_soc_platform {
64606 const char *name;
64607 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
64608 struct snd_soc_dai_link *dai_link;
64609 struct mutex pcm_mutex;
64610 enum snd_soc_pcm_subclass pcm_subclass;
64611 - struct snd_pcm_ops ops;
64612 + snd_pcm_ops_no_const ops;
64613
64614 unsigned int complete:1;
64615 unsigned int dev_registered:1;
64616 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64617 index 444cd6b..3327cc5 100644
64618 --- a/include/sound/ymfpci.h
64619 +++ b/include/sound/ymfpci.h
64620 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64621 spinlock_t reg_lock;
64622 spinlock_t voice_lock;
64623 wait_queue_head_t interrupt_sleep;
64624 - atomic_t interrupt_sleep_count;
64625 + atomic_unchecked_t interrupt_sleep_count;
64626 struct snd_info_entry *proc_entry;
64627 const struct firmware *dsp_microcode;
64628 const struct firmware *controller_microcode;
64629 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64630 index fe73eb8..56388b1 100644
64631 --- a/include/target/target_core_base.h
64632 +++ b/include/target/target_core_base.h
64633 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
64634 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64635 int (*t10_pr_register)(struct se_cmd *);
64636 int (*t10_pr_clear)(struct se_cmd *);
64637 -};
64638 +} __no_const;
64639
64640 struct t10_reservation {
64641 /* Reservation effects all target ports */
64642 @@ -561,8 +561,8 @@ struct se_cmd {
64643 atomic_t t_se_count;
64644 atomic_t t_task_cdbs_left;
64645 atomic_t t_task_cdbs_ex_left;
64646 - atomic_t t_task_cdbs_sent;
64647 - atomic_t t_transport_aborted;
64648 + atomic_unchecked_t t_task_cdbs_sent;
64649 + atomic_unchecked_t t_transport_aborted;
64650 atomic_t t_transport_active;
64651 atomic_t t_transport_complete;
64652 atomic_t t_transport_queue_active;
64653 @@ -799,7 +799,7 @@ struct se_device {
64654 spinlock_t stats_lock;
64655 /* Active commands on this virtual SE device */
64656 atomic_t simple_cmds;
64657 - atomic_t dev_ordered_id;
64658 + atomic_unchecked_t dev_ordered_id;
64659 atomic_t execute_tasks;
64660 atomic_t dev_ordered_sync;
64661 atomic_t dev_qf_count;
64662 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64663 index 1c09820..7f5ec79 100644
64664 --- a/include/trace/events/irq.h
64665 +++ b/include/trace/events/irq.h
64666 @@ -36,7 +36,7 @@ struct softirq_action;
64667 */
64668 TRACE_EVENT(irq_handler_entry,
64669
64670 - TP_PROTO(int irq, struct irqaction *action),
64671 + TP_PROTO(int irq, const struct irqaction *action),
64672
64673 TP_ARGS(irq, action),
64674
64675 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64676 */
64677 TRACE_EVENT(irq_handler_exit,
64678
64679 - TP_PROTO(int irq, struct irqaction *action, int ret),
64680 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64681
64682 TP_ARGS(irq, action, ret),
64683
64684 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64685 index c41f308..6918de3 100644
64686 --- a/include/video/udlfb.h
64687 +++ b/include/video/udlfb.h
64688 @@ -52,10 +52,10 @@ struct dlfb_data {
64689 u32 pseudo_palette[256];
64690 int blank_mode; /*one of FB_BLANK_ */
64691 /* blit-only rendering path metrics, exposed through sysfs */
64692 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64693 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64694 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64695 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64696 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64697 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64698 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64699 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64700 };
64701
64702 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64703 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64704 index 0993a22..32ba2fe 100644
64705 --- a/include/video/uvesafb.h
64706 +++ b/include/video/uvesafb.h
64707 @@ -177,6 +177,7 @@ struct uvesafb_par {
64708 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64709 u8 pmi_setpal; /* PMI for palette changes */
64710 u16 *pmi_base; /* protected mode interface location */
64711 + u8 *pmi_code; /* protected mode code location */
64712 void *pmi_start;
64713 void *pmi_pal;
64714 u8 *vbe_state_orig; /*
64715 diff --git a/init/Kconfig b/init/Kconfig
64716 index 3f42cd6..613f41d 100644
64717 --- a/init/Kconfig
64718 +++ b/init/Kconfig
64719 @@ -799,6 +799,7 @@ endif # CGROUPS
64720
64721 config CHECKPOINT_RESTORE
64722 bool "Checkpoint/restore support" if EXPERT
64723 + depends on !GRKERNSEC
64724 default n
64725 help
64726 Enables additional kernel features in a sake of checkpoint/restore.
64727 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
64728
64729 config COMPAT_BRK
64730 bool "Disable heap randomization"
64731 - default y
64732 + default n
64733 help
64734 Randomizing heap placement makes heap exploits harder, but it
64735 also breaks ancient binaries (including anything libc5 based).
64736 diff --git a/init/do_mounts.c b/init/do_mounts.c
64737 index 2974c8b..0b863ae 100644
64738 --- a/init/do_mounts.c
64739 +++ b/init/do_mounts.c
64740 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64741 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64742 {
64743 struct super_block *s;
64744 - int err = sys_mount(name, "/root", fs, flags, data);
64745 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64746 if (err)
64747 return err;
64748
64749 - sys_chdir((const char __user __force *)"/root");
64750 + sys_chdir((const char __force_user *)"/root");
64751 s = current->fs->pwd.dentry->d_sb;
64752 ROOT_DEV = s->s_dev;
64753 printk(KERN_INFO
64754 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64755 va_start(args, fmt);
64756 vsprintf(buf, fmt, args);
64757 va_end(args);
64758 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64759 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64760 if (fd >= 0) {
64761 sys_ioctl(fd, FDEJECT, 0);
64762 sys_close(fd);
64763 }
64764 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64765 - fd = sys_open("/dev/console", O_RDWR, 0);
64766 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64767 if (fd >= 0) {
64768 sys_ioctl(fd, TCGETS, (long)&termios);
64769 termios.c_lflag &= ~ICANON;
64770 sys_ioctl(fd, TCSETSF, (long)&termios);
64771 - sys_read(fd, &c, 1);
64772 + sys_read(fd, (char __user *)&c, 1);
64773 termios.c_lflag |= ICANON;
64774 sys_ioctl(fd, TCSETSF, (long)&termios);
64775 sys_close(fd);
64776 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64777 mount_root();
64778 out:
64779 devtmpfs_mount("dev");
64780 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64781 - sys_chroot((const char __user __force *)".");
64782 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64783 + sys_chroot((const char __force_user *)".");
64784 }
64785 diff --git a/init/do_mounts.h b/init/do_mounts.h
64786 index f5b978a..69dbfe8 100644
64787 --- a/init/do_mounts.h
64788 +++ b/init/do_mounts.h
64789 @@ -15,15 +15,15 @@ extern int root_mountflags;
64790
64791 static inline int create_dev(char *name, dev_t dev)
64792 {
64793 - sys_unlink(name);
64794 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64795 + sys_unlink((char __force_user *)name);
64796 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64797 }
64798
64799 #if BITS_PER_LONG == 32
64800 static inline u32 bstat(char *name)
64801 {
64802 struct stat64 stat;
64803 - if (sys_stat64(name, &stat) != 0)
64804 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64805 return 0;
64806 if (!S_ISBLK(stat.st_mode))
64807 return 0;
64808 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64809 static inline u32 bstat(char *name)
64810 {
64811 struct stat stat;
64812 - if (sys_newstat(name, &stat) != 0)
64813 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64814 return 0;
64815 if (!S_ISBLK(stat.st_mode))
64816 return 0;
64817 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64818 index 3098a38..253064e 100644
64819 --- a/init/do_mounts_initrd.c
64820 +++ b/init/do_mounts_initrd.c
64821 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64822 create_dev("/dev/root.old", Root_RAM0);
64823 /* mount initrd on rootfs' /root */
64824 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64825 - sys_mkdir("/old", 0700);
64826 - root_fd = sys_open("/", 0, 0);
64827 - old_fd = sys_open("/old", 0, 0);
64828 + sys_mkdir((const char __force_user *)"/old", 0700);
64829 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64830 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64831 /* move initrd over / and chdir/chroot in initrd root */
64832 - sys_chdir("/root");
64833 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64834 - sys_chroot(".");
64835 + sys_chdir((const char __force_user *)"/root");
64836 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64837 + sys_chroot((const char __force_user *)".");
64838
64839 /*
64840 * In case that a resume from disk is carried out by linuxrc or one of
64841 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64842
64843 /* move initrd to rootfs' /old */
64844 sys_fchdir(old_fd);
64845 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64846 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64847 /* switch root and cwd back to / of rootfs */
64848 sys_fchdir(root_fd);
64849 - sys_chroot(".");
64850 + sys_chroot((const char __force_user *)".");
64851 sys_close(old_fd);
64852 sys_close(root_fd);
64853
64854 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64855 - sys_chdir("/old");
64856 + sys_chdir((const char __force_user *)"/old");
64857 return;
64858 }
64859
64860 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64861 mount_root();
64862
64863 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64864 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64865 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64866 if (!error)
64867 printk("okay\n");
64868 else {
64869 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64870 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64871 if (error == -ENOENT)
64872 printk("/initrd does not exist. Ignored.\n");
64873 else
64874 printk("failed\n");
64875 printk(KERN_NOTICE "Unmounting old root\n");
64876 - sys_umount("/old", MNT_DETACH);
64877 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64878 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64879 if (fd < 0) {
64880 error = fd;
64881 @@ -116,11 +116,11 @@ int __init initrd_load(void)
64882 * mounted in the normal path.
64883 */
64884 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64885 - sys_unlink("/initrd.image");
64886 + sys_unlink((const char __force_user *)"/initrd.image");
64887 handle_initrd();
64888 return 1;
64889 }
64890 }
64891 - sys_unlink("/initrd.image");
64892 + sys_unlink((const char __force_user *)"/initrd.image");
64893 return 0;
64894 }
64895 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64896 index 32c4799..c27ee74 100644
64897 --- a/init/do_mounts_md.c
64898 +++ b/init/do_mounts_md.c
64899 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64900 partitioned ? "_d" : "", minor,
64901 md_setup_args[ent].device_names);
64902
64903 - fd = sys_open(name, 0, 0);
64904 + fd = sys_open((char __force_user *)name, 0, 0);
64905 if (fd < 0) {
64906 printk(KERN_ERR "md: open failed - cannot start "
64907 "array %s\n", name);
64908 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64909 * array without it
64910 */
64911 sys_close(fd);
64912 - fd = sys_open(name, 0, 0);
64913 + fd = sys_open((char __force_user *)name, 0, 0);
64914 sys_ioctl(fd, BLKRRPART, 0);
64915 }
64916 sys_close(fd);
64917 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64918
64919 wait_for_device_probe();
64920
64921 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64922 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64923 if (fd >= 0) {
64924 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64925 sys_close(fd);
64926 diff --git a/init/initramfs.c b/init/initramfs.c
64927 index 8216c30..25e8e32 100644
64928 --- a/init/initramfs.c
64929 +++ b/init/initramfs.c
64930 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64931 }
64932 }
64933
64934 -static long __init do_utime(char __user *filename, time_t mtime)
64935 +static long __init do_utime(__force char __user *filename, time_t mtime)
64936 {
64937 struct timespec t[2];
64938
64939 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64940 struct dir_entry *de, *tmp;
64941 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64942 list_del(&de->list);
64943 - do_utime(de->name, de->mtime);
64944 + do_utime((char __force_user *)de->name, de->mtime);
64945 kfree(de->name);
64946 kfree(de);
64947 }
64948 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64949 if (nlink >= 2) {
64950 char *old = find_link(major, minor, ino, mode, collected);
64951 if (old)
64952 - return (sys_link(old, collected) < 0) ? -1 : 1;
64953 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64954 }
64955 return 0;
64956 }
64957 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64958 {
64959 struct stat st;
64960
64961 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64962 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64963 if (S_ISDIR(st.st_mode))
64964 - sys_rmdir(path);
64965 + sys_rmdir((char __force_user *)path);
64966 else
64967 - sys_unlink(path);
64968 + sys_unlink((char __force_user *)path);
64969 }
64970 }
64971
64972 @@ -305,7 +305,7 @@ static int __init do_name(void)
64973 int openflags = O_WRONLY|O_CREAT;
64974 if (ml != 1)
64975 openflags |= O_TRUNC;
64976 - wfd = sys_open(collected, openflags, mode);
64977 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64978
64979 if (wfd >= 0) {
64980 sys_fchown(wfd, uid, gid);
64981 @@ -317,17 +317,17 @@ static int __init do_name(void)
64982 }
64983 }
64984 } else if (S_ISDIR(mode)) {
64985 - sys_mkdir(collected, mode);
64986 - sys_chown(collected, uid, gid);
64987 - sys_chmod(collected, mode);
64988 + sys_mkdir((char __force_user *)collected, mode);
64989 + sys_chown((char __force_user *)collected, uid, gid);
64990 + sys_chmod((char __force_user *)collected, mode);
64991 dir_add(collected, mtime);
64992 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64993 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64994 if (maybe_link() == 0) {
64995 - sys_mknod(collected, mode, rdev);
64996 - sys_chown(collected, uid, gid);
64997 - sys_chmod(collected, mode);
64998 - do_utime(collected, mtime);
64999 + sys_mknod((char __force_user *)collected, mode, rdev);
65000 + sys_chown((char __force_user *)collected, uid, gid);
65001 + sys_chmod((char __force_user *)collected, mode);
65002 + do_utime((char __force_user *)collected, mtime);
65003 }
65004 }
65005 return 0;
65006 @@ -336,15 +336,15 @@ static int __init do_name(void)
65007 static int __init do_copy(void)
65008 {
65009 if (count >= body_len) {
65010 - sys_write(wfd, victim, body_len);
65011 + sys_write(wfd, (char __force_user *)victim, body_len);
65012 sys_close(wfd);
65013 - do_utime(vcollected, mtime);
65014 + do_utime((char __force_user *)vcollected, mtime);
65015 kfree(vcollected);
65016 eat(body_len);
65017 state = SkipIt;
65018 return 0;
65019 } else {
65020 - sys_write(wfd, victim, count);
65021 + sys_write(wfd, (char __force_user *)victim, count);
65022 body_len -= count;
65023 eat(count);
65024 return 1;
65025 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
65026 {
65027 collected[N_ALIGN(name_len) + body_len] = '\0';
65028 clean_path(collected, 0);
65029 - sys_symlink(collected + N_ALIGN(name_len), collected);
65030 - sys_lchown(collected, uid, gid);
65031 - do_utime(collected, mtime);
65032 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65033 + sys_lchown((char __force_user *)collected, uid, gid);
65034 + do_utime((char __force_user *)collected, mtime);
65035 state = SkipIt;
65036 next_state = Reset;
65037 return 0;
65038 diff --git a/init/main.c b/init/main.c
65039 index ff49a6d..5fa0429 100644
65040 --- a/init/main.c
65041 +++ b/init/main.c
65042 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
65043 extern void tc_init(void);
65044 #endif
65045
65046 +extern void grsecurity_init(void);
65047 +
65048 /*
65049 * Debug helper: via this flag we know that we are in 'early bootup code'
65050 * where only the boot processor is running with IRQ disabled. This means
65051 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
65052
65053 __setup("reset_devices", set_reset_devices);
65054
65055 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65056 +extern char pax_enter_kernel_user[];
65057 +extern char pax_exit_kernel_user[];
65058 +extern pgdval_t clone_pgd_mask;
65059 +#endif
65060 +
65061 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65062 +static int __init setup_pax_nouderef(char *str)
65063 +{
65064 +#ifdef CONFIG_X86_32
65065 + unsigned int cpu;
65066 + struct desc_struct *gdt;
65067 +
65068 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65069 + gdt = get_cpu_gdt_table(cpu);
65070 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65071 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65072 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65073 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65074 + }
65075 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65076 +#else
65077 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65078 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65079 + clone_pgd_mask = ~(pgdval_t)0UL;
65080 +#endif
65081 +
65082 + return 0;
65083 +}
65084 +early_param("pax_nouderef", setup_pax_nouderef);
65085 +#endif
65086 +
65087 +#ifdef CONFIG_PAX_SOFTMODE
65088 +int pax_softmode;
65089 +
65090 +static int __init setup_pax_softmode(char *str)
65091 +{
65092 + get_option(&str, &pax_softmode);
65093 + return 1;
65094 +}
65095 +__setup("pax_softmode=", setup_pax_softmode);
65096 +#endif
65097 +
65098 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65099 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65100 static const char *panic_later, *panic_param;
65101 @@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65102 {
65103 int count = preempt_count();
65104 int ret;
65105 + const char *msg1 = "", *msg2 = "";
65106
65107 if (initcall_debug)
65108 ret = do_one_initcall_debug(fn);
65109 @@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65110 sprintf(msgbuf, "error code %d ", ret);
65111
65112 if (preempt_count() != count) {
65113 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65114 + msg1 = " preemption imbalance";
65115 preempt_count() = count;
65116 }
65117 if (irqs_disabled()) {
65118 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65119 + msg2 = " disabled interrupts";
65120 local_irq_enable();
65121 }
65122 - if (msgbuf[0]) {
65123 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65124 + if (msgbuf[0] || *msg1 || *msg2) {
65125 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65126 }
65127
65128 return ret;
65129 @@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
65130 do_basic_setup();
65131
65132 /* Open the /dev/console on the rootfs, this should never fail */
65133 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65134 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65135 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65136
65137 (void) sys_dup(0);
65138 @@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
65139 if (!ramdisk_execute_command)
65140 ramdisk_execute_command = "/init";
65141
65142 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65143 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65144 ramdisk_execute_command = NULL;
65145 prepare_namespace();
65146 }
65147
65148 + grsecurity_init();
65149 +
65150 /*
65151 * Ok, we have completed the initial bootup, and
65152 * we're essentially up and running. Get rid of the
65153 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65154 index 86ee272..773d937 100644
65155 --- a/ipc/mqueue.c
65156 +++ b/ipc/mqueue.c
65157 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65158 mq_bytes = (mq_msg_tblsz +
65159 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65160
65161 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65162 spin_lock(&mq_lock);
65163 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65164 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65165 diff --git a/ipc/msg.c b/ipc/msg.c
65166 index 7385de2..a8180e08 100644
65167 --- a/ipc/msg.c
65168 +++ b/ipc/msg.c
65169 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65170 return security_msg_queue_associate(msq, msgflg);
65171 }
65172
65173 +static struct ipc_ops msg_ops = {
65174 + .getnew = newque,
65175 + .associate = msg_security,
65176 + .more_checks = NULL
65177 +};
65178 +
65179 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65180 {
65181 struct ipc_namespace *ns;
65182 - struct ipc_ops msg_ops;
65183 struct ipc_params msg_params;
65184
65185 ns = current->nsproxy->ipc_ns;
65186
65187 - msg_ops.getnew = newque;
65188 - msg_ops.associate = msg_security;
65189 - msg_ops.more_checks = NULL;
65190 -
65191 msg_params.key = key;
65192 msg_params.flg = msgflg;
65193
65194 diff --git a/ipc/sem.c b/ipc/sem.c
65195 index 5215a81..cfc0cac 100644
65196 --- a/ipc/sem.c
65197 +++ b/ipc/sem.c
65198 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65199 return 0;
65200 }
65201
65202 +static struct ipc_ops sem_ops = {
65203 + .getnew = newary,
65204 + .associate = sem_security,
65205 + .more_checks = sem_more_checks
65206 +};
65207 +
65208 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65209 {
65210 struct ipc_namespace *ns;
65211 - struct ipc_ops sem_ops;
65212 struct ipc_params sem_params;
65213
65214 ns = current->nsproxy->ipc_ns;
65215 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65216 if (nsems < 0 || nsems > ns->sc_semmsl)
65217 return -EINVAL;
65218
65219 - sem_ops.getnew = newary;
65220 - sem_ops.associate = sem_security;
65221 - sem_ops.more_checks = sem_more_checks;
65222 -
65223 sem_params.key = key;
65224 sem_params.flg = semflg;
65225 sem_params.u.nsems = nsems;
65226 diff --git a/ipc/shm.c b/ipc/shm.c
65227 index b76be5b..859e750 100644
65228 --- a/ipc/shm.c
65229 +++ b/ipc/shm.c
65230 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65231 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65232 #endif
65233
65234 +#ifdef CONFIG_GRKERNSEC
65235 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65236 + const time_t shm_createtime, const uid_t cuid,
65237 + const int shmid);
65238 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65239 + const time_t shm_createtime);
65240 +#endif
65241 +
65242 void shm_init_ns(struct ipc_namespace *ns)
65243 {
65244 ns->shm_ctlmax = SHMMAX;
65245 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65246 shp->shm_lprid = 0;
65247 shp->shm_atim = shp->shm_dtim = 0;
65248 shp->shm_ctim = get_seconds();
65249 +#ifdef CONFIG_GRKERNSEC
65250 + {
65251 + struct timespec timeval;
65252 + do_posix_clock_monotonic_gettime(&timeval);
65253 +
65254 + shp->shm_createtime = timeval.tv_sec;
65255 + }
65256 +#endif
65257 shp->shm_segsz = size;
65258 shp->shm_nattch = 0;
65259 shp->shm_file = file;
65260 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65261 return 0;
65262 }
65263
65264 +static struct ipc_ops shm_ops = {
65265 + .getnew = newseg,
65266 + .associate = shm_security,
65267 + .more_checks = shm_more_checks
65268 +};
65269 +
65270 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65271 {
65272 struct ipc_namespace *ns;
65273 - struct ipc_ops shm_ops;
65274 struct ipc_params shm_params;
65275
65276 ns = current->nsproxy->ipc_ns;
65277
65278 - shm_ops.getnew = newseg;
65279 - shm_ops.associate = shm_security;
65280 - shm_ops.more_checks = shm_more_checks;
65281 -
65282 shm_params.key = key;
65283 shm_params.flg = shmflg;
65284 shm_params.u.size = size;
65285 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65286 f_mode = FMODE_READ | FMODE_WRITE;
65287 }
65288 if (shmflg & SHM_EXEC) {
65289 +
65290 +#ifdef CONFIG_PAX_MPROTECT
65291 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65292 + goto out;
65293 +#endif
65294 +
65295 prot |= PROT_EXEC;
65296 acc_mode |= S_IXUGO;
65297 }
65298 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65299 if (err)
65300 goto out_unlock;
65301
65302 +#ifdef CONFIG_GRKERNSEC
65303 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65304 + shp->shm_perm.cuid, shmid) ||
65305 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65306 + err = -EACCES;
65307 + goto out_unlock;
65308 + }
65309 +#endif
65310 +
65311 path = shp->shm_file->f_path;
65312 path_get(&path);
65313 shp->shm_nattch++;
65314 +#ifdef CONFIG_GRKERNSEC
65315 + shp->shm_lapid = current->pid;
65316 +#endif
65317 size = i_size_read(path.dentry->d_inode);
65318 shm_unlock(shp);
65319
65320 diff --git a/kernel/acct.c b/kernel/acct.c
65321 index 02e6167..54824f7 100644
65322 --- a/kernel/acct.c
65323 +++ b/kernel/acct.c
65324 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65325 */
65326 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65327 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65328 - file->f_op->write(file, (char *)&ac,
65329 + file->f_op->write(file, (char __force_user *)&ac,
65330 sizeof(acct_t), &file->f_pos);
65331 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65332 set_fs(fs);
65333 diff --git a/kernel/audit.c b/kernel/audit.c
65334 index bb0eb5b..cf2a03a 100644
65335 --- a/kernel/audit.c
65336 +++ b/kernel/audit.c
65337 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65338 3) suppressed due to audit_rate_limit
65339 4) suppressed due to audit_backlog_limit
65340 */
65341 -static atomic_t audit_lost = ATOMIC_INIT(0);
65342 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65343
65344 /* The netlink socket. */
65345 static struct sock *audit_sock;
65346 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65347 unsigned long now;
65348 int print;
65349
65350 - atomic_inc(&audit_lost);
65351 + atomic_inc_unchecked(&audit_lost);
65352
65353 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65354
65355 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65356 printk(KERN_WARNING
65357 "audit: audit_lost=%d audit_rate_limit=%d "
65358 "audit_backlog_limit=%d\n",
65359 - atomic_read(&audit_lost),
65360 + atomic_read_unchecked(&audit_lost),
65361 audit_rate_limit,
65362 audit_backlog_limit);
65363 audit_panic(message);
65364 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65365 status_set.pid = audit_pid;
65366 status_set.rate_limit = audit_rate_limit;
65367 status_set.backlog_limit = audit_backlog_limit;
65368 - status_set.lost = atomic_read(&audit_lost);
65369 + status_set.lost = atomic_read_unchecked(&audit_lost);
65370 status_set.backlog = skb_queue_len(&audit_skb_queue);
65371 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65372 &status_set, sizeof(status_set));
65373 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65374 index af1de0f..06dfe57 100644
65375 --- a/kernel/auditsc.c
65376 +++ b/kernel/auditsc.c
65377 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65378 }
65379
65380 /* global counter which is incremented every time something logs in */
65381 -static atomic_t session_id = ATOMIC_INIT(0);
65382 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65383
65384 /**
65385 * audit_set_loginuid - set current task's audit_context loginuid
65386 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65387 return -EPERM;
65388 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65389
65390 - sessionid = atomic_inc_return(&session_id);
65391 + sessionid = atomic_inc_return_unchecked(&session_id);
65392 if (context && context->in_syscall) {
65393 struct audit_buffer *ab;
65394
65395 diff --git a/kernel/capability.c b/kernel/capability.c
65396 index 3f1adb6..c564db0 100644
65397 --- a/kernel/capability.c
65398 +++ b/kernel/capability.c
65399 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65400 * before modification is attempted and the application
65401 * fails.
65402 */
65403 + if (tocopy > ARRAY_SIZE(kdata))
65404 + return -EFAULT;
65405 +
65406 if (copy_to_user(dataptr, kdata, tocopy
65407 * sizeof(struct __user_cap_data_struct))) {
65408 return -EFAULT;
65409 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65410 int ret;
65411
65412 rcu_read_lock();
65413 - ret = security_capable(__task_cred(t), ns, cap);
65414 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65415 + gr_task_is_capable(t, __task_cred(t), cap);
65416 rcu_read_unlock();
65417
65418 - return (ret == 0);
65419 + return ret;
65420 }
65421
65422 /**
65423 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65424 int ret;
65425
65426 rcu_read_lock();
65427 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65428 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65429 rcu_read_unlock();
65430
65431 - return (ret == 0);
65432 + return ret;
65433 }
65434
65435 /**
65436 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65437 BUG();
65438 }
65439
65440 - if (security_capable(current_cred(), ns, cap) == 0) {
65441 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65442 current->flags |= PF_SUPERPRIV;
65443 return true;
65444 }
65445 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65446 }
65447 EXPORT_SYMBOL(ns_capable);
65448
65449 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65450 +{
65451 + if (unlikely(!cap_valid(cap))) {
65452 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65453 + BUG();
65454 + }
65455 +
65456 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65457 + current->flags |= PF_SUPERPRIV;
65458 + return true;
65459 + }
65460 + return false;
65461 +}
65462 +EXPORT_SYMBOL(ns_capable_nolog);
65463 +
65464 /**
65465 * capable - Determine if the current task has a superior capability in effect
65466 * @cap: The capability to be tested for
65467 @@ -408,6 +427,12 @@ bool capable(int cap)
65468 }
65469 EXPORT_SYMBOL(capable);
65470
65471 +bool capable_nolog(int cap)
65472 +{
65473 + return ns_capable_nolog(&init_user_ns, cap);
65474 +}
65475 +EXPORT_SYMBOL(capable_nolog);
65476 +
65477 /**
65478 * nsown_capable - Check superior capability to one's own user_ns
65479 * @cap: The capability in question
65480 diff --git a/kernel/compat.c b/kernel/compat.c
65481 index f346ced..aa2b1f4 100644
65482 --- a/kernel/compat.c
65483 +++ b/kernel/compat.c
65484 @@ -13,6 +13,7 @@
65485
65486 #include <linux/linkage.h>
65487 #include <linux/compat.h>
65488 +#include <linux/module.h>
65489 #include <linux/errno.h>
65490 #include <linux/time.h>
65491 #include <linux/signal.h>
65492 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65493 mm_segment_t oldfs;
65494 long ret;
65495
65496 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65497 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65498 oldfs = get_fs();
65499 set_fs(KERNEL_DS);
65500 ret = hrtimer_nanosleep_restart(restart);
65501 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65502 oldfs = get_fs();
65503 set_fs(KERNEL_DS);
65504 ret = hrtimer_nanosleep(&tu,
65505 - rmtp ? (struct timespec __user *)&rmt : NULL,
65506 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65507 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65508 set_fs(oldfs);
65509
65510 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65511 mm_segment_t old_fs = get_fs();
65512
65513 set_fs(KERNEL_DS);
65514 - ret = sys_sigpending((old_sigset_t __user *) &s);
65515 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65516 set_fs(old_fs);
65517 if (ret == 0)
65518 ret = put_user(s, set);
65519 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65520 old_fs = get_fs();
65521 set_fs(KERNEL_DS);
65522 ret = sys_sigprocmask(how,
65523 - set ? (old_sigset_t __user *) &s : NULL,
65524 - oset ? (old_sigset_t __user *) &s : NULL);
65525 + set ? (old_sigset_t __force_user *) &s : NULL,
65526 + oset ? (old_sigset_t __force_user *) &s : NULL);
65527 set_fs(old_fs);
65528 if (ret == 0)
65529 if (oset)
65530 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65531 mm_segment_t old_fs = get_fs();
65532
65533 set_fs(KERNEL_DS);
65534 - ret = sys_old_getrlimit(resource, &r);
65535 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65536 set_fs(old_fs);
65537
65538 if (!ret) {
65539 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65540 mm_segment_t old_fs = get_fs();
65541
65542 set_fs(KERNEL_DS);
65543 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65544 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65545 set_fs(old_fs);
65546
65547 if (ret)
65548 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65549 set_fs (KERNEL_DS);
65550 ret = sys_wait4(pid,
65551 (stat_addr ?
65552 - (unsigned int __user *) &status : NULL),
65553 - options, (struct rusage __user *) &r);
65554 + (unsigned int __force_user *) &status : NULL),
65555 + options, (struct rusage __force_user *) &r);
65556 set_fs (old_fs);
65557
65558 if (ret > 0) {
65559 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65560 memset(&info, 0, sizeof(info));
65561
65562 set_fs(KERNEL_DS);
65563 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65564 - uru ? (struct rusage __user *)&ru : NULL);
65565 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65566 + uru ? (struct rusage __force_user *)&ru : NULL);
65567 set_fs(old_fs);
65568
65569 if ((ret < 0) || (info.si_signo == 0))
65570 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65571 oldfs = get_fs();
65572 set_fs(KERNEL_DS);
65573 err = sys_timer_settime(timer_id, flags,
65574 - (struct itimerspec __user *) &newts,
65575 - (struct itimerspec __user *) &oldts);
65576 + (struct itimerspec __force_user *) &newts,
65577 + (struct itimerspec __force_user *) &oldts);
65578 set_fs(oldfs);
65579 if (!err && old && put_compat_itimerspec(old, &oldts))
65580 return -EFAULT;
65581 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65582 oldfs = get_fs();
65583 set_fs(KERNEL_DS);
65584 err = sys_timer_gettime(timer_id,
65585 - (struct itimerspec __user *) &ts);
65586 + (struct itimerspec __force_user *) &ts);
65587 set_fs(oldfs);
65588 if (!err && put_compat_itimerspec(setting, &ts))
65589 return -EFAULT;
65590 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65591 oldfs = get_fs();
65592 set_fs(KERNEL_DS);
65593 err = sys_clock_settime(which_clock,
65594 - (struct timespec __user *) &ts);
65595 + (struct timespec __force_user *) &ts);
65596 set_fs(oldfs);
65597 return err;
65598 }
65599 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65600 oldfs = get_fs();
65601 set_fs(KERNEL_DS);
65602 err = sys_clock_gettime(which_clock,
65603 - (struct timespec __user *) &ts);
65604 + (struct timespec __force_user *) &ts);
65605 set_fs(oldfs);
65606 if (!err && put_compat_timespec(&ts, tp))
65607 return -EFAULT;
65608 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65609
65610 oldfs = get_fs();
65611 set_fs(KERNEL_DS);
65612 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65613 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65614 set_fs(oldfs);
65615
65616 err = compat_put_timex(utp, &txc);
65617 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65618 oldfs = get_fs();
65619 set_fs(KERNEL_DS);
65620 err = sys_clock_getres(which_clock,
65621 - (struct timespec __user *) &ts);
65622 + (struct timespec __force_user *) &ts);
65623 set_fs(oldfs);
65624 if (!err && tp && put_compat_timespec(&ts, tp))
65625 return -EFAULT;
65626 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65627 long err;
65628 mm_segment_t oldfs;
65629 struct timespec tu;
65630 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65631 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65632
65633 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65634 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65635 oldfs = get_fs();
65636 set_fs(KERNEL_DS);
65637 err = clock_nanosleep_restart(restart);
65638 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65639 oldfs = get_fs();
65640 set_fs(KERNEL_DS);
65641 err = sys_clock_nanosleep(which_clock, flags,
65642 - (struct timespec __user *) &in,
65643 - (struct timespec __user *) &out);
65644 + (struct timespec __force_user *) &in,
65645 + (struct timespec __force_user *) &out);
65646 set_fs(oldfs);
65647
65648 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65649 diff --git a/kernel/configs.c b/kernel/configs.c
65650 index 42e8fa0..9e7406b 100644
65651 --- a/kernel/configs.c
65652 +++ b/kernel/configs.c
65653 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65654 struct proc_dir_entry *entry;
65655
65656 /* create the current config file */
65657 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65658 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65659 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65660 + &ikconfig_file_ops);
65661 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65662 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65663 + &ikconfig_file_ops);
65664 +#endif
65665 +#else
65666 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65667 &ikconfig_file_ops);
65668 +#endif
65669 +
65670 if (!entry)
65671 return -ENOMEM;
65672
65673 diff --git a/kernel/cred.c b/kernel/cred.c
65674 index 48c6fd3..3342f00 100644
65675 --- a/kernel/cred.c
65676 +++ b/kernel/cred.c
65677 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65678 validate_creds(cred);
65679 put_cred(cred);
65680 }
65681 +
65682 +#ifdef CONFIG_GRKERNSEC_SETXID
65683 + cred = (struct cred *) tsk->delayed_cred;
65684 + if (cred) {
65685 + tsk->delayed_cred = NULL;
65686 + validate_creds(cred);
65687 + put_cred(cred);
65688 + }
65689 +#endif
65690 }
65691
65692 /**
65693 @@ -472,7 +481,7 @@ error_put:
65694 * Always returns 0 thus allowing this function to be tail-called at the end
65695 * of, say, sys_setgid().
65696 */
65697 -int commit_creds(struct cred *new)
65698 +static int __commit_creds(struct cred *new)
65699 {
65700 struct task_struct *task = current;
65701 const struct cred *old = task->real_cred;
65702 @@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
65703
65704 get_cred(new); /* we will require a ref for the subj creds too */
65705
65706 + gr_set_role_label(task, new->uid, new->gid);
65707 +
65708 /* dumpability changes */
65709 if (old->euid != new->euid ||
65710 old->egid != new->egid ||
65711 @@ -540,6 +551,92 @@ int commit_creds(struct cred *new)
65712 put_cred(old);
65713 return 0;
65714 }
65715 +#ifdef CONFIG_GRKERNSEC_SETXID
65716 +extern int set_user(struct cred *new);
65717 +
65718 +void gr_delayed_cred_worker(void)
65719 +{
65720 + const struct cred *new = current->delayed_cred;
65721 + struct cred *ncred;
65722 +
65723 + current->delayed_cred = NULL;
65724 +
65725 + if (current_uid() && new != NULL) {
65726 + // from doing get_cred on it when queueing this
65727 + put_cred(new);
65728 + return;
65729 + } else if (new == NULL)
65730 + return;
65731 +
65732 + ncred = prepare_creds();
65733 + if (!ncred)
65734 + goto die;
65735 + // uids
65736 + ncred->uid = new->uid;
65737 + ncred->euid = new->euid;
65738 + ncred->suid = new->suid;
65739 + ncred->fsuid = new->fsuid;
65740 + // gids
65741 + ncred->gid = new->gid;
65742 + ncred->egid = new->egid;
65743 + ncred->sgid = new->sgid;
65744 + ncred->fsgid = new->fsgid;
65745 + // groups
65746 + if (set_groups(ncred, new->group_info) < 0) {
65747 + abort_creds(ncred);
65748 + goto die;
65749 + }
65750 + // caps
65751 + ncred->securebits = new->securebits;
65752 + ncred->cap_inheritable = new->cap_inheritable;
65753 + ncred->cap_permitted = new->cap_permitted;
65754 + ncred->cap_effective = new->cap_effective;
65755 + ncred->cap_bset = new->cap_bset;
65756 +
65757 + if (set_user(ncred)) {
65758 + abort_creds(ncred);
65759 + goto die;
65760 + }
65761 +
65762 + // from doing get_cred on it when queueing this
65763 + put_cred(new);
65764 +
65765 + __commit_creds(ncred);
65766 + return;
65767 +die:
65768 + // from doing get_cred on it when queueing this
65769 + put_cred(new);
65770 + do_group_exit(SIGKILL);
65771 +}
65772 +#endif
65773 +
65774 +int commit_creds(struct cred *new)
65775 +{
65776 +#ifdef CONFIG_GRKERNSEC_SETXID
65777 + struct task_struct *t;
65778 +
65779 + /* we won't get called with tasklist_lock held for writing
65780 + and interrupts disabled as the cred struct in that case is
65781 + init_cred
65782 + */
65783 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65784 + !current_uid() && new->uid) {
65785 + rcu_read_lock();
65786 + read_lock(&tasklist_lock);
65787 + for (t = next_thread(current); t != current;
65788 + t = next_thread(t)) {
65789 + if (t->delayed_cred == NULL) {
65790 + t->delayed_cred = get_cred(new);
65791 + set_tsk_need_resched(t);
65792 + }
65793 + }
65794 + read_unlock(&tasklist_lock);
65795 + rcu_read_unlock();
65796 + }
65797 +#endif
65798 + return __commit_creds(new);
65799 +}
65800 +
65801 EXPORT_SYMBOL(commit_creds);
65802
65803 /**
65804 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65805 index 7fda904..59f620c 100644
65806 --- a/kernel/debug/debug_core.c
65807 +++ b/kernel/debug/debug_core.c
65808 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65809 */
65810 static atomic_t masters_in_kgdb;
65811 static atomic_t slaves_in_kgdb;
65812 -static atomic_t kgdb_break_tasklet_var;
65813 +static atomic_unchecked_t kgdb_break_tasklet_var;
65814 atomic_t kgdb_setting_breakpoint;
65815
65816 struct task_struct *kgdb_usethread;
65817 @@ -129,7 +129,7 @@ int kgdb_single_step;
65818 static pid_t kgdb_sstep_pid;
65819
65820 /* to keep track of the CPU which is doing the single stepping*/
65821 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65822 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65823
65824 /*
65825 * If you are debugging a problem where roundup (the collection of
65826 @@ -537,7 +537,7 @@ return_normal:
65827 * kernel will only try for the value of sstep_tries before
65828 * giving up and continuing on.
65829 */
65830 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65831 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65832 (kgdb_info[cpu].task &&
65833 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65834 atomic_set(&kgdb_active, -1);
65835 @@ -631,8 +631,8 @@ cpu_master_loop:
65836 }
65837
65838 kgdb_restore:
65839 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65840 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65841 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65842 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65843 if (kgdb_info[sstep_cpu].task)
65844 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65845 else
65846 @@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
65847 static void kgdb_tasklet_bpt(unsigned long ing)
65848 {
65849 kgdb_breakpoint();
65850 - atomic_set(&kgdb_break_tasklet_var, 0);
65851 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65852 }
65853
65854 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65855
65856 void kgdb_schedule_breakpoint(void)
65857 {
65858 - if (atomic_read(&kgdb_break_tasklet_var) ||
65859 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65860 atomic_read(&kgdb_active) != -1 ||
65861 atomic_read(&kgdb_setting_breakpoint))
65862 return;
65863 - atomic_inc(&kgdb_break_tasklet_var);
65864 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65865 tasklet_schedule(&kgdb_tasklet_breakpoint);
65866 }
65867 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65868 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65869 index e2ae734..08a4c5c 100644
65870 --- a/kernel/debug/kdb/kdb_main.c
65871 +++ b/kernel/debug/kdb/kdb_main.c
65872 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65873 list_for_each_entry(mod, kdb_modules, list) {
65874
65875 kdb_printf("%-20s%8u 0x%p ", mod->name,
65876 - mod->core_size, (void *)mod);
65877 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65878 #ifdef CONFIG_MODULE_UNLOAD
65879 kdb_printf("%4ld ", module_refcount(mod));
65880 #endif
65881 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65882 kdb_printf(" (Loading)");
65883 else
65884 kdb_printf(" (Live)");
65885 - kdb_printf(" 0x%p", mod->module_core);
65886 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65887
65888 #ifdef CONFIG_MODULE_UNLOAD
65889 {
65890 diff --git a/kernel/events/core.c b/kernel/events/core.c
65891 index 1b5c081..c375f83 100644
65892 --- a/kernel/events/core.c
65893 +++ b/kernel/events/core.c
65894 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65895 return 0;
65896 }
65897
65898 -static atomic64_t perf_event_id;
65899 +static atomic64_unchecked_t perf_event_id;
65900
65901 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65902 enum event_type_t event_type);
65903 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
65904
65905 static inline u64 perf_event_count(struct perf_event *event)
65906 {
65907 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65908 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65909 }
65910
65911 static u64 perf_event_read(struct perf_event *event)
65912 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65913 mutex_lock(&event->child_mutex);
65914 total += perf_event_read(event);
65915 *enabled += event->total_time_enabled +
65916 - atomic64_read(&event->child_total_time_enabled);
65917 + atomic64_read_unchecked(&event->child_total_time_enabled);
65918 *running += event->total_time_running +
65919 - atomic64_read(&event->child_total_time_running);
65920 + atomic64_read_unchecked(&event->child_total_time_running);
65921
65922 list_for_each_entry(child, &event->child_list, child_list) {
65923 total += perf_event_read(child);
65924 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
65925 userpg->offset -= local64_read(&event->hw.prev_count);
65926
65927 userpg->time_enabled = enabled +
65928 - atomic64_read(&event->child_total_time_enabled);
65929 + atomic64_read_unchecked(&event->child_total_time_enabled);
65930
65931 userpg->time_running = running +
65932 - atomic64_read(&event->child_total_time_running);
65933 + atomic64_read_unchecked(&event->child_total_time_running);
65934
65935 barrier();
65936 ++userpg->lock;
65937 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65938 values[n++] = perf_event_count(event);
65939 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65940 values[n++] = enabled +
65941 - atomic64_read(&event->child_total_time_enabled);
65942 + atomic64_read_unchecked(&event->child_total_time_enabled);
65943 }
65944 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65945 values[n++] = running +
65946 - atomic64_read(&event->child_total_time_running);
65947 + atomic64_read_unchecked(&event->child_total_time_running);
65948 }
65949 if (read_format & PERF_FORMAT_ID)
65950 values[n++] = primary_event_id(event);
65951 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65952 * need to add enough zero bytes after the string to handle
65953 * the 64bit alignment we do later.
65954 */
65955 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65956 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65957 if (!buf) {
65958 name = strncpy(tmp, "//enomem", sizeof(tmp));
65959 goto got_name;
65960 }
65961 - name = d_path(&file->f_path, buf, PATH_MAX);
65962 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65963 if (IS_ERR(name)) {
65964 name = strncpy(tmp, "//toolong", sizeof(tmp));
65965 goto got_name;
65966 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65967 event->parent = parent_event;
65968
65969 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65970 - event->id = atomic64_inc_return(&perf_event_id);
65971 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65972
65973 event->state = PERF_EVENT_STATE_INACTIVE;
65974
65975 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
65976 /*
65977 * Add back the child's count to the parent's count:
65978 */
65979 - atomic64_add(child_val, &parent_event->child_count);
65980 - atomic64_add(child_event->total_time_enabled,
65981 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65982 + atomic64_add_unchecked(child_event->total_time_enabled,
65983 &parent_event->child_total_time_enabled);
65984 - atomic64_add(child_event->total_time_running,
65985 + atomic64_add_unchecked(child_event->total_time_running,
65986 &parent_event->child_total_time_running);
65987
65988 /*
65989 diff --git a/kernel/exit.c b/kernel/exit.c
65990 index 4b4042f..5bdd8d5 100644
65991 --- a/kernel/exit.c
65992 +++ b/kernel/exit.c
65993 @@ -58,6 +58,10 @@
65994 #include <asm/pgtable.h>
65995 #include <asm/mmu_context.h>
65996
65997 +#ifdef CONFIG_GRKERNSEC
65998 +extern rwlock_t grsec_exec_file_lock;
65999 +#endif
66000 +
66001 static void exit_mm(struct task_struct * tsk);
66002
66003 static void __unhash_process(struct task_struct *p, bool group_dead)
66004 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
66005 struct task_struct *leader;
66006 int zap_leader;
66007 repeat:
66008 +#ifdef CONFIG_NET
66009 + gr_del_task_from_ip_table(p);
66010 +#endif
66011 +
66012 /* don't need to get the RCU readlock here - the process is dead and
66013 * can't be modifying its own credentials. But shut RCU-lockdep up */
66014 rcu_read_lock();
66015 @@ -381,7 +389,7 @@ int allow_signal(int sig)
66016 * know it'll be handled, so that they don't get converted to
66017 * SIGKILL or just silently dropped.
66018 */
66019 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66020 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66021 recalc_sigpending();
66022 spin_unlock_irq(&current->sighand->siglock);
66023 return 0;
66024 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
66025 vsnprintf(current->comm, sizeof(current->comm), name, args);
66026 va_end(args);
66027
66028 +#ifdef CONFIG_GRKERNSEC
66029 + write_lock(&grsec_exec_file_lock);
66030 + if (current->exec_file) {
66031 + fput(current->exec_file);
66032 + current->exec_file = NULL;
66033 + }
66034 + write_unlock(&grsec_exec_file_lock);
66035 +#endif
66036 +
66037 + gr_set_kernel_label(current);
66038 +
66039 /*
66040 * If we were started as result of loading a module, close all of the
66041 * user space pages. We don't need them, and if we didn't close them
66042 @@ -892,6 +911,8 @@ void do_exit(long code)
66043 struct task_struct *tsk = current;
66044 int group_dead;
66045
66046 + set_fs(USER_DS);
66047 +
66048 profile_task_exit(tsk);
66049
66050 WARN_ON(blk_needs_flush_plug(tsk));
66051 @@ -908,7 +929,6 @@ void do_exit(long code)
66052 * mm_release()->clear_child_tid() from writing to a user-controlled
66053 * kernel address.
66054 */
66055 - set_fs(USER_DS);
66056
66057 ptrace_event(PTRACE_EVENT_EXIT, code);
66058
66059 @@ -969,6 +989,9 @@ void do_exit(long code)
66060 tsk->exit_code = code;
66061 taskstats_exit(tsk, group_dead);
66062
66063 + gr_acl_handle_psacct(tsk, code);
66064 + gr_acl_handle_exit();
66065 +
66066 exit_mm(tsk);
66067
66068 if (group_dead)
66069 @@ -1085,7 +1108,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66070 * Take down every thread in the group. This is called by fatal signals
66071 * as well as by sys_exit_group (below).
66072 */
66073 -void
66074 +__noreturn void
66075 do_group_exit(int exit_code)
66076 {
66077 struct signal_struct *sig = current->signal;
66078 diff --git a/kernel/fork.c b/kernel/fork.c
66079 index 26a7a67..a1053f9 100644
66080 --- a/kernel/fork.c
66081 +++ b/kernel/fork.c
66082 @@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66083 *stackend = STACK_END_MAGIC; /* for overflow detection */
66084
66085 #ifdef CONFIG_CC_STACKPROTECTOR
66086 - tsk->stack_canary = get_random_int();
66087 + tsk->stack_canary = pax_get_random_long();
66088 #endif
66089
66090 /*
66091 @@ -308,13 +308,77 @@ out:
66092 }
66093
66094 #ifdef CONFIG_MMU
66095 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66096 +{
66097 + struct vm_area_struct *tmp;
66098 + unsigned long charge;
66099 + struct mempolicy *pol;
66100 + struct file *file;
66101 +
66102 + charge = 0;
66103 + if (mpnt->vm_flags & VM_ACCOUNT) {
66104 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66105 + if (security_vm_enough_memory(len))
66106 + goto fail_nomem;
66107 + charge = len;
66108 + }
66109 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66110 + if (!tmp)
66111 + goto fail_nomem;
66112 + *tmp = *mpnt;
66113 + tmp->vm_mm = mm;
66114 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66115 + pol = mpol_dup(vma_policy(mpnt));
66116 + if (IS_ERR(pol))
66117 + goto fail_nomem_policy;
66118 + vma_set_policy(tmp, pol);
66119 + if (anon_vma_fork(tmp, mpnt))
66120 + goto fail_nomem_anon_vma_fork;
66121 + tmp->vm_flags &= ~VM_LOCKED;
66122 + tmp->vm_next = tmp->vm_prev = NULL;
66123 + tmp->vm_mirror = NULL;
66124 + file = tmp->vm_file;
66125 + if (file) {
66126 + struct inode *inode = file->f_path.dentry->d_inode;
66127 + struct address_space *mapping = file->f_mapping;
66128 +
66129 + get_file(file);
66130 + if (tmp->vm_flags & VM_DENYWRITE)
66131 + atomic_dec(&inode->i_writecount);
66132 + mutex_lock(&mapping->i_mmap_mutex);
66133 + if (tmp->vm_flags & VM_SHARED)
66134 + mapping->i_mmap_writable++;
66135 + flush_dcache_mmap_lock(mapping);
66136 + /* insert tmp into the share list, just after mpnt */
66137 + vma_prio_tree_add(tmp, mpnt);
66138 + flush_dcache_mmap_unlock(mapping);
66139 + mutex_unlock(&mapping->i_mmap_mutex);
66140 + }
66141 +
66142 + /*
66143 + * Clear hugetlb-related page reserves for children. This only
66144 + * affects MAP_PRIVATE mappings. Faults generated by the child
66145 + * are not guaranteed to succeed, even if read-only
66146 + */
66147 + if (is_vm_hugetlb_page(tmp))
66148 + reset_vma_resv_huge_pages(tmp);
66149 +
66150 + return tmp;
66151 +
66152 +fail_nomem_anon_vma_fork:
66153 + mpol_put(pol);
66154 +fail_nomem_policy:
66155 + kmem_cache_free(vm_area_cachep, tmp);
66156 +fail_nomem:
66157 + vm_unacct_memory(charge);
66158 + return NULL;
66159 +}
66160 +
66161 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66162 {
66163 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66164 struct rb_node **rb_link, *rb_parent;
66165 int retval;
66166 - unsigned long charge;
66167 - struct mempolicy *pol;
66168
66169 down_write(&oldmm->mmap_sem);
66170 flush_cache_dup_mm(oldmm);
66171 @@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66172 mm->locked_vm = 0;
66173 mm->mmap = NULL;
66174 mm->mmap_cache = NULL;
66175 - mm->free_area_cache = oldmm->mmap_base;
66176 - mm->cached_hole_size = ~0UL;
66177 + mm->free_area_cache = oldmm->free_area_cache;
66178 + mm->cached_hole_size = oldmm->cached_hole_size;
66179 mm->map_count = 0;
66180 cpumask_clear(mm_cpumask(mm));
66181 mm->mm_rb = RB_ROOT;
66182 @@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66183
66184 prev = NULL;
66185 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66186 - struct file *file;
66187 -
66188 if (mpnt->vm_flags & VM_DONTCOPY) {
66189 long pages = vma_pages(mpnt);
66190 mm->total_vm -= pages;
66191 @@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66192 -pages);
66193 continue;
66194 }
66195 - charge = 0;
66196 - if (mpnt->vm_flags & VM_ACCOUNT) {
66197 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66198 - if (security_vm_enough_memory(len))
66199 - goto fail_nomem;
66200 - charge = len;
66201 + tmp = dup_vma(mm, mpnt);
66202 + if (!tmp) {
66203 + retval = -ENOMEM;
66204 + goto out;
66205 }
66206 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66207 - if (!tmp)
66208 - goto fail_nomem;
66209 - *tmp = *mpnt;
66210 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66211 - pol = mpol_dup(vma_policy(mpnt));
66212 - retval = PTR_ERR(pol);
66213 - if (IS_ERR(pol))
66214 - goto fail_nomem_policy;
66215 - vma_set_policy(tmp, pol);
66216 - tmp->vm_mm = mm;
66217 - if (anon_vma_fork(tmp, mpnt))
66218 - goto fail_nomem_anon_vma_fork;
66219 - tmp->vm_flags &= ~VM_LOCKED;
66220 - tmp->vm_next = tmp->vm_prev = NULL;
66221 - file = tmp->vm_file;
66222 - if (file) {
66223 - struct inode *inode = file->f_path.dentry->d_inode;
66224 - struct address_space *mapping = file->f_mapping;
66225 -
66226 - get_file(file);
66227 - if (tmp->vm_flags & VM_DENYWRITE)
66228 - atomic_dec(&inode->i_writecount);
66229 - mutex_lock(&mapping->i_mmap_mutex);
66230 - if (tmp->vm_flags & VM_SHARED)
66231 - mapping->i_mmap_writable++;
66232 - flush_dcache_mmap_lock(mapping);
66233 - /* insert tmp into the share list, just after mpnt */
66234 - vma_prio_tree_add(tmp, mpnt);
66235 - flush_dcache_mmap_unlock(mapping);
66236 - mutex_unlock(&mapping->i_mmap_mutex);
66237 - }
66238 -
66239 - /*
66240 - * Clear hugetlb-related page reserves for children. This only
66241 - * affects MAP_PRIVATE mappings. Faults generated by the child
66242 - * are not guaranteed to succeed, even if read-only
66243 - */
66244 - if (is_vm_hugetlb_page(tmp))
66245 - reset_vma_resv_huge_pages(tmp);
66246
66247 /*
66248 * Link in the new vma and copy the page table entries.
66249 @@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66250 if (retval)
66251 goto out;
66252 }
66253 +
66254 +#ifdef CONFIG_PAX_SEGMEXEC
66255 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66256 + struct vm_area_struct *mpnt_m;
66257 +
66258 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66259 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66260 +
66261 + if (!mpnt->vm_mirror)
66262 + continue;
66263 +
66264 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66265 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66266 + mpnt->vm_mirror = mpnt_m;
66267 + } else {
66268 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66269 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66270 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66271 + mpnt->vm_mirror->vm_mirror = mpnt;
66272 + }
66273 + }
66274 + BUG_ON(mpnt_m);
66275 + }
66276 +#endif
66277 +
66278 /* a new mm has just been created */
66279 arch_dup_mmap(oldmm, mm);
66280 retval = 0;
66281 @@ -429,14 +474,6 @@ out:
66282 flush_tlb_mm(oldmm);
66283 up_write(&oldmm->mmap_sem);
66284 return retval;
66285 -fail_nomem_anon_vma_fork:
66286 - mpol_put(pol);
66287 -fail_nomem_policy:
66288 - kmem_cache_free(vm_area_cachep, tmp);
66289 -fail_nomem:
66290 - retval = -ENOMEM;
66291 - vm_unacct_memory(charge);
66292 - goto out;
66293 }
66294
66295 static inline int mm_alloc_pgd(struct mm_struct *mm)
66296 @@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66297 return ERR_PTR(err);
66298
66299 mm = get_task_mm(task);
66300 - if (mm && mm != current->mm &&
66301 - !ptrace_may_access(task, mode)) {
66302 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66303 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66304 mmput(mm);
66305 mm = ERR_PTR(-EACCES);
66306 }
66307 @@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66308 spin_unlock(&fs->lock);
66309 return -EAGAIN;
66310 }
66311 - fs->users++;
66312 + atomic_inc(&fs->users);
66313 spin_unlock(&fs->lock);
66314 return 0;
66315 }
66316 tsk->fs = copy_fs_struct(fs);
66317 if (!tsk->fs)
66318 return -ENOMEM;
66319 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66320 return 0;
66321 }
66322
66323 @@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66324 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66325 #endif
66326 retval = -EAGAIN;
66327 +
66328 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66329 +
66330 if (atomic_read(&p->real_cred->user->processes) >=
66331 task_rlimit(p, RLIMIT_NPROC)) {
66332 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66333 @@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66334 if (clone_flags & CLONE_THREAD)
66335 p->tgid = current->tgid;
66336
66337 + gr_copy_label(p);
66338 +
66339 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66340 /*
66341 * Clear TID on mm_release()?
66342 @@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
66343 bad_fork_free:
66344 free_task(p);
66345 fork_out:
66346 + gr_log_forkfail(retval);
66347 +
66348 return ERR_PTR(retval);
66349 }
66350
66351 @@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
66352 if (clone_flags & CLONE_PARENT_SETTID)
66353 put_user(nr, parent_tidptr);
66354
66355 + gr_handle_brute_check();
66356 +
66357 if (clone_flags & CLONE_VFORK) {
66358 p->vfork_done = &vfork;
66359 init_completion(&vfork);
66360 @@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66361 return 0;
66362
66363 /* don't need lock here; in the worst case we'll do useless copy */
66364 - if (fs->users == 1)
66365 + if (atomic_read(&fs->users) == 1)
66366 return 0;
66367
66368 *new_fsp = copy_fs_struct(fs);
66369 @@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66370 fs = current->fs;
66371 spin_lock(&fs->lock);
66372 current->fs = new_fs;
66373 - if (--fs->users)
66374 + gr_set_chroot_entries(current, &current->fs->root);
66375 + if (atomic_dec_return(&fs->users))
66376 new_fs = NULL;
66377 else
66378 new_fs = fs;
66379 diff --git a/kernel/futex.c b/kernel/futex.c
66380 index 866c9d5..5c5f828 100644
66381 --- a/kernel/futex.c
66382 +++ b/kernel/futex.c
66383 @@ -54,6 +54,7 @@
66384 #include <linux/mount.h>
66385 #include <linux/pagemap.h>
66386 #include <linux/syscalls.h>
66387 +#include <linux/ptrace.h>
66388 #include <linux/signal.h>
66389 #include <linux/export.h>
66390 #include <linux/magic.h>
66391 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66392 struct page *page, *page_head;
66393 int err, ro = 0;
66394
66395 +#ifdef CONFIG_PAX_SEGMEXEC
66396 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66397 + return -EFAULT;
66398 +#endif
66399 +
66400 /*
66401 * The futex address must be "naturally" aligned.
66402 */
66403 @@ -2721,6 +2727,7 @@ static int __init futex_init(void)
66404 {
66405 u32 curval;
66406 int i;
66407 + mm_segment_t oldfs;
66408
66409 /*
66410 * This will fail and we want it. Some arch implementations do
66411 @@ -2732,8 +2739,11 @@ static int __init futex_init(void)
66412 * implementation, the non-functional ones will return
66413 * -ENOSYS.
66414 */
66415 + oldfs = get_fs();
66416 + set_fs(USER_DS);
66417 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66418 futex_cmpxchg_enabled = 1;
66419 + set_fs(oldfs);
66420
66421 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66422 plist_head_init(&futex_queues[i].chain);
66423 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66424 index 9b22d03..6295b62 100644
66425 --- a/kernel/gcov/base.c
66426 +++ b/kernel/gcov/base.c
66427 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66428 }
66429
66430 #ifdef CONFIG_MODULES
66431 -static inline int within(void *addr, void *start, unsigned long size)
66432 -{
66433 - return ((addr >= start) && (addr < start + size));
66434 -}
66435 -
66436 /* Update list and generate events when modules are unloaded. */
66437 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66438 void *data)
66439 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66440 prev = NULL;
66441 /* Remove entries located in module from linked list. */
66442 for (info = gcov_info_head; info; info = info->next) {
66443 - if (within(info, mod->module_core, mod->core_size)) {
66444 + if (within_module_core_rw((unsigned long)info, mod)) {
66445 if (prev)
66446 prev->next = info->next;
66447 else
66448 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66449 index ae34bf5..4e2f3d0 100644
66450 --- a/kernel/hrtimer.c
66451 +++ b/kernel/hrtimer.c
66452 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66453 local_irq_restore(flags);
66454 }
66455
66456 -static void run_hrtimer_softirq(struct softirq_action *h)
66457 +static void run_hrtimer_softirq(void)
66458 {
66459 hrtimer_peek_ahead_timers();
66460 }
66461 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66462 index 01d3b70..9e4d098 100644
66463 --- a/kernel/jump_label.c
66464 +++ b/kernel/jump_label.c
66465 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66466
66467 size = (((unsigned long)stop - (unsigned long)start)
66468 / sizeof(struct jump_entry));
66469 + pax_open_kernel();
66470 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66471 + pax_close_kernel();
66472 }
66473
66474 static void jump_label_update(struct jump_label_key *key, int enable);
66475 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66476 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66477 struct jump_entry *iter;
66478
66479 + pax_open_kernel();
66480 for (iter = iter_start; iter < iter_stop; iter++) {
66481 if (within_module_init(iter->code, mod))
66482 iter->code = 0;
66483 }
66484 + pax_close_kernel();
66485 }
66486
66487 static int
66488 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66489 index 079f1d3..a407562 100644
66490 --- a/kernel/kallsyms.c
66491 +++ b/kernel/kallsyms.c
66492 @@ -11,6 +11,9 @@
66493 * Changed the compression method from stem compression to "table lookup"
66494 * compression (see scripts/kallsyms.c for a more complete description)
66495 */
66496 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66497 +#define __INCLUDED_BY_HIDESYM 1
66498 +#endif
66499 #include <linux/kallsyms.h>
66500 #include <linux/module.h>
66501 #include <linux/init.h>
66502 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66503
66504 static inline int is_kernel_inittext(unsigned long addr)
66505 {
66506 + if (system_state != SYSTEM_BOOTING)
66507 + return 0;
66508 +
66509 if (addr >= (unsigned long)_sinittext
66510 && addr <= (unsigned long)_einittext)
66511 return 1;
66512 return 0;
66513 }
66514
66515 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66516 +#ifdef CONFIG_MODULES
66517 +static inline int is_module_text(unsigned long addr)
66518 +{
66519 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66520 + return 1;
66521 +
66522 + addr = ktla_ktva(addr);
66523 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66524 +}
66525 +#else
66526 +static inline int is_module_text(unsigned long addr)
66527 +{
66528 + return 0;
66529 +}
66530 +#endif
66531 +#endif
66532 +
66533 static inline int is_kernel_text(unsigned long addr)
66534 {
66535 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66536 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66537
66538 static inline int is_kernel(unsigned long addr)
66539 {
66540 +
66541 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66542 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66543 + return 1;
66544 +
66545 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66546 +#else
66547 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66548 +#endif
66549 +
66550 return 1;
66551 return in_gate_area_no_mm(addr);
66552 }
66553
66554 static int is_ksym_addr(unsigned long addr)
66555 {
66556 +
66557 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66558 + if (is_module_text(addr))
66559 + return 0;
66560 +#endif
66561 +
66562 if (all_var)
66563 return is_kernel(addr);
66564
66565 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66566
66567 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66568 {
66569 - iter->name[0] = '\0';
66570 iter->nameoff = get_symbol_offset(new_pos);
66571 iter->pos = new_pos;
66572 }
66573 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66574 {
66575 struct kallsym_iter *iter = m->private;
66576
66577 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66578 + if (current_uid())
66579 + return 0;
66580 +#endif
66581 +
66582 /* Some debugging symbols have no name. Ignore them. */
66583 if (!iter->name[0])
66584 return 0;
66585 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66586 struct kallsym_iter *iter;
66587 int ret;
66588
66589 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66590 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66591 if (!iter)
66592 return -ENOMEM;
66593 reset_iter(iter, 0);
66594 diff --git a/kernel/kexec.c b/kernel/kexec.c
66595 index 7b08867..3bac516 100644
66596 --- a/kernel/kexec.c
66597 +++ b/kernel/kexec.c
66598 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66599 unsigned long flags)
66600 {
66601 struct compat_kexec_segment in;
66602 - struct kexec_segment out, __user *ksegments;
66603 + struct kexec_segment out;
66604 + struct kexec_segment __user *ksegments;
66605 unsigned long i, result;
66606
66607 /* Don't allow clients that don't understand the native
66608 diff --git a/kernel/kmod.c b/kernel/kmod.c
66609 index a3a46cb..f2e42f8 100644
66610 --- a/kernel/kmod.c
66611 +++ b/kernel/kmod.c
66612 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66613 * If module auto-loading support is disabled then this function
66614 * becomes a no-operation.
66615 */
66616 -int __request_module(bool wait, const char *fmt, ...)
66617 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66618 {
66619 - va_list args;
66620 char module_name[MODULE_NAME_LEN];
66621 unsigned int max_modprobes;
66622 int ret;
66623 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66624 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66625 static char *envp[] = { "HOME=/",
66626 "TERM=linux",
66627 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66628 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
66629 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66630 static int kmod_loop_msg;
66631
66632 - va_start(args, fmt);
66633 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66634 - va_end(args);
66635 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66636 if (ret >= MODULE_NAME_LEN)
66637 return -ENAMETOOLONG;
66638
66639 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
66640 if (ret)
66641 return ret;
66642
66643 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66644 + if (!current_uid()) {
66645 + /* hack to workaround consolekit/udisks stupidity */
66646 + read_lock(&tasklist_lock);
66647 + if (!strcmp(current->comm, "mount") &&
66648 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66649 + read_unlock(&tasklist_lock);
66650 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66651 + return -EPERM;
66652 + }
66653 + read_unlock(&tasklist_lock);
66654 + }
66655 +#endif
66656 +
66657 /* If modprobe needs a service that is in a module, we get a recursive
66658 * loop. Limit the number of running kmod threads to max_threads/2 or
66659 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66660 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
66661 atomic_dec(&kmod_concurrent);
66662 return ret;
66663 }
66664 +
66665 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66666 +{
66667 + va_list args;
66668 + int ret;
66669 +
66670 + va_start(args, fmt);
66671 + ret = ____request_module(wait, module_param, fmt, args);
66672 + va_end(args);
66673 +
66674 + return ret;
66675 +}
66676 +
66677 +int __request_module(bool wait, const char *fmt, ...)
66678 +{
66679 + va_list args;
66680 + int ret;
66681 +
66682 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66683 + if (current_uid()) {
66684 + char module_param[MODULE_NAME_LEN];
66685 +
66686 + memset(module_param, 0, sizeof(module_param));
66687 +
66688 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66689 +
66690 + va_start(args, fmt);
66691 + ret = ____request_module(wait, module_param, fmt, args);
66692 + va_end(args);
66693 +
66694 + return ret;
66695 + }
66696 +#endif
66697 +
66698 + va_start(args, fmt);
66699 + ret = ____request_module(wait, NULL, fmt, args);
66700 + va_end(args);
66701 +
66702 + return ret;
66703 +}
66704 +
66705 EXPORT_SYMBOL(__request_module);
66706 #endif /* CONFIG_MODULES */
66707
66708 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
66709 *
66710 * Thus the __user pointer cast is valid here.
66711 */
66712 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66713 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66714
66715 /*
66716 * If ret is 0, either ____call_usermodehelper failed and the
66717 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66718 index c62b854..cb67968 100644
66719 --- a/kernel/kprobes.c
66720 +++ b/kernel/kprobes.c
66721 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66722 * kernel image and loaded module images reside. This is required
66723 * so x86_64 can correctly handle the %rip-relative fixups.
66724 */
66725 - kip->insns = module_alloc(PAGE_SIZE);
66726 + kip->insns = module_alloc_exec(PAGE_SIZE);
66727 if (!kip->insns) {
66728 kfree(kip);
66729 return NULL;
66730 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66731 */
66732 if (!list_is_singular(&kip->list)) {
66733 list_del(&kip->list);
66734 - module_free(NULL, kip->insns);
66735 + module_free_exec(NULL, kip->insns);
66736 kfree(kip);
66737 }
66738 return 1;
66739 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66740 {
66741 int i, err = 0;
66742 unsigned long offset = 0, size = 0;
66743 - char *modname, namebuf[128];
66744 + char *modname, namebuf[KSYM_NAME_LEN];
66745 const char *symbol_name;
66746 void *addr;
66747 struct kprobe_blackpoint *kb;
66748 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66749 const char *sym = NULL;
66750 unsigned int i = *(loff_t *) v;
66751 unsigned long offset = 0;
66752 - char *modname, namebuf[128];
66753 + char *modname, namebuf[KSYM_NAME_LEN];
66754
66755 head = &kprobe_table[i];
66756 preempt_disable();
66757 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66758 index 4e316e1..5501eef 100644
66759 --- a/kernel/ksysfs.c
66760 +++ b/kernel/ksysfs.c
66761 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66762 {
66763 if (count+1 > UEVENT_HELPER_PATH_LEN)
66764 return -ENOENT;
66765 + if (!capable(CAP_SYS_ADMIN))
66766 + return -EPERM;
66767 memcpy(uevent_helper, buf, count);
66768 uevent_helper[count] = '\0';
66769 if (count && uevent_helper[count-1] == '\n')
66770 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66771 index 8889f7d..95319b7 100644
66772 --- a/kernel/lockdep.c
66773 +++ b/kernel/lockdep.c
66774 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66775 end = (unsigned long) &_end,
66776 addr = (unsigned long) obj;
66777
66778 +#ifdef CONFIG_PAX_KERNEXEC
66779 + start = ktla_ktva(start);
66780 +#endif
66781 +
66782 /*
66783 * static variable?
66784 */
66785 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66786 if (!static_obj(lock->key)) {
66787 debug_locks_off();
66788 printk("INFO: trying to register non-static key.\n");
66789 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66790 printk("the code is fine but needs lockdep annotation.\n");
66791 printk("turning off the locking correctness validator.\n");
66792 dump_stack();
66793 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66794 if (!class)
66795 return 0;
66796 }
66797 - atomic_inc((atomic_t *)&class->ops);
66798 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66799 if (very_verbose(class)) {
66800 printk("\nacquire class [%p] %s", class->key, class->name);
66801 if (class->name_version > 1)
66802 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66803 index 91c32a0..b2c71c5 100644
66804 --- a/kernel/lockdep_proc.c
66805 +++ b/kernel/lockdep_proc.c
66806 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66807
66808 static void print_name(struct seq_file *m, struct lock_class *class)
66809 {
66810 - char str[128];
66811 + char str[KSYM_NAME_LEN];
66812 const char *name = class->name;
66813
66814 if (!name) {
66815 diff --git a/kernel/module.c b/kernel/module.c
66816 index 3d56b6f..2a22bd0 100644
66817 --- a/kernel/module.c
66818 +++ b/kernel/module.c
66819 @@ -58,6 +58,7 @@
66820 #include <linux/jump_label.h>
66821 #include <linux/pfn.h>
66822 #include <linux/bsearch.h>
66823 +#include <linux/grsecurity.h>
66824
66825 #define CREATE_TRACE_POINTS
66826 #include <trace/events/module.h>
66827 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66828
66829 /* Bounds of module allocation, for speeding __module_address.
66830 * Protected by module_mutex. */
66831 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66832 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66833 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66834
66835 int register_module_notifier(struct notifier_block * nb)
66836 {
66837 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66838 return true;
66839
66840 list_for_each_entry_rcu(mod, &modules, list) {
66841 - struct symsearch arr[] = {
66842 + struct symsearch modarr[] = {
66843 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66844 NOT_GPL_ONLY, false },
66845 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66846 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66847 #endif
66848 };
66849
66850 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66851 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66852 return true;
66853 }
66854 return false;
66855 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66856 static int percpu_modalloc(struct module *mod,
66857 unsigned long size, unsigned long align)
66858 {
66859 - if (align > PAGE_SIZE) {
66860 + if (align-1 >= PAGE_SIZE) {
66861 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66862 mod->name, align, PAGE_SIZE);
66863 align = PAGE_SIZE;
66864 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
66865 static ssize_t show_coresize(struct module_attribute *mattr,
66866 struct module_kobject *mk, char *buffer)
66867 {
66868 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66869 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66870 }
66871
66872 static struct module_attribute modinfo_coresize =
66873 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
66874 static ssize_t show_initsize(struct module_attribute *mattr,
66875 struct module_kobject *mk, char *buffer)
66876 {
66877 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66878 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66879 }
66880
66881 static struct module_attribute modinfo_initsize =
66882 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
66883 */
66884 #ifdef CONFIG_SYSFS
66885
66886 -#ifdef CONFIG_KALLSYMS
66887 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66888 static inline bool sect_empty(const Elf_Shdr *sect)
66889 {
66890 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66891 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
66892
66893 static void unset_module_core_ro_nx(struct module *mod)
66894 {
66895 - set_page_attributes(mod->module_core + mod->core_text_size,
66896 - mod->module_core + mod->core_size,
66897 + set_page_attributes(mod->module_core_rw,
66898 + mod->module_core_rw + mod->core_size_rw,
66899 set_memory_x);
66900 - set_page_attributes(mod->module_core,
66901 - mod->module_core + mod->core_ro_size,
66902 + set_page_attributes(mod->module_core_rx,
66903 + mod->module_core_rx + mod->core_size_rx,
66904 set_memory_rw);
66905 }
66906
66907 static void unset_module_init_ro_nx(struct module *mod)
66908 {
66909 - set_page_attributes(mod->module_init + mod->init_text_size,
66910 - mod->module_init + mod->init_size,
66911 + set_page_attributes(mod->module_init_rw,
66912 + mod->module_init_rw + mod->init_size_rw,
66913 set_memory_x);
66914 - set_page_attributes(mod->module_init,
66915 - mod->module_init + mod->init_ro_size,
66916 + set_page_attributes(mod->module_init_rx,
66917 + mod->module_init_rx + mod->init_size_rx,
66918 set_memory_rw);
66919 }
66920
66921 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
66922
66923 mutex_lock(&module_mutex);
66924 list_for_each_entry_rcu(mod, &modules, list) {
66925 - if ((mod->module_core) && (mod->core_text_size)) {
66926 - set_page_attributes(mod->module_core,
66927 - mod->module_core + mod->core_text_size,
66928 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66929 + set_page_attributes(mod->module_core_rx,
66930 + mod->module_core_rx + mod->core_size_rx,
66931 set_memory_rw);
66932 }
66933 - if ((mod->module_init) && (mod->init_text_size)) {
66934 - set_page_attributes(mod->module_init,
66935 - mod->module_init + mod->init_text_size,
66936 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66937 + set_page_attributes(mod->module_init_rx,
66938 + mod->module_init_rx + mod->init_size_rx,
66939 set_memory_rw);
66940 }
66941 }
66942 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
66943
66944 mutex_lock(&module_mutex);
66945 list_for_each_entry_rcu(mod, &modules, list) {
66946 - if ((mod->module_core) && (mod->core_text_size)) {
66947 - set_page_attributes(mod->module_core,
66948 - mod->module_core + mod->core_text_size,
66949 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66950 + set_page_attributes(mod->module_core_rx,
66951 + mod->module_core_rx + mod->core_size_rx,
66952 set_memory_ro);
66953 }
66954 - if ((mod->module_init) && (mod->init_text_size)) {
66955 - set_page_attributes(mod->module_init,
66956 - mod->module_init + mod->init_text_size,
66957 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66958 + set_page_attributes(mod->module_init_rx,
66959 + mod->module_init_rx + mod->init_size_rx,
66960 set_memory_ro);
66961 }
66962 }
66963 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
66964
66965 /* This may be NULL, but that's OK */
66966 unset_module_init_ro_nx(mod);
66967 - module_free(mod, mod->module_init);
66968 + module_free(mod, mod->module_init_rw);
66969 + module_free_exec(mod, mod->module_init_rx);
66970 kfree(mod->args);
66971 percpu_modfree(mod);
66972
66973 /* Free lock-classes: */
66974 - lockdep_free_key_range(mod->module_core, mod->core_size);
66975 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66976 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66977
66978 /* Finally, free the core (containing the module structure) */
66979 unset_module_core_ro_nx(mod);
66980 - module_free(mod, mod->module_core);
66981 + module_free_exec(mod, mod->module_core_rx);
66982 + module_free(mod, mod->module_core_rw);
66983
66984 #ifdef CONFIG_MPU
66985 update_protections(current->mm);
66986 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66987 unsigned int i;
66988 int ret = 0;
66989 const struct kernel_symbol *ksym;
66990 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66991 + int is_fs_load = 0;
66992 + int register_filesystem_found = 0;
66993 + char *p;
66994 +
66995 + p = strstr(mod->args, "grsec_modharden_fs");
66996 + if (p) {
66997 + char *endptr = p + strlen("grsec_modharden_fs");
66998 + /* copy \0 as well */
66999 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67000 + is_fs_load = 1;
67001 + }
67002 +#endif
67003
67004 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67005 const char *name = info->strtab + sym[i].st_name;
67006
67007 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67008 + /* it's a real shame this will never get ripped and copied
67009 + upstream! ;(
67010 + */
67011 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67012 + register_filesystem_found = 1;
67013 +#endif
67014 +
67015 switch (sym[i].st_shndx) {
67016 case SHN_COMMON:
67017 /* We compiled with -fno-common. These are not
67018 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67019 ksym = resolve_symbol_wait(mod, info, name);
67020 /* Ok if resolved. */
67021 if (ksym && !IS_ERR(ksym)) {
67022 + pax_open_kernel();
67023 sym[i].st_value = ksym->value;
67024 + pax_close_kernel();
67025 break;
67026 }
67027
67028 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67029 secbase = (unsigned long)mod_percpu(mod);
67030 else
67031 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67032 + pax_open_kernel();
67033 sym[i].st_value += secbase;
67034 + pax_close_kernel();
67035 break;
67036 }
67037 }
67038
67039 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67040 + if (is_fs_load && !register_filesystem_found) {
67041 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67042 + ret = -EPERM;
67043 + }
67044 +#endif
67045 +
67046 return ret;
67047 }
67048
67049 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67050 || s->sh_entsize != ~0UL
67051 || strstarts(sname, ".init"))
67052 continue;
67053 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67054 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67055 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67056 + else
67057 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67058 pr_debug("\t%s\n", sname);
67059 }
67060 - switch (m) {
67061 - case 0: /* executable */
67062 - mod->core_size = debug_align(mod->core_size);
67063 - mod->core_text_size = mod->core_size;
67064 - break;
67065 - case 1: /* RO: text and ro-data */
67066 - mod->core_size = debug_align(mod->core_size);
67067 - mod->core_ro_size = mod->core_size;
67068 - break;
67069 - case 3: /* whole core */
67070 - mod->core_size = debug_align(mod->core_size);
67071 - break;
67072 - }
67073 }
67074
67075 pr_debug("Init section allocation order:\n");
67076 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67077 || s->sh_entsize != ~0UL
67078 || !strstarts(sname, ".init"))
67079 continue;
67080 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67081 - | INIT_OFFSET_MASK);
67082 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67083 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67084 + else
67085 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67086 + s->sh_entsize |= INIT_OFFSET_MASK;
67087 pr_debug("\t%s\n", sname);
67088 }
67089 - switch (m) {
67090 - case 0: /* executable */
67091 - mod->init_size = debug_align(mod->init_size);
67092 - mod->init_text_size = mod->init_size;
67093 - break;
67094 - case 1: /* RO: text and ro-data */
67095 - mod->init_size = debug_align(mod->init_size);
67096 - mod->init_ro_size = mod->init_size;
67097 - break;
67098 - case 3: /* whole init */
67099 - mod->init_size = debug_align(mod->init_size);
67100 - break;
67101 - }
67102 }
67103 }
67104
67105 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67106
67107 /* Put symbol section at end of init part of module. */
67108 symsect->sh_flags |= SHF_ALLOC;
67109 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67110 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67111 info->index.sym) | INIT_OFFSET_MASK;
67112 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67113
67114 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67115 }
67116
67117 /* Append room for core symbols at end of core part. */
67118 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67119 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67120 - mod->core_size += strtab_size;
67121 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67122 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67123 + mod->core_size_rx += strtab_size;
67124
67125 /* Put string table section at end of init part of module. */
67126 strsect->sh_flags |= SHF_ALLOC;
67127 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67128 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67129 info->index.str) | INIT_OFFSET_MASK;
67130 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67131 }
67132 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67133 /* Make sure we get permanent strtab: don't use info->strtab. */
67134 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67135
67136 + pax_open_kernel();
67137 +
67138 /* Set types up while we still have access to sections. */
67139 for (i = 0; i < mod->num_symtab; i++)
67140 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67141
67142 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67143 - mod->core_strtab = s = mod->module_core + info->stroffs;
67144 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67145 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67146 src = mod->symtab;
67147 *dst = *src;
67148 *s++ = 0;
67149 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67150 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67151 }
67152 mod->core_num_syms = ndst;
67153 +
67154 + pax_close_kernel();
67155 }
67156 #else
67157 static inline void layout_symtab(struct module *mod, struct load_info *info)
67158 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67159 return size == 0 ? NULL : vmalloc_exec(size);
67160 }
67161
67162 -static void *module_alloc_update_bounds(unsigned long size)
67163 +static void *module_alloc_update_bounds_rw(unsigned long size)
67164 {
67165 void *ret = module_alloc(size);
67166
67167 if (ret) {
67168 mutex_lock(&module_mutex);
67169 /* Update module bounds. */
67170 - if ((unsigned long)ret < module_addr_min)
67171 - module_addr_min = (unsigned long)ret;
67172 - if ((unsigned long)ret + size > module_addr_max)
67173 - module_addr_max = (unsigned long)ret + size;
67174 + if ((unsigned long)ret < module_addr_min_rw)
67175 + module_addr_min_rw = (unsigned long)ret;
67176 + if ((unsigned long)ret + size > module_addr_max_rw)
67177 + module_addr_max_rw = (unsigned long)ret + size;
67178 + mutex_unlock(&module_mutex);
67179 + }
67180 + return ret;
67181 +}
67182 +
67183 +static void *module_alloc_update_bounds_rx(unsigned long size)
67184 +{
67185 + void *ret = module_alloc_exec(size);
67186 +
67187 + if (ret) {
67188 + mutex_lock(&module_mutex);
67189 + /* Update module bounds. */
67190 + if ((unsigned long)ret < module_addr_min_rx)
67191 + module_addr_min_rx = (unsigned long)ret;
67192 + if ((unsigned long)ret + size > module_addr_max_rx)
67193 + module_addr_max_rx = (unsigned long)ret + size;
67194 mutex_unlock(&module_mutex);
67195 }
67196 return ret;
67197 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67198 static int check_modinfo(struct module *mod, struct load_info *info)
67199 {
67200 const char *modmagic = get_modinfo(info, "vermagic");
67201 + const char *license = get_modinfo(info, "license");
67202 int err;
67203
67204 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67205 + if (!license || !license_is_gpl_compatible(license))
67206 + return -ENOEXEC;
67207 +#endif
67208 +
67209 /* This is allowed: modprobe --force will invalidate it. */
67210 if (!modmagic) {
67211 err = try_to_force_load(mod, "bad vermagic");
67212 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67213 }
67214
67215 /* Set up license info based on the info section */
67216 - set_license(mod, get_modinfo(info, "license"));
67217 + set_license(mod, license);
67218
67219 return 0;
67220 }
67221 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67222 void *ptr;
67223
67224 /* Do the allocs. */
67225 - ptr = module_alloc_update_bounds(mod->core_size);
67226 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67227 /*
67228 * The pointer to this block is stored in the module structure
67229 * which is inside the block. Just mark it as not being a
67230 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67231 if (!ptr)
67232 return -ENOMEM;
67233
67234 - memset(ptr, 0, mod->core_size);
67235 - mod->module_core = ptr;
67236 + memset(ptr, 0, mod->core_size_rw);
67237 + mod->module_core_rw = ptr;
67238
67239 - ptr = module_alloc_update_bounds(mod->init_size);
67240 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67241 /*
67242 * The pointer to this block is stored in the module structure
67243 * which is inside the block. This block doesn't need to be
67244 * scanned as it contains data and code that will be freed
67245 * after the module is initialized.
67246 */
67247 - kmemleak_ignore(ptr);
67248 - if (!ptr && mod->init_size) {
67249 - module_free(mod, mod->module_core);
67250 + kmemleak_not_leak(ptr);
67251 + if (!ptr && mod->init_size_rw) {
67252 + module_free(mod, mod->module_core_rw);
67253 return -ENOMEM;
67254 }
67255 - memset(ptr, 0, mod->init_size);
67256 - mod->module_init = ptr;
67257 + memset(ptr, 0, mod->init_size_rw);
67258 + mod->module_init_rw = ptr;
67259 +
67260 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67261 + kmemleak_not_leak(ptr);
67262 + if (!ptr) {
67263 + module_free(mod, mod->module_init_rw);
67264 + module_free(mod, mod->module_core_rw);
67265 + return -ENOMEM;
67266 + }
67267 +
67268 + pax_open_kernel();
67269 + memset(ptr, 0, mod->core_size_rx);
67270 + pax_close_kernel();
67271 + mod->module_core_rx = ptr;
67272 +
67273 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67274 + kmemleak_not_leak(ptr);
67275 + if (!ptr && mod->init_size_rx) {
67276 + module_free_exec(mod, mod->module_core_rx);
67277 + module_free(mod, mod->module_init_rw);
67278 + module_free(mod, mod->module_core_rw);
67279 + return -ENOMEM;
67280 + }
67281 +
67282 + pax_open_kernel();
67283 + memset(ptr, 0, mod->init_size_rx);
67284 + pax_close_kernel();
67285 + mod->module_init_rx = ptr;
67286
67287 /* Transfer each section which specifies SHF_ALLOC */
67288 pr_debug("final section addresses:\n");
67289 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67290 if (!(shdr->sh_flags & SHF_ALLOC))
67291 continue;
67292
67293 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67294 - dest = mod->module_init
67295 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67296 - else
67297 - dest = mod->module_core + shdr->sh_entsize;
67298 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67299 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67300 + dest = mod->module_init_rw
67301 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67302 + else
67303 + dest = mod->module_init_rx
67304 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67305 + } else {
67306 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67307 + dest = mod->module_core_rw + shdr->sh_entsize;
67308 + else
67309 + dest = mod->module_core_rx + shdr->sh_entsize;
67310 + }
67311 +
67312 + if (shdr->sh_type != SHT_NOBITS) {
67313 +
67314 +#ifdef CONFIG_PAX_KERNEXEC
67315 +#ifdef CONFIG_X86_64
67316 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67317 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67318 +#endif
67319 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67320 + pax_open_kernel();
67321 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67322 + pax_close_kernel();
67323 + } else
67324 +#endif
67325
67326 - if (shdr->sh_type != SHT_NOBITS)
67327 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67328 + }
67329 /* Update sh_addr to point to copy in image. */
67330 - shdr->sh_addr = (unsigned long)dest;
67331 +
67332 +#ifdef CONFIG_PAX_KERNEXEC
67333 + if (shdr->sh_flags & SHF_EXECINSTR)
67334 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67335 + else
67336 +#endif
67337 +
67338 + shdr->sh_addr = (unsigned long)dest;
67339 pr_debug("\t0x%lx %s\n",
67340 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67341 }
67342 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67343 * Do it before processing of module parameters, so the module
67344 * can provide parameter accessor functions of its own.
67345 */
67346 - if (mod->module_init)
67347 - flush_icache_range((unsigned long)mod->module_init,
67348 - (unsigned long)mod->module_init
67349 - + mod->init_size);
67350 - flush_icache_range((unsigned long)mod->module_core,
67351 - (unsigned long)mod->module_core + mod->core_size);
67352 + if (mod->module_init_rx)
67353 + flush_icache_range((unsigned long)mod->module_init_rx,
67354 + (unsigned long)mod->module_init_rx
67355 + + mod->init_size_rx);
67356 + flush_icache_range((unsigned long)mod->module_core_rx,
67357 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67358
67359 set_fs(old_fs);
67360 }
67361 @@ -2802,8 +2901,10 @@ out:
67362 static void module_deallocate(struct module *mod, struct load_info *info)
67363 {
67364 percpu_modfree(mod);
67365 - module_free(mod, mod->module_init);
67366 - module_free(mod, mod->module_core);
67367 + module_free_exec(mod, mod->module_init_rx);
67368 + module_free_exec(mod, mod->module_core_rx);
67369 + module_free(mod, mod->module_init_rw);
67370 + module_free(mod, mod->module_core_rw);
67371 }
67372
67373 int __weak module_finalize(const Elf_Ehdr *hdr,
67374 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67375 if (err)
67376 goto free_unload;
67377
67378 + /* Now copy in args */
67379 + mod->args = strndup_user(uargs, ~0UL >> 1);
67380 + if (IS_ERR(mod->args)) {
67381 + err = PTR_ERR(mod->args);
67382 + goto free_unload;
67383 + }
67384 +
67385 /* Set up MODINFO_ATTR fields */
67386 setup_modinfo(mod, &info);
67387
67388 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67389 + {
67390 + char *p, *p2;
67391 +
67392 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67393 + 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);
67394 + err = -EPERM;
67395 + goto free_modinfo;
67396 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67397 + p += strlen("grsec_modharden_normal");
67398 + p2 = strstr(p, "_");
67399 + if (p2) {
67400 + *p2 = '\0';
67401 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67402 + *p2 = '_';
67403 + }
67404 + err = -EPERM;
67405 + goto free_modinfo;
67406 + }
67407 + }
67408 +#endif
67409 +
67410 /* Fix up syms, so that st_value is a pointer to location. */
67411 err = simplify_symbols(mod, &info);
67412 if (err < 0)
67413 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67414
67415 flush_module_icache(mod);
67416
67417 - /* Now copy in args */
67418 - mod->args = strndup_user(uargs, ~0UL >> 1);
67419 - if (IS_ERR(mod->args)) {
67420 - err = PTR_ERR(mod->args);
67421 - goto free_arch_cleanup;
67422 - }
67423 -
67424 /* Mark state as coming so strong_try_module_get() ignores us. */
67425 mod->state = MODULE_STATE_COMING;
67426
67427 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67428 unlock:
67429 mutex_unlock(&module_mutex);
67430 synchronize_sched();
67431 - kfree(mod->args);
67432 - free_arch_cleanup:
67433 module_arch_cleanup(mod);
67434 free_modinfo:
67435 free_modinfo(mod);
67436 + kfree(mod->args);
67437 free_unload:
67438 module_unload_free(mod);
67439 free_module:
67440 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67441 MODULE_STATE_COMING, mod);
67442
67443 /* Set RO and NX regions for core */
67444 - set_section_ro_nx(mod->module_core,
67445 - mod->core_text_size,
67446 - mod->core_ro_size,
67447 - mod->core_size);
67448 + set_section_ro_nx(mod->module_core_rx,
67449 + mod->core_size_rx,
67450 + mod->core_size_rx,
67451 + mod->core_size_rx);
67452
67453 /* Set RO and NX regions for init */
67454 - set_section_ro_nx(mod->module_init,
67455 - mod->init_text_size,
67456 - mod->init_ro_size,
67457 - mod->init_size);
67458 + set_section_ro_nx(mod->module_init_rx,
67459 + mod->init_size_rx,
67460 + mod->init_size_rx,
67461 + mod->init_size_rx);
67462
67463 do_mod_ctors(mod);
67464 /* Start the module */
67465 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67466 mod->strtab = mod->core_strtab;
67467 #endif
67468 unset_module_init_ro_nx(mod);
67469 - module_free(mod, mod->module_init);
67470 - mod->module_init = NULL;
67471 - mod->init_size = 0;
67472 - mod->init_ro_size = 0;
67473 - mod->init_text_size = 0;
67474 + module_free(mod, mod->module_init_rw);
67475 + module_free_exec(mod, mod->module_init_rx);
67476 + mod->module_init_rw = NULL;
67477 + mod->module_init_rx = NULL;
67478 + mod->init_size_rw = 0;
67479 + mod->init_size_rx = 0;
67480 mutex_unlock(&module_mutex);
67481
67482 return 0;
67483 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67484 unsigned long nextval;
67485
67486 /* At worse, next value is at end of module */
67487 - if (within_module_init(addr, mod))
67488 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67489 + if (within_module_init_rx(addr, mod))
67490 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67491 + else if (within_module_init_rw(addr, mod))
67492 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67493 + else if (within_module_core_rx(addr, mod))
67494 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67495 + else if (within_module_core_rw(addr, mod))
67496 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67497 else
67498 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67499 + return NULL;
67500
67501 /* Scan for closest preceding symbol, and next symbol. (ELF
67502 starts real symbols at 1). */
67503 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67504 char buf[8];
67505
67506 seq_printf(m, "%s %u",
67507 - mod->name, mod->init_size + mod->core_size);
67508 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67509 print_unload_info(m, mod);
67510
67511 /* Informative for users. */
67512 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67513 mod->state == MODULE_STATE_COMING ? "Loading":
67514 "Live");
67515 /* Used by oprofile and other similar tools. */
67516 - seq_printf(m, " 0x%pK", mod->module_core);
67517 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67518
67519 /* Taints info */
67520 if (mod->taints)
67521 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67522
67523 static int __init proc_modules_init(void)
67524 {
67525 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67526 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67527 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67528 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67529 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67530 +#else
67531 proc_create("modules", 0, NULL, &proc_modules_operations);
67532 +#endif
67533 +#else
67534 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67535 +#endif
67536 return 0;
67537 }
67538 module_init(proc_modules_init);
67539 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67540 {
67541 struct module *mod;
67542
67543 - if (addr < module_addr_min || addr > module_addr_max)
67544 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67545 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67546 return NULL;
67547
67548 list_for_each_entry_rcu(mod, &modules, list)
67549 - if (within_module_core(addr, mod)
67550 - || within_module_init(addr, mod))
67551 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67552 return mod;
67553 return NULL;
67554 }
67555 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67556 */
67557 struct module *__module_text_address(unsigned long addr)
67558 {
67559 - struct module *mod = __module_address(addr);
67560 + struct module *mod;
67561 +
67562 +#ifdef CONFIG_X86_32
67563 + addr = ktla_ktva(addr);
67564 +#endif
67565 +
67566 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67567 + return NULL;
67568 +
67569 + mod = __module_address(addr);
67570 +
67571 if (mod) {
67572 /* Make sure it's within the text section. */
67573 - if (!within(addr, mod->module_init, mod->init_text_size)
67574 - && !within(addr, mod->module_core, mod->core_text_size))
67575 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67576 mod = NULL;
67577 }
67578 return mod;
67579 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67580 index 7e3443f..b2a1e6b 100644
67581 --- a/kernel/mutex-debug.c
67582 +++ b/kernel/mutex-debug.c
67583 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67584 }
67585
67586 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67587 - struct thread_info *ti)
67588 + struct task_struct *task)
67589 {
67590 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67591
67592 /* Mark the current thread as blocked on the lock: */
67593 - ti->task->blocked_on = waiter;
67594 + task->blocked_on = waiter;
67595 }
67596
67597 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67598 - struct thread_info *ti)
67599 + struct task_struct *task)
67600 {
67601 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67602 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67603 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67604 - ti->task->blocked_on = NULL;
67605 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67606 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67607 + task->blocked_on = NULL;
67608
67609 list_del_init(&waiter->list);
67610 waiter->task = NULL;
67611 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67612 index 0799fd3..d06ae3b 100644
67613 --- a/kernel/mutex-debug.h
67614 +++ b/kernel/mutex-debug.h
67615 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67616 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67617 extern void debug_mutex_add_waiter(struct mutex *lock,
67618 struct mutex_waiter *waiter,
67619 - struct thread_info *ti);
67620 + struct task_struct *task);
67621 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67622 - struct thread_info *ti);
67623 + struct task_struct *task);
67624 extern void debug_mutex_unlock(struct mutex *lock);
67625 extern void debug_mutex_init(struct mutex *lock, const char *name,
67626 struct lock_class_key *key);
67627 diff --git a/kernel/mutex.c b/kernel/mutex.c
67628 index 89096dd..f91ebc5 100644
67629 --- a/kernel/mutex.c
67630 +++ b/kernel/mutex.c
67631 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67632 spin_lock_mutex(&lock->wait_lock, flags);
67633
67634 debug_mutex_lock_common(lock, &waiter);
67635 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67636 + debug_mutex_add_waiter(lock, &waiter, task);
67637
67638 /* add waiting tasks to the end of the waitqueue (FIFO): */
67639 list_add_tail(&waiter.list, &lock->wait_list);
67640 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67641 * TASK_UNINTERRUPTIBLE case.)
67642 */
67643 if (unlikely(signal_pending_state(state, task))) {
67644 - mutex_remove_waiter(lock, &waiter,
67645 - task_thread_info(task));
67646 + mutex_remove_waiter(lock, &waiter, task);
67647 mutex_release(&lock->dep_map, 1, ip);
67648 spin_unlock_mutex(&lock->wait_lock, flags);
67649
67650 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67651 done:
67652 lock_acquired(&lock->dep_map, ip);
67653 /* got the lock - rejoice! */
67654 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67655 + mutex_remove_waiter(lock, &waiter, task);
67656 mutex_set_owner(lock);
67657
67658 /* set it to 0 if there are no waiters left: */
67659 diff --git a/kernel/padata.c b/kernel/padata.c
67660 index b452599..5d68f4e 100644
67661 --- a/kernel/padata.c
67662 +++ b/kernel/padata.c
67663 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67664 padata->pd = pd;
67665 padata->cb_cpu = cb_cpu;
67666
67667 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67668 - atomic_set(&pd->seq_nr, -1);
67669 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67670 + atomic_set_unchecked(&pd->seq_nr, -1);
67671
67672 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67673 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67674
67675 target_cpu = padata_cpu_hash(padata);
67676 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67677 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67678 padata_init_pqueues(pd);
67679 padata_init_squeues(pd);
67680 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67681 - atomic_set(&pd->seq_nr, -1);
67682 + atomic_set_unchecked(&pd->seq_nr, -1);
67683 atomic_set(&pd->reorder_objects, 0);
67684 atomic_set(&pd->refcnt, 0);
67685 pd->pinst = pinst;
67686 diff --git a/kernel/panic.c b/kernel/panic.c
67687 index 8ed89a1..e83856a 100644
67688 --- a/kernel/panic.c
67689 +++ b/kernel/panic.c
67690 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67691 const char *board;
67692
67693 printk(KERN_WARNING "------------[ cut here ]------------\n");
67694 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67695 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67696 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67697 if (board)
67698 printk(KERN_WARNING "Hardware name: %s\n", board);
67699 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67700 */
67701 void __stack_chk_fail(void)
67702 {
67703 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67704 + dump_stack();
67705 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67706 __builtin_return_address(0));
67707 }
67708 EXPORT_SYMBOL(__stack_chk_fail);
67709 diff --git a/kernel/pid.c b/kernel/pid.c
67710 index 9f08dfa..6765c40 100644
67711 --- a/kernel/pid.c
67712 +++ b/kernel/pid.c
67713 @@ -33,6 +33,7 @@
67714 #include <linux/rculist.h>
67715 #include <linux/bootmem.h>
67716 #include <linux/hash.h>
67717 +#include <linux/security.h>
67718 #include <linux/pid_namespace.h>
67719 #include <linux/init_task.h>
67720 #include <linux/syscalls.h>
67721 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67722
67723 int pid_max = PID_MAX_DEFAULT;
67724
67725 -#define RESERVED_PIDS 300
67726 +#define RESERVED_PIDS 500
67727
67728 int pid_max_min = RESERVED_PIDS + 1;
67729 int pid_max_max = PID_MAX_LIMIT;
67730 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67731 */
67732 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67733 {
67734 + struct task_struct *task;
67735 +
67736 rcu_lockdep_assert(rcu_read_lock_held(),
67737 "find_task_by_pid_ns() needs rcu_read_lock()"
67738 " protection");
67739 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67740 +
67741 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67742 +
67743 + if (gr_pid_is_chrooted(task))
67744 + return NULL;
67745 +
67746 + return task;
67747 }
67748
67749 struct task_struct *find_task_by_vpid(pid_t vnr)
67750 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67751 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67752 }
67753
67754 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67755 +{
67756 + rcu_lockdep_assert(rcu_read_lock_held(),
67757 + "find_task_by_pid_ns() needs rcu_read_lock()"
67758 + " protection");
67759 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67760 +}
67761 +
67762 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67763 {
67764 struct pid *pid;
67765 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67766 index 125cb67..a4d1c30 100644
67767 --- a/kernel/posix-cpu-timers.c
67768 +++ b/kernel/posix-cpu-timers.c
67769 @@ -6,6 +6,7 @@
67770 #include <linux/posix-timers.h>
67771 #include <linux/errno.h>
67772 #include <linux/math64.h>
67773 +#include <linux/security.h>
67774 #include <asm/uaccess.h>
67775 #include <linux/kernel_stat.h>
67776 #include <trace/events/timer.h>
67777 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67778
67779 static __init int init_posix_cpu_timers(void)
67780 {
67781 - struct k_clock process = {
67782 + static struct k_clock process = {
67783 .clock_getres = process_cpu_clock_getres,
67784 .clock_get = process_cpu_clock_get,
67785 .timer_create = process_cpu_timer_create,
67786 .nsleep = process_cpu_nsleep,
67787 .nsleep_restart = process_cpu_nsleep_restart,
67788 };
67789 - struct k_clock thread = {
67790 + static struct k_clock thread = {
67791 .clock_getres = thread_cpu_clock_getres,
67792 .clock_get = thread_cpu_clock_get,
67793 .timer_create = thread_cpu_timer_create,
67794 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67795 index 69185ae..cc2847a 100644
67796 --- a/kernel/posix-timers.c
67797 +++ b/kernel/posix-timers.c
67798 @@ -43,6 +43,7 @@
67799 #include <linux/idr.h>
67800 #include <linux/posix-clock.h>
67801 #include <linux/posix-timers.h>
67802 +#include <linux/grsecurity.h>
67803 #include <linux/syscalls.h>
67804 #include <linux/wait.h>
67805 #include <linux/workqueue.h>
67806 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67807 * which we beg off on and pass to do_sys_settimeofday().
67808 */
67809
67810 -static struct k_clock posix_clocks[MAX_CLOCKS];
67811 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67812
67813 /*
67814 * These ones are defined below.
67815 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67816 */
67817 static __init int init_posix_timers(void)
67818 {
67819 - struct k_clock clock_realtime = {
67820 + static struct k_clock clock_realtime = {
67821 .clock_getres = hrtimer_get_res,
67822 .clock_get = posix_clock_realtime_get,
67823 .clock_set = posix_clock_realtime_set,
67824 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67825 .timer_get = common_timer_get,
67826 .timer_del = common_timer_del,
67827 };
67828 - struct k_clock clock_monotonic = {
67829 + static struct k_clock clock_monotonic = {
67830 .clock_getres = hrtimer_get_res,
67831 .clock_get = posix_ktime_get_ts,
67832 .nsleep = common_nsleep,
67833 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67834 .timer_get = common_timer_get,
67835 .timer_del = common_timer_del,
67836 };
67837 - struct k_clock clock_monotonic_raw = {
67838 + static struct k_clock clock_monotonic_raw = {
67839 .clock_getres = hrtimer_get_res,
67840 .clock_get = posix_get_monotonic_raw,
67841 };
67842 - struct k_clock clock_realtime_coarse = {
67843 + static struct k_clock clock_realtime_coarse = {
67844 .clock_getres = posix_get_coarse_res,
67845 .clock_get = posix_get_realtime_coarse,
67846 };
67847 - struct k_clock clock_monotonic_coarse = {
67848 + static struct k_clock clock_monotonic_coarse = {
67849 .clock_getres = posix_get_coarse_res,
67850 .clock_get = posix_get_monotonic_coarse,
67851 };
67852 - struct k_clock clock_boottime = {
67853 + static struct k_clock clock_boottime = {
67854 .clock_getres = hrtimer_get_res,
67855 .clock_get = posix_get_boottime,
67856 .nsleep = common_nsleep,
67857 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67858 return;
67859 }
67860
67861 - posix_clocks[clock_id] = *new_clock;
67862 + posix_clocks[clock_id] = new_clock;
67863 }
67864 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67865
67866 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67867 return (id & CLOCKFD_MASK) == CLOCKFD ?
67868 &clock_posix_dynamic : &clock_posix_cpu;
67869
67870 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67871 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67872 return NULL;
67873 - return &posix_clocks[id];
67874 + return posix_clocks[id];
67875 }
67876
67877 static int common_timer_create(struct k_itimer *new_timer)
67878 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67879 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67880 return -EFAULT;
67881
67882 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67883 + have their clock_set fptr set to a nosettime dummy function
67884 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67885 + call common_clock_set, which calls do_sys_settimeofday, which
67886 + we hook
67887 + */
67888 +
67889 return kc->clock_set(which_clock, &new_tp);
67890 }
67891
67892 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67893 index d523593..68197a4 100644
67894 --- a/kernel/power/poweroff.c
67895 +++ b/kernel/power/poweroff.c
67896 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67897 .enable_mask = SYSRQ_ENABLE_BOOT,
67898 };
67899
67900 -static int pm_sysrq_init(void)
67901 +static int __init pm_sysrq_init(void)
67902 {
67903 register_sysrq_key('o', &sysrq_poweroff_op);
67904 return 0;
67905 diff --git a/kernel/power/process.c b/kernel/power/process.c
67906 index 7aac07a..2d3c6dc 100644
67907 --- a/kernel/power/process.c
67908 +++ b/kernel/power/process.c
67909 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67910 u64 elapsed_csecs64;
67911 unsigned int elapsed_csecs;
67912 bool wakeup = false;
67913 + bool timedout = false;
67914
67915 do_gettimeofday(&start);
67916
67917 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67918
67919 while (true) {
67920 todo = 0;
67921 + if (time_after(jiffies, end_time))
67922 + timedout = true;
67923 read_lock(&tasklist_lock);
67924 do_each_thread(g, p) {
67925 if (p == current || !freeze_task(p))
67926 @@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
67927 * try_to_stop() after schedule() in ptrace/signal
67928 * stop sees TIF_FREEZE.
67929 */
67930 - if (!task_is_stopped_or_traced(p) &&
67931 - !freezer_should_skip(p))
67932 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67933 todo++;
67934 + if (timedout) {
67935 + printk(KERN_ERR "Task refusing to freeze:\n");
67936 + sched_show_task(p);
67937 + }
67938 + }
67939 } while_each_thread(g, p);
67940 read_unlock(&tasklist_lock);
67941
67942 @@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
67943 todo += wq_busy;
67944 }
67945
67946 - if (!todo || time_after(jiffies, end_time))
67947 + if (!todo || timedout)
67948 break;
67949
67950 if (pm_wakeup_pending()) {
67951 diff --git a/kernel/printk.c b/kernel/printk.c
67952 index 32690a0..cd7c798 100644
67953 --- a/kernel/printk.c
67954 +++ b/kernel/printk.c
67955 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67956 if (from_file && type != SYSLOG_ACTION_OPEN)
67957 return 0;
67958
67959 +#ifdef CONFIG_GRKERNSEC_DMESG
67960 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67961 + return -EPERM;
67962 +#endif
67963 +
67964 if (syslog_action_restricted(type)) {
67965 if (capable(CAP_SYSLOG))
67966 return 0;
67967 diff --git a/kernel/profile.c b/kernel/profile.c
67968 index 76b8e77..a2930e8 100644
67969 --- a/kernel/profile.c
67970 +++ b/kernel/profile.c
67971 @@ -39,7 +39,7 @@ struct profile_hit {
67972 /* Oprofile timer tick hook */
67973 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67974
67975 -static atomic_t *prof_buffer;
67976 +static atomic_unchecked_t *prof_buffer;
67977 static unsigned long prof_len, prof_shift;
67978
67979 int prof_on __read_mostly;
67980 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67981 hits[i].pc = 0;
67982 continue;
67983 }
67984 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67985 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67986 hits[i].hits = hits[i].pc = 0;
67987 }
67988 }
67989 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67990 * Add the current hit(s) and flush the write-queue out
67991 * to the global buffer:
67992 */
67993 - atomic_add(nr_hits, &prof_buffer[pc]);
67994 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67995 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67996 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67997 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67998 hits[i].pc = hits[i].hits = 0;
67999 }
68000 out:
68001 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68002 {
68003 unsigned long pc;
68004 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68005 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68006 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68007 }
68008 #endif /* !CONFIG_SMP */
68009
68010 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68011 return -EFAULT;
68012 buf++; p++; count--; read++;
68013 }
68014 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68015 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68016 if (copy_to_user(buf, (void *)pnt, count))
68017 return -EFAULT;
68018 read += count;
68019 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68020 }
68021 #endif
68022 profile_discard_flip_buffers();
68023 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68024 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68025 return count;
68026 }
68027
68028 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68029 index 00ab2ca..d237f61 100644
68030 --- a/kernel/ptrace.c
68031 +++ b/kernel/ptrace.c
68032 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68033 task->ptrace = PT_PTRACED;
68034 if (seize)
68035 task->ptrace |= PT_SEIZED;
68036 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68037 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68038 task->ptrace |= PT_PTRACE_CAP;
68039
68040 __ptrace_link(task, current);
68041 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68042 break;
68043 return -EIO;
68044 }
68045 - if (copy_to_user(dst, buf, retval))
68046 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68047 return -EFAULT;
68048 copied += retval;
68049 src += retval;
68050 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
68051 bool seized = child->ptrace & PT_SEIZED;
68052 int ret = -EIO;
68053 siginfo_t siginfo, *si;
68054 - void __user *datavp = (void __user *) data;
68055 + void __user *datavp = (__force void __user *) data;
68056 unsigned long __user *datalp = datavp;
68057 unsigned long flags;
68058
68059 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68060 goto out;
68061 }
68062
68063 + if (gr_handle_ptrace(child, request)) {
68064 + ret = -EPERM;
68065 + goto out_put_task_struct;
68066 + }
68067 +
68068 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68069 ret = ptrace_attach(child, request, data);
68070 /*
68071 * Some architectures need to do book-keeping after
68072 * a ptrace attach.
68073 */
68074 - if (!ret)
68075 + if (!ret) {
68076 arch_ptrace_attach(child);
68077 + gr_audit_ptrace(child);
68078 + }
68079 goto out_put_task_struct;
68080 }
68081
68082 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68083 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68084 if (copied != sizeof(tmp))
68085 return -EIO;
68086 - return put_user(tmp, (unsigned long __user *)data);
68087 + return put_user(tmp, (__force unsigned long __user *)data);
68088 }
68089
68090 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68091 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68092 goto out;
68093 }
68094
68095 + if (gr_handle_ptrace(child, request)) {
68096 + ret = -EPERM;
68097 + goto out_put_task_struct;
68098 + }
68099 +
68100 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68101 ret = ptrace_attach(child, request, data);
68102 /*
68103 * Some architectures need to do book-keeping after
68104 * a ptrace attach.
68105 */
68106 - if (!ret)
68107 + if (!ret) {
68108 arch_ptrace_attach(child);
68109 + gr_audit_ptrace(child);
68110 + }
68111 goto out_put_task_struct;
68112 }
68113
68114 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68115 index 977296d..c4744dc 100644
68116 --- a/kernel/rcutiny.c
68117 +++ b/kernel/rcutiny.c
68118 @@ -46,7 +46,7 @@
68119 struct rcu_ctrlblk;
68120 static void invoke_rcu_callbacks(void);
68121 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68122 -static void rcu_process_callbacks(struct softirq_action *unused);
68123 +static void rcu_process_callbacks(void);
68124 static void __call_rcu(struct rcu_head *head,
68125 void (*func)(struct rcu_head *rcu),
68126 struct rcu_ctrlblk *rcp);
68127 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68128 rcu_is_callbacks_kthread()));
68129 }
68130
68131 -static void rcu_process_callbacks(struct softirq_action *unused)
68132 +static void rcu_process_callbacks(void)
68133 {
68134 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68135 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68136 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68137 index 9cb1ae4..aac7d3e 100644
68138 --- a/kernel/rcutiny_plugin.h
68139 +++ b/kernel/rcutiny_plugin.h
68140 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
68141 have_rcu_kthread_work = morework;
68142 local_irq_restore(flags);
68143 if (work)
68144 - rcu_process_callbacks(NULL);
68145 + rcu_process_callbacks();
68146 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68147 }
68148
68149 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68150 index a58ac28..196a3d8 100644
68151 --- a/kernel/rcutorture.c
68152 +++ b/kernel/rcutorture.c
68153 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68154 { 0 };
68155 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68156 { 0 };
68157 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68158 -static atomic_t n_rcu_torture_alloc;
68159 -static atomic_t n_rcu_torture_alloc_fail;
68160 -static atomic_t n_rcu_torture_free;
68161 -static atomic_t n_rcu_torture_mberror;
68162 -static atomic_t n_rcu_torture_error;
68163 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68164 +static atomic_unchecked_t n_rcu_torture_alloc;
68165 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68166 +static atomic_unchecked_t n_rcu_torture_free;
68167 +static atomic_unchecked_t n_rcu_torture_mberror;
68168 +static atomic_unchecked_t n_rcu_torture_error;
68169 static long n_rcu_torture_boost_ktrerror;
68170 static long n_rcu_torture_boost_rterror;
68171 static long n_rcu_torture_boost_failure;
68172 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68173
68174 spin_lock_bh(&rcu_torture_lock);
68175 if (list_empty(&rcu_torture_freelist)) {
68176 - atomic_inc(&n_rcu_torture_alloc_fail);
68177 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68178 spin_unlock_bh(&rcu_torture_lock);
68179 return NULL;
68180 }
68181 - atomic_inc(&n_rcu_torture_alloc);
68182 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68183 p = rcu_torture_freelist.next;
68184 list_del_init(p);
68185 spin_unlock_bh(&rcu_torture_lock);
68186 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68187 static void
68188 rcu_torture_free(struct rcu_torture *p)
68189 {
68190 - atomic_inc(&n_rcu_torture_free);
68191 + atomic_inc_unchecked(&n_rcu_torture_free);
68192 spin_lock_bh(&rcu_torture_lock);
68193 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68194 spin_unlock_bh(&rcu_torture_lock);
68195 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68196 i = rp->rtort_pipe_count;
68197 if (i > RCU_TORTURE_PIPE_LEN)
68198 i = RCU_TORTURE_PIPE_LEN;
68199 - atomic_inc(&rcu_torture_wcount[i]);
68200 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68201 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68202 rp->rtort_mbtest = 0;
68203 rcu_torture_free(rp);
68204 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68205 i = rp->rtort_pipe_count;
68206 if (i > RCU_TORTURE_PIPE_LEN)
68207 i = RCU_TORTURE_PIPE_LEN;
68208 - atomic_inc(&rcu_torture_wcount[i]);
68209 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68210 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68211 rp->rtort_mbtest = 0;
68212 list_del(&rp->rtort_free);
68213 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68214 i = old_rp->rtort_pipe_count;
68215 if (i > RCU_TORTURE_PIPE_LEN)
68216 i = RCU_TORTURE_PIPE_LEN;
68217 - atomic_inc(&rcu_torture_wcount[i]);
68218 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68219 old_rp->rtort_pipe_count++;
68220 cur_ops->deferred_free(old_rp);
68221 }
68222 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68223 return;
68224 }
68225 if (p->rtort_mbtest == 0)
68226 - atomic_inc(&n_rcu_torture_mberror);
68227 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68228 spin_lock(&rand_lock);
68229 cur_ops->read_delay(&rand);
68230 n_rcu_torture_timers++;
68231 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68232 continue;
68233 }
68234 if (p->rtort_mbtest == 0)
68235 - atomic_inc(&n_rcu_torture_mberror);
68236 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68237 cur_ops->read_delay(&rand);
68238 preempt_disable();
68239 pipe_count = p->rtort_pipe_count;
68240 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68241 rcu_torture_current,
68242 rcu_torture_current_version,
68243 list_empty(&rcu_torture_freelist),
68244 - atomic_read(&n_rcu_torture_alloc),
68245 - atomic_read(&n_rcu_torture_alloc_fail),
68246 - atomic_read(&n_rcu_torture_free),
68247 - atomic_read(&n_rcu_torture_mberror),
68248 + atomic_read_unchecked(&n_rcu_torture_alloc),
68249 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68250 + atomic_read_unchecked(&n_rcu_torture_free),
68251 + atomic_read_unchecked(&n_rcu_torture_mberror),
68252 n_rcu_torture_boost_ktrerror,
68253 n_rcu_torture_boost_rterror,
68254 n_rcu_torture_boost_failure,
68255 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68256 n_online_attempts,
68257 n_offline_successes,
68258 n_offline_attempts);
68259 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68260 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68261 n_rcu_torture_boost_ktrerror != 0 ||
68262 n_rcu_torture_boost_rterror != 0 ||
68263 n_rcu_torture_boost_failure != 0)
68264 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68265 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68266 if (i > 1) {
68267 cnt += sprintf(&page[cnt], "!!! ");
68268 - atomic_inc(&n_rcu_torture_error);
68269 + atomic_inc_unchecked(&n_rcu_torture_error);
68270 WARN_ON_ONCE(1);
68271 }
68272 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68273 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68274 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68275 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68276 cnt += sprintf(&page[cnt], " %d",
68277 - atomic_read(&rcu_torture_wcount[i]));
68278 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68279 }
68280 cnt += sprintf(&page[cnt], "\n");
68281 if (cur_ops->stats)
68282 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68283
68284 if (cur_ops->cleanup)
68285 cur_ops->cleanup();
68286 - if (atomic_read(&n_rcu_torture_error))
68287 + if (atomic_read_unchecked(&n_rcu_torture_error))
68288 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68289 else
68290 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68291 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68292
68293 rcu_torture_current = NULL;
68294 rcu_torture_current_version = 0;
68295 - atomic_set(&n_rcu_torture_alloc, 0);
68296 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68297 - atomic_set(&n_rcu_torture_free, 0);
68298 - atomic_set(&n_rcu_torture_mberror, 0);
68299 - atomic_set(&n_rcu_torture_error, 0);
68300 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68301 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68302 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68303 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68304 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68305 n_rcu_torture_boost_ktrerror = 0;
68306 n_rcu_torture_boost_rterror = 0;
68307 n_rcu_torture_boost_failure = 0;
68308 n_rcu_torture_boosts = 0;
68309 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68310 - atomic_set(&rcu_torture_wcount[i], 0);
68311 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68312 for_each_possible_cpu(cpu) {
68313 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68314 per_cpu(rcu_torture_count, cpu)[i] = 0;
68315 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68316 index 6c4a672..70f3202 100644
68317 --- a/kernel/rcutree.c
68318 +++ b/kernel/rcutree.c
68319 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68320 rcu_prepare_for_idle(smp_processor_id());
68321 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68322 smp_mb__before_atomic_inc(); /* See above. */
68323 - atomic_inc(&rdtp->dynticks);
68324 + atomic_inc_unchecked(&rdtp->dynticks);
68325 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68326 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68327 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68328 }
68329
68330 /**
68331 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68332 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68333 {
68334 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68335 - atomic_inc(&rdtp->dynticks);
68336 + atomic_inc_unchecked(&rdtp->dynticks);
68337 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68338 smp_mb__after_atomic_inc(); /* See above. */
68339 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68340 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68341 rcu_cleanup_after_idle(smp_processor_id());
68342 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68343 if (!is_idle_task(current)) {
68344 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68345 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68346
68347 if (rdtp->dynticks_nmi_nesting == 0 &&
68348 - (atomic_read(&rdtp->dynticks) & 0x1))
68349 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68350 return;
68351 rdtp->dynticks_nmi_nesting++;
68352 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68353 - atomic_inc(&rdtp->dynticks);
68354 + atomic_inc_unchecked(&rdtp->dynticks);
68355 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68356 smp_mb__after_atomic_inc(); /* See above. */
68357 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68358 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68359 }
68360
68361 /**
68362 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68363 return;
68364 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68365 smp_mb__before_atomic_inc(); /* See above. */
68366 - atomic_inc(&rdtp->dynticks);
68367 + atomic_inc_unchecked(&rdtp->dynticks);
68368 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68369 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68370 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68371 }
68372
68373 #ifdef CONFIG_PROVE_RCU
68374 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68375 int ret;
68376
68377 preempt_disable();
68378 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68379 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68380 preempt_enable();
68381 return ret;
68382 }
68383 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68384 */
68385 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68386 {
68387 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68388 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68389 return (rdp->dynticks_snap & 0x1) == 0;
68390 }
68391
68392 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68393 unsigned int curr;
68394 unsigned int snap;
68395
68396 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68397 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68398 snap = (unsigned int)rdp->dynticks_snap;
68399
68400 /*
68401 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68402 /*
68403 * Do RCU core processing for the current CPU.
68404 */
68405 -static void rcu_process_callbacks(struct softirq_action *unused)
68406 +static void rcu_process_callbacks(void)
68407 {
68408 trace_rcu_utilization("Start RCU core");
68409 __rcu_process_callbacks(&rcu_sched_state,
68410 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68411 rdp->qlen = 0;
68412 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68413 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68414 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68415 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68416 rdp->cpu = cpu;
68417 rdp->rsp = rsp;
68418 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68419 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68420 rdp->n_force_qs_snap = rsp->n_force_qs;
68421 rdp->blimit = blimit;
68422 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68423 - atomic_set(&rdp->dynticks->dynticks,
68424 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68425 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68426 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68427 rcu_prepare_for_idle_init(cpu);
68428 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68429
68430 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68431 index fddff92..2c08359 100644
68432 --- a/kernel/rcutree.h
68433 +++ b/kernel/rcutree.h
68434 @@ -87,7 +87,7 @@ struct rcu_dynticks {
68435 long long dynticks_nesting; /* Track irq/process nesting level. */
68436 /* Process level is worth LLONG_MAX/2. */
68437 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68438 - atomic_t dynticks; /* Even value for idle, else odd. */
68439 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68440 };
68441
68442 /* RCU's kthread states for tracing. */
68443 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68444 index 8bb35d7..6ea0a463 100644
68445 --- a/kernel/rcutree_plugin.h
68446 +++ b/kernel/rcutree_plugin.h
68447 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68448
68449 /* Clean up and exit. */
68450 smp_mb(); /* ensure expedited GP seen before counter increment. */
68451 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68452 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68453 unlock_mb_ret:
68454 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68455 mb_ret:
68456 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68457
68458 #else /* #ifndef CONFIG_SMP */
68459
68460 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68461 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68462 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68463 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68464
68465 static int synchronize_sched_expedited_cpu_stop(void *data)
68466 {
68467 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68468 int firstsnap, s, snap, trycount = 0;
68469
68470 /* Note that atomic_inc_return() implies full memory barrier. */
68471 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68472 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68473 get_online_cpus();
68474
68475 /*
68476 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68477 }
68478
68479 /* Check to see if someone else did our work for us. */
68480 - s = atomic_read(&sync_sched_expedited_done);
68481 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68482 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68483 smp_mb(); /* ensure test happens before caller kfree */
68484 return;
68485 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68486 * grace period works for us.
68487 */
68488 get_online_cpus();
68489 - snap = atomic_read(&sync_sched_expedited_started);
68490 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68491 smp_mb(); /* ensure read is before try_stop_cpus(). */
68492 }
68493
68494 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68495 * than we did beat us to the punch.
68496 */
68497 do {
68498 - s = atomic_read(&sync_sched_expedited_done);
68499 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68500 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68501 smp_mb(); /* ensure test happens before caller kfree */
68502 break;
68503 }
68504 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68505 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68506
68507 put_online_cpus();
68508 }
68509 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68510 index 654cfe6..c0b28e2 100644
68511 --- a/kernel/rcutree_trace.c
68512 +++ b/kernel/rcutree_trace.c
68513 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68514 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68515 rdp->qs_pending);
68516 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68517 - atomic_read(&rdp->dynticks->dynticks),
68518 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68519 rdp->dynticks->dynticks_nesting,
68520 rdp->dynticks->dynticks_nmi_nesting,
68521 rdp->dynticks_fqs);
68522 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68523 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68524 rdp->qs_pending);
68525 seq_printf(m, ",%d,%llx,%d,%lu",
68526 - atomic_read(&rdp->dynticks->dynticks),
68527 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68528 rdp->dynticks->dynticks_nesting,
68529 rdp->dynticks->dynticks_nmi_nesting,
68530 rdp->dynticks_fqs);
68531 diff --git a/kernel/resource.c b/kernel/resource.c
68532 index 7640b3a..5879283 100644
68533 --- a/kernel/resource.c
68534 +++ b/kernel/resource.c
68535 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68536
68537 static int __init ioresources_init(void)
68538 {
68539 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68540 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68541 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68542 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68543 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68544 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68545 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68546 +#endif
68547 +#else
68548 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68549 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68550 +#endif
68551 return 0;
68552 }
68553 __initcall(ioresources_init);
68554 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68555 index 98ec494..4241d6d 100644
68556 --- a/kernel/rtmutex-tester.c
68557 +++ b/kernel/rtmutex-tester.c
68558 @@ -20,7 +20,7 @@
68559 #define MAX_RT_TEST_MUTEXES 8
68560
68561 static spinlock_t rttest_lock;
68562 -static atomic_t rttest_event;
68563 +static atomic_unchecked_t rttest_event;
68564
68565 struct test_thread_data {
68566 int opcode;
68567 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68568
68569 case RTTEST_LOCKCONT:
68570 td->mutexes[td->opdata] = 1;
68571 - td->event = atomic_add_return(1, &rttest_event);
68572 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68573 return 0;
68574
68575 case RTTEST_RESET:
68576 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68577 return 0;
68578
68579 case RTTEST_RESETEVENT:
68580 - atomic_set(&rttest_event, 0);
68581 + atomic_set_unchecked(&rttest_event, 0);
68582 return 0;
68583
68584 default:
68585 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68586 return ret;
68587
68588 td->mutexes[id] = 1;
68589 - td->event = atomic_add_return(1, &rttest_event);
68590 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68591 rt_mutex_lock(&mutexes[id]);
68592 - td->event = atomic_add_return(1, &rttest_event);
68593 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68594 td->mutexes[id] = 4;
68595 return 0;
68596
68597 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68598 return ret;
68599
68600 td->mutexes[id] = 1;
68601 - td->event = atomic_add_return(1, &rttest_event);
68602 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68603 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68604 - td->event = atomic_add_return(1, &rttest_event);
68605 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68606 td->mutexes[id] = ret ? 0 : 4;
68607 return ret ? -EINTR : 0;
68608
68609 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68610 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68611 return ret;
68612
68613 - td->event = atomic_add_return(1, &rttest_event);
68614 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68615 rt_mutex_unlock(&mutexes[id]);
68616 - td->event = atomic_add_return(1, &rttest_event);
68617 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68618 td->mutexes[id] = 0;
68619 return 0;
68620
68621 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68622 break;
68623
68624 td->mutexes[dat] = 2;
68625 - td->event = atomic_add_return(1, &rttest_event);
68626 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68627 break;
68628
68629 default:
68630 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68631 return;
68632
68633 td->mutexes[dat] = 3;
68634 - td->event = atomic_add_return(1, &rttest_event);
68635 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68636 break;
68637
68638 case RTTEST_LOCKNOWAIT:
68639 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68640 return;
68641
68642 td->mutexes[dat] = 1;
68643 - td->event = atomic_add_return(1, &rttest_event);
68644 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68645 return;
68646
68647 default:
68648 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68649 index e8a1f83..363d17d 100644
68650 --- a/kernel/sched/auto_group.c
68651 +++ b/kernel/sched/auto_group.c
68652 @@ -11,7 +11,7 @@
68653
68654 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68655 static struct autogroup autogroup_default;
68656 -static atomic_t autogroup_seq_nr;
68657 +static atomic_unchecked_t autogroup_seq_nr;
68658
68659 void __init autogroup_init(struct task_struct *init_task)
68660 {
68661 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68662
68663 kref_init(&ag->kref);
68664 init_rwsem(&ag->lock);
68665 - ag->id = atomic_inc_return(&autogroup_seq_nr);
68666 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68667 ag->tg = tg;
68668 #ifdef CONFIG_RT_GROUP_SCHED
68669 /*
68670 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68671 index b342f57..00324a0 100644
68672 --- a/kernel/sched/core.c
68673 +++ b/kernel/sched/core.c
68674 @@ -3143,6 +3143,19 @@ pick_next_task(struct rq *rq)
68675 BUG(); /* the idle class will always have a runnable task */
68676 }
68677
68678 +#ifdef CONFIG_GRKERNSEC_SETXID
68679 +extern void gr_delayed_cred_worker(void);
68680 +static inline void gr_cred_schedule(void)
68681 +{
68682 + if (unlikely(current->delayed_cred))
68683 + gr_delayed_cred_worker();
68684 +}
68685 +#else
68686 +static inline void gr_cred_schedule(void)
68687 +{
68688 +}
68689 +#endif
68690 +
68691 /*
68692 * __schedule() is the main scheduler function.
68693 */
68694 @@ -3162,6 +3175,8 @@ need_resched:
68695
68696 schedule_debug(prev);
68697
68698 + gr_cred_schedule();
68699 +
68700 if (sched_feat(HRTICK))
68701 hrtick_clear(rq);
68702
68703 @@ -3852,6 +3867,8 @@ int can_nice(const struct task_struct *p, const int nice)
68704 /* convert nice value [19,-20] to rlimit style value [1,40] */
68705 int nice_rlim = 20 - nice;
68706
68707 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68708 +
68709 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68710 capable(CAP_SYS_NICE));
68711 }
68712 @@ -3885,7 +3902,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68713 if (nice > 19)
68714 nice = 19;
68715
68716 - if (increment < 0 && !can_nice(current, nice))
68717 + if (increment < 0 && (!can_nice(current, nice) ||
68718 + gr_handle_chroot_nice()))
68719 return -EPERM;
68720
68721 retval = security_task_setnice(current, nice);
68722 @@ -4042,6 +4060,7 @@ recheck:
68723 unsigned long rlim_rtprio =
68724 task_rlimit(p, RLIMIT_RTPRIO);
68725
68726 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68727 /* can't set/change the rt policy */
68728 if (policy != p->policy && !rlim_rtprio)
68729 return -EPERM;
68730 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68731 index aca16b8..8e3acc4 100644
68732 --- a/kernel/sched/fair.c
68733 +++ b/kernel/sched/fair.c
68734 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68735 * run_rebalance_domains is triggered when needed from the scheduler tick.
68736 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68737 */
68738 -static void run_rebalance_domains(struct softirq_action *h)
68739 +static void run_rebalance_domains(void)
68740 {
68741 int this_cpu = smp_processor_id();
68742 struct rq *this_rq = cpu_rq(this_cpu);
68743 diff --git a/kernel/signal.c b/kernel/signal.c
68744 index c73c428..7040057 100644
68745 --- a/kernel/signal.c
68746 +++ b/kernel/signal.c
68747 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
68748
68749 int print_fatal_signals __read_mostly;
68750
68751 -static void __user *sig_handler(struct task_struct *t, int sig)
68752 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68753 {
68754 return t->sighand->action[sig - 1].sa.sa_handler;
68755 }
68756
68757 -static int sig_handler_ignored(void __user *handler, int sig)
68758 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68759 {
68760 /* Is it explicitly or implicitly ignored? */
68761 return handler == SIG_IGN ||
68762 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68763 static int sig_task_ignored(struct task_struct *t, int sig,
68764 int from_ancestor_ns)
68765 {
68766 - void __user *handler;
68767 + __sighandler_t handler;
68768
68769 handler = sig_handler(t, sig);
68770
68771 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68772 atomic_inc(&user->sigpending);
68773 rcu_read_unlock();
68774
68775 + if (!override_rlimit)
68776 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68777 +
68778 if (override_rlimit ||
68779 atomic_read(&user->sigpending) <=
68780 task_rlimit(t, RLIMIT_SIGPENDING)) {
68781 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68782
68783 int unhandled_signal(struct task_struct *tsk, int sig)
68784 {
68785 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68786 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68787 if (is_global_init(tsk))
68788 return 1;
68789 if (handler != SIG_IGN && handler != SIG_DFL)
68790 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68791 }
68792 }
68793
68794 + /* allow glibc communication via tgkill to other threads in our
68795 + thread group */
68796 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68797 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68798 + && gr_handle_signal(t, sig))
68799 + return -EPERM;
68800 +
68801 return security_task_kill(t, info, sig, 0);
68802 }
68803
68804 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68805 return send_signal(sig, info, p, 1);
68806 }
68807
68808 -static int
68809 +int
68810 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68811 {
68812 return send_signal(sig, info, t, 0);
68813 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68814 unsigned long int flags;
68815 int ret, blocked, ignored;
68816 struct k_sigaction *action;
68817 + int is_unhandled = 0;
68818
68819 spin_lock_irqsave(&t->sighand->siglock, flags);
68820 action = &t->sighand->action[sig-1];
68821 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68822 }
68823 if (action->sa.sa_handler == SIG_DFL)
68824 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68825 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68826 + is_unhandled = 1;
68827 ret = specific_send_sig_info(sig, info, t);
68828 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68829
68830 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68831 + normal operation */
68832 + if (is_unhandled) {
68833 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68834 + gr_handle_crash(t, sig);
68835 + }
68836 +
68837 return ret;
68838 }
68839
68840 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68841 ret = check_kill_permission(sig, info, p);
68842 rcu_read_unlock();
68843
68844 - if (!ret && sig)
68845 + if (!ret && sig) {
68846 ret = do_send_sig_info(sig, info, p, true);
68847 + if (!ret)
68848 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68849 + }
68850
68851 return ret;
68852 }
68853 @@ -2820,7 +2843,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68854 int error = -ESRCH;
68855
68856 rcu_read_lock();
68857 - p = find_task_by_vpid(pid);
68858 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68859 + /* allow glibc communication via tgkill to other threads in our
68860 + thread group */
68861 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68862 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68863 + p = find_task_by_vpid_unrestricted(pid);
68864 + else
68865 +#endif
68866 + p = find_task_by_vpid(pid);
68867 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68868 error = check_kill_permission(sig, info, p);
68869 /*
68870 diff --git a/kernel/smp.c b/kernel/smp.c
68871 index db197d6..17aef0b 100644
68872 --- a/kernel/smp.c
68873 +++ b/kernel/smp.c
68874 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68875 }
68876 EXPORT_SYMBOL(smp_call_function);
68877
68878 -void ipi_call_lock(void)
68879 +void ipi_call_lock(void) __acquires(call_function.lock)
68880 {
68881 raw_spin_lock(&call_function.lock);
68882 }
68883
68884 -void ipi_call_unlock(void)
68885 +void ipi_call_unlock(void) __releases(call_function.lock)
68886 {
68887 raw_spin_unlock(&call_function.lock);
68888 }
68889
68890 -void ipi_call_lock_irq(void)
68891 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68892 {
68893 raw_spin_lock_irq(&call_function.lock);
68894 }
68895
68896 -void ipi_call_unlock_irq(void)
68897 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68898 {
68899 raw_spin_unlock_irq(&call_function.lock);
68900 }
68901 diff --git a/kernel/softirq.c b/kernel/softirq.c
68902 index 4eb3a0f..6f1fa81 100644
68903 --- a/kernel/softirq.c
68904 +++ b/kernel/softirq.c
68905 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68906
68907 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68908
68909 -char *softirq_to_name[NR_SOFTIRQS] = {
68910 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68911 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68912 "TASKLET", "SCHED", "HRTIMER", "RCU"
68913 };
68914 @@ -235,7 +235,7 @@ restart:
68915 kstat_incr_softirqs_this_cpu(vec_nr);
68916
68917 trace_softirq_entry(vec_nr);
68918 - h->action(h);
68919 + h->action();
68920 trace_softirq_exit(vec_nr);
68921 if (unlikely(prev_count != preempt_count())) {
68922 printk(KERN_ERR "huh, entered softirq %u %s %p"
68923 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68924 local_irq_restore(flags);
68925 }
68926
68927 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68928 +void open_softirq(int nr, void (*action)(void))
68929 {
68930 - softirq_vec[nr].action = action;
68931 + pax_open_kernel();
68932 + *(void **)&softirq_vec[nr].action = action;
68933 + pax_close_kernel();
68934 }
68935
68936 /*
68937 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68938
68939 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68940
68941 -static void tasklet_action(struct softirq_action *a)
68942 +static void tasklet_action(void)
68943 {
68944 struct tasklet_struct *list;
68945
68946 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68947 }
68948 }
68949
68950 -static void tasklet_hi_action(struct softirq_action *a)
68951 +static void tasklet_hi_action(void)
68952 {
68953 struct tasklet_struct *list;
68954
68955 diff --git a/kernel/sys.c b/kernel/sys.c
68956 index 888d227..f04b318 100644
68957 --- a/kernel/sys.c
68958 +++ b/kernel/sys.c
68959 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68960 error = -EACCES;
68961 goto out;
68962 }
68963 +
68964 + if (gr_handle_chroot_setpriority(p, niceval)) {
68965 + error = -EACCES;
68966 + goto out;
68967 + }
68968 +
68969 no_nice = security_task_setnice(p, niceval);
68970 if (no_nice) {
68971 error = no_nice;
68972 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68973 goto error;
68974 }
68975
68976 + if (gr_check_group_change(new->gid, new->egid, -1))
68977 + goto error;
68978 +
68979 if (rgid != (gid_t) -1 ||
68980 (egid != (gid_t) -1 && egid != old->gid))
68981 new->sgid = new->egid;
68982 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68983 old = current_cred();
68984
68985 retval = -EPERM;
68986 +
68987 + if (gr_check_group_change(gid, gid, gid))
68988 + goto error;
68989 +
68990 if (nsown_capable(CAP_SETGID))
68991 new->gid = new->egid = new->sgid = new->fsgid = gid;
68992 else if (gid == old->gid || gid == old->sgid)
68993 @@ -618,7 +631,7 @@ error:
68994 /*
68995 * change the user struct in a credentials set to match the new UID
68996 */
68997 -static int set_user(struct cred *new)
68998 +int set_user(struct cred *new)
68999 {
69000 struct user_struct *new_user;
69001
69002 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69003 goto error;
69004 }
69005
69006 + if (gr_check_user_change(new->uid, new->euid, -1))
69007 + goto error;
69008 +
69009 if (new->uid != old->uid) {
69010 retval = set_user(new);
69011 if (retval < 0)
69012 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69013 old = current_cred();
69014
69015 retval = -EPERM;
69016 +
69017 + if (gr_check_crash_uid(uid))
69018 + goto error;
69019 + if (gr_check_user_change(uid, uid, uid))
69020 + goto error;
69021 +
69022 if (nsown_capable(CAP_SETUID)) {
69023 new->suid = new->uid = uid;
69024 if (uid != old->uid) {
69025 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69026 goto error;
69027 }
69028
69029 + if (gr_check_user_change(ruid, euid, -1))
69030 + goto error;
69031 +
69032 if (ruid != (uid_t) -1) {
69033 new->uid = ruid;
69034 if (ruid != old->uid) {
69035 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69036 goto error;
69037 }
69038
69039 + if (gr_check_group_change(rgid, egid, -1))
69040 + goto error;
69041 +
69042 if (rgid != (gid_t) -1)
69043 new->gid = rgid;
69044 if (egid != (gid_t) -1)
69045 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69046 old = current_cred();
69047 old_fsuid = old->fsuid;
69048
69049 + if (gr_check_user_change(-1, -1, uid))
69050 + goto error;
69051 +
69052 if (uid == old->uid || uid == old->euid ||
69053 uid == old->suid || uid == old->fsuid ||
69054 nsown_capable(CAP_SETUID)) {
69055 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69056 }
69057 }
69058
69059 +error:
69060 abort_creds(new);
69061 return old_fsuid;
69062
69063 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69064 if (gid == old->gid || gid == old->egid ||
69065 gid == old->sgid || gid == old->fsgid ||
69066 nsown_capable(CAP_SETGID)) {
69067 + if (gr_check_group_change(-1, -1, gid))
69068 + goto error;
69069 +
69070 if (gid != old_fsgid) {
69071 new->fsgid = gid;
69072 goto change_okay;
69073 }
69074 }
69075
69076 +error:
69077 abort_creds(new);
69078 return old_fsgid;
69079
69080 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
69081 }
69082 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69083 snprintf(buf, len, "2.6.%u%s", v, rest);
69084 - ret = copy_to_user(release, buf, len);
69085 + if (len > sizeof(buf))
69086 + ret = -EFAULT;
69087 + else
69088 + ret = copy_to_user(release, buf, len);
69089 }
69090 return ret;
69091 }
69092 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69093 return -EFAULT;
69094
69095 down_read(&uts_sem);
69096 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69097 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69098 __OLD_UTS_LEN);
69099 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69100 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69101 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69102 __OLD_UTS_LEN);
69103 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69104 - error |= __copy_to_user(&name->release, &utsname()->release,
69105 + error |= __copy_to_user(name->release, &utsname()->release,
69106 __OLD_UTS_LEN);
69107 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69108 - error |= __copy_to_user(&name->version, &utsname()->version,
69109 + error |= __copy_to_user(name->version, &utsname()->version,
69110 __OLD_UTS_LEN);
69111 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69112 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69113 + error |= __copy_to_user(name->machine, &utsname()->machine,
69114 __OLD_UTS_LEN);
69115 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69116 up_read(&uts_sem);
69117 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69118 error = get_dumpable(me->mm);
69119 break;
69120 case PR_SET_DUMPABLE:
69121 - if (arg2 < 0 || arg2 > 1) {
69122 + if (arg2 > 1) {
69123 error = -EINVAL;
69124 break;
69125 }
69126 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69127 index f03a6ef..5fcc8af 100644
69128 --- a/kernel/sysctl.c
69129 +++ b/kernel/sysctl.c
69130 @@ -86,6 +86,13 @@
69131
69132
69133 #if defined(CONFIG_SYSCTL)
69134 +#include <linux/grsecurity.h>
69135 +#include <linux/grinternal.h>
69136 +
69137 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69138 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69139 + const int op);
69140 +extern int gr_handle_chroot_sysctl(const int op);
69141
69142 /* External variables not in a header file. */
69143 extern int sysctl_overcommit_memory;
69144 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69145 }
69146
69147 #endif
69148 +extern struct ctl_table grsecurity_table[];
69149
69150 static struct ctl_table root_table[];
69151 static struct ctl_table_root sysctl_table_root;
69152 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
69153 int sysctl_legacy_va_layout;
69154 #endif
69155
69156 +#ifdef CONFIG_PAX_SOFTMODE
69157 +static ctl_table pax_table[] = {
69158 + {
69159 + .procname = "softmode",
69160 + .data = &pax_softmode,
69161 + .maxlen = sizeof(unsigned int),
69162 + .mode = 0600,
69163 + .proc_handler = &proc_dointvec,
69164 + },
69165 +
69166 + { }
69167 +};
69168 +#endif
69169 +
69170 /* The default sysctl tables: */
69171
69172 static struct ctl_table root_table[] = {
69173 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
69174 #endif
69175
69176 static struct ctl_table kern_table[] = {
69177 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69178 + {
69179 + .procname = "grsecurity",
69180 + .mode = 0500,
69181 + .child = grsecurity_table,
69182 + },
69183 +#endif
69184 +
69185 +#ifdef CONFIG_PAX_SOFTMODE
69186 + {
69187 + .procname = "pax",
69188 + .mode = 0500,
69189 + .child = pax_table,
69190 + },
69191 +#endif
69192 +
69193 {
69194 .procname = "sched_child_runs_first",
69195 .data = &sysctl_sched_child_runs_first,
69196 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
69197 .data = &modprobe_path,
69198 .maxlen = KMOD_PATH_LEN,
69199 .mode = 0644,
69200 - .proc_handler = proc_dostring,
69201 + .proc_handler = proc_dostring_modpriv,
69202 },
69203 {
69204 .procname = "modules_disabled",
69205 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
69206 .extra1 = &zero,
69207 .extra2 = &one,
69208 },
69209 +#endif
69210 {
69211 .procname = "kptr_restrict",
69212 .data = &kptr_restrict,
69213 .maxlen = sizeof(int),
69214 .mode = 0644,
69215 .proc_handler = proc_dointvec_minmax_sysadmin,
69216 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69217 + .extra1 = &two,
69218 +#else
69219 .extra1 = &zero,
69220 +#endif
69221 .extra2 = &two,
69222 },
69223 -#endif
69224 {
69225 .procname = "ngroups_max",
69226 .data = &ngroups_max,
69227 @@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
69228 .proc_handler = proc_dointvec_minmax,
69229 .extra1 = &zero,
69230 },
69231 + {
69232 + .procname = "heap_stack_gap",
69233 + .data = &sysctl_heap_stack_gap,
69234 + .maxlen = sizeof(sysctl_heap_stack_gap),
69235 + .mode = 0644,
69236 + .proc_handler = proc_doulongvec_minmax,
69237 + },
69238 #else
69239 {
69240 .procname = "nr_trim_pages",
69241 @@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
69242 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69243 {
69244 int mode;
69245 + int error;
69246 +
69247 + if (table->parent != NULL && table->parent->procname != NULL &&
69248 + table->procname != NULL &&
69249 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69250 + return -EACCES;
69251 + if (gr_handle_chroot_sysctl(op))
69252 + return -EACCES;
69253 + error = gr_handle_sysctl(table, op);
69254 + if (error)
69255 + return error;
69256
69257 if (root->permissions)
69258 mode = root->permissions(root, current->nsproxy, table);
69259 @@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
69260 buffer, lenp, ppos);
69261 }
69262
69263 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69264 + void __user *buffer, size_t *lenp, loff_t *ppos)
69265 +{
69266 + if (write && !capable(CAP_SYS_MODULE))
69267 + return -EPERM;
69268 +
69269 + return _proc_do_string(table->data, table->maxlen, write,
69270 + buffer, lenp, ppos);
69271 +}
69272 +
69273 static size_t proc_skip_spaces(char **buf)
69274 {
69275 size_t ret;
69276 @@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69277 len = strlen(tmp);
69278 if (len > *size)
69279 len = *size;
69280 + if (len > sizeof(tmp))
69281 + len = sizeof(tmp);
69282 if (copy_to_user(*buf, tmp, len))
69283 return -EFAULT;
69284 *size -= len;
69285 @@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69286 *i = val;
69287 } else {
69288 val = convdiv * (*i) / convmul;
69289 - if (!first)
69290 + if (!first) {
69291 err = proc_put_char(&buffer, &left, '\t');
69292 + if (err)
69293 + break;
69294 + }
69295 err = proc_put_long(&buffer, &left, val, false);
69296 if (err)
69297 break;
69298 @@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
69299 return -ENOSYS;
69300 }
69301
69302 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69303 + void __user *buffer, size_t *lenp, loff_t *ppos)
69304 +{
69305 + return -ENOSYS;
69306 +}
69307 +
69308 int proc_dointvec(struct ctl_table *table, int write,
69309 void __user *buffer, size_t *lenp, loff_t *ppos)
69310 {
69311 @@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69312 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69313 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69314 EXPORT_SYMBOL(proc_dostring);
69315 +EXPORT_SYMBOL(proc_dostring_modpriv);
69316 EXPORT_SYMBOL(proc_doulongvec_minmax);
69317 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69318 EXPORT_SYMBOL(register_sysctl_table);
69319 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69320 index a650694..aaeeb20 100644
69321 --- a/kernel/sysctl_binary.c
69322 +++ b/kernel/sysctl_binary.c
69323 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69324 int i;
69325
69326 set_fs(KERNEL_DS);
69327 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69328 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69329 set_fs(old_fs);
69330 if (result < 0)
69331 goto out_kfree;
69332 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69333 }
69334
69335 set_fs(KERNEL_DS);
69336 - result = vfs_write(file, buffer, str - buffer, &pos);
69337 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69338 set_fs(old_fs);
69339 if (result < 0)
69340 goto out_kfree;
69341 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69342 int i;
69343
69344 set_fs(KERNEL_DS);
69345 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69346 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69347 set_fs(old_fs);
69348 if (result < 0)
69349 goto out_kfree;
69350 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69351 }
69352
69353 set_fs(KERNEL_DS);
69354 - result = vfs_write(file, buffer, str - buffer, &pos);
69355 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69356 set_fs(old_fs);
69357 if (result < 0)
69358 goto out_kfree;
69359 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69360 int i;
69361
69362 set_fs(KERNEL_DS);
69363 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69364 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69365 set_fs(old_fs);
69366 if (result < 0)
69367 goto out;
69368 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69369 __le16 dnaddr;
69370
69371 set_fs(KERNEL_DS);
69372 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69373 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69374 set_fs(old_fs);
69375 if (result < 0)
69376 goto out;
69377 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69378 le16_to_cpu(dnaddr) & 0x3ff);
69379
69380 set_fs(KERNEL_DS);
69381 - result = vfs_write(file, buf, len, &pos);
69382 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69383 set_fs(old_fs);
69384 if (result < 0)
69385 goto out;
69386 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69387 index 362da65..ab8ef8c 100644
69388 --- a/kernel/sysctl_check.c
69389 +++ b/kernel/sysctl_check.c
69390 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69391 set_fail(&fail, table, "Directory with extra2");
69392 } else {
69393 if ((table->proc_handler == proc_dostring) ||
69394 + (table->proc_handler == proc_dostring_modpriv) ||
69395 (table->proc_handler == proc_dointvec) ||
69396 (table->proc_handler == proc_dointvec_minmax) ||
69397 (table->proc_handler == proc_dointvec_jiffies) ||
69398 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69399 index e660464..c8b9e67 100644
69400 --- a/kernel/taskstats.c
69401 +++ b/kernel/taskstats.c
69402 @@ -27,9 +27,12 @@
69403 #include <linux/cgroup.h>
69404 #include <linux/fs.h>
69405 #include <linux/file.h>
69406 +#include <linux/grsecurity.h>
69407 #include <net/genetlink.h>
69408 #include <linux/atomic.h>
69409
69410 +extern int gr_is_taskstats_denied(int pid);
69411 +
69412 /*
69413 * Maximum length of a cpumask that can be specified in
69414 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69415 @@ -556,6 +559,9 @@ err:
69416
69417 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69418 {
69419 + if (gr_is_taskstats_denied(current->pid))
69420 + return -EACCES;
69421 +
69422 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69423 return cmd_attr_register_cpumask(info);
69424 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69425 diff --git a/kernel/time.c b/kernel/time.c
69426 index 73e416d..cfc6f69 100644
69427 --- a/kernel/time.c
69428 +++ b/kernel/time.c
69429 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69430 return error;
69431
69432 if (tz) {
69433 + /* we log in do_settimeofday called below, so don't log twice
69434 + */
69435 + if (!tv)
69436 + gr_log_timechange();
69437 +
69438 /* SMP safe, global irq locking makes it work. */
69439 sys_tz = *tz;
69440 update_vsyscall_tz();
69441 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69442 index 8a46f5d..bbe6f9c 100644
69443 --- a/kernel/time/alarmtimer.c
69444 +++ b/kernel/time/alarmtimer.c
69445 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69446 struct platform_device *pdev;
69447 int error = 0;
69448 int i;
69449 - struct k_clock alarm_clock = {
69450 + static struct k_clock alarm_clock = {
69451 .clock_getres = alarm_clock_getres,
69452 .clock_get = alarm_clock_get,
69453 .timer_create = alarm_timer_create,
69454 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69455 index fd4a7b1..fae5c2a 100644
69456 --- a/kernel/time/tick-broadcast.c
69457 +++ b/kernel/time/tick-broadcast.c
69458 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69459 * then clear the broadcast bit.
69460 */
69461 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69462 - int cpu = smp_processor_id();
69463 + cpu = smp_processor_id();
69464
69465 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69466 tick_broadcast_clear_oneshot(cpu);
69467 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69468 index 0c63581..e25dcb6 100644
69469 --- a/kernel/time/timekeeping.c
69470 +++ b/kernel/time/timekeeping.c
69471 @@ -14,6 +14,7 @@
69472 #include <linux/init.h>
69473 #include <linux/mm.h>
69474 #include <linux/sched.h>
69475 +#include <linux/grsecurity.h>
69476 #include <linux/syscore_ops.h>
69477 #include <linux/clocksource.h>
69478 #include <linux/jiffies.h>
69479 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69480 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69481 return -EINVAL;
69482
69483 + gr_log_timechange();
69484 +
69485 write_seqlock_irqsave(&xtime_lock, flags);
69486
69487 timekeeping_forward_now();
69488 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69489 index 3258455..f35227d 100644
69490 --- a/kernel/time/timer_list.c
69491 +++ b/kernel/time/timer_list.c
69492 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69493
69494 static void print_name_offset(struct seq_file *m, void *sym)
69495 {
69496 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69497 + SEQ_printf(m, "<%p>", NULL);
69498 +#else
69499 char symname[KSYM_NAME_LEN];
69500
69501 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69502 SEQ_printf(m, "<%pK>", sym);
69503 else
69504 SEQ_printf(m, "%s", symname);
69505 +#endif
69506 }
69507
69508 static void
69509 @@ -112,7 +116,11 @@ next_one:
69510 static void
69511 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69512 {
69513 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69514 + SEQ_printf(m, " .base: %p\n", NULL);
69515 +#else
69516 SEQ_printf(m, " .base: %pK\n", base);
69517 +#endif
69518 SEQ_printf(m, " .index: %d\n",
69519 base->index);
69520 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69521 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69522 {
69523 struct proc_dir_entry *pe;
69524
69525 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69526 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69527 +#else
69528 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69529 +#endif
69530 if (!pe)
69531 return -ENOMEM;
69532 return 0;
69533 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69534 index 0b537f2..9e71eca 100644
69535 --- a/kernel/time/timer_stats.c
69536 +++ b/kernel/time/timer_stats.c
69537 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69538 static unsigned long nr_entries;
69539 static struct entry entries[MAX_ENTRIES];
69540
69541 -static atomic_t overflow_count;
69542 +static atomic_unchecked_t overflow_count;
69543
69544 /*
69545 * The entries are in a hash-table, for fast lookup:
69546 @@ -140,7 +140,7 @@ static void reset_entries(void)
69547 nr_entries = 0;
69548 memset(entries, 0, sizeof(entries));
69549 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69550 - atomic_set(&overflow_count, 0);
69551 + atomic_set_unchecked(&overflow_count, 0);
69552 }
69553
69554 static struct entry *alloc_entry(void)
69555 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69556 if (likely(entry))
69557 entry->count++;
69558 else
69559 - atomic_inc(&overflow_count);
69560 + atomic_inc_unchecked(&overflow_count);
69561
69562 out_unlock:
69563 raw_spin_unlock_irqrestore(lock, flags);
69564 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69565
69566 static void print_name_offset(struct seq_file *m, unsigned long addr)
69567 {
69568 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69569 + seq_printf(m, "<%p>", NULL);
69570 +#else
69571 char symname[KSYM_NAME_LEN];
69572
69573 if (lookup_symbol_name(addr, symname) < 0)
69574 seq_printf(m, "<%p>", (void *)addr);
69575 else
69576 seq_printf(m, "%s", symname);
69577 +#endif
69578 }
69579
69580 static int tstats_show(struct seq_file *m, void *v)
69581 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69582
69583 seq_puts(m, "Timer Stats Version: v0.2\n");
69584 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69585 - if (atomic_read(&overflow_count))
69586 + if (atomic_read_unchecked(&overflow_count))
69587 seq_printf(m, "Overflow: %d entries\n",
69588 - atomic_read(&overflow_count));
69589 + atomic_read_unchecked(&overflow_count));
69590
69591 for (i = 0; i < nr_entries; i++) {
69592 entry = entries + i;
69593 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69594 {
69595 struct proc_dir_entry *pe;
69596
69597 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69598 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69599 +#else
69600 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69601 +#endif
69602 if (!pe)
69603 return -ENOMEM;
69604 return 0;
69605 diff --git a/kernel/timer.c b/kernel/timer.c
69606 index a297ffc..5e16b0b 100644
69607 --- a/kernel/timer.c
69608 +++ b/kernel/timer.c
69609 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69610 /*
69611 * This function runs timers and the timer-tq in bottom half context.
69612 */
69613 -static void run_timer_softirq(struct softirq_action *h)
69614 +static void run_timer_softirq(void)
69615 {
69616 struct tvec_base *base = __this_cpu_read(tvec_bases);
69617
69618 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69619 index cdea7b5..9b820d4 100644
69620 --- a/kernel/trace/blktrace.c
69621 +++ b/kernel/trace/blktrace.c
69622 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69623 struct blk_trace *bt = filp->private_data;
69624 char buf[16];
69625
69626 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69627 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69628
69629 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69630 }
69631 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69632 return 1;
69633
69634 bt = buf->chan->private_data;
69635 - atomic_inc(&bt->dropped);
69636 + atomic_inc_unchecked(&bt->dropped);
69637 return 0;
69638 }
69639
69640 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69641
69642 bt->dir = dir;
69643 bt->dev = dev;
69644 - atomic_set(&bt->dropped, 0);
69645 + atomic_set_unchecked(&bt->dropped, 0);
69646
69647 ret = -EIO;
69648 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69649 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69650 index 683d559..d70d914 100644
69651 --- a/kernel/trace/ftrace.c
69652 +++ b/kernel/trace/ftrace.c
69653 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69654 if (unlikely(ftrace_disabled))
69655 return 0;
69656
69657 + ret = ftrace_arch_code_modify_prepare();
69658 + FTRACE_WARN_ON(ret);
69659 + if (ret)
69660 + return 0;
69661 +
69662 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69663 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69664 if (ret) {
69665 ftrace_bug(ret, ip);
69666 - return 0;
69667 }
69668 - return 1;
69669 + return ret ? 0 : 1;
69670 }
69671
69672 /*
69673 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69674
69675 int
69676 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69677 - void *data)
69678 + void *data)
69679 {
69680 struct ftrace_func_probe *entry;
69681 struct ftrace_page *pg;
69682 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69683 index c4579f1..6a439da 100644
69684 --- a/kernel/trace/trace.c
69685 +++ b/kernel/trace/trace.c
69686 @@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69687 };
69688 #endif
69689
69690 -static struct dentry *d_tracer;
69691 -
69692 struct dentry *tracing_init_dentry(void)
69693 {
69694 + static struct dentry *d_tracer;
69695 static int once;
69696
69697 if (d_tracer)
69698 @@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
69699 return d_tracer;
69700 }
69701
69702 -static struct dentry *d_percpu;
69703 -
69704 struct dentry *tracing_dentry_percpu(void)
69705 {
69706 + static struct dentry *d_percpu;
69707 static int once;
69708 struct dentry *d_tracer;
69709
69710 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69711 index c212a7f..7b02394 100644
69712 --- a/kernel/trace/trace_events.c
69713 +++ b/kernel/trace/trace_events.c
69714 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69715 struct ftrace_module_file_ops {
69716 struct list_head list;
69717 struct module *mod;
69718 - struct file_operations id;
69719 - struct file_operations enable;
69720 - struct file_operations format;
69721 - struct file_operations filter;
69722 };
69723
69724 static struct ftrace_module_file_ops *
69725 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69726
69727 file_ops->mod = mod;
69728
69729 - file_ops->id = ftrace_event_id_fops;
69730 - file_ops->id.owner = mod;
69731 -
69732 - file_ops->enable = ftrace_enable_fops;
69733 - file_ops->enable.owner = mod;
69734 -
69735 - file_ops->filter = ftrace_event_filter_fops;
69736 - file_ops->filter.owner = mod;
69737 -
69738 - file_ops->format = ftrace_event_format_fops;
69739 - file_ops->format.owner = mod;
69740 + pax_open_kernel();
69741 + *(void **)&mod->trace_id.owner = mod;
69742 + *(void **)&mod->trace_enable.owner = mod;
69743 + *(void **)&mod->trace_filter.owner = mod;
69744 + *(void **)&mod->trace_format.owner = mod;
69745 + pax_close_kernel();
69746
69747 list_add(&file_ops->list, &ftrace_module_file_list);
69748
69749 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69750
69751 for_each_event(call, start, end) {
69752 __trace_add_event_call(*call, mod,
69753 - &file_ops->id, &file_ops->enable,
69754 - &file_ops->filter, &file_ops->format);
69755 + &mod->trace_id, &mod->trace_enable,
69756 + &mod->trace_filter, &mod->trace_format);
69757 }
69758 }
69759
69760 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69761 index 00d527c..7c5b1a3 100644
69762 --- a/kernel/trace/trace_kprobe.c
69763 +++ b/kernel/trace/trace_kprobe.c
69764 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69765 long ret;
69766 int maxlen = get_rloc_len(*(u32 *)dest);
69767 u8 *dst = get_rloc_data(dest);
69768 - u8 *src = addr;
69769 + const u8 __user *src = (const u8 __force_user *)addr;
69770 mm_segment_t old_fs = get_fs();
69771 if (!maxlen)
69772 return;
69773 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69774 pagefault_disable();
69775 do
69776 ret = __copy_from_user_inatomic(dst++, src++, 1);
69777 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69778 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69779 dst[-1] = '\0';
69780 pagefault_enable();
69781 set_fs(old_fs);
69782 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69783 ((u8 *)get_rloc_data(dest))[0] = '\0';
69784 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69785 } else
69786 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69787 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69788 get_rloc_offs(*(u32 *)dest));
69789 }
69790 /* Return the length of string -- including null terminal byte */
69791 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69792 set_fs(KERNEL_DS);
69793 pagefault_disable();
69794 do {
69795 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69796 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69797 len++;
69798 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69799 pagefault_enable();
69800 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69801 index fd3c8aa..5f324a6 100644
69802 --- a/kernel/trace/trace_mmiotrace.c
69803 +++ b/kernel/trace/trace_mmiotrace.c
69804 @@ -24,7 +24,7 @@ struct header_iter {
69805 static struct trace_array *mmio_trace_array;
69806 static bool overrun_detected;
69807 static unsigned long prev_overruns;
69808 -static atomic_t dropped_count;
69809 +static atomic_unchecked_t dropped_count;
69810
69811 static void mmio_reset_data(struct trace_array *tr)
69812 {
69813 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69814
69815 static unsigned long count_overruns(struct trace_iterator *iter)
69816 {
69817 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69818 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69819 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69820
69821 if (over > prev_overruns)
69822 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69823 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69824 sizeof(*entry), 0, pc);
69825 if (!event) {
69826 - atomic_inc(&dropped_count);
69827 + atomic_inc_unchecked(&dropped_count);
69828 return;
69829 }
69830 entry = ring_buffer_event_data(event);
69831 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69832 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69833 sizeof(*entry), 0, pc);
69834 if (!event) {
69835 - atomic_inc(&dropped_count);
69836 + atomic_inc_unchecked(&dropped_count);
69837 return;
69838 }
69839 entry = ring_buffer_event_data(event);
69840 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69841 index 0d6ff35..67e0ed7 100644
69842 --- a/kernel/trace/trace_output.c
69843 +++ b/kernel/trace/trace_output.c
69844 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69845
69846 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69847 if (!IS_ERR(p)) {
69848 - p = mangle_path(s->buffer + s->len, p, "\n");
69849 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69850 if (p) {
69851 s->len = p - s->buffer;
69852 return 1;
69853 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69854 index d4545f4..a9010a1 100644
69855 --- a/kernel/trace/trace_stack.c
69856 +++ b/kernel/trace/trace_stack.c
69857 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69858 return;
69859
69860 /* we do not handle interrupt stacks yet */
69861 - if (!object_is_on_stack(&this_size))
69862 + if (!object_starts_on_stack(&this_size))
69863 return;
69864
69865 local_irq_save(flags);
69866 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69867 index 209b379..7f76423 100644
69868 --- a/kernel/trace/trace_workqueue.c
69869 +++ b/kernel/trace/trace_workqueue.c
69870 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69871 int cpu;
69872 pid_t pid;
69873 /* Can be inserted from interrupt or user context, need to be atomic */
69874 - atomic_t inserted;
69875 + atomic_unchecked_t inserted;
69876 /*
69877 * Don't need to be atomic, works are serialized in a single workqueue thread
69878 * on a single CPU.
69879 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69880 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69881 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69882 if (node->pid == wq_thread->pid) {
69883 - atomic_inc(&node->inserted);
69884 + atomic_inc_unchecked(&node->inserted);
69885 goto found;
69886 }
69887 }
69888 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69889 tsk = get_pid_task(pid, PIDTYPE_PID);
69890 if (tsk) {
69891 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69892 - atomic_read(&cws->inserted), cws->executed,
69893 + atomic_read_unchecked(&cws->inserted), cws->executed,
69894 tsk->comm);
69895 put_task_struct(tsk);
69896 }
69897 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69898 index 8745ac7..d144e37 100644
69899 --- a/lib/Kconfig.debug
69900 +++ b/lib/Kconfig.debug
69901 @@ -1103,6 +1103,7 @@ config LATENCYTOP
69902 depends on DEBUG_KERNEL
69903 depends on STACKTRACE_SUPPORT
69904 depends on PROC_FS
69905 + depends on !GRKERNSEC_HIDESYM
69906 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69907 select KALLSYMS
69908 select KALLSYMS_ALL
69909 diff --git a/lib/bitmap.c b/lib/bitmap.c
69910 index 0d4a127..33a06c7 100644
69911 --- a/lib/bitmap.c
69912 +++ b/lib/bitmap.c
69913 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69914 {
69915 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69916 u32 chunk;
69917 - const char __user __force *ubuf = (const char __user __force *)buf;
69918 + const char __user *ubuf = (const char __force_user *)buf;
69919
69920 bitmap_zero(maskp, nmaskbits);
69921
69922 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69923 {
69924 if (!access_ok(VERIFY_READ, ubuf, ulen))
69925 return -EFAULT;
69926 - return __bitmap_parse((const char __force *)ubuf,
69927 + return __bitmap_parse((const char __force_kernel *)ubuf,
69928 ulen, 1, maskp, nmaskbits);
69929
69930 }
69931 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69932 {
69933 unsigned a, b;
69934 int c, old_c, totaldigits;
69935 - const char __user __force *ubuf = (const char __user __force *)buf;
69936 + const char __user *ubuf = (const char __force_user *)buf;
69937 int exp_digit, in_range;
69938
69939 totaldigits = c = 0;
69940 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69941 {
69942 if (!access_ok(VERIFY_READ, ubuf, ulen))
69943 return -EFAULT;
69944 - return __bitmap_parselist((const char __force *)ubuf,
69945 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69946 ulen, 1, maskp, nmaskbits);
69947 }
69948 EXPORT_SYMBOL(bitmap_parselist_user);
69949 diff --git a/lib/bug.c b/lib/bug.c
69950 index a28c141..2bd3d95 100644
69951 --- a/lib/bug.c
69952 +++ b/lib/bug.c
69953 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69954 return BUG_TRAP_TYPE_NONE;
69955
69956 bug = find_bug(bugaddr);
69957 + if (!bug)
69958 + return BUG_TRAP_TYPE_NONE;
69959
69960 file = NULL;
69961 line = 0;
69962 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69963 index 0ab9ae8..f01ceca 100644
69964 --- a/lib/debugobjects.c
69965 +++ b/lib/debugobjects.c
69966 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69967 if (limit > 4)
69968 return;
69969
69970 - is_on_stack = object_is_on_stack(addr);
69971 + is_on_stack = object_starts_on_stack(addr);
69972 if (is_on_stack == onstack)
69973 return;
69974
69975 diff --git a/lib/devres.c b/lib/devres.c
69976 index 9676617..5149e15 100644
69977 --- a/lib/devres.c
69978 +++ b/lib/devres.c
69979 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69980 void devm_iounmap(struct device *dev, void __iomem *addr)
69981 {
69982 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69983 - (void *)addr));
69984 + (void __force *)addr));
69985 iounmap(addr);
69986 }
69987 EXPORT_SYMBOL(devm_iounmap);
69988 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69989 {
69990 ioport_unmap(addr);
69991 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69992 - devm_ioport_map_match, (void *)addr));
69993 + devm_ioport_map_match, (void __force *)addr));
69994 }
69995 EXPORT_SYMBOL(devm_ioport_unmap);
69996
69997 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69998 index fea790a..ebb0e82 100644
69999 --- a/lib/dma-debug.c
70000 +++ b/lib/dma-debug.c
70001 @@ -925,7 +925,7 @@ out:
70002
70003 static void check_for_stack(struct device *dev, void *addr)
70004 {
70005 - if (object_is_on_stack(addr))
70006 + if (object_starts_on_stack(addr))
70007 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70008 "stack [addr=%p]\n", addr);
70009 }
70010 diff --git a/lib/extable.c b/lib/extable.c
70011 index 4cac81e..63e9b8f 100644
70012 --- a/lib/extable.c
70013 +++ b/lib/extable.c
70014 @@ -13,6 +13,7 @@
70015 #include <linux/init.h>
70016 #include <linux/sort.h>
70017 #include <asm/uaccess.h>
70018 +#include <asm/pgtable.h>
70019
70020 #ifndef ARCH_HAS_SORT_EXTABLE
70021 /*
70022 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70023 void sort_extable(struct exception_table_entry *start,
70024 struct exception_table_entry *finish)
70025 {
70026 + pax_open_kernel();
70027 sort(start, finish - start, sizeof(struct exception_table_entry),
70028 cmp_ex, NULL);
70029 + pax_close_kernel();
70030 }
70031
70032 #ifdef CONFIG_MODULES
70033 diff --git a/lib/inflate.c b/lib/inflate.c
70034 index 013a761..c28f3fc 100644
70035 --- a/lib/inflate.c
70036 +++ b/lib/inflate.c
70037 @@ -269,7 +269,7 @@ static void free(void *where)
70038 malloc_ptr = free_mem_ptr;
70039 }
70040 #else
70041 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70042 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70043 #define free(a) kfree(a)
70044 #endif
70045
70046 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70047 index bd2bea9..6b3c95e 100644
70048 --- a/lib/is_single_threaded.c
70049 +++ b/lib/is_single_threaded.c
70050 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70051 struct task_struct *p, *t;
70052 bool ret;
70053
70054 + if (!mm)
70055 + return true;
70056 +
70057 if (atomic_read(&task->signal->live) != 1)
70058 return false;
70059
70060 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70061 index dc63d08..95ae14a 100644
70062 --- a/lib/radix-tree.c
70063 +++ b/lib/radix-tree.c
70064 @@ -78,7 +78,7 @@ struct radix_tree_preload {
70065 int nr;
70066 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70067 };
70068 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70069 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70070
70071 static inline void *ptr_to_indirect(void *ptr)
70072 {
70073 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70074 index 38e612e..4fb99a8 100644
70075 --- a/lib/vsprintf.c
70076 +++ b/lib/vsprintf.c
70077 @@ -16,6 +16,9 @@
70078 * - scnprintf and vscnprintf
70079 */
70080
70081 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70082 +#define __INCLUDED_BY_HIDESYM 1
70083 +#endif
70084 #include <stdarg.h>
70085 #include <linux/module.h>
70086 #include <linux/types.h>
70087 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70088 char sym[KSYM_SYMBOL_LEN];
70089 if (ext == 'B')
70090 sprint_backtrace(sym, value);
70091 - else if (ext != 'f' && ext != 's')
70092 + else if (ext != 'f' && ext != 's' && ext != 'a')
70093 sprint_symbol(sym, value);
70094 else
70095 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70096 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70097 return number(buf, end, *(const netdev_features_t *)addr, spec);
70098 }
70099
70100 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70101 +int kptr_restrict __read_mostly = 2;
70102 +#else
70103 int kptr_restrict __read_mostly;
70104 +#endif
70105
70106 /*
70107 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70108 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
70109 * - 'S' For symbolic direct pointers with offset
70110 * - 's' For symbolic direct pointers without offset
70111 * - 'B' For backtraced symbolic direct pointers with offset
70112 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70113 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70114 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70115 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70116 * - 'M' For a 6-byte MAC address, it prints the address in the
70117 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70118 {
70119 if (!ptr && *fmt != 'K') {
70120 /*
70121 - * Print (null) with the same width as a pointer so it makes
70122 + * Print (nil) with the same width as a pointer so it makes
70123 * tabular output look nice.
70124 */
70125 if (spec.field_width == -1)
70126 spec.field_width = 2 * sizeof(void *);
70127 - return string(buf, end, "(null)", spec);
70128 + return string(buf, end, "(nil)", spec);
70129 }
70130
70131 switch (*fmt) {
70132 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70133 /* Fallthrough */
70134 case 'S':
70135 case 's':
70136 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70137 + break;
70138 +#else
70139 + return symbol_string(buf, end, ptr, spec, *fmt);
70140 +#endif
70141 + case 'A':
70142 + case 'a':
70143 case 'B':
70144 return symbol_string(buf, end, ptr, spec, *fmt);
70145 case 'R':
70146 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70147 typeof(type) value; \
70148 if (sizeof(type) == 8) { \
70149 args = PTR_ALIGN(args, sizeof(u32)); \
70150 - *(u32 *)&value = *(u32 *)args; \
70151 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70152 + *(u32 *)&value = *(const u32 *)args; \
70153 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70154 } else { \
70155 args = PTR_ALIGN(args, sizeof(type)); \
70156 - value = *(typeof(type) *)args; \
70157 + value = *(const typeof(type) *)args; \
70158 } \
70159 args += sizeof(type); \
70160 value; \
70161 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70162 case FORMAT_TYPE_STR: {
70163 const char *str_arg = args;
70164 args += strlen(str_arg) + 1;
70165 - str = string(str, end, (char *)str_arg, spec);
70166 + str = string(str, end, str_arg, spec);
70167 break;
70168 }
70169
70170 diff --git a/localversion-grsec b/localversion-grsec
70171 new file mode 100644
70172 index 0000000..7cd6065
70173 --- /dev/null
70174 +++ b/localversion-grsec
70175 @@ -0,0 +1 @@
70176 +-grsec
70177 diff --git a/mm/Kconfig b/mm/Kconfig
70178 index e338407..49b5b7a 100644
70179 --- a/mm/Kconfig
70180 +++ b/mm/Kconfig
70181 @@ -247,10 +247,10 @@ config KSM
70182 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70183
70184 config DEFAULT_MMAP_MIN_ADDR
70185 - int "Low address space to protect from user allocation"
70186 + int "Low address space to protect from user allocation"
70187 depends on MMU
70188 - default 4096
70189 - help
70190 + default 65536
70191 + help
70192 This is the portion of low virtual memory which should be protected
70193 from userspace allocation. Keeping a user from writing to low pages
70194 can help reduce the impact of kernel NULL pointer bugs.
70195 diff --git a/mm/filemap.c b/mm/filemap.c
70196 index b662757..3081ddd 100644
70197 --- a/mm/filemap.c
70198 +++ b/mm/filemap.c
70199 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70200 struct address_space *mapping = file->f_mapping;
70201
70202 if (!mapping->a_ops->readpage)
70203 - return -ENOEXEC;
70204 + return -ENODEV;
70205 file_accessed(file);
70206 vma->vm_ops = &generic_file_vm_ops;
70207 vma->vm_flags |= VM_CAN_NONLINEAR;
70208 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70209 *pos = i_size_read(inode);
70210
70211 if (limit != RLIM_INFINITY) {
70212 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70213 if (*pos >= limit) {
70214 send_sig(SIGXFSZ, current, 0);
70215 return -EFBIG;
70216 diff --git a/mm/fremap.c b/mm/fremap.c
70217 index 9ed4fd4..c42648d 100644
70218 --- a/mm/fremap.c
70219 +++ b/mm/fremap.c
70220 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70221 retry:
70222 vma = find_vma(mm, start);
70223
70224 +#ifdef CONFIG_PAX_SEGMEXEC
70225 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70226 + goto out;
70227 +#endif
70228 +
70229 /*
70230 * Make sure the vma is shared, that it supports prefaulting,
70231 * and that the remapped range is valid and fully within
70232 diff --git a/mm/highmem.c b/mm/highmem.c
70233 index 57d82c6..e9e0552 100644
70234 --- a/mm/highmem.c
70235 +++ b/mm/highmem.c
70236 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70237 * So no dangers, even with speculative execution.
70238 */
70239 page = pte_page(pkmap_page_table[i]);
70240 + pax_open_kernel();
70241 pte_clear(&init_mm, (unsigned long)page_address(page),
70242 &pkmap_page_table[i]);
70243 -
70244 + pax_close_kernel();
70245 set_page_address(page, NULL);
70246 need_flush = 1;
70247 }
70248 @@ -186,9 +187,11 @@ start:
70249 }
70250 }
70251 vaddr = PKMAP_ADDR(last_pkmap_nr);
70252 +
70253 + pax_open_kernel();
70254 set_pte_at(&init_mm, vaddr,
70255 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70256 -
70257 + pax_close_kernel();
70258 pkmap_count[last_pkmap_nr] = 1;
70259 set_page_address(page, (void *)vaddr);
70260
70261 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70262 index 8f7fc39..69bf1e9 100644
70263 --- a/mm/huge_memory.c
70264 +++ b/mm/huge_memory.c
70265 @@ -733,7 +733,7 @@ out:
70266 * run pte_offset_map on the pmd, if an huge pmd could
70267 * materialize from under us from a different thread.
70268 */
70269 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70270 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70271 return VM_FAULT_OOM;
70272 /* if an huge pmd materialized from under us just retry later */
70273 if (unlikely(pmd_trans_huge(*pmd)))
70274 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70275 index a7cf829..d60e0e1 100644
70276 --- a/mm/hugetlb.c
70277 +++ b/mm/hugetlb.c
70278 @@ -2346,6 +2346,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70279 return 1;
70280 }
70281
70282 +#ifdef CONFIG_PAX_SEGMEXEC
70283 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70284 +{
70285 + struct mm_struct *mm = vma->vm_mm;
70286 + struct vm_area_struct *vma_m;
70287 + unsigned long address_m;
70288 + pte_t *ptep_m;
70289 +
70290 + vma_m = pax_find_mirror_vma(vma);
70291 + if (!vma_m)
70292 + return;
70293 +
70294 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70295 + address_m = address + SEGMEXEC_TASK_SIZE;
70296 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70297 + get_page(page_m);
70298 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70299 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70300 +}
70301 +#endif
70302 +
70303 /*
70304 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70305 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70306 @@ -2459,6 +2480,11 @@ retry_avoidcopy:
70307 make_huge_pte(vma, new_page, 1));
70308 page_remove_rmap(old_page);
70309 hugepage_add_new_anon_rmap(new_page, vma, address);
70310 +
70311 +#ifdef CONFIG_PAX_SEGMEXEC
70312 + pax_mirror_huge_pte(vma, address, new_page);
70313 +#endif
70314 +
70315 /* Make the old page be freed below */
70316 new_page = old_page;
70317 mmu_notifier_invalidate_range_end(mm,
70318 @@ -2613,6 +2639,10 @@ retry:
70319 && (vma->vm_flags & VM_SHARED)));
70320 set_huge_pte_at(mm, address, ptep, new_pte);
70321
70322 +#ifdef CONFIG_PAX_SEGMEXEC
70323 + pax_mirror_huge_pte(vma, address, page);
70324 +#endif
70325 +
70326 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70327 /* Optimization, do the COW without a second fault */
70328 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70329 @@ -2642,6 +2672,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70330 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70331 struct hstate *h = hstate_vma(vma);
70332
70333 +#ifdef CONFIG_PAX_SEGMEXEC
70334 + struct vm_area_struct *vma_m;
70335 +#endif
70336 +
70337 address &= huge_page_mask(h);
70338
70339 ptep = huge_pte_offset(mm, address);
70340 @@ -2655,6 +2689,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70341 VM_FAULT_SET_HINDEX(h - hstates);
70342 }
70343
70344 +#ifdef CONFIG_PAX_SEGMEXEC
70345 + vma_m = pax_find_mirror_vma(vma);
70346 + if (vma_m) {
70347 + unsigned long address_m;
70348 +
70349 + if (vma->vm_start > vma_m->vm_start) {
70350 + address_m = address;
70351 + address -= SEGMEXEC_TASK_SIZE;
70352 + vma = vma_m;
70353 + h = hstate_vma(vma);
70354 + } else
70355 + address_m = address + SEGMEXEC_TASK_SIZE;
70356 +
70357 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70358 + return VM_FAULT_OOM;
70359 + address_m &= HPAGE_MASK;
70360 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70361 + }
70362 +#endif
70363 +
70364 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70365 if (!ptep)
70366 return VM_FAULT_OOM;
70367 diff --git a/mm/internal.h b/mm/internal.h
70368 index 2189af4..f2ca332 100644
70369 --- a/mm/internal.h
70370 +++ b/mm/internal.h
70371 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70372 * in mm/page_alloc.c
70373 */
70374 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70375 +extern void free_compound_page(struct page *page);
70376 extern void prep_compound_page(struct page *page, unsigned long order);
70377 #ifdef CONFIG_MEMORY_FAILURE
70378 extern bool is_free_buddy_page(struct page *page);
70379 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70380 index 45eb621..6ccd8ea 100644
70381 --- a/mm/kmemleak.c
70382 +++ b/mm/kmemleak.c
70383 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70384
70385 for (i = 0; i < object->trace_len; i++) {
70386 void *ptr = (void *)object->trace[i];
70387 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70388 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70389 }
70390 }
70391
70392 diff --git a/mm/maccess.c b/mm/maccess.c
70393 index d53adf9..03a24bf 100644
70394 --- a/mm/maccess.c
70395 +++ b/mm/maccess.c
70396 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70397 set_fs(KERNEL_DS);
70398 pagefault_disable();
70399 ret = __copy_from_user_inatomic(dst,
70400 - (__force const void __user *)src, size);
70401 + (const void __force_user *)src, size);
70402 pagefault_enable();
70403 set_fs(old_fs);
70404
70405 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70406
70407 set_fs(KERNEL_DS);
70408 pagefault_disable();
70409 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70410 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70411 pagefault_enable();
70412 set_fs(old_fs);
70413
70414 diff --git a/mm/madvise.c b/mm/madvise.c
70415 index 74bf193..feb6fd3 100644
70416 --- a/mm/madvise.c
70417 +++ b/mm/madvise.c
70418 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70419 pgoff_t pgoff;
70420 unsigned long new_flags = vma->vm_flags;
70421
70422 +#ifdef CONFIG_PAX_SEGMEXEC
70423 + struct vm_area_struct *vma_m;
70424 +#endif
70425 +
70426 switch (behavior) {
70427 case MADV_NORMAL:
70428 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70429 @@ -110,6 +114,13 @@ success:
70430 /*
70431 * vm_flags is protected by the mmap_sem held in write mode.
70432 */
70433 +
70434 +#ifdef CONFIG_PAX_SEGMEXEC
70435 + vma_m = pax_find_mirror_vma(vma);
70436 + if (vma_m)
70437 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70438 +#endif
70439 +
70440 vma->vm_flags = new_flags;
70441
70442 out:
70443 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70444 struct vm_area_struct ** prev,
70445 unsigned long start, unsigned long end)
70446 {
70447 +
70448 +#ifdef CONFIG_PAX_SEGMEXEC
70449 + struct vm_area_struct *vma_m;
70450 +#endif
70451 +
70452 *prev = vma;
70453 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70454 return -EINVAL;
70455 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70456 zap_page_range(vma, start, end - start, &details);
70457 } else
70458 zap_page_range(vma, start, end - start, NULL);
70459 +
70460 +#ifdef CONFIG_PAX_SEGMEXEC
70461 + vma_m = pax_find_mirror_vma(vma);
70462 + if (vma_m) {
70463 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70464 + struct zap_details details = {
70465 + .nonlinear_vma = vma_m,
70466 + .last_index = ULONG_MAX,
70467 + };
70468 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70469 + } else
70470 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70471 + }
70472 +#endif
70473 +
70474 return 0;
70475 }
70476
70477 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70478 if (end < start)
70479 goto out;
70480
70481 +#ifdef CONFIG_PAX_SEGMEXEC
70482 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70483 + if (end > SEGMEXEC_TASK_SIZE)
70484 + goto out;
70485 + } else
70486 +#endif
70487 +
70488 + if (end > TASK_SIZE)
70489 + goto out;
70490 +
70491 error = 0;
70492 if (end == start)
70493 goto out;
70494 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70495 index 56080ea..115071e 100644
70496 --- a/mm/memory-failure.c
70497 +++ b/mm/memory-failure.c
70498 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70499
70500 int sysctl_memory_failure_recovery __read_mostly = 1;
70501
70502 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70503 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70504
70505 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70506
70507 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70508 si.si_signo = SIGBUS;
70509 si.si_errno = 0;
70510 si.si_code = BUS_MCEERR_AO;
70511 - si.si_addr = (void *)addr;
70512 + si.si_addr = (void __user *)addr;
70513 #ifdef __ARCH_SI_TRAPNO
70514 si.si_trapno = trapno;
70515 #endif
70516 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70517 }
70518
70519 nr_pages = 1 << compound_trans_order(hpage);
70520 - atomic_long_add(nr_pages, &mce_bad_pages);
70521 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70522
70523 /*
70524 * We need/can do nothing about count=0 pages.
70525 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70526 if (!PageHWPoison(hpage)
70527 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70528 || (p != hpage && TestSetPageHWPoison(hpage))) {
70529 - atomic_long_sub(nr_pages, &mce_bad_pages);
70530 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70531 return 0;
70532 }
70533 set_page_hwpoison_huge_page(hpage);
70534 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70535 }
70536 if (hwpoison_filter(p)) {
70537 if (TestClearPageHWPoison(p))
70538 - atomic_long_sub(nr_pages, &mce_bad_pages);
70539 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70540 unlock_page(hpage);
70541 put_page(hpage);
70542 return 0;
70543 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70544 return 0;
70545 }
70546 if (TestClearPageHWPoison(p))
70547 - atomic_long_sub(nr_pages, &mce_bad_pages);
70548 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70549 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70550 return 0;
70551 }
70552 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70553 */
70554 if (TestClearPageHWPoison(page)) {
70555 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70556 - atomic_long_sub(nr_pages, &mce_bad_pages);
70557 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70558 freeit = 1;
70559 if (PageHuge(page))
70560 clear_page_hwpoison_huge_page(page);
70561 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70562 }
70563 done:
70564 if (!PageHWPoison(hpage))
70565 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70566 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70567 set_page_hwpoison_huge_page(hpage);
70568 dequeue_hwpoisoned_huge_page(hpage);
70569 /* keep elevated page count for bad page */
70570 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70571 return ret;
70572
70573 done:
70574 - atomic_long_add(1, &mce_bad_pages);
70575 + atomic_long_add_unchecked(1, &mce_bad_pages);
70576 SetPageHWPoison(page);
70577 /* keep elevated page count for bad page */
70578 return ret;
70579 diff --git a/mm/memory.c b/mm/memory.c
70580 index 10b4dda..764ee07 100644
70581 --- a/mm/memory.c
70582 +++ b/mm/memory.c
70583 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70584 return;
70585
70586 pmd = pmd_offset(pud, start);
70587 +
70588 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70589 pud_clear(pud);
70590 pmd_free_tlb(tlb, pmd, start);
70591 +#endif
70592 +
70593 }
70594
70595 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70596 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70597 if (end - 1 > ceiling - 1)
70598 return;
70599
70600 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70601 pud = pud_offset(pgd, start);
70602 pgd_clear(pgd);
70603 pud_free_tlb(tlb, pud, start);
70604 +#endif
70605 +
70606 }
70607
70608 /*
70609 @@ -1593,12 +1600,6 @@ no_page_table:
70610 return page;
70611 }
70612
70613 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70614 -{
70615 - return stack_guard_page_start(vma, addr) ||
70616 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70617 -}
70618 -
70619 /**
70620 * __get_user_pages() - pin user pages in memory
70621 * @tsk: task_struct of target task
70622 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70623 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70624 i = 0;
70625
70626 - do {
70627 + while (nr_pages) {
70628 struct vm_area_struct *vma;
70629
70630 - vma = find_extend_vma(mm, start);
70631 + vma = find_vma(mm, start);
70632 if (!vma && in_gate_area(mm, start)) {
70633 unsigned long pg = start & PAGE_MASK;
70634 pgd_t *pgd;
70635 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70636 goto next_page;
70637 }
70638
70639 - if (!vma ||
70640 + if (!vma || start < vma->vm_start ||
70641 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70642 !(vm_flags & vma->vm_flags))
70643 return i ? : -EFAULT;
70644 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70645 int ret;
70646 unsigned int fault_flags = 0;
70647
70648 - /* For mlock, just skip the stack guard page. */
70649 - if (foll_flags & FOLL_MLOCK) {
70650 - if (stack_guard_page(vma, start))
70651 - goto next_page;
70652 - }
70653 if (foll_flags & FOLL_WRITE)
70654 fault_flags |= FAULT_FLAG_WRITE;
70655 if (nonblocking)
70656 @@ -1827,7 +1823,7 @@ next_page:
70657 start += PAGE_SIZE;
70658 nr_pages--;
70659 } while (nr_pages && start < vma->vm_end);
70660 - } while (nr_pages);
70661 + }
70662 return i;
70663 }
70664 EXPORT_SYMBOL(__get_user_pages);
70665 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70666 page_add_file_rmap(page);
70667 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70668
70669 +#ifdef CONFIG_PAX_SEGMEXEC
70670 + pax_mirror_file_pte(vma, addr, page, ptl);
70671 +#endif
70672 +
70673 retval = 0;
70674 pte_unmap_unlock(pte, ptl);
70675 return retval;
70676 @@ -2068,10 +2068,22 @@ out:
70677 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70678 struct page *page)
70679 {
70680 +
70681 +#ifdef CONFIG_PAX_SEGMEXEC
70682 + struct vm_area_struct *vma_m;
70683 +#endif
70684 +
70685 if (addr < vma->vm_start || addr >= vma->vm_end)
70686 return -EFAULT;
70687 if (!page_count(page))
70688 return -EINVAL;
70689 +
70690 +#ifdef CONFIG_PAX_SEGMEXEC
70691 + vma_m = pax_find_mirror_vma(vma);
70692 + if (vma_m)
70693 + vma_m->vm_flags |= VM_INSERTPAGE;
70694 +#endif
70695 +
70696 vma->vm_flags |= VM_INSERTPAGE;
70697 return insert_page(vma, addr, page, vma->vm_page_prot);
70698 }
70699 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70700 unsigned long pfn)
70701 {
70702 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70703 + BUG_ON(vma->vm_mirror);
70704
70705 if (addr < vma->vm_start || addr >= vma->vm_end)
70706 return -EFAULT;
70707 @@ -2472,6 +2485,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70708 copy_user_highpage(dst, src, va, vma);
70709 }
70710
70711 +#ifdef CONFIG_PAX_SEGMEXEC
70712 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70713 +{
70714 + struct mm_struct *mm = vma->vm_mm;
70715 + spinlock_t *ptl;
70716 + pte_t *pte, entry;
70717 +
70718 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70719 + entry = *pte;
70720 + if (!pte_present(entry)) {
70721 + if (!pte_none(entry)) {
70722 + BUG_ON(pte_file(entry));
70723 + free_swap_and_cache(pte_to_swp_entry(entry));
70724 + pte_clear_not_present_full(mm, address, pte, 0);
70725 + }
70726 + } else {
70727 + struct page *page;
70728 +
70729 + flush_cache_page(vma, address, pte_pfn(entry));
70730 + entry = ptep_clear_flush(vma, address, pte);
70731 + BUG_ON(pte_dirty(entry));
70732 + page = vm_normal_page(vma, address, entry);
70733 + if (page) {
70734 + update_hiwater_rss(mm);
70735 + if (PageAnon(page))
70736 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70737 + else
70738 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70739 + page_remove_rmap(page);
70740 + page_cache_release(page);
70741 + }
70742 + }
70743 + pte_unmap_unlock(pte, ptl);
70744 +}
70745 +
70746 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70747 + *
70748 + * the ptl of the lower mapped page is held on entry and is not released on exit
70749 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70750 + */
70751 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70752 +{
70753 + struct mm_struct *mm = vma->vm_mm;
70754 + unsigned long address_m;
70755 + spinlock_t *ptl_m;
70756 + struct vm_area_struct *vma_m;
70757 + pmd_t *pmd_m;
70758 + pte_t *pte_m, entry_m;
70759 +
70760 + BUG_ON(!page_m || !PageAnon(page_m));
70761 +
70762 + vma_m = pax_find_mirror_vma(vma);
70763 + if (!vma_m)
70764 + return;
70765 +
70766 + BUG_ON(!PageLocked(page_m));
70767 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70768 + address_m = address + SEGMEXEC_TASK_SIZE;
70769 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70770 + pte_m = pte_offset_map(pmd_m, address_m);
70771 + ptl_m = pte_lockptr(mm, pmd_m);
70772 + if (ptl != ptl_m) {
70773 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70774 + if (!pte_none(*pte_m))
70775 + goto out;
70776 + }
70777 +
70778 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70779 + page_cache_get(page_m);
70780 + page_add_anon_rmap(page_m, vma_m, address_m);
70781 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70782 + set_pte_at(mm, address_m, pte_m, entry_m);
70783 + update_mmu_cache(vma_m, address_m, entry_m);
70784 +out:
70785 + if (ptl != ptl_m)
70786 + spin_unlock(ptl_m);
70787 + pte_unmap(pte_m);
70788 + unlock_page(page_m);
70789 +}
70790 +
70791 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70792 +{
70793 + struct mm_struct *mm = vma->vm_mm;
70794 + unsigned long address_m;
70795 + spinlock_t *ptl_m;
70796 + struct vm_area_struct *vma_m;
70797 + pmd_t *pmd_m;
70798 + pte_t *pte_m, entry_m;
70799 +
70800 + BUG_ON(!page_m || PageAnon(page_m));
70801 +
70802 + vma_m = pax_find_mirror_vma(vma);
70803 + if (!vma_m)
70804 + return;
70805 +
70806 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70807 + address_m = address + SEGMEXEC_TASK_SIZE;
70808 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70809 + pte_m = pte_offset_map(pmd_m, address_m);
70810 + ptl_m = pte_lockptr(mm, pmd_m);
70811 + if (ptl != ptl_m) {
70812 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70813 + if (!pte_none(*pte_m))
70814 + goto out;
70815 + }
70816 +
70817 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70818 + page_cache_get(page_m);
70819 + page_add_file_rmap(page_m);
70820 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70821 + set_pte_at(mm, address_m, pte_m, entry_m);
70822 + update_mmu_cache(vma_m, address_m, entry_m);
70823 +out:
70824 + if (ptl != ptl_m)
70825 + spin_unlock(ptl_m);
70826 + pte_unmap(pte_m);
70827 +}
70828 +
70829 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70830 +{
70831 + struct mm_struct *mm = vma->vm_mm;
70832 + unsigned long address_m;
70833 + spinlock_t *ptl_m;
70834 + struct vm_area_struct *vma_m;
70835 + pmd_t *pmd_m;
70836 + pte_t *pte_m, entry_m;
70837 +
70838 + vma_m = pax_find_mirror_vma(vma);
70839 + if (!vma_m)
70840 + return;
70841 +
70842 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70843 + address_m = address + SEGMEXEC_TASK_SIZE;
70844 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70845 + pte_m = pte_offset_map(pmd_m, address_m);
70846 + ptl_m = pte_lockptr(mm, pmd_m);
70847 + if (ptl != ptl_m) {
70848 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70849 + if (!pte_none(*pte_m))
70850 + goto out;
70851 + }
70852 +
70853 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70854 + set_pte_at(mm, address_m, pte_m, entry_m);
70855 +out:
70856 + if (ptl != ptl_m)
70857 + spin_unlock(ptl_m);
70858 + pte_unmap(pte_m);
70859 +}
70860 +
70861 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70862 +{
70863 + struct page *page_m;
70864 + pte_t entry;
70865 +
70866 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70867 + goto out;
70868 +
70869 + entry = *pte;
70870 + page_m = vm_normal_page(vma, address, entry);
70871 + if (!page_m)
70872 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70873 + else if (PageAnon(page_m)) {
70874 + if (pax_find_mirror_vma(vma)) {
70875 + pte_unmap_unlock(pte, ptl);
70876 + lock_page(page_m);
70877 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70878 + if (pte_same(entry, *pte))
70879 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70880 + else
70881 + unlock_page(page_m);
70882 + }
70883 + } else
70884 + pax_mirror_file_pte(vma, address, page_m, ptl);
70885 +
70886 +out:
70887 + pte_unmap_unlock(pte, ptl);
70888 +}
70889 +#endif
70890 +
70891 /*
70892 * This routine handles present pages, when users try to write
70893 * to a shared page. It is done by copying the page to a new address
70894 @@ -2683,6 +2876,12 @@ gotten:
70895 */
70896 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70897 if (likely(pte_same(*page_table, orig_pte))) {
70898 +
70899 +#ifdef CONFIG_PAX_SEGMEXEC
70900 + if (pax_find_mirror_vma(vma))
70901 + BUG_ON(!trylock_page(new_page));
70902 +#endif
70903 +
70904 if (old_page) {
70905 if (!PageAnon(old_page)) {
70906 dec_mm_counter_fast(mm, MM_FILEPAGES);
70907 @@ -2734,6 +2933,10 @@ gotten:
70908 page_remove_rmap(old_page);
70909 }
70910
70911 +#ifdef CONFIG_PAX_SEGMEXEC
70912 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70913 +#endif
70914 +
70915 /* Free the old page.. */
70916 new_page = old_page;
70917 ret |= VM_FAULT_WRITE;
70918 @@ -3013,6 +3216,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70919 swap_free(entry);
70920 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70921 try_to_free_swap(page);
70922 +
70923 +#ifdef CONFIG_PAX_SEGMEXEC
70924 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70925 +#endif
70926 +
70927 unlock_page(page);
70928 if (swapcache) {
70929 /*
70930 @@ -3036,6 +3244,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70931
70932 /* No need to invalidate - it was non-present before */
70933 update_mmu_cache(vma, address, page_table);
70934 +
70935 +#ifdef CONFIG_PAX_SEGMEXEC
70936 + pax_mirror_anon_pte(vma, address, page, ptl);
70937 +#endif
70938 +
70939 unlock:
70940 pte_unmap_unlock(page_table, ptl);
70941 out:
70942 @@ -3055,40 +3268,6 @@ out_release:
70943 }
70944
70945 /*
70946 - * This is like a special single-page "expand_{down|up}wards()",
70947 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70948 - * doesn't hit another vma.
70949 - */
70950 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70951 -{
70952 - address &= PAGE_MASK;
70953 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70954 - struct vm_area_struct *prev = vma->vm_prev;
70955 -
70956 - /*
70957 - * Is there a mapping abutting this one below?
70958 - *
70959 - * That's only ok if it's the same stack mapping
70960 - * that has gotten split..
70961 - */
70962 - if (prev && prev->vm_end == address)
70963 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70964 -
70965 - expand_downwards(vma, address - PAGE_SIZE);
70966 - }
70967 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70968 - struct vm_area_struct *next = vma->vm_next;
70969 -
70970 - /* As VM_GROWSDOWN but s/below/above/ */
70971 - if (next && next->vm_start == address + PAGE_SIZE)
70972 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70973 -
70974 - expand_upwards(vma, address + PAGE_SIZE);
70975 - }
70976 - return 0;
70977 -}
70978 -
70979 -/*
70980 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70981 * but allow concurrent faults), and pte mapped but not yet locked.
70982 * We return with mmap_sem still held, but pte unmapped and unlocked.
70983 @@ -3097,27 +3276,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70984 unsigned long address, pte_t *page_table, pmd_t *pmd,
70985 unsigned int flags)
70986 {
70987 - struct page *page;
70988 + struct page *page = NULL;
70989 spinlock_t *ptl;
70990 pte_t entry;
70991
70992 - pte_unmap(page_table);
70993 -
70994 - /* Check if we need to add a guard page to the stack */
70995 - if (check_stack_guard_page(vma, address) < 0)
70996 - return VM_FAULT_SIGBUS;
70997 -
70998 - /* Use the zero-page for reads */
70999 if (!(flags & FAULT_FLAG_WRITE)) {
71000 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71001 vma->vm_page_prot));
71002 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71003 + ptl = pte_lockptr(mm, pmd);
71004 + spin_lock(ptl);
71005 if (!pte_none(*page_table))
71006 goto unlock;
71007 goto setpte;
71008 }
71009
71010 /* Allocate our own private page. */
71011 + pte_unmap(page_table);
71012 +
71013 if (unlikely(anon_vma_prepare(vma)))
71014 goto oom;
71015 page = alloc_zeroed_user_highpage_movable(vma, address);
71016 @@ -3136,6 +3311,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71017 if (!pte_none(*page_table))
71018 goto release;
71019
71020 +#ifdef CONFIG_PAX_SEGMEXEC
71021 + if (pax_find_mirror_vma(vma))
71022 + BUG_ON(!trylock_page(page));
71023 +#endif
71024 +
71025 inc_mm_counter_fast(mm, MM_ANONPAGES);
71026 page_add_new_anon_rmap(page, vma, address);
71027 setpte:
71028 @@ -3143,6 +3323,12 @@ setpte:
71029
71030 /* No need to invalidate - it was non-present before */
71031 update_mmu_cache(vma, address, page_table);
71032 +
71033 +#ifdef CONFIG_PAX_SEGMEXEC
71034 + if (page)
71035 + pax_mirror_anon_pte(vma, address, page, ptl);
71036 +#endif
71037 +
71038 unlock:
71039 pte_unmap_unlock(page_table, ptl);
71040 return 0;
71041 @@ -3286,6 +3472,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71042 */
71043 /* Only go through if we didn't race with anybody else... */
71044 if (likely(pte_same(*page_table, orig_pte))) {
71045 +
71046 +#ifdef CONFIG_PAX_SEGMEXEC
71047 + if (anon && pax_find_mirror_vma(vma))
71048 + BUG_ON(!trylock_page(page));
71049 +#endif
71050 +
71051 flush_icache_page(vma, page);
71052 entry = mk_pte(page, vma->vm_page_prot);
71053 if (flags & FAULT_FLAG_WRITE)
71054 @@ -3305,6 +3497,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71055
71056 /* no need to invalidate: a not-present page won't be cached */
71057 update_mmu_cache(vma, address, page_table);
71058 +
71059 +#ifdef CONFIG_PAX_SEGMEXEC
71060 + if (anon)
71061 + pax_mirror_anon_pte(vma, address, page, ptl);
71062 + else
71063 + pax_mirror_file_pte(vma, address, page, ptl);
71064 +#endif
71065 +
71066 } else {
71067 if (cow_page)
71068 mem_cgroup_uncharge_page(cow_page);
71069 @@ -3458,6 +3658,12 @@ int handle_pte_fault(struct mm_struct *mm,
71070 if (flags & FAULT_FLAG_WRITE)
71071 flush_tlb_fix_spurious_fault(vma, address);
71072 }
71073 +
71074 +#ifdef CONFIG_PAX_SEGMEXEC
71075 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71076 + return 0;
71077 +#endif
71078 +
71079 unlock:
71080 pte_unmap_unlock(pte, ptl);
71081 return 0;
71082 @@ -3474,6 +3680,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71083 pmd_t *pmd;
71084 pte_t *pte;
71085
71086 +#ifdef CONFIG_PAX_SEGMEXEC
71087 + struct vm_area_struct *vma_m;
71088 +#endif
71089 +
71090 __set_current_state(TASK_RUNNING);
71091
71092 count_vm_event(PGFAULT);
71093 @@ -3485,6 +3695,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71094 if (unlikely(is_vm_hugetlb_page(vma)))
71095 return hugetlb_fault(mm, vma, address, flags);
71096
71097 +#ifdef CONFIG_PAX_SEGMEXEC
71098 + vma_m = pax_find_mirror_vma(vma);
71099 + if (vma_m) {
71100 + unsigned long address_m;
71101 + pgd_t *pgd_m;
71102 + pud_t *pud_m;
71103 + pmd_t *pmd_m;
71104 +
71105 + if (vma->vm_start > vma_m->vm_start) {
71106 + address_m = address;
71107 + address -= SEGMEXEC_TASK_SIZE;
71108 + vma = vma_m;
71109 + } else
71110 + address_m = address + SEGMEXEC_TASK_SIZE;
71111 +
71112 + pgd_m = pgd_offset(mm, address_m);
71113 + pud_m = pud_alloc(mm, pgd_m, address_m);
71114 + if (!pud_m)
71115 + return VM_FAULT_OOM;
71116 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71117 + if (!pmd_m)
71118 + return VM_FAULT_OOM;
71119 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71120 + return VM_FAULT_OOM;
71121 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71122 + }
71123 +#endif
71124 +
71125 pgd = pgd_offset(mm, address);
71126 pud = pud_alloc(mm, pgd, address);
71127 if (!pud)
71128 @@ -3514,7 +3752,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71129 * run pte_offset_map on the pmd, if an huge pmd could
71130 * materialize from under us from a different thread.
71131 */
71132 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71133 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71134 return VM_FAULT_OOM;
71135 /* if an huge pmd materialized from under us just retry later */
71136 if (unlikely(pmd_trans_huge(*pmd)))
71137 @@ -3618,7 +3856,7 @@ static int __init gate_vma_init(void)
71138 gate_vma.vm_start = FIXADDR_USER_START;
71139 gate_vma.vm_end = FIXADDR_USER_END;
71140 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71141 - gate_vma.vm_page_prot = __P101;
71142 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71143 /*
71144 * Make sure the vDSO gets into every core dump.
71145 * Dumping its contents makes post-mortem fully interpretable later
71146 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71147 index 0a37570..2048346 100644
71148 --- a/mm/mempolicy.c
71149 +++ b/mm/mempolicy.c
71150 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71151 unsigned long vmstart;
71152 unsigned long vmend;
71153
71154 +#ifdef CONFIG_PAX_SEGMEXEC
71155 + struct vm_area_struct *vma_m;
71156 +#endif
71157 +
71158 vma = find_vma(mm, start);
71159 if (!vma || vma->vm_start > start)
71160 return -EFAULT;
71161 @@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71162 err = policy_vma(vma, new_pol);
71163 if (err)
71164 goto out;
71165 +
71166 +#ifdef CONFIG_PAX_SEGMEXEC
71167 + vma_m = pax_find_mirror_vma(vma);
71168 + if (vma_m) {
71169 + err = policy_vma(vma_m, new_pol);
71170 + if (err)
71171 + goto out;
71172 + }
71173 +#endif
71174 +
71175 }
71176
71177 out:
71178 @@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71179
71180 if (end < start)
71181 return -EINVAL;
71182 +
71183 +#ifdef CONFIG_PAX_SEGMEXEC
71184 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71185 + if (end > SEGMEXEC_TASK_SIZE)
71186 + return -EINVAL;
71187 + } else
71188 +#endif
71189 +
71190 + if (end > TASK_SIZE)
71191 + return -EINVAL;
71192 +
71193 if (end == start)
71194 return 0;
71195
71196 @@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71197 if (!mm)
71198 goto out;
71199
71200 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71201 + if (mm != current->mm &&
71202 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71203 + err = -EPERM;
71204 + goto out;
71205 + }
71206 +#endif
71207 +
71208 /*
71209 * Check if this process has the right to modify the specified
71210 * process. The right exists if the process has administrative
71211 @@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71212 rcu_read_lock();
71213 tcred = __task_cred(task);
71214 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71215 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71216 - !capable(CAP_SYS_NICE)) {
71217 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71218 rcu_read_unlock();
71219 err = -EPERM;
71220 goto out;
71221 diff --git a/mm/migrate.c b/mm/migrate.c
71222 index 1503b6b..156c672 100644
71223 --- a/mm/migrate.c
71224 +++ b/mm/migrate.c
71225 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71226 if (!mm)
71227 return -EINVAL;
71228
71229 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71230 + if (mm != current->mm &&
71231 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71232 + err = -EPERM;
71233 + goto out;
71234 + }
71235 +#endif
71236 +
71237 /*
71238 * Check if this process has the right to modify the specified
71239 * process. The right exists if the process has administrative
71240 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71241 rcu_read_lock();
71242 tcred = __task_cred(task);
71243 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71244 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71245 - !capable(CAP_SYS_NICE)) {
71246 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71247 rcu_read_unlock();
71248 err = -EPERM;
71249 goto out;
71250 diff --git a/mm/mlock.c b/mm/mlock.c
71251 index ef726e8..13e0901 100644
71252 --- a/mm/mlock.c
71253 +++ b/mm/mlock.c
71254 @@ -13,6 +13,7 @@
71255 #include <linux/pagemap.h>
71256 #include <linux/mempolicy.h>
71257 #include <linux/syscalls.h>
71258 +#include <linux/security.h>
71259 #include <linux/sched.h>
71260 #include <linux/export.h>
71261 #include <linux/rmap.h>
71262 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71263 return -EINVAL;
71264 if (end == start)
71265 return 0;
71266 + if (end > TASK_SIZE)
71267 + return -EINVAL;
71268 +
71269 vma = find_vma(current->mm, start);
71270 if (!vma || vma->vm_start > start)
71271 return -ENOMEM;
71272 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71273 for (nstart = start ; ; ) {
71274 vm_flags_t newflags;
71275
71276 +#ifdef CONFIG_PAX_SEGMEXEC
71277 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71278 + break;
71279 +#endif
71280 +
71281 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71282
71283 newflags = vma->vm_flags | VM_LOCKED;
71284 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71285 lock_limit >>= PAGE_SHIFT;
71286
71287 /* check against resource limits */
71288 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71289 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71290 error = do_mlock(start, len, 1);
71291 up_write(&current->mm->mmap_sem);
71292 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71293 static int do_mlockall(int flags)
71294 {
71295 struct vm_area_struct * vma, * prev = NULL;
71296 - unsigned int def_flags = 0;
71297
71298 if (flags & MCL_FUTURE)
71299 - def_flags = VM_LOCKED;
71300 - current->mm->def_flags = def_flags;
71301 + current->mm->def_flags |= VM_LOCKED;
71302 + else
71303 + current->mm->def_flags &= ~VM_LOCKED;
71304 if (flags == MCL_FUTURE)
71305 goto out;
71306
71307 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71308 vm_flags_t newflags;
71309
71310 +#ifdef CONFIG_PAX_SEGMEXEC
71311 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71312 + break;
71313 +#endif
71314 +
71315 + BUG_ON(vma->vm_end > TASK_SIZE);
71316 newflags = vma->vm_flags | VM_LOCKED;
71317 if (!(flags & MCL_CURRENT))
71318 newflags &= ~VM_LOCKED;
71319 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71320 lock_limit >>= PAGE_SHIFT;
71321
71322 ret = -ENOMEM;
71323 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71324 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71325 capable(CAP_IPC_LOCK))
71326 ret = do_mlockall(flags);
71327 diff --git a/mm/mmap.c b/mm/mmap.c
71328 index da15a79..314aef3 100644
71329 --- a/mm/mmap.c
71330 +++ b/mm/mmap.c
71331 @@ -46,6 +46,16 @@
71332 #define arch_rebalance_pgtables(addr, len) (addr)
71333 #endif
71334
71335 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71336 +{
71337 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71338 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71339 + up_read(&mm->mmap_sem);
71340 + BUG();
71341 + }
71342 +#endif
71343 +}
71344 +
71345 static void unmap_region(struct mm_struct *mm,
71346 struct vm_area_struct *vma, struct vm_area_struct *prev,
71347 unsigned long start, unsigned long end);
71348 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71349 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71350 *
71351 */
71352 -pgprot_t protection_map[16] = {
71353 +pgprot_t protection_map[16] __read_only = {
71354 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71355 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71356 };
71357
71358 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71359 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71360 {
71361 - return __pgprot(pgprot_val(protection_map[vm_flags &
71362 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71363 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71364 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71365 +
71366 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71367 + if (!(__supported_pte_mask & _PAGE_NX) &&
71368 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71369 + (vm_flags & (VM_READ | VM_WRITE)))
71370 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71371 +#endif
71372 +
71373 + return prot;
71374 }
71375 EXPORT_SYMBOL(vm_get_page_prot);
71376
71377 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71378 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71379 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71380 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71381 /*
71382 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71383 * other variables. It can be updated by several CPUs frequently.
71384 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71385 struct vm_area_struct *next = vma->vm_next;
71386
71387 might_sleep();
71388 + BUG_ON(vma->vm_mirror);
71389 if (vma->vm_ops && vma->vm_ops->close)
71390 vma->vm_ops->close(vma);
71391 if (vma->vm_file) {
71392 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71393 * not page aligned -Ram Gupta
71394 */
71395 rlim = rlimit(RLIMIT_DATA);
71396 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71397 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71398 (mm->end_data - mm->start_data) > rlim)
71399 goto out;
71400 @@ -689,6 +711,12 @@ static int
71401 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71402 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71403 {
71404 +
71405 +#ifdef CONFIG_PAX_SEGMEXEC
71406 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71407 + return 0;
71408 +#endif
71409 +
71410 if (is_mergeable_vma(vma, file, vm_flags) &&
71411 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71412 if (vma->vm_pgoff == vm_pgoff)
71413 @@ -708,6 +736,12 @@ static int
71414 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71415 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71416 {
71417 +
71418 +#ifdef CONFIG_PAX_SEGMEXEC
71419 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71420 + return 0;
71421 +#endif
71422 +
71423 if (is_mergeable_vma(vma, file, vm_flags) &&
71424 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71425 pgoff_t vm_pglen;
71426 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71427 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71428 struct vm_area_struct *prev, unsigned long addr,
71429 unsigned long end, unsigned long vm_flags,
71430 - struct anon_vma *anon_vma, struct file *file,
71431 + struct anon_vma *anon_vma, struct file *file,
71432 pgoff_t pgoff, struct mempolicy *policy)
71433 {
71434 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71435 struct vm_area_struct *area, *next;
71436 int err;
71437
71438 +#ifdef CONFIG_PAX_SEGMEXEC
71439 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71440 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71441 +
71442 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71443 +#endif
71444 +
71445 /*
71446 * We later require that vma->vm_flags == vm_flags,
71447 * so this tests vma->vm_flags & VM_SPECIAL, too.
71448 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71449 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71450 next = next->vm_next;
71451
71452 +#ifdef CONFIG_PAX_SEGMEXEC
71453 + if (prev)
71454 + prev_m = pax_find_mirror_vma(prev);
71455 + if (area)
71456 + area_m = pax_find_mirror_vma(area);
71457 + if (next)
71458 + next_m = pax_find_mirror_vma(next);
71459 +#endif
71460 +
71461 /*
71462 * Can it merge with the predecessor?
71463 */
71464 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71465 /* cases 1, 6 */
71466 err = vma_adjust(prev, prev->vm_start,
71467 next->vm_end, prev->vm_pgoff, NULL);
71468 - } else /* cases 2, 5, 7 */
71469 +
71470 +#ifdef CONFIG_PAX_SEGMEXEC
71471 + if (!err && prev_m)
71472 + err = vma_adjust(prev_m, prev_m->vm_start,
71473 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71474 +#endif
71475 +
71476 + } else { /* cases 2, 5, 7 */
71477 err = vma_adjust(prev, prev->vm_start,
71478 end, prev->vm_pgoff, NULL);
71479 +
71480 +#ifdef CONFIG_PAX_SEGMEXEC
71481 + if (!err && prev_m)
71482 + err = vma_adjust(prev_m, prev_m->vm_start,
71483 + end_m, prev_m->vm_pgoff, NULL);
71484 +#endif
71485 +
71486 + }
71487 if (err)
71488 return NULL;
71489 khugepaged_enter_vma_merge(prev);
71490 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71491 mpol_equal(policy, vma_policy(next)) &&
71492 can_vma_merge_before(next, vm_flags,
71493 anon_vma, file, pgoff+pglen)) {
71494 - if (prev && addr < prev->vm_end) /* case 4 */
71495 + if (prev && addr < prev->vm_end) { /* case 4 */
71496 err = vma_adjust(prev, prev->vm_start,
71497 addr, prev->vm_pgoff, NULL);
71498 - else /* cases 3, 8 */
71499 +
71500 +#ifdef CONFIG_PAX_SEGMEXEC
71501 + if (!err && prev_m)
71502 + err = vma_adjust(prev_m, prev_m->vm_start,
71503 + addr_m, prev_m->vm_pgoff, NULL);
71504 +#endif
71505 +
71506 + } else { /* cases 3, 8 */
71507 err = vma_adjust(area, addr, next->vm_end,
71508 next->vm_pgoff - pglen, NULL);
71509 +
71510 +#ifdef CONFIG_PAX_SEGMEXEC
71511 + if (!err && area_m)
71512 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71513 + next_m->vm_pgoff - pglen, NULL);
71514 +#endif
71515 +
71516 + }
71517 if (err)
71518 return NULL;
71519 khugepaged_enter_vma_merge(area);
71520 @@ -921,14 +1001,11 @@ none:
71521 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71522 struct file *file, long pages)
71523 {
71524 - const unsigned long stack_flags
71525 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71526 -
71527 if (file) {
71528 mm->shared_vm += pages;
71529 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71530 mm->exec_vm += pages;
71531 - } else if (flags & stack_flags)
71532 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71533 mm->stack_vm += pages;
71534 if (flags & (VM_RESERVED|VM_IO))
71535 mm->reserved_vm += pages;
71536 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71537 * (the exception is when the underlying filesystem is noexec
71538 * mounted, in which case we dont add PROT_EXEC.)
71539 */
71540 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71541 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71542 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71543 prot |= PROT_EXEC;
71544
71545 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71546 /* Obtain the address to map to. we verify (or select) it and ensure
71547 * that it represents a valid section of the address space.
71548 */
71549 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71550 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71551 if (addr & ~PAGE_MASK)
71552 return addr;
71553
71554 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71555 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71556 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71557
71558 +#ifdef CONFIG_PAX_MPROTECT
71559 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71560 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71561 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71562 + gr_log_rwxmmap(file);
71563 +
71564 +#ifdef CONFIG_PAX_EMUPLT
71565 + vm_flags &= ~VM_EXEC;
71566 +#else
71567 + return -EPERM;
71568 +#endif
71569 +
71570 + }
71571 +
71572 + if (!(vm_flags & VM_EXEC))
71573 + vm_flags &= ~VM_MAYEXEC;
71574 +#else
71575 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71576 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71577 +#endif
71578 + else
71579 + vm_flags &= ~VM_MAYWRITE;
71580 + }
71581 +#endif
71582 +
71583 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71584 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71585 + vm_flags &= ~VM_PAGEEXEC;
71586 +#endif
71587 +
71588 if (flags & MAP_LOCKED)
71589 if (!can_do_mlock())
71590 return -EPERM;
71591 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71592 locked += mm->locked_vm;
71593 lock_limit = rlimit(RLIMIT_MEMLOCK);
71594 lock_limit >>= PAGE_SHIFT;
71595 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71596 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71597 return -EAGAIN;
71598 }
71599 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71600 if (error)
71601 return error;
71602
71603 + if (!gr_acl_handle_mmap(file, prot))
71604 + return -EACCES;
71605 +
71606 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71607 }
71608 EXPORT_SYMBOL(do_mmap_pgoff);
71609 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71610 vm_flags_t vm_flags = vma->vm_flags;
71611
71612 /* If it was private or non-writable, the write bit is already clear */
71613 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71614 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71615 return 0;
71616
71617 /* The backer wishes to know when pages are first written to? */
71618 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71619 unsigned long charged = 0;
71620 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71621
71622 +#ifdef CONFIG_PAX_SEGMEXEC
71623 + struct vm_area_struct *vma_m = NULL;
71624 +#endif
71625 +
71626 + /*
71627 + * mm->mmap_sem is required to protect against another thread
71628 + * changing the mappings in case we sleep.
71629 + */
71630 + verify_mm_writelocked(mm);
71631 +
71632 /* Clear old maps */
71633 error = -ENOMEM;
71634 -munmap_back:
71635 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71636 if (vma && vma->vm_start < addr + len) {
71637 if (do_munmap(mm, addr, len))
71638 return -ENOMEM;
71639 - goto munmap_back;
71640 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71641 + BUG_ON(vma && vma->vm_start < addr + len);
71642 }
71643
71644 /* Check against address space limit. */
71645 @@ -1258,6 +1379,16 @@ munmap_back:
71646 goto unacct_error;
71647 }
71648
71649 +#ifdef CONFIG_PAX_SEGMEXEC
71650 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71651 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71652 + if (!vma_m) {
71653 + error = -ENOMEM;
71654 + goto free_vma;
71655 + }
71656 + }
71657 +#endif
71658 +
71659 vma->vm_mm = mm;
71660 vma->vm_start = addr;
71661 vma->vm_end = addr + len;
71662 @@ -1282,6 +1413,19 @@ munmap_back:
71663 error = file->f_op->mmap(file, vma);
71664 if (error)
71665 goto unmap_and_free_vma;
71666 +
71667 +#ifdef CONFIG_PAX_SEGMEXEC
71668 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71669 + added_exe_file_vma(mm);
71670 +#endif
71671 +
71672 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71673 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71674 + vma->vm_flags |= VM_PAGEEXEC;
71675 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71676 + }
71677 +#endif
71678 +
71679 if (vm_flags & VM_EXECUTABLE)
71680 added_exe_file_vma(mm);
71681
71682 @@ -1319,6 +1463,11 @@ munmap_back:
71683 vma_link(mm, vma, prev, rb_link, rb_parent);
71684 file = vma->vm_file;
71685
71686 +#ifdef CONFIG_PAX_SEGMEXEC
71687 + if (vma_m)
71688 + BUG_ON(pax_mirror_vma(vma_m, vma));
71689 +#endif
71690 +
71691 /* Once vma denies write, undo our temporary denial count */
71692 if (correct_wcount)
71693 atomic_inc(&inode->i_writecount);
71694 @@ -1327,6 +1476,7 @@ out:
71695
71696 mm->total_vm += len >> PAGE_SHIFT;
71697 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71698 + track_exec_limit(mm, addr, addr + len, vm_flags);
71699 if (vm_flags & VM_LOCKED) {
71700 if (!mlock_vma_pages_range(vma, addr, addr + len))
71701 mm->locked_vm += (len >> PAGE_SHIFT);
71702 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
71703 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71704 charged = 0;
71705 free_vma:
71706 +
71707 +#ifdef CONFIG_PAX_SEGMEXEC
71708 + if (vma_m)
71709 + kmem_cache_free(vm_area_cachep, vma_m);
71710 +#endif
71711 +
71712 kmem_cache_free(vm_area_cachep, vma);
71713 unacct_error:
71714 if (charged)
71715 @@ -1351,6 +1507,44 @@ unacct_error:
71716 return error;
71717 }
71718
71719 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71720 +{
71721 + if (!vma) {
71722 +#ifdef CONFIG_STACK_GROWSUP
71723 + if (addr > sysctl_heap_stack_gap)
71724 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71725 + else
71726 + vma = find_vma(current->mm, 0);
71727 + if (vma && (vma->vm_flags & VM_GROWSUP))
71728 + return false;
71729 +#endif
71730 + return true;
71731 + }
71732 +
71733 + if (addr + len > vma->vm_start)
71734 + return false;
71735 +
71736 + if (vma->vm_flags & VM_GROWSDOWN)
71737 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71738 +#ifdef CONFIG_STACK_GROWSUP
71739 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71740 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71741 +#endif
71742 +
71743 + return true;
71744 +}
71745 +
71746 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71747 +{
71748 + if (vma->vm_start < len)
71749 + return -ENOMEM;
71750 + if (!(vma->vm_flags & VM_GROWSDOWN))
71751 + return vma->vm_start - len;
71752 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71753 + return vma->vm_start - len - sysctl_heap_stack_gap;
71754 + return -ENOMEM;
71755 +}
71756 +
71757 /* Get an address range which is currently unmapped.
71758 * For shmat() with addr=0.
71759 *
71760 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71761 if (flags & MAP_FIXED)
71762 return addr;
71763
71764 +#ifdef CONFIG_PAX_RANDMMAP
71765 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71766 +#endif
71767 +
71768 if (addr) {
71769 addr = PAGE_ALIGN(addr);
71770 - vma = find_vma(mm, addr);
71771 - if (TASK_SIZE - len >= addr &&
71772 - (!vma || addr + len <= vma->vm_start))
71773 - return addr;
71774 + if (TASK_SIZE - len >= addr) {
71775 + vma = find_vma(mm, addr);
71776 + if (check_heap_stack_gap(vma, addr, len))
71777 + return addr;
71778 + }
71779 }
71780 if (len > mm->cached_hole_size) {
71781 - start_addr = addr = mm->free_area_cache;
71782 + start_addr = addr = mm->free_area_cache;
71783 } else {
71784 - start_addr = addr = TASK_UNMAPPED_BASE;
71785 - mm->cached_hole_size = 0;
71786 + start_addr = addr = mm->mmap_base;
71787 + mm->cached_hole_size = 0;
71788 }
71789
71790 full_search:
71791 @@ -1399,34 +1598,40 @@ full_search:
71792 * Start a new search - just in case we missed
71793 * some holes.
71794 */
71795 - if (start_addr != TASK_UNMAPPED_BASE) {
71796 - addr = TASK_UNMAPPED_BASE;
71797 - start_addr = addr;
71798 + if (start_addr != mm->mmap_base) {
71799 + start_addr = addr = mm->mmap_base;
71800 mm->cached_hole_size = 0;
71801 goto full_search;
71802 }
71803 return -ENOMEM;
71804 }
71805 - if (!vma || addr + len <= vma->vm_start) {
71806 - /*
71807 - * Remember the place where we stopped the search:
71808 - */
71809 - mm->free_area_cache = addr + len;
71810 - return addr;
71811 - }
71812 + if (check_heap_stack_gap(vma, addr, len))
71813 + break;
71814 if (addr + mm->cached_hole_size < vma->vm_start)
71815 mm->cached_hole_size = vma->vm_start - addr;
71816 addr = vma->vm_end;
71817 }
71818 +
71819 + /*
71820 + * Remember the place where we stopped the search:
71821 + */
71822 + mm->free_area_cache = addr + len;
71823 + return addr;
71824 }
71825 #endif
71826
71827 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71828 {
71829 +
71830 +#ifdef CONFIG_PAX_SEGMEXEC
71831 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71832 + return;
71833 +#endif
71834 +
71835 /*
71836 * Is this a new hole at the lowest possible address?
71837 */
71838 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71839 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71840 mm->free_area_cache = addr;
71841 mm->cached_hole_size = ~0UL;
71842 }
71843 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71844 {
71845 struct vm_area_struct *vma;
71846 struct mm_struct *mm = current->mm;
71847 - unsigned long addr = addr0;
71848 + unsigned long base = mm->mmap_base, addr = addr0;
71849
71850 /* requested length too big for entire address space */
71851 if (len > TASK_SIZE)
71852 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71853 if (flags & MAP_FIXED)
71854 return addr;
71855
71856 +#ifdef CONFIG_PAX_RANDMMAP
71857 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71858 +#endif
71859 +
71860 /* requesting a specific address */
71861 if (addr) {
71862 addr = PAGE_ALIGN(addr);
71863 - vma = find_vma(mm, addr);
71864 - if (TASK_SIZE - len >= addr &&
71865 - (!vma || addr + len <= vma->vm_start))
71866 - return addr;
71867 + if (TASK_SIZE - len >= addr) {
71868 + vma = find_vma(mm, addr);
71869 + if (check_heap_stack_gap(vma, addr, len))
71870 + return addr;
71871 + }
71872 }
71873
71874 /* check if free_area_cache is useful for us */
71875 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71876 /* make sure it can fit in the remaining address space */
71877 if (addr > len) {
71878 vma = find_vma(mm, addr-len);
71879 - if (!vma || addr <= vma->vm_start)
71880 + if (check_heap_stack_gap(vma, addr - len, len))
71881 /* remember the address as a hint for next time */
71882 return (mm->free_area_cache = addr-len);
71883 }
71884 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71885 * return with success:
71886 */
71887 vma = find_vma(mm, addr);
71888 - if (!vma || addr+len <= vma->vm_start)
71889 + if (check_heap_stack_gap(vma, addr, len))
71890 /* remember the address as a hint for next time */
71891 return (mm->free_area_cache = addr);
71892
71893 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71894 mm->cached_hole_size = vma->vm_start - addr;
71895
71896 /* try just below the current vma->vm_start */
71897 - addr = vma->vm_start-len;
71898 - } while (len < vma->vm_start);
71899 + addr = skip_heap_stack_gap(vma, len);
71900 + } while (!IS_ERR_VALUE(addr));
71901
71902 bottomup:
71903 /*
71904 @@ -1510,13 +1720,21 @@ bottomup:
71905 * can happen with large stack limits and large mmap()
71906 * allocations.
71907 */
71908 + mm->mmap_base = TASK_UNMAPPED_BASE;
71909 +
71910 +#ifdef CONFIG_PAX_RANDMMAP
71911 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71912 + mm->mmap_base += mm->delta_mmap;
71913 +#endif
71914 +
71915 + mm->free_area_cache = mm->mmap_base;
71916 mm->cached_hole_size = ~0UL;
71917 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71918 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71919 /*
71920 * Restore the topdown base:
71921 */
71922 - mm->free_area_cache = mm->mmap_base;
71923 + mm->mmap_base = base;
71924 + mm->free_area_cache = base;
71925 mm->cached_hole_size = ~0UL;
71926
71927 return addr;
71928 @@ -1525,6 +1743,12 @@ bottomup:
71929
71930 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71931 {
71932 +
71933 +#ifdef CONFIG_PAX_SEGMEXEC
71934 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71935 + return;
71936 +#endif
71937 +
71938 /*
71939 * Is this a new hole at the highest possible address?
71940 */
71941 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71942 mm->free_area_cache = addr;
71943
71944 /* dont allow allocations above current base */
71945 - if (mm->free_area_cache > mm->mmap_base)
71946 + if (mm->free_area_cache > mm->mmap_base) {
71947 mm->free_area_cache = mm->mmap_base;
71948 + mm->cached_hole_size = ~0UL;
71949 + }
71950 }
71951
71952 unsigned long
71953 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71954 return vma;
71955 }
71956
71957 +#ifdef CONFIG_PAX_SEGMEXEC
71958 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71959 +{
71960 + struct vm_area_struct *vma_m;
71961 +
71962 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71963 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71964 + BUG_ON(vma->vm_mirror);
71965 + return NULL;
71966 + }
71967 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71968 + vma_m = vma->vm_mirror;
71969 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71970 + BUG_ON(vma->vm_file != vma_m->vm_file);
71971 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71972 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71973 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71974 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71975 + return vma_m;
71976 +}
71977 +#endif
71978 +
71979 /*
71980 * Verify that the stack growth is acceptable and
71981 * update accounting. This is shared with both the
71982 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71983 return -ENOMEM;
71984
71985 /* Stack limit test */
71986 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
71987 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71988 return -ENOMEM;
71989
71990 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71991 locked = mm->locked_vm + grow;
71992 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71993 limit >>= PAGE_SHIFT;
71994 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71995 if (locked > limit && !capable(CAP_IPC_LOCK))
71996 return -ENOMEM;
71997 }
71998 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71999 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72000 * vma is the last one with address > vma->vm_end. Have to extend vma.
72001 */
72002 +#ifndef CONFIG_IA64
72003 +static
72004 +#endif
72005 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72006 {
72007 int error;
72008 + bool locknext;
72009
72010 if (!(vma->vm_flags & VM_GROWSUP))
72011 return -EFAULT;
72012
72013 + /* Also guard against wrapping around to address 0. */
72014 + if (address < PAGE_ALIGN(address+1))
72015 + address = PAGE_ALIGN(address+1);
72016 + else
72017 + return -ENOMEM;
72018 +
72019 /*
72020 * We must make sure the anon_vma is allocated
72021 * so that the anon_vma locking is not a noop.
72022 */
72023 if (unlikely(anon_vma_prepare(vma)))
72024 return -ENOMEM;
72025 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72026 + if (locknext && anon_vma_prepare(vma->vm_next))
72027 + return -ENOMEM;
72028 vma_lock_anon_vma(vma);
72029 + if (locknext)
72030 + vma_lock_anon_vma(vma->vm_next);
72031
72032 /*
72033 * vma->vm_start/vm_end cannot change under us because the caller
72034 * is required to hold the mmap_sem in read mode. We need the
72035 - * anon_vma lock to serialize against concurrent expand_stacks.
72036 - * Also guard against wrapping around to address 0.
72037 + * anon_vma locks to serialize against concurrent expand_stacks
72038 + * and expand_upwards.
72039 */
72040 - if (address < PAGE_ALIGN(address+4))
72041 - address = PAGE_ALIGN(address+4);
72042 - else {
72043 - vma_unlock_anon_vma(vma);
72044 - return -ENOMEM;
72045 - }
72046 error = 0;
72047
72048 /* Somebody else might have raced and expanded it already */
72049 - if (address > vma->vm_end) {
72050 + 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)
72051 + error = -ENOMEM;
72052 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72053 unsigned long size, grow;
72054
72055 size = address - vma->vm_start;
72056 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72057 }
72058 }
72059 }
72060 + if (locknext)
72061 + vma_unlock_anon_vma(vma->vm_next);
72062 vma_unlock_anon_vma(vma);
72063 khugepaged_enter_vma_merge(vma);
72064 return error;
72065 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72066 unsigned long address)
72067 {
72068 int error;
72069 + bool lockprev = false;
72070 + struct vm_area_struct *prev;
72071
72072 /*
72073 * We must make sure the anon_vma is allocated
72074 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72075 if (error)
72076 return error;
72077
72078 + prev = vma->vm_prev;
72079 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72080 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72081 +#endif
72082 + if (lockprev && anon_vma_prepare(prev))
72083 + return -ENOMEM;
72084 + if (lockprev)
72085 + vma_lock_anon_vma(prev);
72086 +
72087 vma_lock_anon_vma(vma);
72088
72089 /*
72090 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72091 */
72092
72093 /* Somebody else might have raced and expanded it already */
72094 - if (address < vma->vm_start) {
72095 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72096 + error = -ENOMEM;
72097 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72098 unsigned long size, grow;
72099
72100 +#ifdef CONFIG_PAX_SEGMEXEC
72101 + struct vm_area_struct *vma_m;
72102 +
72103 + vma_m = pax_find_mirror_vma(vma);
72104 +#endif
72105 +
72106 size = vma->vm_end - address;
72107 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72108
72109 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72110 if (!error) {
72111 vma->vm_start = address;
72112 vma->vm_pgoff -= grow;
72113 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72114 +
72115 +#ifdef CONFIG_PAX_SEGMEXEC
72116 + if (vma_m) {
72117 + vma_m->vm_start -= grow << PAGE_SHIFT;
72118 + vma_m->vm_pgoff -= grow;
72119 + }
72120 +#endif
72121 +
72122 perf_event_mmap(vma);
72123 }
72124 }
72125 }
72126 vma_unlock_anon_vma(vma);
72127 + if (lockprev)
72128 + vma_unlock_anon_vma(prev);
72129 khugepaged_enter_vma_merge(vma);
72130 return error;
72131 }
72132 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72133 do {
72134 long nrpages = vma_pages(vma);
72135
72136 +#ifdef CONFIG_PAX_SEGMEXEC
72137 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72138 + vma = remove_vma(vma);
72139 + continue;
72140 + }
72141 +#endif
72142 +
72143 mm->total_vm -= nrpages;
72144 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72145 vma = remove_vma(vma);
72146 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72147 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72148 vma->vm_prev = NULL;
72149 do {
72150 +
72151 +#ifdef CONFIG_PAX_SEGMEXEC
72152 + if (vma->vm_mirror) {
72153 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72154 + vma->vm_mirror->vm_mirror = NULL;
72155 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72156 + vma->vm_mirror = NULL;
72157 + }
72158 +#endif
72159 +
72160 rb_erase(&vma->vm_rb, &mm->mm_rb);
72161 mm->map_count--;
72162 tail_vma = vma;
72163 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72164 struct vm_area_struct *new;
72165 int err = -ENOMEM;
72166
72167 +#ifdef CONFIG_PAX_SEGMEXEC
72168 + struct vm_area_struct *vma_m, *new_m = NULL;
72169 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72170 +#endif
72171 +
72172 if (is_vm_hugetlb_page(vma) && (addr &
72173 ~(huge_page_mask(hstate_vma(vma)))))
72174 return -EINVAL;
72175
72176 +#ifdef CONFIG_PAX_SEGMEXEC
72177 + vma_m = pax_find_mirror_vma(vma);
72178 +#endif
72179 +
72180 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72181 if (!new)
72182 goto out_err;
72183
72184 +#ifdef CONFIG_PAX_SEGMEXEC
72185 + if (vma_m) {
72186 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72187 + if (!new_m) {
72188 + kmem_cache_free(vm_area_cachep, new);
72189 + goto out_err;
72190 + }
72191 + }
72192 +#endif
72193 +
72194 /* most fields are the same, copy all, and then fixup */
72195 *new = *vma;
72196
72197 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72198 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72199 }
72200
72201 +#ifdef CONFIG_PAX_SEGMEXEC
72202 + if (vma_m) {
72203 + *new_m = *vma_m;
72204 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72205 + new_m->vm_mirror = new;
72206 + new->vm_mirror = new_m;
72207 +
72208 + if (new_below)
72209 + new_m->vm_end = addr_m;
72210 + else {
72211 + new_m->vm_start = addr_m;
72212 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72213 + }
72214 + }
72215 +#endif
72216 +
72217 pol = mpol_dup(vma_policy(vma));
72218 if (IS_ERR(pol)) {
72219 err = PTR_ERR(pol);
72220 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72221 else
72222 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72223
72224 +#ifdef CONFIG_PAX_SEGMEXEC
72225 + if (!err && vma_m) {
72226 + if (anon_vma_clone(new_m, vma_m))
72227 + goto out_free_mpol;
72228 +
72229 + mpol_get(pol);
72230 + vma_set_policy(new_m, pol);
72231 +
72232 + if (new_m->vm_file) {
72233 + get_file(new_m->vm_file);
72234 + if (vma_m->vm_flags & VM_EXECUTABLE)
72235 + added_exe_file_vma(mm);
72236 + }
72237 +
72238 + if (new_m->vm_ops && new_m->vm_ops->open)
72239 + new_m->vm_ops->open(new_m);
72240 +
72241 + if (new_below)
72242 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72243 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72244 + else
72245 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72246 +
72247 + if (err) {
72248 + if (new_m->vm_ops && new_m->vm_ops->close)
72249 + new_m->vm_ops->close(new_m);
72250 + if (new_m->vm_file) {
72251 + if (vma_m->vm_flags & VM_EXECUTABLE)
72252 + removed_exe_file_vma(mm);
72253 + fput(new_m->vm_file);
72254 + }
72255 + mpol_put(pol);
72256 + }
72257 + }
72258 +#endif
72259 +
72260 /* Success. */
72261 if (!err)
72262 return 0;
72263 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72264 removed_exe_file_vma(mm);
72265 fput(new->vm_file);
72266 }
72267 - unlink_anon_vmas(new);
72268 out_free_mpol:
72269 mpol_put(pol);
72270 out_free_vma:
72271 +
72272 +#ifdef CONFIG_PAX_SEGMEXEC
72273 + if (new_m) {
72274 + unlink_anon_vmas(new_m);
72275 + kmem_cache_free(vm_area_cachep, new_m);
72276 + }
72277 +#endif
72278 +
72279 + unlink_anon_vmas(new);
72280 kmem_cache_free(vm_area_cachep, new);
72281 out_err:
72282 return err;
72283 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72284 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72285 unsigned long addr, int new_below)
72286 {
72287 +
72288 +#ifdef CONFIG_PAX_SEGMEXEC
72289 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72290 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72291 + if (mm->map_count >= sysctl_max_map_count-1)
72292 + return -ENOMEM;
72293 + } else
72294 +#endif
72295 +
72296 if (mm->map_count >= sysctl_max_map_count)
72297 return -ENOMEM;
72298
72299 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72300 * work. This now handles partial unmappings.
72301 * Jeremy Fitzhardinge <jeremy@goop.org>
72302 */
72303 +#ifdef CONFIG_PAX_SEGMEXEC
72304 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72305 {
72306 + int ret = __do_munmap(mm, start, len);
72307 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72308 + return ret;
72309 +
72310 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72311 +}
72312 +
72313 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72314 +#else
72315 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72316 +#endif
72317 +{
72318 unsigned long end;
72319 struct vm_area_struct *vma, *prev, *last;
72320
72321 + /*
72322 + * mm->mmap_sem is required to protect against another thread
72323 + * changing the mappings in case we sleep.
72324 + */
72325 + verify_mm_writelocked(mm);
72326 +
72327 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72328 return -EINVAL;
72329
72330 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72331 /* Fix up all other VM information */
72332 remove_vma_list(mm, vma);
72333
72334 + track_exec_limit(mm, start, end, 0UL);
72335 +
72336 return 0;
72337 }
72338
72339 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72340
72341 profile_munmap(addr);
72342
72343 +#ifdef CONFIG_PAX_SEGMEXEC
72344 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72345 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72346 + return -EINVAL;
72347 +#endif
72348 +
72349 down_write(&mm->mmap_sem);
72350 ret = do_munmap(mm, addr, len);
72351 up_write(&mm->mmap_sem);
72352 return ret;
72353 }
72354
72355 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72356 -{
72357 -#ifdef CONFIG_DEBUG_VM
72358 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72359 - WARN_ON(1);
72360 - up_read(&mm->mmap_sem);
72361 - }
72362 -#endif
72363 -}
72364 -
72365 /*
72366 * this is really a simplified "do_mmap". it only handles
72367 * anonymous maps. eventually we may be able to do some
72368 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72369 struct rb_node ** rb_link, * rb_parent;
72370 pgoff_t pgoff = addr >> PAGE_SHIFT;
72371 int error;
72372 + unsigned long charged;
72373
72374 len = PAGE_ALIGN(len);
72375 if (!len)
72376 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72377
72378 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72379
72380 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72381 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72382 + flags &= ~VM_EXEC;
72383 +
72384 +#ifdef CONFIG_PAX_MPROTECT
72385 + if (mm->pax_flags & MF_PAX_MPROTECT)
72386 + flags &= ~VM_MAYEXEC;
72387 +#endif
72388 +
72389 + }
72390 +#endif
72391 +
72392 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72393 if (error & ~PAGE_MASK)
72394 return error;
72395
72396 + charged = len >> PAGE_SHIFT;
72397 +
72398 /*
72399 * mlock MCL_FUTURE?
72400 */
72401 if (mm->def_flags & VM_LOCKED) {
72402 unsigned long locked, lock_limit;
72403 - locked = len >> PAGE_SHIFT;
72404 + locked = charged;
72405 locked += mm->locked_vm;
72406 lock_limit = rlimit(RLIMIT_MEMLOCK);
72407 lock_limit >>= PAGE_SHIFT;
72408 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72409 /*
72410 * Clear old maps. this also does some error checking for us
72411 */
72412 - munmap_back:
72413 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72414 if (vma && vma->vm_start < addr + len) {
72415 if (do_munmap(mm, addr, len))
72416 return -ENOMEM;
72417 - goto munmap_back;
72418 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72419 + BUG_ON(vma && vma->vm_start < addr + len);
72420 }
72421
72422 /* Check against address space limits *after* clearing old maps... */
72423 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72424 + if (!may_expand_vm(mm, charged))
72425 return -ENOMEM;
72426
72427 if (mm->map_count > sysctl_max_map_count)
72428 return -ENOMEM;
72429
72430 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72431 + if (security_vm_enough_memory(charged))
72432 return -ENOMEM;
72433
72434 /* Can we just expand an old private anonymous mapping? */
72435 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72436 */
72437 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72438 if (!vma) {
72439 - vm_unacct_memory(len >> PAGE_SHIFT);
72440 + vm_unacct_memory(charged);
72441 return -ENOMEM;
72442 }
72443
72444 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72445 vma_link(mm, vma, prev, rb_link, rb_parent);
72446 out:
72447 perf_event_mmap(vma);
72448 - mm->total_vm += len >> PAGE_SHIFT;
72449 + mm->total_vm += charged;
72450 if (flags & VM_LOCKED) {
72451 if (!mlock_vma_pages_range(vma, addr, addr + len))
72452 - mm->locked_vm += (len >> PAGE_SHIFT);
72453 + mm->locked_vm += charged;
72454 }
72455 + track_exec_limit(mm, addr, addr + len, flags);
72456 return addr;
72457 }
72458
72459 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72460 * Walk the list again, actually closing and freeing it,
72461 * with preemption enabled, without holding any MM locks.
72462 */
72463 - while (vma)
72464 + while (vma) {
72465 + vma->vm_mirror = NULL;
72466 vma = remove_vma(vma);
72467 + }
72468
72469 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72470 }
72471 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72472 struct vm_area_struct * __vma, * prev;
72473 struct rb_node ** rb_link, * rb_parent;
72474
72475 +#ifdef CONFIG_PAX_SEGMEXEC
72476 + struct vm_area_struct *vma_m = NULL;
72477 +#endif
72478 +
72479 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72480 + return -EPERM;
72481 +
72482 /*
72483 * The vm_pgoff of a purely anonymous vma should be irrelevant
72484 * until its first write fault, when page's anon_vma and index
72485 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72486 if ((vma->vm_flags & VM_ACCOUNT) &&
72487 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72488 return -ENOMEM;
72489 +
72490 +#ifdef CONFIG_PAX_SEGMEXEC
72491 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72492 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72493 + if (!vma_m)
72494 + return -ENOMEM;
72495 + }
72496 +#endif
72497 +
72498 vma_link(mm, vma, prev, rb_link, rb_parent);
72499 +
72500 +#ifdef CONFIG_PAX_SEGMEXEC
72501 + if (vma_m)
72502 + BUG_ON(pax_mirror_vma(vma_m, vma));
72503 +#endif
72504 +
72505 return 0;
72506 }
72507
72508 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72509 struct mempolicy *pol;
72510 bool faulted_in_anon_vma = true;
72511
72512 + BUG_ON(vma->vm_mirror);
72513 +
72514 /*
72515 * If anonymous vma has not yet been faulted, update new pgoff
72516 * to match new location, to increase its chance of merging.
72517 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72518 return NULL;
72519 }
72520
72521 +#ifdef CONFIG_PAX_SEGMEXEC
72522 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72523 +{
72524 + struct vm_area_struct *prev_m;
72525 + struct rb_node **rb_link_m, *rb_parent_m;
72526 + struct mempolicy *pol_m;
72527 +
72528 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72529 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72530 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72531 + *vma_m = *vma;
72532 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72533 + if (anon_vma_clone(vma_m, vma))
72534 + return -ENOMEM;
72535 + pol_m = vma_policy(vma_m);
72536 + mpol_get(pol_m);
72537 + vma_set_policy(vma_m, pol_m);
72538 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72539 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72540 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72541 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72542 + if (vma_m->vm_file)
72543 + get_file(vma_m->vm_file);
72544 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72545 + vma_m->vm_ops->open(vma_m);
72546 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72547 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72548 + vma_m->vm_mirror = vma;
72549 + vma->vm_mirror = vma_m;
72550 + return 0;
72551 +}
72552 +#endif
72553 +
72554 /*
72555 * Return true if the calling process may expand its vm space by the passed
72556 * number of pages
72557 @@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72558
72559 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72560
72561 +#ifdef CONFIG_PAX_RANDMMAP
72562 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72563 + cur -= mm->brk_gap;
72564 +#endif
72565 +
72566 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72567 if (cur + npages > lim)
72568 return 0;
72569 return 1;
72570 @@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
72571 vma->vm_start = addr;
72572 vma->vm_end = addr + len;
72573
72574 +#ifdef CONFIG_PAX_MPROTECT
72575 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72576 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72577 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72578 + return -EPERM;
72579 + if (!(vm_flags & VM_EXEC))
72580 + vm_flags &= ~VM_MAYEXEC;
72581 +#else
72582 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72583 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72584 +#endif
72585 + else
72586 + vm_flags &= ~VM_MAYWRITE;
72587 + }
72588 +#endif
72589 +
72590 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72591 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72592
72593 diff --git a/mm/mprotect.c b/mm/mprotect.c
72594 index f437d05..e3763f6 100644
72595 --- a/mm/mprotect.c
72596 +++ b/mm/mprotect.c
72597 @@ -23,10 +23,16 @@
72598 #include <linux/mmu_notifier.h>
72599 #include <linux/migrate.h>
72600 #include <linux/perf_event.h>
72601 +
72602 +#ifdef CONFIG_PAX_MPROTECT
72603 +#include <linux/elf.h>
72604 +#endif
72605 +
72606 #include <asm/uaccess.h>
72607 #include <asm/pgtable.h>
72608 #include <asm/cacheflush.h>
72609 #include <asm/tlbflush.h>
72610 +#include <asm/mmu_context.h>
72611
72612 #ifndef pgprot_modify
72613 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72614 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72615 flush_tlb_range(vma, start, end);
72616 }
72617
72618 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72619 +/* called while holding the mmap semaphor for writing except stack expansion */
72620 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72621 +{
72622 + unsigned long oldlimit, newlimit = 0UL;
72623 +
72624 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72625 + return;
72626 +
72627 + spin_lock(&mm->page_table_lock);
72628 + oldlimit = mm->context.user_cs_limit;
72629 + if ((prot & VM_EXEC) && oldlimit < end)
72630 + /* USER_CS limit moved up */
72631 + newlimit = end;
72632 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72633 + /* USER_CS limit moved down */
72634 + newlimit = start;
72635 +
72636 + if (newlimit) {
72637 + mm->context.user_cs_limit = newlimit;
72638 +
72639 +#ifdef CONFIG_SMP
72640 + wmb();
72641 + cpus_clear(mm->context.cpu_user_cs_mask);
72642 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72643 +#endif
72644 +
72645 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72646 + }
72647 + spin_unlock(&mm->page_table_lock);
72648 + if (newlimit == end) {
72649 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72650 +
72651 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72652 + if (is_vm_hugetlb_page(vma))
72653 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72654 + else
72655 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72656 + }
72657 +}
72658 +#endif
72659 +
72660 int
72661 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72662 unsigned long start, unsigned long end, unsigned long newflags)
72663 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72664 int error;
72665 int dirty_accountable = 0;
72666
72667 +#ifdef CONFIG_PAX_SEGMEXEC
72668 + struct vm_area_struct *vma_m = NULL;
72669 + unsigned long start_m, end_m;
72670 +
72671 + start_m = start + SEGMEXEC_TASK_SIZE;
72672 + end_m = end + SEGMEXEC_TASK_SIZE;
72673 +#endif
72674 +
72675 if (newflags == oldflags) {
72676 *pprev = vma;
72677 return 0;
72678 }
72679
72680 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72681 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72682 +
72683 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72684 + return -ENOMEM;
72685 +
72686 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72687 + return -ENOMEM;
72688 + }
72689 +
72690 /*
72691 * If we make a private mapping writable we increase our commit;
72692 * but (without finer accounting) cannot reduce our commit if we
72693 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72694 }
72695 }
72696
72697 +#ifdef CONFIG_PAX_SEGMEXEC
72698 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72699 + if (start != vma->vm_start) {
72700 + error = split_vma(mm, vma, start, 1);
72701 + if (error)
72702 + goto fail;
72703 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72704 + *pprev = (*pprev)->vm_next;
72705 + }
72706 +
72707 + if (end != vma->vm_end) {
72708 + error = split_vma(mm, vma, end, 0);
72709 + if (error)
72710 + goto fail;
72711 + }
72712 +
72713 + if (pax_find_mirror_vma(vma)) {
72714 + error = __do_munmap(mm, start_m, end_m - start_m);
72715 + if (error)
72716 + goto fail;
72717 + } else {
72718 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72719 + if (!vma_m) {
72720 + error = -ENOMEM;
72721 + goto fail;
72722 + }
72723 + vma->vm_flags = newflags;
72724 + error = pax_mirror_vma(vma_m, vma);
72725 + if (error) {
72726 + vma->vm_flags = oldflags;
72727 + goto fail;
72728 + }
72729 + }
72730 + }
72731 +#endif
72732 +
72733 /*
72734 * First try to merge with previous and/or next vma.
72735 */
72736 @@ -204,9 +306,21 @@ success:
72737 * vm_flags and vm_page_prot are protected by the mmap_sem
72738 * held in write mode.
72739 */
72740 +
72741 +#ifdef CONFIG_PAX_SEGMEXEC
72742 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72743 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72744 +#endif
72745 +
72746 vma->vm_flags = newflags;
72747 +
72748 +#ifdef CONFIG_PAX_MPROTECT
72749 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72750 + mm->binfmt->handle_mprotect(vma, newflags);
72751 +#endif
72752 +
72753 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72754 - vm_get_page_prot(newflags));
72755 + vm_get_page_prot(vma->vm_flags));
72756
72757 if (vma_wants_writenotify(vma)) {
72758 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72759 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72760 end = start + len;
72761 if (end <= start)
72762 return -ENOMEM;
72763 +
72764 +#ifdef CONFIG_PAX_SEGMEXEC
72765 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72766 + if (end > SEGMEXEC_TASK_SIZE)
72767 + return -EINVAL;
72768 + } else
72769 +#endif
72770 +
72771 + if (end > TASK_SIZE)
72772 + return -EINVAL;
72773 +
72774 if (!arch_validate_prot(prot))
72775 return -EINVAL;
72776
72777 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72778 /*
72779 * Does the application expect PROT_READ to imply PROT_EXEC:
72780 */
72781 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72782 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72783 prot |= PROT_EXEC;
72784
72785 vm_flags = calc_vm_prot_bits(prot);
72786 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72787 if (start > vma->vm_start)
72788 prev = vma;
72789
72790 +#ifdef CONFIG_PAX_MPROTECT
72791 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72792 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72793 +#endif
72794 +
72795 for (nstart = start ; ; ) {
72796 unsigned long newflags;
72797
72798 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72799
72800 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72801 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72802 + if (prot & (PROT_WRITE | PROT_EXEC))
72803 + gr_log_rwxmprotect(vma->vm_file);
72804 +
72805 + error = -EACCES;
72806 + goto out;
72807 + }
72808 +
72809 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72810 error = -EACCES;
72811 goto out;
72812 }
72813 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72814 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72815 if (error)
72816 goto out;
72817 +
72818 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72819 +
72820 nstart = tmp;
72821
72822 if (nstart < prev->vm_end)
72823 diff --git a/mm/mremap.c b/mm/mremap.c
72824 index 87bb839..c3bfadb 100644
72825 --- a/mm/mremap.c
72826 +++ b/mm/mremap.c
72827 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72828 continue;
72829 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72830 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72831 +
72832 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72833 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72834 + pte = pte_exprotect(pte);
72835 +#endif
72836 +
72837 set_pte_at(mm, new_addr, new_pte, pte);
72838 }
72839
72840 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72841 if (is_vm_hugetlb_page(vma))
72842 goto Einval;
72843
72844 +#ifdef CONFIG_PAX_SEGMEXEC
72845 + if (pax_find_mirror_vma(vma))
72846 + goto Einval;
72847 +#endif
72848 +
72849 /* We can't remap across vm area boundaries */
72850 if (old_len > vma->vm_end - addr)
72851 goto Efault;
72852 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72853 unsigned long ret = -EINVAL;
72854 unsigned long charged = 0;
72855 unsigned long map_flags;
72856 + unsigned long pax_task_size = TASK_SIZE;
72857
72858 if (new_addr & ~PAGE_MASK)
72859 goto out;
72860
72861 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72862 +#ifdef CONFIG_PAX_SEGMEXEC
72863 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72864 + pax_task_size = SEGMEXEC_TASK_SIZE;
72865 +#endif
72866 +
72867 + pax_task_size -= PAGE_SIZE;
72868 +
72869 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72870 goto out;
72871
72872 /* Check if the location we're moving into overlaps the
72873 * old location at all, and fail if it does.
72874 */
72875 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72876 - goto out;
72877 -
72878 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72879 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72880 goto out;
72881
72882 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72883 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72884 struct vm_area_struct *vma;
72885 unsigned long ret = -EINVAL;
72886 unsigned long charged = 0;
72887 + unsigned long pax_task_size = TASK_SIZE;
72888
72889 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72890 goto out;
72891 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72892 if (!new_len)
72893 goto out;
72894
72895 +#ifdef CONFIG_PAX_SEGMEXEC
72896 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72897 + pax_task_size = SEGMEXEC_TASK_SIZE;
72898 +#endif
72899 +
72900 + pax_task_size -= PAGE_SIZE;
72901 +
72902 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72903 + old_len > pax_task_size || addr > pax_task_size-old_len)
72904 + goto out;
72905 +
72906 if (flags & MREMAP_FIXED) {
72907 if (flags & MREMAP_MAYMOVE)
72908 ret = mremap_to(addr, old_len, new_addr, new_len);
72909 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72910 addr + new_len);
72911 }
72912 ret = addr;
72913 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72914 goto out;
72915 }
72916 }
72917 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72918 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72919 if (ret)
72920 goto out;
72921 +
72922 + map_flags = vma->vm_flags;
72923 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72924 + if (!(ret & ~PAGE_MASK)) {
72925 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72926 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72927 + }
72928 }
72929 out:
72930 if (ret & ~PAGE_MASK)
72931 diff --git a/mm/nommu.c b/mm/nommu.c
72932 index f59e170..34e2a2b 100644
72933 --- a/mm/nommu.c
72934 +++ b/mm/nommu.c
72935 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72936 int sysctl_overcommit_ratio = 50; /* default is 50% */
72937 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72938 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72939 -int heap_stack_gap = 0;
72940
72941 atomic_long_t mmap_pages_allocated;
72942
72943 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72944 EXPORT_SYMBOL(find_vma);
72945
72946 /*
72947 - * find a VMA
72948 - * - we don't extend stack VMAs under NOMMU conditions
72949 - */
72950 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72951 -{
72952 - return find_vma(mm, addr);
72953 -}
72954 -
72955 -/*
72956 * expand a stack to a given address
72957 * - not supported under NOMMU conditions
72958 */
72959 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72960
72961 /* most fields are the same, copy all, and then fixup */
72962 *new = *vma;
72963 + INIT_LIST_HEAD(&new->anon_vma_chain);
72964 *region = *vma->vm_region;
72965 new->vm_region = region;
72966
72967 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72968 index a13ded1..b949d15 100644
72969 --- a/mm/page_alloc.c
72970 +++ b/mm/page_alloc.c
72971 @@ -335,7 +335,7 @@ out:
72972 * This usage means that zero-order pages may not be compound.
72973 */
72974
72975 -static void free_compound_page(struct page *page)
72976 +void free_compound_page(struct page *page)
72977 {
72978 __free_pages_ok(page, compound_order(page));
72979 }
72980 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72981 int i;
72982 int bad = 0;
72983
72984 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72985 + unsigned long index = 1UL << order;
72986 +#endif
72987 +
72988 trace_mm_page_free(page, order);
72989 kmemcheck_free_shadow(page, order);
72990
72991 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72992 debug_check_no_obj_freed(page_address(page),
72993 PAGE_SIZE << order);
72994 }
72995 +
72996 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72997 + for (; index; --index)
72998 + sanitize_highpage(page + index - 1);
72999 +#endif
73000 +
73001 arch_free_page(page, order);
73002 kernel_map_pages(page, 1 << order, 0);
73003
73004 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73005 arch_alloc_page(page, order);
73006 kernel_map_pages(page, 1 << order, 1);
73007
73008 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73009 if (gfp_flags & __GFP_ZERO)
73010 prep_zero_page(page, order, gfp_flags);
73011 +#endif
73012
73013 if (order && (gfp_flags & __GFP_COMP))
73014 prep_compound_page(page, order);
73015 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73016 unsigned long pfn;
73017
73018 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73019 +#ifdef CONFIG_X86_32
73020 + /* boot failures in VMware 8 on 32bit vanilla since
73021 + this change */
73022 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73023 +#else
73024 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73025 +#endif
73026 return 1;
73027 }
73028 return 0;
73029 diff --git a/mm/percpu.c b/mm/percpu.c
73030 index f47af91..7eeef99 100644
73031 --- a/mm/percpu.c
73032 +++ b/mm/percpu.c
73033 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73034 static unsigned int pcpu_high_unit_cpu __read_mostly;
73035
73036 /* the address of the first chunk which starts with the kernel static area */
73037 -void *pcpu_base_addr __read_mostly;
73038 +void *pcpu_base_addr __read_only;
73039 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73040
73041 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73042 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73043 index c20ff48..137702a 100644
73044 --- a/mm/process_vm_access.c
73045 +++ b/mm/process_vm_access.c
73046 @@ -13,6 +13,7 @@
73047 #include <linux/uio.h>
73048 #include <linux/sched.h>
73049 #include <linux/highmem.h>
73050 +#include <linux/security.h>
73051 #include <linux/ptrace.h>
73052 #include <linux/slab.h>
73053 #include <linux/syscalls.h>
73054 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73055 size_t iov_l_curr_offset = 0;
73056 ssize_t iov_len;
73057
73058 + return -ENOSYS; // PaX: until properly audited
73059 +
73060 /*
73061 * Work out how many pages of struct pages we're going to need
73062 * when eventually calling get_user_pages
73063 */
73064 for (i = 0; i < riovcnt; i++) {
73065 iov_len = rvec[i].iov_len;
73066 - if (iov_len > 0) {
73067 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73068 - + iov_len)
73069 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73070 - / PAGE_SIZE + 1;
73071 - nr_pages = max(nr_pages, nr_pages_iov);
73072 - }
73073 + if (iov_len <= 0)
73074 + continue;
73075 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73076 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73077 + nr_pages = max(nr_pages, nr_pages_iov);
73078 }
73079
73080 if (nr_pages == 0)
73081 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73082 goto free_proc_pages;
73083 }
73084
73085 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73086 + rc = -EPERM;
73087 + goto put_task_struct;
73088 + }
73089 +
73090 mm = mm_access(task, PTRACE_MODE_ATTACH);
73091 if (!mm || IS_ERR(mm)) {
73092 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73093 diff --git a/mm/rmap.c b/mm/rmap.c
73094 index c8454e0..b04f3a2 100644
73095 --- a/mm/rmap.c
73096 +++ b/mm/rmap.c
73097 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73098 struct anon_vma *anon_vma = vma->anon_vma;
73099 struct anon_vma_chain *avc;
73100
73101 +#ifdef CONFIG_PAX_SEGMEXEC
73102 + struct anon_vma_chain *avc_m = NULL;
73103 +#endif
73104 +
73105 might_sleep();
73106 if (unlikely(!anon_vma)) {
73107 struct mm_struct *mm = vma->vm_mm;
73108 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73109 if (!avc)
73110 goto out_enomem;
73111
73112 +#ifdef CONFIG_PAX_SEGMEXEC
73113 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73114 + if (!avc_m)
73115 + goto out_enomem_free_avc;
73116 +#endif
73117 +
73118 anon_vma = find_mergeable_anon_vma(vma);
73119 allocated = NULL;
73120 if (!anon_vma) {
73121 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73122 /* page_table_lock to protect against threads */
73123 spin_lock(&mm->page_table_lock);
73124 if (likely(!vma->anon_vma)) {
73125 +
73126 +#ifdef CONFIG_PAX_SEGMEXEC
73127 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73128 +
73129 + if (vma_m) {
73130 + BUG_ON(vma_m->anon_vma);
73131 + vma_m->anon_vma = anon_vma;
73132 + avc_m->anon_vma = anon_vma;
73133 + avc_m->vma = vma;
73134 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73135 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73136 + avc_m = NULL;
73137 + }
73138 +#endif
73139 +
73140 vma->anon_vma = anon_vma;
73141 avc->anon_vma = anon_vma;
73142 avc->vma = vma;
73143 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73144
73145 if (unlikely(allocated))
73146 put_anon_vma(allocated);
73147 +
73148 +#ifdef CONFIG_PAX_SEGMEXEC
73149 + if (unlikely(avc_m))
73150 + anon_vma_chain_free(avc_m);
73151 +#endif
73152 +
73153 if (unlikely(avc))
73154 anon_vma_chain_free(avc);
73155 }
73156 return 0;
73157
73158 out_enomem_free_avc:
73159 +
73160 +#ifdef CONFIG_PAX_SEGMEXEC
73161 + if (avc_m)
73162 + anon_vma_chain_free(avc_m);
73163 +#endif
73164 +
73165 anon_vma_chain_free(avc);
73166 out_enomem:
73167 return -ENOMEM;
73168 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73169 * Attach the anon_vmas from src to dst.
73170 * Returns 0 on success, -ENOMEM on failure.
73171 */
73172 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73173 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73174 {
73175 struct anon_vma_chain *avc, *pavc;
73176 struct anon_vma *root = NULL;
73177 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73178 * the corresponding VMA in the parent process is attached to.
73179 * Returns 0 on success, non-zero on failure.
73180 */
73181 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73182 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73183 {
73184 struct anon_vma_chain *avc;
73185 struct anon_vma *anon_vma;
73186 diff --git a/mm/shmem.c b/mm/shmem.c
73187 index 269d049..a9d2b50 100644
73188 --- a/mm/shmem.c
73189 +++ b/mm/shmem.c
73190 @@ -31,7 +31,7 @@
73191 #include <linux/export.h>
73192 #include <linux/swap.h>
73193
73194 -static struct vfsmount *shm_mnt;
73195 +struct vfsmount *shm_mnt;
73196
73197 #ifdef CONFIG_SHMEM
73198 /*
73199 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73200 #define BOGO_DIRENT_SIZE 20
73201
73202 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73203 -#define SHORT_SYMLINK_LEN 128
73204 +#define SHORT_SYMLINK_LEN 64
73205
73206 struct shmem_xattr {
73207 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73208 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73209 int err = -ENOMEM;
73210
73211 /* Round up to L1_CACHE_BYTES to resist false sharing */
73212 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73213 - L1_CACHE_BYTES), GFP_KERNEL);
73214 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73215 if (!sbinfo)
73216 return -ENOMEM;
73217
73218 diff --git a/mm/slab.c b/mm/slab.c
73219 index f0bd785..348b96a 100644
73220 --- a/mm/slab.c
73221 +++ b/mm/slab.c
73222 @@ -153,7 +153,7 @@
73223
73224 /* Legal flag mask for kmem_cache_create(). */
73225 #if DEBUG
73226 -# define CREATE_MASK (SLAB_RED_ZONE | \
73227 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73228 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73229 SLAB_CACHE_DMA | \
73230 SLAB_STORE_USER | \
73231 @@ -161,7 +161,7 @@
73232 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73233 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73234 #else
73235 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73236 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73237 SLAB_CACHE_DMA | \
73238 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73239 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73240 @@ -290,7 +290,7 @@ struct kmem_list3 {
73241 * Need this for bootstrapping a per node allocator.
73242 */
73243 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73244 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73245 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73246 #define CACHE_CACHE 0
73247 #define SIZE_AC MAX_NUMNODES
73248 #define SIZE_L3 (2 * MAX_NUMNODES)
73249 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73250 if ((x)->max_freeable < i) \
73251 (x)->max_freeable = i; \
73252 } while (0)
73253 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73254 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73255 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73256 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73257 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73258 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73259 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73260 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73261 #else
73262 #define STATS_INC_ACTIVE(x) do { } while (0)
73263 #define STATS_DEC_ACTIVE(x) do { } while (0)
73264 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73265 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73266 */
73267 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73268 - const struct slab *slab, void *obj)
73269 + const struct slab *slab, const void *obj)
73270 {
73271 u32 offset = (obj - slab->s_mem);
73272 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73273 @@ -568,7 +568,7 @@ struct cache_names {
73274 static struct cache_names __initdata cache_names[] = {
73275 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73276 #include <linux/kmalloc_sizes.h>
73277 - {NULL,}
73278 + {NULL}
73279 #undef CACHE
73280 };
73281
73282 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73283 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73284 sizes[INDEX_AC].cs_size,
73285 ARCH_KMALLOC_MINALIGN,
73286 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73287 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73288 NULL);
73289
73290 if (INDEX_AC != INDEX_L3) {
73291 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73292 kmem_cache_create(names[INDEX_L3].name,
73293 sizes[INDEX_L3].cs_size,
73294 ARCH_KMALLOC_MINALIGN,
73295 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73296 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73297 NULL);
73298 }
73299
73300 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73301 sizes->cs_cachep = kmem_cache_create(names->name,
73302 sizes->cs_size,
73303 ARCH_KMALLOC_MINALIGN,
73304 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73305 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73306 NULL);
73307 }
73308 #ifdef CONFIG_ZONE_DMA
73309 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73310 }
73311 /* cpu stats */
73312 {
73313 - unsigned long allochit = atomic_read(&cachep->allochit);
73314 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73315 - unsigned long freehit = atomic_read(&cachep->freehit);
73316 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73317 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73318 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73319 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73320 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73321
73322 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73323 allochit, allocmiss, freehit, freemiss);
73324 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73325 {
73326 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73327 #ifdef CONFIG_DEBUG_SLAB_LEAK
73328 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73329 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73330 #endif
73331 return 0;
73332 }
73333 module_init(slab_proc_init);
73334 #endif
73335
73336 +void check_object_size(const void *ptr, unsigned long n, bool to)
73337 +{
73338 +
73339 +#ifdef CONFIG_PAX_USERCOPY
73340 + struct page *page;
73341 + struct kmem_cache *cachep = NULL;
73342 + struct slab *slabp;
73343 + unsigned int objnr;
73344 + unsigned long offset;
73345 + const char *type;
73346 +
73347 + if (!n)
73348 + return;
73349 +
73350 + type = "<null>";
73351 + if (ZERO_OR_NULL_PTR(ptr))
73352 + goto report;
73353 +
73354 + if (!virt_addr_valid(ptr))
73355 + return;
73356 +
73357 + page = virt_to_head_page(ptr);
73358 +
73359 + type = "<process stack>";
73360 + if (!PageSlab(page)) {
73361 + if (object_is_on_stack(ptr, n) == -1)
73362 + goto report;
73363 + return;
73364 + }
73365 +
73366 + cachep = page_get_cache(page);
73367 + type = cachep->name;
73368 + if (!(cachep->flags & SLAB_USERCOPY))
73369 + goto report;
73370 +
73371 + slabp = page_get_slab(page);
73372 + objnr = obj_to_index(cachep, slabp, ptr);
73373 + BUG_ON(objnr >= cachep->num);
73374 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73375 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73376 + return;
73377 +
73378 +report:
73379 + pax_report_usercopy(ptr, n, to, type);
73380 +#endif
73381 +
73382 +}
73383 +EXPORT_SYMBOL(check_object_size);
73384 +
73385 /**
73386 * ksize - get the actual amount of memory allocated for a given object
73387 * @objp: Pointer to the object
73388 diff --git a/mm/slob.c b/mm/slob.c
73389 index 8105be4..e045f96 100644
73390 --- a/mm/slob.c
73391 +++ b/mm/slob.c
73392 @@ -29,7 +29,7 @@
73393 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73394 * alloc_pages() directly, allocating compound pages so the page order
73395 * does not have to be separately tracked, and also stores the exact
73396 - * allocation size in page->private so that it can be used to accurately
73397 + * allocation size in slob_page->size so that it can be used to accurately
73398 * provide ksize(). These objects are detected in kfree() because slob_page()
73399 * is false for them.
73400 *
73401 @@ -58,6 +58,7 @@
73402 */
73403
73404 #include <linux/kernel.h>
73405 +#include <linux/sched.h>
73406 #include <linux/slab.h>
73407 #include <linux/mm.h>
73408 #include <linux/swap.h> /* struct reclaim_state */
73409 @@ -102,7 +103,8 @@ struct slob_page {
73410 unsigned long flags; /* mandatory */
73411 atomic_t _count; /* mandatory */
73412 slobidx_t units; /* free units left in page */
73413 - unsigned long pad[2];
73414 + unsigned long pad[1];
73415 + unsigned long size; /* size when >=PAGE_SIZE */
73416 slob_t *free; /* first free slob_t in page */
73417 struct list_head list; /* linked list of free pages */
73418 };
73419 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73420 */
73421 static inline int is_slob_page(struct slob_page *sp)
73422 {
73423 - return PageSlab((struct page *)sp);
73424 + return PageSlab((struct page *)sp) && !sp->size;
73425 }
73426
73427 static inline void set_slob_page(struct slob_page *sp)
73428 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73429
73430 static inline struct slob_page *slob_page(const void *addr)
73431 {
73432 - return (struct slob_page *)virt_to_page(addr);
73433 + return (struct slob_page *)virt_to_head_page(addr);
73434 }
73435
73436 /*
73437 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73438 /*
73439 * Return the size of a slob block.
73440 */
73441 -static slobidx_t slob_units(slob_t *s)
73442 +static slobidx_t slob_units(const slob_t *s)
73443 {
73444 if (s->units > 0)
73445 return s->units;
73446 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73447 /*
73448 * Return the next free slob block pointer after this one.
73449 */
73450 -static slob_t *slob_next(slob_t *s)
73451 +static slob_t *slob_next(const slob_t *s)
73452 {
73453 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73454 slobidx_t next;
73455 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73456 /*
73457 * Returns true if s is the last free block in its page.
73458 */
73459 -static int slob_last(slob_t *s)
73460 +static int slob_last(const slob_t *s)
73461 {
73462 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73463 }
73464 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73465 if (!page)
73466 return NULL;
73467
73468 + set_slob_page(page);
73469 return page_address(page);
73470 }
73471
73472 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73473 if (!b)
73474 return NULL;
73475 sp = slob_page(b);
73476 - set_slob_page(sp);
73477
73478 spin_lock_irqsave(&slob_lock, flags);
73479 sp->units = SLOB_UNITS(PAGE_SIZE);
73480 sp->free = b;
73481 + sp->size = 0;
73482 INIT_LIST_HEAD(&sp->list);
73483 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73484 set_slob_page_free(sp, slob_list);
73485 @@ -476,10 +479,9 @@ out:
73486 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73487 */
73488
73489 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73490 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73491 {
73492 - unsigned int *m;
73493 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73494 + slob_t *m;
73495 void *ret;
73496
73497 gfp &= gfp_allowed_mask;
73498 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73499
73500 if (!m)
73501 return NULL;
73502 - *m = size;
73503 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73504 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73505 + m[0].units = size;
73506 + m[1].units = align;
73507 ret = (void *)m + align;
73508
73509 trace_kmalloc_node(_RET_IP_, ret,
73510 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73511 gfp |= __GFP_COMP;
73512 ret = slob_new_pages(gfp, order, node);
73513 if (ret) {
73514 - struct page *page;
73515 - page = virt_to_page(ret);
73516 - page->private = size;
73517 + struct slob_page *sp;
73518 + sp = slob_page(ret);
73519 + sp->size = size;
73520 }
73521
73522 trace_kmalloc_node(_RET_IP_, ret,
73523 size, PAGE_SIZE << order, gfp, node);
73524 }
73525
73526 - kmemleak_alloc(ret, size, 1, gfp);
73527 + return ret;
73528 +}
73529 +
73530 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73531 +{
73532 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73533 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73534 +
73535 + if (!ZERO_OR_NULL_PTR(ret))
73536 + kmemleak_alloc(ret, size, 1, gfp);
73537 return ret;
73538 }
73539 EXPORT_SYMBOL(__kmalloc_node);
73540 @@ -533,13 +547,92 @@ void kfree(const void *block)
73541 sp = slob_page(block);
73542 if (is_slob_page(sp)) {
73543 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73544 - unsigned int *m = (unsigned int *)(block - align);
73545 - slob_free(m, *m + align);
73546 - } else
73547 + slob_t *m = (slob_t *)(block - align);
73548 + slob_free(m, m[0].units + align);
73549 + } else {
73550 + clear_slob_page(sp);
73551 + free_slob_page(sp);
73552 + sp->size = 0;
73553 put_page(&sp->page);
73554 + }
73555 }
73556 EXPORT_SYMBOL(kfree);
73557
73558 +void check_object_size(const void *ptr, unsigned long n, bool to)
73559 +{
73560 +
73561 +#ifdef CONFIG_PAX_USERCOPY
73562 + struct slob_page *sp;
73563 + const slob_t *free;
73564 + const void *base;
73565 + unsigned long flags;
73566 + const char *type;
73567 +
73568 + if (!n)
73569 + return;
73570 +
73571 + type = "<null>";
73572 + if (ZERO_OR_NULL_PTR(ptr))
73573 + goto report;
73574 +
73575 + if (!virt_addr_valid(ptr))
73576 + return;
73577 +
73578 + type = "<process stack>";
73579 + sp = slob_page(ptr);
73580 + if (!PageSlab((struct page *)sp)) {
73581 + if (object_is_on_stack(ptr, n) == -1)
73582 + goto report;
73583 + return;
73584 + }
73585 +
73586 + type = "<slob>";
73587 + if (sp->size) {
73588 + base = page_address(&sp->page);
73589 + if (base <= ptr && n <= sp->size - (ptr - base))
73590 + return;
73591 + goto report;
73592 + }
73593 +
73594 + /* some tricky double walking to find the chunk */
73595 + spin_lock_irqsave(&slob_lock, flags);
73596 + base = (void *)((unsigned long)ptr & PAGE_MASK);
73597 + free = sp->free;
73598 +
73599 + while (!slob_last(free) && (void *)free <= ptr) {
73600 + base = free + slob_units(free);
73601 + free = slob_next(free);
73602 + }
73603 +
73604 + while (base < (void *)free) {
73605 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73606 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
73607 + int offset;
73608 +
73609 + if (ptr < base + align)
73610 + break;
73611 +
73612 + offset = ptr - base - align;
73613 + if (offset >= m) {
73614 + base += size;
73615 + continue;
73616 + }
73617 +
73618 + if (n > m - offset)
73619 + break;
73620 +
73621 + spin_unlock_irqrestore(&slob_lock, flags);
73622 + return;
73623 + }
73624 +
73625 + spin_unlock_irqrestore(&slob_lock, flags);
73626 +report:
73627 + pax_report_usercopy(ptr, n, to, type);
73628 +#endif
73629 +
73630 +}
73631 +EXPORT_SYMBOL(check_object_size);
73632 +
73633 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73634 size_t ksize(const void *block)
73635 {
73636 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73637 sp = slob_page(block);
73638 if (is_slob_page(sp)) {
73639 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73640 - unsigned int *m = (unsigned int *)(block - align);
73641 - return SLOB_UNITS(*m) * SLOB_UNIT;
73642 + slob_t *m = (slob_t *)(block - align);
73643 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73644 } else
73645 - return sp->page.private;
73646 + return sp->size;
73647 }
73648 EXPORT_SYMBOL(ksize);
73649
73650 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73651 {
73652 struct kmem_cache *c;
73653
73654 +#ifdef CONFIG_PAX_USERCOPY
73655 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73656 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73657 +#else
73658 c = slob_alloc(sizeof(struct kmem_cache),
73659 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73660 +#endif
73661
73662 if (c) {
73663 c->name = name;
73664 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73665
73666 lockdep_trace_alloc(flags);
73667
73668 +#ifdef CONFIG_PAX_USERCOPY
73669 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73670 +#else
73671 if (c->size < PAGE_SIZE) {
73672 b = slob_alloc(c->size, flags, c->align, node);
73673 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73674 SLOB_UNITS(c->size) * SLOB_UNIT,
73675 flags, node);
73676 } else {
73677 + struct slob_page *sp;
73678 +
73679 b = slob_new_pages(flags, get_order(c->size), node);
73680 + sp = slob_page(b);
73681 + sp->size = c->size;
73682 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73683 PAGE_SIZE << get_order(c->size),
73684 flags, node);
73685 }
73686 +#endif
73687
73688 if (c->ctor)
73689 c->ctor(b);
73690 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73691
73692 static void __kmem_cache_free(void *b, int size)
73693 {
73694 - if (size < PAGE_SIZE)
73695 + struct slob_page *sp = slob_page(b);
73696 +
73697 + if (is_slob_page(sp))
73698 slob_free(b, size);
73699 - else
73700 + else {
73701 + clear_slob_page(sp);
73702 + free_slob_page(sp);
73703 + sp->size = 0;
73704 slob_free_pages(b, get_order(size));
73705 + }
73706 }
73707
73708 static void kmem_rcu_free(struct rcu_head *head)
73709 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73710
73711 void kmem_cache_free(struct kmem_cache *c, void *b)
73712 {
73713 + int size = c->size;
73714 +
73715 +#ifdef CONFIG_PAX_USERCOPY
73716 + if (size + c->align < PAGE_SIZE) {
73717 + size += c->align;
73718 + b -= c->align;
73719 + }
73720 +#endif
73721 +
73722 kmemleak_free_recursive(b, c->flags);
73723 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73724 struct slob_rcu *slob_rcu;
73725 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73726 - slob_rcu->size = c->size;
73727 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73728 + slob_rcu->size = size;
73729 call_rcu(&slob_rcu->head, kmem_rcu_free);
73730 } else {
73731 - __kmem_cache_free(b, c->size);
73732 + __kmem_cache_free(b, size);
73733 }
73734
73735 +#ifdef CONFIG_PAX_USERCOPY
73736 + trace_kfree(_RET_IP_, b);
73737 +#else
73738 trace_kmem_cache_free(_RET_IP_, b);
73739 +#endif
73740 +
73741 }
73742 EXPORT_SYMBOL(kmem_cache_free);
73743
73744 diff --git a/mm/slub.c b/mm/slub.c
73745 index 0342a5d..8180ae9 100644
73746 --- a/mm/slub.c
73747 +++ b/mm/slub.c
73748 @@ -208,7 +208,7 @@ struct track {
73749
73750 enum track_item { TRACK_ALLOC, TRACK_FREE };
73751
73752 -#ifdef CONFIG_SYSFS
73753 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73754 static int sysfs_slab_add(struct kmem_cache *);
73755 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73756 static void sysfs_slab_remove(struct kmem_cache *);
73757 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
73758 if (!t->addr)
73759 return;
73760
73761 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73762 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73763 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73764 #ifdef CONFIG_STACKTRACE
73765 {
73766 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73767
73768 page = virt_to_head_page(x);
73769
73770 + BUG_ON(!PageSlab(page));
73771 +
73772 slab_free(s, page, x, _RET_IP_);
73773
73774 trace_kmem_cache_free(_RET_IP_, x);
73775 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
73776 * Merge control. If this is set then no merging of slab caches will occur.
73777 * (Could be removed. This was introduced to pacify the merge skeptics.)
73778 */
73779 -static int slub_nomerge;
73780 +static int slub_nomerge = 1;
73781
73782 /*
73783 * Calculate the order of allocation given an slab object size.
73784 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73785 else
73786 s->cpu_partial = 30;
73787
73788 - s->refcount = 1;
73789 + atomic_set(&s->refcount, 1);
73790 #ifdef CONFIG_NUMA
73791 s->remote_node_defrag_ratio = 1000;
73792 #endif
73793 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73794 void kmem_cache_destroy(struct kmem_cache *s)
73795 {
73796 down_write(&slub_lock);
73797 - s->refcount--;
73798 - if (!s->refcount) {
73799 + if (atomic_dec_and_test(&s->refcount)) {
73800 list_del(&s->list);
73801 up_write(&slub_lock);
73802 if (kmem_cache_close(s)) {
73803 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73804 EXPORT_SYMBOL(__kmalloc_node);
73805 #endif
73806
73807 +void check_object_size(const void *ptr, unsigned long n, bool to)
73808 +{
73809 +
73810 +#ifdef CONFIG_PAX_USERCOPY
73811 + struct page *page;
73812 + struct kmem_cache *s = NULL;
73813 + unsigned long offset;
73814 + const char *type;
73815 +
73816 + if (!n)
73817 + return;
73818 +
73819 + type = "<null>";
73820 + if (ZERO_OR_NULL_PTR(ptr))
73821 + goto report;
73822 +
73823 + if (!virt_addr_valid(ptr))
73824 + return;
73825 +
73826 + page = virt_to_head_page(ptr);
73827 +
73828 + type = "<process stack>";
73829 + if (!PageSlab(page)) {
73830 + if (object_is_on_stack(ptr, n) == -1)
73831 + goto report;
73832 + return;
73833 + }
73834 +
73835 + s = page->slab;
73836 + type = s->name;
73837 + if (!(s->flags & SLAB_USERCOPY))
73838 + goto report;
73839 +
73840 + offset = (ptr - page_address(page)) % s->size;
73841 + if (offset <= s->objsize && n <= s->objsize - offset)
73842 + return;
73843 +
73844 +report:
73845 + pax_report_usercopy(ptr, n, to, type);
73846 +#endif
73847 +
73848 +}
73849 +EXPORT_SYMBOL(check_object_size);
73850 +
73851 size_t ksize(const void *object)
73852 {
73853 struct page *page;
73854 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73855 int node;
73856
73857 list_add(&s->list, &slab_caches);
73858 - s->refcount = -1;
73859 + atomic_set(&s->refcount, -1);
73860
73861 for_each_node_state(node, N_NORMAL_MEMORY) {
73862 struct kmem_cache_node *n = get_node(s, node);
73863 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
73864
73865 /* Caches that are not of the two-to-the-power-of size */
73866 if (KMALLOC_MIN_SIZE <= 32) {
73867 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73868 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73869 caches++;
73870 }
73871
73872 if (KMALLOC_MIN_SIZE <= 64) {
73873 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73874 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73875 caches++;
73876 }
73877
73878 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73879 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73880 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73881 caches++;
73882 }
73883
73884 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73885 /*
73886 * We may have set a slab to be unmergeable during bootstrap.
73887 */
73888 - if (s->refcount < 0)
73889 + if (atomic_read(&s->refcount) < 0)
73890 return 1;
73891
73892 return 0;
73893 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73894 down_write(&slub_lock);
73895 s = find_mergeable(size, align, flags, name, ctor);
73896 if (s) {
73897 - s->refcount++;
73898 + atomic_inc(&s->refcount);
73899 /*
73900 * Adjust the object sizes so that we clear
73901 * the complete object on kzalloc.
73902 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73903 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73904
73905 if (sysfs_slab_alias(s, name)) {
73906 - s->refcount--;
73907 + atomic_dec(&s->refcount);
73908 goto err;
73909 }
73910 up_write(&slub_lock);
73911 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73912 }
73913 #endif
73914
73915 -#ifdef CONFIG_SYSFS
73916 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73917 static int count_inuse(struct page *page)
73918 {
73919 return page->inuse;
73920 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
73921 validate_slab_cache(kmalloc_caches[9]);
73922 }
73923 #else
73924 -#ifdef CONFIG_SYSFS
73925 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73926 static void resiliency_test(void) {};
73927 #endif
73928 #endif
73929
73930 -#ifdef CONFIG_SYSFS
73931 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73932 enum slab_stat_type {
73933 SL_ALL, /* All slabs */
73934 SL_PARTIAL, /* Only partially allocated slabs */
73935 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
73936
73937 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73938 {
73939 - return sprintf(buf, "%d\n", s->refcount - 1);
73940 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73941 }
73942 SLAB_ATTR_RO(aliases);
73943
73944 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
73945 return name;
73946 }
73947
73948 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73949 static int sysfs_slab_add(struct kmem_cache *s)
73950 {
73951 int err;
73952 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73953 kobject_del(&s->kobj);
73954 kobject_put(&s->kobj);
73955 }
73956 +#endif
73957
73958 /*
73959 * Need to buffer aliases during bootup until sysfs becomes
73960 @@ -5319,6 +5366,7 @@ struct saved_alias {
73961
73962 static struct saved_alias *alias_list;
73963
73964 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73965 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73966 {
73967 struct saved_alias *al;
73968 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73969 alias_list = al;
73970 return 0;
73971 }
73972 +#endif
73973
73974 static int __init slab_sysfs_init(void)
73975 {
73976 diff --git a/mm/swap.c b/mm/swap.c
73977 index 14380e9..e244704 100644
73978 --- a/mm/swap.c
73979 +++ b/mm/swap.c
73980 @@ -30,6 +30,7 @@
73981 #include <linux/backing-dev.h>
73982 #include <linux/memcontrol.h>
73983 #include <linux/gfp.h>
73984 +#include <linux/hugetlb.h>
73985
73986 #include "internal.h"
73987
73988 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
73989
73990 __page_cache_release(page);
73991 dtor = get_compound_page_dtor(page);
73992 + if (!PageHuge(page))
73993 + BUG_ON(dtor != free_compound_page);
73994 (*dtor)(page);
73995 }
73996
73997 diff --git a/mm/swapfile.c b/mm/swapfile.c
73998 index f31b29d..8bdcae2 100644
73999 --- a/mm/swapfile.c
74000 +++ b/mm/swapfile.c
74001 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74002
74003 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74004 /* Activity counter to indicate that a swapon or swapoff has occurred */
74005 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74006 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74007
74008 static inline unsigned char swap_count(unsigned char ent)
74009 {
74010 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74011 }
74012 filp_close(swap_file, NULL);
74013 err = 0;
74014 - atomic_inc(&proc_poll_event);
74015 + atomic_inc_unchecked(&proc_poll_event);
74016 wake_up_interruptible(&proc_poll_wait);
74017
74018 out_dput:
74019 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74020
74021 poll_wait(file, &proc_poll_wait, wait);
74022
74023 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74024 - seq->poll_event = atomic_read(&proc_poll_event);
74025 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74026 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74027 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74028 }
74029
74030 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74031 return ret;
74032
74033 seq = file->private_data;
74034 - seq->poll_event = atomic_read(&proc_poll_event);
74035 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74036 return 0;
74037 }
74038
74039 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74040 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74041
74042 mutex_unlock(&swapon_mutex);
74043 - atomic_inc(&proc_poll_event);
74044 + atomic_inc_unchecked(&proc_poll_event);
74045 wake_up_interruptible(&proc_poll_wait);
74046
74047 if (S_ISREG(inode->i_mode))
74048 diff --git a/mm/util.c b/mm/util.c
74049 index 136ac4f..f917fa9 100644
74050 --- a/mm/util.c
74051 +++ b/mm/util.c
74052 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74053 void arch_pick_mmap_layout(struct mm_struct *mm)
74054 {
74055 mm->mmap_base = TASK_UNMAPPED_BASE;
74056 +
74057 +#ifdef CONFIG_PAX_RANDMMAP
74058 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74059 + mm->mmap_base += mm->delta_mmap;
74060 +#endif
74061 +
74062 mm->get_unmapped_area = arch_get_unmapped_area;
74063 mm->unmap_area = arch_unmap_area;
74064 }
74065 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74066 index 86ce9a5..bc498f3 100644
74067 --- a/mm/vmalloc.c
74068 +++ b/mm/vmalloc.c
74069 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74070
74071 pte = pte_offset_kernel(pmd, addr);
74072 do {
74073 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74074 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74075 +
74076 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74077 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74078 + BUG_ON(!pte_exec(*pte));
74079 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74080 + continue;
74081 + }
74082 +#endif
74083 +
74084 + {
74085 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74086 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74087 + }
74088 } while (pte++, addr += PAGE_SIZE, addr != end);
74089 }
74090
74091 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74092 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74093 {
74094 pte_t *pte;
74095 + int ret = -ENOMEM;
74096
74097 /*
74098 * nr is a running index into the array which helps higher level
74099 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74100 pte = pte_alloc_kernel(pmd, addr);
74101 if (!pte)
74102 return -ENOMEM;
74103 +
74104 + pax_open_kernel();
74105 do {
74106 struct page *page = pages[*nr];
74107
74108 - if (WARN_ON(!pte_none(*pte)))
74109 - return -EBUSY;
74110 - if (WARN_ON(!page))
74111 - return -ENOMEM;
74112 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74113 + if (pgprot_val(prot) & _PAGE_NX)
74114 +#endif
74115 +
74116 + if (WARN_ON(!pte_none(*pte))) {
74117 + ret = -EBUSY;
74118 + goto out;
74119 + }
74120 + if (WARN_ON(!page)) {
74121 + ret = -ENOMEM;
74122 + goto out;
74123 + }
74124 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74125 (*nr)++;
74126 } while (pte++, addr += PAGE_SIZE, addr != end);
74127 - return 0;
74128 + ret = 0;
74129 +out:
74130 + pax_close_kernel();
74131 + return ret;
74132 }
74133
74134 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74135 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74136 * and fall back on vmalloc() if that fails. Others
74137 * just put it in the vmalloc space.
74138 */
74139 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74140 +#ifdef CONFIG_MODULES
74141 +#ifdef MODULES_VADDR
74142 unsigned long addr = (unsigned long)x;
74143 if (addr >= MODULES_VADDR && addr < MODULES_END)
74144 return 1;
74145 #endif
74146 +
74147 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74148 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74149 + return 1;
74150 +#endif
74151 +
74152 +#endif
74153 +
74154 return is_vmalloc_addr(x);
74155 }
74156
74157 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74158
74159 if (!pgd_none(*pgd)) {
74160 pud_t *pud = pud_offset(pgd, addr);
74161 +#ifdef CONFIG_X86
74162 + if (!pud_large(*pud))
74163 +#endif
74164 if (!pud_none(*pud)) {
74165 pmd_t *pmd = pmd_offset(pud, addr);
74166 +#ifdef CONFIG_X86
74167 + if (!pmd_large(*pmd))
74168 +#endif
74169 if (!pmd_none(*pmd)) {
74170 pte_t *ptep, pte;
74171
74172 @@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74173 struct vm_struct *area;
74174
74175 BUG_ON(in_interrupt());
74176 +
74177 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74178 + if (flags & VM_KERNEXEC) {
74179 + if (start != VMALLOC_START || end != VMALLOC_END)
74180 + return NULL;
74181 + start = (unsigned long)MODULES_EXEC_VADDR;
74182 + end = (unsigned long)MODULES_EXEC_END;
74183 + }
74184 +#endif
74185 +
74186 if (flags & VM_IOREMAP) {
74187 int bit = fls(size);
74188
74189 @@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
74190 if (count > totalram_pages)
74191 return NULL;
74192
74193 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74194 + if (!(pgprot_val(prot) & _PAGE_NX))
74195 + flags |= VM_KERNEXEC;
74196 +#endif
74197 +
74198 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74199 __builtin_return_address(0));
74200 if (!area)
74201 @@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74202 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74203 goto fail;
74204
74205 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74206 + if (!(pgprot_val(prot) & _PAGE_NX))
74207 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74208 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74209 + else
74210 +#endif
74211 +
74212 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74213 start, end, node, gfp_mask, caller);
74214 if (!area)
74215 @@ -1825,10 +1887,9 @@ EXPORT_SYMBOL(vzalloc_node);
74216 * For tight control over page level allocator and protection flags
74217 * use __vmalloc() instead.
74218 */
74219 -
74220 void *vmalloc_exec(unsigned long size)
74221 {
74222 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74223 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74224 -1, __builtin_return_address(0));
74225 }
74226
74227 @@ -2123,6 +2184,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74228 unsigned long uaddr = vma->vm_start;
74229 unsigned long usize = vma->vm_end - vma->vm_start;
74230
74231 + BUG_ON(vma->vm_mirror);
74232 +
74233 if ((PAGE_SIZE-1) & (unsigned long)addr)
74234 return -EINVAL;
74235
74236 diff --git a/mm/vmstat.c b/mm/vmstat.c
74237 index f600557..1459fc8 100644
74238 --- a/mm/vmstat.c
74239 +++ b/mm/vmstat.c
74240 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74241 *
74242 * vm_stat contains the global counters
74243 */
74244 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74245 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74246 EXPORT_SYMBOL(vm_stat);
74247
74248 #ifdef CONFIG_SMP
74249 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74250 v = p->vm_stat_diff[i];
74251 p->vm_stat_diff[i] = 0;
74252 local_irq_restore(flags);
74253 - atomic_long_add(v, &zone->vm_stat[i]);
74254 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74255 global_diff[i] += v;
74256 #ifdef CONFIG_NUMA
74257 /* 3 seconds idle till flush */
74258 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74259
74260 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74261 if (global_diff[i])
74262 - atomic_long_add(global_diff[i], &vm_stat[i]);
74263 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74264 }
74265
74266 #endif
74267 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74268 start_cpu_timer(cpu);
74269 #endif
74270 #ifdef CONFIG_PROC_FS
74271 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74272 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74273 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74274 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74275 + {
74276 + mode_t gr_mode = S_IRUGO;
74277 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74278 + gr_mode = S_IRUSR;
74279 +#endif
74280 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74281 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74282 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74283 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74284 +#else
74285 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74286 +#endif
74287 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74288 + }
74289 #endif
74290 return 0;
74291 }
74292 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74293 index efea35b..9c8dd0b 100644
74294 --- a/net/8021q/vlan.c
74295 +++ b/net/8021q/vlan.c
74296 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74297 err = -EPERM;
74298 if (!capable(CAP_NET_ADMIN))
74299 break;
74300 - if ((args.u.name_type >= 0) &&
74301 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74302 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74303 struct vlan_net *vn;
74304
74305 vn = net_generic(net, vlan_net_id);
74306 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74307 index fccae26..e7ece2f 100644
74308 --- a/net/9p/trans_fd.c
74309 +++ b/net/9p/trans_fd.c
74310 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74311 oldfs = get_fs();
74312 set_fs(get_ds());
74313 /* The cast to a user pointer is valid due to the set_fs() */
74314 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74315 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74316 set_fs(oldfs);
74317
74318 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74319 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74320 index 876fbe8..8bbea9f 100644
74321 --- a/net/atm/atm_misc.c
74322 +++ b/net/atm/atm_misc.c
74323 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74324 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74325 return 1;
74326 atm_return(vcc, truesize);
74327 - atomic_inc(&vcc->stats->rx_drop);
74328 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74329 return 0;
74330 }
74331 EXPORT_SYMBOL(atm_charge);
74332 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74333 }
74334 }
74335 atm_return(vcc, guess);
74336 - atomic_inc(&vcc->stats->rx_drop);
74337 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74338 return NULL;
74339 }
74340 EXPORT_SYMBOL(atm_alloc_charge);
74341 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74342
74343 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74344 {
74345 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74346 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74347 __SONET_ITEMS
74348 #undef __HANDLE_ITEM
74349 }
74350 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74351
74352 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74353 {
74354 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74355 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74356 __SONET_ITEMS
74357 #undef __HANDLE_ITEM
74358 }
74359 diff --git a/net/atm/lec.h b/net/atm/lec.h
74360 index dfc0719..47c5322 100644
74361 --- a/net/atm/lec.h
74362 +++ b/net/atm/lec.h
74363 @@ -48,7 +48,7 @@ struct lane2_ops {
74364 const u8 *tlvs, u32 sizeoftlvs);
74365 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74366 const u8 *tlvs, u32 sizeoftlvs);
74367 -};
74368 +} __no_const;
74369
74370 /*
74371 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74372 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74373 index 0919a88..a23d54e 100644
74374 --- a/net/atm/mpc.h
74375 +++ b/net/atm/mpc.h
74376 @@ -33,7 +33,7 @@ struct mpoa_client {
74377 struct mpc_parameters parameters; /* parameters for this client */
74378
74379 const struct net_device_ops *old_ops;
74380 - struct net_device_ops new_ops;
74381 + net_device_ops_no_const new_ops;
74382 };
74383
74384
74385 diff --git a/net/atm/proc.c b/net/atm/proc.c
74386 index 0d020de..011c7bb 100644
74387 --- a/net/atm/proc.c
74388 +++ b/net/atm/proc.c
74389 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74390 const struct k_atm_aal_stats *stats)
74391 {
74392 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74393 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74394 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74395 - atomic_read(&stats->rx_drop));
74396 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74397 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74398 + atomic_read_unchecked(&stats->rx_drop));
74399 }
74400
74401 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74402 diff --git a/net/atm/resources.c b/net/atm/resources.c
74403 index 23f45ce..c748f1a 100644
74404 --- a/net/atm/resources.c
74405 +++ b/net/atm/resources.c
74406 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74407 static void copy_aal_stats(struct k_atm_aal_stats *from,
74408 struct atm_aal_stats *to)
74409 {
74410 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74411 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74412 __AAL_STAT_ITEMS
74413 #undef __HANDLE_ITEM
74414 }
74415 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74416 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74417 struct atm_aal_stats *to)
74418 {
74419 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74420 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74421 __AAL_STAT_ITEMS
74422 #undef __HANDLE_ITEM
74423 }
74424 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74425 index 3512e25..2b33401 100644
74426 --- a/net/batman-adv/bat_iv_ogm.c
74427 +++ b/net/batman-adv/bat_iv_ogm.c
74428 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74429
74430 /* change sequence number to network order */
74431 batman_ogm_packet->seqno =
74432 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74433 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74434
74435 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74436 batman_ogm_packet->tt_crc = htons((uint16_t)
74437 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74438 else
74439 batman_ogm_packet->gw_flags = NO_FLAGS;
74440
74441 - atomic_inc(&hard_iface->seqno);
74442 + atomic_inc_unchecked(&hard_iface->seqno);
74443
74444 slide_own_bcast_window(hard_iface);
74445 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74446 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74447 return;
74448
74449 /* could be changed by schedule_own_packet() */
74450 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74451 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74452
74453 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74454
74455 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74456 index 7704df4..beb4e16 100644
74457 --- a/net/batman-adv/hard-interface.c
74458 +++ b/net/batman-adv/hard-interface.c
74459 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74460 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74461 dev_add_pack(&hard_iface->batman_adv_ptype);
74462
74463 - atomic_set(&hard_iface->seqno, 1);
74464 - atomic_set(&hard_iface->frag_seqno, 1);
74465 + atomic_set_unchecked(&hard_iface->seqno, 1);
74466 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74467 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74468 hard_iface->net_dev->name);
74469
74470 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74471 index 987c75a..20d6f36 100644
74472 --- a/net/batman-adv/soft-interface.c
74473 +++ b/net/batman-adv/soft-interface.c
74474 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74475
74476 /* set broadcast sequence number */
74477 bcast_packet->seqno =
74478 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74479 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74480
74481 add_bcast_packet_to_list(bat_priv, skb, 1);
74482
74483 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
74484 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74485
74486 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74487 - atomic_set(&bat_priv->bcast_seqno, 1);
74488 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74489 atomic_set(&bat_priv->ttvn, 0);
74490 atomic_set(&bat_priv->tt_local_changes, 0);
74491 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74492 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74493 index e9eb043..d174eeb 100644
74494 --- a/net/batman-adv/types.h
74495 +++ b/net/batman-adv/types.h
74496 @@ -38,8 +38,8 @@ struct hard_iface {
74497 int16_t if_num;
74498 char if_status;
74499 struct net_device *net_dev;
74500 - atomic_t seqno;
74501 - atomic_t frag_seqno;
74502 + atomic_unchecked_t seqno;
74503 + atomic_unchecked_t frag_seqno;
74504 unsigned char *packet_buff;
74505 int packet_len;
74506 struct kobject *hardif_obj;
74507 @@ -154,7 +154,7 @@ struct bat_priv {
74508 atomic_t orig_interval; /* uint */
74509 atomic_t hop_penalty; /* uint */
74510 atomic_t log_level; /* uint */
74511 - atomic_t bcast_seqno;
74512 + atomic_unchecked_t bcast_seqno;
74513 atomic_t bcast_queue_left;
74514 atomic_t batman_queue_left;
74515 atomic_t ttvn; /* translation table version number */
74516 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74517 index 07d1c1d..7e9bea9 100644
74518 --- a/net/batman-adv/unicast.c
74519 +++ b/net/batman-adv/unicast.c
74520 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74521 frag1->flags = UNI_FRAG_HEAD | large_tail;
74522 frag2->flags = large_tail;
74523
74524 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74525 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74526 frag1->seqno = htons(seqno - 1);
74527 frag2->seqno = htons(seqno);
74528
74529 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74530 index 280953b..cd219bb 100644
74531 --- a/net/bluetooth/hci_conn.c
74532 +++ b/net/bluetooth/hci_conn.c
74533 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74534 memset(&cp, 0, sizeof(cp));
74535
74536 cp.handle = cpu_to_le16(conn->handle);
74537 - memcpy(cp.ltk, ltk, sizeof(ltk));
74538 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74539
74540 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74541 }
74542 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74543 index 32d338c..d24bcdb 100644
74544 --- a/net/bluetooth/l2cap_core.c
74545 +++ b/net/bluetooth/l2cap_core.c
74546 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74547 break;
74548
74549 case L2CAP_CONF_RFC:
74550 - if (olen == sizeof(rfc))
74551 - memcpy(&rfc, (void *)val, olen);
74552 + if (olen != sizeof(rfc))
74553 + break;
74554 +
74555 + memcpy(&rfc, (void *)val, olen);
74556
74557 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74558 rfc.mode != chan->mode)
74559 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74560
74561 switch (type) {
74562 case L2CAP_CONF_RFC:
74563 - if (olen == sizeof(rfc))
74564 - memcpy(&rfc, (void *)val, olen);
74565 + if (olen != sizeof(rfc))
74566 + break;
74567 +
74568 + memcpy(&rfc, (void *)val, olen);
74569 goto done;
74570 }
74571 }
74572 diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
74573 index 5449294..7da9a5f 100644
74574 --- a/net/bridge/netfilter/ebt_ulog.c
74575 +++ b/net/bridge/netfilter/ebt_ulog.c
74576 @@ -96,6 +96,7 @@ static void ulog_timer(unsigned long data)
74577 spin_unlock_bh(&ulog_buffers[data].lock);
74578 }
74579
74580 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
74581 static struct sk_buff *ulog_alloc_skb(unsigned int size)
74582 {
74583 struct sk_buff *skb;
74584 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74585 index 5fe2ff3..10968b5 100644
74586 --- a/net/bridge/netfilter/ebtables.c
74587 +++ b/net/bridge/netfilter/ebtables.c
74588 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74589 tmp.valid_hooks = t->table->valid_hooks;
74590 }
74591 mutex_unlock(&ebt_mutex);
74592 - if (copy_to_user(user, &tmp, *len) != 0){
74593 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74594 BUGPRINT("c2u Didn't work\n");
74595 ret = -EFAULT;
74596 break;
74597 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74598 index a97d97a..6f679ed 100644
74599 --- a/net/caif/caif_socket.c
74600 +++ b/net/caif/caif_socket.c
74601 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74602 #ifdef CONFIG_DEBUG_FS
74603 struct debug_fs_counter {
74604 atomic_t caif_nr_socks;
74605 - atomic_t caif_sock_create;
74606 - atomic_t num_connect_req;
74607 - atomic_t num_connect_resp;
74608 - atomic_t num_connect_fail_resp;
74609 - atomic_t num_disconnect;
74610 - atomic_t num_remote_shutdown_ind;
74611 - atomic_t num_tx_flow_off_ind;
74612 - atomic_t num_tx_flow_on_ind;
74613 - atomic_t num_rx_flow_off;
74614 - atomic_t num_rx_flow_on;
74615 + atomic_unchecked_t caif_sock_create;
74616 + atomic_unchecked_t num_connect_req;
74617 + atomic_unchecked_t num_connect_resp;
74618 + atomic_unchecked_t num_connect_fail_resp;
74619 + atomic_unchecked_t num_disconnect;
74620 + atomic_unchecked_t num_remote_shutdown_ind;
74621 + atomic_unchecked_t num_tx_flow_off_ind;
74622 + atomic_unchecked_t num_tx_flow_on_ind;
74623 + atomic_unchecked_t num_rx_flow_off;
74624 + atomic_unchecked_t num_rx_flow_on;
74625 };
74626 static struct debug_fs_counter cnt;
74627 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74628 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74629 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74630 #else
74631 #define dbfs_atomic_inc(v) 0
74632 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74633 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74634 sk_rcvbuf_lowwater(cf_sk));
74635 set_rx_flow_off(cf_sk);
74636 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74637 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74638 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74639 }
74640
74641 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74642 set_rx_flow_off(cf_sk);
74643 if (net_ratelimit())
74644 pr_debug("sending flow OFF due to rmem_schedule\n");
74645 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74646 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74647 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74648 }
74649 skb->dev = NULL;
74650 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74651 switch (flow) {
74652 case CAIF_CTRLCMD_FLOW_ON_IND:
74653 /* OK from modem to start sending again */
74654 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74655 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74656 set_tx_flow_on(cf_sk);
74657 cf_sk->sk.sk_state_change(&cf_sk->sk);
74658 break;
74659
74660 case CAIF_CTRLCMD_FLOW_OFF_IND:
74661 /* Modem asks us to shut up */
74662 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74663 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74664 set_tx_flow_off(cf_sk);
74665 cf_sk->sk.sk_state_change(&cf_sk->sk);
74666 break;
74667 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74668 /* We're now connected */
74669 caif_client_register_refcnt(&cf_sk->layer,
74670 cfsk_hold, cfsk_put);
74671 - dbfs_atomic_inc(&cnt.num_connect_resp);
74672 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74673 cf_sk->sk.sk_state = CAIF_CONNECTED;
74674 set_tx_flow_on(cf_sk);
74675 cf_sk->sk.sk_state_change(&cf_sk->sk);
74676 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74677
74678 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74679 /* Connect request failed */
74680 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74681 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74682 cf_sk->sk.sk_err = ECONNREFUSED;
74683 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74684 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74685 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74686
74687 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74688 /* Modem has closed this connection, or device is down. */
74689 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74690 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74691 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74692 cf_sk->sk.sk_err = ECONNRESET;
74693 set_rx_flow_on(cf_sk);
74694 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74695 return;
74696
74697 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74698 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
74699 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74700 set_rx_flow_on(cf_sk);
74701 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74702 }
74703 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74704 /*ifindex = id of the interface.*/
74705 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74706
74707 - dbfs_atomic_inc(&cnt.num_connect_req);
74708 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74709 cf_sk->layer.receive = caif_sktrecv_cb;
74710
74711 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74712 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
74713 spin_unlock_bh(&sk->sk_receive_queue.lock);
74714 sock->sk = NULL;
74715
74716 - dbfs_atomic_inc(&cnt.num_disconnect);
74717 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74718
74719 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74720 if (cf_sk->debugfs_socket_dir != NULL)
74721 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74722 cf_sk->conn_req.protocol = protocol;
74723 /* Increase the number of sockets created. */
74724 dbfs_atomic_inc(&cnt.caif_nr_socks);
74725 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
74726 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74727 #ifdef CONFIG_DEBUG_FS
74728 if (!IS_ERR(debugfsdir)) {
74729
74730 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74731 index 5cf5222..6f704ad 100644
74732 --- a/net/caif/cfctrl.c
74733 +++ b/net/caif/cfctrl.c
74734 @@ -9,6 +9,7 @@
74735 #include <linux/stddef.h>
74736 #include <linux/spinlock.h>
74737 #include <linux/slab.h>
74738 +#include <linux/sched.h>
74739 #include <net/caif/caif_layer.h>
74740 #include <net/caif/cfpkt.h>
74741 #include <net/caif/cfctrl.h>
74742 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74743 memset(&dev_info, 0, sizeof(dev_info));
74744 dev_info.id = 0xff;
74745 cfsrvl_init(&this->serv, 0, &dev_info, false);
74746 - atomic_set(&this->req_seq_no, 1);
74747 - atomic_set(&this->rsp_seq_no, 1);
74748 + atomic_set_unchecked(&this->req_seq_no, 1);
74749 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74750 this->serv.layer.receive = cfctrl_recv;
74751 sprintf(this->serv.layer.name, "ctrl");
74752 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74753 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74754 struct cfctrl_request_info *req)
74755 {
74756 spin_lock_bh(&ctrl->info_list_lock);
74757 - atomic_inc(&ctrl->req_seq_no);
74758 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74759 + atomic_inc_unchecked(&ctrl->req_seq_no);
74760 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74761 list_add_tail(&req->list, &ctrl->list);
74762 spin_unlock_bh(&ctrl->info_list_lock);
74763 }
74764 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74765 if (p != first)
74766 pr_warn("Requests are not received in order\n");
74767
74768 - atomic_set(&ctrl->rsp_seq_no,
74769 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74770 p->sequence_no);
74771 list_del(&p->list);
74772 goto out;
74773 diff --git a/net/can/gw.c b/net/can/gw.c
74774 index 3d79b12..8de85fa 100644
74775 --- a/net/can/gw.c
74776 +++ b/net/can/gw.c
74777 @@ -96,7 +96,7 @@ struct cf_mod {
74778 struct {
74779 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74780 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74781 - } csumfunc;
74782 + } __no_const csumfunc;
74783 };
74784
74785
74786 diff --git a/net/compat.c b/net/compat.c
74787 index 6def90e..c6992fa 100644
74788 --- a/net/compat.c
74789 +++ b/net/compat.c
74790 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74791 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74792 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74793 return -EFAULT;
74794 - kmsg->msg_name = compat_ptr(tmp1);
74795 - kmsg->msg_iov = compat_ptr(tmp2);
74796 - kmsg->msg_control = compat_ptr(tmp3);
74797 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74798 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74799 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74800 return 0;
74801 }
74802
74803 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74804
74805 if (kern_msg->msg_namelen) {
74806 if (mode == VERIFY_READ) {
74807 - int err = move_addr_to_kernel(kern_msg->msg_name,
74808 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74809 kern_msg->msg_namelen,
74810 kern_address);
74811 if (err < 0)
74812 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74813 kern_msg->msg_name = NULL;
74814
74815 tot_len = iov_from_user_compat_to_kern(kern_iov,
74816 - (struct compat_iovec __user *)kern_msg->msg_iov,
74817 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74818 kern_msg->msg_iovlen);
74819 if (tot_len >= 0)
74820 kern_msg->msg_iov = kern_iov;
74821 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74822
74823 #define CMSG_COMPAT_FIRSTHDR(msg) \
74824 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74825 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74826 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74827 (struct compat_cmsghdr __user *)NULL)
74828
74829 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74830 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74831 (ucmlen) <= (unsigned long) \
74832 ((mhdr)->msg_controllen - \
74833 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74834 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74835
74836 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74837 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74838 {
74839 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74840 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74841 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74842 msg->msg_controllen)
74843 return NULL;
74844 return (struct compat_cmsghdr __user *)ptr;
74845 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74846 {
74847 struct compat_timeval ctv;
74848 struct compat_timespec cts[3];
74849 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74850 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74851 struct compat_cmsghdr cmhdr;
74852 int cmlen;
74853
74854 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74855
74856 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74857 {
74858 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74859 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74860 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74861 int fdnum = scm->fp->count;
74862 struct file **fp = scm->fp->fp;
74863 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74864 return -EFAULT;
74865 old_fs = get_fs();
74866 set_fs(KERNEL_DS);
74867 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74868 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74869 set_fs(old_fs);
74870
74871 return err;
74872 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74873 len = sizeof(ktime);
74874 old_fs = get_fs();
74875 set_fs(KERNEL_DS);
74876 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74877 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74878 set_fs(old_fs);
74879
74880 if (!err) {
74881 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74882 case MCAST_JOIN_GROUP:
74883 case MCAST_LEAVE_GROUP:
74884 {
74885 - struct compat_group_req __user *gr32 = (void *)optval;
74886 + struct compat_group_req __user *gr32 = (void __user *)optval;
74887 struct group_req __user *kgr =
74888 compat_alloc_user_space(sizeof(struct group_req));
74889 u32 interface;
74890 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74891 case MCAST_BLOCK_SOURCE:
74892 case MCAST_UNBLOCK_SOURCE:
74893 {
74894 - struct compat_group_source_req __user *gsr32 = (void *)optval;
74895 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74896 struct group_source_req __user *kgsr = compat_alloc_user_space(
74897 sizeof(struct group_source_req));
74898 u32 interface;
74899 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74900 }
74901 case MCAST_MSFILTER:
74902 {
74903 - struct compat_group_filter __user *gf32 = (void *)optval;
74904 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74905 struct group_filter __user *kgf;
74906 u32 interface, fmode, numsrc;
74907
74908 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74909 char __user *optval, int __user *optlen,
74910 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74911 {
74912 - struct compat_group_filter __user *gf32 = (void *)optval;
74913 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74914 struct group_filter __user *kgf;
74915 int __user *koptlen;
74916 u32 interface, fmode, numsrc;
74917 diff --git a/net/core/datagram.c b/net/core/datagram.c
74918 index 68bbf9f..5ef0d12 100644
74919 --- a/net/core/datagram.c
74920 +++ b/net/core/datagram.c
74921 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74922 }
74923
74924 kfree_skb(skb);
74925 - atomic_inc(&sk->sk_drops);
74926 + atomic_inc_unchecked(&sk->sk_drops);
74927 sk_mem_reclaim_partial(sk);
74928
74929 return err;
74930 diff --git a/net/core/dev.c b/net/core/dev.c
74931 index a4bf943..9c83051 100644
74932 --- a/net/core/dev.c
74933 +++ b/net/core/dev.c
74934 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
74935 if (no_module && capable(CAP_NET_ADMIN))
74936 no_module = request_module("netdev-%s", name);
74937 if (no_module && capable(CAP_SYS_MODULE)) {
74938 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74939 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
74940 +#else
74941 if (!request_module("%s", name))
74942 pr_err("Loading kernel module for a network device "
74943 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
74944 "instead\n", name);
74945 +#endif
74946 }
74947 }
74948 EXPORT_SYMBOL(dev_load);
74949 @@ -1585,7 +1589,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74950 {
74951 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74952 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74953 - atomic_long_inc(&dev->rx_dropped);
74954 + atomic_long_inc_unchecked(&dev->rx_dropped);
74955 kfree_skb(skb);
74956 return NET_RX_DROP;
74957 }
74958 @@ -1595,7 +1599,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74959 nf_reset(skb);
74960
74961 if (unlikely(!is_skb_forwardable(dev, skb))) {
74962 - atomic_long_inc(&dev->rx_dropped);
74963 + atomic_long_inc_unchecked(&dev->rx_dropped);
74964 kfree_skb(skb);
74965 return NET_RX_DROP;
74966 }
74967 @@ -2057,7 +2061,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74968
74969 struct dev_gso_cb {
74970 void (*destructor)(struct sk_buff *skb);
74971 -};
74972 +} __no_const;
74973
74974 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74975
74976 @@ -2913,7 +2917,7 @@ enqueue:
74977
74978 local_irq_restore(flags);
74979
74980 - atomic_long_inc(&skb->dev->rx_dropped);
74981 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74982 kfree_skb(skb);
74983 return NET_RX_DROP;
74984 }
74985 @@ -2985,7 +2989,7 @@ int netif_rx_ni(struct sk_buff *skb)
74986 }
74987 EXPORT_SYMBOL(netif_rx_ni);
74988
74989 -static void net_tx_action(struct softirq_action *h)
74990 +static void net_tx_action(void)
74991 {
74992 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74993
74994 @@ -3273,7 +3277,7 @@ ncls:
74995 if (pt_prev) {
74996 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74997 } else {
74998 - atomic_long_inc(&skb->dev->rx_dropped);
74999 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75000 kfree_skb(skb);
75001 /* Jamal, now you will not able to escape explaining
75002 * me how you were going to use this. :-)
75003 @@ -3833,7 +3837,7 @@ void netif_napi_del(struct napi_struct *napi)
75004 }
75005 EXPORT_SYMBOL(netif_napi_del);
75006
75007 -static void net_rx_action(struct softirq_action *h)
75008 +static void net_rx_action(void)
75009 {
75010 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75011 unsigned long time_limit = jiffies + 2;
75012 @@ -5890,7 +5894,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75013 } else {
75014 netdev_stats_to_stats64(storage, &dev->stats);
75015 }
75016 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75017 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75018 return storage;
75019 }
75020 EXPORT_SYMBOL(dev_get_stats);
75021 diff --git a/net/core/flow.c b/net/core/flow.c
75022 index e318c7e..168b1d0 100644
75023 --- a/net/core/flow.c
75024 +++ b/net/core/flow.c
75025 @@ -61,7 +61,7 @@ struct flow_cache {
75026 struct timer_list rnd_timer;
75027 };
75028
75029 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75030 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75031 EXPORT_SYMBOL(flow_cache_genid);
75032 static struct flow_cache flow_cache_global;
75033 static struct kmem_cache *flow_cachep __read_mostly;
75034 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75035
75036 static int flow_entry_valid(struct flow_cache_entry *fle)
75037 {
75038 - if (atomic_read(&flow_cache_genid) != fle->genid)
75039 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75040 return 0;
75041 if (fle->object && !fle->object->ops->check(fle->object))
75042 return 0;
75043 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75044 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75045 fcp->hash_count++;
75046 }
75047 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75048 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75049 flo = fle->object;
75050 if (!flo)
75051 goto ret_object;
75052 @@ -280,7 +280,7 @@ nocache:
75053 }
75054 flo = resolver(net, key, family, dir, flo, ctx);
75055 if (fle) {
75056 - fle->genid = atomic_read(&flow_cache_genid);
75057 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75058 if (!IS_ERR(flo))
75059 fle->object = flo;
75060 else
75061 diff --git a/net/core/iovec.c b/net/core/iovec.c
75062 index c40f27e..7f49254 100644
75063 --- a/net/core/iovec.c
75064 +++ b/net/core/iovec.c
75065 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75066 if (m->msg_namelen) {
75067 if (mode == VERIFY_READ) {
75068 void __user *namep;
75069 - namep = (void __user __force *) m->msg_name;
75070 + namep = (void __force_user *) m->msg_name;
75071 err = move_addr_to_kernel(namep, m->msg_namelen,
75072 address);
75073 if (err < 0)
75074 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75075 }
75076
75077 size = m->msg_iovlen * sizeof(struct iovec);
75078 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75079 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75080 return -EFAULT;
75081
75082 m->msg_iov = iov;
75083 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75084 index 5c30296..ebe7b61 100644
75085 --- a/net/core/rtnetlink.c
75086 +++ b/net/core/rtnetlink.c
75087 @@ -57,7 +57,7 @@ struct rtnl_link {
75088 rtnl_doit_func doit;
75089 rtnl_dumpit_func dumpit;
75090 rtnl_calcit_func calcit;
75091 -};
75092 +} __no_const;
75093
75094 static DEFINE_MUTEX(rtnl_mutex);
75095
75096 diff --git a/net/core/scm.c b/net/core/scm.c
75097 index ff52ad0..aff1c0f 100644
75098 --- a/net/core/scm.c
75099 +++ b/net/core/scm.c
75100 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75101 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75102 {
75103 struct cmsghdr __user *cm
75104 - = (__force struct cmsghdr __user *)msg->msg_control;
75105 + = (struct cmsghdr __force_user *)msg->msg_control;
75106 struct cmsghdr cmhdr;
75107 int cmlen = CMSG_LEN(len);
75108 int err;
75109 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75110 err = -EFAULT;
75111 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75112 goto out;
75113 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75114 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75115 goto out;
75116 cmlen = CMSG_SPACE(len);
75117 if (msg->msg_controllen < cmlen)
75118 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75119 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75120 {
75121 struct cmsghdr __user *cm
75122 - = (__force struct cmsghdr __user*)msg->msg_control;
75123 + = (struct cmsghdr __force_user *)msg->msg_control;
75124
75125 int fdmax = 0;
75126 int fdnum = scm->fp->count;
75127 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75128 if (fdnum < fdmax)
75129 fdmax = fdnum;
75130
75131 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75132 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75133 i++, cmfptr++)
75134 {
75135 int new_fd;
75136 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
75137 index da0c97f..8253632 100644
75138 --- a/net/core/skbuff.c
75139 +++ b/net/core/skbuff.c
75140 @@ -3160,6 +3160,8 @@ static void sock_rmem_free(struct sk_buff *skb)
75141 */
75142 int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75143 {
75144 + int len = skb->len;
75145 +
75146 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75147 (unsigned)sk->sk_rcvbuf)
75148 return -ENOMEM;
75149 @@ -3174,7 +3176,7 @@ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
75150
75151 skb_queue_tail(&sk->sk_error_queue, skb);
75152 if (!sock_flag(sk, SOCK_DEAD))
75153 - sk->sk_data_ready(sk, skb->len);
75154 + sk->sk_data_ready(sk, len);
75155 return 0;
75156 }
75157 EXPORT_SYMBOL(sock_queue_err_skb);
75158 diff --git a/net/core/sock.c b/net/core/sock.c
75159 index 02f8dfe..86dfd4a 100644
75160 --- a/net/core/sock.c
75161 +++ b/net/core/sock.c
75162 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75163 struct sk_buff_head *list = &sk->sk_receive_queue;
75164
75165 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75166 - atomic_inc(&sk->sk_drops);
75167 + atomic_inc_unchecked(&sk->sk_drops);
75168 trace_sock_rcvqueue_full(sk, skb);
75169 return -ENOMEM;
75170 }
75171 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75172 return err;
75173
75174 if (!sk_rmem_schedule(sk, skb->truesize)) {
75175 - atomic_inc(&sk->sk_drops);
75176 + atomic_inc_unchecked(&sk->sk_drops);
75177 return -ENOBUFS;
75178 }
75179
75180 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75181 skb_dst_force(skb);
75182
75183 spin_lock_irqsave(&list->lock, flags);
75184 - skb->dropcount = atomic_read(&sk->sk_drops);
75185 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75186 __skb_queue_tail(list, skb);
75187 spin_unlock_irqrestore(&list->lock, flags);
75188
75189 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75190 skb->dev = NULL;
75191
75192 if (sk_rcvqueues_full(sk, skb)) {
75193 - atomic_inc(&sk->sk_drops);
75194 + atomic_inc_unchecked(&sk->sk_drops);
75195 goto discard_and_relse;
75196 }
75197 if (nested)
75198 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75199 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75200 } else if (sk_add_backlog(sk, skb)) {
75201 bh_unlock_sock(sk);
75202 - atomic_inc(&sk->sk_drops);
75203 + atomic_inc_unchecked(&sk->sk_drops);
75204 goto discard_and_relse;
75205 }
75206
75207 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75208 if (len > sizeof(peercred))
75209 len = sizeof(peercred);
75210 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75211 - if (copy_to_user(optval, &peercred, len))
75212 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75213 return -EFAULT;
75214 goto lenout;
75215 }
75216 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75217 return -ENOTCONN;
75218 if (lv < len)
75219 return -EINVAL;
75220 - if (copy_to_user(optval, address, len))
75221 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75222 return -EFAULT;
75223 goto lenout;
75224 }
75225 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75226
75227 if (len > lv)
75228 len = lv;
75229 - if (copy_to_user(optval, &v, len))
75230 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75231 return -EFAULT;
75232 lenout:
75233 if (put_user(len, optlen))
75234 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75235 */
75236 smp_wmb();
75237 atomic_set(&sk->sk_refcnt, 1);
75238 - atomic_set(&sk->sk_drops, 0);
75239 + atomic_set_unchecked(&sk->sk_drops, 0);
75240 }
75241 EXPORT_SYMBOL(sock_init_data);
75242
75243 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75244 index b9868e1..849f809 100644
75245 --- a/net/core/sock_diag.c
75246 +++ b/net/core/sock_diag.c
75247 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75248
75249 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75250 {
75251 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75252 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75253 cookie[1] != INET_DIAG_NOCOOKIE) &&
75254 ((u32)(unsigned long)sk != cookie[0] ||
75255 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75256 return -ESTALE;
75257 else
75258 +#endif
75259 return 0;
75260 }
75261 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75262
75263 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75264 {
75265 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75266 + cookie[0] = 0;
75267 + cookie[1] = 0;
75268 +#else
75269 cookie[0] = (u32)(unsigned long)sk;
75270 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75271 +#endif
75272 }
75273 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75274
75275 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75276 index 02e75d1..9a57a7c 100644
75277 --- a/net/decnet/sysctl_net_decnet.c
75278 +++ b/net/decnet/sysctl_net_decnet.c
75279 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75280
75281 if (len > *lenp) len = *lenp;
75282
75283 - if (copy_to_user(buffer, addr, len))
75284 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75285 return -EFAULT;
75286
75287 *lenp = len;
75288 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75289
75290 if (len > *lenp) len = *lenp;
75291
75292 - if (copy_to_user(buffer, devname, len))
75293 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75294 return -EFAULT;
75295
75296 *lenp = len;
75297 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75298 index 39a2d29..f39c0fe 100644
75299 --- a/net/econet/Kconfig
75300 +++ b/net/econet/Kconfig
75301 @@ -4,7 +4,7 @@
75302
75303 config ECONET
75304 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75305 - depends on EXPERIMENTAL && INET
75306 + depends on EXPERIMENTAL && INET && BROKEN
75307 ---help---
75308 Econet is a fairly old and slow networking protocol mainly used by
75309 Acorn computers to access file and print servers. It uses native
75310 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
75311 index 36d1440..44ff28b 100644
75312 --- a/net/ipv4/ah4.c
75313 +++ b/net/ipv4/ah4.c
75314 @@ -19,6 +19,8 @@ struct ah_skb_cb {
75315 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75316
75317 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75318 + unsigned int size) __size_overflow(3);
75319 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75320 unsigned int size)
75321 {
75322 unsigned int len;
75323 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75324 index 92fc5f6..b790d91 100644
75325 --- a/net/ipv4/fib_frontend.c
75326 +++ b/net/ipv4/fib_frontend.c
75327 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75328 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75329 fib_sync_up(dev);
75330 #endif
75331 - atomic_inc(&net->ipv4.dev_addr_genid);
75332 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75333 rt_cache_flush(dev_net(dev), -1);
75334 break;
75335 case NETDEV_DOWN:
75336 fib_del_ifaddr(ifa, NULL);
75337 - atomic_inc(&net->ipv4.dev_addr_genid);
75338 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75339 if (ifa->ifa_dev->ifa_list == NULL) {
75340 /* Last address was deleted from this interface.
75341 * Disable IP.
75342 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75343 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75344 fib_sync_up(dev);
75345 #endif
75346 - atomic_inc(&net->ipv4.dev_addr_genid);
75347 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75348 rt_cache_flush(dev_net(dev), -1);
75349 break;
75350 case NETDEV_DOWN:
75351 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75352 index 80106d8..232e898 100644
75353 --- a/net/ipv4/fib_semantics.c
75354 +++ b/net/ipv4/fib_semantics.c
75355 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75356 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75357 nh->nh_gw,
75358 nh->nh_parent->fib_scope);
75359 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75360 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75361
75362 return nh->nh_saddr;
75363 }
75364 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75365 index 984ec65..97ac518 100644
75366 --- a/net/ipv4/inet_hashtables.c
75367 +++ b/net/ipv4/inet_hashtables.c
75368 @@ -18,12 +18,15 @@
75369 #include <linux/sched.h>
75370 #include <linux/slab.h>
75371 #include <linux/wait.h>
75372 +#include <linux/security.h>
75373
75374 #include <net/inet_connection_sock.h>
75375 #include <net/inet_hashtables.h>
75376 #include <net/secure_seq.h>
75377 #include <net/ip.h>
75378
75379 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75380 +
75381 /*
75382 * Allocate and initialize a new local port bind bucket.
75383 * The bindhash mutex for snum's hash chain must be held here.
75384 @@ -530,6 +533,8 @@ ok:
75385 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75386 spin_unlock(&head->lock);
75387
75388 + gr_update_task_in_ip_table(current, inet_sk(sk));
75389 +
75390 if (tw) {
75391 inet_twsk_deschedule(tw, death_row);
75392 while (twrefcnt) {
75393 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75394 index d4d61b6..b81aec8 100644
75395 --- a/net/ipv4/inetpeer.c
75396 +++ b/net/ipv4/inetpeer.c
75397 @@ -487,8 +487,8 @@ relookup:
75398 if (p) {
75399 p->daddr = *daddr;
75400 atomic_set(&p->refcnt, 1);
75401 - atomic_set(&p->rid, 0);
75402 - atomic_set(&p->ip_id_count,
75403 + atomic_set_unchecked(&p->rid, 0);
75404 + atomic_set_unchecked(&p->ip_id_count,
75405 (daddr->family == AF_INET) ?
75406 secure_ip_id(daddr->addr.a4) :
75407 secure_ipv6_id(daddr->addr.a6));
75408 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75409 index 1f23a57..7180dfe 100644
75410 --- a/net/ipv4/ip_fragment.c
75411 +++ b/net/ipv4/ip_fragment.c
75412 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75413 return 0;
75414
75415 start = qp->rid;
75416 - end = atomic_inc_return(&peer->rid);
75417 + end = atomic_inc_return_unchecked(&peer->rid);
75418 qp->rid = end;
75419
75420 rc = qp->q.fragments && (end - start) > max;
75421 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75422 index 8aa87c1..35c3248 100644
75423 --- a/net/ipv4/ip_sockglue.c
75424 +++ b/net/ipv4/ip_sockglue.c
75425 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75426 len = min_t(unsigned int, len, opt->optlen);
75427 if (put_user(len, optlen))
75428 return -EFAULT;
75429 - if (copy_to_user(optval, opt->__data, len))
75430 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75431 + copy_to_user(optval, opt->__data, len))
75432 return -EFAULT;
75433 return 0;
75434 }
75435 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75436 if (sk->sk_type != SOCK_STREAM)
75437 return -ENOPROTOOPT;
75438
75439 - msg.msg_control = optval;
75440 + msg.msg_control = (void __force_kernel *)optval;
75441 msg.msg_controllen = len;
75442 msg.msg_flags = flags;
75443
75444 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75445 index 6e412a6..6640538 100644
75446 --- a/net/ipv4/ipconfig.c
75447 +++ b/net/ipv4/ipconfig.c
75448 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75449
75450 mm_segment_t oldfs = get_fs();
75451 set_fs(get_ds());
75452 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75453 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75454 set_fs(oldfs);
75455 return res;
75456 }
75457 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75458
75459 mm_segment_t oldfs = get_fs();
75460 set_fs(get_ds());
75461 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75462 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75463 set_fs(oldfs);
75464 return res;
75465 }
75466 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75467
75468 mm_segment_t oldfs = get_fs();
75469 set_fs(get_ds());
75470 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75471 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75472 set_fs(oldfs);
75473 return res;
75474 }
75475 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
75476 index fd7a3f6..a1b1013 100644
75477 --- a/net/ipv4/netfilter/arp_tables.c
75478 +++ b/net/ipv4/netfilter/arp_tables.c
75479 @@ -757,6 +757,9 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75480
75481 static int copy_entries_to_user(unsigned int total_size,
75482 const struct xt_table *table,
75483 + void __user *userptr) __size_overflow(1);
75484 +static int copy_entries_to_user(unsigned int total_size,
75485 + const struct xt_table *table,
75486 void __user *userptr)
75487 {
75488 unsigned int off, num;
75489 @@ -984,6 +987,11 @@ static int __do_replace(struct net *net, const char *name,
75490 unsigned int valid_hooks,
75491 struct xt_table_info *newinfo,
75492 unsigned int num_counters,
75493 + void __user *counters_ptr) __size_overflow(5);
75494 +static int __do_replace(struct net *net, const char *name,
75495 + unsigned int valid_hooks,
75496 + struct xt_table_info *newinfo,
75497 + unsigned int num_counters,
75498 void __user *counters_ptr)
75499 {
75500 int ret;
75501 @@ -1104,6 +1112,8 @@ static int do_replace(struct net *net, const void __user *user,
75502 }
75503
75504 static int do_add_counters(struct net *net, const void __user *user,
75505 + unsigned int len, int compat) __size_overflow(3);
75506 +static int do_add_counters(struct net *net, const void __user *user,
75507 unsigned int len, int compat)
75508 {
75509 unsigned int i, curcpu;
75510 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
75511 index 24e556e..b073356 100644
75512 --- a/net/ipv4/netfilter/ip_tables.c
75513 +++ b/net/ipv4/netfilter/ip_tables.c
75514 @@ -923,6 +923,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
75515 static int
75516 copy_entries_to_user(unsigned int total_size,
75517 const struct xt_table *table,
75518 + void __user *userptr) __size_overflow(1);
75519 +static int
75520 +copy_entries_to_user(unsigned int total_size,
75521 + const struct xt_table *table,
75522 void __user *userptr)
75523 {
75524 unsigned int off, num;
75525 @@ -1172,6 +1176,10 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
75526 static int
75527 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75528 struct xt_table_info *newinfo, unsigned int num_counters,
75529 + void __user *counters_ptr) __size_overflow(5);
75530 +static int
75531 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75532 + struct xt_table_info *newinfo, unsigned int num_counters,
75533 void __user *counters_ptr)
75534 {
75535 int ret;
75536 @@ -1293,6 +1301,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
75537
75538 static int
75539 do_add_counters(struct net *net, const void __user *user,
75540 + unsigned int len, int compat) __size_overflow(3);
75541 +static int
75542 +do_add_counters(struct net *net, const void __user *user,
75543 unsigned int len, int compat)
75544 {
75545 unsigned int i, curcpu;
75546 diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
75547 index ba5756d..8d34d74 100644
75548 --- a/net/ipv4/netfilter/ipt_ULOG.c
75549 +++ b/net/ipv4/netfilter/ipt_ULOG.c
75550 @@ -125,6 +125,7 @@ static void ulog_timer(unsigned long data)
75551 spin_unlock_bh(&ulog_lock);
75552 }
75553
75554 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
75555 static struct sk_buff *ulog_alloc_skb(unsigned int size)
75556 {
75557 struct sk_buff *skb;
75558 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75559 index 2133c30..0e8047e 100644
75560 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
75561 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75562 @@ -435,6 +435,10 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
75563 static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75564 unsigned char *eoc,
75565 unsigned long **oid,
75566 + unsigned int *len) __size_overflow(2);
75567 +static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75568 + unsigned char *eoc,
75569 + unsigned long **oid,
75570 unsigned int *len)
75571 {
75572 unsigned long subid;
75573 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75574 index b072386..abdebcf 100644
75575 --- a/net/ipv4/ping.c
75576 +++ b/net/ipv4/ping.c
75577 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75578 sk_rmem_alloc_get(sp),
75579 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75580 atomic_read(&sp->sk_refcnt), sp,
75581 - atomic_read(&sp->sk_drops), len);
75582 + atomic_read_unchecked(&sp->sk_drops), len);
75583 }
75584
75585 static int ping_seq_show(struct seq_file *seq, void *v)
75586 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75587 index 3ccda5a..3c1e61d 100644
75588 --- a/net/ipv4/raw.c
75589 +++ b/net/ipv4/raw.c
75590 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75591 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75592 {
75593 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75594 - atomic_inc(&sk->sk_drops);
75595 + atomic_inc_unchecked(&sk->sk_drops);
75596 kfree_skb(skb);
75597 return NET_RX_DROP;
75598 }
75599 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
75600
75601 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75602 {
75603 + struct icmp_filter filter;
75604 +
75605 if (optlen > sizeof(struct icmp_filter))
75606 optlen = sizeof(struct icmp_filter);
75607 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75608 + if (copy_from_user(&filter, optval, optlen))
75609 return -EFAULT;
75610 + raw_sk(sk)->filter = filter;
75611 return 0;
75612 }
75613
75614 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75615 {
75616 int len, ret = -EFAULT;
75617 + struct icmp_filter filter;
75618
75619 if (get_user(len, optlen))
75620 goto out;
75621 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75622 if (len > sizeof(struct icmp_filter))
75623 len = sizeof(struct icmp_filter);
75624 ret = -EFAULT;
75625 - if (put_user(len, optlen) ||
75626 - copy_to_user(optval, &raw_sk(sk)->filter, len))
75627 + filter = raw_sk(sk)->filter;
75628 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75629 goto out;
75630 ret = 0;
75631 out: return ret;
75632 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75633 sk_wmem_alloc_get(sp),
75634 sk_rmem_alloc_get(sp),
75635 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75636 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75637 + atomic_read(&sp->sk_refcnt),
75638 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75639 + NULL,
75640 +#else
75641 + sp,
75642 +#endif
75643 + atomic_read_unchecked(&sp->sk_drops));
75644 }
75645
75646 static int raw_seq_show(struct seq_file *seq, void *v)
75647 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75648 index 0197747..7adb0dc 100644
75649 --- a/net/ipv4/route.c
75650 +++ b/net/ipv4/route.c
75651 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75652
75653 static inline int rt_genid(struct net *net)
75654 {
75655 - return atomic_read(&net->ipv4.rt_genid);
75656 + return atomic_read_unchecked(&net->ipv4.rt_genid);
75657 }
75658
75659 #ifdef CONFIG_PROC_FS
75660 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
75661 unsigned char shuffle;
75662
75663 get_random_bytes(&shuffle, sizeof(shuffle));
75664 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75665 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75666 inetpeer_invalidate_tree(AF_INET);
75667 }
75668
75669 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
75670 error = rt->dst.error;
75671 if (peer) {
75672 inet_peer_refcheck(rt->peer);
75673 - id = atomic_read(&peer->ip_id_count) & 0xffff;
75674 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75675 if (peer->tcp_ts_stamp) {
75676 ts = peer->tcp_ts;
75677 tsage = get_seconds() - peer->tcp_ts_stamp;
75678 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75679 index fd54c5f..96d6407 100644
75680 --- a/net/ipv4/tcp_ipv4.c
75681 +++ b/net/ipv4/tcp_ipv4.c
75682 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75683 int sysctl_tcp_low_latency __read_mostly;
75684 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75685
75686 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75687 +extern int grsec_enable_blackhole;
75688 +#endif
75689
75690 #ifdef CONFIG_TCP_MD5SIG
75691 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75692 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75693 return 0;
75694
75695 reset:
75696 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75697 + if (!grsec_enable_blackhole)
75698 +#endif
75699 tcp_v4_send_reset(rsk, skb);
75700 discard:
75701 kfree_skb(skb);
75702 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75703 TCP_SKB_CB(skb)->sacked = 0;
75704
75705 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75706 - if (!sk)
75707 + if (!sk) {
75708 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75709 + ret = 1;
75710 +#endif
75711 goto no_tcp_socket;
75712 -
75713 + }
75714 process:
75715 - if (sk->sk_state == TCP_TIME_WAIT)
75716 + if (sk->sk_state == TCP_TIME_WAIT) {
75717 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75718 + ret = 2;
75719 +#endif
75720 goto do_time_wait;
75721 + }
75722
75723 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75724 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75725 @@ -1755,6 +1768,10 @@ no_tcp_socket:
75726 bad_packet:
75727 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75728 } else {
75729 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75730 + if (!grsec_enable_blackhole || (ret == 1 &&
75731 + (skb->dev->flags & IFF_LOOPBACK)))
75732 +#endif
75733 tcp_v4_send_reset(NULL, skb);
75734 }
75735
75736 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75737 0, /* non standard timer */
75738 0, /* open_requests have no inode */
75739 atomic_read(&sk->sk_refcnt),
75740 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75741 + NULL,
75742 +#else
75743 req,
75744 +#endif
75745 len);
75746 }
75747
75748 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75749 sock_i_uid(sk),
75750 icsk->icsk_probes_out,
75751 sock_i_ino(sk),
75752 - atomic_read(&sk->sk_refcnt), sk,
75753 + atomic_read(&sk->sk_refcnt),
75754 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75755 + NULL,
75756 +#else
75757 + sk,
75758 +#endif
75759 jiffies_to_clock_t(icsk->icsk_rto),
75760 jiffies_to_clock_t(icsk->icsk_ack.ato),
75761 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75762 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75763 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75764 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75765 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75766 - atomic_read(&tw->tw_refcnt), tw, len);
75767 + atomic_read(&tw->tw_refcnt),
75768 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75769 + NULL,
75770 +#else
75771 + tw,
75772 +#endif
75773 + len);
75774 }
75775
75776 #define TMPSZ 150
75777 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75778 index 550e755..25721b3 100644
75779 --- a/net/ipv4/tcp_minisocks.c
75780 +++ b/net/ipv4/tcp_minisocks.c
75781 @@ -27,6 +27,10 @@
75782 #include <net/inet_common.h>
75783 #include <net/xfrm.h>
75784
75785 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75786 +extern int grsec_enable_blackhole;
75787 +#endif
75788 +
75789 int sysctl_tcp_syncookies __read_mostly = 1;
75790 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75791
75792 @@ -753,6 +757,10 @@ listen_overflow:
75793
75794 embryonic_reset:
75795 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75796 +
75797 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75798 + if (!grsec_enable_blackhole)
75799 +#endif
75800 if (!(flg & TCP_FLAG_RST))
75801 req->rsk_ops->send_reset(sk, skb);
75802
75803 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75804 index 85ee7eb..53277ab 100644
75805 --- a/net/ipv4/tcp_probe.c
75806 +++ b/net/ipv4/tcp_probe.c
75807 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75808 if (cnt + width >= len)
75809 break;
75810
75811 - if (copy_to_user(buf + cnt, tbuf, width))
75812 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75813 return -EFAULT;
75814 cnt += width;
75815 }
75816 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75817 index cd2e072..1fffee2 100644
75818 --- a/net/ipv4/tcp_timer.c
75819 +++ b/net/ipv4/tcp_timer.c
75820 @@ -22,6 +22,10 @@
75821 #include <linux/gfp.h>
75822 #include <net/tcp.h>
75823
75824 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75825 +extern int grsec_lastack_retries;
75826 +#endif
75827 +
75828 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75829 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75830 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75831 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75832 }
75833 }
75834
75835 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75836 + if ((sk->sk_state == TCP_LAST_ACK) &&
75837 + (grsec_lastack_retries > 0) &&
75838 + (grsec_lastack_retries < retry_until))
75839 + retry_until = grsec_lastack_retries;
75840 +#endif
75841 +
75842 if (retransmits_timed_out(sk, retry_until,
75843 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75844 /* Has it gone just too far? */
75845 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75846 index 5d075b5..d907d5f 100644
75847 --- a/net/ipv4/udp.c
75848 +++ b/net/ipv4/udp.c
75849 @@ -86,6 +86,7 @@
75850 #include <linux/types.h>
75851 #include <linux/fcntl.h>
75852 #include <linux/module.h>
75853 +#include <linux/security.h>
75854 #include <linux/socket.h>
75855 #include <linux/sockios.h>
75856 #include <linux/igmp.h>
75857 @@ -108,6 +109,10 @@
75858 #include <trace/events/udp.h>
75859 #include "udp_impl.h"
75860
75861 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75862 +extern int grsec_enable_blackhole;
75863 +#endif
75864 +
75865 struct udp_table udp_table __read_mostly;
75866 EXPORT_SYMBOL(udp_table);
75867
75868 @@ -566,6 +571,9 @@ found:
75869 return s;
75870 }
75871
75872 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75873 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75874 +
75875 /*
75876 * This routine is called by the ICMP module when it gets some
75877 * sort of error condition. If err < 0 then the socket should
75878 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75879 dport = usin->sin_port;
75880 if (dport == 0)
75881 return -EINVAL;
75882 +
75883 + err = gr_search_udp_sendmsg(sk, usin);
75884 + if (err)
75885 + return err;
75886 } else {
75887 if (sk->sk_state != TCP_ESTABLISHED)
75888 return -EDESTADDRREQ;
75889 +
75890 + err = gr_search_udp_sendmsg(sk, NULL);
75891 + if (err)
75892 + return err;
75893 +
75894 daddr = inet->inet_daddr;
75895 dport = inet->inet_dport;
75896 /* Open fast path for connected socket.
75897 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
75898 udp_lib_checksum_complete(skb)) {
75899 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75900 IS_UDPLITE(sk));
75901 - atomic_inc(&sk->sk_drops);
75902 + atomic_inc_unchecked(&sk->sk_drops);
75903 __skb_unlink(skb, rcvq);
75904 __skb_queue_tail(&list_kill, skb);
75905 }
75906 @@ -1186,6 +1203,10 @@ try_again:
75907 if (!skb)
75908 goto out;
75909
75910 + err = gr_search_udp_recvmsg(sk, skb);
75911 + if (err)
75912 + goto out_free;
75913 +
75914 ulen = skb->len - sizeof(struct udphdr);
75915 copied = len;
75916 if (copied > ulen)
75917 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75918
75919 drop:
75920 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75921 - atomic_inc(&sk->sk_drops);
75922 + atomic_inc_unchecked(&sk->sk_drops);
75923 kfree_skb(skb);
75924 return -1;
75925 }
75926 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75927 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75928
75929 if (!skb1) {
75930 - atomic_inc(&sk->sk_drops);
75931 + atomic_inc_unchecked(&sk->sk_drops);
75932 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75933 IS_UDPLITE(sk));
75934 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75935 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75936 goto csum_error;
75937
75938 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75939 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75940 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75941 +#endif
75942 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75943
75944 /*
75945 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75946 sk_wmem_alloc_get(sp),
75947 sk_rmem_alloc_get(sp),
75948 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75949 - atomic_read(&sp->sk_refcnt), sp,
75950 - atomic_read(&sp->sk_drops), len);
75951 + atomic_read(&sp->sk_refcnt),
75952 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75953 + NULL,
75954 +#else
75955 + sp,
75956 +#endif
75957 + atomic_read_unchecked(&sp->sk_drops), len);
75958 }
75959
75960 int udp4_seq_show(struct seq_file *seq, void *v)
75961 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75962 index 6b8ebc5..1d624f4 100644
75963 --- a/net/ipv6/addrconf.c
75964 +++ b/net/ipv6/addrconf.c
75965 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75966 p.iph.ihl = 5;
75967 p.iph.protocol = IPPROTO_IPV6;
75968 p.iph.ttl = 64;
75969 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75970 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75971
75972 if (ops->ndo_do_ioctl) {
75973 mm_segment_t oldfs = get_fs();
75974 diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
75975 index 2ae79db..8f101bf 100644
75976 --- a/net/ipv6/ah6.c
75977 +++ b/net/ipv6/ah6.c
75978 @@ -56,6 +56,8 @@ struct ah_skb_cb {
75979 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75980
75981 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75982 + unsigned int size) __size_overflow(3);
75983 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75984 unsigned int size)
75985 {
75986 unsigned int len;
75987 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75988 index 02dd203..e03fcc9 100644
75989 --- a/net/ipv6/inet6_connection_sock.c
75990 +++ b/net/ipv6/inet6_connection_sock.c
75991 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75992 #ifdef CONFIG_XFRM
75993 {
75994 struct rt6_info *rt = (struct rt6_info *)dst;
75995 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75996 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75997 }
75998 #endif
75999 }
76000 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76001 #ifdef CONFIG_XFRM
76002 if (dst) {
76003 struct rt6_info *rt = (struct rt6_info *)dst;
76004 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76005 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76006 __sk_dst_reset(sk);
76007 dst = NULL;
76008 }
76009 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76010 index 18a2719..779f36a 100644
76011 --- a/net/ipv6/ipv6_sockglue.c
76012 +++ b/net/ipv6/ipv6_sockglue.c
76013 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76014 if (sk->sk_type != SOCK_STREAM)
76015 return -ENOPROTOOPT;
76016
76017 - msg.msg_control = optval;
76018 + msg.msg_control = (void __force_kernel *)optval;
76019 msg.msg_controllen = len;
76020 msg.msg_flags = flags;
76021
76022 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
76023 index 94874b0..108a94d 100644
76024 --- a/net/ipv6/netfilter/ip6_tables.c
76025 +++ b/net/ipv6/netfilter/ip6_tables.c
76026 @@ -945,6 +945,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76027 static int
76028 copy_entries_to_user(unsigned int total_size,
76029 const struct xt_table *table,
76030 + void __user *userptr) __size_overflow(1);
76031 +static int
76032 +copy_entries_to_user(unsigned int total_size,
76033 + const struct xt_table *table,
76034 void __user *userptr)
76035 {
76036 unsigned int off, num;
76037 @@ -1194,6 +1198,10 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
76038 static int
76039 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76040 struct xt_table_info *newinfo, unsigned int num_counters,
76041 + void __user *counters_ptr) __size_overflow(5);
76042 +static int
76043 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76044 + struct xt_table_info *newinfo, unsigned int num_counters,
76045 void __user *counters_ptr)
76046 {
76047 int ret;
76048 @@ -1315,6 +1323,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76049
76050 static int
76051 do_add_counters(struct net *net, const void __user *user, unsigned int len,
76052 + int compat) __size_overflow(3);
76053 +static int
76054 +do_add_counters(struct net *net, const void __user *user, unsigned int len,
76055 int compat)
76056 {
76057 unsigned int i, curcpu;
76058 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76059 index d02f7e4..2d2a0f1 100644
76060 --- a/net/ipv6/raw.c
76061 +++ b/net/ipv6/raw.c
76062 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76063 {
76064 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76065 skb_checksum_complete(skb)) {
76066 - atomic_inc(&sk->sk_drops);
76067 + atomic_inc_unchecked(&sk->sk_drops);
76068 kfree_skb(skb);
76069 return NET_RX_DROP;
76070 }
76071 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76072 struct raw6_sock *rp = raw6_sk(sk);
76073
76074 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76075 - atomic_inc(&sk->sk_drops);
76076 + atomic_inc_unchecked(&sk->sk_drops);
76077 kfree_skb(skb);
76078 return NET_RX_DROP;
76079 }
76080 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76081
76082 if (inet->hdrincl) {
76083 if (skb_checksum_complete(skb)) {
76084 - atomic_inc(&sk->sk_drops);
76085 + atomic_inc_unchecked(&sk->sk_drops);
76086 kfree_skb(skb);
76087 return NET_RX_DROP;
76088 }
76089 @@ -602,7 +602,7 @@ out:
76090 return err;
76091 }
76092
76093 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76094 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76095 struct flowi6 *fl6, struct dst_entry **dstp,
76096 unsigned int flags)
76097 {
76098 @@ -912,12 +912,15 @@ do_confirm:
76099 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76100 char __user *optval, int optlen)
76101 {
76102 + struct icmp6_filter filter;
76103 +
76104 switch (optname) {
76105 case ICMPV6_FILTER:
76106 if (optlen > sizeof(struct icmp6_filter))
76107 optlen = sizeof(struct icmp6_filter);
76108 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76109 + if (copy_from_user(&filter, optval, optlen))
76110 return -EFAULT;
76111 + raw6_sk(sk)->filter = filter;
76112 return 0;
76113 default:
76114 return -ENOPROTOOPT;
76115 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76116 char __user *optval, int __user *optlen)
76117 {
76118 int len;
76119 + struct icmp6_filter filter;
76120
76121 switch (optname) {
76122 case ICMPV6_FILTER:
76123 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76124 len = sizeof(struct icmp6_filter);
76125 if (put_user(len, optlen))
76126 return -EFAULT;
76127 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76128 + filter = raw6_sk(sk)->filter;
76129 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76130 return -EFAULT;
76131 return 0;
76132 default:
76133 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76134 0, 0L, 0,
76135 sock_i_uid(sp), 0,
76136 sock_i_ino(sp),
76137 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76138 + atomic_read(&sp->sk_refcnt),
76139 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76140 + NULL,
76141 +#else
76142 + sp,
76143 +#endif
76144 + atomic_read_unchecked(&sp->sk_drops));
76145 }
76146
76147 static int raw6_seq_show(struct seq_file *seq, void *v)
76148 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76149 index 3edd05a..63aad01 100644
76150 --- a/net/ipv6/tcp_ipv6.c
76151 +++ b/net/ipv6/tcp_ipv6.c
76152 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76153 }
76154 #endif
76155
76156 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76157 +extern int grsec_enable_blackhole;
76158 +#endif
76159 +
76160 static void tcp_v6_hash(struct sock *sk)
76161 {
76162 if (sk->sk_state != TCP_CLOSE) {
76163 @@ -1650,6 +1654,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76164 return 0;
76165
76166 reset:
76167 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76168 + if (!grsec_enable_blackhole)
76169 +#endif
76170 tcp_v6_send_reset(sk, skb);
76171 discard:
76172 if (opt_skb)
76173 @@ -1729,12 +1736,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76174 TCP_SKB_CB(skb)->sacked = 0;
76175
76176 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76177 - if (!sk)
76178 + if (!sk) {
76179 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76180 + ret = 1;
76181 +#endif
76182 goto no_tcp_socket;
76183 + }
76184
76185 process:
76186 - if (sk->sk_state == TCP_TIME_WAIT)
76187 + if (sk->sk_state == TCP_TIME_WAIT) {
76188 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76189 + ret = 2;
76190 +#endif
76191 goto do_time_wait;
76192 + }
76193
76194 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76195 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76196 @@ -1782,6 +1797,10 @@ no_tcp_socket:
76197 bad_packet:
76198 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76199 } else {
76200 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76201 + if (!grsec_enable_blackhole || (ret == 1 &&
76202 + (skb->dev->flags & IFF_LOOPBACK)))
76203 +#endif
76204 tcp_v6_send_reset(NULL, skb);
76205 }
76206
76207 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
76208 uid,
76209 0, /* non standard timer */
76210 0, /* open_requests have no inode */
76211 - 0, req);
76212 + 0,
76213 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76214 + NULL
76215 +#else
76216 + req
76217 +#endif
76218 + );
76219 }
76220
76221 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76222 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76223 sock_i_uid(sp),
76224 icsk->icsk_probes_out,
76225 sock_i_ino(sp),
76226 - atomic_read(&sp->sk_refcnt), sp,
76227 + atomic_read(&sp->sk_refcnt),
76228 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76229 + NULL,
76230 +#else
76231 + sp,
76232 +#endif
76233 jiffies_to_clock_t(icsk->icsk_rto),
76234 jiffies_to_clock_t(icsk->icsk_ack.ato),
76235 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76236 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76237 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76238 tw->tw_substate, 0, 0,
76239 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76240 - atomic_read(&tw->tw_refcnt), tw);
76241 + atomic_read(&tw->tw_refcnt),
76242 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76243 + NULL
76244 +#else
76245 + tw
76246 +#endif
76247 + );
76248 }
76249
76250 static int tcp6_seq_show(struct seq_file *seq, void *v)
76251 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76252 index 4f96b5c..75543d7 100644
76253 --- a/net/ipv6/udp.c
76254 +++ b/net/ipv6/udp.c
76255 @@ -50,6 +50,10 @@
76256 #include <linux/seq_file.h>
76257 #include "udp_impl.h"
76258
76259 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76260 +extern int grsec_enable_blackhole;
76261 +#endif
76262 +
76263 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76264 {
76265 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76266 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76267
76268 return 0;
76269 drop:
76270 - atomic_inc(&sk->sk_drops);
76271 + atomic_inc_unchecked(&sk->sk_drops);
76272 drop_no_sk_drops_inc:
76273 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76274 kfree_skb(skb);
76275 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76276 continue;
76277 }
76278 drop:
76279 - atomic_inc(&sk->sk_drops);
76280 + atomic_inc_unchecked(&sk->sk_drops);
76281 UDP6_INC_STATS_BH(sock_net(sk),
76282 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76283 UDP6_INC_STATS_BH(sock_net(sk),
76284 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76285 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76286 proto == IPPROTO_UDPLITE);
76287
76288 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76289 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76290 +#endif
76291 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76292
76293 kfree_skb(skb);
76294 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76295 if (!sock_owned_by_user(sk))
76296 udpv6_queue_rcv_skb(sk, skb);
76297 else if (sk_add_backlog(sk, skb)) {
76298 - atomic_inc(&sk->sk_drops);
76299 + atomic_inc_unchecked(&sk->sk_drops);
76300 bh_unlock_sock(sk);
76301 sock_put(sk);
76302 goto discard;
76303 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76304 0, 0L, 0,
76305 sock_i_uid(sp), 0,
76306 sock_i_ino(sp),
76307 - atomic_read(&sp->sk_refcnt), sp,
76308 - atomic_read(&sp->sk_drops));
76309 + atomic_read(&sp->sk_refcnt),
76310 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76311 + NULL,
76312 +#else
76313 + sp,
76314 +#endif
76315 + atomic_read_unchecked(&sp->sk_drops));
76316 }
76317
76318 int udp6_seq_show(struct seq_file *seq, void *v)
76319 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76320 index 253695d..9481ce8 100644
76321 --- a/net/irda/ircomm/ircomm_tty.c
76322 +++ b/net/irda/ircomm/ircomm_tty.c
76323 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76324 add_wait_queue(&self->open_wait, &wait);
76325
76326 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76327 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76328 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76329
76330 /* As far as I can see, we protect open_count - Jean II */
76331 spin_lock_irqsave(&self->spinlock, flags);
76332 if (!tty_hung_up_p(filp)) {
76333 extra_count = 1;
76334 - self->open_count--;
76335 + local_dec(&self->open_count);
76336 }
76337 spin_unlock_irqrestore(&self->spinlock, flags);
76338 - self->blocked_open++;
76339 + local_inc(&self->blocked_open);
76340
76341 while (1) {
76342 if (tty->termios->c_cflag & CBAUD) {
76343 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76344 }
76345
76346 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76347 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76348 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76349
76350 schedule();
76351 }
76352 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76353 if (extra_count) {
76354 /* ++ is not atomic, so this should be protected - Jean II */
76355 spin_lock_irqsave(&self->spinlock, flags);
76356 - self->open_count++;
76357 + local_inc(&self->open_count);
76358 spin_unlock_irqrestore(&self->spinlock, flags);
76359 }
76360 - self->blocked_open--;
76361 + local_dec(&self->blocked_open);
76362
76363 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76364 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76365 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76366
76367 if (!retval)
76368 self->flags |= ASYNC_NORMAL_ACTIVE;
76369 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76370 }
76371 /* ++ is not atomic, so this should be protected - Jean II */
76372 spin_lock_irqsave(&self->spinlock, flags);
76373 - self->open_count++;
76374 + local_inc(&self->open_count);
76375
76376 tty->driver_data = self;
76377 self->tty = tty;
76378 spin_unlock_irqrestore(&self->spinlock, flags);
76379
76380 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76381 - self->line, self->open_count);
76382 + self->line, local_read(&self->open_count));
76383
76384 /* Not really used by us, but lets do it anyway */
76385 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76386 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76387 return;
76388 }
76389
76390 - if ((tty->count == 1) && (self->open_count != 1)) {
76391 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76392 /*
76393 * Uh, oh. tty->count is 1, which means that the tty
76394 * structure will be freed. state->count should always
76395 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76396 */
76397 IRDA_DEBUG(0, "%s(), bad serial port count; "
76398 "tty->count is 1, state->count is %d\n", __func__ ,
76399 - self->open_count);
76400 - self->open_count = 1;
76401 + local_read(&self->open_count));
76402 + local_set(&self->open_count, 1);
76403 }
76404
76405 - if (--self->open_count < 0) {
76406 + if (local_dec_return(&self->open_count) < 0) {
76407 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76408 - __func__, self->line, self->open_count);
76409 - self->open_count = 0;
76410 + __func__, self->line, local_read(&self->open_count));
76411 + local_set(&self->open_count, 0);
76412 }
76413 - if (self->open_count) {
76414 + if (local_read(&self->open_count)) {
76415 spin_unlock_irqrestore(&self->spinlock, flags);
76416
76417 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76418 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76419 tty->closing = 0;
76420 self->tty = NULL;
76421
76422 - if (self->blocked_open) {
76423 + if (local_read(&self->blocked_open)) {
76424 if (self->close_delay)
76425 schedule_timeout_interruptible(self->close_delay);
76426 wake_up_interruptible(&self->open_wait);
76427 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76428 spin_lock_irqsave(&self->spinlock, flags);
76429 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76430 self->tty = NULL;
76431 - self->open_count = 0;
76432 + local_set(&self->open_count, 0);
76433 spin_unlock_irqrestore(&self->spinlock, flags);
76434
76435 wake_up_interruptible(&self->open_wait);
76436 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76437 seq_putc(m, '\n');
76438
76439 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76440 - seq_printf(m, "Open count: %d\n", self->open_count);
76441 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76442 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76443 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76444
76445 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76446 index d5c5b8f..33beff0 100644
76447 --- a/net/iucv/af_iucv.c
76448 +++ b/net/iucv/af_iucv.c
76449 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76450
76451 write_lock_bh(&iucv_sk_list.lock);
76452
76453 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76454 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76455 while (__iucv_get_sock_by_name(name)) {
76456 sprintf(name, "%08x",
76457 - atomic_inc_return(&iucv_sk_list.autobind_name));
76458 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76459 }
76460
76461 write_unlock_bh(&iucv_sk_list.lock);
76462 diff --git a/net/key/af_key.c b/net/key/af_key.c
76463 index 11dbb22..c20f667 100644
76464 --- a/net/key/af_key.c
76465 +++ b/net/key/af_key.c
76466 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76467 static u32 get_acqseq(void)
76468 {
76469 u32 res;
76470 - static atomic_t acqseq;
76471 + static atomic_unchecked_t acqseq;
76472
76473 do {
76474 - res = atomic_inc_return(&acqseq);
76475 + res = atomic_inc_return_unchecked(&acqseq);
76476 } while (!res);
76477 return res;
76478 }
76479 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76480 index 2f0642d..e5c6fba 100644
76481 --- a/net/mac80211/ieee80211_i.h
76482 +++ b/net/mac80211/ieee80211_i.h
76483 @@ -28,6 +28,7 @@
76484 #include <net/ieee80211_radiotap.h>
76485 #include <net/cfg80211.h>
76486 #include <net/mac80211.h>
76487 +#include <asm/local.h>
76488 #include "key.h"
76489 #include "sta_info.h"
76490
76491 @@ -781,7 +782,7 @@ struct ieee80211_local {
76492 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76493 spinlock_t queue_stop_reason_lock;
76494
76495 - int open_count;
76496 + local_t open_count;
76497 int monitors, cooked_mntrs;
76498 /* number of interfaces with corresponding FIF_ flags */
76499 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76500 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76501 index 8e2137b..2974283 100644
76502 --- a/net/mac80211/iface.c
76503 +++ b/net/mac80211/iface.c
76504 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76505 break;
76506 }
76507
76508 - if (local->open_count == 0) {
76509 + if (local_read(&local->open_count) == 0) {
76510 res = drv_start(local);
76511 if (res)
76512 goto err_del_bss;
76513 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76514 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76515
76516 if (!is_valid_ether_addr(dev->dev_addr)) {
76517 - if (!local->open_count)
76518 + if (!local_read(&local->open_count))
76519 drv_stop(local);
76520 return -EADDRNOTAVAIL;
76521 }
76522 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76523 mutex_unlock(&local->mtx);
76524
76525 if (coming_up)
76526 - local->open_count++;
76527 + local_inc(&local->open_count);
76528
76529 if (hw_reconf_flags)
76530 ieee80211_hw_config(local, hw_reconf_flags);
76531 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76532 err_del_interface:
76533 drv_remove_interface(local, sdata);
76534 err_stop:
76535 - if (!local->open_count)
76536 + if (!local_read(&local->open_count))
76537 drv_stop(local);
76538 err_del_bss:
76539 sdata->bss = NULL;
76540 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76541 }
76542
76543 if (going_down)
76544 - local->open_count--;
76545 + local_dec(&local->open_count);
76546
76547 switch (sdata->vif.type) {
76548 case NL80211_IFTYPE_AP_VLAN:
76549 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76550
76551 ieee80211_recalc_ps(local, -1);
76552
76553 - if (local->open_count == 0) {
76554 + if (local_read(&local->open_count) == 0) {
76555 if (local->ops->napi_poll)
76556 napi_disable(&local->napi);
76557 ieee80211_clear_tx_pending(local);
76558 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76559 index b142bd4..a651749 100644
76560 --- a/net/mac80211/main.c
76561 +++ b/net/mac80211/main.c
76562 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76563 local->hw.conf.power_level = power;
76564 }
76565
76566 - if (changed && local->open_count) {
76567 + if (changed && local_read(&local->open_count)) {
76568 ret = drv_config(local, changed);
76569 /*
76570 * Goal:
76571 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76572 index 596efaf..8f1911f 100644
76573 --- a/net/mac80211/pm.c
76574 +++ b/net/mac80211/pm.c
76575 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76576 struct ieee80211_sub_if_data *sdata;
76577 struct sta_info *sta;
76578
76579 - if (!local->open_count)
76580 + if (!local_read(&local->open_count))
76581 goto suspend;
76582
76583 ieee80211_scan_cancel(local);
76584 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76585 cancel_work_sync(&local->dynamic_ps_enable_work);
76586 del_timer_sync(&local->dynamic_ps_timer);
76587
76588 - local->wowlan = wowlan && local->open_count;
76589 + local->wowlan = wowlan && local_read(&local->open_count);
76590 if (local->wowlan) {
76591 int err = drv_suspend(local, wowlan);
76592 if (err < 0) {
76593 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76594 }
76595
76596 /* stop hardware - this must stop RX */
76597 - if (local->open_count)
76598 + if (local_read(&local->open_count))
76599 ieee80211_stop_device(local);
76600
76601 suspend:
76602 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76603 index f9b8e81..bb89b46 100644
76604 --- a/net/mac80211/rate.c
76605 +++ b/net/mac80211/rate.c
76606 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76607
76608 ASSERT_RTNL();
76609
76610 - if (local->open_count)
76611 + if (local_read(&local->open_count))
76612 return -EBUSY;
76613
76614 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76615 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76616 index c97a065..ff61928 100644
76617 --- a/net/mac80211/rc80211_pid_debugfs.c
76618 +++ b/net/mac80211/rc80211_pid_debugfs.c
76619 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76620
76621 spin_unlock_irqrestore(&events->lock, status);
76622
76623 - if (copy_to_user(buf, pb, p))
76624 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76625 return -EFAULT;
76626
76627 return p;
76628 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76629 index 9919892..8c49803 100644
76630 --- a/net/mac80211/util.c
76631 +++ b/net/mac80211/util.c
76632 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76633 }
76634 #endif
76635 /* everything else happens only if HW was up & running */
76636 - if (!local->open_count)
76637 + if (!local_read(&local->open_count))
76638 goto wake_up;
76639
76640 /*
76641 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76642 index f8ac4ef..b02560b 100644
76643 --- a/net/netfilter/Kconfig
76644 +++ b/net/netfilter/Kconfig
76645 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
76646
76647 To compile it as a module, choose M here. If unsure, say N.
76648
76649 +config NETFILTER_XT_MATCH_GRADM
76650 + tristate '"gradm" match support'
76651 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76652 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76653 + ---help---
76654 + The gradm match allows to match on grsecurity RBAC being enabled.
76655 + It is useful when iptables rules are applied early on bootup to
76656 + prevent connections to the machine (except from a trusted host)
76657 + while the RBAC system is disabled.
76658 +
76659 config NETFILTER_XT_MATCH_HASHLIMIT
76660 tristate '"hashlimit" match support'
76661 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76662 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76663 index 40f4c3d..0d5dd6b 100644
76664 --- a/net/netfilter/Makefile
76665 +++ b/net/netfilter/Makefile
76666 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76667 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76668 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76669 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76670 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76671 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76672 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76673 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76674 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76675 index 29fa5ba..8debc79 100644
76676 --- a/net/netfilter/ipvs/ip_vs_conn.c
76677 +++ b/net/netfilter/ipvs/ip_vs_conn.c
76678 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76679 /* Increase the refcnt counter of the dest */
76680 atomic_inc(&dest->refcnt);
76681
76682 - conn_flags = atomic_read(&dest->conn_flags);
76683 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
76684 if (cp->protocol != IPPROTO_UDP)
76685 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76686 /* Bind with the destination and its corresponding transmitter */
76687 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76688 atomic_set(&cp->refcnt, 1);
76689
76690 atomic_set(&cp->n_control, 0);
76691 - atomic_set(&cp->in_pkts, 0);
76692 + atomic_set_unchecked(&cp->in_pkts, 0);
76693
76694 atomic_inc(&ipvs->conn_count);
76695 if (flags & IP_VS_CONN_F_NO_CPORT)
76696 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76697
76698 /* Don't drop the entry if its number of incoming packets is not
76699 located in [0, 8] */
76700 - i = atomic_read(&cp->in_pkts);
76701 + i = atomic_read_unchecked(&cp->in_pkts);
76702 if (i > 8 || i < 0) return 0;
76703
76704 if (!todrop_rate[i]) return 0;
76705 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76706 index 2555816..31492d9 100644
76707 --- a/net/netfilter/ipvs/ip_vs_core.c
76708 +++ b/net/netfilter/ipvs/ip_vs_core.c
76709 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76710 ret = cp->packet_xmit(skb, cp, pd->pp);
76711 /* do not touch skb anymore */
76712
76713 - atomic_inc(&cp->in_pkts);
76714 + atomic_inc_unchecked(&cp->in_pkts);
76715 ip_vs_conn_put(cp);
76716 return ret;
76717 }
76718 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76719 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76720 pkts = sysctl_sync_threshold(ipvs);
76721 else
76722 - pkts = atomic_add_return(1, &cp->in_pkts);
76723 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76724
76725 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76726 cp->protocol == IPPROTO_SCTP) {
76727 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76728 index b3afe18..08ec940 100644
76729 --- a/net/netfilter/ipvs/ip_vs_ctl.c
76730 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
76731 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76732 ip_vs_rs_hash(ipvs, dest);
76733 write_unlock_bh(&ipvs->rs_lock);
76734 }
76735 - atomic_set(&dest->conn_flags, conn_flags);
76736 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
76737
76738 /* bind the service */
76739 if (!dest->svc) {
76740 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76741 " %-7s %-6d %-10d %-10d\n",
76742 &dest->addr.in6,
76743 ntohs(dest->port),
76744 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76745 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76746 atomic_read(&dest->weight),
76747 atomic_read(&dest->activeconns),
76748 atomic_read(&dest->inactconns));
76749 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76750 "%-7s %-6d %-10d %-10d\n",
76751 ntohl(dest->addr.ip),
76752 ntohs(dest->port),
76753 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76754 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76755 atomic_read(&dest->weight),
76756 atomic_read(&dest->activeconns),
76757 atomic_read(&dest->inactconns));
76758 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76759
76760 entry.addr = dest->addr.ip;
76761 entry.port = dest->port;
76762 - entry.conn_flags = atomic_read(&dest->conn_flags);
76763 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76764 entry.weight = atomic_read(&dest->weight);
76765 entry.u_threshold = dest->u_threshold;
76766 entry.l_threshold = dest->l_threshold;
76767 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76768 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76769
76770 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76771 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76772 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76773 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76774 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76775 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76776 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76777 index 8a0d6d6..90ec197 100644
76778 --- a/net/netfilter/ipvs/ip_vs_sync.c
76779 +++ b/net/netfilter/ipvs/ip_vs_sync.c
76780 @@ -649,7 +649,7 @@ control:
76781 * i.e only increment in_pkts for Templates.
76782 */
76783 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76784 - int pkts = atomic_add_return(1, &cp->in_pkts);
76785 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76786
76787 if (pkts % sysctl_sync_period(ipvs) != 1)
76788 return;
76789 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76790
76791 if (opt)
76792 memcpy(&cp->in_seq, opt, sizeof(*opt));
76793 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76794 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76795 cp->state = state;
76796 cp->old_state = cp->state;
76797 /*
76798 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76799 index 7fd66de..e6fb361 100644
76800 --- a/net/netfilter/ipvs/ip_vs_xmit.c
76801 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
76802 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76803 else
76804 rc = NF_ACCEPT;
76805 /* do not touch skb anymore */
76806 - atomic_inc(&cp->in_pkts);
76807 + atomic_inc_unchecked(&cp->in_pkts);
76808 goto out;
76809 }
76810
76811 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76812 else
76813 rc = NF_ACCEPT;
76814 /* do not touch skb anymore */
76815 - atomic_inc(&cp->in_pkts);
76816 + atomic_inc_unchecked(&cp->in_pkts);
76817 goto out;
76818 }
76819
76820 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76821 index 66b2c54..c7884e3 100644
76822 --- a/net/netfilter/nfnetlink_log.c
76823 +++ b/net/netfilter/nfnetlink_log.c
76824 @@ -70,7 +70,7 @@ struct nfulnl_instance {
76825 };
76826
76827 static DEFINE_SPINLOCK(instances_lock);
76828 -static atomic_t global_seq;
76829 +static atomic_unchecked_t global_seq;
76830
76831 #define INSTANCE_BUCKETS 16
76832 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76833 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76834 /* global sequence number */
76835 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76836 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76837 - htonl(atomic_inc_return(&global_seq)));
76838 + htonl(atomic_inc_return_unchecked(&global_seq)));
76839
76840 if (data_len) {
76841 struct nlattr *nla;
76842 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76843 new file mode 100644
76844 index 0000000..6905327
76845 --- /dev/null
76846 +++ b/net/netfilter/xt_gradm.c
76847 @@ -0,0 +1,51 @@
76848 +/*
76849 + * gradm match for netfilter
76850 + * Copyright © Zbigniew Krzystolik, 2010
76851 + *
76852 + * This program is free software; you can redistribute it and/or modify
76853 + * it under the terms of the GNU General Public License; either version
76854 + * 2 or 3 as published by the Free Software Foundation.
76855 + */
76856 +#include <linux/module.h>
76857 +#include <linux/moduleparam.h>
76858 +#include <linux/skbuff.h>
76859 +#include <linux/netfilter/x_tables.h>
76860 +#include <linux/grsecurity.h>
76861 +#include <linux/netfilter/xt_gradm.h>
76862 +
76863 +static bool
76864 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
76865 +{
76866 + const struct xt_gradm_mtinfo *info = par->matchinfo;
76867 + bool retval = false;
76868 + if (gr_acl_is_enabled())
76869 + retval = true;
76870 + return retval ^ info->invflags;
76871 +}
76872 +
76873 +static struct xt_match gradm_mt_reg __read_mostly = {
76874 + .name = "gradm",
76875 + .revision = 0,
76876 + .family = NFPROTO_UNSPEC,
76877 + .match = gradm_mt,
76878 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76879 + .me = THIS_MODULE,
76880 +};
76881 +
76882 +static int __init gradm_mt_init(void)
76883 +{
76884 + return xt_register_match(&gradm_mt_reg);
76885 +}
76886 +
76887 +static void __exit gradm_mt_exit(void)
76888 +{
76889 + xt_unregister_match(&gradm_mt_reg);
76890 +}
76891 +
76892 +module_init(gradm_mt_init);
76893 +module_exit(gradm_mt_exit);
76894 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
76895 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
76896 +MODULE_LICENSE("GPL");
76897 +MODULE_ALIAS("ipt_gradm");
76898 +MODULE_ALIAS("ip6t_gradm");
76899 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
76900 index 4fe4fb4..87a89e5 100644
76901 --- a/net/netfilter/xt_statistic.c
76902 +++ b/net/netfilter/xt_statistic.c
76903 @@ -19,7 +19,7 @@
76904 #include <linux/module.h>
76905
76906 struct xt_statistic_priv {
76907 - atomic_t count;
76908 + atomic_unchecked_t count;
76909 } ____cacheline_aligned_in_smp;
76910
76911 MODULE_LICENSE("GPL");
76912 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
76913 break;
76914 case XT_STATISTIC_MODE_NTH:
76915 do {
76916 - oval = atomic_read(&info->master->count);
76917 + oval = atomic_read_unchecked(&info->master->count);
76918 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
76919 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
76920 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
76921 if (nval == 0)
76922 ret = !ret;
76923 break;
76924 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
76925 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
76926 if (info->master == NULL)
76927 return -ENOMEM;
76928 - atomic_set(&info->master->count, info->u.nth.count);
76929 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
76930
76931 return 0;
76932 }
76933 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
76934 index 629b061..8f415cc 100644
76935 --- a/net/netlink/af_netlink.c
76936 +++ b/net/netlink/af_netlink.c
76937 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
76938 sk->sk_error_report(sk);
76939 }
76940 }
76941 - atomic_inc(&sk->sk_drops);
76942 + atomic_inc_unchecked(&sk->sk_drops);
76943 }
76944
76945 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76946 @@ -829,12 +829,19 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
76947 return 0;
76948 }
76949
76950 -int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76951 +static int __netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76952 {
76953 int len = skb->len;
76954
76955 skb_queue_tail(&sk->sk_receive_queue, skb);
76956 sk->sk_data_ready(sk, len);
76957 + return len;
76958 +}
76959 +
76960 +int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
76961 +{
76962 + int len = __netlink_sendskb(sk, skb);
76963 +
76964 sock_put(sk);
76965 return len;
76966 }
76967 @@ -957,8 +964,7 @@ static int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
76968 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
76969 !test_bit(0, &nlk->state)) {
76970 skb_set_owner_r(skb, sk);
76971 - skb_queue_tail(&sk->sk_receive_queue, skb);
76972 - sk->sk_data_ready(sk, skb->len);
76973 + __netlink_sendskb(sk, skb);
76974 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
76975 }
76976 return -1;
76977 @@ -1680,10 +1686,8 @@ static int netlink_dump(struct sock *sk)
76978
76979 if (sk_filter(sk, skb))
76980 kfree_skb(skb);
76981 - else {
76982 - skb_queue_tail(&sk->sk_receive_queue, skb);
76983 - sk->sk_data_ready(sk, skb->len);
76984 - }
76985 + else
76986 + __netlink_sendskb(sk, skb);
76987 return 0;
76988 }
76989
76990 @@ -1697,10 +1701,8 @@ static int netlink_dump(struct sock *sk)
76991
76992 if (sk_filter(sk, skb))
76993 kfree_skb(skb);
76994 - else {
76995 - skb_queue_tail(&sk->sk_receive_queue, skb);
76996 - sk->sk_data_ready(sk, skb->len);
76997 - }
76998 + else
76999 + __netlink_sendskb(sk, skb);
77000
77001 if (cb->done)
77002 cb->done(cb);
77003 @@ -1995,7 +1997,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77004 sk_wmem_alloc_get(s),
77005 nlk->cb,
77006 atomic_read(&s->sk_refcnt),
77007 - atomic_read(&s->sk_drops),
77008 + atomic_read_unchecked(&s->sk_drops),
77009 sock_i_ino(s)
77010 );
77011
77012 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77013 index 7dab229..212156f 100644
77014 --- a/net/netrom/af_netrom.c
77015 +++ b/net/netrom/af_netrom.c
77016 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77017 struct sock *sk = sock->sk;
77018 struct nr_sock *nr = nr_sk(sk);
77019
77020 + memset(sax, 0, sizeof(*sax));
77021 lock_sock(sk);
77022 if (peer != 0) {
77023 if (sk->sk_state != TCP_ESTABLISHED) {
77024 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77025 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77026 } else {
77027 sax->fsa_ax25.sax25_family = AF_NETROM;
77028 - sax->fsa_ax25.sax25_ndigis = 0;
77029 sax->fsa_ax25.sax25_call = nr->source_addr;
77030 *uaddr_len = sizeof(struct sockaddr_ax25);
77031 }
77032 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77033 index 2dbb32b..a1b4722 100644
77034 --- a/net/packet/af_packet.c
77035 +++ b/net/packet/af_packet.c
77036 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77037
77038 spin_lock(&sk->sk_receive_queue.lock);
77039 po->stats.tp_packets++;
77040 - skb->dropcount = atomic_read(&sk->sk_drops);
77041 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77042 __skb_queue_tail(&sk->sk_receive_queue, skb);
77043 spin_unlock(&sk->sk_receive_queue.lock);
77044 sk->sk_data_ready(sk, skb->len);
77045 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77046 drop_n_acct:
77047 spin_lock(&sk->sk_receive_queue.lock);
77048 po->stats.tp_drops++;
77049 - atomic_inc(&sk->sk_drops);
77050 + atomic_inc_unchecked(&sk->sk_drops);
77051 spin_unlock(&sk->sk_receive_queue.lock);
77052
77053 drop_n_restore:
77054 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77055 case PACKET_HDRLEN:
77056 if (len > sizeof(int))
77057 len = sizeof(int);
77058 - if (copy_from_user(&val, optval, len))
77059 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77060 return -EFAULT;
77061 switch (val) {
77062 case TPACKET_V1:
77063 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77064
77065 if (put_user(len, optlen))
77066 return -EFAULT;
77067 - if (copy_to_user(optval, data, len))
77068 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77069 return -EFAULT;
77070 return 0;
77071 }
77072 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77073 index d65f699..05aa6ce 100644
77074 --- a/net/phonet/af_phonet.c
77075 +++ b/net/phonet/af_phonet.c
77076 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77077 {
77078 struct phonet_protocol *pp;
77079
77080 - if (protocol >= PHONET_NPROTO)
77081 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77082 return NULL;
77083
77084 rcu_read_lock();
77085 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77086 {
77087 int err = 0;
77088
77089 - if (protocol >= PHONET_NPROTO)
77090 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77091 return -EINVAL;
77092
77093 err = proto_register(pp->prot, 1);
77094 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77095 index 9f60008..ae96f04 100644
77096 --- a/net/phonet/pep.c
77097 +++ b/net/phonet/pep.c
77098 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77099
77100 case PNS_PEP_CTRL_REQ:
77101 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77102 - atomic_inc(&sk->sk_drops);
77103 + atomic_inc_unchecked(&sk->sk_drops);
77104 break;
77105 }
77106 __skb_pull(skb, 4);
77107 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77108 }
77109
77110 if (pn->rx_credits == 0) {
77111 - atomic_inc(&sk->sk_drops);
77112 + atomic_inc_unchecked(&sk->sk_drops);
77113 err = -ENOBUFS;
77114 break;
77115 }
77116 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77117 }
77118
77119 if (pn->rx_credits == 0) {
77120 - atomic_inc(&sk->sk_drops);
77121 + atomic_inc_unchecked(&sk->sk_drops);
77122 err = NET_RX_DROP;
77123 break;
77124 }
77125 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77126 index 4c7eff3..59c727f 100644
77127 --- a/net/phonet/socket.c
77128 +++ b/net/phonet/socket.c
77129 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77130 pn->resource, sk->sk_state,
77131 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77132 sock_i_uid(sk), sock_i_ino(sk),
77133 - atomic_read(&sk->sk_refcnt), sk,
77134 - atomic_read(&sk->sk_drops), &len);
77135 + atomic_read(&sk->sk_refcnt),
77136 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77137 + NULL,
77138 +#else
77139 + sk,
77140 +#endif
77141 + atomic_read_unchecked(&sk->sk_drops), &len);
77142 }
77143 seq_printf(seq, "%*s\n", 127 - len, "");
77144 return 0;
77145 diff --git a/net/rds/cong.c b/net/rds/cong.c
77146 index e5b65ac..f3b6fb7 100644
77147 --- a/net/rds/cong.c
77148 +++ b/net/rds/cong.c
77149 @@ -78,7 +78,7 @@
77150 * finds that the saved generation number is smaller than the global generation
77151 * number, it wakes up the process.
77152 */
77153 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77154 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77155
77156 /*
77157 * Congestion monitoring
77158 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77159 rdsdebug("waking map %p for %pI4\n",
77160 map, &map->m_addr);
77161 rds_stats_inc(s_cong_update_received);
77162 - atomic_inc(&rds_cong_generation);
77163 + atomic_inc_unchecked(&rds_cong_generation);
77164 if (waitqueue_active(&map->m_waitq))
77165 wake_up(&map->m_waitq);
77166 if (waitqueue_active(&rds_poll_waitq))
77167 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77168
77169 int rds_cong_updated_since(unsigned long *recent)
77170 {
77171 - unsigned long gen = atomic_read(&rds_cong_generation);
77172 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77173
77174 if (likely(*recent == gen))
77175 return 0;
77176 diff --git a/net/rds/ib.h b/net/rds/ib.h
77177 index edfaaaf..8c89879 100644
77178 --- a/net/rds/ib.h
77179 +++ b/net/rds/ib.h
77180 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77181 /* sending acks */
77182 unsigned long i_ack_flags;
77183 #ifdef KERNEL_HAS_ATOMIC64
77184 - atomic64_t i_ack_next; /* next ACK to send */
77185 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77186 #else
77187 spinlock_t i_ack_lock; /* protect i_ack_next */
77188 u64 i_ack_next; /* next ACK to send */
77189 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77190 index 51c8689..36c555f 100644
77191 --- a/net/rds/ib_cm.c
77192 +++ b/net/rds/ib_cm.c
77193 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77194 /* Clear the ACK state */
77195 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77196 #ifdef KERNEL_HAS_ATOMIC64
77197 - atomic64_set(&ic->i_ack_next, 0);
77198 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77199 #else
77200 ic->i_ack_next = 0;
77201 #endif
77202 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77203 index e29e0ca..fa3a6a3 100644
77204 --- a/net/rds/ib_recv.c
77205 +++ b/net/rds/ib_recv.c
77206 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77207 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77208 int ack_required)
77209 {
77210 - atomic64_set(&ic->i_ack_next, seq);
77211 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77212 if (ack_required) {
77213 smp_mb__before_clear_bit();
77214 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77215 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77216 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77217 smp_mb__after_clear_bit();
77218
77219 - return atomic64_read(&ic->i_ack_next);
77220 + return atomic64_read_unchecked(&ic->i_ack_next);
77221 }
77222 #endif
77223
77224 diff --git a/net/rds/iw.h b/net/rds/iw.h
77225 index 04ce3b1..48119a6 100644
77226 --- a/net/rds/iw.h
77227 +++ b/net/rds/iw.h
77228 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77229 /* sending acks */
77230 unsigned long i_ack_flags;
77231 #ifdef KERNEL_HAS_ATOMIC64
77232 - atomic64_t i_ack_next; /* next ACK to send */
77233 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77234 #else
77235 spinlock_t i_ack_lock; /* protect i_ack_next */
77236 u64 i_ack_next; /* next ACK to send */
77237 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77238 index 9556d28..f046d0e 100644
77239 --- a/net/rds/iw_cm.c
77240 +++ b/net/rds/iw_cm.c
77241 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77242 /* Clear the ACK state */
77243 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77244 #ifdef KERNEL_HAS_ATOMIC64
77245 - atomic64_set(&ic->i_ack_next, 0);
77246 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77247 #else
77248 ic->i_ack_next = 0;
77249 #endif
77250 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77251 index 5e57347..3916042 100644
77252 --- a/net/rds/iw_recv.c
77253 +++ b/net/rds/iw_recv.c
77254 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77255 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77256 int ack_required)
77257 {
77258 - atomic64_set(&ic->i_ack_next, seq);
77259 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77260 if (ack_required) {
77261 smp_mb__before_clear_bit();
77262 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77263 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77264 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77265 smp_mb__after_clear_bit();
77266
77267 - return atomic64_read(&ic->i_ack_next);
77268 + return atomic64_read_unchecked(&ic->i_ack_next);
77269 }
77270 #endif
77271
77272 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77273 index edac9ef..16bcb98 100644
77274 --- a/net/rds/tcp.c
77275 +++ b/net/rds/tcp.c
77276 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77277 int val = 1;
77278
77279 set_fs(KERNEL_DS);
77280 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77281 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77282 sizeof(val));
77283 set_fs(oldfs);
77284 }
77285 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77286 index 1b4fd68..2234175 100644
77287 --- a/net/rds/tcp_send.c
77288 +++ b/net/rds/tcp_send.c
77289 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77290
77291 oldfs = get_fs();
77292 set_fs(KERNEL_DS);
77293 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77294 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77295 sizeof(val));
77296 set_fs(oldfs);
77297 }
77298 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77299 index 74c064c..fdec26f 100644
77300 --- a/net/rxrpc/af_rxrpc.c
77301 +++ b/net/rxrpc/af_rxrpc.c
77302 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77303 __be32 rxrpc_epoch;
77304
77305 /* current debugging ID */
77306 -atomic_t rxrpc_debug_id;
77307 +atomic_unchecked_t rxrpc_debug_id;
77308
77309 /* count of skbs currently in use */
77310 atomic_t rxrpc_n_skbs;
77311 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77312 index c3126e8..21facc7 100644
77313 --- a/net/rxrpc/ar-ack.c
77314 +++ b/net/rxrpc/ar-ack.c
77315 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77316
77317 _enter("{%d,%d,%d,%d},",
77318 call->acks_hard, call->acks_unacked,
77319 - atomic_read(&call->sequence),
77320 + atomic_read_unchecked(&call->sequence),
77321 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77322
77323 stop = 0;
77324 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77325
77326 /* each Tx packet has a new serial number */
77327 sp->hdr.serial =
77328 - htonl(atomic_inc_return(&call->conn->serial));
77329 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77330
77331 hdr = (struct rxrpc_header *) txb->head;
77332 hdr->serial = sp->hdr.serial;
77333 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77334 */
77335 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77336 {
77337 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77338 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77339 }
77340
77341 /*
77342 @@ -629,7 +629,7 @@ process_further:
77343
77344 latest = ntohl(sp->hdr.serial);
77345 hard = ntohl(ack.firstPacket);
77346 - tx = atomic_read(&call->sequence);
77347 + tx = atomic_read_unchecked(&call->sequence);
77348
77349 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77350 latest,
77351 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77352 goto maybe_reschedule;
77353
77354 send_ACK_with_skew:
77355 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77356 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77357 ntohl(ack.serial));
77358 send_ACK:
77359 mtu = call->conn->trans->peer->if_mtu;
77360 @@ -1173,7 +1173,7 @@ send_ACK:
77361 ackinfo.rxMTU = htonl(5692);
77362 ackinfo.jumbo_max = htonl(4);
77363
77364 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77365 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77366 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77367 ntohl(hdr.serial),
77368 ntohs(ack.maxSkew),
77369 @@ -1191,7 +1191,7 @@ send_ACK:
77370 send_message:
77371 _debug("send message");
77372
77373 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77374 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77375 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77376 send_message_2:
77377
77378 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77379 index bf656c2..48f9d27 100644
77380 --- a/net/rxrpc/ar-call.c
77381 +++ b/net/rxrpc/ar-call.c
77382 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77383 spin_lock_init(&call->lock);
77384 rwlock_init(&call->state_lock);
77385 atomic_set(&call->usage, 1);
77386 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77387 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77388 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77389
77390 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77391 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77392 index 4106ca9..a338d7a 100644
77393 --- a/net/rxrpc/ar-connection.c
77394 +++ b/net/rxrpc/ar-connection.c
77395 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77396 rwlock_init(&conn->lock);
77397 spin_lock_init(&conn->state_lock);
77398 atomic_set(&conn->usage, 1);
77399 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77400 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77401 conn->avail_calls = RXRPC_MAXCALLS;
77402 conn->size_align = 4;
77403 conn->header_size = sizeof(struct rxrpc_header);
77404 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77405 index e7ed43a..6afa140 100644
77406 --- a/net/rxrpc/ar-connevent.c
77407 +++ b/net/rxrpc/ar-connevent.c
77408 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77409
77410 len = iov[0].iov_len + iov[1].iov_len;
77411
77412 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77413 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77414 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77415
77416 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77417 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77418 index 1a2b0633..e8d1382 100644
77419 --- a/net/rxrpc/ar-input.c
77420 +++ b/net/rxrpc/ar-input.c
77421 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77422 /* track the latest serial number on this connection for ACK packet
77423 * information */
77424 serial = ntohl(sp->hdr.serial);
77425 - hi_serial = atomic_read(&call->conn->hi_serial);
77426 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77427 while (serial > hi_serial)
77428 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77429 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77430 serial);
77431
77432 /* request ACK generation for any ACK or DATA packet that requests
77433 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77434 index 8e22bd3..f66d1c0 100644
77435 --- a/net/rxrpc/ar-internal.h
77436 +++ b/net/rxrpc/ar-internal.h
77437 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77438 int error; /* error code for local abort */
77439 int debug_id; /* debug ID for printks */
77440 unsigned call_counter; /* call ID counter */
77441 - atomic_t serial; /* packet serial number counter */
77442 - atomic_t hi_serial; /* highest serial number received */
77443 + atomic_unchecked_t serial; /* packet serial number counter */
77444 + atomic_unchecked_t hi_serial; /* highest serial number received */
77445 u8 avail_calls; /* number of calls available */
77446 u8 size_align; /* data size alignment (for security) */
77447 u8 header_size; /* rxrpc + security header size */
77448 @@ -346,7 +346,7 @@ struct rxrpc_call {
77449 spinlock_t lock;
77450 rwlock_t state_lock; /* lock for state transition */
77451 atomic_t usage;
77452 - atomic_t sequence; /* Tx data packet sequence counter */
77453 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77454 u32 abort_code; /* local/remote abort code */
77455 enum { /* current state of call */
77456 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77457 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77458 */
77459 extern atomic_t rxrpc_n_skbs;
77460 extern __be32 rxrpc_epoch;
77461 -extern atomic_t rxrpc_debug_id;
77462 +extern atomic_unchecked_t rxrpc_debug_id;
77463 extern struct workqueue_struct *rxrpc_workqueue;
77464
77465 /*
77466 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77467 index 87f7135..74d3703 100644
77468 --- a/net/rxrpc/ar-local.c
77469 +++ b/net/rxrpc/ar-local.c
77470 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77471 spin_lock_init(&local->lock);
77472 rwlock_init(&local->services_lock);
77473 atomic_set(&local->usage, 1);
77474 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77475 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77476 memcpy(&local->srx, srx, sizeof(*srx));
77477 }
77478
77479 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77480 index 16ae887..d24f12b 100644
77481 --- a/net/rxrpc/ar-output.c
77482 +++ b/net/rxrpc/ar-output.c
77483 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77484 sp->hdr.cid = call->cid;
77485 sp->hdr.callNumber = call->call_id;
77486 sp->hdr.seq =
77487 - htonl(atomic_inc_return(&call->sequence));
77488 + htonl(atomic_inc_return_unchecked(&call->sequence));
77489 sp->hdr.serial =
77490 - htonl(atomic_inc_return(&conn->serial));
77491 + htonl(atomic_inc_return_unchecked(&conn->serial));
77492 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77493 sp->hdr.userStatus = 0;
77494 sp->hdr.securityIndex = conn->security_ix;
77495 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77496 index 2754f09..b20e38f 100644
77497 --- a/net/rxrpc/ar-peer.c
77498 +++ b/net/rxrpc/ar-peer.c
77499 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77500 INIT_LIST_HEAD(&peer->error_targets);
77501 spin_lock_init(&peer->lock);
77502 atomic_set(&peer->usage, 1);
77503 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77504 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77505 memcpy(&peer->srx, srx, sizeof(*srx));
77506
77507 rxrpc_assess_MTU_size(peer);
77508 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77509 index 38047f7..9f48511 100644
77510 --- a/net/rxrpc/ar-proc.c
77511 +++ b/net/rxrpc/ar-proc.c
77512 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77513 atomic_read(&conn->usage),
77514 rxrpc_conn_states[conn->state],
77515 key_serial(conn->key),
77516 - atomic_read(&conn->serial),
77517 - atomic_read(&conn->hi_serial));
77518 + atomic_read_unchecked(&conn->serial),
77519 + atomic_read_unchecked(&conn->hi_serial));
77520
77521 return 0;
77522 }
77523 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77524 index 92df566..87ec1bf 100644
77525 --- a/net/rxrpc/ar-transport.c
77526 +++ b/net/rxrpc/ar-transport.c
77527 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77528 spin_lock_init(&trans->client_lock);
77529 rwlock_init(&trans->conn_lock);
77530 atomic_set(&trans->usage, 1);
77531 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77532 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77533
77534 if (peer->srx.transport.family == AF_INET) {
77535 switch (peer->srx.transport_type) {
77536 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77537 index 7635107..4670276 100644
77538 --- a/net/rxrpc/rxkad.c
77539 +++ b/net/rxrpc/rxkad.c
77540 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77541
77542 len = iov[0].iov_len + iov[1].iov_len;
77543
77544 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77545 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77546 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77547
77548 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77549 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77550
77551 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77552
77553 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77554 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77555 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77556
77557 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77558 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77559 index 1e2eee8..ce3967e 100644
77560 --- a/net/sctp/proc.c
77561 +++ b/net/sctp/proc.c
77562 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77563 seq_printf(seq,
77564 "%8pK %8pK %-3d %-3d %-2d %-4d "
77565 "%4d %8d %8d %7d %5lu %-5d %5d ",
77566 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77567 + assoc, sk,
77568 + sctp_sk(sk)->type, sk->sk_state,
77569 assoc->state, hash,
77570 assoc->assoc_id,
77571 assoc->sndbuf_used,
77572 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77573 index 408ebd0..202aa85 100644
77574 --- a/net/sctp/socket.c
77575 +++ b/net/sctp/socket.c
77576 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77577 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77578 if (space_left < addrlen)
77579 return -ENOMEM;
77580 - if (copy_to_user(to, &temp, addrlen))
77581 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77582 return -EFAULT;
77583 to += addrlen;
77584 cnt++;
77585 diff --git a/net/socket.c b/net/socket.c
77586 index 28a96af..61a7a06 100644
77587 --- a/net/socket.c
77588 +++ b/net/socket.c
77589 @@ -88,6 +88,7 @@
77590 #include <linux/nsproxy.h>
77591 #include <linux/magic.h>
77592 #include <linux/slab.h>
77593 +#include <linux/in.h>
77594
77595 #include <asm/uaccess.h>
77596 #include <asm/unistd.h>
77597 @@ -105,6 +106,8 @@
77598 #include <linux/sockios.h>
77599 #include <linux/atalk.h>
77600
77601 +#include <linux/grsock.h>
77602 +
77603 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
77604 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
77605 unsigned long nr_segs, loff_t pos);
77606 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
77607 &sockfs_dentry_operations, SOCKFS_MAGIC);
77608 }
77609
77610 -static struct vfsmount *sock_mnt __read_mostly;
77611 +struct vfsmount *sock_mnt __read_mostly;
77612
77613 static struct file_system_type sock_fs_type = {
77614 .name = "sockfs",
77615 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
77616 return -EAFNOSUPPORT;
77617 if (type < 0 || type >= SOCK_MAX)
77618 return -EINVAL;
77619 + if (protocol < 0)
77620 + return -EINVAL;
77621
77622 /* Compatibility.
77623
77624 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
77625 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
77626 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
77627
77628 + if(!gr_search_socket(family, type, protocol)) {
77629 + retval = -EACCES;
77630 + goto out;
77631 + }
77632 +
77633 + if (gr_handle_sock_all(family, type, protocol)) {
77634 + retval = -EACCES;
77635 + goto out;
77636 + }
77637 +
77638 retval = sock_create(family, type, protocol, &sock);
77639 if (retval < 0)
77640 goto out;
77641 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77642 if (sock) {
77643 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
77644 if (err >= 0) {
77645 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
77646 + err = -EACCES;
77647 + goto error;
77648 + }
77649 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
77650 + if (err)
77651 + goto error;
77652 +
77653 err = security_socket_bind(sock,
77654 (struct sockaddr *)&address,
77655 addrlen);
77656 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77657 (struct sockaddr *)
77658 &address, addrlen);
77659 }
77660 +error:
77661 fput_light(sock->file, fput_needed);
77662 }
77663 return err;
77664 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
77665 if ((unsigned)backlog > somaxconn)
77666 backlog = somaxconn;
77667
77668 + if (gr_handle_sock_server_other(sock->sk)) {
77669 + err = -EPERM;
77670 + goto error;
77671 + }
77672 +
77673 + err = gr_search_listen(sock);
77674 + if (err)
77675 + goto error;
77676 +
77677 err = security_socket_listen(sock, backlog);
77678 if (!err)
77679 err = sock->ops->listen(sock, backlog);
77680
77681 +error:
77682 fput_light(sock->file, fput_needed);
77683 }
77684 return err;
77685 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77686 newsock->type = sock->type;
77687 newsock->ops = sock->ops;
77688
77689 + if (gr_handle_sock_server_other(sock->sk)) {
77690 + err = -EPERM;
77691 + sock_release(newsock);
77692 + goto out_put;
77693 + }
77694 +
77695 + err = gr_search_accept(sock);
77696 + if (err) {
77697 + sock_release(newsock);
77698 + goto out_put;
77699 + }
77700 +
77701 /*
77702 * We don't need try_module_get here, as the listening socket (sock)
77703 * has the protocol module (sock->ops->owner) held.
77704 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77705 fd_install(newfd, newfile);
77706 err = newfd;
77707
77708 + gr_attach_curr_ip(newsock->sk);
77709 +
77710 out_put:
77711 fput_light(sock->file, fput_needed);
77712 out:
77713 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77714 int, addrlen)
77715 {
77716 struct socket *sock;
77717 + struct sockaddr *sck;
77718 struct sockaddr_storage address;
77719 int err, fput_needed;
77720
77721 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77722 if (err < 0)
77723 goto out_put;
77724
77725 + sck = (struct sockaddr *)&address;
77726 +
77727 + if (gr_handle_sock_client(sck)) {
77728 + err = -EACCES;
77729 + goto out_put;
77730 + }
77731 +
77732 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
77733 + if (err)
77734 + goto out_put;
77735 +
77736 err =
77737 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
77738 if (err)
77739 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
77740 * checking falls down on this.
77741 */
77742 if (copy_from_user(ctl_buf,
77743 - (void __user __force *)msg_sys->msg_control,
77744 + (void __force_user *)msg_sys->msg_control,
77745 ctl_len))
77746 goto out_freectl;
77747 msg_sys->msg_control = ctl_buf;
77748 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
77749 * kernel msghdr to use the kernel address space)
77750 */
77751
77752 - uaddr = (__force void __user *)msg_sys->msg_name;
77753 + uaddr = (void __force_user *)msg_sys->msg_name;
77754 uaddr_len = COMPAT_NAMELEN(msg);
77755 if (MSG_CMSG_COMPAT & flags) {
77756 err = verify_compat_iovec(msg_sys, iov,
77757 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77758 }
77759
77760 ifr = compat_alloc_user_space(buf_size);
77761 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
77762 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
77763
77764 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
77765 return -EFAULT;
77766 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77767 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
77768
77769 if (copy_in_user(rxnfc, compat_rxnfc,
77770 - (void *)(&rxnfc->fs.m_ext + 1) -
77771 - (void *)rxnfc) ||
77772 + (void __user *)(&rxnfc->fs.m_ext + 1) -
77773 + (void __user *)rxnfc) ||
77774 copy_in_user(&rxnfc->fs.ring_cookie,
77775 &compat_rxnfc->fs.ring_cookie,
77776 - (void *)(&rxnfc->fs.location + 1) -
77777 - (void *)&rxnfc->fs.ring_cookie) ||
77778 + (void __user *)(&rxnfc->fs.location + 1) -
77779 + (void __user *)&rxnfc->fs.ring_cookie) ||
77780 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
77781 sizeof(rxnfc->rule_cnt)))
77782 return -EFAULT;
77783 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77784
77785 if (convert_out) {
77786 if (copy_in_user(compat_rxnfc, rxnfc,
77787 - (const void *)(&rxnfc->fs.m_ext + 1) -
77788 - (const void *)rxnfc) ||
77789 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
77790 + (const void __user *)rxnfc) ||
77791 copy_in_user(&compat_rxnfc->fs.ring_cookie,
77792 &rxnfc->fs.ring_cookie,
77793 - (const void *)(&rxnfc->fs.location + 1) -
77794 - (const void *)&rxnfc->fs.ring_cookie) ||
77795 + (const void __user *)(&rxnfc->fs.location + 1) -
77796 + (const void __user *)&rxnfc->fs.ring_cookie) ||
77797 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
77798 sizeof(rxnfc->rule_cnt)))
77799 return -EFAULT;
77800 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
77801 old_fs = get_fs();
77802 set_fs(KERNEL_DS);
77803 err = dev_ioctl(net, cmd,
77804 - (struct ifreq __user __force *) &kifr);
77805 + (struct ifreq __force_user *) &kifr);
77806 set_fs(old_fs);
77807
77808 return err;
77809 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
77810
77811 old_fs = get_fs();
77812 set_fs(KERNEL_DS);
77813 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
77814 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
77815 set_fs(old_fs);
77816
77817 if (cmd == SIOCGIFMAP && !err) {
77818 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
77819 ret |= __get_user(rtdev, &(ur4->rt_dev));
77820 if (rtdev) {
77821 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
77822 - r4.rt_dev = (char __user __force *)devname;
77823 + r4.rt_dev = (char __force_user *)devname;
77824 devname[15] = 0;
77825 } else
77826 r4.rt_dev = NULL;
77827 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
77828 int __user *uoptlen;
77829 int err;
77830
77831 - uoptval = (char __user __force *) optval;
77832 - uoptlen = (int __user __force *) optlen;
77833 + uoptval = (char __force_user *) optval;
77834 + uoptlen = (int __force_user *) optlen;
77835
77836 set_fs(KERNEL_DS);
77837 if (level == SOL_SOCKET)
77838 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
77839 char __user *uoptval;
77840 int err;
77841
77842 - uoptval = (char __user __force *) optval;
77843 + uoptval = (char __force_user *) optval;
77844
77845 set_fs(KERNEL_DS);
77846 if (level == SOL_SOCKET)
77847 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
77848 index 8efd96c..b492ab2 100644
77849 --- a/net/sunrpc/sched.c
77850 +++ b/net/sunrpc/sched.c
77851 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
77852 #ifdef RPC_DEBUG
77853 static void rpc_task_set_debuginfo(struct rpc_task *task)
77854 {
77855 - static atomic_t rpc_pid;
77856 + static atomic_unchecked_t rpc_pid;
77857
77858 - task->tk_pid = atomic_inc_return(&rpc_pid);
77859 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
77860 }
77861 #else
77862 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
77863 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
77864 index 4645709..d41d668 100644
77865 --- a/net/sunrpc/svcsock.c
77866 +++ b/net/sunrpc/svcsock.c
77867 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
77868 int buflen, unsigned int base)
77869 {
77870 size_t save_iovlen;
77871 - void __user *save_iovbase;
77872 + void *save_iovbase;
77873 unsigned int i;
77874 int ret;
77875
77876 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
77877 index 09af4fa..77110a9 100644
77878 --- a/net/sunrpc/xprtrdma/svc_rdma.c
77879 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
77880 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
77881 static unsigned int min_max_inline = 4096;
77882 static unsigned int max_max_inline = 65536;
77883
77884 -atomic_t rdma_stat_recv;
77885 -atomic_t rdma_stat_read;
77886 -atomic_t rdma_stat_write;
77887 -atomic_t rdma_stat_sq_starve;
77888 -atomic_t rdma_stat_rq_starve;
77889 -atomic_t rdma_stat_rq_poll;
77890 -atomic_t rdma_stat_rq_prod;
77891 -atomic_t rdma_stat_sq_poll;
77892 -atomic_t rdma_stat_sq_prod;
77893 +atomic_unchecked_t rdma_stat_recv;
77894 +atomic_unchecked_t rdma_stat_read;
77895 +atomic_unchecked_t rdma_stat_write;
77896 +atomic_unchecked_t rdma_stat_sq_starve;
77897 +atomic_unchecked_t rdma_stat_rq_starve;
77898 +atomic_unchecked_t rdma_stat_rq_poll;
77899 +atomic_unchecked_t rdma_stat_rq_prod;
77900 +atomic_unchecked_t rdma_stat_sq_poll;
77901 +atomic_unchecked_t rdma_stat_sq_prod;
77902
77903 /* Temporary NFS request map and context caches */
77904 struct kmem_cache *svc_rdma_map_cachep;
77905 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
77906 len -= *ppos;
77907 if (len > *lenp)
77908 len = *lenp;
77909 - if (len && copy_to_user(buffer, str_buf, len))
77910 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
77911 return -EFAULT;
77912 *lenp = len;
77913 *ppos += len;
77914 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
77915 {
77916 .procname = "rdma_stat_read",
77917 .data = &rdma_stat_read,
77918 - .maxlen = sizeof(atomic_t),
77919 + .maxlen = sizeof(atomic_unchecked_t),
77920 .mode = 0644,
77921 .proc_handler = read_reset_stat,
77922 },
77923 {
77924 .procname = "rdma_stat_recv",
77925 .data = &rdma_stat_recv,
77926 - .maxlen = sizeof(atomic_t),
77927 + .maxlen = sizeof(atomic_unchecked_t),
77928 .mode = 0644,
77929 .proc_handler = read_reset_stat,
77930 },
77931 {
77932 .procname = "rdma_stat_write",
77933 .data = &rdma_stat_write,
77934 - .maxlen = sizeof(atomic_t),
77935 + .maxlen = sizeof(atomic_unchecked_t),
77936 .mode = 0644,
77937 .proc_handler = read_reset_stat,
77938 },
77939 {
77940 .procname = "rdma_stat_sq_starve",
77941 .data = &rdma_stat_sq_starve,
77942 - .maxlen = sizeof(atomic_t),
77943 + .maxlen = sizeof(atomic_unchecked_t),
77944 .mode = 0644,
77945 .proc_handler = read_reset_stat,
77946 },
77947 {
77948 .procname = "rdma_stat_rq_starve",
77949 .data = &rdma_stat_rq_starve,
77950 - .maxlen = sizeof(atomic_t),
77951 + .maxlen = sizeof(atomic_unchecked_t),
77952 .mode = 0644,
77953 .proc_handler = read_reset_stat,
77954 },
77955 {
77956 .procname = "rdma_stat_rq_poll",
77957 .data = &rdma_stat_rq_poll,
77958 - .maxlen = sizeof(atomic_t),
77959 + .maxlen = sizeof(atomic_unchecked_t),
77960 .mode = 0644,
77961 .proc_handler = read_reset_stat,
77962 },
77963 {
77964 .procname = "rdma_stat_rq_prod",
77965 .data = &rdma_stat_rq_prod,
77966 - .maxlen = sizeof(atomic_t),
77967 + .maxlen = sizeof(atomic_unchecked_t),
77968 .mode = 0644,
77969 .proc_handler = read_reset_stat,
77970 },
77971 {
77972 .procname = "rdma_stat_sq_poll",
77973 .data = &rdma_stat_sq_poll,
77974 - .maxlen = sizeof(atomic_t),
77975 + .maxlen = sizeof(atomic_unchecked_t),
77976 .mode = 0644,
77977 .proc_handler = read_reset_stat,
77978 },
77979 {
77980 .procname = "rdma_stat_sq_prod",
77981 .data = &rdma_stat_sq_prod,
77982 - .maxlen = sizeof(atomic_t),
77983 + .maxlen = sizeof(atomic_unchecked_t),
77984 .mode = 0644,
77985 .proc_handler = read_reset_stat,
77986 },
77987 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77988 index df67211..c354b13 100644
77989 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77990 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77991 @@ -499,7 +499,7 @@ next_sge:
77992 svc_rdma_put_context(ctxt, 0);
77993 goto out;
77994 }
77995 - atomic_inc(&rdma_stat_read);
77996 + atomic_inc_unchecked(&rdma_stat_read);
77997
77998 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
77999 chl_map->ch[ch_no].count -= read_wr.num_sge;
78000 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78001 dto_q);
78002 list_del_init(&ctxt->dto_q);
78003 } else {
78004 - atomic_inc(&rdma_stat_rq_starve);
78005 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78006 clear_bit(XPT_DATA, &xprt->xpt_flags);
78007 ctxt = NULL;
78008 }
78009 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78010 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78011 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78012 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78013 - atomic_inc(&rdma_stat_recv);
78014 + atomic_inc_unchecked(&rdma_stat_recv);
78015
78016 /* Build up the XDR from the receive buffers. */
78017 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78018 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78019 index 249a835..fb2794b 100644
78020 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78021 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78022 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78023 write_wr.wr.rdma.remote_addr = to;
78024
78025 /* Post It */
78026 - atomic_inc(&rdma_stat_write);
78027 + atomic_inc_unchecked(&rdma_stat_write);
78028 if (svc_rdma_send(xprt, &write_wr))
78029 goto err;
78030 return 0;
78031 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78032 index 894cb42..cf5bafb 100644
78033 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78034 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78035 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78036 return;
78037
78038 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78039 - atomic_inc(&rdma_stat_rq_poll);
78040 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78041
78042 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78043 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78044 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78045 }
78046
78047 if (ctxt)
78048 - atomic_inc(&rdma_stat_rq_prod);
78049 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78050
78051 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78052 /*
78053 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78054 return;
78055
78056 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78057 - atomic_inc(&rdma_stat_sq_poll);
78058 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78059 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78060 if (wc.status != IB_WC_SUCCESS)
78061 /* Close the transport */
78062 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78063 }
78064
78065 if (ctxt)
78066 - atomic_inc(&rdma_stat_sq_prod);
78067 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78068 }
78069
78070 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78071 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78072 spin_lock_bh(&xprt->sc_lock);
78073 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78074 spin_unlock_bh(&xprt->sc_lock);
78075 - atomic_inc(&rdma_stat_sq_starve);
78076 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78077
78078 /* See if we can opportunistically reap SQ WR to make room */
78079 sq_cq_reap(xprt);
78080 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78081 index e758139..d29ea47 100644
78082 --- a/net/sysctl_net.c
78083 +++ b/net/sysctl_net.c
78084 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78085 struct ctl_table *table)
78086 {
78087 /* Allow network administrator to have same access as root. */
78088 - if (capable(CAP_NET_ADMIN)) {
78089 + if (capable_nolog(CAP_NET_ADMIN)) {
78090 int mode = (table->mode >> 6) & 7;
78091 return (mode << 6) | (mode << 3) | mode;
78092 }
78093 diff --git a/net/tipc/link.c b/net/tipc/link.c
78094 index ac1832a..533ed97 100644
78095 --- a/net/tipc/link.c
78096 +++ b/net/tipc/link.c
78097 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78098 struct tipc_msg fragm_hdr;
78099 struct sk_buff *buf, *buf_chain, *prev;
78100 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78101 - const unchar *sect_crs;
78102 + const unchar __user *sect_crs;
78103 int curr_sect;
78104 u32 fragm_no;
78105
78106 @@ -1249,7 +1249,7 @@ again:
78107
78108 if (!sect_rest) {
78109 sect_rest = msg_sect[++curr_sect].iov_len;
78110 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78111 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78112 }
78113
78114 if (sect_rest < fragm_rest)
78115 @@ -1268,7 +1268,7 @@ error:
78116 }
78117 } else
78118 skb_copy_to_linear_data_offset(buf, fragm_crs,
78119 - sect_crs, sz);
78120 + (const void __force_kernel *)sect_crs, sz);
78121 sect_crs += sz;
78122 sect_rest -= sz;
78123 fragm_crs += sz;
78124 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78125 index 3e4d3e2..27b55dc 100644
78126 --- a/net/tipc/msg.c
78127 +++ b/net/tipc/msg.c
78128 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78129 msg_sect[cnt].iov_len);
78130 else
78131 skb_copy_to_linear_data_offset(*buf, pos,
78132 - msg_sect[cnt].iov_base,
78133 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78134 msg_sect[cnt].iov_len);
78135 pos += msg_sect[cnt].iov_len;
78136 }
78137 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78138 index 8c49566..14510cb 100644
78139 --- a/net/tipc/subscr.c
78140 +++ b/net/tipc/subscr.c
78141 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78142 {
78143 struct iovec msg_sect;
78144
78145 - msg_sect.iov_base = (void *)&sub->evt;
78146 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78147 msg_sect.iov_len = sizeof(struct tipc_event);
78148
78149 sub->evt.event = htohl(event, sub->swap);
78150 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78151 index 85d3bb7..79f4487 100644
78152 --- a/net/unix/af_unix.c
78153 +++ b/net/unix/af_unix.c
78154 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
78155 err = -ECONNREFUSED;
78156 if (!S_ISSOCK(inode->i_mode))
78157 goto put_fail;
78158 +
78159 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78160 + err = -EACCES;
78161 + goto put_fail;
78162 + }
78163 +
78164 u = unix_find_socket_byinode(inode);
78165 if (!u)
78166 goto put_fail;
78167 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
78168 if (u) {
78169 struct dentry *dentry;
78170 dentry = unix_sk(u)->dentry;
78171 +
78172 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78173 + err = -EPERM;
78174 + sock_put(u);
78175 + goto fail;
78176 + }
78177 +
78178 if (dentry)
78179 touch_atime(unix_sk(u)->mnt, dentry);
78180 } else
78181 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78182 err = security_path_mknod(&path, dentry, mode, 0);
78183 if (err)
78184 goto out_mknod_drop_write;
78185 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78186 + err = -EACCES;
78187 + goto out_mknod_drop_write;
78188 + }
78189 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78190 out_mknod_drop_write:
78191 mnt_drop_write(path.mnt);
78192 if (err)
78193 goto out_mknod_dput;
78194 +
78195 + gr_handle_create(dentry, path.mnt);
78196 +
78197 mutex_unlock(&path.dentry->d_inode->i_mutex);
78198 dput(path.dentry);
78199 path.dentry = dentry;
78200 diff --git a/net/wireless/core.h b/net/wireless/core.h
78201 index 43ad9c8..ab5127c 100644
78202 --- a/net/wireless/core.h
78203 +++ b/net/wireless/core.h
78204 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78205 struct mutex mtx;
78206
78207 /* rfkill support */
78208 - struct rfkill_ops rfkill_ops;
78209 + rfkill_ops_no_const rfkill_ops;
78210 struct rfkill *rfkill;
78211 struct work_struct rfkill_sync;
78212
78213 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78214 index 0af7f54..c916d2f 100644
78215 --- a/net/wireless/wext-core.c
78216 +++ b/net/wireless/wext-core.c
78217 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78218 */
78219
78220 /* Support for very large requests */
78221 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78222 - (user_length > descr->max_tokens)) {
78223 + if (user_length > descr->max_tokens) {
78224 /* Allow userspace to GET more than max so
78225 * we can support any size GET requests.
78226 * There is still a limit : -ENOMEM.
78227 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78228 }
78229 }
78230
78231 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78232 - /*
78233 - * If this is a GET, but not NOMAX, it means that the extra
78234 - * data is not bounded by userspace, but by max_tokens. Thus
78235 - * set the length to max_tokens. This matches the extra data
78236 - * allocation.
78237 - * The driver should fill it with the number of tokens it
78238 - * provided, and it may check iwp->length rather than having
78239 - * knowledge of max_tokens. If the driver doesn't change the
78240 - * iwp->length, this ioctl just copies back max_token tokens
78241 - * filled with zeroes. Hopefully the driver isn't claiming
78242 - * them to be valid data.
78243 - */
78244 - iwp->length = descr->max_tokens;
78245 - }
78246 -
78247 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78248
78249 iwp->length += essid_compat;
78250 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78251 index 7661576..80f7627 100644
78252 --- a/net/xfrm/xfrm_policy.c
78253 +++ b/net/xfrm/xfrm_policy.c
78254 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78255 {
78256 policy->walk.dead = 1;
78257
78258 - atomic_inc(&policy->genid);
78259 + atomic_inc_unchecked(&policy->genid);
78260
78261 if (del_timer(&policy->timer))
78262 xfrm_pol_put(policy);
78263 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78264 hlist_add_head(&policy->bydst, chain);
78265 xfrm_pol_hold(policy);
78266 net->xfrm.policy_count[dir]++;
78267 - atomic_inc(&flow_cache_genid);
78268 + atomic_inc_unchecked(&flow_cache_genid);
78269 if (delpol)
78270 __xfrm_policy_unlink(delpol, dir);
78271 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78272 @@ -1530,7 +1530,7 @@ free_dst:
78273 goto out;
78274 }
78275
78276 -static int inline
78277 +static inline int
78278 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78279 {
78280 if (!*target) {
78281 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78282 return 0;
78283 }
78284
78285 -static int inline
78286 +static inline int
78287 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78288 {
78289 #ifdef CONFIG_XFRM_SUB_POLICY
78290 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78291 #endif
78292 }
78293
78294 -static int inline
78295 +static inline int
78296 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78297 {
78298 #ifdef CONFIG_XFRM_SUB_POLICY
78299 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78300
78301 xdst->num_pols = num_pols;
78302 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78303 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78304 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78305
78306 return xdst;
78307 }
78308 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78309 if (xdst->xfrm_genid != dst->xfrm->genid)
78310 return 0;
78311 if (xdst->num_pols > 0 &&
78312 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78313 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78314 return 0;
78315
78316 mtu = dst_mtu(dst->child);
78317 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78318 sizeof(pol->xfrm_vec[i].saddr));
78319 pol->xfrm_vec[i].encap_family = mp->new_family;
78320 /* flush bundles */
78321 - atomic_inc(&pol->genid);
78322 + atomic_inc_unchecked(&pol->genid);
78323 }
78324 }
78325
78326 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78327 index d2b366c..51ff91ebc 100644
78328 --- a/scripts/Makefile.build
78329 +++ b/scripts/Makefile.build
78330 @@ -109,7 +109,7 @@ endif
78331 endif
78332
78333 # Do not include host rules unless needed
78334 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78335 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78336 include scripts/Makefile.host
78337 endif
78338
78339 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78340 index 686cb0d..9d653bf 100644
78341 --- a/scripts/Makefile.clean
78342 +++ b/scripts/Makefile.clean
78343 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78344 __clean-files := $(extra-y) $(always) \
78345 $(targets) $(clean-files) \
78346 $(host-progs) \
78347 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78348 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78349 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78350
78351 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78352
78353 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78354 index 1ac414f..a1c1451 100644
78355 --- a/scripts/Makefile.host
78356 +++ b/scripts/Makefile.host
78357 @@ -31,6 +31,7 @@
78358 # Note: Shared libraries consisting of C++ files are not supported
78359
78360 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78361 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78362
78363 # C code
78364 # Executables compiled from a single .c file
78365 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78366 # Shared libaries (only .c supported)
78367 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78368 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78369 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78370 # Remove .so files from "xxx-objs"
78371 host-cobjs := $(filter-out %.so,$(host-cobjs))
78372
78373 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78374 index cb1f50c..cef2a7c 100644
78375 --- a/scripts/basic/fixdep.c
78376 +++ b/scripts/basic/fixdep.c
78377 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78378 /*
78379 * Lookup a value in the configuration string.
78380 */
78381 -static int is_defined_config(const char *name, int len, unsigned int hash)
78382 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78383 {
78384 struct item *aux;
78385
78386 @@ -211,10 +211,10 @@ static void clear_config(void)
78387 /*
78388 * Record the use of a CONFIG_* word.
78389 */
78390 -static void use_config(const char *m, int slen)
78391 +static void use_config(const char *m, unsigned int slen)
78392 {
78393 unsigned int hash = strhash(m, slen);
78394 - int c, i;
78395 + unsigned int c, i;
78396
78397 if (is_defined_config(m, slen, hash))
78398 return;
78399 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78400
78401 static void parse_config_file(const char *map, size_t len)
78402 {
78403 - const int *end = (const int *) (map + len);
78404 + const unsigned int *end = (const unsigned int *) (map + len);
78405 /* start at +1, so that p can never be < map */
78406 - const int *m = (const int *) map + 1;
78407 + const unsigned int *m = (const unsigned int *) map + 1;
78408 const char *p, *q;
78409
78410 for (; m < end; m++) {
78411 @@ -406,7 +406,7 @@ static void print_deps(void)
78412 static void traps(void)
78413 {
78414 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78415 - int *p = (int *)test;
78416 + unsigned int *p = (unsigned int *)test;
78417
78418 if (*p != INT_CONF) {
78419 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78420 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78421 new file mode 100644
78422 index 0000000..8729101
78423 --- /dev/null
78424 +++ b/scripts/gcc-plugin.sh
78425 @@ -0,0 +1,2 @@
78426 +#!/bin/sh
78427 +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"
78428 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78429 index b89efe6..2c30808 100644
78430 --- a/scripts/mod/file2alias.c
78431 +++ b/scripts/mod/file2alias.c
78432 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78433 unsigned long size, unsigned long id_size,
78434 void *symval)
78435 {
78436 - int i;
78437 + unsigned int i;
78438
78439 if (size % id_size || size < id_size) {
78440 if (cross_build != 0)
78441 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78442 /* USB is special because the bcdDevice can be matched against a numeric range */
78443 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78444 static void do_usb_entry(struct usb_device_id *id,
78445 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78446 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78447 unsigned char range_lo, unsigned char range_hi,
78448 unsigned char max, struct module *mod)
78449 {
78450 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78451 {
78452 unsigned int devlo, devhi;
78453 unsigned char chi, clo, max;
78454 - int ndigits;
78455 + unsigned int ndigits;
78456
78457 id->match_flags = TO_NATIVE(id->match_flags);
78458 id->idVendor = TO_NATIVE(id->idVendor);
78459 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78460 for (i = 0; i < count; i++) {
78461 const char *id = (char *)devs[i].id;
78462 char acpi_id[sizeof(devs[0].id)];
78463 - int j;
78464 + unsigned int j;
78465
78466 buf_printf(&mod->dev_table_buf,
78467 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78468 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78469
78470 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78471 const char *id = (char *)card->devs[j].id;
78472 - int i2, j2;
78473 + unsigned int i2, j2;
78474 int dup = 0;
78475
78476 if (!id[0])
78477 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78478 /* add an individual alias for every device entry */
78479 if (!dup) {
78480 char acpi_id[sizeof(card->devs[0].id)];
78481 - int k;
78482 + unsigned int k;
78483
78484 buf_printf(&mod->dev_table_buf,
78485 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78486 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78487 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78488 char *alias)
78489 {
78490 - int i, j;
78491 + unsigned int i, j;
78492
78493 sprintf(alias, "dmi*");
78494
78495 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78496 index c4e7d15..4241aef 100644
78497 --- a/scripts/mod/modpost.c
78498 +++ b/scripts/mod/modpost.c
78499 @@ -922,6 +922,7 @@ enum mismatch {
78500 ANY_INIT_TO_ANY_EXIT,
78501 ANY_EXIT_TO_ANY_INIT,
78502 EXPORT_TO_INIT_EXIT,
78503 + DATA_TO_TEXT
78504 };
78505
78506 struct sectioncheck {
78507 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
78508 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78509 .mismatch = EXPORT_TO_INIT_EXIT,
78510 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78511 +},
78512 +/* Do not reference code from writable data */
78513 +{
78514 + .fromsec = { DATA_SECTIONS, NULL },
78515 + .tosec = { TEXT_SECTIONS, NULL },
78516 + .mismatch = DATA_TO_TEXT
78517 }
78518 };
78519
78520 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78521 continue;
78522 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78523 continue;
78524 - if (sym->st_value == addr)
78525 - return sym;
78526 /* Find a symbol nearby - addr are maybe negative */
78527 d = sym->st_value - addr;
78528 + if (d == 0)
78529 + return sym;
78530 if (d < 0)
78531 d = addr - sym->st_value;
78532 if (d < distance) {
78533 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
78534 tosym, prl_to, prl_to, tosym);
78535 free(prl_to);
78536 break;
78537 + case DATA_TO_TEXT:
78538 +/*
78539 + fprintf(stderr,
78540 + "The variable %s references\n"
78541 + "the %s %s%s%s\n",
78542 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78543 +*/
78544 + break;
78545 }
78546 fprintf(stderr, "\n");
78547 }
78548 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78549 static void check_sec_ref(struct module *mod, const char *modname,
78550 struct elf_info *elf)
78551 {
78552 - int i;
78553 + unsigned int i;
78554 Elf_Shdr *sechdrs = elf->sechdrs;
78555
78556 /* Walk through all sections */
78557 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78558 va_end(ap);
78559 }
78560
78561 -void buf_write(struct buffer *buf, const char *s, int len)
78562 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78563 {
78564 if (buf->size - buf->pos < len) {
78565 buf->size += len + SZ;
78566 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78567 if (fstat(fileno(file), &st) < 0)
78568 goto close_write;
78569
78570 - if (st.st_size != b->pos)
78571 + if (st.st_size != (off_t)b->pos)
78572 goto close_write;
78573
78574 tmp = NOFAIL(malloc(b->pos));
78575 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78576 index 51207e4..f7d603d 100644
78577 --- a/scripts/mod/modpost.h
78578 +++ b/scripts/mod/modpost.h
78579 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78580
78581 struct buffer {
78582 char *p;
78583 - int pos;
78584 - int size;
78585 + unsigned int pos;
78586 + unsigned int size;
78587 };
78588
78589 void __attribute__((format(printf, 2, 3)))
78590 buf_printf(struct buffer *buf, const char *fmt, ...);
78591
78592 void
78593 -buf_write(struct buffer *buf, const char *s, int len);
78594 +buf_write(struct buffer *buf, const char *s, unsigned int len);
78595
78596 struct module {
78597 struct module *next;
78598 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
78599 index 9dfcd6d..099068e 100644
78600 --- a/scripts/mod/sumversion.c
78601 +++ b/scripts/mod/sumversion.c
78602 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
78603 goto out;
78604 }
78605
78606 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
78607 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
78608 warn("writing sum in %s failed: %s\n",
78609 filename, strerror(errno));
78610 goto out;
78611 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
78612 index 5c11312..72742b5 100644
78613 --- a/scripts/pnmtologo.c
78614 +++ b/scripts/pnmtologo.c
78615 @@ -237,14 +237,14 @@ static void write_header(void)
78616 fprintf(out, " * Linux logo %s\n", logoname);
78617 fputs(" */\n\n", out);
78618 fputs("#include <linux/linux_logo.h>\n\n", out);
78619 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
78620 + fprintf(out, "static unsigned char %s_data[] = {\n",
78621 logoname);
78622 }
78623
78624 static void write_footer(void)
78625 {
78626 fputs("\n};\n\n", out);
78627 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
78628 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
78629 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
78630 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
78631 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
78632 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
78633 fputs("\n};\n\n", out);
78634
78635 /* write logo clut */
78636 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
78637 + fprintf(out, "static unsigned char %s_clut[] = {\n",
78638 logoname);
78639 write_hex_cnt = 0;
78640 for (i = 0; i < logo_clutsize; i++) {
78641 diff --git a/scripts/tags.sh b/scripts/tags.sh
78642 index 833813a..0bc8588 100755
78643 --- a/scripts/tags.sh
78644 +++ b/scripts/tags.sh
78645 @@ -116,7 +116,7 @@ docscope()
78646
78647 dogtags()
78648 {
78649 - all_sources | gtags -f -
78650 + all_sources | gtags -i -f -
78651 }
78652
78653 exuberant()
78654 diff --git a/security/Kconfig b/security/Kconfig
78655 index 51bd5a0..c37f5e6 100644
78656 --- a/security/Kconfig
78657 +++ b/security/Kconfig
78658 @@ -4,6 +4,640 @@
78659
78660 menu "Security options"
78661
78662 +source grsecurity/Kconfig
78663 +
78664 +menu "PaX"
78665 +
78666 + config ARCH_TRACK_EXEC_LIMIT
78667 + bool
78668 +
78669 + config PAX_KERNEXEC_PLUGIN
78670 + bool
78671 +
78672 + config PAX_PER_CPU_PGD
78673 + bool
78674 +
78675 + config TASK_SIZE_MAX_SHIFT
78676 + int
78677 + depends on X86_64
78678 + default 47 if !PAX_PER_CPU_PGD
78679 + default 42 if PAX_PER_CPU_PGD
78680 +
78681 + config PAX_ENABLE_PAE
78682 + bool
78683 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
78684 +
78685 +config PAX
78686 + bool "Enable various PaX features"
78687 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
78688 + help
78689 + This allows you to enable various PaX features. PaX adds
78690 + intrusion prevention mechanisms to the kernel that reduce
78691 + the risks posed by exploitable memory corruption bugs.
78692 +
78693 +menu "PaX Control"
78694 + depends on PAX
78695 +
78696 +config PAX_SOFTMODE
78697 + bool 'Support soft mode'
78698 + help
78699 + Enabling this option will allow you to run PaX in soft mode, that
78700 + is, PaX features will not be enforced by default, only on executables
78701 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
78702 + support as they are the only way to mark executables for soft mode use.
78703 +
78704 + Soft mode can be activated by using the "pax_softmode=1" kernel command
78705 + line option on boot. Furthermore you can control various PaX features
78706 + at runtime via the entries in /proc/sys/kernel/pax.
78707 +
78708 +config PAX_EI_PAX
78709 + bool 'Use legacy ELF header marking'
78710 + help
78711 + Enabling this option will allow you to control PaX features on
78712 + a per executable basis via the 'chpax' utility available at
78713 + http://pax.grsecurity.net/. The control flags will be read from
78714 + an otherwise reserved part of the ELF header. This marking has
78715 + numerous drawbacks (no support for soft-mode, toolchain does not
78716 + know about the non-standard use of the ELF header) therefore it
78717 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
78718 + support.
78719 +
78720 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78721 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
78722 + option otherwise they will not get any protection.
78723 +
78724 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
78725 + support as well, they will override the legacy EI_PAX marks.
78726 +
78727 +config PAX_PT_PAX_FLAGS
78728 + bool 'Use ELF program header marking'
78729 + help
78730 + Enabling this option will allow you to control PaX features on
78731 + a per executable basis via the 'paxctl' utility available at
78732 + http://pax.grsecurity.net/. The control flags will be read from
78733 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
78734 + has the benefits of supporting both soft mode and being fully
78735 + integrated into the toolchain (the binutils patch is available
78736 + from http://pax.grsecurity.net).
78737 +
78738 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78739 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78740 + support otherwise they will not get any protection.
78741 +
78742 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78743 + must make sure that the marks are the same if a binary has both marks.
78744 +
78745 + Note that if you enable the legacy EI_PAX marking support as well,
78746 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
78747 +
78748 +config PAX_XATTR_PAX_FLAGS
78749 + bool 'Use filesystem extended attributes marking'
78750 + select CIFS_XATTR if CIFS
78751 + select EXT2_FS_XATTR if EXT2_FS
78752 + select EXT3_FS_XATTR if EXT3_FS
78753 + select EXT4_FS_XATTR if EXT4_FS
78754 + select JFFS2_FS_XATTR if JFFS2_FS
78755 + select REISERFS_FS_XATTR if REISERFS_FS
78756 + select SQUASHFS_XATTR if SQUASHFS
78757 + select TMPFS_XATTR if TMPFS
78758 + select UBIFS_FS_XATTR if UBIFS_FS
78759 + help
78760 + Enabling this option will allow you to control PaX features on
78761 + a per executable basis via the 'setfattr' utility. The control
78762 + flags will be read from the user.pax.flags extended attribute of
78763 + the file. This marking has the benefit of supporting binary-only
78764 + applications that self-check themselves (e.g., skype) and would
78765 + not tolerate chpax/paxctl changes. The main drawback is that
78766 + extended attributes are not supported by some filesystems (e.g.,
78767 + isofs, udf, vfat) so copying files through such filesystems will
78768 + lose the extended attributes and these PaX markings.
78769 +
78770 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78771 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78772 + support otherwise they will not get any protection.
78773 +
78774 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78775 + must make sure that the marks are the same if a binary has both marks.
78776 +
78777 + Note that if you enable the legacy EI_PAX marking support as well,
78778 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78779 +
78780 +choice
78781 + prompt 'MAC system integration'
78782 + default PAX_HAVE_ACL_FLAGS
78783 + help
78784 + Mandatory Access Control systems have the option of controlling
78785 + PaX flags on a per executable basis, choose the method supported
78786 + by your particular system.
78787 +
78788 + - "none": if your MAC system does not interact with PaX,
78789 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78790 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78791 +
78792 + NOTE: this option is for developers/integrators only.
78793 +
78794 + config PAX_NO_ACL_FLAGS
78795 + bool 'none'
78796 +
78797 + config PAX_HAVE_ACL_FLAGS
78798 + bool 'direct'
78799 +
78800 + config PAX_HOOK_ACL_FLAGS
78801 + bool 'hook'
78802 +endchoice
78803 +
78804 +endmenu
78805 +
78806 +menu "Non-executable pages"
78807 + depends on PAX
78808 +
78809 +config PAX_NOEXEC
78810 + bool "Enforce non-executable pages"
78811 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78812 + help
78813 + By design some architectures do not allow for protecting memory
78814 + pages against execution or even if they do, Linux does not make
78815 + use of this feature. In practice this means that if a page is
78816 + readable (such as the stack or heap) it is also executable.
78817 +
78818 + There is a well known exploit technique that makes use of this
78819 + fact and a common programming mistake where an attacker can
78820 + introduce code of his choice somewhere in the attacked program's
78821 + memory (typically the stack or the heap) and then execute it.
78822 +
78823 + If the attacked program was running with different (typically
78824 + higher) privileges than that of the attacker, then he can elevate
78825 + his own privilege level (e.g. get a root shell, write to files for
78826 + which he does not have write access to, etc).
78827 +
78828 + Enabling this option will let you choose from various features
78829 + that prevent the injection and execution of 'foreign' code in
78830 + a program.
78831 +
78832 + This will also break programs that rely on the old behaviour and
78833 + expect that dynamically allocated memory via the malloc() family
78834 + of functions is executable (which it is not). Notable examples
78835 + are the XFree86 4.x server, the java runtime and wine.
78836 +
78837 +config PAX_PAGEEXEC
78838 + bool "Paging based non-executable pages"
78839 + 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)
78840 + select S390_SWITCH_AMODE if S390
78841 + select S390_EXEC_PROTECT if S390
78842 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78843 + help
78844 + This implementation is based on the paging feature of the CPU.
78845 + On i386 without hardware non-executable bit support there is a
78846 + variable but usually low performance impact, however on Intel's
78847 + P4 core based CPUs it is very high so you should not enable this
78848 + for kernels meant to be used on such CPUs.
78849 +
78850 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78851 + with hardware non-executable bit support there is no performance
78852 + impact, on ppc the impact is negligible.
78853 +
78854 + Note that several architectures require various emulations due to
78855 + badly designed userland ABIs, this will cause a performance impact
78856 + but will disappear as soon as userland is fixed. For example, ppc
78857 + userland MUST have been built with secure-plt by a recent toolchain.
78858 +
78859 +config PAX_SEGMEXEC
78860 + bool "Segmentation based non-executable pages"
78861 + depends on PAX_NOEXEC && X86_32
78862 + help
78863 + This implementation is based on the segmentation feature of the
78864 + CPU and has a very small performance impact, however applications
78865 + will be limited to a 1.5 GB address space instead of the normal
78866 + 3 GB.
78867 +
78868 +config PAX_EMUTRAMP
78869 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78870 + default y if PARISC
78871 + help
78872 + There are some programs and libraries that for one reason or
78873 + another attempt to execute special small code snippets from
78874 + non-executable memory pages. Most notable examples are the
78875 + signal handler return code generated by the kernel itself and
78876 + the GCC trampolines.
78877 +
78878 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78879 + such programs will no longer work under your kernel.
78880 +
78881 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78882 + utilities to enable trampoline emulation for the affected programs
78883 + yet still have the protection provided by the non-executable pages.
78884 +
78885 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78886 + your system will not even boot.
78887 +
78888 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78889 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78890 + for the affected files.
78891 +
78892 + NOTE: enabling this feature *may* open up a loophole in the
78893 + protection provided by non-executable pages that an attacker
78894 + could abuse. Therefore the best solution is to not have any
78895 + files on your system that would require this option. This can
78896 + be achieved by not using libc5 (which relies on the kernel
78897 + signal handler return code) and not using or rewriting programs
78898 + that make use of the nested function implementation of GCC.
78899 + Skilled users can just fix GCC itself so that it implements
78900 + nested function calls in a way that does not interfere with PaX.
78901 +
78902 +config PAX_EMUSIGRT
78903 + bool "Automatically emulate sigreturn trampolines"
78904 + depends on PAX_EMUTRAMP && PARISC
78905 + default y
78906 + help
78907 + Enabling this option will have the kernel automatically detect
78908 + and emulate signal return trampolines executing on the stack
78909 + that would otherwise lead to task termination.
78910 +
78911 + This solution is intended as a temporary one for users with
78912 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78913 + Modula-3 runtime, etc) or executables linked to such, basically
78914 + everything that does not specify its own SA_RESTORER function in
78915 + normal executable memory like glibc 2.1+ does.
78916 +
78917 + On parisc you MUST enable this option, otherwise your system will
78918 + not even boot.
78919 +
78920 + NOTE: this feature cannot be disabled on a per executable basis
78921 + and since it *does* open up a loophole in the protection provided
78922 + by non-executable pages, the best solution is to not have any
78923 + files on your system that would require this option.
78924 +
78925 +config PAX_MPROTECT
78926 + bool "Restrict mprotect()"
78927 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78928 + help
78929 + Enabling this option will prevent programs from
78930 + - changing the executable status of memory pages that were
78931 + not originally created as executable,
78932 + - making read-only executable pages writable again,
78933 + - creating executable pages from anonymous memory,
78934 + - making read-only-after-relocations (RELRO) data pages writable again.
78935 +
78936 + You should say Y here to complete the protection provided by
78937 + the enforcement of non-executable pages.
78938 +
78939 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78940 + this feature on a per file basis.
78941 +
78942 +config PAX_MPROTECT_COMPAT
78943 + bool "Use legacy/compat protection demoting (read help)"
78944 + depends on PAX_MPROTECT
78945 + default n
78946 + help
78947 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78948 + by sending the proper error code to the application. For some broken
78949 + userland, this can cause problems with Python or other applications. The
78950 + current implementation however allows for applications like clamav to
78951 + detect if JIT compilation/execution is allowed and to fall back gracefully
78952 + to an interpreter-based mode if it does not. While we encourage everyone
78953 + to use the current implementation as-is and push upstream to fix broken
78954 + userland (note that the RWX logging option can assist with this), in some
78955 + environments this may not be possible. Having to disable MPROTECT
78956 + completely on certain binaries reduces the security benefit of PaX,
78957 + so this option is provided for those environments to revert to the old
78958 + behavior.
78959 +
78960 +config PAX_ELFRELOCS
78961 + bool "Allow ELF text relocations (read help)"
78962 + depends on PAX_MPROTECT
78963 + default n
78964 + help
78965 + Non-executable pages and mprotect() restrictions are effective
78966 + in preventing the introduction of new executable code into an
78967 + attacked task's address space. There remain only two venues
78968 + for this kind of attack: if the attacker can execute already
78969 + existing code in the attacked task then he can either have it
78970 + create and mmap() a file containing his code or have it mmap()
78971 + an already existing ELF library that does not have position
78972 + independent code in it and use mprotect() on it to make it
78973 + writable and copy his code there. While protecting against
78974 + the former approach is beyond PaX, the latter can be prevented
78975 + by having only PIC ELF libraries on one's system (which do not
78976 + need to relocate their code). If you are sure this is your case,
78977 + as is the case with all modern Linux distributions, then leave
78978 + this option disabled. You should say 'n' here.
78979 +
78980 +config PAX_ETEXECRELOCS
78981 + bool "Allow ELF ET_EXEC text relocations"
78982 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78983 + select PAX_ELFRELOCS
78984 + default y
78985 + help
78986 + On some architectures there are incorrectly created applications
78987 + that require text relocations and would not work without enabling
78988 + this option. If you are an alpha, ia64 or parisc user, you should
78989 + enable this option and disable it once you have made sure that
78990 + none of your applications need it.
78991 +
78992 +config PAX_EMUPLT
78993 + bool "Automatically emulate ELF PLT"
78994 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
78995 + default y
78996 + help
78997 + Enabling this option will have the kernel automatically detect
78998 + and emulate the Procedure Linkage Table entries in ELF files.
78999 + On some architectures such entries are in writable memory, and
79000 + become non-executable leading to task termination. Therefore
79001 + it is mandatory that you enable this option on alpha, parisc,
79002 + sparc and sparc64, otherwise your system would not even boot.
79003 +
79004 + NOTE: this feature *does* open up a loophole in the protection
79005 + provided by the non-executable pages, therefore the proper
79006 + solution is to modify the toolchain to produce a PLT that does
79007 + not need to be writable.
79008 +
79009 +config PAX_DLRESOLVE
79010 + bool 'Emulate old glibc resolver stub'
79011 + depends on PAX_EMUPLT && SPARC
79012 + default n
79013 + help
79014 + This option is needed if userland has an old glibc (before 2.4)
79015 + that puts a 'save' instruction into the runtime generated resolver
79016 + stub that needs special emulation.
79017 +
79018 +config PAX_KERNEXEC
79019 + bool "Enforce non-executable kernel pages"
79020 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79021 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79022 + select PAX_KERNEXEC_PLUGIN if X86_64
79023 + help
79024 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79025 + that is, enabling this option will make it harder to inject
79026 + and execute 'foreign' code in kernel memory itself.
79027 +
79028 + Note that on x86_64 kernels there is a known regression when
79029 + this feature and KVM/VMX are both enabled in the host kernel.
79030 +
79031 +choice
79032 + prompt "Return Address Instrumentation Method"
79033 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79034 + depends on PAX_KERNEXEC_PLUGIN
79035 + help
79036 + Select the method used to instrument function pointer dereferences.
79037 + Note that binary modules cannot be instrumented by this approach.
79038 +
79039 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79040 + bool "bts"
79041 + help
79042 + This method is compatible with binary only modules but has
79043 + a higher runtime overhead.
79044 +
79045 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79046 + bool "or"
79047 + depends on !PARAVIRT
79048 + help
79049 + This method is incompatible with binary only modules but has
79050 + a lower runtime overhead.
79051 +endchoice
79052 +
79053 +config PAX_KERNEXEC_PLUGIN_METHOD
79054 + string
79055 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79056 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79057 + default ""
79058 +
79059 +config PAX_KERNEXEC_MODULE_TEXT
79060 + int "Minimum amount of memory reserved for module code"
79061 + default "4"
79062 + depends on PAX_KERNEXEC && X86_32 && MODULES
79063 + help
79064 + Due to implementation details the kernel must reserve a fixed
79065 + amount of memory for module code at compile time that cannot be
79066 + changed at runtime. Here you can specify the minimum amount
79067 + in MB that will be reserved. Due to the same implementation
79068 + details this size will always be rounded up to the next 2/4 MB
79069 + boundary (depends on PAE) so the actually available memory for
79070 + module code will usually be more than this minimum.
79071 +
79072 + The default 4 MB should be enough for most users but if you have
79073 + an excessive number of modules (e.g., most distribution configs
79074 + compile many drivers as modules) or use huge modules such as
79075 + nvidia's kernel driver, you will need to adjust this amount.
79076 + A good rule of thumb is to look at your currently loaded kernel
79077 + modules and add up their sizes.
79078 +
79079 +endmenu
79080 +
79081 +menu "Address Space Layout Randomization"
79082 + depends on PAX
79083 +
79084 +config PAX_ASLR
79085 + bool "Address Space Layout Randomization"
79086 + help
79087 + Many if not most exploit techniques rely on the knowledge of
79088 + certain addresses in the attacked program. The following options
79089 + will allow the kernel to apply a certain amount of randomization
79090 + to specific parts of the program thereby forcing an attacker to
79091 + guess them in most cases. Any failed guess will most likely crash
79092 + the attacked program which allows the kernel to detect such attempts
79093 + and react on them. PaX itself provides no reaction mechanisms,
79094 + instead it is strongly encouraged that you make use of Nergal's
79095 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79096 + (http://www.grsecurity.net/) built-in crash detection features or
79097 + develop one yourself.
79098 +
79099 + By saying Y here you can choose to randomize the following areas:
79100 + - top of the task's kernel stack
79101 + - top of the task's userland stack
79102 + - base address for mmap() requests that do not specify one
79103 + (this includes all libraries)
79104 + - base address of the main executable
79105 +
79106 + It is strongly recommended to say Y here as address space layout
79107 + randomization has negligible impact on performance yet it provides
79108 + a very effective protection.
79109 +
79110 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79111 + this feature on a per file basis.
79112 +
79113 +config PAX_RANDKSTACK
79114 + bool "Randomize kernel stack base"
79115 + depends on X86_TSC && X86
79116 + help
79117 + By saying Y here the kernel will randomize every task's kernel
79118 + stack on every system call. This will not only force an attacker
79119 + to guess it but also prevent him from making use of possible
79120 + leaked information about it.
79121 +
79122 + Since the kernel stack is a rather scarce resource, randomization
79123 + may cause unexpected stack overflows, therefore you should very
79124 + carefully test your system. Note that once enabled in the kernel
79125 + configuration, this feature cannot be disabled on a per file basis.
79126 +
79127 +config PAX_RANDUSTACK
79128 + bool "Randomize user stack base"
79129 + depends on PAX_ASLR
79130 + help
79131 + By saying Y here the kernel will randomize every task's userland
79132 + stack. The randomization is done in two steps where the second
79133 + one may apply a big amount of shift to the top of the stack and
79134 + cause problems for programs that want to use lots of memory (more
79135 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79136 + For this reason the second step can be controlled by 'chpax' or
79137 + 'paxctl' on a per file basis.
79138 +
79139 +config PAX_RANDMMAP
79140 + bool "Randomize mmap() base"
79141 + depends on PAX_ASLR
79142 + help
79143 + By saying Y here the kernel will use a randomized base address for
79144 + mmap() requests that do not specify one themselves. As a result
79145 + all dynamically loaded libraries will appear at random addresses
79146 + and therefore be harder to exploit by a technique where an attacker
79147 + attempts to execute library code for his purposes (e.g. spawn a
79148 + shell from an exploited program that is running at an elevated
79149 + privilege level).
79150 +
79151 + Furthermore, if a program is relinked as a dynamic ELF file, its
79152 + base address will be randomized as well, completing the full
79153 + randomization of the address space layout. Attacking such programs
79154 + becomes a guess game. You can find an example of doing this at
79155 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79156 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79157 +
79158 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79159 + feature on a per file basis.
79160 +
79161 +endmenu
79162 +
79163 +menu "Miscellaneous hardening features"
79164 +
79165 +config PAX_MEMORY_SANITIZE
79166 + bool "Sanitize all freed memory"
79167 + depends on !HIBERNATION
79168 + help
79169 + By saying Y here the kernel will erase memory pages as soon as they
79170 + are freed. This in turn reduces the lifetime of data stored in the
79171 + pages, making it less likely that sensitive information such as
79172 + passwords, cryptographic secrets, etc stay in memory for too long.
79173 +
79174 + This is especially useful for programs whose runtime is short, long
79175 + lived processes and the kernel itself benefit from this as long as
79176 + they operate on whole memory pages and ensure timely freeing of pages
79177 + that may hold sensitive information.
79178 +
79179 + The tradeoff is performance impact, on a single CPU system kernel
79180 + compilation sees a 3% slowdown, other systems and workloads may vary
79181 + and you are advised to test this feature on your expected workload
79182 + before deploying it.
79183 +
79184 + Note that this feature does not protect data stored in live pages,
79185 + e.g., process memory swapped to disk may stay there for a long time.
79186 +
79187 +config PAX_MEMORY_STACKLEAK
79188 + bool "Sanitize kernel stack"
79189 + depends on X86
79190 + help
79191 + By saying Y here the kernel will erase the kernel stack before it
79192 + returns from a system call. This in turn reduces the information
79193 + that a kernel stack leak bug can reveal.
79194 +
79195 + Note that such a bug can still leak information that was put on
79196 + the stack by the current system call (the one eventually triggering
79197 + the bug) but traces of earlier system calls on the kernel stack
79198 + cannot leak anymore.
79199 +
79200 + The tradeoff is performance impact: on a single CPU system kernel
79201 + compilation sees a 1% slowdown, other systems and workloads may vary
79202 + and you are advised to test this feature on your expected workload
79203 + before deploying it.
79204 +
79205 + Note: full support for this feature requires gcc with plugin support
79206 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79207 + versions means that functions with large enough stack frames may
79208 + leave uninitialized memory behind that may be exposed to a later
79209 + syscall leaking the stack.
79210 +
79211 +config PAX_MEMORY_UDEREF
79212 + bool "Prevent invalid userland pointer dereference"
79213 + depends on X86 && !UML_X86 && !XEN
79214 + select PAX_PER_CPU_PGD if X86_64
79215 + help
79216 + By saying Y here the kernel will be prevented from dereferencing
79217 + userland pointers in contexts where the kernel expects only kernel
79218 + pointers. This is both a useful runtime debugging feature and a
79219 + security measure that prevents exploiting a class of kernel bugs.
79220 +
79221 + The tradeoff is that some virtualization solutions may experience
79222 + a huge slowdown and therefore you should not enable this feature
79223 + for kernels meant to run in such environments. Whether a given VM
79224 + solution is affected or not is best determined by simply trying it
79225 + out, the performance impact will be obvious right on boot as this
79226 + mechanism engages from very early on. A good rule of thumb is that
79227 + VMs running on CPUs without hardware virtualization support (i.e.,
79228 + the majority of IA-32 CPUs) will likely experience the slowdown.
79229 +
79230 +config PAX_REFCOUNT
79231 + bool "Prevent various kernel object reference counter overflows"
79232 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79233 + help
79234 + By saying Y here the kernel will detect and prevent overflowing
79235 + various (but not all) kinds of object reference counters. Such
79236 + overflows can normally occur due to bugs only and are often, if
79237 + not always, exploitable.
79238 +
79239 + The tradeoff is that data structures protected by an overflowed
79240 + refcount will never be freed and therefore will leak memory. Note
79241 + that this leak also happens even without this protection but in
79242 + that case the overflow can eventually trigger the freeing of the
79243 + data structure while it is still being used elsewhere, resulting
79244 + in the exploitable situation that this feature prevents.
79245 +
79246 + Since this has a negligible performance impact, you should enable
79247 + this feature.
79248 +
79249 +config PAX_USERCOPY
79250 + bool "Harden heap object copies between kernel and userland"
79251 + depends on X86 || PPC || SPARC || ARM
79252 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79253 + help
79254 + By saying Y here the kernel will enforce the size of heap objects
79255 + when they are copied in either direction between the kernel and
79256 + userland, even if only a part of the heap object is copied.
79257 +
79258 + Specifically, this checking prevents information leaking from the
79259 + kernel heap during kernel to userland copies (if the kernel heap
79260 + object is otherwise fully initialized) and prevents kernel heap
79261 + overflows during userland to kernel copies.
79262 +
79263 + Note that the current implementation provides the strictest bounds
79264 + checks for the SLUB allocator.
79265 +
79266 + Enabling this option also enables per-slab cache protection against
79267 + data in a given cache being copied into/out of via userland
79268 + accessors. Though the whitelist of regions will be reduced over
79269 + time, it notably protects important data structures like task structs.
79270 +
79271 + If frame pointers are enabled on x86, this option will also restrict
79272 + copies into and out of the kernel stack to local variables within a
79273 + single frame.
79274 +
79275 + Since this has a negligible performance impact, you should enable
79276 + this feature.
79277 +
79278 +config PAX_SIZE_OVERFLOW
79279 + bool "Prevent various integer overflows in function size parameters"
79280 + depends on X86
79281 + help
79282 + By saying Y here the kernel recomputes expressions of function
79283 + arguments marked by a size_overflow attribute with double integer
79284 + precision (DImode/TImode for 32/64 bit integer types).
79285 +
79286 + The recomputed argument is checked against INT_MAX and an event
79287 + is logged on overflow and the triggering process is killed.
79288 +
79289 + Homepage:
79290 + http://www.grsecurity.net/~ephox/overflow_plugin/
79291 +
79292 +endmenu
79293 +
79294 +endmenu
79295 +
79296 config KEYS
79297 bool "Enable access key retention support"
79298 help
79299 @@ -169,7 +803,7 @@ config INTEL_TXT
79300 config LSM_MMAP_MIN_ADDR
79301 int "Low address space for LSM to protect from user allocation"
79302 depends on SECURITY && SECURITY_SELINUX
79303 - default 32768 if ARM
79304 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79305 default 65536
79306 help
79307 This is the portion of low virtual memory which should be protected
79308 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79309 index 97ce8fa..23dad96 100644
79310 --- a/security/apparmor/lsm.c
79311 +++ b/security/apparmor/lsm.c
79312 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79313 return error;
79314 }
79315
79316 -static struct security_operations apparmor_ops = {
79317 +static struct security_operations apparmor_ops __read_only = {
79318 .name = "apparmor",
79319
79320 .ptrace_access_check = apparmor_ptrace_access_check,
79321 diff --git a/security/commoncap.c b/security/commoncap.c
79322 index b8d2bb9..980069e 100644
79323 --- a/security/commoncap.c
79324 +++ b/security/commoncap.c
79325 @@ -29,6 +29,7 @@
79326 #include <linux/securebits.h>
79327 #include <linux/user_namespace.h>
79328 #include <linux/personality.h>
79329 +#include <net/sock.h>
79330
79331 /*
79332 * If a non-root user executes a setuid-root binary in
79333 @@ -575,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79334 {
79335 const struct cred *cred = current_cred();
79336
79337 + if (gr_acl_enable_at_secure())
79338 + return 1;
79339 +
79340 if (cred->uid != 0) {
79341 if (bprm->cap_effective)
79342 return 1;
79343 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79344 index 3ccf7ac..d73ad64 100644
79345 --- a/security/integrity/ima/ima.h
79346 +++ b/security/integrity/ima/ima.h
79347 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79348 extern spinlock_t ima_queue_lock;
79349
79350 struct ima_h_table {
79351 - atomic_long_t len; /* number of stored measurements in the list */
79352 - atomic_long_t violations;
79353 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79354 + atomic_long_unchecked_t violations;
79355 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79356 };
79357 extern struct ima_h_table ima_htable;
79358 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79359 index 88a2788..581ab92 100644
79360 --- a/security/integrity/ima/ima_api.c
79361 +++ b/security/integrity/ima/ima_api.c
79362 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79363 int result;
79364
79365 /* can overflow, only indicator */
79366 - atomic_long_inc(&ima_htable.violations);
79367 + atomic_long_inc_unchecked(&ima_htable.violations);
79368
79369 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79370 if (!entry) {
79371 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79372 index e1aa2b4..52027bf 100644
79373 --- a/security/integrity/ima/ima_fs.c
79374 +++ b/security/integrity/ima/ima_fs.c
79375 @@ -28,12 +28,12 @@
79376 static int valid_policy = 1;
79377 #define TMPBUFLEN 12
79378 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79379 - loff_t *ppos, atomic_long_t *val)
79380 + loff_t *ppos, atomic_long_unchecked_t *val)
79381 {
79382 char tmpbuf[TMPBUFLEN];
79383 ssize_t len;
79384
79385 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79386 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79387 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79388 }
79389
79390 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79391 index 55a6271..ad829c3 100644
79392 --- a/security/integrity/ima/ima_queue.c
79393 +++ b/security/integrity/ima/ima_queue.c
79394 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79395 INIT_LIST_HEAD(&qe->later);
79396 list_add_tail_rcu(&qe->later, &ima_measurements);
79397
79398 - atomic_long_inc(&ima_htable.len);
79399 + atomic_long_inc_unchecked(&ima_htable.len);
79400 key = ima_hash_key(entry->digest);
79401 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79402 return 0;
79403 diff --git a/security/keys/compat.c b/security/keys/compat.c
79404 index 4c48e13..7abdac9 100644
79405 --- a/security/keys/compat.c
79406 +++ b/security/keys/compat.c
79407 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79408 if (ret == 0)
79409 goto no_payload_free;
79410
79411 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79412 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79413
79414 if (iov != iovstack)
79415 kfree(iov);
79416 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79417 index 0b3f5d7..892c8a6 100644
79418 --- a/security/keys/keyctl.c
79419 +++ b/security/keys/keyctl.c
79420 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79421 /*
79422 * Copy the iovec data from userspace
79423 */
79424 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79425 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79426 unsigned ioc)
79427 {
79428 for (; ioc > 0; ioc--) {
79429 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79430 * If successful, 0 will be returned.
79431 */
79432 long keyctl_instantiate_key_common(key_serial_t id,
79433 - const struct iovec *payload_iov,
79434 + const struct iovec __user *payload_iov,
79435 unsigned ioc,
79436 size_t plen,
79437 key_serial_t ringid)
79438 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79439 [0].iov_len = plen
79440 };
79441
79442 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79443 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79444 }
79445
79446 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79447 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79448 if (ret == 0)
79449 goto no_payload_free;
79450
79451 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79452 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79453
79454 if (iov != iovstack)
79455 kfree(iov);
79456 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79457 index d605f75..2bc6be9 100644
79458 --- a/security/keys/keyring.c
79459 +++ b/security/keys/keyring.c
79460 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79461 ret = -EFAULT;
79462
79463 for (loop = 0; loop < klist->nkeys; loop++) {
79464 + key_serial_t serial;
79465 key = klist->keys[loop];
79466 + serial = key->serial;
79467
79468 tmp = sizeof(key_serial_t);
79469 if (tmp > buflen)
79470 tmp = buflen;
79471
79472 - if (copy_to_user(buffer,
79473 - &key->serial,
79474 - tmp) != 0)
79475 + if (copy_to_user(buffer, &serial, tmp))
79476 goto error;
79477
79478 buflen -= tmp;
79479 diff --git a/security/min_addr.c b/security/min_addr.c
79480 index f728728..6457a0c 100644
79481 --- a/security/min_addr.c
79482 +++ b/security/min_addr.c
79483 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79484 */
79485 static void update_mmap_min_addr(void)
79486 {
79487 +#ifndef SPARC
79488 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79489 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79490 mmap_min_addr = dac_mmap_min_addr;
79491 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79492 #else
79493 mmap_min_addr = dac_mmap_min_addr;
79494 #endif
79495 +#endif
79496 }
79497
79498 /*
79499 diff --git a/security/security.c b/security/security.c
79500 index d754249..8bf426e 100644
79501 --- a/security/security.c
79502 +++ b/security/security.c
79503 @@ -26,8 +26,8 @@
79504 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79505 CONFIG_DEFAULT_SECURITY;
79506
79507 -static struct security_operations *security_ops;
79508 -static struct security_operations default_security_ops = {
79509 +static struct security_operations *security_ops __read_only;
79510 +static struct security_operations default_security_ops __read_only = {
79511 .name = "default",
79512 };
79513
79514 @@ -68,7 +68,9 @@ int __init security_init(void)
79515
79516 void reset_security_ops(void)
79517 {
79518 + pax_open_kernel();
79519 security_ops = &default_security_ops;
79520 + pax_close_kernel();
79521 }
79522
79523 /* Save user chosen LSM */
79524 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79525 index 6a3683e..f52f4c0 100644
79526 --- a/security/selinux/hooks.c
79527 +++ b/security/selinux/hooks.c
79528 @@ -94,8 +94,6 @@
79529
79530 #define NUM_SEL_MNT_OPTS 5
79531
79532 -extern struct security_operations *security_ops;
79533 -
79534 /* SECMARK reference count */
79535 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79536
79537 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
79538
79539 #endif
79540
79541 -static struct security_operations selinux_ops = {
79542 +static struct security_operations selinux_ops __read_only = {
79543 .name = "selinux",
79544
79545 .ptrace_access_check = selinux_ptrace_access_check,
79546 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
79547 index b43813c..74be837 100644
79548 --- a/security/selinux/include/xfrm.h
79549 +++ b/security/selinux/include/xfrm.h
79550 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
79551
79552 static inline void selinux_xfrm_notify_policyload(void)
79553 {
79554 - atomic_inc(&flow_cache_genid);
79555 + atomic_inc_unchecked(&flow_cache_genid);
79556 }
79557 #else
79558 static inline int selinux_xfrm_enabled(void)
79559 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
79560 index e8af5b0b..78527ef 100644
79561 --- a/security/smack/smack_lsm.c
79562 +++ b/security/smack/smack_lsm.c
79563 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
79564 return 0;
79565 }
79566
79567 -struct security_operations smack_ops = {
79568 +struct security_operations smack_ops __read_only = {
79569 .name = "smack",
79570
79571 .ptrace_access_check = smack_ptrace_access_check,
79572 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
79573 index 620d37c..e2ad89b 100644
79574 --- a/security/tomoyo/tomoyo.c
79575 +++ b/security/tomoyo/tomoyo.c
79576 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
79577 * tomoyo_security_ops is a "struct security_operations" which is used for
79578 * registering TOMOYO.
79579 */
79580 -static struct security_operations tomoyo_security_ops = {
79581 +static struct security_operations tomoyo_security_ops __read_only = {
79582 .name = "tomoyo",
79583 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79584 .cred_prepare = tomoyo_cred_prepare,
79585 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
79586 index 762af68..7103453 100644
79587 --- a/sound/aoa/codecs/onyx.c
79588 +++ b/sound/aoa/codecs/onyx.c
79589 @@ -54,7 +54,7 @@ struct onyx {
79590 spdif_locked:1,
79591 analog_locked:1,
79592 original_mute:2;
79593 - int open_count;
79594 + local_t open_count;
79595 struct codec_info *codec_info;
79596
79597 /* mutex serializes concurrent access to the device
79598 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
79599 struct onyx *onyx = cii->codec_data;
79600
79601 mutex_lock(&onyx->mutex);
79602 - onyx->open_count++;
79603 + local_inc(&onyx->open_count);
79604 mutex_unlock(&onyx->mutex);
79605
79606 return 0;
79607 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
79608 struct onyx *onyx = cii->codec_data;
79609
79610 mutex_lock(&onyx->mutex);
79611 - onyx->open_count--;
79612 - if (!onyx->open_count)
79613 + if (local_dec_and_test(&onyx->open_count))
79614 onyx->spdif_locked = onyx->analog_locked = 0;
79615 mutex_unlock(&onyx->mutex);
79616
79617 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
79618 index ffd2025..df062c9 100644
79619 --- a/sound/aoa/codecs/onyx.h
79620 +++ b/sound/aoa/codecs/onyx.h
79621 @@ -11,6 +11,7 @@
79622 #include <linux/i2c.h>
79623 #include <asm/pmac_low_i2c.h>
79624 #include <asm/prom.h>
79625 +#include <asm/local.h>
79626
79627 /* PCM3052 register definitions */
79628
79629 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
79630 index 08fde00..0bf641a 100644
79631 --- a/sound/core/oss/pcm_oss.c
79632 +++ b/sound/core/oss/pcm_oss.c
79633 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
79634 if (in_kernel) {
79635 mm_segment_t fs;
79636 fs = snd_enter_user();
79637 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79638 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79639 snd_leave_user(fs);
79640 } else {
79641 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79642 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79643 }
79644 if (ret != -EPIPE && ret != -ESTRPIPE)
79645 break;
79646 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
79647 if (in_kernel) {
79648 mm_segment_t fs;
79649 fs = snd_enter_user();
79650 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79651 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79652 snd_leave_user(fs);
79653 } else {
79654 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79655 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79656 }
79657 if (ret == -EPIPE) {
79658 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
79659 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
79660 struct snd_pcm_plugin_channel *channels;
79661 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
79662 if (!in_kernel) {
79663 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
79664 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
79665 return -EFAULT;
79666 buf = runtime->oss.buffer;
79667 }
79668 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
79669 }
79670 } else {
79671 tmp = snd_pcm_oss_write2(substream,
79672 - (const char __force *)buf,
79673 + (const char __force_kernel *)buf,
79674 runtime->oss.period_bytes, 0);
79675 if (tmp <= 0)
79676 goto err;
79677 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
79678 struct snd_pcm_runtime *runtime = substream->runtime;
79679 snd_pcm_sframes_t frames, frames1;
79680 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
79681 - char __user *final_dst = (char __force __user *)buf;
79682 + char __user *final_dst = (char __force_user *)buf;
79683 if (runtime->oss.plugin_first) {
79684 struct snd_pcm_plugin_channel *channels;
79685 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
79686 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
79687 xfer += tmp;
79688 runtime->oss.buffer_used -= tmp;
79689 } else {
79690 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
79691 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
79692 runtime->oss.period_bytes, 0);
79693 if (tmp <= 0)
79694 goto err;
79695 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
79696 size1);
79697 size1 /= runtime->channels; /* frames */
79698 fs = snd_enter_user();
79699 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
79700 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
79701 snd_leave_user(fs);
79702 }
79703 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
79704 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
79705 index 91cdf94..4085161 100644
79706 --- a/sound/core/pcm_compat.c
79707 +++ b/sound/core/pcm_compat.c
79708 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
79709 int err;
79710
79711 fs = snd_enter_user();
79712 - err = snd_pcm_delay(substream, &delay);
79713 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
79714 snd_leave_user(fs);
79715 if (err < 0)
79716 return err;
79717 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
79718 index 25ed9fe..24c46e9 100644
79719 --- a/sound/core/pcm_native.c
79720 +++ b/sound/core/pcm_native.c
79721 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
79722 switch (substream->stream) {
79723 case SNDRV_PCM_STREAM_PLAYBACK:
79724 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
79725 - (void __user *)arg);
79726 + (void __force_user *)arg);
79727 break;
79728 case SNDRV_PCM_STREAM_CAPTURE:
79729 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79730 - (void __user *)arg);
79731 + (void __force_user *)arg);
79732 break;
79733 default:
79734 result = -EINVAL;
79735 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79736 index 5cf8d65..912a79c 100644
79737 --- a/sound/core/seq/seq_device.c
79738 +++ b/sound/core/seq/seq_device.c
79739 @@ -64,7 +64,7 @@ struct ops_list {
79740 int argsize; /* argument size */
79741
79742 /* operators */
79743 - struct snd_seq_dev_ops ops;
79744 + struct snd_seq_dev_ops *ops;
79745
79746 /* registred devices */
79747 struct list_head dev_list; /* list of devices */
79748 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79749
79750 mutex_lock(&ops->reg_mutex);
79751 /* copy driver operators */
79752 - ops->ops = *entry;
79753 + ops->ops = entry;
79754 ops->driver |= DRIVER_LOADED;
79755 ops->argsize = argsize;
79756
79757 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79758 dev->name, ops->id, ops->argsize, dev->argsize);
79759 return -EINVAL;
79760 }
79761 - if (ops->ops.init_device(dev) >= 0) {
79762 + if (ops->ops->init_device(dev) >= 0) {
79763 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79764 ops->num_init_devices++;
79765 } else {
79766 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79767 dev->name, ops->id, ops->argsize, dev->argsize);
79768 return -EINVAL;
79769 }
79770 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79771 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79772 dev->status = SNDRV_SEQ_DEVICE_FREE;
79773 dev->driver_data = NULL;
79774 ops->num_init_devices--;
79775 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79776 index 621e60e..f4543f5 100644
79777 --- a/sound/drivers/mts64.c
79778 +++ b/sound/drivers/mts64.c
79779 @@ -29,6 +29,7 @@
79780 #include <sound/initval.h>
79781 #include <sound/rawmidi.h>
79782 #include <sound/control.h>
79783 +#include <asm/local.h>
79784
79785 #define CARD_NAME "Miditerminal 4140"
79786 #define DRIVER_NAME "MTS64"
79787 @@ -67,7 +68,7 @@ struct mts64 {
79788 struct pardevice *pardev;
79789 int pardev_claimed;
79790
79791 - int open_count;
79792 + local_t open_count;
79793 int current_midi_output_port;
79794 int current_midi_input_port;
79795 u8 mode[MTS64_NUM_INPUT_PORTS];
79796 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79797 {
79798 struct mts64 *mts = substream->rmidi->private_data;
79799
79800 - if (mts->open_count == 0) {
79801 + if (local_read(&mts->open_count) == 0) {
79802 /* We don't need a spinlock here, because this is just called
79803 if the device has not been opened before.
79804 So there aren't any IRQs from the device */
79805 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79806
79807 msleep(50);
79808 }
79809 - ++(mts->open_count);
79810 + local_inc(&mts->open_count);
79811
79812 return 0;
79813 }
79814 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79815 struct mts64 *mts = substream->rmidi->private_data;
79816 unsigned long flags;
79817
79818 - --(mts->open_count);
79819 - if (mts->open_count == 0) {
79820 + if (local_dec_return(&mts->open_count) == 0) {
79821 /* We need the spinlock_irqsave here because we can still
79822 have IRQs at this point */
79823 spin_lock_irqsave(&mts->lock, flags);
79824 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79825
79826 msleep(500);
79827
79828 - } else if (mts->open_count < 0)
79829 - mts->open_count = 0;
79830 + } else if (local_read(&mts->open_count) < 0)
79831 + local_set(&mts->open_count, 0);
79832
79833 return 0;
79834 }
79835 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79836 index b953fb4..1999c01 100644
79837 --- a/sound/drivers/opl4/opl4_lib.c
79838 +++ b/sound/drivers/opl4/opl4_lib.c
79839 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79840 MODULE_DESCRIPTION("OPL4 driver");
79841 MODULE_LICENSE("GPL");
79842
79843 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79844 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79845 {
79846 int timeout = 10;
79847 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79848 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79849 index 3e32bd3..46fc152 100644
79850 --- a/sound/drivers/portman2x4.c
79851 +++ b/sound/drivers/portman2x4.c
79852 @@ -48,6 +48,7 @@
79853 #include <sound/initval.h>
79854 #include <sound/rawmidi.h>
79855 #include <sound/control.h>
79856 +#include <asm/local.h>
79857
79858 #define CARD_NAME "Portman 2x4"
79859 #define DRIVER_NAME "portman"
79860 @@ -85,7 +86,7 @@ struct portman {
79861 struct pardevice *pardev;
79862 int pardev_claimed;
79863
79864 - int open_count;
79865 + local_t open_count;
79866 int mode[PORTMAN_NUM_INPUT_PORTS];
79867 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79868 };
79869 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79870 index 87657dd..a8268d4 100644
79871 --- a/sound/firewire/amdtp.c
79872 +++ b/sound/firewire/amdtp.c
79873 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79874 ptr = s->pcm_buffer_pointer + data_blocks;
79875 if (ptr >= pcm->runtime->buffer_size)
79876 ptr -= pcm->runtime->buffer_size;
79877 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79878 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79879
79880 s->pcm_period_pointer += data_blocks;
79881 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79882 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79883 */
79884 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79885 {
79886 - ACCESS_ONCE(s->source_node_id_field) =
79887 + ACCESS_ONCE_RW(s->source_node_id_field) =
79888 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79889 }
79890 EXPORT_SYMBOL(amdtp_out_stream_update);
79891 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79892 index 537a9cb..8e8c8e9 100644
79893 --- a/sound/firewire/amdtp.h
79894 +++ b/sound/firewire/amdtp.h
79895 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79896 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79897 struct snd_pcm_substream *pcm)
79898 {
79899 - ACCESS_ONCE(s->pcm) = pcm;
79900 + ACCESS_ONCE_RW(s->pcm) = pcm;
79901 }
79902
79903 /**
79904 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79905 index cd094ec..eca1277 100644
79906 --- a/sound/firewire/isight.c
79907 +++ b/sound/firewire/isight.c
79908 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79909 ptr += count;
79910 if (ptr >= runtime->buffer_size)
79911 ptr -= runtime->buffer_size;
79912 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79913 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79914
79915 isight->period_counter += count;
79916 if (isight->period_counter >= runtime->period_size) {
79917 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79918 if (err < 0)
79919 return err;
79920
79921 - ACCESS_ONCE(isight->pcm_active) = true;
79922 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79923
79924 return 0;
79925 }
79926 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79927 {
79928 struct isight *isight = substream->private_data;
79929
79930 - ACCESS_ONCE(isight->pcm_active) = false;
79931 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79932
79933 mutex_lock(&isight->mutex);
79934 isight_stop_streaming(isight);
79935 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79936
79937 switch (cmd) {
79938 case SNDRV_PCM_TRIGGER_START:
79939 - ACCESS_ONCE(isight->pcm_running) = true;
79940 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79941 break;
79942 case SNDRV_PCM_TRIGGER_STOP:
79943 - ACCESS_ONCE(isight->pcm_running) = false;
79944 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79945 break;
79946 default:
79947 return -EINVAL;
79948 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79949 index 7bd5e33..1fcab12 100644
79950 --- a/sound/isa/cmi8330.c
79951 +++ b/sound/isa/cmi8330.c
79952 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79953
79954 struct snd_pcm *pcm;
79955 struct snd_cmi8330_stream {
79956 - struct snd_pcm_ops ops;
79957 + snd_pcm_ops_no_const ops;
79958 snd_pcm_open_callback_t open;
79959 void *private_data; /* sb or wss */
79960 } streams[2];
79961 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79962 index 733b014..56ce96f 100644
79963 --- a/sound/oss/sb_audio.c
79964 +++ b/sound/oss/sb_audio.c
79965 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79966 buf16 = (signed short *)(localbuf + localoffs);
79967 while (c)
79968 {
79969 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79970 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79971 if (copy_from_user(lbuf8,
79972 userbuf+useroffs + p,
79973 locallen))
79974 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79975 index 09d4648..cf234c7 100644
79976 --- a/sound/oss/swarm_cs4297a.c
79977 +++ b/sound/oss/swarm_cs4297a.c
79978 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79979 {
79980 struct cs4297a_state *s;
79981 u32 pwr, id;
79982 - mm_segment_t fs;
79983 int rval;
79984 #ifndef CONFIG_BCM_CS4297A_CSWARM
79985 u64 cfg;
79986 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
79987 if (!rval) {
79988 char *sb1250_duart_present;
79989
79990 +#if 0
79991 + mm_segment_t fs;
79992 fs = get_fs();
79993 set_fs(KERNEL_DS);
79994 -#if 0
79995 val = SOUND_MASK_LINE;
79996 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
79997 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
79998 val = initvol[i].vol;
79999 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80000 }
80001 + set_fs(fs);
80002 // cs4297a_write_ac97(s, 0x18, 0x0808);
80003 #else
80004 // cs4297a_write_ac97(s, 0x5e, 0x180);
80005 cs4297a_write_ac97(s, 0x02, 0x0808);
80006 cs4297a_write_ac97(s, 0x18, 0x0808);
80007 #endif
80008 - set_fs(fs);
80009
80010 list_add(&s->list, &cs4297a_devs);
80011
80012 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80013 index f0f1943..8e1f96c 100644
80014 --- a/sound/pci/hda/hda_codec.h
80015 +++ b/sound/pci/hda/hda_codec.h
80016 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80017 /* notify power-up/down from codec to controller */
80018 void (*pm_notify)(struct hda_bus *bus);
80019 #endif
80020 -};
80021 +} __no_const;
80022
80023 /* template to pass to the bus constructor */
80024 struct hda_bus_template {
80025 @@ -713,6 +713,7 @@ struct hda_codec_ops {
80026 #endif
80027 void (*reboot_notify)(struct hda_codec *codec);
80028 };
80029 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80030
80031 /* record for amp information cache */
80032 struct hda_cache_head {
80033 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
80034 struct snd_pcm_substream *substream);
80035 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80036 struct snd_pcm_substream *substream);
80037 -};
80038 +} __no_const;
80039
80040 /* PCM information for each substream */
80041 struct hda_pcm_stream {
80042 @@ -801,7 +802,7 @@ struct hda_codec {
80043 const char *modelname; /* model name for preset */
80044
80045 /* set by patch */
80046 - struct hda_codec_ops patch_ops;
80047 + hda_codec_ops_no_const patch_ops;
80048
80049 /* PCM to create, set by patch_ops.build_pcms callback */
80050 unsigned int num_pcms;
80051 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80052 index 0da778a..bc38b84 100644
80053 --- a/sound/pci/ice1712/ice1712.h
80054 +++ b/sound/pci/ice1712/ice1712.h
80055 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80056 unsigned int mask_flags; /* total mask bits */
80057 struct snd_akm4xxx_ops {
80058 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80059 - } ops;
80060 + } __no_const ops;
80061 };
80062
80063 struct snd_ice1712_spdif {
80064 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80065 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80066 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80067 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80068 - } ops;
80069 + } __no_const ops;
80070 };
80071
80072
80073 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80074 index 12a9a2b..2b6138f 100644
80075 --- a/sound/pci/ymfpci/ymfpci_main.c
80076 +++ b/sound/pci/ymfpci/ymfpci_main.c
80077 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80078 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80079 break;
80080 }
80081 - if (atomic_read(&chip->interrupt_sleep_count)) {
80082 - atomic_set(&chip->interrupt_sleep_count, 0);
80083 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80084 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80085 wake_up(&chip->interrupt_sleep);
80086 }
80087 __end:
80088 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80089 continue;
80090 init_waitqueue_entry(&wait, current);
80091 add_wait_queue(&chip->interrupt_sleep, &wait);
80092 - atomic_inc(&chip->interrupt_sleep_count);
80093 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80094 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80095 remove_wait_queue(&chip->interrupt_sleep, &wait);
80096 }
80097 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80098 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80099 spin_unlock(&chip->reg_lock);
80100
80101 - if (atomic_read(&chip->interrupt_sleep_count)) {
80102 - atomic_set(&chip->interrupt_sleep_count, 0);
80103 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80104 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80105 wake_up(&chip->interrupt_sleep);
80106 }
80107 }
80108 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80109 spin_lock_init(&chip->reg_lock);
80110 spin_lock_init(&chip->voice_lock);
80111 init_waitqueue_head(&chip->interrupt_sleep);
80112 - atomic_set(&chip->interrupt_sleep_count, 0);
80113 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80114 chip->card = card;
80115 chip->pci = pci;
80116 chip->irq = -1;
80117 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80118 index cdc860a..db34a93 100644
80119 --- a/sound/soc/soc-pcm.c
80120 +++ b/sound/soc/soc-pcm.c
80121 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
80122 struct snd_soc_platform *platform = rtd->platform;
80123 struct snd_soc_dai *codec_dai = rtd->codec_dai;
80124 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80125 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
80126 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
80127 struct snd_pcm *pcm;
80128 char new_name[64];
80129 int ret = 0, playback = 0, capture = 0;
80130 diff --git a/sound/usb/card.h b/sound/usb/card.h
80131 index da5fa1a..113cd02 100644
80132 --- a/sound/usb/card.h
80133 +++ b/sound/usb/card.h
80134 @@ -45,6 +45,7 @@ struct snd_urb_ops {
80135 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80136 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80137 };
80138 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80139
80140 struct snd_usb_substream {
80141 struct snd_usb_stream *stream;
80142 @@ -94,7 +95,7 @@ struct snd_usb_substream {
80143 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80144 spinlock_t lock;
80145
80146 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80147 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80148 int last_frame_number; /* stored frame number */
80149 int last_delay; /* stored delay */
80150 };
80151 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80152 new file mode 100644
80153 index 0000000..ca64170
80154 --- /dev/null
80155 +++ b/tools/gcc/Makefile
80156 @@ -0,0 +1,26 @@
80157 +#CC := gcc
80158 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80159 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80160 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80161 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80162 +
80163 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80164 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
80165 +
80166 +hostlibs-y := constify_plugin.so
80167 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80168 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80169 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80170 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80171 +hostlibs-y += colorize_plugin.so
80172 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80173 +
80174 +always := $(hostlibs-y)
80175 +
80176 +constify_plugin-objs := constify_plugin.o
80177 +stackleak_plugin-objs := stackleak_plugin.o
80178 +kallocstat_plugin-objs := kallocstat_plugin.o
80179 +kernexec_plugin-objs := kernexec_plugin.o
80180 +checker_plugin-objs := checker_plugin.o
80181 +colorize_plugin-objs := colorize_plugin.o
80182 +size_overflow_plugin-objs := size_overflow_plugin.o
80183 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80184 new file mode 100644
80185 index 0000000..d41b5af
80186 --- /dev/null
80187 +++ b/tools/gcc/checker_plugin.c
80188 @@ -0,0 +1,171 @@
80189 +/*
80190 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80191 + * Licensed under the GPL v2
80192 + *
80193 + * Note: the choice of the license means that the compilation process is
80194 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80195 + * but for the kernel it doesn't matter since it doesn't link against
80196 + * any of the gcc libraries
80197 + *
80198 + * gcc plugin to implement various sparse (source code checker) features
80199 + *
80200 + * TODO:
80201 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80202 + *
80203 + * BUGS:
80204 + * - none known
80205 + */
80206 +#include "gcc-plugin.h"
80207 +#include "config.h"
80208 +#include "system.h"
80209 +#include "coretypes.h"
80210 +#include "tree.h"
80211 +#include "tree-pass.h"
80212 +#include "flags.h"
80213 +#include "intl.h"
80214 +#include "toplev.h"
80215 +#include "plugin.h"
80216 +//#include "expr.h" where are you...
80217 +#include "diagnostic.h"
80218 +#include "plugin-version.h"
80219 +#include "tm.h"
80220 +#include "function.h"
80221 +#include "basic-block.h"
80222 +#include "gimple.h"
80223 +#include "rtl.h"
80224 +#include "emit-rtl.h"
80225 +#include "tree-flow.h"
80226 +#include "target.h"
80227 +
80228 +extern void c_register_addr_space (const char *str, addr_space_t as);
80229 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80230 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80231 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80232 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80233 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80234 +
80235 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80236 +extern rtx emit_move_insn(rtx x, rtx y);
80237 +
80238 +int plugin_is_GPL_compatible;
80239 +
80240 +static struct plugin_info checker_plugin_info = {
80241 + .version = "201111150100",
80242 +};
80243 +
80244 +#define ADDR_SPACE_KERNEL 0
80245 +#define ADDR_SPACE_FORCE_KERNEL 1
80246 +#define ADDR_SPACE_USER 2
80247 +#define ADDR_SPACE_FORCE_USER 3
80248 +#define ADDR_SPACE_IOMEM 0
80249 +#define ADDR_SPACE_FORCE_IOMEM 0
80250 +#define ADDR_SPACE_PERCPU 0
80251 +#define ADDR_SPACE_FORCE_PERCPU 0
80252 +#define ADDR_SPACE_RCU 0
80253 +#define ADDR_SPACE_FORCE_RCU 0
80254 +
80255 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80256 +{
80257 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80258 +}
80259 +
80260 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80261 +{
80262 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80263 +}
80264 +
80265 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80266 +{
80267 + return default_addr_space_valid_pointer_mode(mode, as);
80268 +}
80269 +
80270 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80271 +{
80272 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80273 +}
80274 +
80275 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80276 +{
80277 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80278 +}
80279 +
80280 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80281 +{
80282 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80283 + return true;
80284 +
80285 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80286 + return true;
80287 +
80288 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80289 + return true;
80290 +
80291 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80292 + return true;
80293 +
80294 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80295 + return true;
80296 +
80297 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80298 + return true;
80299 +
80300 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80301 + return true;
80302 +
80303 + return subset == superset;
80304 +}
80305 +
80306 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80307 +{
80308 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80309 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80310 +
80311 + return op;
80312 +}
80313 +
80314 +static void register_checker_address_spaces(void *event_data, void *data)
80315 +{
80316 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80317 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80318 + c_register_addr_space("__user", ADDR_SPACE_USER);
80319 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80320 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80321 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80322 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80323 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80324 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80325 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80326 +
80327 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80328 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80329 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80330 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80331 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80332 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80333 + targetm.addr_space.convert = checker_addr_space_convert;
80334 +}
80335 +
80336 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80337 +{
80338 + const char * const plugin_name = plugin_info->base_name;
80339 + const int argc = plugin_info->argc;
80340 + const struct plugin_argument * const argv = plugin_info->argv;
80341 + int i;
80342 +
80343 + if (!plugin_default_version_check(version, &gcc_version)) {
80344 + error(G_("incompatible gcc/plugin versions"));
80345 + return 1;
80346 + }
80347 +
80348 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80349 +
80350 + for (i = 0; i < argc; ++i)
80351 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80352 +
80353 + if (TARGET_64BIT == 0)
80354 + return 0;
80355 +
80356 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80357 +
80358 + return 0;
80359 +}
80360 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80361 new file mode 100644
80362 index 0000000..ee950d0
80363 --- /dev/null
80364 +++ b/tools/gcc/colorize_plugin.c
80365 @@ -0,0 +1,147 @@
80366 +/*
80367 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80368 + * Licensed under the GPL v2
80369 + *
80370 + * Note: the choice of the license means that the compilation process is
80371 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80372 + * but for the kernel it doesn't matter since it doesn't link against
80373 + * any of the gcc libraries
80374 + *
80375 + * gcc plugin to colorize diagnostic output
80376 + *
80377 + */
80378 +
80379 +#include "gcc-plugin.h"
80380 +#include "config.h"
80381 +#include "system.h"
80382 +#include "coretypes.h"
80383 +#include "tree.h"
80384 +#include "tree-pass.h"
80385 +#include "flags.h"
80386 +#include "intl.h"
80387 +#include "toplev.h"
80388 +#include "plugin.h"
80389 +#include "diagnostic.h"
80390 +#include "plugin-version.h"
80391 +#include "tm.h"
80392 +
80393 +int plugin_is_GPL_compatible;
80394 +
80395 +static struct plugin_info colorize_plugin_info = {
80396 + .version = "201203092200",
80397 +};
80398 +
80399 +#define GREEN "\033[32m\033[2m"
80400 +#define LIGHTGREEN "\033[32m\033[1m"
80401 +#define YELLOW "\033[33m\033[2m"
80402 +#define LIGHTYELLOW "\033[33m\033[1m"
80403 +#define RED "\033[31m\033[2m"
80404 +#define LIGHTRED "\033[31m\033[1m"
80405 +#define BLUE "\033[34m\033[2m"
80406 +#define LIGHTBLUE "\033[34m\033[1m"
80407 +#define BRIGHT "\033[m\033[1m"
80408 +#define NORMAL "\033[m"
80409 +
80410 +static diagnostic_starter_fn old_starter;
80411 +static diagnostic_finalizer_fn old_finalizer;
80412 +
80413 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80414 +{
80415 + const char *color;
80416 + char *newprefix;
80417 +
80418 + switch (diagnostic->kind) {
80419 + case DK_NOTE:
80420 + color = LIGHTBLUE;
80421 + break;
80422 +
80423 + case DK_PEDWARN:
80424 + case DK_WARNING:
80425 + color = LIGHTYELLOW;
80426 + break;
80427 +
80428 + case DK_ERROR:
80429 + case DK_FATAL:
80430 + case DK_ICE:
80431 + case DK_PERMERROR:
80432 + case DK_SORRY:
80433 + color = LIGHTRED;
80434 + break;
80435 +
80436 + default:
80437 + color = NORMAL;
80438 + }
80439 +
80440 + old_starter(context, diagnostic);
80441 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80442 + return;
80443 + pp_destroy_prefix(context->printer);
80444 + pp_set_prefix(context->printer, newprefix);
80445 +}
80446 +
80447 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80448 +{
80449 + old_finalizer(context, diagnostic);
80450 +}
80451 +
80452 +static void colorize_arm(void)
80453 +{
80454 + old_starter = diagnostic_starter(global_dc);
80455 + old_finalizer = diagnostic_finalizer(global_dc);
80456 +
80457 + diagnostic_starter(global_dc) = start_colorize;
80458 + diagnostic_finalizer(global_dc) = finalize_colorize;
80459 +}
80460 +
80461 +static unsigned int execute_colorize_rearm(void)
80462 +{
80463 + if (diagnostic_starter(global_dc) == start_colorize)
80464 + return 0;
80465 +
80466 + colorize_arm();
80467 + return 0;
80468 +}
80469 +
80470 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80471 + .pass = {
80472 + .type = SIMPLE_IPA_PASS,
80473 + .name = "colorize_rearm",
80474 + .gate = NULL,
80475 + .execute = execute_colorize_rearm,
80476 + .sub = NULL,
80477 + .next = NULL,
80478 + .static_pass_number = 0,
80479 + .tv_id = TV_NONE,
80480 + .properties_required = 0,
80481 + .properties_provided = 0,
80482 + .properties_destroyed = 0,
80483 + .todo_flags_start = 0,
80484 + .todo_flags_finish = 0
80485 + }
80486 +};
80487 +
80488 +static void colorize_start_unit(void *gcc_data, void *user_data)
80489 +{
80490 + colorize_arm();
80491 +}
80492 +
80493 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80494 +{
80495 + const char * const plugin_name = plugin_info->base_name;
80496 + struct register_pass_info colorize_rearm_pass_info = {
80497 + .pass = &pass_ipa_colorize_rearm.pass,
80498 + .reference_pass_name = "*free_lang_data",
80499 + .ref_pass_instance_number = 0,
80500 + .pos_op = PASS_POS_INSERT_AFTER
80501 + };
80502 +
80503 + if (!plugin_default_version_check(version, &gcc_version)) {
80504 + error(G_("incompatible gcc/plugin versions"));
80505 + return 1;
80506 + }
80507 +
80508 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80509 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80510 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80511 + return 0;
80512 +}
80513 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80514 new file mode 100644
80515 index 0000000..704a564
80516 --- /dev/null
80517 +++ b/tools/gcc/constify_plugin.c
80518 @@ -0,0 +1,303 @@
80519 +/*
80520 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80521 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80522 + * Licensed under the GPL v2, or (at your option) v3
80523 + *
80524 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80525 + *
80526 + * Homepage:
80527 + * http://www.grsecurity.net/~ephox/const_plugin/
80528 + *
80529 + * Usage:
80530 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
80531 + * $ gcc -fplugin=constify_plugin.so test.c -O2
80532 + */
80533 +
80534 +#include "gcc-plugin.h"
80535 +#include "config.h"
80536 +#include "system.h"
80537 +#include "coretypes.h"
80538 +#include "tree.h"
80539 +#include "tree-pass.h"
80540 +#include "flags.h"
80541 +#include "intl.h"
80542 +#include "toplev.h"
80543 +#include "plugin.h"
80544 +#include "diagnostic.h"
80545 +#include "plugin-version.h"
80546 +#include "tm.h"
80547 +#include "function.h"
80548 +#include "basic-block.h"
80549 +#include "gimple.h"
80550 +#include "rtl.h"
80551 +#include "emit-rtl.h"
80552 +#include "tree-flow.h"
80553 +
80554 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
80555 +
80556 +int plugin_is_GPL_compatible;
80557 +
80558 +static struct plugin_info const_plugin_info = {
80559 + .version = "201111150100",
80560 + .help = "no-constify\tturn off constification\n",
80561 +};
80562 +
80563 +static void constify_type(tree type);
80564 +static bool walk_struct(tree node);
80565 +
80566 +static tree deconstify_type(tree old_type)
80567 +{
80568 + tree new_type, field;
80569 +
80570 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
80571 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
80572 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
80573 + DECL_FIELD_CONTEXT(field) = new_type;
80574 + TYPE_READONLY(new_type) = 0;
80575 + C_TYPE_FIELDS_READONLY(new_type) = 0;
80576 + return new_type;
80577 +}
80578 +
80579 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80580 +{
80581 + tree type;
80582 +
80583 + *no_add_attrs = true;
80584 + if (TREE_CODE(*node) == FUNCTION_DECL) {
80585 + error("%qE attribute does not apply to functions", name);
80586 + return NULL_TREE;
80587 + }
80588 +
80589 + if (TREE_CODE(*node) == VAR_DECL) {
80590 + error("%qE attribute does not apply to variables", name);
80591 + return NULL_TREE;
80592 + }
80593 +
80594 + if (TYPE_P(*node)) {
80595 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
80596 + *no_add_attrs = false;
80597 + else
80598 + error("%qE attribute applies to struct and union types only", name);
80599 + return NULL_TREE;
80600 + }
80601 +
80602 + type = TREE_TYPE(*node);
80603 +
80604 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
80605 + error("%qE attribute applies to struct and union types only", name);
80606 + return NULL_TREE;
80607 + }
80608 +
80609 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
80610 + error("%qE attribute is already applied to the type", name);
80611 + return NULL_TREE;
80612 + }
80613 +
80614 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
80615 + error("%qE attribute used on type that is not constified", name);
80616 + return NULL_TREE;
80617 + }
80618 +
80619 + if (TREE_CODE(*node) == TYPE_DECL) {
80620 + TREE_TYPE(*node) = deconstify_type(type);
80621 + TREE_READONLY(*node) = 0;
80622 + return NULL_TREE;
80623 + }
80624 +
80625 + return NULL_TREE;
80626 +}
80627 +
80628 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80629 +{
80630 + *no_add_attrs = true;
80631 + if (!TYPE_P(*node)) {
80632 + error("%qE attribute applies to types only", name);
80633 + return NULL_TREE;
80634 + }
80635 +
80636 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80637 + error("%qE attribute applies to struct and union types only", name);
80638 + return NULL_TREE;
80639 + }
80640 +
80641 + *no_add_attrs = false;
80642 + constify_type(*node);
80643 + return NULL_TREE;
80644 +}
80645 +
80646 +static struct attribute_spec no_const_attr = {
80647 + .name = "no_const",
80648 + .min_length = 0,
80649 + .max_length = 0,
80650 + .decl_required = false,
80651 + .type_required = false,
80652 + .function_type_required = false,
80653 + .handler = handle_no_const_attribute,
80654 +#if BUILDING_GCC_VERSION >= 4007
80655 + .affects_type_identity = true
80656 +#endif
80657 +};
80658 +
80659 +static struct attribute_spec do_const_attr = {
80660 + .name = "do_const",
80661 + .min_length = 0,
80662 + .max_length = 0,
80663 + .decl_required = false,
80664 + .type_required = false,
80665 + .function_type_required = false,
80666 + .handler = handle_do_const_attribute,
80667 +#if BUILDING_GCC_VERSION >= 4007
80668 + .affects_type_identity = true
80669 +#endif
80670 +};
80671 +
80672 +static void register_attributes(void *event_data, void *data)
80673 +{
80674 + register_attribute(&no_const_attr);
80675 + register_attribute(&do_const_attr);
80676 +}
80677 +
80678 +static void constify_type(tree type)
80679 +{
80680 + TYPE_READONLY(type) = 1;
80681 + C_TYPE_FIELDS_READONLY(type) = 1;
80682 +}
80683 +
80684 +static bool is_fptr(tree field)
80685 +{
80686 + tree ptr = TREE_TYPE(field);
80687 +
80688 + if (TREE_CODE(ptr) != POINTER_TYPE)
80689 + return false;
80690 +
80691 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80692 +}
80693 +
80694 +static bool walk_struct(tree node)
80695 +{
80696 + tree field;
80697 +
80698 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
80699 + return false;
80700 +
80701 + if (TYPE_FIELDS(node) == NULL_TREE)
80702 + return false;
80703 +
80704 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80705 + tree type = TREE_TYPE(field);
80706 + enum tree_code code = TREE_CODE(type);
80707 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80708 + if (!(walk_struct(type)))
80709 + return false;
80710 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80711 + return false;
80712 + }
80713 + return true;
80714 +}
80715 +
80716 +static void finish_type(void *event_data, void *data)
80717 +{
80718 + tree type = (tree)event_data;
80719 +
80720 + if (type == NULL_TREE)
80721 + return;
80722 +
80723 + if (TYPE_READONLY(type))
80724 + return;
80725 +
80726 + if (walk_struct(type))
80727 + constify_type(type);
80728 +}
80729 +
80730 +static unsigned int check_local_variables(void);
80731 +
80732 +struct gimple_opt_pass pass_local_variable = {
80733 + {
80734 + .type = GIMPLE_PASS,
80735 + .name = "check_local_variables",
80736 + .gate = NULL,
80737 + .execute = check_local_variables,
80738 + .sub = NULL,
80739 + .next = NULL,
80740 + .static_pass_number = 0,
80741 + .tv_id = TV_NONE,
80742 + .properties_required = 0,
80743 + .properties_provided = 0,
80744 + .properties_destroyed = 0,
80745 + .todo_flags_start = 0,
80746 + .todo_flags_finish = 0
80747 + }
80748 +};
80749 +
80750 +static unsigned int check_local_variables(void)
80751 +{
80752 + tree var;
80753 + referenced_var_iterator rvi;
80754 +
80755 +#if BUILDING_GCC_VERSION == 4005
80756 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80757 +#else
80758 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80759 +#endif
80760 + tree type = TREE_TYPE(var);
80761 +
80762 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80763 + continue;
80764 +
80765 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80766 + continue;
80767 +
80768 + if (!TYPE_READONLY(type))
80769 + continue;
80770 +
80771 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80772 +// continue;
80773 +
80774 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80775 +// continue;
80776 +
80777 + if (walk_struct(type)) {
80778 + error("constified variable %qE cannot be local", var);
80779 + return 1;
80780 + }
80781 + }
80782 + return 0;
80783 +}
80784 +
80785 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80786 +{
80787 + const char * const plugin_name = plugin_info->base_name;
80788 + const int argc = plugin_info->argc;
80789 + const struct plugin_argument * const argv = plugin_info->argv;
80790 + int i;
80791 + bool constify = true;
80792 +
80793 + struct register_pass_info local_variable_pass_info = {
80794 + .pass = &pass_local_variable.pass,
80795 + .reference_pass_name = "*referenced_vars",
80796 + .ref_pass_instance_number = 0,
80797 + .pos_op = PASS_POS_INSERT_AFTER
80798 + };
80799 +
80800 + if (!plugin_default_version_check(version, &gcc_version)) {
80801 + error(G_("incompatible gcc/plugin versions"));
80802 + return 1;
80803 + }
80804 +
80805 + for (i = 0; i < argc; ++i) {
80806 + if (!(strcmp(argv[i].key, "no-constify"))) {
80807 + constify = false;
80808 + continue;
80809 + }
80810 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80811 + }
80812 +
80813 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80814 + if (constify) {
80815 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80816 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80817 + }
80818 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80819 +
80820 + return 0;
80821 +}
80822 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80823 new file mode 100644
80824 index 0000000..a5eabce
80825 --- /dev/null
80826 +++ b/tools/gcc/kallocstat_plugin.c
80827 @@ -0,0 +1,167 @@
80828 +/*
80829 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80830 + * Licensed under the GPL v2
80831 + *
80832 + * Note: the choice of the license means that the compilation process is
80833 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80834 + * but for the kernel it doesn't matter since it doesn't link against
80835 + * any of the gcc libraries
80836 + *
80837 + * gcc plugin to find the distribution of k*alloc sizes
80838 + *
80839 + * TODO:
80840 + *
80841 + * BUGS:
80842 + * - none known
80843 + */
80844 +#include "gcc-plugin.h"
80845 +#include "config.h"
80846 +#include "system.h"
80847 +#include "coretypes.h"
80848 +#include "tree.h"
80849 +#include "tree-pass.h"
80850 +#include "flags.h"
80851 +#include "intl.h"
80852 +#include "toplev.h"
80853 +#include "plugin.h"
80854 +//#include "expr.h" where are you...
80855 +#include "diagnostic.h"
80856 +#include "plugin-version.h"
80857 +#include "tm.h"
80858 +#include "function.h"
80859 +#include "basic-block.h"
80860 +#include "gimple.h"
80861 +#include "rtl.h"
80862 +#include "emit-rtl.h"
80863 +
80864 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80865 +
80866 +int plugin_is_GPL_compatible;
80867 +
80868 +static const char * const kalloc_functions[] = {
80869 + "__kmalloc",
80870 + "kmalloc",
80871 + "kmalloc_large",
80872 + "kmalloc_node",
80873 + "kmalloc_order",
80874 + "kmalloc_order_trace",
80875 + "kmalloc_slab",
80876 + "kzalloc",
80877 + "kzalloc_node",
80878 +};
80879 +
80880 +static struct plugin_info kallocstat_plugin_info = {
80881 + .version = "201111150100",
80882 +};
80883 +
80884 +static unsigned int execute_kallocstat(void);
80885 +
80886 +static struct gimple_opt_pass kallocstat_pass = {
80887 + .pass = {
80888 + .type = GIMPLE_PASS,
80889 + .name = "kallocstat",
80890 + .gate = NULL,
80891 + .execute = execute_kallocstat,
80892 + .sub = NULL,
80893 + .next = NULL,
80894 + .static_pass_number = 0,
80895 + .tv_id = TV_NONE,
80896 + .properties_required = 0,
80897 + .properties_provided = 0,
80898 + .properties_destroyed = 0,
80899 + .todo_flags_start = 0,
80900 + .todo_flags_finish = 0
80901 + }
80902 +};
80903 +
80904 +static bool is_kalloc(const char *fnname)
80905 +{
80906 + size_t i;
80907 +
80908 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80909 + if (!strcmp(fnname, kalloc_functions[i]))
80910 + return true;
80911 + return false;
80912 +}
80913 +
80914 +static unsigned int execute_kallocstat(void)
80915 +{
80916 + basic_block bb;
80917 +
80918 + // 1. loop through BBs and GIMPLE statements
80919 + FOR_EACH_BB(bb) {
80920 + gimple_stmt_iterator gsi;
80921 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80922 + // gimple match:
80923 + tree fndecl, size;
80924 + gimple call_stmt;
80925 + const char *fnname;
80926 +
80927 + // is it a call
80928 + call_stmt = gsi_stmt(gsi);
80929 + if (!is_gimple_call(call_stmt))
80930 + continue;
80931 + fndecl = gimple_call_fndecl(call_stmt);
80932 + if (fndecl == NULL_TREE)
80933 + continue;
80934 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80935 + continue;
80936 +
80937 + // is it a call to k*alloc
80938 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80939 + if (!is_kalloc(fnname))
80940 + continue;
80941 +
80942 + // is the size arg the result of a simple const assignment
80943 + size = gimple_call_arg(call_stmt, 0);
80944 + while (true) {
80945 + gimple def_stmt;
80946 + expanded_location xloc;
80947 + size_t size_val;
80948 +
80949 + if (TREE_CODE(size) != SSA_NAME)
80950 + break;
80951 + def_stmt = SSA_NAME_DEF_STMT(size);
80952 + if (!def_stmt || !is_gimple_assign(def_stmt))
80953 + break;
80954 + if (gimple_num_ops(def_stmt) != 2)
80955 + break;
80956 + size = gimple_assign_rhs1(def_stmt);
80957 + if (!TREE_CONSTANT(size))
80958 + continue;
80959 + xloc = expand_location(gimple_location(def_stmt));
80960 + if (!xloc.file)
80961 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80962 + size_val = TREE_INT_CST_LOW(size);
80963 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80964 + break;
80965 + }
80966 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80967 +//debug_tree(gimple_call_fn(call_stmt));
80968 +//print_node(stderr, "pax", fndecl, 4);
80969 + }
80970 + }
80971 +
80972 + return 0;
80973 +}
80974 +
80975 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80976 +{
80977 + const char * const plugin_name = plugin_info->base_name;
80978 + struct register_pass_info kallocstat_pass_info = {
80979 + .pass = &kallocstat_pass.pass,
80980 + .reference_pass_name = "ssa",
80981 + .ref_pass_instance_number = 0,
80982 + .pos_op = PASS_POS_INSERT_AFTER
80983 + };
80984 +
80985 + if (!plugin_default_version_check(version, &gcc_version)) {
80986 + error(G_("incompatible gcc/plugin versions"));
80987 + return 1;
80988 + }
80989 +
80990 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
80991 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
80992 +
80993 + return 0;
80994 +}
80995 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
80996 new file mode 100644
80997 index 0000000..d8a8da2
80998 --- /dev/null
80999 +++ b/tools/gcc/kernexec_plugin.c
81000 @@ -0,0 +1,427 @@
81001 +/*
81002 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81003 + * Licensed under the GPL v2
81004 + *
81005 + * Note: the choice of the license means that the compilation process is
81006 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81007 + * but for the kernel it doesn't matter since it doesn't link against
81008 + * any of the gcc libraries
81009 + *
81010 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81011 + *
81012 + * TODO:
81013 + *
81014 + * BUGS:
81015 + * - none known
81016 + */
81017 +#include "gcc-plugin.h"
81018 +#include "config.h"
81019 +#include "system.h"
81020 +#include "coretypes.h"
81021 +#include "tree.h"
81022 +#include "tree-pass.h"
81023 +#include "flags.h"
81024 +#include "intl.h"
81025 +#include "toplev.h"
81026 +#include "plugin.h"
81027 +//#include "expr.h" where are you...
81028 +#include "diagnostic.h"
81029 +#include "plugin-version.h"
81030 +#include "tm.h"
81031 +#include "function.h"
81032 +#include "basic-block.h"
81033 +#include "gimple.h"
81034 +#include "rtl.h"
81035 +#include "emit-rtl.h"
81036 +#include "tree-flow.h"
81037 +
81038 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81039 +extern rtx emit_move_insn(rtx x, rtx y);
81040 +
81041 +int plugin_is_GPL_compatible;
81042 +
81043 +static struct plugin_info kernexec_plugin_info = {
81044 + .version = "201111291120",
81045 + .help = "method=[bts|or]\tinstrumentation method\n"
81046 +};
81047 +
81048 +static unsigned int execute_kernexec_reload(void);
81049 +static unsigned int execute_kernexec_fptr(void);
81050 +static unsigned int execute_kernexec_retaddr(void);
81051 +static bool kernexec_cmodel_check(void);
81052 +
81053 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81054 +static void (*kernexec_instrument_retaddr)(rtx);
81055 +
81056 +static struct gimple_opt_pass kernexec_reload_pass = {
81057 + .pass = {
81058 + .type = GIMPLE_PASS,
81059 + .name = "kernexec_reload",
81060 + .gate = kernexec_cmodel_check,
81061 + .execute = execute_kernexec_reload,
81062 + .sub = NULL,
81063 + .next = NULL,
81064 + .static_pass_number = 0,
81065 + .tv_id = TV_NONE,
81066 + .properties_required = 0,
81067 + .properties_provided = 0,
81068 + .properties_destroyed = 0,
81069 + .todo_flags_start = 0,
81070 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81071 + }
81072 +};
81073 +
81074 +static struct gimple_opt_pass kernexec_fptr_pass = {
81075 + .pass = {
81076 + .type = GIMPLE_PASS,
81077 + .name = "kernexec_fptr",
81078 + .gate = kernexec_cmodel_check,
81079 + .execute = execute_kernexec_fptr,
81080 + .sub = NULL,
81081 + .next = NULL,
81082 + .static_pass_number = 0,
81083 + .tv_id = TV_NONE,
81084 + .properties_required = 0,
81085 + .properties_provided = 0,
81086 + .properties_destroyed = 0,
81087 + .todo_flags_start = 0,
81088 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81089 + }
81090 +};
81091 +
81092 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81093 + .pass = {
81094 + .type = RTL_PASS,
81095 + .name = "kernexec_retaddr",
81096 + .gate = kernexec_cmodel_check,
81097 + .execute = execute_kernexec_retaddr,
81098 + .sub = NULL,
81099 + .next = NULL,
81100 + .static_pass_number = 0,
81101 + .tv_id = TV_NONE,
81102 + .properties_required = 0,
81103 + .properties_provided = 0,
81104 + .properties_destroyed = 0,
81105 + .todo_flags_start = 0,
81106 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81107 + }
81108 +};
81109 +
81110 +static bool kernexec_cmodel_check(void)
81111 +{
81112 + tree section;
81113 +
81114 + if (ix86_cmodel != CM_KERNEL)
81115 + return false;
81116 +
81117 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81118 + if (!section || !TREE_VALUE(section))
81119 + return true;
81120 +
81121 + section = TREE_VALUE(TREE_VALUE(section));
81122 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81123 + return true;
81124 +
81125 + return false;
81126 +}
81127 +
81128 +/*
81129 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81130 + */
81131 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81132 +{
81133 + gimple asm_movabs_stmt;
81134 +
81135 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81136 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81137 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81138 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81139 + update_stmt(asm_movabs_stmt);
81140 +}
81141 +
81142 +/*
81143 + * find all asm() stmts that clobber r10 and add a reload of r10
81144 + */
81145 +static unsigned int execute_kernexec_reload(void)
81146 +{
81147 + basic_block bb;
81148 +
81149 + // 1. loop through BBs and GIMPLE statements
81150 + FOR_EACH_BB(bb) {
81151 + gimple_stmt_iterator gsi;
81152 +
81153 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81154 + // gimple match: __asm__ ("" : : : "r10");
81155 + gimple asm_stmt;
81156 + size_t nclobbers;
81157 +
81158 + // is it an asm ...
81159 + asm_stmt = gsi_stmt(gsi);
81160 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81161 + continue;
81162 +
81163 + // ... clobbering r10
81164 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81165 + while (nclobbers--) {
81166 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81167 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81168 + continue;
81169 + kernexec_reload_fptr_mask(&gsi);
81170 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81171 + break;
81172 + }
81173 + }
81174 + }
81175 +
81176 + return 0;
81177 +}
81178 +
81179 +/*
81180 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81181 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81182 + */
81183 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81184 +{
81185 + gimple assign_intptr, assign_new_fptr, call_stmt;
81186 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81187 +
81188 + call_stmt = gsi_stmt(*gsi);
81189 + old_fptr = gimple_call_fn(call_stmt);
81190 +
81191 + // create temporary unsigned long variable used for bitops and cast fptr to it
81192 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81193 + add_referenced_var(intptr);
81194 + mark_sym_for_renaming(intptr);
81195 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81196 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81197 + update_stmt(assign_intptr);
81198 +
81199 + // apply logical or to temporary unsigned long and bitmask
81200 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81201 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81202 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81203 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81204 + update_stmt(assign_intptr);
81205 +
81206 + // cast temporary unsigned long back to a temporary fptr variable
81207 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
81208 + add_referenced_var(new_fptr);
81209 + mark_sym_for_renaming(new_fptr);
81210 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81211 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81212 + update_stmt(assign_new_fptr);
81213 +
81214 + // replace call stmt fn with the new fptr
81215 + gimple_call_set_fn(call_stmt, new_fptr);
81216 + update_stmt(call_stmt);
81217 +}
81218 +
81219 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81220 +{
81221 + gimple asm_or_stmt, call_stmt;
81222 + tree old_fptr, new_fptr, input, output;
81223 + VEC(tree, gc) *inputs = NULL;
81224 + VEC(tree, gc) *outputs = NULL;
81225 +
81226 + call_stmt = gsi_stmt(*gsi);
81227 + old_fptr = gimple_call_fn(call_stmt);
81228 +
81229 + // create temporary fptr variable
81230 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81231 + add_referenced_var(new_fptr);
81232 + mark_sym_for_renaming(new_fptr);
81233 +
81234 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81235 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81236 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81237 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81238 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81239 + VEC_safe_push(tree, gc, inputs, input);
81240 + VEC_safe_push(tree, gc, outputs, output);
81241 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81242 + gimple_asm_set_volatile(asm_or_stmt, true);
81243 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81244 + update_stmt(asm_or_stmt);
81245 +
81246 + // replace call stmt fn with the new fptr
81247 + gimple_call_set_fn(call_stmt, new_fptr);
81248 + update_stmt(call_stmt);
81249 +}
81250 +
81251 +/*
81252 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81253 + */
81254 +static unsigned int execute_kernexec_fptr(void)
81255 +{
81256 + basic_block bb;
81257 +
81258 + // 1. loop through BBs and GIMPLE statements
81259 + FOR_EACH_BB(bb) {
81260 + gimple_stmt_iterator gsi;
81261 +
81262 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81263 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81264 + tree fn;
81265 + gimple call_stmt;
81266 +
81267 + // is it a call ...
81268 + call_stmt = gsi_stmt(gsi);
81269 + if (!is_gimple_call(call_stmt))
81270 + continue;
81271 + fn = gimple_call_fn(call_stmt);
81272 + if (TREE_CODE(fn) == ADDR_EXPR)
81273 + continue;
81274 + if (TREE_CODE(fn) != SSA_NAME)
81275 + gcc_unreachable();
81276 +
81277 + // ... through a function pointer
81278 + fn = SSA_NAME_VAR(fn);
81279 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81280 + continue;
81281 + fn = TREE_TYPE(fn);
81282 + if (TREE_CODE(fn) != POINTER_TYPE)
81283 + continue;
81284 + fn = TREE_TYPE(fn);
81285 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81286 + continue;
81287 +
81288 + kernexec_instrument_fptr(&gsi);
81289 +
81290 +//debug_tree(gimple_call_fn(call_stmt));
81291 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81292 + }
81293 + }
81294 +
81295 + return 0;
81296 +}
81297 +
81298 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81299 +static void kernexec_instrument_retaddr_bts(rtx insn)
81300 +{
81301 + rtx btsq;
81302 + rtvec argvec, constraintvec, labelvec;
81303 + int line;
81304 +
81305 + // create asm volatile("btsq $63,(%%rsp)":::)
81306 + argvec = rtvec_alloc(0);
81307 + constraintvec = rtvec_alloc(0);
81308 + labelvec = rtvec_alloc(0);
81309 + line = expand_location(RTL_LOCATION(insn)).line;
81310 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81311 + MEM_VOLATILE_P(btsq) = 1;
81312 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81313 + emit_insn_before(btsq, insn);
81314 +}
81315 +
81316 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81317 +static void kernexec_instrument_retaddr_or(rtx insn)
81318 +{
81319 + rtx orq;
81320 + rtvec argvec, constraintvec, labelvec;
81321 + int line;
81322 +
81323 + // create asm volatile("orq %%r10,(%%rsp)":::)
81324 + argvec = rtvec_alloc(0);
81325 + constraintvec = rtvec_alloc(0);
81326 + labelvec = rtvec_alloc(0);
81327 + line = expand_location(RTL_LOCATION(insn)).line;
81328 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81329 + MEM_VOLATILE_P(orq) = 1;
81330 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81331 + emit_insn_before(orq, insn);
81332 +}
81333 +
81334 +/*
81335 + * find all asm level function returns and forcibly set the highest bit of the return address
81336 + */
81337 +static unsigned int execute_kernexec_retaddr(void)
81338 +{
81339 + rtx insn;
81340 +
81341 + // 1. find function returns
81342 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81343 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81344 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81345 + rtx body;
81346 +
81347 + // is it a retn
81348 + if (!JUMP_P(insn))
81349 + continue;
81350 + body = PATTERN(insn);
81351 + if (GET_CODE(body) == PARALLEL)
81352 + body = XVECEXP(body, 0, 0);
81353 + if (GET_CODE(body) != RETURN)
81354 + continue;
81355 + kernexec_instrument_retaddr(insn);
81356 + }
81357 +
81358 +// print_simple_rtl(stderr, get_insns());
81359 +// print_rtl(stderr, get_insns());
81360 +
81361 + return 0;
81362 +}
81363 +
81364 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81365 +{
81366 + const char * const plugin_name = plugin_info->base_name;
81367 + const int argc = plugin_info->argc;
81368 + const struct plugin_argument * const argv = plugin_info->argv;
81369 + int i;
81370 + struct register_pass_info kernexec_reload_pass_info = {
81371 + .pass = &kernexec_reload_pass.pass,
81372 + .reference_pass_name = "ssa",
81373 + .ref_pass_instance_number = 0,
81374 + .pos_op = PASS_POS_INSERT_AFTER
81375 + };
81376 + struct register_pass_info kernexec_fptr_pass_info = {
81377 + .pass = &kernexec_fptr_pass.pass,
81378 + .reference_pass_name = "ssa",
81379 + .ref_pass_instance_number = 0,
81380 + .pos_op = PASS_POS_INSERT_AFTER
81381 + };
81382 + struct register_pass_info kernexec_retaddr_pass_info = {
81383 + .pass = &kernexec_retaddr_pass.pass,
81384 + .reference_pass_name = "pro_and_epilogue",
81385 + .ref_pass_instance_number = 0,
81386 + .pos_op = PASS_POS_INSERT_AFTER
81387 + };
81388 +
81389 + if (!plugin_default_version_check(version, &gcc_version)) {
81390 + error(G_("incompatible gcc/plugin versions"));
81391 + return 1;
81392 + }
81393 +
81394 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81395 +
81396 + if (TARGET_64BIT == 0)
81397 + return 0;
81398 +
81399 + for (i = 0; i < argc; ++i) {
81400 + if (!strcmp(argv[i].key, "method")) {
81401 + if (!argv[i].value) {
81402 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81403 + continue;
81404 + }
81405 + if (!strcmp(argv[i].value, "bts")) {
81406 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81407 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81408 + } else if (!strcmp(argv[i].value, "or")) {
81409 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81410 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81411 + fix_register("r10", 1, 1);
81412 + } else
81413 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81414 + continue;
81415 + }
81416 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81417 + }
81418 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81419 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81420 +
81421 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81422 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81423 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81424 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81425 +
81426 + return 0;
81427 +}
81428 diff --git a/tools/gcc/size_overflow_hash1.h b/tools/gcc/size_overflow_hash1.h
81429 new file mode 100644
81430 index 0000000..16ccac1
81431 --- /dev/null
81432 +++ b/tools/gcc/size_overflow_hash1.h
81433 @@ -0,0 +1,3047 @@
81434 +struct size_overflow_hash size_overflow_hash1[65536] = {
81435 + [10013].file = "security/smack/smackfs.c",
81436 + [10013].name = "smk_write_direct",
81437 + [10013].param3 = 1,
81438 + [10167].file = "sound/core/oss/pcm_plugin.c",
81439 + [10167].name = "snd_pcm_plugin_build",
81440 + [10167].param5 = 1,
81441 + [1020].file = "drivers/usb/misc/usbtest.c",
81442 + [1020].name = "test_unaligned_bulk",
81443 + [1020].param3 = 1,
81444 + [1022].file = "sound/pci/rme9652/rme9652.c",
81445 + [1022].name = "snd_rme9652_playback_copy",
81446 + [1022].param5 = 1,
81447 + [10321].file = "drivers/platform/x86/thinkpad_acpi.c",
81448 + [10321].name = "create_attr_set",
81449 + [10321].param1 = 1,
81450 + [10341].file = "fs/nfsd/nfs4xdr.c",
81451 + [10341].name = "read_buf",
81452 + [10341].param2 = 1,
81453 + [10357].file = "net/sunrpc/cache.c",
81454 + [10357].name = "cache_read",
81455 + [10357].param3 = 1,
81456 + [10397].file = "drivers/gpu/drm/i915/i915_debugfs.c",
81457 + [10397].name = "i915_wedged_write",
81458 + [10397].param3 = 1,
81459 + [10399].file = "kernel/trace/trace.c",
81460 + [10399].name = "trace_seq_to_user",
81461 + [10399].param3 = 1,
81462 + [10414].file = "drivers/tty/vt/vt.c",
81463 + [10414].name = "vc_do_resize",
81464 + [10414].param3 = 1,
81465 + [10414].param4 = 1,
81466 + [10565].file = "drivers/input/touchscreen/ad7879-spi.c",
81467 + [10565].name = "ad7879_spi_multi_read",
81468 + [10565].param3 = 1,
81469 + [10623].file = "drivers/infiniband/core/user_mad.c",
81470 + [10623].name = "ib_umad_write",
81471 + [10623].param3 = 1,
81472 + [10707].file = "fs/nfs/idmap.c",
81473 + [10707].name = "nfs_idmap_request_key",
81474 + [10707].param2 = 1,
81475 + [1073].file = "drivers/block/aoe/aoecmd.c",
81476 + [1073].name = "addtgt",
81477 + [1073].param3 = 1,
81478 + [10745].file = "fs/cifs/connect.c",
81479 + [10745].name = "get_server_iovec",
81480 + [10745].param2 = 1,
81481 + [10750].file = "drivers/net/wireless/iwmc3200wifi/rx.c",
81482 + [10750].name = "iwm_ntf_calib_res",
81483 + [10750].param3 = 1,
81484 + [10773].file = "drivers/input/mousedev.c",
81485 + [10773].name = "mousedev_read",
81486 + [10773].param3 = 1,
81487 + [10777].file = "fs/ntfs/file.c",
81488 + [10777].name = "ntfs_file_buffered_write",
81489 + [10777].param6 = 1,
81490 + [10893].file = "drivers/misc/sgi-gru/gruprocfs.c",
81491 + [10893].name = "options_write",
81492 + [10893].param3 = 1,
81493 + [10919].file = "net/ipv4/netfilter/arp_tables.c",
81494 + [10919].name = "do_arpt_set_ctl",
81495 + [10919].param4 = 1,
81496 + [1107].file = "mm/process_vm_access.c",
81497 + [1107].name = "process_vm_rw_single_vec",
81498 + [1107].param1 = 1,
81499 + [1107].param2 = 1,
81500 + [11230].file = "net/core/neighbour.c",
81501 + [11230].name = "neigh_hash_grow",
81502 + [11230].param2 = 1,
81503 + [11364].file = "fs/ext4/super.c",
81504 + [11364].name = "ext4_kvzalloc",
81505 + [11364].param1 = 1,
81506 + [114].file = "security/selinux/selinuxfs.c",
81507 + [114].name = "sel_write_relabel",
81508 + [114].param3 = 1,
81509 + [11549].file = "drivers/media/rc/redrat3.c",
81510 + [11549].name = "redrat3_transmit_ir",
81511 + [11549].param3 = 1,
81512 + [11568].file = "drivers/gpu/drm/drm_scatter.c",
81513 + [11568].name = "drm_vmalloc_dma",
81514 + [11568].param1 = 1,
81515 + [11582].file = "drivers/scsi/lpfc/lpfc_sli.c",
81516 + [11582].name = "lpfc_sli4_queue_alloc",
81517 + [11582].param3 = 1,
81518 + [11616].file = "security/selinux/selinuxfs.c",
81519 + [11616].name = "sel_write_enforce",
81520 + [11616].param3 = 1,
81521 + [11699].file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
81522 + [11699].name = "vxge_os_dma_malloc",
81523 + [11699].param2 = 1,
81524 + [11766].file = "drivers/block/paride/pt.c",
81525 + [11766].name = "pt_read",
81526 + [11766].param3 = 1,
81527 + [11784].file = "fs/bio.c",
81528 + [11784].name = "bio_kmalloc",
81529 + [11784].param2 = 1,
81530 + [11919].file = "drivers/lguest/core.c",
81531 + [11919].name = "__lgread",
81532 + [11919].param4 = 1,
81533 + [11925].file = "drivers/media/video/cx18/cx18-fileops.c",
81534 + [11925].name = "cx18_copy_mdl_to_user",
81535 + [11925].param4 = 1,
81536 + [11985].file = "drivers/block/floppy.c",
81537 + [11985].name = "fd_copyin",
81538 + [11985].param3 = 1,
81539 + [11986].file = "drivers/net/usb/asix.c",
81540 + [11986].name = "asix_read_cmd",
81541 + [11986].param5 = 1,
81542 + [12018].file = "sound/core/oss/pcm_oss.c",
81543 + [12018].name = "snd_pcm_oss_read1",
81544 + [12018].param3 = 1,
81545 + [12059].file = "drivers/net/wireless/libertas/debugfs.c",
81546 + [12059].name = "lbs_debugfs_write",
81547 + [12059].param3 = 1,
81548 + [12151].file = "fs/compat.c",
81549 + [12151].name = "compat_rw_copy_check_uvector",
81550 + [12151].param3 = 1,
81551 + [12205].file = "fs/reiserfs/journal.c",
81552 + [12205].name = "reiserfs_allocate_list_bitmaps",
81553 + [12205].param3 = 1,
81554 + [12234].file = "include/acpi/platform/aclinux.h",
81555 + [12234].name = "acpi_os_allocate",
81556 + [12234].param1 = 1,
81557 + [1227].file = "lib/cpu_rmap.c",
81558 + [1227].name = "alloc_cpu_rmap",
81559 + [1227].param1 = 1,
81560 + [12395].file = "drivers/char/hw_random/core.c",
81561 + [12395].name = "rng_dev_read",
81562 + [12395].param3 = 1,
81563 + [12602].file = "net/sunrpc/cache.c",
81564 + [12602].name = "cache_downcall",
81565 + [12602].param3 = 1,
81566 + [12712].file = "drivers/net/wimax/i2400m/fw.c",
81567 + [12712].name = "i2400m_zrealloc_2x",
81568 + [12712].param3 = 1,
81569 + [12755].file = "sound/drivers/opl4/opl4_proc.c",
81570 + [12755].name = "snd_opl4_mem_proc_read",
81571 + [12755].param5 = 1,
81572 + [12833].file = "net/sctp/auth.c",
81573 + [12833].name = "sctp_auth_create_key",
81574 + [12833].param1 = 1,
81575 + [12840].file = "net/sctp/tsnmap.c",
81576 + [12840].name = "sctp_tsnmap_mark",
81577 + [12840].param2 = 1,
81578 + [12931].file = "drivers/hid/hid-roccat.c",
81579 + [12931].name = "roccat_read",
81580 + [12931].param3 = 1,
81581 + [12954].file = "fs/proc/base.c",
81582 + [12954].name = "oom_adjust_write",
81583 + [12954].param3 = 1,
81584 + [13103].file = "drivers/acpi/acpica/utobject.c",
81585 + [13103].name = "acpi_ut_create_string_object",
81586 + [13103].param1 = 1,
81587 + [13121].file = "net/ipv4/ip_sockglue.c",
81588 + [13121].name = "do_ip_setsockopt",
81589 + [13121].param5 = 1,
81590 + [1327].file = "net/netfilter/nfnetlink_log.c",
81591 + [1327].name = "nfulnl_alloc_skb",
81592 + [1327].param2 = 1,
81593 + [13337].file = "net/core/iovec.c",
81594 + [13337].name = "csum_partial_copy_fromiovecend",
81595 + [13337].param4 = 1,
81596 + [13339].file = "security/smack/smackfs.c",
81597 + [13339].name = "smk_write_netlbladdr",
81598 + [13339].param3 = 1,
81599 + [13342].file = "fs/jbd2/journal.c",
81600 + [13342].name = "jbd2_alloc",
81601 + [13342].param1 = 1,
81602 + [13384].file = "drivers/char/virtio_console.c",
81603 + [13384].name = "alloc_buf",
81604 + [13384].param1 = 1,
81605 + [13412].file = "fs/proc/base.c",
81606 + [13412].name = "oom_score_adj_write",
81607 + [13412].param3 = 1,
81608 + [13559].file = "drivers/media/video/ivtv/ivtv-fileops.c",
81609 + [13559].name = "ivtv_read",
81610 + [13559].param3 = 1,
81611 + [13618].file = "drivers/net/team/team.c",
81612 + [13618].name = "team_options_register",
81613 + [13618].param3 = 1,
81614 + [13659].file = "drivers/net/wan/hdlc.c",
81615 + [13659].name = "attach_hdlc_protocol",
81616 + [13659].param3 = 1,
81617 + [13708].file = "drivers/usb/misc/usbtest.c",
81618 + [13708].name = "simple_alloc_urb",
81619 + [13708].param3 = 1,
81620 + [13805].file = "drivers/misc/altera-stapl/altera-jtag.c",
81621 + [13805].name = "altera_swap_dr",
81622 + [13805].param2 = 1,
81623 + [13868].file = "fs/lockd/mon.c",
81624 + [13868].name = "nsm_create_handle",
81625 + [13868].param4 = 1,
81626 + [13924].file = "net/ipv4/netfilter/ip_tables.c",
81627 + [13924].name = "do_ipt_set_ctl",
81628 + [13924].param4 = 1,
81629 + [14019].file = "net/dns_resolver/dns_key.c",
81630 + [14019].name = "dns_resolver_instantiate",
81631 + [14019].param2 = 1,
81632 + [14019].param3 = 1,
81633 + [14025].file = "net/ax25/af_ax25.c",
81634 + [14025].name = "ax25_setsockopt",
81635 + [14025].param5 = 1,
81636 + [14029].file = "drivers/spi/spidev.c",
81637 + [14029].name = "spidev_compat_ioctl",
81638 + [14029].param2 = 1,
81639 + [14090].file = "drivers/bluetooth/btmrvl_debugfs.c",
81640 + [14090].name = "btmrvl_hsmode_write",
81641 + [14090].param3 = 1,
81642 + [14149].file = "drivers/hid/hidraw.c",
81643 + [14149].name = "hidraw_ioctl",
81644 + [14149].param2 = 1,
81645 + [14153].file = "drivers/staging/bcm/led_control.c",
81646 + [14153].name = "ValidateDSDParamsChecksum",
81647 + [14153].param3 = 1,
81648 + [14174].file = "sound/pci/es1938.c",
81649 + [14174].name = "snd_es1938_capture_copy",
81650 + [14174].param5 = 1,
81651 + [14207].file = "drivers/media/video/v4l2-event.c",
81652 + [14207].name = "v4l2_event_subscribe",
81653 + [14207].param3 = 1,
81654 + [14241].file = "drivers/platform/x86/asus_acpi.c",
81655 + [14241].name = "brn_proc_write",
81656 + [14241].param3 = 1,
81657 + [14345].file = "fs/cachefiles/daemon.c",
81658 + [14345].name = "cachefiles_daemon_write",
81659 + [14345].param3 = 1,
81660 + [14347].file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
81661 + [14347].name = "dvb_ca_en50221_io_write",
81662 + [14347].param3 = 1,
81663 + [14566].file = "drivers/pci/hotplug/ibmphp_ebda.c",
81664 + [14566].name = "alloc_ebda_hpc",
81665 + [14566].param1 = 1,
81666 + [14566].param2 = 1,
81667 + [1458].file = "drivers/misc/lkdtm.c",
81668 + [1458].name = "direct_entry",
81669 + [1458].param3 = 1,
81670 + [14646].file = "fs/compat.c",
81671 + [14646].name = "compat_writev",
81672 + [14646].param3 = 1,
81673 + [14684].file = "drivers/media/video/stk-webcam.c",
81674 + [14684].name = "stk_allocate_buffers",
81675 + [14684].param2 = 1,
81676 + [14736].file = "drivers/usb/misc/usbtest.c",
81677 + [14736].name = "unlink_queued",
81678 + [14736].param3 = 1,
81679 + [1482].file = "drivers/scsi/scsi_netlink.c",
81680 + [1482].name = "scsi_nl_send_vendor_msg",
81681 + [1482].param5 = 1,
81682 + [15017].file = "drivers/edac/edac_device.c",
81683 + [15017].name = "edac_device_alloc_ctl_info",
81684 + [15017].param1 = 1,
81685 + [15044].file = "drivers/uio/uio.c",
81686 + [15044].name = "uio_write",
81687 + [15044].param3 = 1,
81688 + [15087].file = "fs/bio.c",
81689 + [15087].name = "bio_map_kern",
81690 + [15087].param2 = 1,
81691 + [15087].param3 = 1,
81692 + [15112].file = "drivers/xen/evtchn.c",
81693 + [15112].name = "evtchn_write",
81694 + [15112].param3 = 1,
81695 + [15130].file = "net/bluetooth/hci_core.c",
81696 + [15130].name = "hci_send_cmd",
81697 + [15130].param3 = 1,
81698 + [15202].file = "net/bluetooth/rfcomm/tty.c",
81699 + [15202].name = "rfcomm_wmalloc",
81700 + [15202].param2 = 1,
81701 + [15274].file = "crypto/shash.c",
81702 + [15274].name = "crypto_shash_setkey",
81703 + [15274].param3 = 1,
81704 + [15354].file = "drivers/isdn/mISDN/socket.c",
81705 + [15354].name = "mISDN_sock_sendmsg",
81706 + [15354].param4 = 1,
81707 + [15361].file = "drivers/char/agp/generic.c",
81708 + [15361].name = "agp_allocate_memory",
81709 + [15361].param2 = 1,
81710 + [15497].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
81711 + [15497].name = "ts_read",
81712 + [15497].param3 = 1,
81713 + [15551].file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
81714 + [15551].name = "clusterip_proc_write",
81715 + [15551].param3 = 1,
81716 + [15701].file = "drivers/hid/hid-roccat-common.c",
81717 + [15701].name = "roccat_common_receive",
81718 + [15701].param4 = 1,
81719 + [1572].file = "net/ceph/pagevec.c",
81720 + [1572].name = "ceph_copy_page_vector_to_user",
81721 + [1572].param4 = 1,
81722 + [15814].file = "net/mac80211/debugfs_netdev.c",
81723 + [15814].name = "ieee80211_if_write",
81724 + [15814].param3 = 1,
81725 + [15883].file = "security/keys/keyctl.c",
81726 + [15883].name = "sys_add_key",
81727 + [15883].param4 = 1,
81728 + [15884].file = "fs/exofs/super.c",
81729 + [15884].name = "exofs_read_lookup_dev_table",
81730 + [15884].param3 = 1,
81731 + [16037].file = "drivers/staging/media/easycap/easycap_sound.c",
81732 + [16037].name = "easycap_alsa_vmalloc",
81733 + [16037].param2 = 1,
81734 + [16073].file = "net/sctp/socket.c",
81735 + [16073].name = "sctp_setsockopt",
81736 + [16073].param5 = 1,
81737 + [16132].file = "drivers/staging/vme/devices/vme_user.c",
81738 + [16132].name = "buffer_from_user",
81739 + [16132].param3 = 1,
81740 + [16138].file = "security/selinux/ss/services.c",
81741 + [16138].name = "security_context_to_sid_force",
81742 + [16138].param2 = 1,
81743 + [16166].file = "drivers/platform/x86/thinkpad_acpi.c",
81744 + [16166].name = "dispatch_proc_write",
81745 + [16166].param3 = 1,
81746 + [16229].file = "drivers/scsi/scsi_transport_iscsi.c",
81747 + [16229].name = "iscsi_offload_mesg",
81748 + [16229].param5 = 1,
81749 + [16353].file = "drivers/base/regmap/regmap.c",
81750 + [16353].name = "regmap_raw_write",
81751 + [16353].param4 = 1,
81752 + [16383].file = "fs/proc/base.c",
81753 + [16383].name = "comm_write",
81754 + [16383].param3 = 1,
81755 + [16396].file = "drivers/misc/altera-stapl/altera-jtag.c",
81756 + [16396].name = "altera_irscan",
81757 + [16396].param2 = 1,
81758 + [16447].file = "drivers/hid/usbhid/hiddev.c",
81759 + [16447].name = "hiddev_ioctl",
81760 + [16447].param2 = 1,
81761 + [16453].file = "include/linux/slab.h",
81762 + [16453].name = "kzalloc",
81763 + [16453].param1 = 1,
81764 + [16605].file = "fs/ecryptfs/miscdev.c",
81765 + [16605].name = "ecryptfs_send_miscdev",
81766 + [16605].param2 = 1,
81767 + [16606].file = "drivers/ide/ide-tape.c",
81768 + [16606].name = "idetape_chrdev_write",
81769 + [16606].param3 = 1,
81770 + [16637].file = "security/keys/encrypted-keys/encrypted.c",
81771 + [16637].name = "datablob_hmac_verify",
81772 + [16637].param4 = 1,
81773 + [16828].file = "net/batman-adv/hash.c",
81774 + [16828].name = "hash_new",
81775 + [16828].param1 = 1,
81776 + [16853].file = "drivers/net/ethernet/chelsio/cxgb4vf/sge.c",
81777 + [16853].name = "t4vf_pktgl_to_skb",
81778 + [16853].param2 = 1,
81779 + [16911].file = "drivers/media/dvb/ttpci/av7110_hw.c",
81780 + [16911].name = "LoadBitmap",
81781 + [16911].param2 = 1,
81782 + [169].file = "drivers/net/ethernet/amd/pcnet32.c",
81783 + [169].name = "pcnet32_realloc_rx_ring",
81784 + [169].param3 = 1,
81785 + [17075].file = "sound/isa/gus/gus_dram.c",
81786 + [17075].name = "snd_gus_dram_write",
81787 + [17075].param4 = 1,
81788 + [17133].file = "drivers/usb/misc/iowarrior.c",
81789 + [17133].name = "iowarrior_read",
81790 + [17133].param3 = 1,
81791 + [17185].file = "net/wireless/scan.c",
81792 + [17185].name = "cfg80211_inform_bss",
81793 + [17185].param8 = 1,
81794 + [17349].file = "net/tipc/link.c",
81795 + [17349].name = "tipc_link_send_sections_fast",
81796 + [17349].param4 = 1,
81797 + [17377].file = "drivers/usb/class/cdc-wdm.c",
81798 + [17377].name = "wdm_write",
81799 + [17377].param3 = 1,
81800 + [17459].file = "drivers/usb/misc/rio500.c",
81801 + [17459].name = "write_rio",
81802 + [17459].param3 = 1,
81803 + [17460].file = "fs/nfsd/nfscache.c",
81804 + [17460].name = "nfsd_cache_update",
81805 + [17460].param3 = 1,
81806 + [17492].file = "net/dccp/proto.c",
81807 + [17492].name = "do_dccp_setsockopt",
81808 + [17492].param5 = 1,
81809 + [1754].file = "sound/core/oss/pcm_oss.c",
81810 + [1754].name = "snd_pcm_oss_write",
81811 + [1754].param3 = 1,
81812 + [17604].file = "fs/proc/generic.c",
81813 + [17604].name = "__proc_file_read",
81814 + [17604].param3 = 1,
81815 + [17718].file = "net/caif/caif_socket.c",
81816 + [17718].name = "setsockopt",
81817 + [17718].param5 = 1,
81818 + [17828].file = "kernel/sched/core.c",
81819 + [17828].name = "sched_feat_write",
81820 + [17828].param3 = 1,
81821 + [17841].file = "drivers/misc/tifm_core.c",
81822 + [17841].name = "tifm_alloc_adapter",
81823 + [17841].param1 = 1,
81824 + [17946].file = "drivers/net/wireless/libertas/if_spi.c",
81825 + [17946].name = "if_spi_host_to_card",
81826 + [17946].param4 = 1,
81827 + [1800].file = "drivers/media/dvb/dvb-core/dmxdev.c",
81828 + [1800].name = "dvb_dvr_do_ioctl",
81829 + [1800].param3 = 1,
81830 + [18119].file = "drivers/misc/iwmc3200top/fw-download.c",
81831 + [18119].name = "iwmct_fw_parser_init",
81832 + [18119].param4 = 1,
81833 + [18140].file = "drivers/scsi/pm8001/pm8001_ctl.c",
81834 + [18140].name = "pm8001_store_update_fw",
81835 + [18140].param4 = 1,
81836 + [18191].file = "sound/pci/hda/patch_realtek.c",
81837 + [18191].name = "new_bind_ctl",
81838 + [18191].param2 = 1,
81839 + [18224].file = "drivers/xen/grant-table.c",
81840 + [18224].name = "gnttab_map",
81841 + [18224].param2 = 1,
81842 + [18232].file = "fs/nfs/write.c",
81843 + [18232].name = "nfs_writedata_alloc",
81844 + [18232].param1 = 1,
81845 + [18247].file = "drivers/char/agp/generic.c",
81846 + [18247].name = "agp_create_user_memory",
81847 + [18247].param1 = 1,
81848 + [18303].file = "fs/xattr.c",
81849 + [18303].name = "getxattr",
81850 + [18303].param4 = 1,
81851 + [18353].file = "net/rfkill/core.c",
81852 + [18353].name = "rfkill_fop_read",
81853 + [18353].param3 = 1,
81854 + [18386].file = "fs/read_write.c",
81855 + [18386].name = "vfs_readv",
81856 + [18386].param3 = 1,
81857 + [18391].file = "fs/ocfs2/stack_user.c",
81858 + [18391].name = "ocfs2_control_write",
81859 + [18391].param3 = 1,
81860 + [183].file = "crypto/ahash.c",
81861 + [183].name = "crypto_ahash_setkey",
81862 + [183].param3 = 1,
81863 + [18406].file = "drivers/media/video/tm6000/tm6000-core.c",
81864 + [18406].name = "tm6000_read_write_usb",
81865 + [18406].param7 = 1,
81866 + [1845].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
81867 + [1845].name = "rt2x00debug_write_rf",
81868 + [1845].param3 = 1,
81869 + [18465].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
81870 + [18465].name = "cxgb_alloc_mem",
81871 + [18465].param1 = 1,
81872 + [184].file = "drivers/firewire/nosy.c",
81873 + [184].name = "packet_buffer_init",
81874 + [184].param2 = 1,
81875 + [1858].file = "net/ipv6/netfilter/ip6_tables.c",
81876 + [1858].name = "do_ip6t_set_ctl",
81877 + [1858].param4 = 1,
81878 + [18659].file = "drivers/media/dvb/dvb-core/dvbdev.c",
81879 + [18659].name = "dvb_usercopy",
81880 + [18659].param2 = 1,
81881 + [18722].file = "security/tomoyo/condition.c",
81882 + [18722].name = "tomoyo_scan_bprm",
81883 + [18722].param2 = 1,
81884 + [18722].param4 = 1,
81885 + [18775].file = "include/linux/textsearch.h",
81886 + [18775].name = "alloc_ts_config",
81887 + [18775].param1 = 1,
81888 + [18940].file = "drivers/usb/host/hwa-hc.c",
81889 + [18940].name = "__hwahc_op_set_gtk",
81890 + [18940].param4 = 1,
81891 + [19012].file = "drivers/acpi/event.c",
81892 + [19012].name = "acpi_system_read_event",
81893 + [19012].param3 = 1,
81894 + [19028].file = "mm/filemap.c",
81895 + [19028].name = "iov_iter_copy_from_user_atomic",
81896 + [19028].param4 = 1,
81897 + [19107].file = "security/smack/smackfs.c",
81898 + [19107].name = "smk_write_load_list",
81899 + [19107].param3 = 1,
81900 + [19240].file = "net/sctp/socket.c",
81901 + [19240].name = "sctp_setsockopt_delayed_ack",
81902 + [19240].param3 = 1,
81903 + [19274].file = "net/core/pktgen.c",
81904 + [19274].name = "pktgen_if_write",
81905 + [19274].param3 = 1,
81906 + [19286].file = "drivers/base/regmap/regmap.c",
81907 + [19286].name = "_regmap_raw_write",
81908 + [19286].param4 = 1,
81909 + [19308].file = "drivers/char/mem.c",
81910 + [19308].name = "read_oldmem",
81911 + [19308].param3 = 1,
81912 + [19343].file = "security/keys/encrypted-keys/encrypted.c",
81913 + [19343].name = "datablob_hmac_append",
81914 + [19343].param3 = 1,
81915 + [19349].file = "drivers/acpi/acpica/utobject.c",
81916 + [19349].name = "acpi_ut_create_package_object",
81917 + [19349].param1 = 1,
81918 + [19453].file = "drivers/net/ethernet/chelsio/cxgb/sge.c",
81919 + [19453].name = "sge_rx",
81920 + [19453].param3 = 1,
81921 + [19504].file = "drivers/usb/serial/garmin_gps.c",
81922 + [19504].name = "pkt_add",
81923 + [19504].param3 = 1,
81924 + [19522].file = "mm/percpu.c",
81925 + [19522].name = "pcpu_mem_zalloc",
81926 + [19522].param1 = 1,
81927 + [19548].file = "drivers/scsi/qla2xxx/qla_init.c",
81928 + [19548].name = "qla2x00_get_ctx_sp",
81929 + [19548].param3 = 1,
81930 + [19592].file = "net/dccp/proto.c",
81931 + [19592].name = "dccp_setsockopt_service",
81932 + [19592].param4 = 1,
81933 + [19726].file = "kernel/trace/trace.c",
81934 + [19726].name = "tracing_set_trace_write",
81935 + [19726].param3 = 1,
81936 + [19738].file = "fs/sysfs/file.c",
81937 + [19738].name = "sysfs_write_file",
81938 + [19738].param3 = 1,
81939 + [19833].file = "drivers/xen/privcmd.c",
81940 + [19833].name = "gather_array",
81941 + [19833].param3 = 1,
81942 + [19910].file = "drivers/media/video/saa7164/saa7164-buffer.c",
81943 + [19910].name = "saa7164_buffer_alloc_user",
81944 + [19910].param2 = 1,
81945 + [19920].file = "drivers/input/joydev.c",
81946 + [19920].name = "joydev_ioctl",
81947 + [19920].param2 = 1,
81948 + [19931].file = "drivers/usb/misc/ftdi-elan.c",
81949 + [19931].name = "ftdi_elan_write",
81950 + [19931].param3 = 1,
81951 + [19960].file = "drivers/usb/class/usblp.c",
81952 + [19960].name = "usblp_read",
81953 + [19960].param3 = 1,
81954 + [1996].file = "drivers/scsi/libsrp.c",
81955 + [1996].name = "srp_target_alloc",
81956 + [1996].param3 = 1,
81957 + [20023].file = "drivers/media/video/gspca/gspca.c",
81958 + [20023].name = "dev_read",
81959 + [20023].param3 = 1,
81960 + [20207].file = "net/core/sock.c",
81961 + [20207].name = "sock_alloc_send_pskb",
81962 + [20207].param2 = 1,
81963 + [20263].file = "kernel/trace/trace_events.c",
81964 + [20263].name = "event_filter_write",
81965 + [20263].param3 = 1,
81966 + [20314].file = "drivers/gpu/drm/drm_hashtab.c",
81967 + [20314].name = "drm_ht_create",
81968 + [20314].param2 = 1,
81969 + [20320].file = "drivers/mfd/sm501.c",
81970 + [20320].name = "sm501_create_subdev",
81971 + [20320].param3 = 1,
81972 + [20320].param4 = 1,
81973 + [20376].file = "mm/nobootmem.c",
81974 + [20376].name = "__alloc_bootmem_nopanic",
81975 + [20376].param1 = 1,
81976 + [20409].file = "drivers/media/dvb/dvb-usb/opera1.c",
81977 + [20409].name = "opera1_usb_i2c_msgxfer",
81978 + [20409].param4 = 1,
81979 + [20473].file = "drivers/mtd/mtdchar.c",
81980 + [20473].name = "mtdchar_write",
81981 + [20473].param3 = 1,
81982 + [20611].file = "net/netfilter/x_tables.c",
81983 + [20611].name = "xt_alloc_table_info",
81984 + [20611].param1 = 1,
81985 + [20618].file = "drivers/staging/crystalhd/crystalhd_lnx.c",
81986 + [20618].name = "chd_dec_fetch_cdata",
81987 + [20618].param3 = 1,
81988 + [20713].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
81989 + [20713].name = "ttm_bo_io",
81990 + [20713].param5 = 1,
81991 + [20801].file = "drivers/vhost/vhost.c",
81992 + [20801].name = "vhost_add_used_n",
81993 + [20801].param3 = 1,
81994 + [20835].file = "drivers/isdn/i4l/isdn_common.c",
81995 + [20835].name = "isdn_read",
81996 + [20835].param3 = 1,
81997 + [20951].file = "crypto/rng.c",
81998 + [20951].name = "rngapi_reset",
81999 + [20951].param3 = 1,
82000 + [21125].file = "fs/gfs2/dir.c",
82001 + [21125].name = "gfs2_alloc_sort_buffer",
82002 + [21125].param1 = 1,
82003 + [21132].file = "kernel/cgroup.c",
82004 + [21132].name = "cgroup_write_X64",
82005 + [21132].param5 = 1,
82006 + [21138].file = "drivers/uio/uio.c",
82007 + [21138].name = "uio_read",
82008 + [21138].param3 = 1,
82009 + [21193].file = "net/wireless/sme.c",
82010 + [21193].name = "cfg80211_disconnected",
82011 + [21193].param4 = 1,
82012 + [21312].file = "lib/ts_kmp.c",
82013 + [21312].name = "kmp_init",
82014 + [21312].param2 = 1,
82015 + [21335].file = "net/econet/af_econet.c",
82016 + [21335].name = "econet_sendmsg",
82017 + [21335].param4 = 1,
82018 + [21406].file = "fs/libfs.c",
82019 + [21406].name = "simple_write_to_buffer",
82020 + [21406].param2 = 1,
82021 + [21406].param5 = 1,
82022 + [21451].file = "net/netfilter/ipvs/ip_vs_ctl.c",
82023 + [21451].name = "do_ip_vs_set_ctl",
82024 + [21451].param4 = 1,
82025 + [21459].file = "security/smack/smackfs.c",
82026 + [21459].name = "smk_write_doi",
82027 + [21459].param3 = 1,
82028 + [21508].file = "include/linux/usb/wusb.h",
82029 + [21508].name = "wusb_prf_64",
82030 + [21508].param7 = 1,
82031 + [21511].file = "drivers/input/ff-core.c",
82032 + [21511].name = "input_ff_create",
82033 + [21511].param2 = 1,
82034 + [21538].file = "net/bluetooth/l2cap_sock.c",
82035 + [21538].name = "l2cap_sock_setsockopt",
82036 + [21538].param5 = 1,
82037 + [21543].file = "drivers/media/video/gspca/gspca.c",
82038 + [21543].name = "frame_alloc",
82039 + [21543].param4 = 1,
82040 + [21608].file = "drivers/char/tpm/tpm.c",
82041 + [21608].name = "tpm_write",
82042 + [21608].param3 = 1,
82043 + [2160].file = "drivers/net/wireless/ray_cs.c",
82044 + [2160].name = "int_proc_write",
82045 + [2160].param3 = 1,
82046 + [21632].file = "fs/afs/cell.c",
82047 + [21632].name = "afs_cell_create",
82048 + [21632].param2 = 1,
82049 + [21679].file = "drivers/net/wireless/ath/carl9170/debug.c",
82050 + [21679].name = "carl9170_debugfs_write",
82051 + [21679].param3 = 1,
82052 + [21784].file = "crypto/ahash.c",
82053 + [21784].name = "ahash_setkey_unaligned",
82054 + [21784].param3 = 1,
82055 + [2180].file = "drivers/char/ppdev.c",
82056 + [2180].name = "pp_write",
82057 + [2180].param3 = 1,
82058 + [21810].file = "net/core/netprio_cgroup.c",
82059 + [21810].name = "extend_netdev_table",
82060 + [21810].param2 = 1,
82061 + [21906].file = "net/atm/mpc.c",
82062 + [21906].name = "copy_macs",
82063 + [21906].param4 = 1,
82064 + [21946].file = "fs/nfs/idmap.c",
82065 + [21946].name = "nfs_map_name_to_uid",
82066 + [21946].param3 = 1,
82067 + [22052].file = "drivers/net/ethernet/chelsio/cxgb3/sge.c",
82068 + [22052].name = "get_packet_pg",
82069 + [22052].param4 = 1,
82070 + [22085].file = "drivers/staging/sep/sep_driver.c",
82071 + [22085].name = "sep_lock_user_pages",
82072 + [22085].param2 = 1,
82073 + [22085].param3 = 1,
82074 + [22190].file = "drivers/char/tpm/tpm.c",
82075 + [22190].name = "tpm_read",
82076 + [22190].param3 = 1,
82077 + [22291].file = "net/core/pktgen.c",
82078 + [22291].name = "pgctrl_write",
82079 + [22291].param3 = 1,
82080 + [22439].file = "fs/afs/rxrpc.c",
82081 + [22439].name = "afs_alloc_flat_call",
82082 + [22439].param2 = 1,
82083 + [22439].param3 = 1,
82084 + [2243].file = "drivers/scsi/scsi_tgt_lib.c",
82085 + [2243].name = "scsi_tgt_kspace_exec",
82086 + [2243].param8 = 1,
82087 + [22440].file = "drivers/uwb/neh.c",
82088 + [22440].name = "uwb_rc_neh_grok_event",
82089 + [22440].param3 = 1,
82090 + [22611].file = "drivers/staging/android/logger.c",
82091 + [22611].name = "do_write_log_from_user",
82092 + [22611].param3 = 1,
82093 + [22614].file = "drivers/media/video/cx18/cx18-fileops.c",
82094 + [22614].name = "cx18_copy_buf_to_user",
82095 + [22614].param4 = 1,
82096 + [22667].file = "drivers/misc/altera-stapl/altera-jtag.c",
82097 + [22667].name = "altera_set_ir_post",
82098 + [22667].param2 = 1,
82099 + [22772].file = "drivers/target/iscsi/iscsi_target_erl1.c",
82100 + [22772].name = "iscsit_dump_data_payload",
82101 + [22772].param2 = 1,
82102 + [22777].file = "drivers/infiniband/ulp/srp/ib_srp.c",
82103 + [22777].name = "srp_alloc_iu",
82104 + [22777].param2 = 1,
82105 + [22811].file = "drivers/usb/dwc3/debugfs.c",
82106 + [22811].name = "dwc3_mode_write",
82107 + [22811].param3 = 1,
82108 + [22817].file = "drivers/media/video/usbvision/usbvision-core.c",
82109 + [22817].name = "usbvision_rvmalloc",
82110 + [22817].param1 = 1,
82111 + [22864].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82112 + [22864].name = "ath6kl_add_bss_if_needed",
82113 + [22864].param6 = 1,
82114 + [2286].file = "drivers/scsi/mvumi.c",
82115 + [2286].name = "mvumi_alloc_mem_resource",
82116 + [2286].param3 = 1,
82117 + [22904].file = "security/selinux/ss/services.c",
82118 + [22904].name = "security_context_to_sid_default",
82119 + [22904].param2 = 1,
82120 + [22932].file = "fs/compat.c",
82121 + [22932].name = "compat_sys_writev",
82122 + [22932].param3 = 1,
82123 + [2302].file = "drivers/media/video/stk-webcam.c",
82124 + [2302].name = "v4l_stk_read",
82125 + [2302].param3 = 1,
82126 + [2307].file = "drivers/pcmcia/cistpl.c",
82127 + [2307].name = "pcmcia_replace_cis",
82128 + [2307].param3 = 1,
82129 + [23117].file = "drivers/media/dvb/ttpci/av7110_av.c",
82130 + [23117].name = "dvb_audio_write",
82131 + [23117].param3 = 1,
82132 + [23220].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82133 + [23220].name = "do_dmabuf_dirty_sou",
82134 + [23220].param7 = 1,
82135 + [23232].file = "drivers/md/persistent-data/dm-space-map-checker.c",
82136 + [23232].name = "sm_checker_extend",
82137 + [23232].param2 = 1,
82138 + [2324].file = "net/ieee802154/wpan-class.c",
82139 + [2324].name = "wpan_phy_alloc",
82140 + [2324].param1 = 1,
82141 + [2328].file = "kernel/trace/ftrace.c",
82142 + [2328].name = "ftrace_pid_write",
82143 + [2328].param3 = 1,
82144 + [23290].file = "fs/proc/base.c",
82145 + [23290].name = "mem_rw",
82146 + [23290].param3 = 1,
82147 + [23449].file = "crypto/blkcipher.c",
82148 + [23449].name = "blkcipher_next_slow",
82149 + [23449].param3 = 1,
82150 + [23449].param4 = 1,
82151 + [23535].file = "ipc/sem.c",
82152 + [23535].name = "sys_semtimedop",
82153 + [23535].param3 = 1,
82154 + [2357].file = "drivers/usb/serial/garmin_gps.c",
82155 + [2357].name = "garmin_read_process",
82156 + [2357].param3 = 1,
82157 + [23589].file = "kernel/relay.c",
82158 + [23589].name = "subbuf_read_actor",
82159 + [23589].param3 = 1,
82160 + [23848].file = "crypto/blkcipher.c",
82161 + [23848].name = "async_setkey",
82162 + [23848].param3 = 1,
82163 + [2386].file = "drivers/acpi/acpica/exnames.c",
82164 + [2386].name = "acpi_ex_allocate_name_string",
82165 + [2386].param2 = 1,
82166 + [2389].file = "net/core/sock.c",
82167 + [2389].name = "sock_rmalloc",
82168 + [2389].param2 = 1,
82169 + [23994].file = "net/bluetooth/mgmt.c",
82170 + [23994].name = "set_powered",
82171 + [23994].param4 = 1,
82172 + [23999].file = "sound/pci/rme9652/hdsp.c",
82173 + [23999].name = "snd_hdsp_capture_copy",
82174 + [23999].param5 = 1,
82175 + [24233].file = "drivers/pci/pcie/aer/aer_inject.c",
82176 + [24233].name = "aer_inject_write",
82177 + [24233].param3 = 1,
82178 + [24359].file = "kernel/power/qos.c",
82179 + [24359].name = "pm_qos_power_write",
82180 + [24359].param3 = 1,
82181 + [24457].file = "fs/btrfs/backref.c",
82182 + [24457].name = "init_data_container",
82183 + [24457].param1 = 1,
82184 + [24719].file = "drivers/input/evdev.c",
82185 + [24719].name = "bits_to_user",
82186 + [24719].param3 = 1,
82187 + [2472].file = "net/ipv4/netfilter/ip_tables.c",
82188 + [2472].name = "compat_do_ipt_set_ctl",
82189 + [2472].param4 = 1,
82190 + [24755].file = "drivers/infiniband/hw/qib/qib_diag.c",
82191 + [24755].name = "qib_diag_write",
82192 + [24755].param3 = 1,
82193 + [24805].file = "security/keys/user_defined.c",
82194 + [24805].name = "user_update",
82195 + [24805].param3 = 1,
82196 + [25036].file = "fs/pipe.c",
82197 + [25036].name = "pipe_iov_copy_from_user",
82198 + [25036].param3 = 1,
82199 + [25078].file = "drivers/net/wireless/p54/fwio.c",
82200 + [25078].name = "p54_download_eeprom",
82201 + [25078].param4 = 1,
82202 + [25127].file = "drivers/scsi/device_handler/scsi_dh_alua.c",
82203 + [25127].name = "realloc_buffer",
82204 + [25127].param2 = 1,
82205 + [25145].file = "net/tipc/link.c",
82206 + [25145].name = "link_send_sections_long",
82207 + [25145].param4 = 1,
82208 + [25157].file = "security/keys/request_key_auth.c",
82209 + [25157].name = "request_key_auth_new",
82210 + [25157].param3 = 1,
82211 + [25158].file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
82212 + [25158].name = "mlx4_en_create_rx_ring",
82213 + [25158].param3 = 1,
82214 + [25267].file = "fs/configfs/file.c",
82215 + [25267].name = "configfs_write_file",
82216 + [25267].param3 = 1,
82217 + [25495].file = "drivers/scsi/bfa/bfad_debugfs.c",
82218 + [25495].name = "bfad_debugfs_write_regwr",
82219 + [25495].param3 = 1,
82220 + [25558].file = "fs/proc/task_mmu.c",
82221 + [25558].name = "clear_refs_write",
82222 + [25558].param3 = 1,
82223 + [25692].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
82224 + [25692].name = "ath6kl_wmi_send_action_cmd",
82225 + [25692].param7 = 1,
82226 + [25765].file = "drivers/media/dvb/b2c2/flexcop.c",
82227 + [25765].name = "flexcop_device_kmalloc",
82228 + [25765].param1 = 1,
82229 + [26100].file = "sound/core/info.c",
82230 + [26100].name = "snd_info_entry_write",
82231 + [26100].param3 = 1,
82232 + [26256].file = "fs/hpfs/name.c",
82233 + [26256].name = "hpfs_translate_name",
82234 + [26256].param3 = 1,
82235 + [26394].file = "drivers/hid/hidraw.c",
82236 + [26394].name = "hidraw_get_report",
82237 + [26394].param3 = 1,
82238 + [26494].file = "kernel/signal.c",
82239 + [26494].name = "sys_rt_sigpending",
82240 + [26494].param2 = 1,
82241 + [26497].file = "security/keys/keyctl.c",
82242 + [26497].name = "sys_keyctl",
82243 + [26497].param4 = 1,
82244 + [26533].file = "drivers/block/aoe/aoechr.c",
82245 + [26533].name = "aoechr_write",
82246 + [26533].param3 = 1,
82247 + [26560].file = "crypto/algapi.c",
82248 + [26560].name = "crypto_alloc_instance2",
82249 + [26560].param3 = 1,
82250 + [26605].file = "security/selinux/selinuxfs.c",
82251 + [26605].name = "sel_write_user",
82252 + [26605].param3 = 1,
82253 + [26620].file = "net/bluetooth/mgmt.c",
82254 + [26620].name = "mgmt_control",
82255 + [26620].param3 = 1,
82256 + [26701].file = "drivers/mtd/chips/cfi_util.c",
82257 + [26701].name = "cfi_read_pri",
82258 + [26701].param3 = 1,
82259 + [26757].file = "fs/xattr.c",
82260 + [26757].name = "sys_fgetxattr",
82261 + [26757].param4 = 1,
82262 + [2678].file = "drivers/platform/x86/asus_acpi.c",
82263 + [2678].name = "disp_proc_write",
82264 + [2678].param3 = 1,
82265 + [26834].file = "drivers/gpu/drm/drm_drv.c",
82266 + [26834].name = "drm_ioctl",
82267 + [26834].param2 = 1,
82268 + [26843].file = "drivers/firewire/core-cdev.c",
82269 + [26843].name = "fw_device_op_compat_ioctl",
82270 + [26843].param2 = 1,
82271 + [26845].file = "drivers/scsi/qla2xxx/qla_bsg.c",
82272 + [26845].name = "qla2x00_get_ctx_bsg_sp",
82273 + [26845].param3 = 1,
82274 + [26888].file = "net/bridge/br_ioctl.c",
82275 + [26888].name = "get_fdb_entries",
82276 + [26888].param3 = 1,
82277 + [26962].file = "drivers/usb/class/usbtmc.c",
82278 + [26962].name = "usbtmc_write",
82279 + [26962].param3 = 1,
82280 + [26966].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82281 + [26966].name = "ts_write",
82282 + [26966].param3 = 1,
82283 + [27004].file = "drivers/misc/hpilo.c",
82284 + [27004].name = "ilo_write",
82285 + [27004].param3 = 1,
82286 + [27025].file = "fs/ntfs/file.c",
82287 + [27025].name = "__ntfs_copy_from_user_iovec_inatomic",
82288 + [27025].param3 = 1,
82289 + [27025].param4 = 1,
82290 + [27061].file = "drivers/firewire/core-cdev.c",
82291 + [27061].name = "iso_callback",
82292 + [27061].param3 = 1,
82293 + [2711].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82294 + [2711].name = "dvb_ringbuffer_read_user",
82295 + [2711].param3 = 1,
82296 + [27129].file = "fs/lockd/mon.c",
82297 + [27129].name = "nsm_get_handle",
82298 + [27129].param4 = 1,
82299 + [27142].file = "fs/proc/kcore.c",
82300 + [27142].name = "read_kcore",
82301 + [27142].param3 = 1,
82302 + [27164].file = "include/drm/drm_mem_util.h",
82303 + [27164].name = "drm_calloc_large",
82304 + [27164].param1 = 1,
82305 + [27164].param2 = 1,
82306 + [27176].file = "drivers/mtd/devices/mtd_dataflash.c",
82307 + [27176].name = "otp_read",
82308 + [27176].param2 = 1,
82309 + [27176].param5 = 1,
82310 + [27232].file = "security/apparmor/lib.c",
82311 + [27232].name = "kvmalloc",
82312 + [27232].param1 = 1,
82313 + [27275].file = "drivers/scsi/cxgbi/libcxgbi.c",
82314 + [27275].name = "cxgbi_ddp_reserve",
82315 + [27275].param4 = 1,
82316 + [27280].file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
82317 + [27280].name = "mlx4_en_create_tx_ring",
82318 + [27280].param4 = 1,
82319 + [27290].file = "security/selinux/ss/services.c",
82320 + [27290].name = "security_context_to_sid_core",
82321 + [27290].param2 = 1,
82322 + [27302].file = "fs/proc/base.c",
82323 + [27302].name = "proc_loginuid_write",
82324 + [27302].param3 = 1,
82325 + [2730].file = "drivers/target/iscsi/iscsi_target_parameters.c",
82326 + [2730].name = "iscsi_decode_text_input",
82327 + [2730].param4 = 1,
82328 + [27314].file = "net/bluetooth/mgmt.c",
82329 + [27314].name = "cmd_complete",
82330 + [27314].param5 = 1,
82331 + [27472].file = "security/selinux/selinuxfs.c",
82332 + [27472].name = "sel_write_load",
82333 + [27472].param3 = 1,
82334 + [27491].file = "fs/proc/base.c",
82335 + [27491].name = "proc_pid_attr_write",
82336 + [27491].param3 = 1,
82337 + [27568].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
82338 + [27568].name = "t4_alloc_mem",
82339 + [27568].param1 = 1,
82340 + [27582].file = "drivers/platform/x86/asus_acpi.c",
82341 + [27582].name = "ledd_proc_write",
82342 + [27582].param3 = 1,
82343 + [27595].file = "net/core/sock.c",
82344 + [27595].name = "sock_alloc_send_skb",
82345 + [27595].param2 = 1,
82346 + [27648].file = "net/bluetooth/l2cap_core.c",
82347 + [27648].name = "l2cap_bredr_sig_cmd",
82348 + [27648].param3 = 1,
82349 + [27697].file = "drivers/staging/mei/iorw.c",
82350 + [27697].name = "amthi_read",
82351 + [27697].param4 = 1,
82352 + [27911].file = "fs/ext4/resize.c",
82353 + [27911].name = "alloc_flex_gd",
82354 + [27911].param1 = 1,
82355 + [27927].file = "drivers/tty/tty_io.c",
82356 + [27927].name = "redirected_tty_write",
82357 + [27927].param3 = 1,
82358 + [28040].file = "kernel/kfifo.c",
82359 + [28040].name = "__kfifo_alloc",
82360 + [28040].param2 = 1,
82361 + [28040].param3 = 1,
82362 + [28151].file = "mm/filemap_xip.c",
82363 + [28151].name = "do_xip_mapping_read",
82364 + [28151].param5 = 1,
82365 + [28247].file = "net/sctp/tsnmap.c",
82366 + [28247].name = "sctp_tsnmap_init",
82367 + [28247].param2 = 1,
82368 + [28253].file = "include/linux/fb.h",
82369 + [28253].name = "alloc_apertures",
82370 + [28253].param1 = 1,
82371 + [28265].file = "fs/notify/fanotify/fanotify_user.c",
82372 + [28265].name = "fanotify_write",
82373 + [28265].param3 = 1,
82374 + [28316].file = "drivers/input/joydev.c",
82375 + [28316].name = "joydev_ioctl_common",
82376 + [28316].param2 = 1,
82377 + [28359].file = "drivers/spi/spidev.c",
82378 + [28359].name = "spidev_message",
82379 + [28359].param3 = 1,
82380 + [28360].file = "drivers/hid/usbhid/hiddev.c",
82381 + [28360].name = "hiddev_compat_ioctl",
82382 + [28360].param2 = 1,
82383 + [28407].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82384 + [28407].name = "rt2x00debug_write_csr",
82385 + [28407].param3 = 1,
82386 + [2847].file = "fs/ntfs/file.c",
82387 + [2847].name = "ntfs_copy_from_user",
82388 + [2847].param3 = 1,
82389 + [2847].param5 = 1,
82390 + [28584].file = "drivers/memstick/core/memstick.c",
82391 + [28584].name = "memstick_alloc_host",
82392 + [28584].param1 = 1,
82393 + [28783].file = "drivers/gpu/drm/i915/i915_debugfs.c",
82394 + [28783].name = "i915_cache_sharing_write",
82395 + [28783].param3 = 1,
82396 + [28787].file = "drivers/media/video/videobuf2-core.c",
82397 + [28787].name = "vb2_write",
82398 + [28787].param3 = 1,
82399 + [28879].file = "drivers/base/map.c",
82400 + [28879].name = "kobj_map",
82401 + [28879].param2 = 1,
82402 + [28879].param3 = 1,
82403 + [28889].file = "drivers/char/pcmcia/cm4040_cs.c",
82404 + [28889].name = "cm4040_write",
82405 + [28889].param3 = 1,
82406 + [29073].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82407 + [29073].name = "vmw_kms_readback",
82408 + [29073].param6 = 1,
82409 + [29085].file = "security/apparmor/apparmorfs.c",
82410 + [29085].name = "profile_load",
82411 + [29085].param3 = 1,
82412 + [29092].file = "lib/lru_cache.c",
82413 + [29092].name = "lc_create",
82414 + [29092].param3 = 1,
82415 + [29257].file = "drivers/vhost/vhost.c",
82416 + [29257].name = "vhost_add_used_and_signal_n",
82417 + [29257].param4 = 1,
82418 + [29267].file = "net/ipv4/fib_trie.c",
82419 + [29267].name = "tnode_alloc",
82420 + [29267].param1 = 1,
82421 + [29338].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82422 + [29338].name = "bnad_debugfs_write_regwr",
82423 + [29338].param3 = 1,
82424 + [29353].file = "net/sctp/socket.c",
82425 + [29353].name = "sctp_setsockopt_del_key",
82426 + [29353].param3 = 1,
82427 + [29405].file = "drivers/media/dvb/dvb-usb/dw2102.c",
82428 + [29405].name = "dw210x_op_rw",
82429 + [29405].param6 = 1,
82430 + [29542].file = "net/nfc/nci/core.c",
82431 + [29542].name = "nci_send_cmd",
82432 + [29542].param3 = 1,
82433 + [29714].file = "drivers/scsi/cxgbi/libcxgbi.c",
82434 + [29714].name = "cxgbi_device_register",
82435 + [29714].param1 = 1,
82436 + [29714].param2 = 1,
82437 + [2972].file = "drivers/staging/crystalhd/crystalhd_misc.c",
82438 + [2972].name = "crystalhd_create_dio_pool",
82439 + [2972].param2 = 1,
82440 + [29769].file = "drivers/misc/iwmc3200top/log.c",
82441 + [29769].name = "store_iwmct_log_level",
82442 + [29769].param4 = 1,
82443 + [29792].file = "drivers/staging/bcm/nvm.c",
82444 + [29792].name = "BcmCopySection",
82445 + [29792].param5 = 1,
82446 + [29859].file = "net/rds/page.c",
82447 + [29859].name = "rds_page_copy_user",
82448 + [29859].param4 = 1,
82449 + [29905].file = "mm/nobootmem.c",
82450 + [29905].name = "___alloc_bootmem",
82451 + [29905].param1 = 1,
82452 + [2995].file = "mm/page_alloc.c",
82453 + [2995].name = "alloc_large_system_hash",
82454 + [2995].param2 = 1,
82455 + [30000].file = "drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c",
82456 + [30000].name = "wlc_phy_loadsampletable_nphy",
82457 + [30000].param3 = 1,
82458 + [30242].file = "fs/cifs/cifssmb.c",
82459 + [30242].name = "cifs_readdata_alloc",
82460 + [30242].param1 = 1,
82461 + [30494].file = "net/ceph/buffer.c",
82462 + [30494].name = "ceph_buffer_new",
82463 + [30494].param1 = 1,
82464 + [30590].file = "security/tomoyo/memory.c",
82465 + [30590].name = "tomoyo_commit_ok",
82466 + [30590].param2 = 1,
82467 + [3060].file = "lib/mpi/mpiutil.c",
82468 + [3060].name = "mpi_alloc_limb_space",
82469 + [3060].param1 = 1,
82470 + [30687].file = "drivers/uwb/uwb-debug.c",
82471 + [30687].name = "command_write",
82472 + [30687].param3 = 1,
82473 + [30726].file = "drivers/bluetooth/hci_vhci.c",
82474 + [30726].name = "vhci_get_user",
82475 + [30726].param3 = 1,
82476 + [30873].file = "net/packet/af_packet.c",
82477 + [30873].name = "alloc_one_pg_vec_page",
82478 + [30873].param1 = 1,
82479 + [30970].file = "drivers/staging/hv/storvsc_drv.c",
82480 + [30970].name = "create_bounce_buffer",
82481 + [30970].param3 = 1,
82482 + [310].file = "drivers/block/drbd/drbd_bitmap.c",
82483 + [310].name = "bm_realloc_pages",
82484 + [310].param2 = 1,
82485 + [3119].file = "drivers/misc/ibmasm/command.c",
82486 + [3119].name = "ibmasm_new_command",
82487 + [3119].param2 = 1,
82488 + [31207].file = "drivers/platform/x86/asus_acpi.c",
82489 + [31207].name = "parse_arg",
82490 + [31207].param2 = 1,
82491 + [31287].file = "drivers/scsi/libsrp.c",
82492 + [31287].name = "srp_iu_pool_alloc",
82493 + [31287].param2 = 1,
82494 + [31291].file = "sound/pci/rme9652/rme9652.c",
82495 + [31291].name = "snd_rme9652_capture_copy",
82496 + [31291].param5 = 1,
82497 + [31348].file = "kernel/sched/core.c",
82498 + [31348].name = "sys_sched_getaffinity",
82499 + [31348].param2 = 1,
82500 + [31492].file = "drivers/hid/hidraw.c",
82501 + [31492].name = "hidraw_read",
82502 + [31492].param3 = 1,
82503 + [3170].file = "security/integrity/ima/ima_fs.c",
82504 + [3170].name = "ima_write_policy",
82505 + [3170].param3 = 1,
82506 + [31782].file = "drivers/misc/pti.c",
82507 + [31782].name = "pti_char_write",
82508 + [31782].param3 = 1,
82509 + [31789].file = "fs/file.c",
82510 + [31789].name = "alloc_fdmem",
82511 + [31789].param1 = 1,
82512 + [31957].file = "fs/afs/proc.c",
82513 + [31957].name = "afs_proc_cells_write",
82514 + [31957].param3 = 1,
82515 + [32002].file = "net/sctp/socket.c",
82516 + [32002].name = "sctp_setsockopt_active_key",
82517 + [32002].param3 = 1,
82518 + [32182].file = "net/sunrpc/cache.c",
82519 + [32182].name = "cache_write",
82520 + [32182].param3 = 1,
82521 + [32278].file = "kernel/time/timer_stats.c",
82522 + [32278].name = "tstats_write",
82523 + [32278].param3 = 1,
82524 + [32326].file = "drivers/tty/n_r3964.c",
82525 + [32326].name = "r3964_write",
82526 + [32326].param4 = 1,
82527 + [32399].file = "drivers/net/phy/mdio_bus.c",
82528 + [32399].name = "mdiobus_alloc_size",
82529 + [32399].param1 = 1,
82530 + [32402].file = "net/ceph/pagevec.c",
82531 + [32402].name = "ceph_copy_user_to_page_vector",
82532 + [32402].param4 = 1,
82533 + [3241].file = "drivers/usb/wusbcore/crypto.c",
82534 + [3241].name = "wusb_prf",
82535 + [3241].param7 = 1,
82536 + [32459].file = "drivers/media/radio/radio-wl1273.c",
82537 + [32459].name = "wl1273_fm_fops_write",
82538 + [32459].param3 = 1,
82539 + [32531].file = "fs/bio.c",
82540 + [32531].name = "__bio_map_kern",
82541 + [32531].param2 = 1,
82542 + [32531].param3 = 1,
82543 + [32537].file = "drivers/staging/vme/devices/vme_user.c",
82544 + [32537].name = "buffer_to_user",
82545 + [32537].param3 = 1,
82546 + [32560].file = "drivers/input/input-mt.c",
82547 + [32560].name = "input_mt_init_slots",
82548 + [32560].param2 = 1,
82549 + [32600].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82550 + [32600].name = "ath6kl_set_assoc_req_ies",
82551 + [32600].param3 = 1,
82552 + [32608].file = "security/selinux/selinuxfs.c",
82553 + [32608].name = "sel_write_checkreqprot",
82554 + [32608].param3 = 1,
82555 + [32812].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
82556 + [32812].name = "__vxge_hw_channel_allocate",
82557 + [32812].param3 = 1,
82558 + [32950].file = "fs/reiserfs/resize.c",
82559 + [32950].name = "reiserfs_resize",
82560 + [32950].param2 = 1,
82561 + [33010].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82562 + [33010].name = "dvb_ringbuffer_pkt_read_user",
82563 + [33010].param5 = 1,
82564 + [33130].file = "net/llc/llc_sap.c",
82565 + [33130].name = "llc_alloc_frame",
82566 + [33130].param4 = 1,
82567 + [33221].file = "crypto/ablkcipher.c",
82568 + [33221].name = "ablkcipher_copy_iv",
82569 + [33221].param3 = 1,
82570 + [33268].file = "mm/maccess.c",
82571 + [33268].name = "__probe_kernel_write",
82572 + [33268].param3 = 1,
82573 + [33280].file = "fs/xfs/kmem.c",
82574 + [33280].name = "kmem_realloc",
82575 + [33280].param2 = 1,
82576 + [33375].file = "drivers/staging/rtl8712/osdep_service.h",
82577 + [33375].name = "_malloc",
82578 + [33375].param1 = 1,
82579 + [33420].file = "drivers/net/team/team.c",
82580 + [33420].name = "__team_options_register",
82581 + [33420].param3 = 1,
82582 + [33489].file = "fs/binfmt_misc.c",
82583 + [33489].name = "create_entry",
82584 + [33489].param2 = 1,
82585 + [33637].file = "net/9p/client.c",
82586 + [33637].name = "p9_client_read",
82587 + [33637].param5 = 1,
82588 + [33669].file = "fs/gfs2/glock.c",
82589 + [33669].name = "gfs2_glock_nq_m",
82590 + [33669].param1 = 1,
82591 + [33704].file = "drivers/gpu/drm/ttm/ttm_page_alloc_dma.c",
82592 + [33704].name = "ttm_dma_page_pool_free",
82593 + [33704].param2 = 1,
82594 + [33779].file = "drivers/staging/vme/devices/vme_user.c",
82595 + [33779].name = "resource_from_user",
82596 + [33779].param3 = 1,
82597 + [33810].file = "net/mac80211/util.c",
82598 + [33810].name = "ieee80211_send_probe_req",
82599 + [33810].param6 = 1,
82600 + [3384].file = "drivers/block/paride/pg.c",
82601 + [3384].name = "pg_write",
82602 + [3384].param3 = 1,
82603 + [34105].file = "fs/libfs.c",
82604 + [34105].name = "simple_read_from_buffer",
82605 + [34105].param2 = 1,
82606 + [34105].param5 = 1,
82607 + [34120].file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
82608 + [34120].name = "pvr2_stream_buffer_count",
82609 + [34120].param2 = 1,
82610 + [34226].file = "mm/shmem.c",
82611 + [34226].name = "shmem_xattr_set",
82612 + [34226].param4 = 1,
82613 + [34251].file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
82614 + [34251].name = "OS_kmalloc",
82615 + [34251].param1 = 1,
82616 + [34276].file = "drivers/media/video/videobuf2-core.c",
82617 + [34276].name = "__vb2_perform_fileio",
82618 + [34276].param3 = 1,
82619 + [34278].file = "fs/ubifs/debug.c",
82620 + [34278].name = "dfs_global_file_write",
82621 + [34278].param3 = 1,
82622 + [34432].file = "drivers/edac/edac_pci.c",
82623 + [34432].name = "edac_pci_alloc_ctl_info",
82624 + [34432].param1 = 1,
82625 + [34532].file = "drivers/virtio/virtio_ring.c",
82626 + [34532].name = "vring_add_indirect",
82627 + [34532].param3 = 1,
82628 + [34532].param4 = 1,
82629 + [34543].file = "net/sctp/tsnmap.c",
82630 + [34543].name = "sctp_tsnmap_grow",
82631 + [34543].param2 = 1,
82632 + [34551].file = "fs/ocfs2/stack_user.c",
82633 + [34551].name = "ocfs2_control_cfu",
82634 + [34551].param2 = 1,
82635 + [34634].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82636 + [34634].name = "ath6kl_send_go_probe_resp",
82637 + [34634].param3 = 1,
82638 + [34666].file = "fs/cifs/cifs_debug.c",
82639 + [34666].name = "cifs_security_flags_proc_write",
82640 + [34666].param3 = 1,
82641 + [3466].file = "drivers/misc/altera-stapl/altera-jtag.c",
82642 + [3466].name = "altera_drscan",
82643 + [3466].param2 = 1,
82644 + [34672].file = "drivers/tty/tty_io.c",
82645 + [34672].name = "tty_write",
82646 + [34672].param3 = 1,
82647 + [34679].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82648 + [34679].name = "ivtv_copy_buf_to_user",
82649 + [34679].param4 = 1,
82650 + [34721].file = "drivers/usb/host/hwa-hc.c",
82651 + [34721].name = "__hwahc_dev_set_key",
82652 + [34721].param5 = 1,
82653 + [34749].file = "mm/nobootmem.c",
82654 + [34749].name = "__alloc_bootmem_low_node",
82655 + [34749].param2 = 1,
82656 + [34760].file = "include/acpi/platform/aclinux.h",
82657 + [34760].name = "acpi_os_allocate_zeroed",
82658 + [34760].param1 = 1,
82659 + [34802].file = "drivers/scsi/cxgbi/libcxgbi.h",
82660 + [34802].name = "cxgbi_alloc_big_mem",
82661 + [34802].param1 = 1,
82662 + [34863].file = "drivers/video/fbsysfs.c",
82663 + [34863].name = "framebuffer_alloc",
82664 + [34863].param1 = 1,
82665 + [34868].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
82666 + [34868].name = "bnad_debugfs_write_regrd",
82667 + [34868].param3 = 1,
82668 + [34882].file = "drivers/platform/x86/toshiba_acpi.c",
82669 + [34882].name = "video_proc_write",
82670 + [34882].param3 = 1,
82671 + [35050].file = "fs/ocfs2/dlmfs/dlmfs.c",
82672 + [35050].name = "dlmfs_file_write",
82673 + [35050].param3 = 1,
82674 + [35119].file = "fs/xattr.c",
82675 + [35119].name = "sys_llistxattr",
82676 + [35119].param3 = 1,
82677 + [35129].file = "mm/nobootmem.c",
82678 + [35129].name = "___alloc_bootmem_nopanic",
82679 + [35129].param1 = 1,
82680 + [35159].file = "drivers/net/wimax/i2400m/usb.c",
82681 + [35159].name = "__i2400mu_send_barker",
82682 + [35159].param3 = 1,
82683 + [35232].file = "drivers/media/video/cx18/cx18-fileops.c",
82684 + [35232].name = "cx18_read",
82685 + [35232].param3 = 1,
82686 + [35234].file = "net/irda/irnet/irnet_ppp.c",
82687 + [35234].name = "irnet_ctrl_write",
82688 + [35234].param3 = 1,
82689 + [35256].file = "sound/core/memory.c",
82690 + [35256].name = "copy_from_user_toio",
82691 + [35256].param3 = 1,
82692 + [35268].file = "security/keys/request_key_auth.c",
82693 + [35268].name = "request_key_auth_read",
82694 + [35268].param3 = 1,
82695 + [3538].file = "net/bluetooth/mgmt.c",
82696 + [3538].name = "disconnect",
82697 + [3538].param4 = 1,
82698 + [35443].file = "sound/core/pcm_memory.c",
82699 + [35443].name = "_snd_pcm_lib_alloc_vmalloc_buffer",
82700 + [35443].param2 = 1,
82701 + [35468].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82702 + [35468].name = "xenbus_file_write",
82703 + [35468].param3 = 1,
82704 + [35536].file = "kernel/sysctl_binary.c",
82705 + [35536].name = "bin_uuid",
82706 + [35536].param3 = 1,
82707 + [35551].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82708 + [35551].name = "ivtv_read_pos",
82709 + [35551].param3 = 1,
82710 + [35556].file = "fs/read_write.c",
82711 + [35556].name = "sys_readv",
82712 + [35556].param3 = 1,
82713 + [35693].file = "drivers/staging/mei/main.c",
82714 + [35693].name = "mei_read",
82715 + [35693].param3 = 1,
82716 + [35703].file = "crypto/ablkcipher.c",
82717 + [35703].name = "ablkcipher_next_slow",
82718 + [35703].param3 = 1,
82719 + [35703].param4 = 1,
82720 + [35729].file = "include/linux/skbuff.h",
82721 + [35729].name = "__dev_alloc_skb",
82722 + [35729].param1 = 1,
82723 + [35731].file = "drivers/usb/class/cdc-wdm.c",
82724 + [35731].name = "wdm_read",
82725 + [35731].param3 = 1,
82726 + [35796].file = "drivers/mtd/nand/nand_bch.c",
82727 + [35796].name = "nand_bch_init",
82728 + [35796].param2 = 1,
82729 + [35796].param3 = 1,
82730 + [35880].file = "fs/ecryptfs/crypto.c",
82731 + [35880].name = "ecryptfs_encrypt_and_encode_filename",
82732 + [35880].param6 = 1,
82733 + [36076].file = "drivers/net/ethernet/sfc/tx.c",
82734 + [36076].name = "efx_tsoh_heap_alloc",
82735 + [36076].param2 = 1,
82736 + [36080].file = "drivers/media/video/v4l2-ioctl.c",
82737 + [36080].name = "video_usercopy",
82738 + [36080].param2 = 1,
82739 + [36149].file = "fs/udf/inode.c",
82740 + [36149].name = "udf_alloc_i_data",
82741 + [36149].param2 = 1,
82742 + [36183].file = "drivers/tty/vt/vc_screen.c",
82743 + [36183].name = "vcs_read",
82744 + [36183].param3 = 1,
82745 + [36199].file = "net/sunrpc/auth_gss/auth_gss.c",
82746 + [36199].name = "gss_pipe_downcall",
82747 + [36199].param3 = 1,
82748 + [36206].file = "net/ipv4/tcp_input.c",
82749 + [36206].name = "tcp_collapse",
82750 + [36206].param5 = 1,
82751 + [36206].param6 = 1,
82752 + [36230].file = "drivers/net/wan/hdlc_ppp.c",
82753 + [36230].name = "ppp_cp_parse_cr",
82754 + [36230].param4 = 1,
82755 + [36284].file = "drivers/spi/spi.c",
82756 + [36284].name = "spi_register_board_info",
82757 + [36284].param2 = 1,
82758 + [36490].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
82759 + [36490].name = "ath6kl_cfg80211_connect_event",
82760 + [36490].param7 = 1,
82761 + [36522].file = "drivers/hid/hidraw.c",
82762 + [36522].name = "hidraw_send_report",
82763 + [36522].param3 = 1,
82764 + [36560].file = "net/sunrpc/cache.c",
82765 + [36560].name = "write_flush",
82766 + [36560].param3 = 1,
82767 + [36807].file = "drivers/usb/mon/mon_bin.c",
82768 + [36807].name = "mon_bin_get_event",
82769 + [36807].param4 = 1,
82770 + [37034].file = "fs/cifs/cifssmb.c",
82771 + [37034].name = "cifs_writedata_alloc",
82772 + [37034].param1 = 1,
82773 + [37044].file = "sound/firewire/packets-buffer.c",
82774 + [37044].name = "iso_packets_buffer_init",
82775 + [37044].param3 = 1,
82776 + [37108].file = "drivers/media/dvb/ttpci/av7110_av.c",
82777 + [37108].name = "dvb_video_write",
82778 + [37108].param3 = 1,
82779 + [37154].file = "net/nfc/llcp/commands.c",
82780 + [37154].name = "nfc_llcp_build_tlv",
82781 + [37154].param3 = 1,
82782 + [37163].file = "net/core/skbuff.c",
82783 + [37163].name = "__netdev_alloc_skb",
82784 + [37163].param2 = 1,
82785 + [37233].file = "fs/ocfs2/cluster/tcp.c",
82786 + [37233].name = "o2net_send_message_vec",
82787 + [37233].param4 = 1,
82788 + [37241].file = "net/atm/lec.c",
82789 + [37241].name = "lane2_associate_req",
82790 + [37241].param4 = 1,
82791 + [37384].file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
82792 + [37384].name = "vmw_fifo_reserve",
82793 + [37384].param2 = 1,
82794 + [37497].file = "net/mac80211/util.c",
82795 + [37497].name = "ieee80211_build_probe_req",
82796 + [37497].param7 = 1,
82797 + [37535].file = "kernel/trace/trace.c",
82798 + [37535].name = "tracing_trace_options_write",
82799 + [37535].param3 = 1,
82800 + [37611].file = "drivers/xen/xenbus/xenbus_xs.c",
82801 + [37611].name = "split",
82802 + [37611].param2 = 1,
82803 + [37661].file = "mm/filemap.c",
82804 + [37661].name = "file_read_actor",
82805 + [37661].param4 = 1,
82806 + [37852].file = "drivers/staging/android/logger.c",
82807 + [37852].name = "do_read_log_to_user",
82808 + [37852].param4 = 1,
82809 + [37921].file = "drivers/net/wireless/wl12xx/rx.c",
82810 + [37921].name = "wl1271_rx_handle_data",
82811 + [37921].param3 = 1,
82812 + [37976].file = "drivers/platform/x86/asus_acpi.c",
82813 + [37976].name = "bluetooth_proc_write",
82814 + [37976].param3 = 1,
82815 + [3797].file = "sound/pci/asihpi/hpicmn.c",
82816 + [3797].name = "hpi_alloc_control_cache",
82817 + [3797].param1 = 1,
82818 + [3801].file = "drivers/block/paride/pt.c",
82819 + [3801].name = "pt_write",
82820 + [3801].param3 = 1,
82821 + [38052].file = "kernel/kexec.c",
82822 + [38052].name = "kimage_normal_alloc",
82823 + [38052].param3 = 1,
82824 + [38057].file = "fs/coda/psdev.c",
82825 + [38057].name = "coda_psdev_write",
82826 + [38057].param3 = 1,
82827 + [38186].file = "kernel/signal.c",
82828 + [38186].name = "do_sigpending",
82829 + [38186].param2 = 1,
82830 + [38314].file = "fs/nfs/read.c",
82831 + [38314].name = "nfs_readdata_alloc",
82832 + [38314].param1 = 1,
82833 + [38401].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
82834 + [38401].name = "queue_reply",
82835 + [38401].param3 = 1,
82836 + [3841].file = "drivers/platform/x86/asus_acpi.c",
82837 + [3841].name = "write_led",
82838 + [3841].param2 = 1,
82839 + [38532].file = "fs/afs/cell.c",
82840 + [38532].name = "afs_cell_lookup",
82841 + [38532].param2 = 1,
82842 + [38564].file = "fs/nfs/nfs4proc.c",
82843 + [38564].name = "nfs4_realloc_slot_table",
82844 + [38564].param2 = 1,
82845 + [38576].file = "drivers/i2c/i2c-dev.c",
82846 + [38576].name = "i2cdev_read",
82847 + [38576].param3 = 1,
82848 + [38704].file = "drivers/media/video/uvc/uvc_driver.c",
82849 + [38704].name = "uvc_alloc_entity",
82850 + [38704].param3 = 1,
82851 + [38704].param4 = 1,
82852 + [38747].file = "fs/xattr.c",
82853 + [38747].name = "sys_lgetxattr",
82854 + [38747].param4 = 1,
82855 + [38867].file = "drivers/scsi/scsi_transport_fc.c",
82856 + [38867].name = "fc_host_post_vendor_event",
82857 + [38867].param3 = 1,
82858 + [38931].file = "drivers/isdn/hardware/eicon/capimain.c",
82859 + [38931].name = "diva_os_alloc_message_buffer",
82860 + [38931].param1 = 1,
82861 + [38972].file = "security/smack/smackfs.c",
82862 + [38972].name = "smk_write_logging",
82863 + [38972].param3 = 1,
82864 + [39001].file = "net/xfrm/xfrm_hash.c",
82865 + [39001].name = "xfrm_hash_alloc",
82866 + [39001].param1 = 1,
82867 + [39052].file = "drivers/input/evdev.c",
82868 + [39052].name = "evdev_ioctl",
82869 + [39052].param2 = 1,
82870 + [39066].file = "drivers/media/dvb/frontends/tda10048.c",
82871 + [39066].name = "tda10048_writeregbulk",
82872 + [39066].param4 = 1,
82873 + [39118].file = "drivers/misc/iwmc3200top/log.c",
82874 + [39118].name = "store_iwmct_log_level_fw",
82875 + [39118].param4 = 1,
82876 + [39254].file = "drivers/char/pcmcia/cm4000_cs.c",
82877 + [39254].name = "cmm_write",
82878 + [39254].param3 = 1,
82879 + [39392].file = "drivers/atm/solos-pci.c",
82880 + [39392].name = "send_command",
82881 + [39392].param4 = 1,
82882 + [39415].file = "fs/pstore/inode.c",
82883 + [39415].name = "pstore_mkfile",
82884 + [39415].param5 = 1,
82885 + [39417].file = "drivers/block/DAC960.c",
82886 + [39417].name = "dac960_user_command_proc_write",
82887 + [39417].param3 = 1,
82888 + [39460].file = "fs/btrfs/volumes.c",
82889 + [39460].name = "btrfs_map_block",
82890 + [39460].param3 = 1,
82891 + [39479].file = "drivers/ide/ide-tape.c",
82892 + [39479].name = "idetape_chrdev_read",
82893 + [39479].param3 = 1,
82894 + [39586].file = "drivers/hv/channel.c",
82895 + [39586].name = "create_gpadl_header",
82896 + [39586].param2 = 1,
82897 + [39638].file = "security/selinux/selinuxfs.c",
82898 + [39638].name = "sel_write_avc_cache_threshold",
82899 + [39638].param3 = 1,
82900 + [39645].file = "drivers/media/dvb/dvb-core/dvbdev.c",
82901 + [39645].name = "dvb_generic_ioctl",
82902 + [39645].param2 = 1,
82903 + [39770].file = "include/linux/mISDNif.h",
82904 + [39770].name = "mI_alloc_skb",
82905 + [39770].param1 = 1,
82906 + [39813].file = "fs/ocfs2/stack_user.c",
82907 + [39813].name = "ocfs2_control_message",
82908 + [39813].param3 = 1,
82909 + [39888].file = "net/core/skbuff.c",
82910 + [39888].name = "__alloc_skb",
82911 + [39888].param1 = 1,
82912 + [39980].file = "net/bluetooth/mgmt.c",
82913 + [39980].name = "pair_device",
82914 + [39980].param4 = 1,
82915 + [40043].file = "drivers/media/video/v4l2-ioctl.c",
82916 + [40043].name = "video_ioctl2",
82917 + [40043].param2 = 1,
82918 + [40049].file = "drivers/bluetooth/btmrvl_debugfs.c",
82919 + [40049].name = "btmrvl_psmode_write",
82920 + [40049].param3 = 1,
82921 + [40075].file = "drivers/media/video/c-qcam.c",
82922 + [40075].name = "qc_capture",
82923 + [40075].param3 = 1,
82924 + [40163].file = "fs/ncpfs/file.c",
82925 + [40163].name = "ncp_file_write",
82926 + [40163].param3 = 1,
82927 + [40240].file = "drivers/char/nvram.c",
82928 + [40240].name = "nvram_write",
82929 + [40240].param3 = 1,
82930 + [40256].file = "drivers/tty/vt/vc_screen.c",
82931 + [40256].name = "vcs_write",
82932 + [40256].param3 = 1,
82933 + [40302].file = "sound/isa/gus/gus_dram.c",
82934 + [40302].name = "snd_gus_dram_poke",
82935 + [40302].param4 = 1,
82936 + [40339].file = "drivers/acpi/apei/hest.c",
82937 + [40339].name = "hest_ghes_dev_register",
82938 + [40339].param1 = 1,
82939 + [40355].file = "drivers/staging/mei/main.c",
82940 + [40355].name = "mei_write",
82941 + [40355].param3 = 1,
82942 + [40373].file = "fs/cifs/cifs_spnego.c",
82943 + [40373].name = "cifs_spnego_key_instantiate",
82944 + [40373].param3 = 1,
82945 + [40519].file = "net/sctp/socket.c",
82946 + [40519].name = "sctp_setsockopt_events",
82947 + [40519].param3 = 1,
82948 + [40694].file = "mm/page_cgroup.c",
82949 + [40694].name = "alloc_page_cgroup",
82950 + [40694].param1 = 1,
82951 + [40731].file = "drivers/tty/tty_io.c",
82952 + [40731].name = "do_tty_write",
82953 + [40731].param5 = 1,
82954 + [40754].file = "fs/btrfs/delayed-inode.c",
82955 + [40754].name = "btrfs_alloc_delayed_item",
82956 + [40754].param1 = 1,
82957 + [40786].file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
82958 + [40786].name = "asn1_octets_decode",
82959 + [40786].param2 = 1,
82960 + [40901].file = "drivers/block/drbd/drbd_bitmap.c",
82961 + [40901].name = "drbd_bm_resize",
82962 + [40901].param2 = 1,
82963 + [40951].file = "drivers/xen/evtchn.c",
82964 + [40951].name = "evtchn_read",
82965 + [40951].param3 = 1,
82966 + [40952].file = "drivers/misc/sgi-xp/xpc_partition.c",
82967 + [40952].name = "xpc_kmalloc_cacheline_aligned",
82968 + [40952].param1 = 1,
82969 + [41000].file = "sound/core/pcm_native.c",
82970 + [41000].name = "snd_pcm_aio_read",
82971 + [41000].param3 = 1,
82972 + [41005].file = "net/bridge/netfilter/ebtables.c",
82973 + [41005].name = "copy_counters_to_user",
82974 + [41005].param5 = 1,
82975 + [41041].file = "net/core/sock.c",
82976 + [41041].name = "sock_wmalloc",
82977 + [41041].param2 = 1,
82978 + [41122].file = "fs/binfmt_misc.c",
82979 + [41122].name = "bm_status_write",
82980 + [41122].param3 = 1,
82981 + [41176].file = "kernel/trace/trace_events.c",
82982 + [41176].name = "subsystem_filter_write",
82983 + [41176].param3 = 1,
82984 + [41249].file = "drivers/media/video/zr364xx.c",
82985 + [41249].name = "send_control_msg",
82986 + [41249].param6 = 1,
82987 + [41287].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
82988 + [41287].name = "vxge_os_dma_malloc_async",
82989 + [41287].param3 = 1,
82990 + [41302].file = "net/dns_resolver/dns_query.c",
82991 + [41302].name = "dns_query",
82992 + [41302].param3 = 1,
82993 + [41408].file = "mm/filemap_xip.c",
82994 + [41408].name = "__xip_file_write",
82995 + [41408].param3 = 1,
82996 + [41547].file = "net/bluetooth/smp.c",
82997 + [41547].name = "smp_build_cmd",
82998 + [41547].param3 = 1,
82999 + [4155].file = "kernel/kexec.c",
83000 + [4155].name = "do_kimage_alloc",
83001 + [4155].param3 = 1,
83002 + [41676].file = "fs/compat.c",
83003 + [41676].name = "compat_sys_preadv",
83004 + [41676].param3 = 1,
83005 + [4167].file = "drivers/media/dvb/frontends/cx24116.c",
83006 + [4167].name = "cx24116_writeregN",
83007 + [4167].param4 = 1,
83008 + [41793].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
83009 + [41793].name = "ath6kl_wmi_send_mgmt_cmd",
83010 + [41793].param7 = 1,
83011 + [41924].file = "security/keys/keyctl.c",
83012 + [41924].name = "keyctl_get_security",
83013 + [41924].param3 = 1,
83014 + [41968].file = "fs/btrfs/volumes.c",
83015 + [41968].name = "__btrfs_map_block",
83016 + [41968].param3 = 1,
83017 + [4202].file = "drivers/edac/edac_mc.c",
83018 + [4202].name = "edac_mc_alloc",
83019 + [4202].param1 = 1,
83020 + [42081].file = "net/econet/af_econet.c",
83021 + [42081].name = "aun_incoming",
83022 + [42081].param3 = 1,
83023 + [42143].file = "drivers/media/video/c-qcam.c",
83024 + [42143].name = "qcam_read",
83025 + [42143].param3 = 1,
83026 + [42206].file = "fs/quota/quota_tree.c",
83027 + [42206].name = "getdqbuf",
83028 + [42206].param1 = 1,
83029 + [42270].file = "net/wireless/scan.c",
83030 + [42270].name = "cfg80211_inform_bss_frame",
83031 + [42270].param4 = 1,
83032 + [42281].file = "include/linux/mISDNif.h",
83033 + [42281].name = "_queue_data",
83034 + [42281].param4 = 1,
83035 + [42420].file = "drivers/net/wireless/hostap/hostap_ioctl.c",
83036 + [42420].name = "prism2_set_genericelement",
83037 + [42420].param3 = 1,
83038 + [42472].file = "fs/compat.c",
83039 + [42472].name = "compat_readv",
83040 + [42472].param3 = 1,
83041 + [42473].file = "net/tipc/name_table.c",
83042 + [42473].name = "tipc_subseq_alloc",
83043 + [42473].param1 = 1,
83044 + [42562].file = "kernel/kfifo.c",
83045 + [42562].name = "__kfifo_to_user_r",
83046 + [42562].param3 = 1,
83047 + [42666].file = "drivers/pcmcia/cistpl.c",
83048 + [42666].name = "read_cis_cache",
83049 + [42666].param4 = 1,
83050 + [42714].file = "drivers/scsi/scsi_tgt_lib.c",
83051 + [42714].name = "scsi_tgt_copy_sense",
83052 + [42714].param3 = 1,
83053 + [42833].file = "kernel/trace/blktrace.c",
83054 + [42833].name = "blk_msg_write",
83055 + [42833].param3 = 1,
83056 + [42857].file = "security/selinux/selinuxfs.c",
83057 + [42857].name = "sel_write_member",
83058 + [42857].param3 = 1,
83059 + [42882].file = "security/keys/user_defined.c",
83060 + [42882].name = "user_instantiate",
83061 + [42882].param3 = 1,
83062 + [42930].file = "net/caif/cfpkt_skbuff.c",
83063 + [42930].name = "cfpkt_create_pfx",
83064 + [42930].param1 = 1,
83065 + [42930].param2 = 1,
83066 + [43023].file = "drivers/usb/misc/usblcd.c",
83067 + [43023].name = "lcd_write",
83068 + [43023].param3 = 1,
83069 + [43104].file = "drivers/mtd/devices/mtd_dataflash.c",
83070 + [43104].name = "dataflash_read_user_otp",
83071 + [43104].param3 = 1,
83072 + [43133].file = "lib/mpi/mpiutil.c",
83073 + [43133].name = "mpi_resize",
83074 + [43133].param2 = 1,
83075 + [4324].file = "drivers/video/fbmem.c",
83076 + [4324].name = "fb_read",
83077 + [4324].param3 = 1,
83078 + [43266].file = "fs/afs/cell.c",
83079 + [43266].name = "afs_cell_alloc",
83080 + [43266].param2 = 1,
83081 + [4328].file = "drivers/usb/musb/musb_debugfs.c",
83082 + [4328].name = "musb_test_mode_write",
83083 + [4328].param3 = 1,
83084 + [43380].file = "drivers/scsi/bfa/bfad_debugfs.c",
83085 + [43380].name = "bfad_debugfs_write_regrd",
83086 + [43380].param3 = 1,
83087 + [43510].file = "kernel/kexec.c",
83088 + [43510].name = "compat_sys_kexec_load",
83089 + [43510].param2 = 1,
83090 + [43540].file = "include/rdma/ib_verbs.h",
83091 + [43540].name = "ib_copy_to_udata",
83092 + [43540].param3 = 1,
83093 + [4357].file = "security/tomoyo/securityfs_if.c",
83094 + [4357].name = "tomoyo_read_self",
83095 + [4357].param3 = 1,
83096 + [43590].file = "security/smack/smackfs.c",
83097 + [43590].name = "smk_write_onlycap",
83098 + [43590].param3 = 1,
83099 + [43596].file = "drivers/usb/core/buffer.c",
83100 + [43596].name = "hcd_buffer_alloc",
83101 + [43596].param2 = 1,
83102 + [43632].file = "drivers/media/video/videobuf2-core.c",
83103 + [43632].name = "vb2_read",
83104 + [43632].param3 = 1,
83105 + [43659].file = "drivers/firmware/efivars.c",
83106 + [43659].name = "efivar_create_sysfs_entry",
83107 + [43659].param2 = 1,
83108 + [43731].file = "drivers/hid/hid-picolcd.c",
83109 + [43731].name = "picolcd_debug_eeprom_read",
83110 + [43731].param3 = 1,
83111 + [43777].file = "drivers/acpi/acpica/utobject.c",
83112 + [43777].name = "acpi_ut_create_buffer_object",
83113 + [43777].param1 = 1,
83114 + [43798].file = "net/bluetooth/mgmt.c",
83115 + [43798].name = "set_local_name",
83116 + [43798].param4 = 1,
83117 + [4380].file = "drivers/mtd/devices/mtd_dataflash.c",
83118 + [4380].name = "dataflash_read_fact_otp",
83119 + [4380].param3 = 1,
83120 + [43834].file = "security/apparmor/apparmorfs.c",
83121 + [43834].name = "profile_replace",
83122 + [43834].param3 = 1,
83123 + [43895].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
83124 + [43895].name = "ddb_output_write",
83125 + [43895].param3 = 1,
83126 + [43899].file = "drivers/media/rc/imon.c",
83127 + [43899].name = "vfd_write",
83128 + [43899].param3 = 1,
83129 + [43900].file = "drivers/scsi/cxgbi/libcxgbi.c",
83130 + [43900].name = "cxgbi_device_portmap_create",
83131 + [43900].param3 = 1,
83132 + [43922].file = "drivers/mmc/card/mmc_test.c",
83133 + [43922].name = "mmc_test_alloc_mem",
83134 + [43922].param3 = 1,
83135 + [43946].file = "drivers/net/wireless/ath/ath6kl/txrx.c",
83136 + [43946].name = "aggr_recv_addba_req_evt",
83137 + [43946].param4 = 1,
83138 + [44006].file = "mm/process_vm_access.c",
83139 + [44006].name = "process_vm_rw_pages",
83140 + [44006].param5 = 1,
83141 + [44006].param6 = 1,
83142 + [44050].file = "fs/nfs/idmap.c",
83143 + [44050].name = "nfs_map_group_to_gid",
83144 + [44050].param3 = 1,
83145 + [44125].file = "fs/ext4/super.c",
83146 + [44125].name = "ext4_kvmalloc",
83147 + [44125].param1 = 1,
83148 + [44266].file = "kernel/cgroup.c",
83149 + [44266].name = "cgroup_write_string",
83150 + [44266].param5 = 1,
83151 + [44290].file = "drivers/net/usb/dm9601.c",
83152 + [44290].name = "dm_read",
83153 + [44290].param3 = 1,
83154 + [44308].file = "crypto/af_alg.c",
83155 + [44308].name = "alg_setkey",
83156 + [44308].param3 = 1,
83157 + [44510].file = "drivers/net/ethernet/broadcom/bnx2.c",
83158 + [44510].name = "bnx2_nvram_write",
83159 + [44510].param2 = 1,
83160 + [44625].file = "net/bluetooth/mgmt.c",
83161 + [44625].name = "set_connectable",
83162 + [44625].param4 = 1,
83163 + [44642].file = "drivers/net/wireless/iwmc3200wifi/commands.c",
83164 + [44642].name = "iwm_umac_set_config_var",
83165 + [44642].param4 = 1,
83166 + [44698].file = "net/sctp/socket.c",
83167 + [44698].name = "sctp_setsockopt_context",
83168 + [44698].param3 = 1,
83169 + [4471].file = "fs/ntfs/malloc.h",
83170 + [4471].name = "__ntfs_malloc",
83171 + [4471].param1 = 1,
83172 + [44773].file = "drivers/staging/vme/devices/vme_user.c",
83173 + [44773].name = "vme_user_write",
83174 + [44773].param3 = 1,
83175 + [44825].file = "drivers/scsi/osd/osd_initiator.c",
83176 + [44825].name = "_osd_realloc_seg",
83177 + [44825].param3 = 1,
83178 + [44852].file = "net/sctp/socket.c",
83179 + [44852].name = "sctp_setsockopt_rtoinfo",
83180 + [44852].param3 = 1,
83181 + [44936].file = "drivers/md/dm-raid.c",
83182 + [44936].name = "context_alloc",
83183 + [44936].param3 = 1,
83184 + [44943].file = "mm/util.c",
83185 + [44943].name = "kmemdup",
83186 + [44943].param2 = 1,
83187 + [44946].file = "net/sctp/socket.c",
83188 + [44946].name = "sctp_setsockopt_auth_chunk",
83189 + [44946].param3 = 1,
83190 + [44990].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83191 + [44990].name = "pvr2_ioread_set_sync_key",
83192 + [44990].param3 = 1,
83193 + [45000].file = "fs/afs/proc.c",
83194 + [45000].name = "afs_proc_rootcell_write",
83195 + [45000].param3 = 1,
83196 + [45117].file = "drivers/staging/winbond/wb35reg.c",
83197 + [45117].name = "Wb35Reg_BurstWrite",
83198 + [45117].param4 = 1,
83199 + [45200].file = "drivers/scsi/scsi_proc.c",
83200 + [45200].name = "proc_scsi_write_proc",
83201 + [45200].param3 = 1,
83202 + [45217].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83203 + [45217].name = "iwl_dbgfs_debug_level_write",
83204 + [45217].param3 = 1,
83205 + [45233].file = "net/rds/info.c",
83206 + [45233].name = "rds_info_getsockopt",
83207 + [45233].param3 = 1,
83208 + [45326].file = "drivers/mtd/ubi/cdev.c",
83209 + [45326].name = "vol_cdev_read",
83210 + [45326].param3 = 1,
83211 + [45335].file = "fs/read_write.c",
83212 + [45335].name = "vfs_writev",
83213 + [45335].param3 = 1,
83214 + [45366].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
83215 + [45366].name = "init_tid_tabs",
83216 + [45366].param2 = 1,
83217 + [45366].param3 = 1,
83218 + [45366].param4 = 1,
83219 + [45534].file = "drivers/net/wireless/ath/carl9170/cmd.c",
83220 + [45534].name = "carl9170_cmd_buf",
83221 + [45534].param3 = 1,
83222 + [45576].file = "net/netfilter/xt_recent.c",
83223 + [45576].name = "recent_mt_proc_write",
83224 + [45576].param3 = 1,
83225 + [45583].file = "fs/gfs2/dir.c",
83226 + [45583].name = "leaf_dealloc",
83227 + [45583].param3 = 1,
83228 + [45586].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83229 + [45586].name = "rt2x00debug_write_bbp",
83230 + [45586].param3 = 1,
83231 + [45629].file = "lib/bch.c",
83232 + [45629].name = "bch_alloc",
83233 + [45629].param1 = 1,
83234 + [45633].file = "drivers/input/evdev.c",
83235 + [45633].name = "evdev_do_ioctl",
83236 + [45633].param2 = 1,
83237 + [45743].file = "drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c",
83238 + [45743].name = "qlcnic_alloc_msix_entries",
83239 + [45743].param2 = 1,
83240 + [45864].file = "drivers/atm/ambassador.c",
83241 + [45864].name = "create_queues",
83242 + [45864].param2 = 1,
83243 + [45864].param3 = 1,
83244 + [45930].file = "security/apparmor/apparmorfs.c",
83245 + [45930].name = "profile_remove",
83246 + [45930].param3 = 1,
83247 + [45954].file = "drivers/usb/misc/legousbtower.c",
83248 + [45954].name = "tower_write",
83249 + [45954].param3 = 1,
83250 + [46140].file = "sound/core/memalloc.c",
83251 + [46140].name = "snd_mem_proc_write",
83252 + [46140].param3 = 1,
83253 + [4616].file = "net/sunrpc/cache.c",
83254 + [4616].name = "cache_do_downcall",
83255 + [4616].param3 = 1,
83256 + [46243].file = "fs/binfmt_misc.c",
83257 + [46243].name = "bm_register_write",
83258 + [46243].param3 = 1,
83259 + [46250].file = "fs/xattr.c",
83260 + [46250].name = "sys_getxattr",
83261 + [46250].param4 = 1,
83262 + [46343].file = "fs/compat.c",
83263 + [46343].name = "compat_do_readv_writev",
83264 + [46343].param4 = 1,
83265 + [46400].file = "drivers/staging/sep/sep_driver.c",
83266 + [46400].name = "sep_prepare_input_output_dma_table",
83267 + [46400].param2 = 1,
83268 + [46400].param3 = 1,
83269 + [46400].param4 = 1,
83270 + [4644].file = "drivers/net/usb/mcs7830.c",
83271 + [4644].name = "mcs7830_get_reg",
83272 + [4644].param3 = 1,
83273 + [46605].file = "sound/core/oss/pcm_oss.c",
83274 + [46605].name = "snd_pcm_oss_sync1",
83275 + [46605].param2 = 1,
83276 + [46630].file = "net/decnet/af_decnet.c",
83277 + [46630].name = "__dn_setsockopt",
83278 + [46630].param5 = 1,
83279 + [46655].file = "drivers/media/video/hdpvr/hdpvr-video.c",
83280 + [46655].name = "hdpvr_read",
83281 + [46655].param3 = 1,
83282 + [46685].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
83283 + [46685].name = "ttm_bo_fbdev_io",
83284 + [46685].param4 = 1,
83285 + [46742].file = "drivers/scsi/st.c",
83286 + [46742].name = "sgl_map_user_pages",
83287 + [46742].param2 = 1,
83288 + [46881].file = "drivers/char/lp.c",
83289 + [46881].name = "lp_write",
83290 + [46881].param3 = 1,
83291 + [47130].file = "kernel/kfifo.c",
83292 + [47130].name = "kfifo_copy_to_user",
83293 + [47130].param3 = 1,
83294 + [47265].file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
83295 + [47265].name = "bnx2fc_cmd_mgr_alloc",
83296 + [47265].param2 = 1,
83297 + [47265].param3 = 1,
83298 + [47309].file = "drivers/scsi/aic94xx/aic94xx_init.c",
83299 + [47309].name = "asd_store_update_bios",
83300 + [47309].param4 = 1,
83301 + [47342].file = "fs/proc/base.c",
83302 + [47342].name = "sched_autogroup_write",
83303 + [47342].param3 = 1,
83304 + [47363].file = "drivers/input/evdev.c",
83305 + [47363].name = "evdev_ioctl_handler",
83306 + [47363].param2 = 1,
83307 + [47385].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83308 + [47385].name = "zd_usb_iowrite16v",
83309 + [47385].param3 = 1,
83310 + [4738].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83311 + [4738].name = "ath6kl_set_ap_probe_resp_ies",
83312 + [4738].param3 = 1,
83313 + [47393].file = "drivers/net/wireless/ath/main.c",
83314 + [47393].name = "ath_rxbuf_alloc",
83315 + [47393].param2 = 1,
83316 + [47463].file = "fs/xfs/kmem.c",
83317 + [47463].name = "kmem_zalloc",
83318 + [47463].param1 = 1,
83319 + [47474].file = "kernel/trace/trace.c",
83320 + [47474].name = "tracing_buffers_read",
83321 + [47474].param3 = 1,
83322 + [47636].file = "drivers/usb/class/usblp.c",
83323 + [47636].name = "usblp_ioctl",
83324 + [47636].param2 = 1,
83325 + [47637].file = "drivers/block/cciss.c",
83326 + [47637].name = "cciss_proc_write",
83327 + [47637].param3 = 1,
83328 + [47712].file = "net/sctp/socket.c",
83329 + [47712].name = "sctp_setsockopt_maxburst",
83330 + [47712].param3 = 1,
83331 + [47728].file = "drivers/char/agp/isoch.c",
83332 + [47728].name = "agp_3_5_isochronous_node_enable",
83333 + [47728].param3 = 1,
83334 + [4779].file = "fs/pipe.c",
83335 + [4779].name = "pipe_set_size",
83336 + [4779].param2 = 1,
83337 + [47881].file = "security/selinux/selinuxfs.c",
83338 + [47881].name = "sel_write_disable",
83339 + [47881].param3 = 1,
83340 + [48111].file = "net/wireless/sme.c",
83341 + [48111].name = "cfg80211_roamed_bss",
83342 + [48111].param4 = 1,
83343 + [48111].param6 = 1,
83344 + [48124].file = "drivers/net/wireless/iwmc3200wifi/main.c",
83345 + [48124].name = "iwm_notif_send",
83346 + [48124].param6 = 1,
83347 + [48155].file = "net/sctp/sm_make_chunk.c",
83348 + [48155].name = "sctp_make_abort_user",
83349 + [48155].param3 = 1,
83350 + [48182].file = "crypto/cryptd.c",
83351 + [48182].name = "cryptd_alloc_instance",
83352 + [48182].param2 = 1,
83353 + [48182].param3 = 1,
83354 + [48248].file = "security/keys/keyctl.c",
83355 + [48248].name = "keyctl_instantiate_key",
83356 + [48248].param3 = 1,
83357 + [4829].file = "drivers/block/floppy.c",
83358 + [4829].name = "fd_copyout",
83359 + [4829].param3 = 1,
83360 + [48632].file = "net/bluetooth/l2cap_core.c",
83361 + [48632].name = "l2cap_build_cmd",
83362 + [48632].param4 = 1,
83363 + [48642].file = "fs/hugetlbfs/inode.c",
83364 + [48642].name = "hugetlbfs_read",
83365 + [48642].param3 = 1,
83366 + [48720].file = "drivers/gpu/drm/i915/i915_debugfs.c",
83367 + [48720].name = "i915_max_freq_write",
83368 + [48720].param3 = 1,
83369 + [48768].file = "net/irda/irnet/irnet_ppp.c",
83370 + [48768].name = "dev_irnet_write",
83371 + [48768].param3 = 1,
83372 + [48818].file = "net/sunrpc/svc.c",
83373 + [48818].name = "svc_pool_map_alloc_arrays",
83374 + [48818].param2 = 1,
83375 + [48856].file = "drivers/acpi/acpica/utalloc.c",
83376 + [48856].name = "acpi_ut_initialize_buffer",
83377 + [48856].param2 = 1,
83378 + [48862].file = "net/sctp/socket.c",
83379 + [48862].name = "sctp_setsockopt_adaptation_layer",
83380 + [48862].param3 = 1,
83381 + [49126].file = "lib/prio_heap.c",
83382 + [49126].name = "heap_init",
83383 + [49126].param2 = 1,
83384 + [49143].file = "sound/core/oss/pcm_oss.c",
83385 + [49143].name = "snd_pcm_oss_write2",
83386 + [49143].param3 = 1,
83387 + [49216].file = "fs/read_write.c",
83388 + [49216].name = "do_readv_writev",
83389 + [49216].param4 = 1,
83390 + [49426].file = "net/bluetooth/l2cap_sock.c",
83391 + [49426].name = "l2cap_sock_setsockopt_old",
83392 + [49426].param4 = 1,
83393 + [49448].file = "drivers/isdn/gigaset/common.c",
83394 + [49448].name = "gigaset_initdriver",
83395 + [49448].param2 = 1,
83396 + [49494].file = "drivers/virtio/virtio_ring.c",
83397 + [49494].name = "vring_new_virtqueue",
83398 + [49494].param1 = 1,
83399 + [49499].file = "drivers/block/nvme.c",
83400 + [49499].name = "nvme_alloc_iod",
83401 + [49499].param1 = 1,
83402 + [49510].file = "net/sctp/socket.c",
83403 + [49510].name = "sctp_setsockopt_autoclose",
83404 + [49510].param3 = 1,
83405 + [4958].file = "drivers/net/wireless/p54/fwio.c",
83406 + [4958].name = "p54_alloc_skb",
83407 + [4958].param3 = 1,
83408 + [49604].file = "crypto/af_alg.c",
83409 + [49604].name = "alg_setsockopt",
83410 + [49604].param5 = 1,
83411 + [49646].file = "drivers/tty/vt/vt.c",
83412 + [49646].name = "vc_resize",
83413 + [49646].param2 = 1,
83414 + [49646].param3 = 1,
83415 + [49658].file = "drivers/net/wireless/brcm80211/brcmsmac/dma.c",
83416 + [49658].name = "dma_attach",
83417 + [49658].param6 = 1,
83418 + [49658].param7 = 1,
83419 + [49663].file = "drivers/media/video/uvc/uvc_driver.c",
83420 + [49663].name = "uvc_simplify_fraction",
83421 + [49663].param3 = 1,
83422 + [49746].file = "net/ipv4/netfilter/arp_tables.c",
83423 + [49746].name = "compat_do_arpt_set_ctl",
83424 + [49746].param4 = 1,
83425 + [49780].file = "net/mac80211/key.c",
83426 + [49780].name = "ieee80211_key_alloc",
83427 + [49780].param3 = 1,
83428 + [49805].file = "drivers/pci/pci.c",
83429 + [49805].name = "pci_add_cap_save_buffer",
83430 + [49805].param3 = 1,
83431 + [49845].file = "mm/vmalloc.c",
83432 + [49845].name = "__vmalloc_node",
83433 + [49845].param1 = 1,
83434 + [49929].file = "drivers/mtd/ubi/cdev.c",
83435 + [49929].name = "vol_cdev_direct_write",
83436 + [49929].param3 = 1,
83437 + [49935].file = "fs/xfs/kmem.c",
83438 + [49935].name = "kmem_zalloc_greedy",
83439 + [49935].param2 = 1,
83440 + [49935].param3 = 1,
83441 + [49].file = "net/atm/svc.c",
83442 + [49].name = "svc_setsockopt",
83443 + [49].param5 = 1,
83444 + [50518].file = "drivers/gpu/drm/nouveau/nouveau_gem.c",
83445 + [50518].name = "u_memcpya",
83446 + [50518].param2 = 1,
83447 + [50518].param3 = 1,
83448 + [5052].file = "drivers/char/ppdev.c",
83449 + [5052].name = "pp_read",
83450 + [5052].param3 = 1,
83451 + [50562].file = "drivers/media/video/zoran/zoran_procfs.c",
83452 + [50562].name = "zoran_write",
83453 + [50562].param3 = 1,
83454 + [50617].file = "fs/hugetlbfs/inode.c",
83455 + [50617].name = "hugetlbfs_read_actor",
83456 + [50617].param2 = 1,
83457 + [50617].param4 = 1,
83458 + [50617].param5 = 1,
83459 + [50692].file = "lib/ts_bm.c",
83460 + [50692].name = "bm_init",
83461 + [50692].param2 = 1,
83462 + [50813].file = "mm/vmalloc.c",
83463 + [50813].name = "__vmalloc_node_flags",
83464 + [50813].param1 = 1,
83465 + [5087].file = "drivers/atm/solos-pci.c",
83466 + [5087].name = "console_store",
83467 + [5087].param4 = 1,
83468 + [5102].file = "drivers/usb/misc/usbtest.c",
83469 + [5102].name = "usbtest_alloc_urb",
83470 + [5102].param3 = 1,
83471 + [5102].param5 = 1,
83472 + [51061].file = "net/bluetooth/mgmt.c",
83473 + [51061].name = "pin_code_reply",
83474 + [51061].param4 = 1,
83475 + [51139].file = "fs/pipe.c",
83476 + [51139].name = "pipe_iov_copy_to_user",
83477 + [51139].param3 = 1,
83478 + [51177].file = "net/sunrpc/xprtrdma/transport.c",
83479 + [51177].name = "xprt_rdma_allocate",
83480 + [51177].param2 = 1,
83481 + [51182].file = "drivers/misc/sgi-xp/xpc_main.c",
83482 + [51182].name = "xpc_kzalloc_cacheline_aligned",
83483 + [51182].param1 = 1,
83484 + [51250].file = "fs/read_write.c",
83485 + [51250].name = "rw_copy_check_uvector",
83486 + [51250].param3 = 1,
83487 + [51253].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83488 + [51253].name = "rt2x00debug_write_eeprom",
83489 + [51253].param3 = 1,
83490 + [51323].file = "sound/pci/ac97/ac97_pcm.c",
83491 + [51323].name = "snd_ac97_pcm_assign",
83492 + [51323].param2 = 1,
83493 + [51340].file = "drivers/usb/class/usblp.c",
83494 + [51340].name = "usblp_write",
83495 + [51340].param3 = 1,
83496 + [51499].file = "net/802/garp.c",
83497 + [51499].name = "garp_attr_create",
83498 + [51499].param3 = 1,
83499 + [51842].file = "drivers/hid/hid-core.c",
83500 + [51842].name = "hid_register_field",
83501 + [51842].param2 = 1,
83502 + [51842].param3 = 1,
83503 + [5197].file = "net/core/dev.c",
83504 + [5197].name = "dev_set_alias",
83505 + [5197].param3 = 1,
83506 + [5204].file = "drivers/media/video/usbvision/usbvision-video.c",
83507 + [5204].name = "usbvision_v4l2_read",
83508 + [5204].param3 = 1,
83509 + [5206].file = "drivers/media/dvb/ttpci/av7110_v4l.c",
83510 + [5206].name = "av7110_vbi_write",
83511 + [5206].param3 = 1,
83512 + [52086].file = "drivers/usb/image/mdc800.c",
83513 + [52086].name = "mdc800_device_read",
83514 + [52086].param3 = 1,
83515 + [52099].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
83516 + [52099].name = "do_surface_dirty_sou",
83517 + [52099].param7 = 1,
83518 + [52172].file = "drivers/pcmcia/cistpl.c",
83519 + [52172].name = "pccard_store_cis",
83520 + [52172].param6 = 1,
83521 + [52173].file = "drivers/misc/ibmasm/ibmasmfs.c",
83522 + [52173].name = "remote_settings_file_write",
83523 + [52173].param3 = 1,
83524 + [52199].file = "mm/nobootmem.c",
83525 + [52199].name = "__alloc_bootmem",
83526 + [52199].param1 = 1,
83527 + [52343].file = "drivers/usb/misc/adutux.c",
83528 + [52343].name = "adu_read",
83529 + [52343].param3 = 1,
83530 + [52401].file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
83531 + [52401].name = "r871x_set_wpa_ie",
83532 + [52401].param3 = 1,
83533 + [52699].file = "lib/ts_fsm.c",
83534 + [52699].name = "fsm_init",
83535 + [52699].param2 = 1,
83536 + [52721].file = "security/keys/encrypted-keys/encrypted.c",
83537 + [52721].name = "encrypted_instantiate",
83538 + [52721].param3 = 1,
83539 + [52902].file = "fs/xfs/kmem.h",
83540 + [52902].name = "kmem_zalloc_large",
83541 + [52902].param1 = 1,
83542 + [52950].file = "net/bluetooth/mgmt.c",
83543 + [52950].name = "set_discoverable",
83544 + [52950].param4 = 1,
83545 + [53041].file = "fs/libfs.c",
83546 + [53041].name = "simple_transaction_get",
83547 + [53041].param3 = 1,
83548 + [5313].file = "fs/gfs2/quota.c",
83549 + [5313].name = "do_sync",
83550 + [5313].param1 = 1,
83551 + [53209].file = "drivers/usb/host/ehci-sched.c",
83552 + [53209].name = "iso_sched_alloc",
83553 + [53209].param1 = 1,
83554 + [53302].file = "drivers/firewire/core-cdev.c",
83555 + [53302].name = "dispatch_ioctl",
83556 + [53302].param2 = 1,
83557 + [53355].file = "fs/ceph/dir.c",
83558 + [53355].name = "ceph_read_dir",
83559 + [53355].param3 = 1,
83560 + [53405].file = "drivers/media/video/videobuf-core.c",
83561 + [53405].name = "__videobuf_copy_to_user",
83562 + [53405].param4 = 1,
83563 + [53407].file = "net/wireless/sme.c",
83564 + [53407].name = "cfg80211_connect_result",
83565 + [53407].param4 = 1,
83566 + [53407].param6 = 1,
83567 + [53426].file = "fs/libfs.c",
83568 + [53426].name = "simple_transaction_read",
83569 + [53426].param3 = 1,
83570 + [5344].file = "security/selinux/ss/hashtab.c",
83571 + [5344].name = "hashtab_create",
83572 + [5344].param3 = 1,
83573 + [53513].file = "drivers/mmc/core/mmc_ops.c",
83574 + [53513].name = "mmc_send_bus_test",
83575 + [53513].param4 = 1,
83576 + [53626].file = "drivers/block/paride/pg.c",
83577 + [53626].name = "pg_read",
83578 + [53626].param3 = 1,
83579 + [53631].file = "mm/util.c",
83580 + [53631].name = "memdup_user",
83581 + [53631].param2 = 1,
83582 + [53674].file = "drivers/media/dvb/ttpci/av7110_ca.c",
83583 + [53674].name = "ci_ll_write",
83584 + [53674].param4 = 1,
83585 + [5389].file = "drivers/infiniband/core/uverbs_cmd.c",
83586 + [5389].name = "ib_uverbs_unmarshall_recv",
83587 + [5389].param5 = 1,
83588 + [53901].file = "net/rds/message.c",
83589 + [53901].name = "rds_message_alloc",
83590 + [53901].param1 = 1,
83591 + [53902].file = "net/sctp/socket.c",
83592 + [53902].name = "sctp_setsockopt_initmsg",
83593 + [53902].param3 = 1,
83594 + [5410].file = "kernel/kexec.c",
83595 + [5410].name = "sys_kexec_load",
83596 + [5410].param2 = 1,
83597 + [54172].file = "net/nfc/core.c",
83598 + [54172].name = "nfc_alloc_recv_skb",
83599 + [54172].param1 = 1,
83600 + [54182].file = "drivers/block/rbd.c",
83601 + [54182].name = "rbd_snap_add",
83602 + [54182].param4 = 1,
83603 + [54201].file = "drivers/platform/x86/asus_acpi.c",
83604 + [54201].name = "mled_proc_write",
83605 + [54201].param3 = 1,
83606 + [54263].file = "security/keys/trusted.c",
83607 + [54263].name = "trusted_instantiate",
83608 + [54263].param3 = 1,
83609 + [54296].file = "include/linux/mISDNif.h",
83610 + [54296].name = "_alloc_mISDN_skb",
83611 + [54296].param3 = 1,
83612 + [54298].file = "drivers/usb/wusbcore/crypto.c",
83613 + [54298].name = "wusb_ccm_mac",
83614 + [54298].param7 = 1,
83615 + [54318].file = "include/drm/drm_mem_util.h",
83616 + [54318].name = "drm_malloc_ab",
83617 + [54318].param1 = 1,
83618 + [54318].param2 = 1,
83619 + [54335].file = "drivers/md/dm-table.c",
83620 + [54335].name = "dm_vcalloc",
83621 + [54335].param1 = 1,
83622 + [54335].param2 = 1,
83623 + [54338].file = "fs/ntfs/malloc.h",
83624 + [54338].name = "ntfs_malloc_nofs",
83625 + [54338].param1 = 1,
83626 + [54339].file = "security/smack/smackfs.c",
83627 + [54339].name = "smk_write_cipso",
83628 + [54339].param3 = 1,
83629 + [54369].file = "drivers/usb/storage/realtek_cr.c",
83630 + [54369].name = "rts51x_read_mem",
83631 + [54369].param4 = 1,
83632 + [5438].file = "sound/core/memory.c",
83633 + [5438].name = "copy_to_user_fromio",
83634 + [5438].param3 = 1,
83635 + [54401].file = "lib/dynamic_debug.c",
83636 + [54401].name = "ddebug_proc_write",
83637 + [54401].param3 = 1,
83638 + [54467].file = "net/packet/af_packet.c",
83639 + [54467].name = "packet_setsockopt",
83640 + [54467].param5 = 1,
83641 + [54573].file = "ipc/sem.c",
83642 + [54573].name = "sys_semop",
83643 + [54573].param3 = 1,
83644 + [54583].file = "net/sctp/socket.c",
83645 + [54583].name = "sctp_setsockopt_peer_addr_params",
83646 + [54583].param3 = 1,
83647 + [54643].file = "drivers/isdn/hardware/eicon/divasi.c",
83648 + [54643].name = "um_idi_write",
83649 + [54643].param3 = 1,
83650 + [54657].file = "mm/migrate.c",
83651 + [54657].name = "do_pages_stat",
83652 + [54657].param2 = 1,
83653 + [54663].file = "drivers/isdn/hardware/eicon/platform.h",
83654 + [54663].name = "diva_os_malloc",
83655 + [54663].param2 = 1,
83656 + [54701].file = "drivers/misc/altera-stapl/altera-jtag.c",
83657 + [54701].name = "altera_swap_ir",
83658 + [54701].param2 = 1,
83659 + [54751].file = "drivers/infiniband/core/device.c",
83660 + [54751].name = "ib_alloc_device",
83661 + [54751].param1 = 1,
83662 + [54771].file = "drivers/isdn/mISDN/socket.c",
83663 + [54771].name = "_l2_alloc_skb",
83664 + [54771].param1 = 1,
83665 + [54777].file = "drivers/net/wireless/ath/ath6kl/debug.c",
83666 + [54777].name = "ath6kl_debug_roam_tbl_event",
83667 + [54777].param3 = 1,
83668 + [54806].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
83669 + [54806].name = "lpfc_debugfs_dif_err_write",
83670 + [54806].param3 = 1,
83671 + [5494].file = "fs/cifs/cifsacl.c",
83672 + [5494].name = "cifs_idmap_key_instantiate",
83673 + [5494].param3 = 1,
83674 + [55066].file = "net/ipv6/ipv6_sockglue.c",
83675 + [55066].name = "do_ipv6_setsockopt",
83676 + [55066].param5 = 1,
83677 + [55105].file = "drivers/base/devres.c",
83678 + [55105].name = "devres_alloc",
83679 + [55105].param2 = 1,
83680 + [55115].file = "net/sctp/probe.c",
83681 + [55115].name = "sctpprobe_read",
83682 + [55115].param3 = 1,
83683 + [55155].file = "net/bluetooth/rfcomm/sock.c",
83684 + [55155].name = "rfcomm_sock_setsockopt",
83685 + [55155].param5 = 1,
83686 + [55187].file = "security/keys/keyctl.c",
83687 + [55187].name = "keyctl_describe_key",
83688 + [55187].param3 = 1,
83689 + [55253].file = "drivers/net/wireless/ray_cs.c",
83690 + [55253].name = "ray_cs_essid_proc_write",
83691 + [55253].param3 = 1,
83692 + [55341].file = "drivers/staging/sep/sep_driver.c",
83693 + [55341].name = "sep_prepare_input_output_dma_table_in_dcb",
83694 + [55341].param4 = 1,
83695 + [55341].param5 = 1,
83696 + [55417].file = "drivers/hv/channel.c",
83697 + [55417].name = "vmbus_open",
83698 + [55417].param2 = 1,
83699 + [55417].param3 = 1,
83700 + [5548].file = "drivers/media/media-entity.c",
83701 + [5548].name = "media_entity_init",
83702 + [5548].param2 = 1,
83703 + [5548].param4 = 1,
83704 + [55546].file = "drivers/spi/spi.c",
83705 + [55546].name = "spi_alloc_master",
83706 + [55546].param2 = 1,
83707 + [55580].file = "drivers/usb/mon/mon_bin.c",
83708 + [55580].name = "copy_from_buf",
83709 + [55580].param2 = 1,
83710 + [55584].file = "drivers/tty/tty_buffer.c",
83711 + [55584].name = "tty_buffer_alloc",
83712 + [55584].param2 = 1,
83713 + [55712].file = "drivers/char/mem.c",
83714 + [55712].name = "read_zero",
83715 + [55712].param3 = 1,
83716 + [55727].file = "drivers/media/video/stk-webcam.c",
83717 + [55727].name = "stk_prepare_sio_buffers",
83718 + [55727].param2 = 1,
83719 + [55816].file = "drivers/misc/altera-stapl/altera-jtag.c",
83720 + [55816].name = "altera_set_ir_pre",
83721 + [55816].param2 = 1,
83722 + [55826].file = "drivers/infiniband/hw/ipath/ipath_file_ops.c",
83723 + [55826].name = "ipath_get_base_info",
83724 + [55826].param3 = 1,
83725 + [5586].file = "net/atm/common.c",
83726 + [5586].name = "alloc_tx",
83727 + [5586].param2 = 1,
83728 + [55978].file = "drivers/usb/misc/iowarrior.c",
83729 + [55978].name = "iowarrior_write",
83730 + [55978].param3 = 1,
83731 + [56170].file = "drivers/usb/wusbcore/wa-xfer.c",
83732 + [56170].name = "__wa_xfer_setup_segs",
83733 + [56170].param2 = 1,
83734 + [56199].file = "fs/binfmt_misc.c",
83735 + [56199].name = "parse_command",
83736 + [56199].param2 = 1,
83737 + [56218].file = "drivers/mmc/card/mmc_test.c",
83738 + [56218].name = "mtf_test_write",
83739 + [56218].param3 = 1,
83740 + [56239].file = "fs/sysfs/file.c",
83741 + [56239].name = "fill_write_buffer",
83742 + [56239].param3 = 1,
83743 + [5624].file = "drivers/net/wireless/ath/ath9k/wmi.c",
83744 + [5624].name = "ath9k_wmi_cmd",
83745 + [5624].param4 = 1,
83746 + [56416].file = "drivers/misc/lkdtm.c",
83747 + [56416].name = "do_register_entry",
83748 + [56416].param4 = 1,
83749 + [56458].file = "drivers/usb/host/hwa-hc.c",
83750 + [56458].name = "__hwahc_op_set_ptk",
83751 + [56458].param5 = 1,
83752 + [56471].file = "include/linux/slab.h",
83753 + [56471].name = "kcalloc",
83754 + [56471].param1 = 1,
83755 + [56471].param2 = 1,
83756 + [56513].file = "fs/cifs/connect.c",
83757 + [56513].name = "cifs_readv_from_socket",
83758 + [56513].param3 = 1,
83759 + [56531].file = "net/bluetooth/l2cap_core.c",
83760 + [56531].name = "l2cap_send_cmd",
83761 + [56531].param4 = 1,
83762 + [56544].file = "drivers/block/drbd/drbd_receiver.c",
83763 + [56544].name = "receive_DataRequest",
83764 + [56544].param3 = 1,
83765 + [56609].file = "lib/mpi/mpi-internal.h",
83766 + [56609].name = "RESIZE_IF_NEEDED",
83767 + [56609].param2 = 1,
83768 + [56652].file = "drivers/misc/altera-stapl/altera-jtag.c",
83769 + [56652].name = "altera_set_dr_post",
83770 + [56652].param2 = 1,
83771 + [56653].file = "net/irda/af_irda.c",
83772 + [56653].name = "irda_setsockopt",
83773 + [56653].param5 = 1,
83774 + [56672].file = "drivers/char/agp/generic.c",
83775 + [56672].name = "agp_alloc_page_array",
83776 + [56672].param1 = 1,
83777 + [56798].file = "fs/bio.c",
83778 + [56798].name = "bio_alloc_map_data",
83779 + [56798].param2 = 1,
83780 + [56843].file = "drivers/scsi/scsi_transport_iscsi.c",
83781 + [56843].name = "iscsi_recv_pdu",
83782 + [56843].param4 = 1,
83783 + [56903].file = "drivers/mtd/mtdchar.c",
83784 + [56903].name = "mtdchar_readoob",
83785 + [56903].param4 = 1,
83786 + [5699].file = "net/sctp/socket.c",
83787 + [5699].name = "sctp_setsockopt_default_send_param",
83788 + [5699].param3 = 1,
83789 + [5704].file = "drivers/mtd/mtdswap.c",
83790 + [5704].name = "mtdswap_init",
83791 + [5704].param2 = 1,
83792 + [57128].file = "drivers/pnp/pnpbios/proc.c",
83793 + [57128].name = "pnpbios_proc_write",
83794 + [57128].param3 = 1,
83795 + [57190].file = "drivers/char/agp/generic.c",
83796 + [57190].name = "agp_generic_alloc_user",
83797 + [57190].param1 = 1,
83798 + [57252].file = "drivers/media/dvb/dvb-core/dmxdev.c",
83799 + [57252].name = "dvb_dmxdev_set_buffer_size",
83800 + [57252].param2 = 1,
83801 + [57392].file = "drivers/block/aoe/aoecmd.c",
83802 + [57392].name = "new_skb",
83803 + [57392].param1 = 1,
83804 + [57471].file = "drivers/media/video/sn9c102/sn9c102_core.c",
83805 + [57471].name = "sn9c102_read",
83806 + [57471].param3 = 1,
83807 + [57547].file = "security/keys/encrypted-keys/encrypted.c",
83808 + [57547].name = "get_derived_key",
83809 + [57547].param4 = 1,
83810 + [57552].file = "net/sunrpc/cache.c",
83811 + [57552].name = "cache_slow_downcall",
83812 + [57552].param2 = 1,
83813 + [57670].file = "drivers/bluetooth/btmrvl_debugfs.c",
83814 + [57670].name = "btmrvl_pscmd_write",
83815 + [57670].param3 = 1,
83816 + [57710].file = "include/linux/usb/wusb.h",
83817 + [57710].name = "wusb_prf_256",
83818 + [57710].param7 = 1,
83819 + [57724].file = "net/bluetooth/hci_sock.c",
83820 + [57724].name = "hci_sock_setsockopt",
83821 + [57724].param5 = 1,
83822 + [57761].file = "kernel/kexec.c",
83823 + [57761].name = "kimage_crash_alloc",
83824 + [57761].param3 = 1,
83825 + [57786].file = "net/ipv6/netfilter/ip6_tables.c",
83826 + [57786].name = "compat_do_ip6t_set_ctl",
83827 + [57786].param4 = 1,
83828 + [57872].file = "fs/ceph/xattr.c",
83829 + [57872].name = "ceph_setxattr",
83830 + [57872].param4 = 1,
83831 + [57927].file = "fs/read_write.c",
83832 + [57927].name = "sys_preadv",
83833 + [57927].param3 = 1,
83834 + [58012].file = "include/net/bluetooth/bluetooth.h",
83835 + [58012].name = "bt_skb_alloc",
83836 + [58012].param1 = 1,
83837 + [58020].file = "drivers/firewire/core-cdev.c",
83838 + [58020].name = "fw_device_op_ioctl",
83839 + [58020].param2 = 1,
83840 + [58043].file = "kernel/auditfilter.c",
83841 + [58043].name = "audit_unpack_string",
83842 + [58043].param3 = 1,
83843 + [58087].file = "kernel/module.c",
83844 + [58087].name = "module_alloc_update_bounds_rw",
83845 + [58087].param1 = 1,
83846 + [58124].file = "drivers/usb/misc/usbtest.c",
83847 + [58124].name = "ctrl_out",
83848 + [58124].param3 = 1,
83849 + [58124].param5 = 1,
83850 + [58217].file = "net/sctp/socket.c",
83851 + [58217].name = "sctp_setsockopt_peer_primary_addr",
83852 + [58217].param3 = 1,
83853 + [58263].file = "security/keys/keyring.c",
83854 + [58263].name = "keyring_read",
83855 + [58263].param3 = 1,
83856 + [5830].file = "drivers/gpu/vga/vga_switcheroo.c",
83857 + [5830].name = "vga_switcheroo_debugfs_write",
83858 + [5830].param3 = 1,
83859 + [58320].file = "drivers/scsi/scsi_proc.c",
83860 + [58320].name = "proc_scsi_write",
83861 + [58320].param3 = 1,
83862 + [58344].file = "net/sunrpc/cache.c",
83863 + [58344].name = "read_flush",
83864 + [58344].param3 = 1,
83865 + [58379].file = "mm/nobootmem.c",
83866 + [58379].name = "__alloc_bootmem_node",
83867 + [58379].param2 = 1,
83868 + [58597].file = "kernel/kfifo.c",
83869 + [58597].name = "__kfifo_to_user",
83870 + [58597].param3 = 1,
83871 + [58641].file = "drivers/usb/misc/adutux.c",
83872 + [58641].name = "adu_write",
83873 + [58641].param3 = 1,
83874 + [58709].file = "fs/compat.c",
83875 + [58709].name = "compat_sys_pwritev",
83876 + [58709].param3 = 1,
83877 + [58769].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83878 + [58769].name = "zd_usb_read_fw",
83879 + [58769].param4 = 1,
83880 + [5876].file = "drivers/net/ppp/ppp_generic.c",
83881 + [5876].name = "ppp_write",
83882 + [5876].param3 = 1,
83883 + [58826].file = "net/sunrpc/xprt.c",
83884 + [58826].name = "xprt_alloc",
83885 + [58826].param2 = 1,
83886 + [58865].file = "include/linux/slub_def.h",
83887 + [58865].name = "kmalloc_order_trace",
83888 + [58865].param1 = 1,
83889 + [58867].file = "drivers/platform/x86/asus_acpi.c",
83890 + [58867].name = "wled_proc_write",
83891 + [58867].param3 = 1,
83892 + [58888].file = "fs/xattr.c",
83893 + [58888].name = "listxattr",
83894 + [58888].param3 = 1,
83895 + [58889].file = "kernel/trace/trace_kprobe.c",
83896 + [58889].name = "probes_write",
83897 + [58889].param3 = 1,
83898 + [58912].file = "drivers/lguest/core.c",
83899 + [58912].name = "__lgwrite",
83900 + [58912].param4 = 1,
83901 + [58918].file = "sound/core/pcm_native.c",
83902 + [58918].name = "snd_pcm_aio_write",
83903 + [58918].param3 = 1,
83904 + [58942].file = "drivers/block/aoe/aoedev.c",
83905 + [58942].name = "aoedev_flush",
83906 + [58942].param2 = 1,
83907 + [58958].file = "fs/fuse/control.c",
83908 + [58958].name = "fuse_conn_limit_write",
83909 + [58958].param3 = 1,
83910 + [59005].file = "drivers/staging/sep/sep_driver.c",
83911 + [59005].name = "sep_prepare_input_dma_table",
83912 + [59005].param2 = 1,
83913 + [59005].param3 = 1,
83914 + [59013].file = "fs/xfs/xfs_ioctl.c",
83915 + [59013].name = "xfs_handle_to_dentry",
83916 + [59013].param3 = 1,
83917 + [59034].file = "drivers/acpi/acpica/dsobject.c",
83918 + [59034].name = "acpi_ds_build_internal_package_obj",
83919 + [59034].param3 = 1,
83920 + [59073].file = "drivers/staging/speakup/i18n.c",
83921 + [59073].name = "msg_set",
83922 + [59073].param3 = 1,
83923 + [59074].file = "drivers/scsi/cxgbi/libcxgbi.c",
83924 + [59074].name = "ddp_make_gl",
83925 + [59074].param1 = 1,
83926 + [59297].file = "drivers/media/dvb/ttpci/av7110_av.c",
83927 + [59297].name = "dvb_play",
83928 + [59297].param3 = 1,
83929 + [59472].file = "drivers/misc/ibmasm/ibmasmfs.c",
83930 + [59472].name = "command_file_write",
83931 + [59472].param3 = 1,
83932 + [59504].file = "fs/exofs/super.c",
83933 + [59504].name = "__alloc_dev_table",
83934 + [59504].param2 = 1,
83935 + [59505].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83936 + [59505].name = "pvr2_ioread_read",
83937 + [59505].param3 = 1,
83938 + [59681].file = "fs/xfs/kmem.c",
83939 + [59681].name = "kmem_alloc",
83940 + [59681].param1 = 1,
83941 + [5968].file = "net/sunrpc/sched.c",
83942 + [5968].name = "rpc_malloc",
83943 + [5968].param2 = 1,
83944 + [59695].file = "net/ipv4/netfilter/ipt_ULOG.c",
83945 + [59695].name = "ulog_alloc_skb",
83946 + [59695].param1 = 1,
83947 + [59838].file = "net/netlink/af_netlink.c",
83948 + [59838].name = "nl_pid_hash_zalloc",
83949 + [59838].param1 = 1,
83950 + [59856].file = "drivers/base/devres.c",
83951 + [59856].name = "devm_kzalloc",
83952 + [59856].param2 = 1,
83953 + [60066].file = "mm/filemap.c",
83954 + [60066].name = "iov_iter_copy_from_user",
83955 + [60066].param4 = 1,
83956 + [60185].file = "kernel/params.c",
83957 + [60185].name = "kmalloc_parameter",
83958 + [60185].param1 = 1,
83959 + [60198].file = "fs/nfs/nfs4proc.c",
83960 + [60198].name = "nfs4_write_cached_acl",
83961 + [60198].param3 = 1,
83962 + [60330].file = "drivers/media/video/w9966.c",
83963 + [60330].name = "w9966_v4l_read",
83964 + [60330].param3 = 1,
83965 + [604].file = "drivers/staging/rtl8712/usb_ops_linux.c",
83966 + [604].name = "r8712_usbctrl_vendorreq",
83967 + [604].param6 = 1,
83968 + [60543].file = "drivers/usb/class/usbtmc.c",
83969 + [60543].name = "usbtmc_read",
83970 + [60543].param3 = 1,
83971 + [60683].file = "sound/drivers/opl4/opl4_proc.c",
83972 + [60683].name = "snd_opl4_mem_proc_write",
83973 + [60683].param5 = 1,
83974 + [60693].file = "drivers/misc/hpilo.c",
83975 + [60693].name = "ilo_read",
83976 + [60693].param3 = 1,
83977 + [60744].file = "sound/pci/emu10k1/emuproc.c",
83978 + [60744].name = "snd_emu10k1_fx8010_read",
83979 + [60744].param5 = 1,
83980 + [60777].file = "fs/ntfs/malloc.h",
83981 + [60777].name = "ntfs_malloc_nofs_nofail",
83982 + [60777].param1 = 1,
83983 + [60833].file = "drivers/block/aoe/aoenet.c",
83984 + [60833].name = "set_aoe_iflist",
83985 + [60833].param2 = 1,
83986 + [60882].file = "drivers/input/joydev.c",
83987 + [60882].name = "joydev_compat_ioctl",
83988 + [60882].param2 = 1,
83989 + [60891].file = "kernel/sched/core.c",
83990 + [60891].name = "sys_sched_setaffinity",
83991 + [60891].param2 = 1,
83992 + [60920].file = "drivers/infiniband/hw/qib/qib_file_ops.c",
83993 + [60920].name = "qib_get_base_info",
83994 + [60920].param3 = 1,
83995 + [60928].file = "drivers/staging/bcm/Bcmchar.c",
83996 + [60928].name = "bcm_char_read",
83997 + [60928].param3 = 1,
83998 + [61122].file = "drivers/base/devres.c",
83999 + [61122].name = "alloc_dr",
84000 + [61122].param2 = 1,
84001 + [61254].file = "drivers/scsi/scsi_devinfo.c",
84002 + [61254].name = "proc_scsi_devinfo_write",
84003 + [61254].param3 = 1,
84004 + [61283].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84005 + [61283].name = "ath6kl_fwlog_read",
84006 + [61283].param3 = 1,
84007 + [61289].file = "security/apparmor/apparmorfs.c",
84008 + [61289].name = "aa_simple_write_to_buffer",
84009 + [61289].param4 = 1,
84010 + [61389].file = "include/linux/slab.h",
84011 + [61389].name = "kzalloc_node",
84012 + [61389].param1 = 1,
84013 + [61441].file = "fs/ntfs/file.c",
84014 + [61441].name = "ntfs_copy_from_user_iovec",
84015 + [61441].param3 = 1,
84016 + [61441].param6 = 1,
84017 + [61552].file = "drivers/input/evdev.c",
84018 + [61552].name = "str_to_user",
84019 + [61552].param2 = 1,
84020 + [61673].file = "security/keys/trusted.c",
84021 + [61673].name = "trusted_update",
84022 + [61673].param3 = 1,
84023 + [61676].file = "kernel/module.c",
84024 + [61676].name = "module_alloc_update_bounds_rx",
84025 + [61676].param1 = 1,
84026 + [61684].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
84027 + [61684].name = "cxgb3_get_cpl_reply_skb",
84028 + [61684].param2 = 1,
84029 + [6173].file = "net/netlink/af_netlink.c",
84030 + [6173].name = "netlink_sendmsg",
84031 + [6173].param4 = 1,
84032 + [61770].file = "drivers/media/video/et61x251/et61x251_core.c",
84033 + [61770].name = "et61x251_read",
84034 + [61770].param3 = 1,
84035 + [61772].file = "fs/exofs/ore_raid.c",
84036 + [61772].name = "_sp2d_alloc",
84037 + [61772].param1 = 1,
84038 + [61772].param2 = 1,
84039 + [61772].param3 = 1,
84040 + [61926].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
84041 + [61926].name = "ddb_input_read",
84042 + [61926].param3 = 1,
84043 + [61932].file = "drivers/message/fusion/mptctl.c",
84044 + [61932].name = "__mptctl_ioctl",
84045 + [61932].param2 = 1,
84046 + [61966].file = "fs/nfs/nfs4proc.c",
84047 + [61966].name = "nfs4_alloc_slots",
84048 + [61966].param1 = 1,
84049 + [62081].file = "drivers/net/irda/vlsi_ir.c",
84050 + [62081].name = "vlsi_alloc_ring",
84051 + [62081].param3 = 1,
84052 + [62081].param4 = 1,
84053 + [62116].file = "fs/libfs.c",
84054 + [62116].name = "simple_attr_read",
84055 + [62116].param3 = 1,
84056 + [6211].file = "drivers/net/ethernet/amd/pcnet32.c",
84057 + [6211].name = "pcnet32_realloc_tx_ring",
84058 + [6211].param3 = 1,
84059 + [62294].file = "sound/core/info.c",
84060 + [62294].name = "resize_info_buffer",
84061 + [62294].param2 = 1,
84062 + [62387].file = "fs/nfs/idmap.c",
84063 + [62387].name = "nfs_idmap_lookup_id",
84064 + [62387].param2 = 1,
84065 + [62465].file = "drivers/misc/altera-stapl/altera-jtag.c",
84066 + [62465].name = "altera_set_dr_pre",
84067 + [62465].param2 = 1,
84068 + [62466].file = "lib/mpi/mpiutil.c",
84069 + [62466].name = "mpi_alloc",
84070 + [62466].param1 = 1,
84071 + [62495].file = "drivers/block/floppy.c",
84072 + [62495].name = "fallback_on_nodma_alloc",
84073 + [62495].param2 = 1,
84074 + [62498].file = "fs/xattr.c",
84075 + [62498].name = "sys_listxattr",
84076 + [62498].param3 = 1,
84077 + [625].file = "fs/read_write.c",
84078 + [625].name = "sys_pwritev",
84079 + [625].param3 = 1,
84080 + [62662].file = "drivers/message/fusion/mptctl.c",
84081 + [62662].name = "mptctl_getiocinfo",
84082 + [62662].param2 = 1,
84083 + [62669].file = "drivers/platform/x86/asus_acpi.c",
84084 + [62669].name = "tled_proc_write",
84085 + [62669].param3 = 1,
84086 + [62714].file = "security/keys/keyctl.c",
84087 + [62714].name = "keyctl_update_key",
84088 + [62714].param3 = 1,
84089 + [62760].file = "drivers/media/dvb/ttpci/av7110_av.c",
84090 + [62760].name = "play_iframe",
84091 + [62760].param3 = 1,
84092 + [62851].file = "fs/proc/vmcore.c",
84093 + [62851].name = "read_vmcore",
84094 + [62851].param3 = 1,
84095 + [62870].file = "fs/nfs/idmap.c",
84096 + [62870].name = "nfs_idmap_get_desc",
84097 + [62870].param2 = 1,
84098 + [62870].param4 = 1,
84099 + [62905].file = "net/caif/cfpkt_skbuff.c",
84100 + [62905].name = "cfpkt_create",
84101 + [62905].param1 = 1,
84102 + [62920].file = "drivers/net/wireless/b43/phy_n.c",
84103 + [62920].name = "b43_nphy_load_samples",
84104 + [62920].param3 = 1,
84105 + [62925].file = "include/rdma/ib_verbs.h",
84106 + [62925].name = "ib_copy_from_udata",
84107 + [62925].param3 = 1,
84108 + [62934].file = "drivers/net/wireless/wl1251/cmd.c",
84109 + [62934].name = "wl1251_cmd_template_set",
84110 + [62934].param4 = 1,
84111 + [62940].file = "drivers/scsi/libsrp.c",
84112 + [62940].name = "srp_ring_alloc",
84113 + [62940].param2 = 1,
84114 + [62967].file = "security/keys/encrypted-keys/encrypted.c",
84115 + [62967].name = "encrypted_update",
84116 + [62967].param3 = 1,
84117 + [62970].file = "net/sched/sch_api.c",
84118 + [62970].name = "qdisc_class_hash_alloc",
84119 + [62970].param1 = 1,
84120 + [62999].file = "net/core/neighbour.c",
84121 + [62999].name = "neigh_hash_alloc",
84122 + [62999].param1 = 1,
84123 + [63007].file = "fs/proc/base.c",
84124 + [63007].name = "proc_coredump_filter_write",
84125 + [63007].param3 = 1,
84126 + [63010].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
84127 + [63010].name = "ttm_page_pool_free",
84128 + [63010].param2 = 1,
84129 + [63045].file = "crypto/shash.c",
84130 + [63045].name = "shash_setkey_unaligned",
84131 + [63045].param3 = 1,
84132 + [63075].file = "kernel/relay.c",
84133 + [63075].name = "relay_alloc_page_array",
84134 + [63075].param1 = 1,
84135 + [63076].file = "fs/cifs/xattr.c",
84136 + [63076].name = "cifs_setxattr",
84137 + [63076].param4 = 1,
84138 + [63091].file = "drivers/net/usb/pegasus.c",
84139 + [63091].name = "get_registers",
84140 + [63091].param3 = 1,
84141 + [6331].file = "drivers/atm/solos-pci.c",
84142 + [6331].name = "solos_param_store",
84143 + [6331].param4 = 1,
84144 + [63367].file = "net/netfilter/ipset/ip_set_core.c",
84145 + [63367].name = "ip_set_alloc",
84146 + [63367].param1 = 1,
84147 + [63489].file = "drivers/bluetooth/btmrvl_debugfs.c",
84148 + [63489].name = "btmrvl_hscfgcmd_write",
84149 + [63489].param3 = 1,
84150 + [63490].file = "crypto/shash.c",
84151 + [63490].name = "shash_compat_setkey",
84152 + [63490].param3 = 1,
84153 + [63605].file = "mm/mempool.c",
84154 + [63605].name = "mempool_kmalloc",
84155 + [63605].param2 = 1,
84156 + [63633].file = "drivers/bluetooth/btmrvl_sdio.c",
84157 + [63633].name = "btmrvl_sdio_host_to_card",
84158 + [63633].param3 = 1,
84159 + [63961].file = "fs/xattr.c",
84160 + [63961].name = "sys_flistxattr",
84161 + [63961].param3 = 1,
84162 + [63964].file = "net/sctp/socket.c",
84163 + [63964].name = "sctp_setsockopt_maxseg",
84164 + [63964].param3 = 1,
84165 + [63988].file = "drivers/input/evdev.c",
84166 + [63988].name = "evdev_ioctl_compat",
84167 + [63988].param2 = 1,
84168 + [64055].file = "drivers/media/dvb/ttpci/av7110_av.c",
84169 + [64055].name = "dvb_aplay",
84170 + [64055].param3 = 1,
84171 + [64156].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84172 + [64156].name = "ath6kl_mgmt_tx",
84173 + [64156].param9 = 1,
84174 + [64226].file = "drivers/md/persistent-data/dm-space-map-checker.c",
84175 + [64226].name = "ca_extend",
84176 + [64226].param2 = 1,
84177 + [64227].file = "mm/nobootmem.c",
84178 + [64227].name = "__alloc_bootmem_node_nopanic",
84179 + [64227].param2 = 1,
84180 + [64351].file = "kernel/kfifo.c",
84181 + [64351].name = "kfifo_copy_from_user",
84182 + [64351].param3 = 1,
84183 + [64392].file = "drivers/mmc/core/mmc_ops.c",
84184 + [64392].name = "mmc_send_cxd_data",
84185 + [64392].param5 = 1,
84186 + [64423].file = "kernel/sched/core.c",
84187 + [64423].name = "get_user_cpu_mask",
84188 + [64423].param2 = 1,
84189 + [64432].file = "security/selinux/selinuxfs.c",
84190 + [64432].name = "sel_write_create",
84191 + [64432].param3 = 1,
84192 + [64471].file = "drivers/bluetooth/btmrvl_debugfs.c",
84193 + [64471].name = "btmrvl_hscmd_write",
84194 + [64471].param3 = 1,
84195 + [64667].file = "sound/core/oss/pcm_oss.c",
84196 + [64667].name = "snd_pcm_oss_read",
84197 + [64667].param3 = 1,
84198 + [64689].file = "sound/isa/gus/gus_dram.c",
84199 + [64689].name = "snd_gus_dram_read",
84200 + [64689].param4 = 1,
84201 + [64692].file = "fs/binfmt_misc.c",
84202 + [64692].name = "bm_entry_write",
84203 + [64692].param3 = 1,
84204 + [64705].file = "drivers/staging/iio/accel/sca3000_ring.c",
84205 + [64705].name = "sca3000_read_first_n_hw_rb",
84206 + [64705].param2 = 1,
84207 + [64713].file = "fs/cifs/connect.c",
84208 + [64713].name = "extract_hostname",
84209 + [64713].param1 = 1,
84210 + [64743].file = "fs/ocfs2/dlmfs/dlmfs.c",
84211 + [64743].name = "dlmfs_file_read",
84212 + [64743].param3 = 1,
84213 + [64771].file = "security/keys/encrypted-keys/encrypted.c",
84214 + [64771].name = "datablob_format",
84215 + [64771].param2 = 1,
84216 + [6477].file = "net/bluetooth/mgmt.c",
84217 + [6477].name = "mgmt_pending_add",
84218 + [6477].param5 = 1,
84219 + [64906].file = "drivers/net/wireless/b43legacy/debugfs.c",
84220 + [64906].name = "b43legacy_debugfs_write",
84221 + [64906].param3 = 1,
84222 + [64913].file = "sound/core/oss/pcm_oss.c",
84223 + [64913].name = "snd_pcm_oss_write1",
84224 + [64913].param3 = 1,
84225 + [64961].file = "drivers/spi/spidev.c",
84226 + [64961].name = "spidev_ioctl",
84227 + [64961].param2 = 1,
84228 + [65033].file = "crypto/shash.c",
84229 + [65033].name = "shash_async_setkey",
84230 + [65033].param3 = 1,
84231 + [65093].file = "security/integrity/evm/evm_secfs.c",
84232 + [65093].name = "evm_write_key",
84233 + [65093].param3 = 1,
84234 + [6514].file = "mm/nobootmem.c",
84235 + [6514].name = "__alloc_bootmem_low",
84236 + [6514].param1 = 1,
84237 + [65169].file = "net/core/skbuff.c",
84238 + [65169].name = "dev_alloc_skb",
84239 + [65169].param1 = 1,
84240 + [6517].file = "drivers/md/dm-table.c",
84241 + [6517].name = "alloc_targets",
84242 + [6517].param2 = 1,
84243 + [65205].file = "drivers/input/evdev.c",
84244 + [65205].name = "handle_eviocgbit",
84245 + [65205].param3 = 1,
84246 + [65237].file = "kernel/profile.c",
84247 + [65237].name = "read_profile",
84248 + [65237].param3 = 1,
84249 + [65343].file = "kernel/trace/trace.c",
84250 + [65343].name = "tracing_clock_write",
84251 + [65343].param3 = 1,
84252 + [65345].file = "lib/xz/xz_dec_lzma2.c",
84253 + [65345].name = "xz_dec_lzma2_create",
84254 + [65345].param2 = 1,
84255 + [65409].file = "net/802/garp.c",
84256 + [65409].name = "garp_request_join",
84257 + [65409].param4 = 1,
84258 + [65432].file = "drivers/hid/hid-roccat-kone.c",
84259 + [65432].name = "kone_receive",
84260 + [65432].param4 = 1,
84261 + [65514].file = "drivers/media/video/gspca/t613.c",
84262 + [65514].name = "reg_w_ixbuf",
84263 + [65514].param4 = 1,
84264 + [6551].file = "drivers/usb/host/xhci-mem.c",
84265 + [6551].name = "xhci_alloc_stream_info",
84266 + [6551].param3 = 1,
84267 + [65535].file = "drivers/media/dvb/dvb-usb/opera1.c",
84268 + [65535].name = "opera1_xilinx_rw",
84269 + [65535].param5 = 1,
84270 + [6672].file = "drivers/net/wireless/b43/debugfs.c",
84271 + [6672].name = "b43_debugfs_write",
84272 + [6672].param3 = 1,
84273 + [6691].file = "drivers/acpi/proc.c",
84274 + [6691].name = "acpi_system_write_wakeup_device",
84275 + [6691].param3 = 1,
84276 + [6865].file = "drivers/staging/iio/ring_sw.c",
84277 + [6865].name = "iio_read_first_n_sw_rb",
84278 + [6865].param2 = 1,
84279 + [6867].file = "fs/coda/psdev.c",
84280 + [6867].name = "coda_psdev_read",
84281 + [6867].param3 = 1,
84282 + [6891].file = "drivers/bluetooth/btmrvl_debugfs.c",
84283 + [6891].name = "btmrvl_gpiogap_write",
84284 + [6891].param3 = 1,
84285 + [6944].file = "drivers/ide/ide-proc.c",
84286 + [6944].name = "ide_settings_proc_write",
84287 + [6944].param3 = 1,
84288 + [6950].file = "drivers/isdn/capi/capi.c",
84289 + [6950].name = "capi_write",
84290 + [6950].param3 = 1,
84291 + [697].file = "sound/isa/gus/gus_dram.c",
84292 + [697].name = "snd_gus_dram_peek",
84293 + [697].param4 = 1,
84294 + [7066].file = "security/keys/keyctl.c",
84295 + [7066].name = "keyctl_instantiate_key_common",
84296 + [7066].param4 = 1,
84297 + [7125].file = "include/net/nfc/nci_core.h",
84298 + [7125].name = "nci_skb_alloc",
84299 + [7125].param2 = 1,
84300 + [7129].file = "mm/maccess.c",
84301 + [7129].name = "__probe_kernel_read",
84302 + [7129].param3 = 1,
84303 + [7158].file = "kernel/trace/trace.c",
84304 + [7158].name = "tracing_read_pipe",
84305 + [7158].param3 = 1,
84306 + [720].file = "sound/pci/rme9652/hdsp.c",
84307 + [720].name = "snd_hdsp_playback_copy",
84308 + [720].param5 = 1,
84309 + [7236].file = "drivers/gpu/drm/drm_crtc.c",
84310 + [7236].name = "drm_plane_init",
84311 + [7236].param6 = 1,
84312 + [7411].file = "drivers/vhost/vhost.c",
84313 + [7411].name = "__vhost_add_used_n",
84314 + [7411].param3 = 1,
84315 + [7432].file = "net/bluetooth/mgmt.c",
84316 + [7432].name = "mgmt_event",
84317 + [7432].param4 = 1,
84318 + [7488].file = "security/keys/user_defined.c",
84319 + [7488].name = "user_read",
84320 + [7488].param3 = 1,
84321 + [7551].file = "drivers/input/touchscreen/ad7879-spi.c",
84322 + [7551].name = "ad7879_spi_xfer",
84323 + [7551].param3 = 1,
84324 + [7671].file = "mm/nobootmem.c",
84325 + [7671].name = "__alloc_bootmem_node_high",
84326 + [7671].param2 = 1,
84327 + [7676].file = "drivers/acpi/custom_method.c",
84328 + [7676].name = "cm_write",
84329 + [7676].param3 = 1,
84330 + [7693].file = "net/sctp/socket.c",
84331 + [7693].name = "sctp_setsockopt_associnfo",
84332 + [7693].param3 = 1,
84333 + [7697].file = "security/selinux/selinuxfs.c",
84334 + [7697].name = "sel_write_access",
84335 + [7697].param3 = 1,
84336 + [7843].file = "fs/compat.c",
84337 + [7843].name = "compat_sys_readv",
84338 + [7843].param3 = 1,
84339 + [7883].file = "net/sched/sch_sfq.c",
84340 + [7883].name = "sfq_alloc",
84341 + [7883].param1 = 1,
84342 + [7924].file = "drivers/media/video/cx18/cx18-fileops.c",
84343 + [7924].name = "cx18_read_pos",
84344 + [7924].param3 = 1,
84345 + [7958].file = "drivers/gpu/vga/vgaarb.c",
84346 + [7958].name = "vga_arb_write",
84347 + [7958].param3 = 1,
84348 + [7976].file = "drivers/usb/gadget/rndis.c",
84349 + [7976].name = "rndis_add_response",
84350 + [7976].param2 = 1,
84351 + [7985].file = "net/mac80211/cfg.c",
84352 + [7985].name = "ieee80211_mgmt_tx",
84353 + [7985].param9 = 1,
84354 + [8014].file = "net/netfilter/ipset/ip_set_list_set.c",
84355 + [8014].name = "init_list_set",
84356 + [8014].param2 = 1,
84357 + [8014].param3 = 1,
84358 + [8126].file = "sound/soc/soc-core.c",
84359 + [8126].name = "codec_reg_read_file",
84360 + [8126].param3 = 1,
84361 + [8317].file = "security/smack/smackfs.c",
84362 + [8317].name = "smk_write_ambient",
84363 + [8317].param3 = 1,
84364 + [8335].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84365 + [8335].name = "dvb_dvr_set_buffer_size",
84366 + [8335].param2 = 1,
84367 + [8383].file = "kernel/module.c",
84368 + [8383].name = "copy_and_check",
84369 + [8383].param3 = 1,
84370 + [8411].file = "net/caif/cfpkt_skbuff.c",
84371 + [8411].name = "cfpkt_append",
84372 + [8411].param3 = 1,
84373 + [8536].file = "fs/cifs/dns_resolve.c",
84374 + [8536].name = "dns_resolve_server_name_to_ip",
84375 + [8536].param1 = 1,
84376 + [857].file = "drivers/virtio/virtio_ring.c",
84377 + [857].name = "virtqueue_add_buf",
84378 + [857].param3 = 1,
84379 + [857].param4 = 1,
84380 + [8650].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
84381 + [8650].name = "vmw_kms_present",
84382 + [8650].param9 = 1,
84383 + [8654].file = "drivers/net/wireless/mwifiex/sdio.c",
84384 + [8654].name = "mwifiex_alloc_sdio_mpa_buffers",
84385 + [8654].param2 = 1,
84386 + [8654].param3 = 1,
84387 + [865].file = "drivers/base/regmap/regmap-debugfs.c",
84388 + [865].name = "regmap_access_read_file",
84389 + [865].param3 = 1,
84390 + [8663].file = "net/bridge/netfilter/ebtables.c",
84391 + [8663].name = "do_update_counters",
84392 + [8663].param4 = 1,
84393 + [8684].file = "fs/read_write.c",
84394 + [8684].name = "sys_writev",
84395 + [8684].param3 = 1,
84396 + [8699].file = "security/selinux/selinuxfs.c",
84397 + [8699].name = "sel_commit_bools_write",
84398 + [8699].param3 = 1,
84399 + [8764].file = "drivers/usb/core/devio.c",
84400 + [8764].name = "usbdev_read",
84401 + [8764].param3 = 1,
84402 + [8802].file = "fs/dlm/user.c",
84403 + [8802].name = "device_write",
84404 + [8802].param3 = 1,
84405 + [8810].file = "net/mac80211/debugfs_sta.c",
84406 + [8810].name = "sta_agg_status_write",
84407 + [8810].param3 = 1,
84408 + [8815].file = "security/tomoyo/securityfs_if.c",
84409 + [8815].name = "tomoyo_write_self",
84410 + [8815].param3 = 1,
84411 + [8821].file = "net/wireless/sme.c",
84412 + [8821].name = "cfg80211_roamed",
84413 + [8821].param5 = 1,
84414 + [8821].param7 = 1,
84415 + [8833].file = "security/selinux/ss/services.c",
84416 + [8833].name = "security_context_to_sid",
84417 + [8833].param2 = 1,
84418 + [8838].file = "lib/mpi/mpi-bit.c",
84419 + [8838].name = "mpi_lshift_limbs",
84420 + [8838].param2 = 1,
84421 + [8851].file = "net/key/af_key.c",
84422 + [8851].name = "pfkey_sendmsg",
84423 + [8851].param4 = 1,
84424 + [8917].file = "net/can/raw.c",
84425 + [8917].name = "raw_setsockopt",
84426 + [8917].param5 = 1,
84427 + [8983].file = "include/linux/skbuff.h",
84428 + [8983].name = "alloc_skb",
84429 + [8983].param1 = 1,
84430 + [9117].file = "drivers/base/regmap/regcache-rbtree.c",
84431 + [9117].name = "regcache_rbtree_insert_to_block",
84432 + [9117].param5 = 1,
84433 + [9226].file = "mm/migrate.c",
84434 + [9226].name = "sys_move_pages",
84435 + [9226].param2 = 1,
84436 + [9304].file = "kernel/auditfilter.c",
84437 + [9304].name = "audit_init_entry",
84438 + [9304].param1 = 1,
84439 + [9317].file = "drivers/usb/wusbcore/wa-nep.c",
84440 + [9317].name = "wa_nep_queue",
84441 + [9317].param2 = 1,
84442 + [9341].file = "drivers/acpi/apei/erst-dbg.c",
84443 + [9341].name = "erst_dbg_write",
84444 + [9341].param3 = 1,
84445 + [9386].file = "fs/exofs/ore.c",
84446 + [9386].name = "_ore_get_io_state",
84447 + [9386].param3 = 1,
84448 + [9386].param4 = 1,
84449 + [9386].param5 = 1,
84450 + [9538].file = "crypto/blkcipher.c",
84451 + [9538].name = "blkcipher_copy_iv",
84452 + [9538].param3 = 1,
84453 + [9546].file = "drivers/video/fbmem.c",
84454 + [9546].name = "fb_write",
84455 + [9546].param3 = 1,
84456 + [9601].file = "kernel/kfifo.c",
84457 + [9601].name = "__kfifo_from_user",
84458 + [9601].param3 = 1,
84459 + [9618].file = "security/selinux/selinuxfs.c",
84460 + [9618].name = "sel_write_bool",
84461 + [9618].param3 = 1,
84462 + [9768].file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
84463 + [9768].name = "vmw_execbuf_process",
84464 + [9768].param5 = 1,
84465 + [9828].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84466 + [9828].name = "dvb_demux_do_ioctl",
84467 + [9828].param3 = 1,
84468 + [9870].file = "net/atm/addr.c",
84469 + [9870].name = "atm_get_addr",
84470 + [9870].param3 = 1,
84471 + [9977].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84472 + [9977].name = "zd_usb_iowrite16v_async",
84473 + [9977].param3 = 1,
84474 + [16344].collision = 1,
84475 + [307].collision = 1,
84476 + [31649].collision = 1,
84477 + [33040].collision = 1,
84478 + [45231].collision = 1,
84479 + [60651].collision = 1,
84480 +};
84481 diff --git a/tools/gcc/size_overflow_hash2.h b/tools/gcc/size_overflow_hash2.h
84482 new file mode 100644
84483 index 0000000..9ec45ae
84484 --- /dev/null
84485 +++ b/tools/gcc/size_overflow_hash2.h
84486 @@ -0,0 +1,35 @@
84487 +struct size_overflow_hash size_overflow_hash2[65536] = {
84488 + [22224].file = "fs/proc/vmcore.c",
84489 + [22224].name = "read_from_oldmem",
84490 + [22224].param2 = 1,
84491 + [2344].file = "fs/ecryptfs/crypto.c",
84492 + [2344].name = "ecryptfs_decode_and_decrypt_filename",
84493 + [2344].param5 = 1,
84494 + [2515].file = "fs/ecryptfs/crypto.c",
84495 + [2515].name = "ecryptfs_copy_filename",
84496 + [2515].param4 = 1,
84497 + [26518].file = "drivers/gpu/vga/vgaarb.c",
84498 + [26518].name = "vga_arb_read",
84499 + [26518].param3 = 1,
84500 + [30632].file = "drivers/ide/ide-proc.c",
84501 + [30632].name = "ide_driver_proc_write",
84502 + [30632].param3 = 1,
84503 + [39024].file = "lib/scatterlist.c",
84504 + [39024].name = "sg_kmalloc",
84505 + [39024].param1 = 1,
84506 + [50359].file = "kernel/sched/core.c",
84507 + [50359].name = "alloc_sched_domains",
84508 + [50359].param1 = 1,
84509 + [53262].file = "drivers/block/aoe/aoechr.c",
84510 + [53262].name = "revalidate",
84511 + [53262].param2 = 1,
84512 + [56432].file = "drivers/base/regmap/regmap-debugfs.c",
84513 + [56432].name = "regmap_map_read_file",
84514 + [56432].param3 = 1,
84515 + [57500].file = "drivers/spi/spidev.c",
84516 + [57500].name = "spidev_write",
84517 + [57500].param3 = 1,
84518 + [8155].file = "drivers/hv/channel.c",
84519 + [8155].name = "vmbus_establish_gpadl",
84520 + [8155].param3 = 1,
84521 +};
84522 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
84523 new file mode 100644
84524 index 0000000..255439f
84525 --- /dev/null
84526 +++ b/tools/gcc/size_overflow_plugin.c
84527 @@ -0,0 +1,1110 @@
84528 +/*
84529 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
84530 + * Licensed under the GPL v2, or (at your option) v3
84531 + *
84532 + * Homepage:
84533 + * http://www.grsecurity.net/~ephox/overflow_plugin/
84534 + *
84535 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
84536 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
84537 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
84538 + *
84539 + * Usage:
84540 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
84541 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
84542 + */
84543 +
84544 +#include "gcc-plugin.h"
84545 +#include "config.h"
84546 +#include "system.h"
84547 +#include "coretypes.h"
84548 +#include "tree.h"
84549 +#include "tree-pass.h"
84550 +#include "intl.h"
84551 +#include "plugin-version.h"
84552 +#include "tm.h"
84553 +#include "toplev.h"
84554 +#include "function.h"
84555 +#include "tree-flow.h"
84556 +#include "plugin.h"
84557 +#include "gimple.h"
84558 +#include "c-common.h"
84559 +#include "diagnostic.h"
84560 +#include "cfgloop.h"
84561 +
84562 +struct size_overflow_hash {
84563 + const char *name;
84564 + const char *file;
84565 + unsigned short collision:1;
84566 + unsigned short param1:1;
84567 + unsigned short param2:1;
84568 + unsigned short param3:1;
84569 + unsigned short param4:1;
84570 + unsigned short param5:1;
84571 + unsigned short param6:1;
84572 + unsigned short param7:1;
84573 + unsigned short param8:1;
84574 + unsigned short param9:1;
84575 +};
84576 +
84577 +#include "size_overflow_hash1.h"
84578 +#include "size_overflow_hash2.h"
84579 +
84580 +#define __unused __attribute__((__unused__))
84581 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
84582 +#define BEFORE_STMT true
84583 +#define AFTER_STMT false
84584 +#define CREATE_NEW_VAR NULL_TREE
84585 +
84586 +int plugin_is_GPL_compatible;
84587 +void debug_gimple_stmt (gimple gs);
84588 +
84589 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
84590 +static tree signed_size_overflow_type;
84591 +static tree unsigned_size_overflow_type;
84592 +static tree report_size_overflow_decl;
84593 +static tree const_char_ptr_type_node;
84594 +static unsigned int handle_function(void);
84595 +
84596 +static struct plugin_info size_overflow_plugin_info = {
84597 + .version = "20120409beta",
84598 + .help = "no-size_overflow\tturn off size overflow checking\n",
84599 +};
84600 +
84601 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
84602 +{
84603 + unsigned int arg_count = type_num_arguments(*node);
84604 +
84605 + for (; args; args = TREE_CHAIN(args)) {
84606 + tree position = TREE_VALUE(args);
84607 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
84608 + error("handle_size_overflow_attribute: overflow parameter outside range.");
84609 + *no_add_attrs = true;
84610 + }
84611 + }
84612 + return NULL_TREE;
84613 +}
84614 +
84615 +static struct attribute_spec no_size_overflow_attr = {
84616 + .name = "size_overflow",
84617 + .min_length = 1,
84618 + .max_length = -1,
84619 + .decl_required = false,
84620 + .type_required = true,
84621 + .function_type_required = true,
84622 + .handler = handle_size_overflow_attribute
84623 +};
84624 +
84625 +static void register_attributes(void __unused *event_data, void __unused *data)
84626 +{
84627 + register_attribute(&no_size_overflow_attr);
84628 +}
84629 +
84630 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
84631 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
84632 +{
84633 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
84634 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
84635 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
84636 +
84637 + const unsigned int m = 0x57559429;
84638 + const unsigned int n = 0x5052acdb;
84639 + const unsigned int *key4 = (const unsigned int *)key;
84640 + unsigned int h = len;
84641 + unsigned int k = len + seed + n;
84642 + unsigned long long p;
84643 +
84644 + while (len >= 8) {
84645 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
84646 + len -= 8;
84647 + }
84648 + if (len >= 4) {
84649 + cwmixb(key4[0]) key4 += 1;
84650 + len -= 4;
84651 + }
84652 + if (len)
84653 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
84654 + cwmixb(h ^ (k + n));
84655 + return k ^ h;
84656 +
84657 +#undef cwfold
84658 +#undef cwmixa
84659 +#undef cwmixb
84660 +}
84661 +
84662 +static inline unsigned int size_overflow_hash(const char *fndecl, unsigned int seed)
84663 +{
84664 + return CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
84665 +}
84666 +
84667 +static inline tree get_original_function_decl(tree fndecl)
84668 +{
84669 + if (DECL_ABSTRACT_ORIGIN(fndecl))
84670 + return DECL_ABSTRACT_ORIGIN(fndecl);
84671 + return fndecl;
84672 +}
84673 +
84674 +static inline gimple get_def_stmt(tree node)
84675 +{
84676 + gcc_assert(TREE_CODE(node) == SSA_NAME);
84677 + return SSA_NAME_DEF_STMT(node);
84678 +}
84679 +
84680 +static struct size_overflow_hash *get_function_hash(tree fndecl)
84681 +{
84682 + unsigned int hash;
84683 + const char *func = NAME(fndecl);
84684 +
84685 + hash = size_overflow_hash(func, 0);
84686 +
84687 + if (size_overflow_hash1[hash].collision) {
84688 + hash = size_overflow_hash(func, 23432);
84689 + return &size_overflow_hash2[hash];
84690 + }
84691 + return &size_overflow_hash1[hash];
84692 +}
84693 +
84694 +static void check_arg_type(tree var)
84695 +{
84696 + tree type = TREE_TYPE(var);
84697 + enum tree_code code = TREE_CODE(type);
84698 +
84699 + gcc_assert(code == INTEGER_TYPE ||
84700 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
84701 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
84702 +}
84703 +
84704 +static void check_missing_attribute(tree arg)
84705 +{
84706 + tree var, type, func = get_original_function_decl(current_function_decl);
84707 + const char *curfunc = NAME(func);
84708 + unsigned int new_hash, argnum = 1;
84709 + struct size_overflow_hash *hash;
84710 + location_t loc;
84711 + expanded_location xloc;
84712 + bool match = false;
84713 +
84714 + type = TREE_TYPE(arg);
84715 + // skip function pointers
84716 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
84717 + return;
84718 +
84719 + loc = DECL_SOURCE_LOCATION(func);
84720 + xloc = expand_location(loc);
84721 +
84722 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
84723 + return;
84724 +
84725 + hash = get_function_hash(func);
84726 + if (hash->name && !strcmp(hash->name, NAME(func)) && !strcmp(hash->file, xloc.file))
84727 + return;
84728 +
84729 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
84730 +
84731 + if (TREE_CODE(arg) == SSA_NAME)
84732 + arg = SSA_NAME_VAR(arg);
84733 +
84734 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
84735 + if (strcmp(NAME(arg), NAME(var))) {
84736 + argnum++;
84737 + continue;
84738 + }
84739 + check_arg_type(var);
84740 +
84741 + match = true;
84742 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
84743 + return;
84744 + break;
84745 + }
84746 + if (!match) {
84747 + warning(0, "check_missing_attribute: cannot find the %s argument in %s", NAME(arg), NAME(func));
84748 + return;
84749 + }
84750 +
84751 +#define check_param(num) \
84752 + if (num == argnum && hash->param##num) \
84753 + return;
84754 + check_param(1);
84755 + check_param(2);
84756 + check_param(3);
84757 + check_param(4);
84758 + check_param(5);
84759 + check_param(6);
84760 + check_param(7);
84761 + check_param(8);
84762 + check_param(9);
84763 +#undef check_param
84764 +
84765 + new_hash = size_overflow_hash(curfunc, 0);
84766 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s", curfunc, curfunc, argnum, new_hash, xloc.file);
84767 +}
84768 +
84769 +static tree create_new_var(tree type)
84770 +{
84771 + tree new_var = create_tmp_var(type, "cicus");
84772 +
84773 + add_referenced_var(new_var);
84774 + mark_sym_for_renaming(new_var);
84775 + return new_var;
84776 +}
84777 +
84778 +static bool is_bool(tree node)
84779 +{
84780 + tree type;
84781 +
84782 + if (node == NULL_TREE)
84783 + return false;
84784 +
84785 + type = TREE_TYPE(node);
84786 + if (!INTEGRAL_TYPE_P(type))
84787 + return false;
84788 + if (TREE_CODE(type) == BOOLEAN_TYPE)
84789 + return true;
84790 + if (TYPE_PRECISION(type) == 1)
84791 + return true;
84792 + return false;
84793 +}
84794 +
84795 +static tree cast_a_tree(tree type, tree var)
84796 +{
84797 + gcc_assert(fold_convertible_p(type, var));
84798 +
84799 + return fold_convert(type, var);
84800 +}
84801 +
84802 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
84803 +{
84804 + gimple assign;
84805 +
84806 + if (new_var == CREATE_NEW_VAR)
84807 + new_var = create_new_var(type);
84808 +
84809 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
84810 + gimple_set_location(assign, loc);
84811 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
84812 +
84813 + return assign;
84814 +}
84815 +
84816 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
84817 +{
84818 + tree oldstmt_rhs1;
84819 + enum tree_code code;
84820 + gimple stmt;
84821 + gimple_stmt_iterator gsi;
84822 +
84823 + if (!*potentionally_overflowed)
84824 + return NULL_TREE;
84825 +
84826 + if (rhs1 == NULL_TREE) {
84827 + debug_gimple_stmt(oldstmt);
84828 + error("create_assign: rhs1 is NULL_TREE");
84829 + gcc_unreachable();
84830 + }
84831 +
84832 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
84833 + code = TREE_CODE(oldstmt_rhs1);
84834 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
84835 + check_missing_attribute(oldstmt_rhs1);
84836 +
84837 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
84838 + gsi = gsi_for_stmt(oldstmt);
84839 + if (before)
84840 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
84841 + else
84842 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
84843 + update_stmt(stmt);
84844 + pointer_set_insert(visited, oldstmt);
84845 + return gimple_get_lhs(stmt);
84846 +}
84847 +
84848 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
84849 +{
84850 + tree new_var, lhs = gimple_get_lhs(oldstmt);
84851 + gimple stmt;
84852 + gimple_stmt_iterator gsi;
84853 +
84854 + if (!*potentionally_overflowed)
84855 + return NULL_TREE;
84856 +
84857 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
84858 + rhs1 = gimple_assign_rhs1(oldstmt);
84859 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
84860 + }
84861 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
84862 + rhs2 = gimple_assign_rhs2(oldstmt);
84863 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
84864 + }
84865 +
84866 + stmt = gimple_copy(oldstmt);
84867 + gimple_set_location(stmt, gimple_location(oldstmt));
84868 +
84869 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
84870 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
84871 +
84872 + if (is_bool(lhs))
84873 + new_var = SSA_NAME_VAR(lhs);
84874 + else
84875 + new_var = create_new_var(signed_size_overflow_type);
84876 + new_var = make_ssa_name(new_var, stmt);
84877 + gimple_set_lhs(stmt, new_var);
84878 +
84879 + if (rhs1 != NULL_TREE) {
84880 + if (!gimple_assign_cast_p(oldstmt))
84881 + rhs1 = cast_a_tree(signed_size_overflow_type, rhs1);
84882 + gimple_assign_set_rhs1(stmt, rhs1);
84883 + }
84884 +
84885 + if (rhs2 != NULL_TREE)
84886 + gimple_assign_set_rhs2(stmt, rhs2);
84887 +#if BUILDING_GCC_VERSION >= 4007
84888 + if (rhs3 != NULL_TREE)
84889 + gimple_assign_set_rhs3(stmt, rhs3);
84890 +#endif
84891 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
84892 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
84893 +
84894 + gsi = gsi_for_stmt(oldstmt);
84895 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
84896 + update_stmt(stmt);
84897 + pointer_set_insert(visited, oldstmt);
84898 + return gimple_get_lhs(stmt);
84899 +}
84900 +
84901 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
84902 +{
84903 + basic_block bb;
84904 + gimple phi;
84905 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
84906 +
84907 + bb = gsi_bb(gsi);
84908 +
84909 + phi = create_phi_node(var, bb);
84910 + gsi = gsi_last(phi_nodes(bb));
84911 + gsi_remove(&gsi, false);
84912 +
84913 + gsi = gsi_for_stmt(oldstmt);
84914 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
84915 + gimple_set_bb(phi, bb);
84916 + return phi;
84917 +}
84918 +
84919 +static tree signed_cast_constant(tree node)
84920 +{
84921 + gcc_assert(is_gimple_constant(node));
84922 +
84923 + return cast_a_tree(signed_size_overflow_type, node);
84924 +}
84925 +
84926 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
84927 +{
84928 + basic_block bb;
84929 + gimple newstmt, def_stmt;
84930 + gimple_stmt_iterator gsi;
84931 +
84932 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
84933 + if (TREE_CODE(arg) == SSA_NAME) {
84934 + def_stmt = get_def_stmt(arg);
84935 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
84936 + gsi = gsi_for_stmt(def_stmt);
84937 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
84938 + return newstmt;
84939 + }
84940 + }
84941 +
84942 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
84943 + gsi = gsi_after_labels(bb);
84944 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
84945 + return newstmt;
84946 +}
84947 +
84948 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
84949 +{
84950 + gimple newstmt;
84951 + gimple_stmt_iterator gsi;
84952 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
84953 + gimple def_newstmt = get_def_stmt(new_rhs);
84954 +
84955 + gsi_insert = gsi_insert_after;
84956 + gsi = gsi_for_stmt(def_newstmt);
84957 +
84958 + switch (gimple_code(get_def_stmt(arg))) {
84959 + case GIMPLE_PHI:
84960 + newstmt = gimple_build_assign(new_var, new_rhs);
84961 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
84962 + gsi_insert = gsi_insert_before;
84963 + break;
84964 + case GIMPLE_ASM:
84965 + case GIMPLE_CALL:
84966 + newstmt = gimple_build_assign(new_var, new_rhs);
84967 + break;
84968 + case GIMPLE_ASSIGN:
84969 + newstmt = gimple_copy(def_newstmt);
84970 + break;
84971 + default:
84972 + /* unknown gimple_code (handle_build_new_phi_arg) */
84973 + gcc_unreachable();
84974 + }
84975 +
84976 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
84977 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
84978 + return newstmt;
84979 +}
84980 +
84981 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
84982 +{
84983 + gimple newstmt;
84984 + tree new_rhs;
84985 +
84986 + new_rhs = expand(visited, potentionally_overflowed, arg);
84987 +
84988 + if (new_rhs == NULL_TREE)
84989 + return NULL_TREE;
84990 +
84991 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
84992 + update_stmt(newstmt);
84993 + return gimple_get_lhs(newstmt);
84994 +}
84995 +
84996 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
84997 +{
84998 + gimple phi;
84999 + tree new_var = create_new_var(signed_size_overflow_type);
85000 + unsigned int i, n = gimple_phi_num_args(oldstmt);
85001 +
85002 + pointer_set_insert(visited, oldstmt);
85003 + phi = overflow_create_phi_node(oldstmt, new_var);
85004 + for (i = 0; i < n; i++) {
85005 + tree arg, lhs;
85006 +
85007 + arg = gimple_phi_arg_def(oldstmt, i);
85008 + if (is_gimple_constant(arg))
85009 + arg = signed_cast_constant(arg);
85010 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
85011 + if (lhs == NULL_TREE)
85012 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
85013 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85014 + }
85015 +
85016 + update_stmt(phi);
85017 + return gimple_phi_result(phi);
85018 +}
85019 +
85020 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85021 +{
85022 + gimple def_stmt = get_def_stmt(var);
85023 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85024 +
85025 + *potentionally_overflowed = true;
85026 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85027 + if (new_rhs1 == NULL_TREE) {
85028 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
85029 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85030 + else
85031 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
85032 + }
85033 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85034 +}
85035 +
85036 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85037 +{
85038 + gimple def_stmt = get_def_stmt(var);
85039 + tree rhs1 = gimple_assign_rhs1(def_stmt);
85040 +
85041 + if (is_gimple_constant(rhs1))
85042 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
85043 +
85044 + switch (TREE_CODE(rhs1)) {
85045 + case SSA_NAME:
85046 + return handle_unary_rhs(visited, potentionally_overflowed, var);
85047 +
85048 + case ARRAY_REF:
85049 + case ADDR_EXPR:
85050 + case COMPONENT_REF:
85051 + case COND_EXPR:
85052 + case INDIRECT_REF:
85053 +#if BUILDING_GCC_VERSION >= 4006
85054 + case MEM_REF:
85055 +#endif
85056 + case PARM_DECL:
85057 + case TARGET_MEM_REF:
85058 + case VAR_DECL:
85059 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85060 +
85061 + default:
85062 + debug_gimple_stmt(def_stmt);
85063 + debug_tree(rhs1);
85064 + gcc_unreachable();
85065 + }
85066 +}
85067 +
85068 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
85069 +{
85070 + gimple cond_stmt;
85071 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85072 +
85073 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
85074 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85075 + update_stmt(cond_stmt);
85076 +}
85077 +
85078 +static tree create_string_param(tree string)
85079 +{
85080 + tree array_ref = build4(ARRAY_REF, TREE_TYPE(string), string, integer_zero_node, NULL, NULL);
85081 +
85082 + return build1(ADDR_EXPR, ptr_type_node, array_ref);
85083 +}
85084 +
85085 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85086 +{
85087 + gimple func_stmt, def_stmt;
85088 + tree current_func, loc_file, loc_line;
85089 + expanded_location xloc;
85090 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85091 +
85092 + def_stmt = get_def_stmt(arg);
85093 + xloc = expand_location(gimple_location(def_stmt));
85094 +
85095 + if (!gimple_has_location(def_stmt)) {
85096 + xloc = expand_location(gimple_location(stmt));
85097 + if (!gimple_has_location(stmt))
85098 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85099 + }
85100 +
85101 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85102 +
85103 + loc_file = build_string(strlen(xloc.file), xloc.file);
85104 + TREE_TYPE(loc_file) = char_array_type_node;
85105 + loc_file = create_string_param(loc_file);
85106 +
85107 + current_func = build_string(IDENTIFIER_LENGTH(DECL_NAME(current_function_decl)), NAME(current_function_decl));
85108 + TREE_TYPE(current_func) = char_array_type_node;
85109 + current_func = create_string_param(current_func);
85110 +
85111 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85112 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85113 +
85114 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85115 +}
85116 +
85117 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
85118 +{
85119 + basic_block cond_bb, join_bb, bb_true;
85120 + edge e;
85121 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85122 +// location_t loc = gimple_location(stmt);
85123 +
85124 + cond_bb = gimple_bb(stmt);
85125 + gsi_prev(&gsi);
85126 + if (gsi_end_p(gsi))
85127 + e = split_block_after_labels(cond_bb);
85128 + else
85129 + e = split_block(cond_bb, gsi_stmt(gsi));
85130 + cond_bb = e->src;
85131 + join_bb = e->dest;
85132 + e->flags = EDGE_FALSE_VALUE;
85133 + e->probability = REG_BR_PROB_BASE;
85134 +
85135 + bb_true = create_empty_bb(cond_bb);
85136 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85137 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
85138 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
85139 +
85140 + if (dom_info_available_p(CDI_DOMINATORS)) {
85141 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85142 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85143 + }
85144 +
85145 + if (current_loops != NULL) {
85146 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
85147 + add_bb_to_loop(bb_true, cond_bb->loop_father);
85148 + }
85149 +
85150 + insert_cond(cond_bb, arg, cond_code, type_value);
85151 + insert_cond_result(bb_true, stmt, arg);
85152 +
85153 +// inform(loc, "Integer size_overflow check applied here.");
85154 +}
85155 +
85156 +static tree get_type_for_check(tree rhs)
85157 +{
85158 + tree def_rhs;
85159 + gimple def_stmt = get_def_stmt(rhs);
85160 +
85161 + if (!gimple_assign_cast_p(def_stmt))
85162 + return TREE_TYPE(rhs);
85163 + def_rhs = gimple_assign_rhs1(def_stmt);
85164 + if (TREE_CODE(TREE_TYPE(def_rhs)) == INTEGER_TYPE)
85165 + return TREE_TYPE(def_rhs);
85166 + return TREE_TYPE(rhs);
85167 +}
85168 +
85169 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
85170 +{
85171 + gimple ucast_stmt;
85172 + gimple_stmt_iterator gsi;
85173 + location_t loc = gimple_location(stmt);
85174 +
85175 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
85176 + gsi = gsi_for_stmt(stmt);
85177 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85178 + return ucast_stmt;
85179 +}
85180 +
85181 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
85182 +{
85183 + tree type_max, type_min, rhs_type;
85184 + gimple ucast_stmt;
85185 +
85186 + if (!*potentionally_overflowed)
85187 + return;
85188 +
85189 + rhs_type = get_type_for_check(rhs);
85190 +
85191 + if (TYPE_UNSIGNED(rhs_type)) {
85192 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
85193 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85194 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85195 + } else {
85196 + type_max = cast_a_tree(signed_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85197 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
85198 +
85199 + type_min = cast_a_tree(signed_size_overflow_type, TYPE_MIN_VALUE(rhs_type));
85200 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
85201 + }
85202 +}
85203 +
85204 +static tree change_assign_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree orig_rhs)
85205 +{
85206 + gimple assign;
85207 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85208 + tree new_rhs, origtype = TREE_TYPE(orig_rhs);
85209 +
85210 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
85211 +
85212 + new_rhs = expand(visited, potentionally_overflowed, orig_rhs);
85213 + if (new_rhs == NULL_TREE)
85214 + return NULL_TREE;
85215 +
85216 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
85217 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85218 + update_stmt(assign);
85219 + return gimple_get_lhs(assign);
85220 +}
85221 +
85222 +static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var, tree rhs, tree new_rhs1, tree new_rhs2, void (*gimple_assign_set_rhs)(gimple, tree))
85223 +{
85224 + tree new_rhs, cast_rhs;
85225 +
85226 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
85227 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85228 +
85229 + new_rhs = change_assign_rhs(visited, potentionally_overflowed, def_stmt, rhs);
85230 + if (new_rhs != NULL_TREE) {
85231 + gimple_assign_set_rhs(def_stmt, new_rhs);
85232 + update_stmt(def_stmt);
85233 +
85234 + cast_rhs = gimple_assign_rhs1(get_def_stmt(new_rhs));
85235 +
85236 + check_size_overflow(def_stmt, cast_rhs, rhs, potentionally_overflowed);
85237 + }
85238 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85239 +}
85240 +
85241 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85242 +{
85243 + tree rhs1, rhs2;
85244 + gimple def_stmt = get_def_stmt(var);
85245 + tree new_rhs1 = NULL_TREE;
85246 + tree new_rhs2 = NULL_TREE;
85247 +
85248 + rhs1 = gimple_assign_rhs1(def_stmt);
85249 + rhs2 = gimple_assign_rhs2(def_stmt);
85250 +
85251 + /* no DImode/TImode division in the 32/64 bit kernel */
85252 + switch (gimple_assign_rhs_code(def_stmt)) {
85253 + case RDIV_EXPR:
85254 + case TRUNC_DIV_EXPR:
85255 + case CEIL_DIV_EXPR:
85256 + case FLOOR_DIV_EXPR:
85257 + case ROUND_DIV_EXPR:
85258 + case TRUNC_MOD_EXPR:
85259 + case CEIL_MOD_EXPR:
85260 + case FLOOR_MOD_EXPR:
85261 + case ROUND_MOD_EXPR:
85262 + case EXACT_DIV_EXPR:
85263 + case POINTER_PLUS_EXPR:
85264 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85265 + default:
85266 + break;
85267 + }
85268 +
85269 + *potentionally_overflowed = true;
85270 +
85271 + if (TREE_CODE(rhs1) == SSA_NAME)
85272 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85273 + if (TREE_CODE(rhs2) == SSA_NAME)
85274 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
85275 +
85276 + if (is_gimple_constant(rhs2))
85277 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, signed_cast_constant(rhs2), &gimple_assign_set_rhs1);
85278 +
85279 + if (is_gimple_constant(rhs1))
85280 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, signed_cast_constant(rhs1), new_rhs2, &gimple_assign_set_rhs2);
85281 +
85282 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85283 +}
85284 +
85285 +#if BUILDING_GCC_VERSION >= 4007
85286 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
85287 +{
85288 + if (is_gimple_constant(rhs))
85289 + return signed_cast_constant(rhs);
85290 + if (TREE_CODE(rhs) != SSA_NAME)
85291 + return NULL_TREE;
85292 + return expand(visited, potentionally_overflowed, rhs);
85293 +}
85294 +
85295 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85296 +{
85297 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85298 + gimple def_stmt = get_def_stmt(var);
85299 +
85300 + *potentionally_overflowed = true;
85301 +
85302 + rhs1 = gimple_assign_rhs1(def_stmt);
85303 + rhs2 = gimple_assign_rhs2(def_stmt);
85304 + rhs3 = gimple_assign_rhs3(def_stmt);
85305 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
85306 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
85307 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
85308 +
85309 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85310 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85311 + error("handle_ternary_ops: unknown rhs");
85312 + gcc_unreachable();
85313 +}
85314 +#endif
85315 +
85316 +static void set_size_overflow_type(tree node)
85317 +{
85318 + switch (TYPE_MODE(TREE_TYPE(node))) {
85319 + case SImode:
85320 + signed_size_overflow_type = intDI_type_node;
85321 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85322 + break;
85323 + case DImode:
85324 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85325 + signed_size_overflow_type = intDI_type_node;
85326 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85327 + } else {
85328 + signed_size_overflow_type = intTI_type_node;
85329 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85330 + }
85331 + break;
85332 + default:
85333 + error("set_size_overflow_type: unsupported gcc configuration.");
85334 + gcc_unreachable();
85335 + }
85336 +}
85337 +
85338 +static tree expand_visited(gimple def_stmt)
85339 +{
85340 + gimple tmp;
85341 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85342 +
85343 + gsi_next(&gsi);
85344 + tmp = gsi_stmt(gsi);
85345 + switch (gimple_code(tmp)) {
85346 + case GIMPLE_ASSIGN:
85347 + return gimple_get_lhs(tmp);
85348 + case GIMPLE_PHI:
85349 + return gimple_phi_result(tmp);
85350 + case GIMPLE_CALL:
85351 + return gimple_call_lhs(tmp);
85352 + default:
85353 + return NULL_TREE;
85354 + }
85355 +}
85356 +
85357 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85358 +{
85359 + gimple def_stmt;
85360 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
85361 +
85362 + if (is_gimple_constant(var))
85363 + return NULL_TREE;
85364 +
85365 + if (TREE_CODE(var) == ADDR_EXPR)
85366 + return NULL_TREE;
85367 +
85368 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE);
85369 + if (code != INTEGER_TYPE)
85370 + return NULL_TREE;
85371 +
85372 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
85373 + check_missing_attribute(var);
85374 + return NULL_TREE;
85375 + }
85376 +
85377 + def_stmt = get_def_stmt(var);
85378 +
85379 + if (!def_stmt)
85380 + return NULL_TREE;
85381 +
85382 + if (pointer_set_contains(visited, def_stmt))
85383 + return expand_visited(def_stmt);
85384 +
85385 + switch (gimple_code(def_stmt)) {
85386 + case GIMPLE_NOP:
85387 + check_missing_attribute(var);
85388 + return NULL_TREE;
85389 + case GIMPLE_PHI:
85390 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
85391 + case GIMPLE_CALL:
85392 + case GIMPLE_ASM:
85393 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85394 + case GIMPLE_ASSIGN:
85395 + switch (gimple_num_ops(def_stmt)) {
85396 + case 2:
85397 + return handle_unary_ops(visited, potentionally_overflowed, var);
85398 + case 3:
85399 + return handle_binary_ops(visited, potentionally_overflowed, var);
85400 +#if BUILDING_GCC_VERSION >= 4007
85401 + case 4:
85402 + return handle_ternary_ops(visited, potentionally_overflowed, var);
85403 +#endif
85404 + }
85405 + default:
85406 + debug_gimple_stmt(def_stmt);
85407 + error("expand: unknown gimple code");
85408 + gcc_unreachable();
85409 + }
85410 +}
85411 +
85412 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
85413 +{
85414 + gimple assign;
85415 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85416 + tree origtype = TREE_TYPE(origarg);
85417 +
85418 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
85419 +
85420 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
85421 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85422 + update_stmt(assign);
85423 +
85424 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
85425 + update_stmt(stmt);
85426 +}
85427 +
85428 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
85429 +{
85430 + const char *origid;
85431 + tree arg, origarg;
85432 +
85433 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
85434 + gcc_assert(gimple_call_num_args(stmt) > argnum);
85435 + return gimple_call_arg(stmt, argnum);
85436 + }
85437 +
85438 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
85439 + while (origarg && argnum) {
85440 + argnum--;
85441 + origarg = TREE_CHAIN(origarg);
85442 + }
85443 +
85444 + gcc_assert(argnum == 0);
85445 +
85446 + gcc_assert(origarg != NULL_TREE);
85447 + origid = NAME(origarg);
85448 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
85449 + if (!strcmp(origid, NAME(arg)))
85450 + return arg;
85451 + }
85452 + return NULL_TREE;
85453 +}
85454 +
85455 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
85456 +{
85457 + struct pointer_set_t *visited;
85458 + tree arg, newarg, type_max;
85459 + gimple ucast_stmt;
85460 + bool potentionally_overflowed;
85461 +
85462 + arg = get_function_arg(argnum, stmt, fndecl);
85463 + if (arg == NULL_TREE)
85464 + return;
85465 +
85466 + if (is_gimple_constant(arg))
85467 + return;
85468 + if (TREE_CODE(arg) != SSA_NAME)
85469 + return;
85470 +
85471 + check_arg_type(arg);
85472 +
85473 + set_size_overflow_type(arg);
85474 +
85475 + visited = pointer_set_create();
85476 + potentionally_overflowed = false;
85477 + newarg = expand(visited, &potentionally_overflowed, arg);
85478 + pointer_set_destroy(visited);
85479 +
85480 + if (newarg == NULL_TREE || !potentionally_overflowed)
85481 + return;
85482 +
85483 + change_function_arg(stmt, arg, argnum, newarg);
85484 +
85485 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, newarg);
85486 +
85487 + type_max = build_int_cstu(unsigned_size_overflow_type, 0x7fffffff);
85488 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85489 +}
85490 +
85491 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
85492 +{
85493 + tree p = TREE_VALUE(attr);
85494 + do {
85495 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
85496 + p = TREE_CHAIN(p);
85497 + } while (p);
85498 +}
85499 +
85500 +static void handle_function_by_hash(gimple stmt, tree fndecl)
85501 +{
85502 + struct size_overflow_hash *hash;
85503 + expanded_location xloc;
85504 +
85505 + hash = get_function_hash(fndecl);
85506 + xloc = expand_location(DECL_SOURCE_LOCATION(fndecl));
85507 +
85508 + fndecl = get_original_function_decl(fndecl);
85509 + if (!hash->name || !hash->file)
85510 + return;
85511 + if (strcmp(hash->name, NAME(fndecl)) || strcmp(hash->file, xloc.file))
85512 + return;
85513 +
85514 +#define search_param(argnum) \
85515 + if (hash->param##argnum) \
85516 + handle_function_arg(stmt, fndecl, argnum - 1);
85517 +
85518 + search_param(1);
85519 + search_param(2);
85520 + search_param(3);
85521 + search_param(4);
85522 + search_param(5);
85523 + search_param(6);
85524 + search_param(7);
85525 + search_param(8);
85526 + search_param(9);
85527 +#undef search_param
85528 +}
85529 +
85530 +static unsigned int handle_function(void)
85531 +{
85532 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
85533 + int saved_last_basic_block = last_basic_block;
85534 +
85535 + do {
85536 + gimple_stmt_iterator gsi;
85537 + basic_block next = bb->next_bb;
85538 +
85539 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85540 + tree fndecl, attr;
85541 + gimple stmt = gsi_stmt(gsi);
85542 +
85543 + if (!(is_gimple_call(stmt)))
85544 + continue;
85545 + fndecl = gimple_call_fndecl(stmt);
85546 + if (fndecl == NULL_TREE)
85547 + continue;
85548 + if (gimple_call_num_args(stmt) == 0)
85549 + continue;
85550 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
85551 + if (!attr || !TREE_VALUE(attr))
85552 + handle_function_by_hash(stmt, fndecl);
85553 + else
85554 + handle_function_by_attribute(stmt, attr, fndecl);
85555 + gsi = gsi_for_stmt(stmt);
85556 + }
85557 + bb = next;
85558 + } while (bb && bb->index <= saved_last_basic_block);
85559 + return 0;
85560 +}
85561 +
85562 +static struct gimple_opt_pass size_overflow_pass = {
85563 + .pass = {
85564 + .type = GIMPLE_PASS,
85565 + .name = "size_overflow",
85566 + .gate = NULL,
85567 + .execute = handle_function,
85568 + .sub = NULL,
85569 + .next = NULL,
85570 + .static_pass_number = 0,
85571 + .tv_id = TV_NONE,
85572 + .properties_required = PROP_cfg | PROP_referenced_vars,
85573 + .properties_provided = 0,
85574 + .properties_destroyed = 0,
85575 + .todo_flags_start = 0,
85576 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
85577 + }
85578 +};
85579 +
85580 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
85581 +{
85582 + tree fntype;
85583 +
85584 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
85585 +
85586 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
85587 + fntype = build_function_type_list(void_type_node,
85588 + const_char_ptr_type_node,
85589 + unsigned_type_node,
85590 + const_char_ptr_type_node,
85591 + NULL_TREE);
85592 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
85593 +
85594 + TREE_PUBLIC(report_size_overflow_decl) = 1;
85595 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
85596 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
85597 +}
85598 +
85599 +extern struct gimple_opt_pass pass_dce;
85600 +
85601 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85602 +{
85603 + int i;
85604 + const char * const plugin_name = plugin_info->base_name;
85605 + const int argc = plugin_info->argc;
85606 + const struct plugin_argument * const argv = plugin_info->argv;
85607 + bool enable = true;
85608 +
85609 + struct register_pass_info size_overflow_pass_info = {
85610 + .pass = &size_overflow_pass.pass,
85611 + .reference_pass_name = "ssa",
85612 + .ref_pass_instance_number = 1,
85613 + .pos_op = PASS_POS_INSERT_AFTER
85614 + };
85615 +
85616 + if (!plugin_default_version_check(version, &gcc_version)) {
85617 + error(G_("incompatible gcc/plugin versions"));
85618 + return 1;
85619 + }
85620 +
85621 + for (i = 0; i < argc; ++i) {
85622 + if (!(strcmp(argv[i].key, "no-size_overflow"))) {
85623 + enable = false;
85624 + continue;
85625 + }
85626 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85627 + }
85628 +
85629 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
85630 + if (enable) {
85631 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
85632 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
85633 + }
85634 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85635 +
85636 + return 0;
85637 +}
85638 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
85639 new file mode 100644
85640 index 0000000..b87ec9d
85641 --- /dev/null
85642 +++ b/tools/gcc/stackleak_plugin.c
85643 @@ -0,0 +1,313 @@
85644 +/*
85645 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85646 + * Licensed under the GPL v2
85647 + *
85648 + * Note: the choice of the license means that the compilation process is
85649 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85650 + * but for the kernel it doesn't matter since it doesn't link against
85651 + * any of the gcc libraries
85652 + *
85653 + * gcc plugin to help implement various PaX features
85654 + *
85655 + * - track lowest stack pointer
85656 + *
85657 + * TODO:
85658 + * - initialize all local variables
85659 + *
85660 + * BUGS:
85661 + * - none known
85662 + */
85663 +#include "gcc-plugin.h"
85664 +#include "config.h"
85665 +#include "system.h"
85666 +#include "coretypes.h"
85667 +#include "tree.h"
85668 +#include "tree-pass.h"
85669 +#include "flags.h"
85670 +#include "intl.h"
85671 +#include "toplev.h"
85672 +#include "plugin.h"
85673 +//#include "expr.h" where are you...
85674 +#include "diagnostic.h"
85675 +#include "plugin-version.h"
85676 +#include "tm.h"
85677 +#include "function.h"
85678 +#include "basic-block.h"
85679 +#include "gimple.h"
85680 +#include "rtl.h"
85681 +#include "emit-rtl.h"
85682 +
85683 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85684 +
85685 +int plugin_is_GPL_compatible;
85686 +
85687 +static int track_frame_size = -1;
85688 +static const char track_function[] = "pax_track_stack";
85689 +static const char check_function[] = "pax_check_alloca";
85690 +static bool init_locals;
85691 +
85692 +static struct plugin_info stackleak_plugin_info = {
85693 + .version = "201203140940",
85694 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
85695 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
85696 +};
85697 +
85698 +static bool gate_stackleak_track_stack(void);
85699 +static unsigned int execute_stackleak_tree_instrument(void);
85700 +static unsigned int execute_stackleak_final(void);
85701 +
85702 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
85703 + .pass = {
85704 + .type = GIMPLE_PASS,
85705 + .name = "stackleak_tree_instrument",
85706 + .gate = gate_stackleak_track_stack,
85707 + .execute = execute_stackleak_tree_instrument,
85708 + .sub = NULL,
85709 + .next = NULL,
85710 + .static_pass_number = 0,
85711 + .tv_id = TV_NONE,
85712 + .properties_required = PROP_gimple_leh | PROP_cfg,
85713 + .properties_provided = 0,
85714 + .properties_destroyed = 0,
85715 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
85716 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
85717 + }
85718 +};
85719 +
85720 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
85721 + .pass = {
85722 + .type = RTL_PASS,
85723 + .name = "stackleak_final",
85724 + .gate = gate_stackleak_track_stack,
85725 + .execute = execute_stackleak_final,
85726 + .sub = NULL,
85727 + .next = NULL,
85728 + .static_pass_number = 0,
85729 + .tv_id = TV_NONE,
85730 + .properties_required = 0,
85731 + .properties_provided = 0,
85732 + .properties_destroyed = 0,
85733 + .todo_flags_start = 0,
85734 + .todo_flags_finish = TODO_dump_func
85735 + }
85736 +};
85737 +
85738 +static bool gate_stackleak_track_stack(void)
85739 +{
85740 + return track_frame_size >= 0;
85741 +}
85742 +
85743 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
85744 +{
85745 + gimple check_alloca;
85746 + tree fntype, fndecl, alloca_size;
85747 +
85748 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
85749 + fndecl = build_fn_decl(check_function, fntype);
85750 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85751 +
85752 + // insert call to void pax_check_alloca(unsigned long size)
85753 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
85754 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
85755 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
85756 +}
85757 +
85758 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
85759 +{
85760 + gimple track_stack;
85761 + tree fntype, fndecl;
85762 +
85763 + fntype = build_function_type_list(void_type_node, NULL_TREE);
85764 + fndecl = build_fn_decl(track_function, fntype);
85765 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85766 +
85767 + // insert call to void pax_track_stack(void)
85768 + track_stack = gimple_build_call(fndecl, 0);
85769 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
85770 +}
85771 +
85772 +#if BUILDING_GCC_VERSION == 4005
85773 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
85774 +{
85775 + tree fndecl;
85776 +
85777 + if (!is_gimple_call(stmt))
85778 + return false;
85779 + fndecl = gimple_call_fndecl(stmt);
85780 + if (!fndecl)
85781 + return false;
85782 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
85783 + return false;
85784 +// print_node(stderr, "pax", fndecl, 4);
85785 + return DECL_FUNCTION_CODE(fndecl) == code;
85786 +}
85787 +#endif
85788 +
85789 +static bool is_alloca(gimple stmt)
85790 +{
85791 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
85792 + return true;
85793 +
85794 +#if BUILDING_GCC_VERSION >= 4007
85795 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
85796 + return true;
85797 +#endif
85798 +
85799 + return false;
85800 +}
85801 +
85802 +static unsigned int execute_stackleak_tree_instrument(void)
85803 +{
85804 + basic_block bb, entry_bb;
85805 + bool prologue_instrumented = false, is_leaf = true;
85806 +
85807 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
85808 +
85809 + // 1. loop through BBs and GIMPLE statements
85810 + FOR_EACH_BB(bb) {
85811 + gimple_stmt_iterator gsi;
85812 +
85813 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85814 + gimple stmt;
85815 +
85816 + stmt = gsi_stmt(gsi);
85817 +
85818 + if (is_gimple_call(stmt))
85819 + is_leaf = false;
85820 +
85821 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
85822 + if (!is_alloca(stmt))
85823 + continue;
85824 +
85825 + // 2. insert stack overflow check before each __builtin_alloca call
85826 + stackleak_check_alloca(&gsi);
85827 +
85828 + // 3. insert track call after each __builtin_alloca call
85829 + stackleak_add_instrumentation(&gsi);
85830 + if (bb == entry_bb)
85831 + prologue_instrumented = true;
85832 + }
85833 + }
85834 +
85835 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
85836 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
85837 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
85838 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
85839 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
85840 + return 0;
85841 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
85842 + return 0;
85843 +
85844 + // 4. insert track call at the beginning
85845 + if (!prologue_instrumented) {
85846 + gimple_stmt_iterator gsi;
85847 +
85848 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85849 + if (dom_info_available_p(CDI_DOMINATORS))
85850 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85851 + gsi = gsi_start_bb(bb);
85852 + stackleak_add_instrumentation(&gsi);
85853 + }
85854 +
85855 + return 0;
85856 +}
85857 +
85858 +static unsigned int execute_stackleak_final(void)
85859 +{
85860 + rtx insn;
85861 +
85862 + if (cfun->calls_alloca)
85863 + return 0;
85864 +
85865 + // keep calls only if function frame is big enough
85866 + if (get_frame_size() >= track_frame_size)
85867 + return 0;
85868 +
85869 + // 1. find pax_track_stack calls
85870 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85871 + // 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))
85872 + rtx body;
85873 +
85874 + if (!CALL_P(insn))
85875 + continue;
85876 + body = PATTERN(insn);
85877 + if (GET_CODE(body) != CALL)
85878 + continue;
85879 + body = XEXP(body, 0);
85880 + if (GET_CODE(body) != MEM)
85881 + continue;
85882 + body = XEXP(body, 0);
85883 + if (GET_CODE(body) != SYMBOL_REF)
85884 + continue;
85885 + if (strcmp(XSTR(body, 0), track_function))
85886 + continue;
85887 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85888 + // 2. delete call
85889 + insn = delete_insn_and_edges(insn);
85890 +#if BUILDING_GCC_VERSION >= 4007
85891 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
85892 + insn = delete_insn_and_edges(insn);
85893 +#endif
85894 + }
85895 +
85896 +// print_simple_rtl(stderr, get_insns());
85897 +// print_rtl(stderr, get_insns());
85898 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85899 +
85900 + return 0;
85901 +}
85902 +
85903 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85904 +{
85905 + const char * const plugin_name = plugin_info->base_name;
85906 + const int argc = plugin_info->argc;
85907 + const struct plugin_argument * const argv = plugin_info->argv;
85908 + int i;
85909 + struct register_pass_info stackleak_tree_instrument_pass_info = {
85910 + .pass = &stackleak_tree_instrument_pass.pass,
85911 +// .reference_pass_name = "tree_profile",
85912 + .reference_pass_name = "optimized",
85913 + .ref_pass_instance_number = 0,
85914 + .pos_op = PASS_POS_INSERT_BEFORE
85915 + };
85916 + struct register_pass_info stackleak_final_pass_info = {
85917 + .pass = &stackleak_final_rtl_opt_pass.pass,
85918 + .reference_pass_name = "final",
85919 + .ref_pass_instance_number = 0,
85920 + .pos_op = PASS_POS_INSERT_BEFORE
85921 + };
85922 +
85923 + if (!plugin_default_version_check(version, &gcc_version)) {
85924 + error(G_("incompatible gcc/plugin versions"));
85925 + return 1;
85926 + }
85927 +
85928 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
85929 +
85930 + for (i = 0; i < argc; ++i) {
85931 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
85932 + if (!argv[i].value) {
85933 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85934 + continue;
85935 + }
85936 + track_frame_size = atoi(argv[i].value);
85937 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
85938 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85939 + continue;
85940 + }
85941 + if (!strcmp(argv[i].key, "initialize-locals")) {
85942 + if (argv[i].value) {
85943 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85944 + continue;
85945 + }
85946 + init_locals = true;
85947 + continue;
85948 + }
85949 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85950 + }
85951 +
85952 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
85953 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
85954 +
85955 + return 0;
85956 +}
85957 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
85958 index 6789d78..4afd019 100644
85959 --- a/tools/perf/util/include/asm/alternative-asm.h
85960 +++ b/tools/perf/util/include/asm/alternative-asm.h
85961 @@ -5,4 +5,7 @@
85962
85963 #define altinstruction_entry #
85964
85965 + .macro pax_force_retaddr rip=0, reload=0
85966 + .endm
85967 +
85968 #endif
85969 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
85970 index af0f22f..9a7d479 100644
85971 --- a/usr/gen_init_cpio.c
85972 +++ b/usr/gen_init_cpio.c
85973 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
85974 int retval;
85975 int rc = -1;
85976 int namesize;
85977 - int i;
85978 + unsigned int i;
85979
85980 mode |= S_IFREG;
85981
85982 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
85983 *env_var = *expanded = '\0';
85984 strncat(env_var, start + 2, end - start - 2);
85985 strncat(expanded, new_location, start - new_location);
85986 - strncat(expanded, getenv(env_var), PATH_MAX);
85987 - strncat(expanded, end + 1, PATH_MAX);
85988 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
85989 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
85990 strncpy(new_location, expanded, PATH_MAX);
85991 + new_location[PATH_MAX] = 0;
85992 } else
85993 break;
85994 }
85995 diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
85996 index a457d21..fec1723 100644
85997 --- a/virt/kvm/iommu.c
85998 +++ b/virt/kvm/iommu.c
85999 @@ -310,6 +310,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
86000 }
86001 }
86002
86003 +void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
86004 +{
86005 + kvm_iommu_put_pages(kvm, slot->base_gfn, slot->npages);
86006 +}
86007 +
86008 static int kvm_iommu_unmap_memslots(struct kvm *kvm)
86009 {
86010 int idx;
86011 @@ -320,7 +325,7 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm)
86012 slots = kvm_memslots(kvm);
86013
86014 kvm_for_each_memslot(memslot, slots)
86015 - kvm_iommu_put_pages(kvm, memslot->base_gfn, memslot->npages);
86016 + kvm_iommu_unmap_pages(kvm, memslot);
86017
86018 srcu_read_unlock(&kvm->srcu, idx);
86019
86020 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86021 index a91f980..527711d 100644
86022 --- a/virt/kvm/kvm_main.c
86023 +++ b/virt/kvm/kvm_main.c
86024 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
86025
86026 static cpumask_var_t cpus_hardware_enabled;
86027 static int kvm_usage_count = 0;
86028 -static atomic_t hardware_enable_failed;
86029 +static atomic_unchecked_t hardware_enable_failed;
86030
86031 struct kmem_cache *kvm_vcpu_cache;
86032 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86033 @@ -873,12 +873,13 @@ skip_lpage:
86034 if (r)
86035 goto out_free;
86036
86037 - /* map the pages in iommu page table */
86038 + /* map/unmap the pages in iommu page table */
86039 if (npages) {
86040 r = kvm_iommu_map_pages(kvm, &new);
86041 if (r)
86042 goto out_free;
86043 - }
86044 + } else
86045 + kvm_iommu_unmap_pages(kvm, &old);
86046
86047 r = -ENOMEM;
86048 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
86049 @@ -2312,7 +2313,7 @@ static void hardware_enable_nolock(void *junk)
86050
86051 if (r) {
86052 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86053 - atomic_inc(&hardware_enable_failed);
86054 + atomic_inc_unchecked(&hardware_enable_failed);
86055 printk(KERN_INFO "kvm: enabling virtualization on "
86056 "CPU%d failed\n", cpu);
86057 }
86058 @@ -2366,10 +2367,10 @@ static int hardware_enable_all(void)
86059
86060 kvm_usage_count++;
86061 if (kvm_usage_count == 1) {
86062 - atomic_set(&hardware_enable_failed, 0);
86063 + atomic_set_unchecked(&hardware_enable_failed, 0);
86064 on_each_cpu(hardware_enable_nolock, NULL, 1);
86065
86066 - if (atomic_read(&hardware_enable_failed)) {
86067 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86068 hardware_disable_all_nolock();
86069 r = -EBUSY;
86070 }
86071 @@ -2732,7 +2733,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86072 kvm_arch_vcpu_put(vcpu);
86073 }
86074
86075 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86076 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86077 struct module *module)
86078 {
86079 int r;
86080 @@ -2795,7 +2796,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86081 if (!vcpu_align)
86082 vcpu_align = __alignof__(struct kvm_vcpu);
86083 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86084 - 0, NULL);
86085 + SLAB_USERCOPY, NULL);
86086 if (!kvm_vcpu_cache) {
86087 r = -ENOMEM;
86088 goto out_free_3;
86089 @@ -2805,9 +2806,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86090 if (r)
86091 goto out_free;
86092
86093 - kvm_chardev_ops.owner = module;
86094 - kvm_vm_fops.owner = module;
86095 - kvm_vcpu_fops.owner = module;
86096 + pax_open_kernel();
86097 + *(void **)&kvm_chardev_ops.owner = module;
86098 + *(void **)&kvm_vm_fops.owner = module;
86099 + *(void **)&kvm_vcpu_fops.owner = module;
86100 + pax_close_kernel();
86101
86102 r = misc_register(&kvm_dev);
86103 if (r) {